1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qapplication.h"
43 #ifndef QT_NO_DRAGANDDROP
51 #include "qfileinfo.h"
54 #ifndef QT_NO_ACCESSIBILITY
55 # include "qaccessible.h"
58 #include <private/qapplication_p.h>
59 #include <private/qwidget_p.h>
60 #include <private/qdnd_p.h>
61 #include <private/qt_mac_p.h>
67 QMacDndAnswerRecord qt_mac_dnd_answer_rec;
69 /*****************************************************************************
71 *****************************************************************************/
72 //#define DEBUG_DRAG_EVENTS
73 //#define DEBUG_DRAG_PROMISES
75 /*****************************************************************************
77 *****************************************************************************/
78 bool qt_mac_in_drag = false;
80 /*****************************************************************************
82 *****************************************************************************/
83 extern void qt_mac_send_modifiers_changed(quint32, QObject *); //qapplication_mac.cpp
84 extern uint qGlobalPostedEventsCount(); //qapplication.cpp
85 extern RgnHandle qt_mac_get_rgn(); // qregion_mac.cpp
86 extern void qt_mac_dispose_rgn(RgnHandle); // qregion_mac.cpp
87 /*****************************************************************************
88 QDnD utility functions
89 *****************************************************************************/
92 #ifdef DEBUG_DRAG_EVENTS
93 # define MAP_MAC_ENUM(x) x, #x
95 # define MAP_MAC_ENUM(x) x
97 struct mac_enum_mapper
101 #ifdef DEBUG_DRAG_EVENTS
106 /*****************************************************************************
108 *****************************************************************************/
109 bool QDropData::hasFormat_sys(const QString &mime) const
115 QVariant QDropData::retrieveData_sys(const QString &mime, QVariant::Type type) const
122 QStringList QDropData::formats_sys() const
124 return QStringList();
127 void QDragManager::timerEvent(QTimerEvent*)
131 bool QDragManager::eventFilter(QObject *, QEvent *)
136 void QDragManager::updateCursor()
140 void QDragManager::cancel(bool)
143 beingCancelled = true;
146 #ifndef QT_NO_ACCESSIBILITY
147 QAccessible::updateAccessibility(this, 0, QAccessible::DragDropEnd);
151 void QDragManager::move(const QPoint &)
155 void QDragManager::drop()
160 If a drop action is already set on the carbon event
161 (from e.g. an earlier enter event), we insert the same
162 action on the new Qt event that has yet to be sendt.
164 static inline bool qt_mac_set_existing_drop_action(const DragRef &dragRef, QDropEvent &event)
172 If an answer rect has been set on the event (after being sent
173 to the global event processor), we store that rect so we can
174 check if the mouse is in the same area upon next drag move event.
176 void qt_mac_copy_answer_rect(const QDragMoveEvent &event)
178 if (!event.answerRect().isEmpty()) {
179 qt_mac_dnd_answer_rec.rect = event.answerRect();
180 qt_mac_dnd_answer_rec.buttons = event.mouseButtons();
181 qt_mac_dnd_answer_rec.modifiers = event.keyboardModifiers();
182 qt_mac_dnd_answer_rec.lastAction = event.dropAction();
186 bool qt_mac_mouse_inside_answer_rect(QPoint mouse)
188 if (!qt_mac_dnd_answer_rec.rect.isEmpty()
189 && qt_mac_dnd_answer_rec.rect.contains(mouse)
190 && QApplication::mouseButtons() == qt_mac_dnd_answer_rec.buttons
191 && QApplication::keyboardModifiers() == qt_mac_dnd_answer_rec.modifiers)
197 bool QWidgetPrivate::qt_mac_dnd_event(uint kind, DragRef dragRef)
204 void QDragManager::updatePixmap()
208 QCocoaDropData::QCocoaDropData(CFStringRef pasteboard)
209 : QInternalMimeData()
211 NSString* pasteboardName = (NSString*)pasteboard;
212 [pasteboardName retain];
213 dropPasteboard = pasteboard;
216 QCocoaDropData::~QCocoaDropData()
218 NSString* pasteboardName = (NSString*)dropPasteboard;
219 [pasteboardName release];
222 QStringList QCocoaDropData::formats_sys() const
225 OSPasteboardRef board;
226 if (PasteboardCreate(dropPasteboard, &board) != noErr) {
227 qDebug("DnD: Cannot get PasteBoard!");
230 formats = QMacPasteboard(board, QMacPasteboardMime::MIME_DND).formats();
234 QVariant QCocoaDropData::retrieveData_sys(const QString &mimeType, QVariant::Type type) const
237 OSPasteboardRef board;
238 if (PasteboardCreate(dropPasteboard, &board) != noErr) {
239 qDebug("DnD: Cannot get PasteBoard!");
242 data = QMacPasteboard(board, QMacPasteboardMime::MIME_DND).retrieveData(mimeType, type);
247 bool QCocoaDropData::hasFormat_sys(const QString &mimeType) const
250 OSPasteboardRef board;
251 if (PasteboardCreate(dropPasteboard, &board) != noErr) {
252 qDebug("DnD: Cannot get PasteBoard!");
255 has = QMacPasteboard(board, QMacPasteboardMime::MIME_DND).hasFormat(mimeType);
260 #endif // QT_NO_DRAGANDDROP