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