author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 01:19:32 +0300 | |
changeset 37 | 758a864f9613 |
parent 33 | 3e2da88830cd |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#import <private/qcocoaview_mac_p.h> |
|
43 |
#ifdef QT_MAC_USE_COCOA |
|
44 |
||
45 |
#include <private/qwidget_p.h> |
|
46 |
#include <private/qt_mac_p.h> |
|
47 |
#include <private/qapplication_p.h> |
|
48 |
#include <private/qabstractscrollarea_p.h> |
|
49 |
#include <private/qt_cocoa_helpers_mac_p.h> |
|
50 |
#include <private/qdnd_p.h> |
|
51 |
#include <private/qmacinputcontext_p.h> |
|
52 |
#include <private/qmultitouch_mac_p.h> |
|
53 |
#include <private/qevent_p.h> |
|
54 |
#include <private/qbackingstore_p.h> |
|
55 |
||
56 |
#include <qscrollarea.h> |
|
57 |
#include <qhash.h> |
|
58 |
#include <qtextformat.h> |
|
59 |
#include <qpaintengine.h> |
|
60 |
#include <QUrl> |
|
61 |
#include <QAccessible> |
|
62 |
#include <QFileInfo> |
|
63 |
#include <QFile> |
|
64 |
||
65 |
#include <qdebug.h> |
|
66 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
67 |
@interface NSEvent (Qt_Compile_Leopard_DeviceDelta) |
0 | 68 |
- (CGFloat)deviceDeltaX; |
69 |
- (CGFloat)deviceDeltaY; |
|
70 |
- (CGFloat)deviceDeltaZ; |
|
71 |
@end |
|
72 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
@interface NSEvent (Qt_Compile_Leopard_Gestures) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
74 |
- (CGFloat)magnification; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
75 |
@end |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
76 |
|
0 | 77 |
QT_BEGIN_NAMESPACE |
78 |
||
79 |
Q_GLOBAL_STATIC(DnDParams, qMacDnDParams); |
|
80 |
||
81 |
extern void qt_mac_update_cursor_at_global_pos(const QPoint &globalPos); // qcursor_mac.mm |
|
82 |
extern bool qt_sendSpontaneousEvent(QObject *, QEvent *); // qapplication.cpp |
|
83 |
extern OSViewRef qt_mac_nativeview_for(const QWidget *w); // qwidget_mac.mm |
|
84 |
extern QPointer<QWidget> qt_mouseover; //qapplication_mac.mm |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
85 |
extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
86 |
extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); |
0 | 87 |
|
88 |
struct dndenum_mapper |
|
89 |
{ |
|
90 |
NSDragOperation mac_code; |
|
91 |
Qt::DropAction qt_code; |
|
92 |
bool Qt2Mac; |
|
93 |
}; |
|
94 |
||
95 |
static dndenum_mapper dnd_enums[] = { |
|
96 |
{ NSDragOperationLink, Qt::LinkAction, true }, |
|
97 |
{ NSDragOperationMove, Qt::MoveAction, true }, |
|
98 |
{ NSDragOperationCopy, Qt::CopyAction, true }, |
|
99 |
{ NSDragOperationGeneric, Qt::CopyAction, false }, |
|
100 |
{ NSDragOperationEvery, Qt::ActionMask, false }, |
|
101 |
{ NSDragOperationNone, Qt::IgnoreAction, false } |
|
102 |
}; |
|
103 |
||
104 |
static NSDragOperation qt_mac_mapDropAction(Qt::DropAction action) |
|
105 |
{ |
|
106 |
for (int i=0; dnd_enums[i].qt_code; i++) { |
|
107 |
if (dnd_enums[i].Qt2Mac && (action & dnd_enums[i].qt_code)) { |
|
108 |
return dnd_enums[i].mac_code; |
|
109 |
} |
|
110 |
} |
|
111 |
return NSDragOperationNone; |
|
112 |
} |
|
113 |
||
114 |
static NSDragOperation qt_mac_mapDropActions(Qt::DropActions actions) |
|
115 |
{ |
|
116 |
NSDragOperation nsActions = NSDragOperationNone; |
|
117 |
for (int i=0; dnd_enums[i].qt_code; i++) { |
|
118 |
if (dnd_enums[i].Qt2Mac && (actions & dnd_enums[i].qt_code)) |
|
119 |
nsActions |= dnd_enums[i].mac_code; |
|
120 |
} |
|
121 |
return nsActions; |
|
122 |
} |
|
123 |
||
124 |
static Qt::DropAction qt_mac_mapNSDragOperation(NSDragOperation nsActions) |
|
125 |
{ |
|
126 |
Qt::DropAction action = Qt::IgnoreAction; |
|
127 |
for (int i=0; dnd_enums[i].mac_code; i++) { |
|
128 |
if (nsActions & dnd_enums[i].mac_code) |
|
129 |
return dnd_enums[i].qt_code; |
|
130 |
} |
|
131 |
return action; |
|
132 |
} |
|
133 |
||
134 |
static Qt::DropActions qt_mac_mapNSDragOperations(NSDragOperation nsActions) |
|
135 |
{ |
|
136 |
Qt::DropActions actions = Qt::IgnoreAction; |
|
137 |
for (int i=0; dnd_enums[i].mac_code; i++) { |
|
138 |
if (nsActions & dnd_enums[i].mac_code) |
|
139 |
actions |= dnd_enums[i].qt_code; |
|
140 |
} |
|
141 |
return actions; |
|
142 |
} |
|
143 |
||
144 |
static QColor colorFrom(NSColor *color) |
|
145 |
{ |
|
146 |
QColor qtColor; |
|
147 |
NSString *colorSpace = [color colorSpaceName]; |
|
148 |
if (colorSpace == NSDeviceCMYKColorSpace) { |
|
149 |
CGFloat cyan, magenta, yellow, black, alpha; |
|
150 |
[color getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha]; |
|
151 |
qtColor.setCmykF(cyan, magenta, yellow, black, alpha); |
|
152 |
} else { |
|
153 |
NSColor *tmpColor; |
|
154 |
tmpColor = [color colorUsingColorSpaceName:NSDeviceRGBColorSpace]; |
|
155 |
CGFloat red, green, blue, alpha; |
|
156 |
[tmpColor getRed:&red green:&green blue:&blue alpha:&alpha]; |
|
157 |
qtColor.setRgbF(red, green, blue, alpha); |
|
158 |
} |
|
159 |
return qtColor; |
|
160 |
} |
|
161 |
||
162 |
QT_END_NAMESPACE |
|
163 |
||
164 |
QT_FORWARD_DECLARE_CLASS(QMacCocoaAutoReleasePool) |
|
165 |
QT_FORWARD_DECLARE_CLASS(QCFString) |
|
166 |
QT_FORWARD_DECLARE_CLASS(QDragManager) |
|
167 |
QT_FORWARD_DECLARE_CLASS(QMimeData) |
|
168 |
QT_FORWARD_DECLARE_CLASS(QPoint) |
|
169 |
QT_FORWARD_DECLARE_CLASS(QApplication) |
|
170 |
QT_FORWARD_DECLARE_CLASS(QApplicationPrivate) |
|
171 |
QT_FORWARD_DECLARE_CLASS(QDragEnterEvent) |
|
172 |
QT_FORWARD_DECLARE_CLASS(QDragMoveEvent) |
|
173 |
QT_FORWARD_DECLARE_CLASS(QStringList) |
|
174 |
QT_FORWARD_DECLARE_CLASS(QString) |
|
175 |
QT_FORWARD_DECLARE_CLASS(QRect) |
|
176 |
QT_FORWARD_DECLARE_CLASS(QRegion) |
|
177 |
QT_FORWARD_DECLARE_CLASS(QAbstractScrollArea) |
|
178 |
QT_FORWARD_DECLARE_CLASS(QAbstractScrollAreaPrivate) |
|
179 |
QT_FORWARD_DECLARE_CLASS(QPaintEvent) |
|
180 |
QT_FORWARD_DECLARE_CLASS(QPainter) |
|
181 |
QT_FORWARD_DECLARE_CLASS(QHoverEvent) |
|
182 |
QT_FORWARD_DECLARE_CLASS(QCursor) |
|
183 |
QT_USE_NAMESPACE |
|
184 |
extern "C" { |
|
185 |
extern NSString *NSTextInputReplacementRangeAttributeName; |
|
186 |
} |
|
187 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
188 |
#ifdef ALIEN_DEBUG |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
189 |
static int qCocoaViewCount = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
190 |
#endif |
0 | 191 |
|
192 |
@implementation QT_MANGLE_NAMESPACE(QCocoaView) |
|
193 |
||
194 |
- (id)initWithQWidget:(QWidget *)widget widgetPrivate:(QWidgetPrivate *)widgetprivate |
|
195 |
{ |
|
196 |
self = [super init]; |
|
197 |
if (self) { |
|
198 |
[self finishInitWithQWidget:widget widgetPrivate:widgetprivate]; |
|
199 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
200 |
[self setFocusRingType:NSFocusRingTypeNone]; |
0 | 201 |
composingText = new QString(); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
202 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
203 |
#ifdef ALIEN_DEBUG |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
204 |
++qCocoaViewCount; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
205 |
qDebug() << "init: qCocoaViewCount is" << qCocoaViewCount; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
206 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
207 |
|
0 | 208 |
composing = false; |
209 |
sendKeyEvents = true; |
|
210 |
[self setHidden:YES]; |
|
211 |
return self; |
|
212 |
} |
|
213 |
||
214 |
- (void) finishInitWithQWidget:(QWidget *)widget widgetPrivate:(QWidgetPrivate *)widgetprivate |
|
215 |
{ |
|
216 |
qwidget = widget; |
|
217 |
qwidgetprivate = widgetprivate; |
|
218 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
219 |
selector:@selector(frameDidChange:) |
|
220 |
name:@"NSViewFrameDidChangeNotification" |
|
221 |
object:self]; |
|
222 |
} |
|
223 |
||
224 |
- (void)resetCursorRects |
|
225 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
226 |
// [NSView addCursorRect] is slow, so bail out early if we can: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
227 |
if (NSIsEmptyRect([self visibleRect])) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
228 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
229 |
|
0 | 230 |
QWidget *cursorWidget = qwidget; |
231 |
||
232 |
if (cursorWidget->testAttribute(Qt::WA_TransparentForMouseEvents)) |
|
233 |
cursorWidget = QApplication::widgetAt(qwidget->mapToGlobal(qwidget->rect().center())); |
|
234 |
||
235 |
if (cursorWidget == 0) |
|
236 |
return; |
|
237 |
||
238 |
if (!cursorWidget->testAttribute(Qt::WA_SetCursor)) { |
|
239 |
[super resetCursorRects]; |
|
240 |
return; |
|
241 |
} |
|
242 |
||
243 |
QRegion mask = qt_widget_private(cursorWidget)->extra->mask; |
|
244 |
NSCursor *nscursor = static_cast<NSCursor *>(qt_mac_nsCursorForQCursor(cursorWidget->cursor())); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
245 |
// The mask could have the WA_MouseNoMask attribute set and that means that we have to ignore the mask. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
246 |
if (mask.isEmpty() || cursorWidget->testAttribute(Qt::WA_MouseNoMask)) { |
0 | 247 |
[self addCursorRect:[qt_mac_nativeview_for(cursorWidget) visibleRect] cursor:nscursor]; |
248 |
} else { |
|
249 |
const QVector<QRect> &rects = mask.rects(); |
|
250 |
for (int i = 0; i < rects.size(); ++i) { |
|
251 |
const QRect &rect = rects.at(i); |
|
252 |
[self addCursorRect:NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height()) cursor:nscursor]; |
|
253 |
} |
|
254 |
} |
|
255 |
} |
|
256 |
||
257 |
- (void)removeDropData |
|
258 |
{ |
|
259 |
if (dropData) { |
|
260 |
delete dropData; |
|
261 |
dropData = 0; |
|
262 |
} |
|
263 |
} |
|
264 |
||
265 |
- (void)addDropData:(id <NSDraggingInfo>)sender |
|
266 |
{ |
|
267 |
[self removeDropData]; |
|
268 |
CFStringRef dropPasteboard = (CFStringRef) [[sender draggingPasteboard] name]; |
|
269 |
dropData = new QCocoaDropData(dropPasteboard); |
|
270 |
} |
|
271 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
272 |
- (void)changeDraggingCursor:(NSDragOperation)newOperation |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
273 |
{ |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
274 |
static SEL action = nil; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
275 |
static bool operationSupported = false; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
276 |
if (action == nil) { |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
277 |
action = NSSelectorFromString(@"operationNotAllowedCursor"); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
278 |
if ([NSCursor respondsToSelector:action]) { |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
279 |
operationSupported = true; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
280 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
281 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
282 |
if (operationSupported) { |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
283 |
NSCursor *notAllowedCursor = [NSCursor performSelector:action]; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
284 |
bool isNotAllowedCursor = ([NSCursor currentCursor] == notAllowedCursor); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
285 |
if (newOperation == NSDragOperationNone && !isNotAllowedCursor) { |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
286 |
[notAllowedCursor push]; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
287 |
} else if (newOperation != NSDragOperationNone && isNotAllowedCursor) { |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
288 |
[notAllowedCursor pop]; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
289 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
290 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
291 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
292 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
293 |
|
0 | 294 |
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender |
295 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
296 |
// NB: This function is called from QCoocaWindow/QCocoaPanel rather than directly |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
297 |
// from Cocoa. They modify the drag target, and might fake enter/leave events. |
0 | 298 |
NSPoint windowPoint = [sender draggingLocation]; |
299 |
dragEnterSequence = [sender draggingSequenceNumber]; |
|
300 |
[self addDropData:sender]; |
|
301 |
QMimeData *mimeData = dropData; |
|
302 |
if (QDragManager::self()->source()) |
|
303 |
mimeData = QDragManager::self()->dragPrivate()->data; |
|
304 |
NSPoint globalPoint = [[sender draggingDestinationWindow] convertBaseToScreen:windowPoint]; |
|
305 |
NSPoint localPoint = [self convertPoint:windowPoint fromView:nil]; |
|
306 |
QPoint posDrag(localPoint.x, localPoint.y); |
|
307 |
NSDragOperation nsActions = [sender draggingSourceOperationMask]; |
|
308 |
Qt::DropActions qtAllowed = qt_mac_mapNSDragOperations(nsActions); |
|
309 |
QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec.lastOperation) = nsActions; |
|
310 |
Qt::KeyboardModifiers modifiers = Qt::NoModifier; |
|
311 |
if ([sender draggingSource] != nil) { |
|
312 |
// modifier flags might have changed, update it here since we don't send any input events. |
|
313 |
QApplicationPrivate::modifier_buttons = qt_cocoaModifiers2QtModifiers([[NSApp currentEvent] modifierFlags]); |
|
314 |
modifiers = QApplication::keyboardModifiers(); |
|
315 |
} else { |
|
316 |
// when the source is from another application the above technique will not work. |
|
317 |
modifiers = qt_cocoaDragOperation2QtModifiers(nsActions); |
|
318 |
} |
|
319 |
// send the drag enter event to the widget. |
|
320 |
QDragEnterEvent qDEEvent(posDrag, qtAllowed, mimeData, QApplication::mouseButtons(), modifiers); |
|
321 |
QApplication::sendEvent(qwidget, &qDEEvent); |
|
322 |
if (!qDEEvent.isAccepted()) { |
|
323 |
// widget is not interested in this drag, so ignore this drop data. |
|
324 |
[self removeDropData]; |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
325 |
[self changeDraggingCursor:NSDragOperationNone]; |
0 | 326 |
return NSDragOperationNone; |
327 |
} else { |
|
328 |
// save the mouse position, used by draggingExited handler. |
|
329 |
DnDParams *dndParams = [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]; |
|
330 |
dndParams->activeDragEnterPos = windowPoint; |
|
331 |
// send a drag move event immediately after a drag enter event (as per documentation). |
|
332 |
QDragMoveEvent qDMEvent(posDrag, qtAllowed, mimeData, QApplication::mouseButtons(), modifiers); |
|
333 |
qDMEvent.setDropAction(qDEEvent.dropAction()); |
|
334 |
qDMEvent.accept(); // accept by default, since enter event was accepted. |
|
335 |
QApplication::sendEvent(qwidget, &qDMEvent); |
|
336 |
if (!qDMEvent.isAccepted() || qDMEvent.dropAction() == Qt::IgnoreAction) { |
|
337 |
// since we accepted the drag enter event, the widget expects |
|
338 |
// future drage move events. |
|
339 |
// ### check if we need to treat this like the drag enter event. |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
340 |
nsActions = NSDragOperationNone; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
341 |
// Save as ignored in the answer rect. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
342 |
qDMEvent.setDropAction(Qt::IgnoreAction); |
0 | 343 |
} else { |
344 |
nsActions = QT_PREPEND_NAMESPACE(qt_mac_mapDropAction)(qDMEvent.dropAction()); |
|
345 |
} |
|
346 |
QT_PREPEND_NAMESPACE(qt_mac_copy_answer_rect)(qDMEvent); |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
347 |
[self changeDraggingCursor:nsActions]; |
0 | 348 |
return nsActions; |
349 |
} |
|
350 |
} |
|
351 |
- (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender |
|
352 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
353 |
// NB: This function is called from QCoocaWindow/QCocoaPanel rather than directly |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
354 |
// from Cocoa. They modify the drag target, and might fake enter/leave events. |
0 | 355 |
NSPoint windowPoint = [sender draggingLocation]; |
356 |
// in cases like QFocusFrame, the view under the mouse might |
|
357 |
// not have received the drag enter. Generate a synthetic |
|
358 |
// drag enter event for that view. |
|
359 |
if (dragEnterSequence != [sender draggingSequenceNumber]) |
|
360 |
[self draggingEntered:sender]; |
|
361 |
// drag enter event was rejected, so ignore the move event. |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
362 |
if (dropData == 0) { |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
363 |
[self changeDraggingCursor:NSDragOperationNone]; |
0 | 364 |
return NSDragOperationNone; |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
365 |
} |
0 | 366 |
// return last value, if we are still in the answerRect. |
367 |
NSPoint globalPoint = [[sender draggingDestinationWindow] convertBaseToScreen:windowPoint]; |
|
368 |
NSPoint localPoint = [self convertPoint:windowPoint fromView:nil]; |
|
369 |
NSDragOperation nsActions = [sender draggingSourceOperationMask]; |
|
370 |
QPoint posDrag(localPoint.x, localPoint.y); |
|
371 |
if (qt_mac_mouse_inside_answer_rect(posDrag) |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
372 |
&& QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec.lastOperation) == nsActions) { |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
373 |
NSDragOperation operation = QT_PREPEND_NAMESPACE(qt_mac_mapDropActions)(QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec.lastAction)); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
374 |
[self changeDraggingCursor:operation]; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
375 |
return operation; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
376 |
} |
0 | 377 |
// send drag move event to the widget |
378 |
QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec.lastOperation) = nsActions; |
|
379 |
Qt::DropActions qtAllowed = QT_PREPEND_NAMESPACE(qt_mac_mapNSDragOperations)(nsActions); |
|
380 |
Qt::KeyboardModifiers modifiers = Qt::NoModifier; |
|
381 |
if ([sender draggingSource] != nil) { |
|
382 |
// modifier flags might have changed, update it here since we don't send any input events. |
|
383 |
QApplicationPrivate::modifier_buttons = qt_cocoaModifiers2QtModifiers([[NSApp currentEvent] modifierFlags]); |
|
384 |
modifiers = QApplication::keyboardModifiers(); |
|
385 |
} else { |
|
386 |
// when the source is from another application the above technique will not work. |
|
387 |
modifiers = qt_cocoaDragOperation2QtModifiers(nsActions); |
|
388 |
} |
|
389 |
QMimeData *mimeData = dropData; |
|
390 |
if (QDragManager::self()->source()) |
|
391 |
mimeData = QDragManager::self()->dragPrivate()->data; |
|
392 |
QDragMoveEvent qDMEvent(posDrag, qtAllowed, mimeData, QApplication::mouseButtons(), modifiers); |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
393 |
if (QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec).lastAction != Qt::IgnoreAction |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
394 |
&& QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec).buttons == qDMEvent.mouseButtons() |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
395 |
&& QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec).modifiers == qDMEvent.keyboardModifiers()) |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
396 |
qDMEvent.setDropAction(QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec).lastAction); |
0 | 397 |
qDMEvent.accept(); |
398 |
QApplication::sendEvent(qwidget, &qDMEvent); |
|
399 |
||
400 |
NSDragOperation operation = qt_mac_mapDropAction(qDMEvent.dropAction()); |
|
401 |
if (!qDMEvent.isAccepted() || qDMEvent.dropAction() == Qt::IgnoreAction) { |
|
402 |
// ignore this event (we will still receive further notifications) |
|
403 |
operation = NSDragOperationNone; |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
404 |
// Save as ignored in the answer rect. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
405 |
qDMEvent.setDropAction(Qt::IgnoreAction); |
0 | 406 |
} |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
407 |
qt_mac_copy_answer_rect(qDMEvent); |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
408 |
[self changeDraggingCursor:operation]; |
0 | 409 |
return operation; |
410 |
} |
|
411 |
||
412 |
- (void)draggingExited:(id < NSDraggingInfo >)sender |
|
413 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
414 |
// NB: This function is called from QCoocaWindow/QCocoaPanel rather than directly |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
415 |
// from Cocoa. They modify the drag target, and might fake enter/leave events. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
416 |
Q_UNUSED(sender); |
0 | 417 |
dragEnterSequence = -1; |
418 |
// drag enter event was rejected, so ignore the move event. |
|
419 |
if (dropData) { |
|
420 |
QDragLeaveEvent de; |
|
421 |
QApplication::sendEvent(qwidget, &de); |
|
422 |
[self removeDropData]; |
|
423 |
} |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
424 |
[self changeDraggingCursor:NSDragOperationEvery]; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
425 |
|
0 | 426 |
} |
427 |
||
428 |
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender |
|
429 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
430 |
// NB: This function is called from QCoocaWindow/QCocoaPanel rather than directly |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
431 |
// from Cocoa. They modify the drag target, and might fake enter/leave events. |
0 | 432 |
NSPoint windowPoint = [sender draggingLocation]; |
433 |
dragEnterSequence = -1; |
|
434 |
[self addDropData:sender]; |
|
435 |
||
436 |
NSPoint globalPoint = [[sender draggingDestinationWindow] convertBaseToScreen:windowPoint]; |
|
437 |
NSPoint localPoint = [self convertPoint:windowPoint fromView:nil]; |
|
438 |
QPoint posDrop(localPoint.x, localPoint.y); |
|
439 |
||
440 |
NSDragOperation nsActions = [sender draggingSourceOperationMask]; |
|
441 |
Qt::DropActions qtAllowed = qt_mac_mapNSDragOperations(nsActions); |
|
442 |
QMimeData *mimeData = dropData; |
|
443 |
if (QDragManager::self()->source()) |
|
444 |
mimeData = QDragManager::self()->dragPrivate()->data; |
|
445 |
// send the drop event to the widget. |
|
446 |
QDropEvent de(posDrop, qtAllowed, mimeData, |
|
447 |
QApplication::mouseButtons(), QApplication::keyboardModifiers()); |
|
448 |
if (QDragManager::self()->object) |
|
449 |
QDragManager::self()->dragPrivate()->target = qwidget; |
|
450 |
QApplication::sendEvent(qwidget, &de); |
|
451 |
if (QDragManager::self()->object) |
|
452 |
QDragManager::self()->dragPrivate()->executed_action = de.dropAction(); |
|
453 |
if (!de.isAccepted()) |
|
454 |
return NO; |
|
455 |
else |
|
456 |
return YES; |
|
457 |
} |
|
458 |
||
459 |
- (void)dealloc |
|
460 |
{ |
|
461 |
delete composingText; |
|
462 |
[[NSNotificationCenter defaultCenter] removeObserver:self]; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
463 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
464 |
#ifdef ALIEN_DEBUG |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
465 |
--qCocoaViewCount; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
466 |
qDebug() << "qCocoaViewCount is" << qCocoaViewCount; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
467 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
468 |
|
0 | 469 |
[super dealloc]; |
470 |
} |
|
471 |
||
472 |
- (BOOL)isOpaque; |
|
473 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
474 |
if (!qwidgetprivate) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
475 |
return [super isOpaque]; |
0 | 476 |
return qwidgetprivate->isOpaque; |
477 |
} |
|
478 |
||
479 |
- (BOOL)isFlipped; |
|
480 |
{ |
|
481 |
return YES; |
|
482 |
} |
|
483 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
484 |
// We preserve the content of the view if WA_StaticContents is defined. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
485 |
// |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
486 |
// More info in the Cocoa documentation: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
487 |
// http://developer.apple.com/mac/library/documentation/cocoa/conceptual/CocoaViewsGuide/Optimizing/Optimizing.html |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
488 |
- (BOOL) preservesContentDuringLiveResize |
0 | 489 |
{ |
490 |
return qwidget->testAttribute(Qt::WA_StaticContents); |
|
491 |
} |
|
492 |
||
493 |
- (void) setFrameSize:(NSSize)newSize |
|
494 |
{ |
|
495 |
[super setFrameSize:newSize]; |
|
496 |
||
497 |
// A change in size has required the view to be invalidated. |
|
498 |
if ([self inLiveResize]) { |
|
499 |
NSRect rects[4]; |
|
500 |
NSInteger count; |
|
501 |
[self getRectsExposedDuringLiveResize:rects count:&count]; |
|
502 |
while (count-- > 0) |
|
503 |
{ |
|
504 |
[self setNeedsDisplayInRect:rects[count]]; |
|
505 |
} |
|
506 |
} else { |
|
507 |
[self setNeedsDisplay:YES]; |
|
508 |
} |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
509 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
510 |
// Make sure the opengl context is updated on resize. |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
511 |
if (qwidgetprivate && qwidgetprivate->isGLWidget) { |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
512 |
qwidgetprivate->needWindowChange = true; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
513 |
QEvent event(QEvent::MacGLWindowChange); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
514 |
qApp->sendEvent(qwidget, &event); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
515 |
} |
0 | 516 |
} |
517 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
518 |
// We catch the 'setNeedsDisplay:' message in order to avoid a useless full repaint. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
519 |
// During the resize, the top of the widget is repainted, probably because of the |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
520 |
// change of coordinate space (Quartz vs Qt). This is then followed by this message: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
521 |
// -[NSView _setNeedsDisplayIfTopLeftChanged] |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
522 |
// which force a full repaint by sending the message 'setNeedsDisplay:'. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
523 |
// That is what we are preventing here. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
524 |
- (void)setNeedsDisplay:(BOOL)flag { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
525 |
if (![self inLiveResize] || !(qwidget->testAttribute(Qt::WA_StaticContents))) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
526 |
[super setNeedsDisplay:flag]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
527 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
528 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
529 |
|
0 | 530 |
- (void)drawRect:(NSRect)aRect |
531 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
532 |
if (!qwidget) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
533 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
534 |
|
0 | 535 |
if (QApplicationPrivate::graphicsSystem() != 0) { |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
536 |
if (qwidgetprivate->maybeBackingStore()) { |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
537 |
// Drawing is handled on the window level |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
538 |
// See qcocoasharedwindowmethods_mac_p.h |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
539 |
if (!qwidget->testAttribute(Qt::WA_PaintOnScreen)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
540 |
return; |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
541 |
} |
0 | 542 |
} |
543 |
CGContextRef cg = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; |
|
544 |
qwidgetprivate->hd = cg; |
|
545 |
CGContextSaveGState(cg); |
|
546 |
||
547 |
if (qwidget->isVisible() && qwidget->updatesEnabled()) { //process the actual paint event. |
|
548 |
if (qwidget->testAttribute(Qt::WA_WState_InPaintEvent)) |
|
549 |
qWarning("QWidget::repaint: Recursive repaint detected"); |
|
550 |
||
551 |
const QRect qrect = QRect(aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
552 |
QRegion qrgn; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
553 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
554 |
const NSRect *rects; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
555 |
NSInteger count; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
556 |
[self getRectsBeingDrawn:&rects count:&count]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
557 |
for (int i = 0; i < count; ++i) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
558 |
QRect tmpRect = QRect(rects[i].origin.x, rects[i].origin.y, rects[i].size.width, rects[i].size.height); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
559 |
qrgn += tmpRect; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
560 |
} |
0 | 561 |
|
562 |
if (!qwidget->isWindow() && !qobject_cast<QAbstractScrollArea *>(qwidget->parent())) { |
|
563 |
const QRegion &parentMask = qwidget->window()->mask(); |
|
564 |
if (!parentMask.isEmpty()) { |
|
565 |
const QPoint mappedPoint = qwidget->mapTo(qwidget->window(), qrect.topLeft()); |
|
566 |
qrgn.translate(mappedPoint); |
|
567 |
qrgn &= parentMask; |
|
568 |
qrgn.translate(-mappedPoint.x(), -mappedPoint.y()); |
|
569 |
} |
|
570 |
} |
|
571 |
||
572 |
QPoint redirectionOffset(0, 0); |
|
573 |
//setup the context |
|
574 |
qwidget->setAttribute(Qt::WA_WState_InPaintEvent); |
|
575 |
QPaintEngine *engine = qwidget->paintEngine(); |
|
576 |
if (engine) |
|
577 |
engine->setSystemClip(qrgn); |
|
578 |
if (qwidgetprivate->extra && qwidgetprivate->extra->hasMask) { |
|
579 |
CGRect widgetRect = CGRectMake(0, 0, qwidget->width(), qwidget->height()); |
|
580 |
CGContextTranslateCTM (cg, 0, widgetRect.size.height); |
|
581 |
CGContextScaleCTM(cg, 1, -1); |
|
582 |
if (qwidget->isWindow()) |
|
583 |
CGContextClearRect(cg, widgetRect); |
|
584 |
CGContextClipToMask(cg, widgetRect, qwidgetprivate->extra->imageMask); |
|
585 |
CGContextScaleCTM(cg, 1, -1); |
|
586 |
CGContextTranslateCTM (cg, 0, -widgetRect.size.height); |
|
587 |
} |
|
588 |
||
589 |
if (qwidget->isWindow() && !qwidgetprivate->isOpaque |
|
590 |
&& !qwidget->testAttribute(Qt::WA_MacBrushedMetal)) { |
|
591 |
CGContextClearRect(cg, NSRectToCGRect(aRect)); |
|
592 |
} |
|
593 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
594 |
// Check for alien widgets, use qwidgetPrivate->drawWidget() to draw the widget if this |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
595 |
// is the case. This makes sure child widgets are drawn as well, Cocoa does not know about |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
596 |
// those and wont send them drawRect calls. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
597 |
if (qwidget->testAttribute(Qt::WA_NativeWindow) && qt_widget_private(qwidget)->hasAlienChildren == false) { |
0 | 598 |
if (engine && !qwidget->testAttribute(Qt::WA_NoSystemBackground) |
599 |
&& (qwidget->isWindow() || qwidget->autoFillBackground()) |
|
600 |
|| qwidget->testAttribute(Qt::WA_TintedBackground) |
|
601 |
|| qwidget->testAttribute(Qt::WA_StyledBackground)) { |
|
602 |
#ifdef DEBUG_WIDGET_PAINT |
|
603 |
if(doDebug) |
|
604 |
qDebug(" Handling erase for [%s::%s]", qwidget->metaObject()->className(), |
|
605 |
qwidget->objectName().local8Bit().data()); |
|
606 |
#endif |
|
607 |
QPainter p(qwidget); |
|
608 |
qwidgetprivate->paintBackground(&p, qrgn, |
|
609 |
qwidget->isWindow() ? QWidgetPrivate::DrawAsRoot : 0); |
|
610 |
p.end(); |
|
611 |
} |
|
612 |
QPaintEvent e(qrgn); |
|
613 |
#ifdef QT3_SUPPORT |
|
614 |
e.setErased(true); |
|
615 |
#endif |
|
616 |
qt_sendSpontaneousEvent(qwidget, &e); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
617 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
618 |
qwidget->setAttribute(Qt::WA_WState_InPaintEvent, false); // QWidgetPrivate::drawWidget sets this |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
619 |
QWidgetPrivate *qwidgetPrivate = qt_widget_private(qwidget); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
620 |
qwidgetPrivate->drawWidget(qwidget, qrgn, QPoint(), QWidgetPrivate::DrawAsRoot | QWidgetPrivate::DrawPaintOnScreen | QWidgetPrivate::DrawRecursive, 0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
621 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
622 |
|
0 | 623 |
if (!redirectionOffset.isNull()) |
624 |
QPainter::restoreRedirected(qwidget); |
|
625 |
if (engine) |
|
626 |
engine->setSystemClip(QRegion()); |
|
627 |
qwidget->setAttribute(Qt::WA_WState_InPaintEvent, false); |
|
628 |
if(!qwidget->testAttribute(Qt::WA_PaintOutsidePaintEvent) && qwidget->paintingActive()) |
|
629 |
qWarning("QWidget: It is dangerous to leave painters active on a" |
|
630 |
" widget outside of the PaintEvent"); |
|
631 |
} |
|
632 |
qwidgetprivate->hd = 0; |
|
633 |
CGContextRestoreGState(cg); |
|
634 |
} |
|
635 |
||
636 |
- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent |
|
637 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
638 |
if (!qwidget) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
639 |
return NO; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
640 |
|
0 | 641 |
Q_UNUSED(theEvent); |
642 |
return !qwidget->testAttribute(Qt::WA_MacNoClickThrough); |
|
643 |
} |
|
644 |
||
645 |
- (NSView *)hitTest:(NSPoint)aPoint |
|
646 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
647 |
if (!qwidget) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
648 |
return [super hitTest:aPoint]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
649 |
|
0 | 650 |
if (qwidget->testAttribute(Qt::WA_TransparentForMouseEvents)) |
651 |
return nil; // You cannot hit a transparent for mouse event widget. |
|
652 |
return [super hitTest:aPoint]; |
|
653 |
} |
|
654 |
||
655 |
- (void)updateTrackingAreas |
|
656 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
657 |
if (!qwidget) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
658 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
659 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
660 |
// [NSView addTrackingArea] is slow, so bail out early if we can: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
661 |
if (NSIsEmptyRect([self visibleRect])) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
662 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
663 |
|
0 | 664 |
QMacCocoaAutoReleasePool pool; |
665 |
if (NSArray *trackingArray = [self trackingAreas]) { |
|
666 |
NSUInteger size = [trackingArray count]; |
|
667 |
for (NSUInteger i = 0; i < size; ++i) { |
|
668 |
NSTrackingArea *t = [trackingArray objectAtIndex:i]; |
|
669 |
[self removeTrackingArea:t]; |
|
670 |
} |
|
671 |
} |
|
672 |
||
673 |
// Ideally, we shouldn't have NSTrackingMouseMoved events included below, it should |
|
674 |
// only be turned on if mouseTracking, hover is on or a tool tip is set. |
|
675 |
// Unfortunately, Qt will send "tooltip" events on mouse moves, so we need to |
|
676 |
// turn it on in ALL case. That means EVERY QCocoaView gets to pay the cost of |
|
677 |
// mouse moves delivered to it (Apple recommends keeping it OFF because there |
|
678 |
// is a performance hit). So it goes. |
|
679 |
NSUInteger trackingOptions = NSTrackingMouseEnteredAndExited | NSTrackingActiveInActiveApp |
|
680 |
| NSTrackingInVisibleRect | NSTrackingMouseMoved; |
|
681 |
NSTrackingArea *ta = [[NSTrackingArea alloc] initWithRect:NSMakeRect(0, 0, |
|
682 |
qwidget->width(), |
|
683 |
qwidget->height()) |
|
684 |
options:trackingOptions |
|
685 |
owner:self |
|
686 |
userInfo:nil]; |
|
687 |
[self addTrackingArea:ta]; |
|
688 |
[ta release]; |
|
689 |
} |
|
690 |
||
691 |
- (void)mouseEntered:(NSEvent *)event |
|
692 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
693 |
if (!qwidget) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
694 |
return; |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
695 |
if (qwidgetprivate->data.in_destructor) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
696 |
return; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
697 |
|
0 | 698 |
if (!qAppInstance()->activeModalWidget() || QApplicationPrivate::tryModalHelper(qwidget, 0)) { |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
699 |
QEvent enterEvent(QEvent::Enter); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
700 |
NSPoint windowPoint = [event locationInWindow]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
701 |
NSPoint globalPoint = [[event window] convertBaseToScreen:windowPoint]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
702 |
NSPoint viewPoint = [self convertPoint:windowPoint fromView:nil]; |
0 | 703 |
QApplication::sendEvent(qwidget, &enterEvent); |
704 |
qt_mouseover = qwidget; |
|
705 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
706 |
// Update cursor icon: |
0 | 707 |
qt_mac_update_cursor_at_global_pos(flipPoint(globalPoint).toPoint()); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
708 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
709 |
// Send mouse move and hover events as well: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
710 |
if (!qAppInstance()->activePopupWidget() || qAppInstance()->activePopupWidget() == qwidget->window()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
711 |
// This mouse move event should be sendt, even when mouse |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
712 |
// tracking is switched off (to trigger tooltips): |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
713 |
NSEvent *mouseEvent = [NSEvent mouseEventWithType:NSMouseMoved |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
714 |
location:windowPoint modifierFlags:[event modifierFlags] timestamp:[event timestamp] |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
715 |
windowNumber:[event windowNumber] context:[event context] eventNumber:[event eventNumber] |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
716 |
clickCount:0 pressure:0]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
717 |
qt_mac_handleMouseEvent(self, mouseEvent, QEvent::MouseMove, Qt::NoButton); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
718 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
719 |
if (qwidget->testAttribute(Qt::WA_Hover)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
720 |
QHoverEvent he(QEvent::HoverEnter, QPoint(viewPoint.x, viewPoint.y), QPoint(-1, -1)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
721 |
QApplicationPrivate::instance()->notify_helper(qwidget, &he); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
722 |
} |
0 | 723 |
} |
724 |
} |
|
725 |
} |
|
726 |
||
727 |
- (void)mouseExited:(NSEvent *)event |
|
728 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
729 |
if (!qwidget) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
730 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
731 |
|
0 | 732 |
QEvent leaveEvent(QEvent::Leave); |
733 |
NSPoint globalPoint = [[event window] convertBaseToScreen:[event locationInWindow]]; |
|
734 |
if (!qAppInstance()->activeModalWidget() || QApplicationPrivate::tryModalHelper(qwidget, 0)) { |
|
735 |
QApplication::sendEvent(qwidget, &leaveEvent); |
|
736 |
||
737 |
// ### Think about if it is necessary to update the cursor, should only be for a few cases. |
|
738 |
qt_mac_update_cursor_at_global_pos(flipPoint(globalPoint).toPoint()); |
|
739 |
if (qwidget->testAttribute(Qt::WA_Hover) |
|
740 |
&& (!qAppInstance()->activePopupWidget() || qAppInstance()->activePopupWidget() == qwidget->window())) { |
|
741 |
QHoverEvent he(QEvent::HoverLeave, QPoint(-1, -1), |
|
742 |
qwidget->mapFromGlobal(QApplicationPrivate::instance()->hoverGlobalPos)); |
|
743 |
QApplicationPrivate::instance()->notify_helper(qwidget, &he); |
|
744 |
} |
|
745 |
} |
|
746 |
} |
|
747 |
||
748 |
- (void)flagsChanged:(NSEvent *)theEvent |
|
749 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
750 |
if (!qwidget) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
751 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
752 |
|
0 | 753 |
QWidget *widgetToGetKey = qwidget; |
754 |
||
755 |
QWidget *popup = qAppInstance()->activePopupWidget(); |
|
756 |
if (popup && popup != qwidget->window()) |
|
757 |
widgetToGetKey = popup->focusWidget() ? popup->focusWidget() : popup; |
|
758 |
qt_dispatchModifiersChanged(theEvent, widgetToGetKey); |
|
759 |
[super flagsChanged:theEvent]; |
|
760 |
} |
|
761 |
||
762 |
- (void)mouseMoved:(NSEvent *)theEvent |
|
763 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
764 |
if (!qwidget) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
765 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
766 |
|
0 | 767 |
// We always enable mouse tracking for all QCocoaView-s. In cases where we have |
768 |
// child views, we will receive mouseMoved for both parent & the child (if |
|
769 |
// mouse is over the child). We need to ignore the parent mouseMoved in such |
|
770 |
// cases. |
|
771 |
NSPoint windowPoint = [theEvent locationInWindow]; |
|
772 |
NSView *candidateView = [[[self window] contentView] hitTest:windowPoint]; |
|
773 |
if (candidateView && candidateView == self) { |
|
774 |
qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseMove, Qt::NoButton); |
|
775 |
} |
|
776 |
} |
|
777 |
||
778 |
- (void)mouseDown:(NSEvent *)theEvent |
|
779 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
780 |
if (!qt_button_down) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
781 |
qt_button_down = qwidget; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
782 |
|
0 | 783 |
qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonPress, Qt::LeftButton); |
784 |
// Don't call super here. This prevents us from getting the mouseUp event, |
|
785 |
// which we need to send even if the mouseDown event was not accepted. |
|
786 |
// (this is standard Qt behavior.) |
|
787 |
} |
|
788 |
||
789 |
||
790 |
- (void)mouseUp:(NSEvent *)theEvent |
|
791 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
792 |
qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonRelease, Qt::LeftButton); |
0 | 793 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
794 |
qt_button_down = 0; |
0 | 795 |
} |
796 |
||
797 |
- (void)rightMouseDown:(NSEvent *)theEvent |
|
798 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
799 |
if (!qt_button_down) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
800 |
qt_button_down = qwidget; |
0 | 801 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
802 |
qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonPress, Qt::RightButton); |
0 | 803 |
} |
804 |
||
805 |
- (void)rightMouseUp:(NSEvent *)theEvent |
|
806 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
807 |
qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonRelease, Qt::RightButton); |
0 | 808 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
809 |
qt_button_down = 0; |
0 | 810 |
} |
811 |
||
812 |
- (void)otherMouseDown:(NSEvent *)theEvent |
|
813 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
814 |
if (!qt_button_down) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
815 |
qt_button_down = qwidget; |
0 | 816 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
817 |
Qt::MouseButton mouseButton = cocoaButton2QtButton([theEvent buttonNumber]); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
818 |
qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonPress, mouseButton); |
0 | 819 |
} |
820 |
||
821 |
- (void)otherMouseUp:(NSEvent *)theEvent |
|
822 |
{ |
|
823 |
Qt::MouseButton mouseButton = cocoaButton2QtButton([theEvent buttonNumber]); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
824 |
qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseButtonRelease, mouseButton); |
0 | 825 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
826 |
qt_button_down = 0; |
0 | 827 |
} |
828 |
||
829 |
- (void)mouseDragged:(NSEvent *)theEvent |
|
830 |
{ |
|
831 |
qMacDnDParams()->view = self; |
|
832 |
qMacDnDParams()->theEvent = theEvent; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
833 |
qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseMove, Qt::NoButton); |
0 | 834 |
} |
835 |
||
836 |
- (void)rightMouseDragged:(NSEvent *)theEvent |
|
837 |
{ |
|
838 |
qMacDnDParams()->view = self; |
|
839 |
qMacDnDParams()->theEvent = theEvent; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
840 |
qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseMove, Qt::NoButton); |
0 | 841 |
} |
842 |
||
843 |
- (void)otherMouseDragged:(NSEvent *)theEvent |
|
844 |
{ |
|
845 |
qMacDnDParams()->view = self; |
|
846 |
qMacDnDParams()->theEvent = theEvent; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
847 |
qt_mac_handleMouseEvent(self, theEvent, QEvent::MouseMove, Qt::NoButton); |
0 | 848 |
} |
849 |
||
850 |
- (void)scrollWheel:(NSEvent *)theEvent |
|
851 |
{ |
|
852 |
// Give the Input Manager a chance to process the wheel event. |
|
853 |
NSInputManager *currentIManager = [NSInputManager currentInputManager]; |
|
854 |
if (currentIManager && [currentIManager wantsToHandleMouseEvents]) { |
|
855 |
[currentIManager handleMouseEvent:theEvent]; |
|
856 |
} |
|
857 |
||
858 |
NSPoint windowPoint = [theEvent locationInWindow]; |
|
859 |
NSPoint globalPoint = [[theEvent window] convertBaseToScreen:windowPoint]; |
|
860 |
NSPoint localPoint = [self convertPoint:windowPoint fromView:nil]; |
|
861 |
QPoint qlocal = QPoint(localPoint.x, localPoint.y); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
862 |
QPoint qglobal = QPoint(globalPoint.x, flipYCoordinate(globalPoint.y)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
863 |
Qt::MouseButtons buttons = QApplication::mouseButtons(); |
0 | 864 |
bool wheelOK = false; |
865 |
Qt::KeyboardModifiers keyMods = qt_cocoaModifiers2QtModifiers([theEvent modifierFlags]); |
|
866 |
QWidget *widgetToGetMouse = qwidget; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
867 |
// if popup is open it should get wheel events if the cursor is over the popup, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
868 |
// otherwise the event should be ignored. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
869 |
if (QWidget *popup = qAppInstance()->activePopupWidget()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
870 |
if (!popup->geometry().contains(qglobal)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
871 |
return; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
872 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
873 |
|
0 | 874 |
int deltaX = 0; |
875 |
int deltaY = 0; |
|
876 |
int deltaZ = 0; |
|
877 |
||
878 |
const EventRef carbonEvent = (EventRef)[theEvent eventRef]; |
|
879 |
const UInt32 carbonEventKind = carbonEvent ? ::GetEventKind(carbonEvent) : 0; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
880 |
const bool scrollEvent = carbonEventKind == kEventMouseScroll; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
881 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
882 |
if (scrollEvent) { |
0 | 883 |
// The mouse device containts pixel scroll wheel support (Mighty Mouse, Trackpad). |
884 |
// Since deviceDelta is delivered as pixels rather than degrees, we need to |
|
885 |
// convert from pixels to degrees in a sensible manner. |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
886 |
// It looks like 1/4 degrees per pixel behaves most native. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
887 |
// (NB: Qt expects the unit for delta to be 8 per degree): |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
888 |
const int pixelsToDegrees = 2; // 8 * 1/4 |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
889 |
deltaX = [theEvent deviceDeltaX] * pixelsToDegrees; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
890 |
deltaY = [theEvent deviceDeltaY] * pixelsToDegrees; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
891 |
deltaZ = [theEvent deviceDeltaZ] * pixelsToDegrees; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
892 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
893 |
// carbonEventKind == kEventMouseWheelMoved |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
894 |
// Remove acceleration, and use either -120 or 120 as delta: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
895 |
deltaX = qBound(-120, int([theEvent deltaX] * 10000), 120); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
896 |
deltaY = qBound(-120, int([theEvent deltaY] * 10000), 120); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
897 |
deltaZ = qBound(-120, int([theEvent deltaZ] * 10000), 120); |
0 | 898 |
} |
899 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
900 |
#ifndef QT_NO_WHEELEVENT |
0 | 901 |
if (deltaX != 0) { |
902 |
QWheelEvent qwe(qlocal, qglobal, deltaX, buttons, keyMods, Qt::Horizontal); |
|
903 |
qt_sendSpontaneousEvent(widgetToGetMouse, &qwe); |
|
904 |
wheelOK = qwe.isAccepted(); |
|
905 |
if (!wheelOK && QApplicationPrivate::focus_widget |
|
906 |
&& QApplicationPrivate::focus_widget != widgetToGetMouse) { |
|
907 |
QWheelEvent qwe2(QApplicationPrivate::focus_widget->mapFromGlobal(qglobal), qglobal, |
|
908 |
deltaX, buttons, keyMods, Qt::Horizontal); |
|
909 |
qt_sendSpontaneousEvent(QApplicationPrivate::focus_widget, &qwe2); |
|
910 |
wheelOK = qwe2.isAccepted(); |
|
911 |
} |
|
912 |
} |
|
913 |
||
914 |
if (deltaY) { |
|
915 |
QWheelEvent qwe(qlocal, qglobal, deltaY, buttons, keyMods, Qt::Vertical); |
|
916 |
qt_sendSpontaneousEvent(widgetToGetMouse, &qwe); |
|
917 |
wheelOK = qwe.isAccepted(); |
|
918 |
if (!wheelOK && QApplicationPrivate::focus_widget |
|
919 |
&& QApplicationPrivate::focus_widget != widgetToGetMouse) { |
|
920 |
QWheelEvent qwe2(QApplicationPrivate::focus_widget->mapFromGlobal(qglobal), qglobal, |
|
921 |
deltaY, buttons, keyMods, Qt::Vertical); |
|
922 |
qt_sendSpontaneousEvent(QApplicationPrivate::focus_widget, &qwe2); |
|
923 |
wheelOK = qwe2.isAccepted(); |
|
924 |
} |
|
925 |
} |
|
926 |
||
927 |
if (deltaZ) { |
|
928 |
// Qt doesn't explicitly support wheels with a Z component. In a misguided attempt to |
|
929 |
// try to be ahead of the pack, I'm adding this extra value. |
|
930 |
QWheelEvent qwe(qlocal, qglobal, deltaZ, buttons, keyMods, (Qt::Orientation)3); |
|
931 |
qt_sendSpontaneousEvent(widgetToGetMouse, &qwe); |
|
932 |
wheelOK = qwe.isAccepted(); |
|
933 |
if (!wheelOK && QApplicationPrivate::focus_widget |
|
934 |
&& QApplicationPrivate::focus_widget != widgetToGetMouse) { |
|
935 |
QWheelEvent qwe2(QApplicationPrivate::focus_widget->mapFromGlobal(qglobal), qglobal, |
|
936 |
deltaZ, buttons, keyMods, (Qt::Orientation)3); |
|
937 |
qt_sendSpontaneousEvent(QApplicationPrivate::focus_widget, &qwe2); |
|
938 |
wheelOK = qwe2.isAccepted(); |
|
939 |
} |
|
940 |
} |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
941 |
#endif //QT_NO_WHEELEVENT |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
942 |
|
0 | 943 |
if (!wheelOK) { |
944 |
return [super scrollWheel:theEvent]; |
|
945 |
} |
|
946 |
} |
|
947 |
||
948 |
- (void)tabletProximity:(NSEvent *)tabletEvent |
|
949 |
{ |
|
950 |
qt_dispatchTabletProximityEvent(tabletEvent); |
|
951 |
} |
|
952 |
||
953 |
- (void)tabletPoint:(NSEvent *)tabletEvent |
|
954 |
{ |
|
955 |
if (!qt_mac_handleTabletEvent(self, tabletEvent)) |
|
956 |
[super tabletPoint:tabletEvent]; |
|
957 |
} |
|
958 |
||
959 |
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 |
|
960 |
- (void)touchesBeganWithEvent:(NSEvent *)event; |
|
961 |
{ |
|
962 |
bool all = qwidget->testAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents); |
|
963 |
qt_translateRawTouchEvent(qwidget, QTouchEvent::TouchPad, QCocoaTouch::getCurrentTouchPointList(event, all)); |
|
964 |
} |
|
965 |
||
966 |
- (void)touchesMovedWithEvent:(NSEvent *)event; |
|
967 |
{ |
|
968 |
bool all = qwidget->testAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents); |
|
969 |
qt_translateRawTouchEvent(qwidget, QTouchEvent::TouchPad, QCocoaTouch::getCurrentTouchPointList(event, all)); |
|
970 |
} |
|
971 |
||
972 |
- (void)touchesEndedWithEvent:(NSEvent *)event; |
|
973 |
{ |
|
974 |
bool all = qwidget->testAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents); |
|
975 |
qt_translateRawTouchEvent(qwidget, QTouchEvent::TouchPad, QCocoaTouch::getCurrentTouchPointList(event, all)); |
|
976 |
} |
|
977 |
||
978 |
- (void)touchesCancelledWithEvent:(NSEvent *)event; |
|
979 |
{ |
|
980 |
bool all = qwidget->testAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents); |
|
981 |
qt_translateRawTouchEvent(qwidget, QTouchEvent::TouchPad, QCocoaTouch::getCurrentTouchPointList(event, all)); |
|
982 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
983 |
#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 |
0 | 984 |
|
985 |
- (void)magnifyWithEvent:(NSEvent *)event; |
|
986 |
{ |
|
987 |
if (!QApplicationPrivate::tryModalHelper(qwidget, 0)) |
|
988 |
return; |
|
989 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
990 |
#ifndef QT_NO_GESTURES |
0 | 991 |
QNativeGestureEvent qNGEvent; |
992 |
qNGEvent.gestureType = QNativeGestureEvent::Zoom; |
|
993 |
NSPoint p = [[event window] convertBaseToScreen:[event locationInWindow]]; |
|
994 |
qNGEvent.position = flipPoint(p).toPoint(); |
|
995 |
qNGEvent.percentage = [event magnification]; |
|
996 |
qt_sendSpontaneousEvent(qwidget, &qNGEvent); |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
997 |
#endif // QT_NO_GESTURES |
0 | 998 |
} |
999 |
||
1000 |
- (void)rotateWithEvent:(NSEvent *)event; |
|
1001 |
{ |
|
1002 |
if (!QApplicationPrivate::tryModalHelper(qwidget, 0)) |
|
1003 |
return; |
|
1004 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1005 |
#ifndef QT_NO_GESTURES |
0 | 1006 |
QNativeGestureEvent qNGEvent; |
1007 |
qNGEvent.gestureType = QNativeGestureEvent::Rotate; |
|
1008 |
NSPoint p = [[event window] convertBaseToScreen:[event locationInWindow]]; |
|
1009 |
qNGEvent.position = flipPoint(p).toPoint(); |
|
1010 |
qNGEvent.percentage = -[event rotation]; |
|
1011 |
qt_sendSpontaneousEvent(qwidget, &qNGEvent); |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1012 |
#endif // QT_NO_GESTURES |
0 | 1013 |
} |
1014 |
||
1015 |
- (void)swipeWithEvent:(NSEvent *)event; |
|
1016 |
{ |
|
1017 |
if (!QApplicationPrivate::tryModalHelper(qwidget, 0)) |
|
1018 |
return; |
|
1019 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1020 |
#ifndef QT_NO_GESTURES |
0 | 1021 |
QNativeGestureEvent qNGEvent; |
1022 |
qNGEvent.gestureType = QNativeGestureEvent::Swipe; |
|
1023 |
NSPoint p = [[event window] convertBaseToScreen:[event locationInWindow]]; |
|
1024 |
qNGEvent.position = flipPoint(p).toPoint(); |
|
1025 |
if ([event deltaX] == 1) |
|
1026 |
qNGEvent.angle = 180.0f; |
|
1027 |
else if ([event deltaX] == -1) |
|
1028 |
qNGEvent.angle = 0.0f; |
|
1029 |
else if ([event deltaY] == 1) |
|
1030 |
qNGEvent.angle = 90.0f; |
|
1031 |
else if ([event deltaY] == -1) |
|
1032 |
qNGEvent.angle = 270.0f; |
|
1033 |
qt_sendSpontaneousEvent(qwidget, &qNGEvent); |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1034 |
#endif // QT_NO_GESTURES |
0 | 1035 |
} |
1036 |
||
1037 |
- (void)beginGestureWithEvent:(NSEvent *)event; |
|
1038 |
{ |
|
1039 |
if (!QApplicationPrivate::tryModalHelper(qwidget, 0)) |
|
1040 |
return; |
|
1041 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1042 |
#ifndef QT_NO_GESTURES |
0 | 1043 |
QNativeGestureEvent qNGEvent; |
1044 |
qNGEvent.gestureType = QNativeGestureEvent::GestureBegin; |
|
1045 |
NSPoint p = [[event window] convertBaseToScreen:[event locationInWindow]]; |
|
1046 |
qNGEvent.position = flipPoint(p).toPoint(); |
|
1047 |
qt_sendSpontaneousEvent(qwidget, &qNGEvent); |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1048 |
#endif // QT_NO_GESTURES |
0 | 1049 |
} |
1050 |
||
1051 |
- (void)endGestureWithEvent:(NSEvent *)event; |
|
1052 |
{ |
|
1053 |
if (!QApplicationPrivate::tryModalHelper(qwidget, 0)) |
|
1054 |
return; |
|
1055 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1056 |
#ifndef QT_NO_GESTURES |
0 | 1057 |
QNativeGestureEvent qNGEvent; |
1058 |
qNGEvent.gestureType = QNativeGestureEvent::GestureEnd; |
|
1059 |
NSPoint p = [[event window] convertBaseToScreen:[event locationInWindow]]; |
|
1060 |
qNGEvent.position = flipPoint(p).toPoint(); |
|
1061 |
qt_sendSpontaneousEvent(qwidget, &qNGEvent); |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1062 |
#endif // QT_NO_GESTURES |
0 | 1063 |
} |
1064 |
||
1065 |
- (void)frameDidChange:(NSNotification *)note |
|
1066 |
{ |
|
1067 |
Q_UNUSED(note); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1068 |
if (!qwidget) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1069 |
return; |
0 | 1070 |
if (qwidget->isWindow()) |
1071 |
return; |
|
1072 |
NSRect newFrame = [self frame]; |
|
1073 |
QRect newGeo(newFrame.origin.x, newFrame.origin.y, newFrame.size.width, newFrame.size.height); |
|
1074 |
bool moved = qwidget->testAttribute(Qt::WA_Moved); |
|
1075 |
bool resized = qwidget->testAttribute(Qt::WA_Resized); |
|
1076 |
qwidget->setGeometry(newGeo); |
|
1077 |
qwidget->setAttribute(Qt::WA_Moved, moved); |
|
1078 |
qwidget->setAttribute(Qt::WA_Resized, resized); |
|
1079 |
qwidgetprivate->syncCocoaMask(); |
|
1080 |
} |
|
1081 |
||
1082 |
- (BOOL)isEnabled |
|
1083 |
{ |
|
1084 |
if (!qwidget) |
|
1085 |
return [super isEnabled]; |
|
1086 |
return [super isEnabled] && qwidget->isEnabled(); |
|
1087 |
} |
|
1088 |
||
1089 |
- (void)setEnabled:(BOOL)flag |
|
1090 |
{ |
|
1091 |
QMacCocoaAutoReleasePool pool; |
|
1092 |
[super setEnabled:flag]; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1093 |
if (qwidget && qwidget->isEnabled() != flag) |
0 | 1094 |
qwidget->setEnabled(flag); |
1095 |
} |
|
1096 |
||
1097 |
+ (Class)cellClass |
|
1098 |
{ |
|
1099 |
return [NSActionCell class]; |
|
1100 |
} |
|
1101 |
||
1102 |
- (BOOL)acceptsFirstResponder |
|
1103 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1104 |
if (!qwidget) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1105 |
return NO; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1106 |
// disabled widget shouldn't get focus even if it's a window. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1107 |
// hence disabled windows will not get any key or mouse events. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1108 |
if (!qwidget->isEnabled()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1109 |
return NO; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1110 |
// Before accepting the focus for a window, we check that |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1111 |
// the focusWidget (if any) is not contained in the same window. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1112 |
if (qwidget->isWindow() && !qt_widget_private(qwidget)->topData()->embedded |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1113 |
&& (!qApp->focusWidget() || qApp->focusWidget()->window() != qwidget)) { |
0 | 1114 |
return YES; // Always do it, so that windows can accept key press events. |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1115 |
} |
0 | 1116 |
return qwidget->focusPolicy() != Qt::NoFocus; |
1117 |
} |
|
1118 |
||
1119 |
- (BOOL)resignFirstResponder |
|
1120 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1121 |
if (!qwidget) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1122 |
return NO; |
0 | 1123 |
// Seems like the following test only triggers if this |
1124 |
// view is inside a QMacNativeWidget: |
|
1125 |
if (qwidget == QApplication::focusWidget()) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1126 |
qwidget->clearFocus(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1127 |
return YES; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1128 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1129 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1130 |
- (BOOL)becomeFirstResponder |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1131 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1132 |
// see the comment in the acceptsFirstResponder - if the window "stole" focus |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1133 |
// let it become the responder, but don't tell Qt |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1134 |
if (qwidget && qt_widget_private(qwidget->window())->topData()->embedded |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1135 |
&& !QApplication::focusWidget() && qwidget->focusPolicy() != Qt::NoFocus) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1136 |
qwidget->setFocus(Qt::OtherFocusReason); |
0 | 1137 |
return YES; |
1138 |
} |
|
1139 |
||
1140 |
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal |
|
1141 |
{ |
|
1142 |
Q_UNUSED(isLocal); |
|
1143 |
return supportedActions; |
|
1144 |
} |
|
1145 |
||
1146 |
- (void)setSupportedActions:(NSDragOperation)actions |
|
1147 |
{ |
|
1148 |
supportedActions = actions; |
|
1149 |
} |
|
1150 |
||
1151 |
- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation |
|
1152 |
{ |
|
1153 |
Q_UNUSED(anImage); |
|
1154 |
Q_UNUSED(aPoint); |
|
1155 |
qMacDnDParams()->performedAction = operation; |
|
1156 |
if (QDragManager::self()->object |
|
1157 |
&& QDragManager::self()->dragPrivate()->executed_action != Qt::ActionMask) { |
|
1158 |
qMacDnDParams()->performedAction = |
|
1159 |
qt_mac_mapDropAction(QDragManager::self()->dragPrivate()->executed_action); |
|
1160 |
} |
|
1161 |
} |
|
1162 |
||
1163 |
- (QWidget *)qt_qwidget |
|
1164 |
{ |
|
1165 |
return qwidget; |
|
1166 |
} |
|
1167 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1168 |
- (void) qt_clearQWidget |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1169 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1170 |
qwidget = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1171 |
qwidgetprivate = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1172 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1173 |
|
0 | 1174 |
- (BOOL)qt_leftButtonIsRightButton |
1175 |
{ |
|
1176 |
return leftButtonIsRightButton; |
|
1177 |
} |
|
1178 |
||
1179 |
- (void)qt_setLeftButtonIsRightButton:(BOOL)isSwapped |
|
1180 |
{ |
|
1181 |
leftButtonIsRightButton = isSwapped; |
|
1182 |
} |
|
1183 |
||
1184 |
+ (DnDParams*)currentMouseEvent |
|
1185 |
{ |
|
1186 |
return qMacDnDParams(); |
|
1187 |
} |
|
1188 |
||
1189 |
- (void)keyDown:(NSEvent *)theEvent |
|
1190 |
{ |
|
1191 |
sendKeyEvents = true; |
|
1192 |
||
1193 |
QWidget *widgetToGetKey = qwidget; |
|
1194 |
||
1195 |
QWidget *popup = qAppInstance()->activePopupWidget(); |
|
1196 |
bool sendToPopup = false; |
|
1197 |
if (popup && popup != qwidget->window()) { |
|
1198 |
widgetToGetKey = popup->focusWidget() ? popup->focusWidget() : popup; |
|
1199 |
sendToPopup = true; |
|
1200 |
} |
|
1201 |
||
1202 |
if (widgetToGetKey->testAttribute(Qt::WA_InputMethodEnabled) |
|
1203 |
&& !(widgetToGetKey->inputMethodHints() & Qt::ImhDigitsOnly |
|
1204 |
|| widgetToGetKey->inputMethodHints() & Qt::ImhFormattedNumbersOnly |
|
1205 |
|| widgetToGetKey->inputMethodHints() & Qt::ImhHiddenText)) { |
|
1206 |
[qt_mac_nativeview_for(widgetToGetKey) interpretKeyEvents:[NSArray arrayWithObject: theEvent]]; |
|
1207 |
} |
|
1208 |
if (sendKeyEvents && !composing) { |
|
1209 |
bool keyOK = qt_dispatchKeyEvent(theEvent, widgetToGetKey); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1210 |
if (!keyOK && !sendToPopup) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1211 |
// find the first responder that is not created by Qt and forward |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1212 |
// the event to it (for example if Qt widget is embedded into native). |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1213 |
QWidget *toplevel = qwidget->window(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1214 |
if (toplevel && qt_widget_private(toplevel)->topData()->embedded) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1215 |
if (NSResponder *w = [qt_mac_nativeview_for(toplevel) superview]) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1216 |
[w keyDown:theEvent]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1217 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1218 |
} |
0 | 1219 |
} |
1220 |
} |
|
1221 |
||
1222 |
||
1223 |
- (void)keyUp:(NSEvent *)theEvent |
|
1224 |
{ |
|
1225 |
if (sendKeyEvents) { |
|
1226 |
bool keyOK = qt_dispatchKeyEvent(theEvent, qwidget); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1227 |
if (!keyOK) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1228 |
QWidget *toplevel = qwidget->window(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1229 |
if (toplevel && qt_widget_private(toplevel)->topData()->embedded) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1230 |
if (NSResponder *w = [qt_mac_nativeview_for(toplevel) superview]) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1231 |
[w keyUp:theEvent]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1232 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1233 |
} |
0 | 1234 |
} |
1235 |
} |
|
1236 |
||
1237 |
- (void)viewWillMoveToWindow:(NSWindow *)window |
|
1238 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1239 |
if (qwidget == 0) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1240 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1241 |
|
0 | 1242 |
if (qwidget->windowFlags() & Qt::MSWindowsOwnDC |
1243 |
&& (window != [self window])) { // OpenGL Widget |
|
1244 |
QEvent event(QEvent::MacGLClearDrawable); |
|
1245 |
qApp->sendEvent(qwidget, &event); |
|
1246 |
} |
|
1247 |
} |
|
1248 |
||
1249 |
- (void)viewDidMoveToWindow |
|
1250 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1251 |
if (qwidget == 0) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1252 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1253 |
|
0 | 1254 |
if (qwidget->windowFlags() & Qt::MSWindowsOwnDC && [self window]) { |
1255 |
// call update paint event |
|
1256 |
qwidgetprivate->needWindowChange = true; |
|
1257 |
QEvent event(QEvent::MacGLWindowChange); |
|
1258 |
qApp->sendEvent(qwidget, &event); |
|
1259 |
} |
|
1260 |
} |
|
1261 |
||
1262 |
||
1263 |
// NSTextInput Protocol implementation |
|
1264 |
||
1265 |
- (void) insertText:(id)aString |
|
1266 |
{ |
|
1267 |
QString commitText; |
|
1268 |
if ([aString length]) { |
|
1269 |
if ([aString isKindOfClass:[NSAttributedString class]]) { |
|
1270 |
commitText = QCFString::toQString(reinterpret_cast<CFStringRef>([aString string])); |
|
1271 |
} else { |
|
1272 |
commitText = QCFString::toQString(reinterpret_cast<CFStringRef>(aString)); |
|
1273 |
}; |
|
1274 |
} |
|
1275 |
||
1276 |
if ([aString length] && composing) { |
|
1277 |
// Send the commit string to the widget. |
|
1278 |
composing = false; |
|
1279 |
sendKeyEvents = false; |
|
1280 |
QInputMethodEvent e; |
|
1281 |
e.setCommitString(commitText); |
|
1282 |
qt_sendSpontaneousEvent(qwidget, &e); |
|
1283 |
} else { |
|
1284 |
// The key sequence "`q" on a French Keyboard will generate two calls to insertText before |
|
1285 |
// it returns from interpretKeyEvents. The first call will turn off 'composing' and accept |
|
1286 |
// the "`" key. The last keyDown event needs to be processed by the widget to get the |
|
1287 |
// character "q". The string parameter is ignored for the second call. |
|
1288 |
sendKeyEvents = true; |
|
1289 |
} |
|
1290 |
||
1291 |
composingText->clear(); |
|
1292 |
} |
|
1293 |
||
1294 |
- (void) setMarkedText:(id)aString selectedRange:(NSRange)selRange |
|
1295 |
{ |
|
1296 |
// Generate the QInputMethodEvent with preedit string and the attributes |
|
1297 |
// for rendering it. The attributes handled here are 'underline', |
|
1298 |
// 'underline color' and 'cursor position'. |
|
1299 |
sendKeyEvents = false; |
|
1300 |
composing = true; |
|
1301 |
QString qtText; |
|
1302 |
// Cursor position is retrived from the range. |
|
1303 |
QList<QInputMethodEvent::Attribute> attrs; |
|
1304 |
attrs<<QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, selRange.location, 1, QVariant()); |
|
1305 |
if ([aString isKindOfClass:[NSAttributedString class]]) { |
|
1306 |
qtText = QCFString::toQString(reinterpret_cast<CFStringRef>([aString string])); |
|
1307 |
composingLength = qtText.length(); |
|
1308 |
int index = 0; |
|
1309 |
// Create attributes for individual sections of preedit text |
|
1310 |
while (index < composingLength) { |
|
1311 |
NSRange effectiveRange; |
|
1312 |
NSRange range = NSMakeRange(index, composingLength-index); |
|
1313 |
NSDictionary *attributes = [aString attributesAtIndex:index |
|
1314 |
longestEffectiveRange:&effectiveRange |
|
1315 |
inRange:range]; |
|
1316 |
NSNumber *underlineStyle = [attributes objectForKey:NSUnderlineStyleAttributeName]; |
|
1317 |
if (underlineStyle) { |
|
1318 |
QColor clr (Qt::black); |
|
1319 |
NSColor *color = [attributes objectForKey:NSUnderlineColorAttributeName]; |
|
1320 |
if (color) { |
|
1321 |
clr = colorFrom(color); |
|
1322 |
} |
|
1323 |
QTextCharFormat format; |
|
1324 |
format.setFontUnderline(true); |
|
1325 |
format.setUnderlineColor(clr); |
|
1326 |
attrs<<QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, |
|
1327 |
effectiveRange.location, |
|
1328 |
effectiveRange.length, |
|
1329 |
format); |
|
1330 |
} |
|
1331 |
index = effectiveRange.location + effectiveRange.length; |
|
1332 |
} |
|
1333 |
} else { |
|
1334 |
// No attributes specified, take only the preedit text. |
|
1335 |
qtText = QCFString::toQString(reinterpret_cast<CFStringRef>(aString)); |
|
1336 |
composingLength = qtText.length(); |
|
1337 |
} |
|
1338 |
// Make sure that we have at least one text format. |
|
1339 |
if (attrs.size() <= 1) { |
|
1340 |
QTextCharFormat format; |
|
1341 |
format.setFontUnderline(true); |
|
1342 |
attrs<<QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, |
|
1343 |
0, composingLength, format); |
|
1344 |
} |
|
1345 |
*composingText = qtText; |
|
1346 |
QInputMethodEvent e(qtText, attrs); |
|
1347 |
qt_sendSpontaneousEvent(qwidget, &e); |
|
1348 |
if (!composingLength) |
|
1349 |
composing = false; |
|
1350 |
} |
|
1351 |
||
1352 |
- (void) unmarkText |
|
1353 |
{ |
|
1354 |
if (composing) { |
|
1355 |
QInputMethodEvent e; |
|
1356 |
e.setCommitString(*composingText); |
|
1357 |
qt_sendSpontaneousEvent(qwidget, &e); |
|
1358 |
} |
|
1359 |
composingText->clear(); |
|
1360 |
composing = false; |
|
1361 |
} |
|
1362 |
||
1363 |
- (BOOL) hasMarkedText |
|
1364 |
{ |
|
1365 |
return (composing ? YES: NO); |
|
1366 |
} |
|
1367 |
||
1368 |
- (void) doCommandBySelector:(SEL)aSelector |
|
1369 |
{ |
|
1370 |
Q_UNUSED(aSelector); |
|
1371 |
} |
|
1372 |
||
1373 |
- (BOOL)isComposing |
|
1374 |
{ |
|
1375 |
return composing; |
|
1376 |
} |
|
1377 |
||
1378 |
- (NSInteger) conversationIdentifier |
|
1379 |
{ |
|
1380 |
// Return a unique identifier fot this ime conversation |
|
1381 |
return (NSInteger)self; |
|
1382 |
} |
|
1383 |
||
1384 |
- (NSAttributedString *) attributedSubstringFromRange:(NSRange)theRange |
|
1385 |
{ |
|
1386 |
QString selectedText(qwidget->inputMethodQuery(Qt::ImCurrentSelection).toString()); |
|
1387 |
if (!selectedText.isEmpty()) { |
|
1388 |
QCFString string(selectedText.mid(theRange.location, theRange.length)); |
|
1389 |
const NSString *tmpString = reinterpret_cast<const NSString *>((CFStringRef)string); |
|
1390 |
return [[[NSAttributedString alloc] initWithString:tmpString] autorelease]; |
|
1391 |
} else { |
|
1392 |
return nil; |
|
1393 |
} |
|
1394 |
} |
|
1395 |
||
1396 |
- (NSRange) markedRange |
|
1397 |
{ |
|
1398 |
NSRange range; |
|
1399 |
if (composing) { |
|
1400 |
range.location = 0; |
|
1401 |
range.length = composingLength; |
|
1402 |
} else { |
|
1403 |
range.location = NSNotFound; |
|
1404 |
range.length = 0; |
|
1405 |
} |
|
1406 |
return range; |
|
1407 |
} |
|
1408 |
||
1409 |
- (NSRange) selectedRange |
|
1410 |
{ |
|
1411 |
NSRange selRange; |
|
1412 |
QString selectedText(qwidget->inputMethodQuery(Qt::ImCurrentSelection).toString()); |
|
1413 |
if (!selectedText.isEmpty()) { |
|
1414 |
// Consider only the selected text. |
|
1415 |
selRange.location = 0; |
|
1416 |
selRange.length = selectedText.length(); |
|
1417 |
} else { |
|
1418 |
// No selected text. |
|
1419 |
selRange.location = NSNotFound; |
|
1420 |
selRange.length = 0; |
|
1421 |
} |
|
1422 |
return selRange; |
|
1423 |
||
1424 |
} |
|
1425 |
||
1426 |
- (NSRect) firstRectForCharacterRange:(NSRange)theRange |
|
1427 |
{ |
|
1428 |
Q_UNUSED(theRange); |
|
1429 |
// The returned rect is always based on the internal cursor. |
|
1430 |
QRect mr(qwidget->inputMethodQuery(Qt::ImMicroFocus).toRect()); |
|
1431 |
QPoint mp(qwidget->mapToGlobal(QPoint(mr.bottomLeft()))); |
|
1432 |
NSRect rect ; |
|
1433 |
rect.origin.x = mp.x(); |
|
1434 |
rect.origin.y = flipYCoordinate(mp.y()); |
|
1435 |
rect.size.width = mr.width(); |
|
1436 |
rect.size.height = mr.height(); |
|
1437 |
return rect; |
|
1438 |
} |
|
1439 |
||
1440 |
- (NSUInteger)characterIndexForPoint:(NSPoint)thePoint |
|
1441 |
{ |
|
1442 |
// We dont support cursor movements using mouse while composing. |
|
1443 |
Q_UNUSED(thePoint); |
|
1444 |
return NSNotFound; |
|
1445 |
} |
|
1446 |
||
1447 |
- (NSArray*) validAttributesForMarkedText |
|
1448 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1449 |
if (qwidget == 0) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1450 |
return nil; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1451 |
|
0 | 1452 |
if (!qwidget->testAttribute(Qt::WA_InputMethodEnabled)) |
1453 |
return nil; // Not sure if that's correct, but it's saves a malloc. |
|
1454 |
||
1455 |
// Support only underline color/style. |
|
1456 |
return [NSArray arrayWithObjects:NSUnderlineColorAttributeName, |
|
1457 |
NSUnderlineStyleAttributeName, nil]; |
|
1458 |
} |
|
1459 |
@end |
|
1460 |
||
1461 |
QT_BEGIN_NAMESPACE |
|
1462 |
void QMacInputContext::reset() |
|
1463 |
{ |
|
1464 |
QWidget *w = QInputContext::focusWidget(); |
|
1465 |
if (w) { |
|
1466 |
NSView *view = qt_mac_nativeview_for(w); |
|
1467 |
if ([view isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaView) class]]) { |
|
1468 |
QMacCocoaAutoReleasePool pool; |
|
1469 |
QT_MANGLE_NAMESPACE(QCocoaView) *qc = static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(view); |
|
1470 |
NSInputManager *currentIManager = [NSInputManager currentInputManager]; |
|
1471 |
if (currentIManager) { |
|
1472 |
[currentIManager markedTextAbandoned:view]; |
|
1473 |
[qc unmarkText]; |
|
1474 |
} |
|
1475 |
} |
|
1476 |
} |
|
1477 |
} |
|
1478 |
||
1479 |
bool QMacInputContext::isComposing() const |
|
1480 |
{ |
|
1481 |
QWidget *w = QInputContext::focusWidget(); |
|
1482 |
if (w) { |
|
1483 |
NSView *view = qt_mac_nativeview_for(w); |
|
1484 |
if ([view isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaView) class]]) { |
|
1485 |
return [static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(view) isComposing]; |
|
1486 |
} |
|
1487 |
} |
|
1488 |
return false; |
|
1489 |
} |
|
1490 |
||
1491 |
extern bool qt_mac_in_drag; |
|
1492 |
void * /*NSImage */qt_mac_create_nsimage(const QPixmap &pm); |
|
1493 |
static const int default_pm_hotx = -2; |
|
1494 |
static const int default_pm_hoty = -16; |
|
1495 |
static const char* default_pm[] = { |
|
1496 |
"13 9 3 1", |
|
1497 |
". c None", |
|
1498 |
" c #000000", |
|
1499 |
"X c #FFFFFF", |
|
1500 |
"X X X X X X X", |
|
1501 |
" X X X X X X ", |
|
1502 |
"X ......... X", |
|
1503 |
" X.........X ", |
|
1504 |
"X ......... X", |
|
1505 |
" X.........X ", |
|
1506 |
"X ......... X", |
|
1507 |
" X X X X X X ", |
|
1508 |
"X X X X X X X", |
|
1509 |
}; |
|
1510 |
||
1511 |
Qt::DropAction QDragManager::drag(QDrag *o) |
|
1512 |
{ |
|
1513 |
if(qt_mac_in_drag) { //just make sure.. |
|
1514 |
qWarning("Qt: Internal error: WH0A, unexpected condition reached"); |
|
1515 |
return Qt::IgnoreAction; |
|
1516 |
} |
|
1517 |
if(object == o) |
|
1518 |
return Qt::IgnoreAction; |
|
1519 |
/* At the moment it seems clear that Mac OS X does not want to drag with a non-left button |
|
1520 |
so we just bail early to prevent it */ |
|
1521 |
if(!(GetCurrentEventButtonState() & kEventMouseButtonPrimary)) |
|
1522 |
return Qt::IgnoreAction; |
|
1523 |
||
1524 |
if(object) { |
|
1525 |
dragPrivate()->source->removeEventFilter(this); |
|
1526 |
cancel(); |
|
1527 |
beingCancelled = false; |
|
1528 |
} |
|
1529 |
||
1530 |
object = o; |
|
1531 |
dragPrivate()->target = 0; |
|
1532 |
||
1533 |
#ifndef QT_NO_ACCESSIBILITY |
|
1534 |
QAccessible::updateAccessibility(this, 0, QAccessible::DragDropStart); |
|
1535 |
#endif |
|
1536 |
||
1537 |
// setup the data |
|
1538 |
QMacPasteboard dragBoard((CFStringRef) NSDragPboard, QMacPasteboardMime::MIME_DND); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1539 |
dragPrivate()->data->setData(QLatin1String("application/x-qt-mime-type-name"), QByteArray("dummy")); |
0 | 1540 |
dragBoard.setMimeData(dragPrivate()->data); |
1541 |
||
1542 |
// create the image |
|
1543 |
QPoint hotspot; |
|
1544 |
QPixmap pix = dragPrivate()->pixmap; |
|
1545 |
if(pix.isNull()) { |
|
1546 |
if(dragPrivate()->data->hasText() || dragPrivate()->data->hasUrls()) { |
|
1547 |
// get the string |
|
1548 |
QString s = dragPrivate()->data->hasText() ? dragPrivate()->data->text() |
|
1549 |
: dragPrivate()->data->urls().first().toString(); |
|
1550 |
if(s.length() > 26) |
|
1551 |
s = s.left(23) + QChar(0x2026); |
|
1552 |
if(!s.isEmpty()) { |
|
1553 |
// draw it |
|
1554 |
QFont f(qApp->font()); |
|
1555 |
f.setPointSize(12); |
|
1556 |
QFontMetrics fm(f); |
|
1557 |
QPixmap tmp(fm.width(s), fm.height()); |
|
1558 |
if(!tmp.isNull()) { |
|
1559 |
QPainter p(&tmp); |
|
1560 |
p.fillRect(0, 0, tmp.width(), tmp.height(), Qt::color0); |
|
1561 |
p.setPen(Qt::color1); |
|
1562 |
p.setFont(f); |
|
1563 |
p.drawText(0, fm.ascent(), s); |
|
1564 |
// save it |
|
1565 |
pix = tmp; |
|
1566 |
hotspot = QPoint(tmp.width() / 2, tmp.height() / 2); |
|
1567 |
} |
|
1568 |
} |
|
1569 |
} else { |
|
1570 |
pix = QPixmap(default_pm); |
|
1571 |
hotspot = QPoint(default_pm_hotx, default_pm_hoty); |
|
1572 |
} |
|
1573 |
} else { |
|
1574 |
hotspot = dragPrivate()->hotspot; |
|
1575 |
} |
|
1576 |
// convert the image to NSImage. |
|
1577 |
NSImage *image = (NSImage *)qt_mac_create_nsimage(pix); |
|
1578 |
[image retain]; |
|
1579 |
DnDParams dndParams = *[QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]; |
|
1580 |
// save supported actions |
|
1581 |
[dndParams.view setSupportedActions: qt_mac_mapDropActions(dragPrivate()->possible_actions)]; |
|
1582 |
NSPoint imageLoc = {dndParams.localPoint.x - hotspot.x(), |
|
1583 |
dndParams.localPoint.y + pix.height() - hotspot.y()}; |
|
1584 |
NSSize mouseOffset = {0.0, 0.0}; |
|
1585 |
NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard]; |
|
1586 |
NSPoint windowPoint = [dndParams.theEvent locationInWindow]; |
|
1587 |
dragPrivate()->executed_action = Qt::ActionMask; |
|
1588 |
// do the drag |
|
1589 |
[dndParams.view retain]; |
|
1590 |
[dndParams.view dragImage:image |
|
1591 |
at:imageLoc |
|
1592 |
offset:mouseOffset |
|
1593 |
event:dndParams.theEvent |
|
1594 |
pasteboard:pboard |
|
1595 |
source:dndParams.view |
|
1596 |
slideBack:YES]; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1597 |
// reset the implicit grab widget when drag ends because we will not |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1598 |
// receive the mouse release event when DND is active. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1599 |
qt_button_down = 0; |
0 | 1600 |
[dndParams.view release]; |
1601 |
[image release]; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1602 |
if (dragPrivate()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1603 |
dragPrivate()->executed_action = Qt::IgnoreAction; |
0 | 1604 |
object = 0; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1605 |
Qt::DropAction performedAction(qt_mac_mapNSDragOperation(qMacDnDParams()->performedAction)); |
0 | 1606 |
// do post drag processing, if required. |
1607 |
if(performedAction != Qt::IgnoreAction) { |
|
1608 |
// check if the receiver points us to a file location. |
|
1609 |
// if so, we need to do the file copy/move ourselves. |
|
1610 |
QCFType<CFURLRef> pasteLocation = 0; |
|
1611 |
PasteboardCopyPasteLocation(dragBoard.pasteBoard(), &pasteLocation); |
|
1612 |
if (pasteLocation) { |
|
1613 |
QList<QUrl> urls = o->mimeData()->urls(); |
|
1614 |
for (int i = 0; i < urls.size(); ++i) { |
|
1615 |
QUrl fromUrl = urls.at(i); |
|
1616 |
QString filename = QFileInfo(fromUrl.path()).fileName(); |
|
1617 |
QUrl toUrl(QCFString::toQString(CFURLGetString(pasteLocation)) + filename); |
|
1618 |
if (performedAction == Qt::MoveAction) |
|
1619 |
QFile::rename(fromUrl.path(), toUrl.path()); |
|
1620 |
else if (performedAction == Qt::CopyAction) |
|
1621 |
QFile::copy(fromUrl.path(), toUrl.path()); |
|
1622 |
} |
|
1623 |
} |
|
1624 |
} |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1625 |
o->setMimeData(0); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1626 |
o->deleteLater(); |
0 | 1627 |
return performedAction; |
1628 |
} |
|
1629 |
||
1630 |
QT_END_NAMESPACE |
|
1631 |
||
1632 |
#endif // QT_MAC_USE_COCOA |