Fixed crash in GL 2 paint engine on Intel Atom.
[profile/ivi/qtbase.git] / src / widgets / platforms / mac / qdnd_mac.mm
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
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 ** 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.
17 **
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.
21 **
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.
29 **
30 ** Other Usage
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.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qapplication.h"
43 #ifndef QT_NO_DRAGANDDROP
44 #include "qbitmap.h"
45 #include "qcursor.h"
46 #include "qevent.h"
47 #include "qpainter.h"
48 #include "qurl.h"
49 #include "qwidget.h"
50 #include "qfile.h"
51 #include "qfileinfo.h"
52 #include <stdlib.h>
53 #include <string.h>
54 #ifndef QT_NO_ACCESSIBILITY
55 # include "qaccessible.h"
56 #endif
57
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>
62
63 QT_BEGIN_NAMESPACE
64
65 QT_USE_NAMESPACE
66
67 QMacDndAnswerRecord qt_mac_dnd_answer_rec; 
68
69 /*****************************************************************************
70   QDnD debug facilities
71  *****************************************************************************/
72 //#define DEBUG_DRAG_EVENTS
73 //#define DEBUG_DRAG_PROMISES
74
75 /*****************************************************************************
76   QDnD globals
77  *****************************************************************************/
78 bool qt_mac_in_drag = false;
79
80 /*****************************************************************************
81   Externals
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  *****************************************************************************/
90
91 //action management
92 #ifdef DEBUG_DRAG_EVENTS
93 # define MAP_MAC_ENUM(x) x, #x
94 #else
95 # define MAP_MAC_ENUM(x) x
96 #endif
97 struct mac_enum_mapper
98 {
99     int mac_code;
100     int qt_code;
101 #ifdef DEBUG_DRAG_EVENTS
102     char *qt_desc;
103 #endif
104 };
105
106 /*****************************************************************************
107   DnD functions
108  *****************************************************************************/
109 bool QDropData::hasFormat_sys(const QString &mime) const
110 {
111     Q_UNUSED(mime);
112     return false;
113 }
114
115 QVariant QDropData::retrieveData_sys(const QString &mime, QVariant::Type type) const
116 {
117     Q_UNUSED(mime);
118     Q_UNUSED(type);
119     return QVariant();
120 }
121
122 QStringList QDropData::formats_sys() const
123 {
124     return QStringList();
125 }
126
127 void QDragManager::timerEvent(QTimerEvent*)
128 {
129 }
130
131 bool QDragManager::eventFilter(QObject *, QEvent *)
132 {
133     return false;
134 }
135
136 void QDragManager::updateCursor()
137 {
138 }
139
140 void QDragManager::cancel(bool)
141 {
142     if(object) {
143         beingCancelled = true;
144         object = 0;
145     }
146 #ifndef QT_NO_ACCESSIBILITY
147     QAccessible::updateAccessibility(this, 0, QAccessible::DragDropEnd);
148 #endif
149 }
150
151 void QDragManager::move(const QPoint &)
152 {
153 }
154
155 void QDragManager::drop()
156 {
157 }
158
159 /**
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.
163 */
164 static inline bool qt_mac_set_existing_drop_action(const DragRef &dragRef, QDropEvent &event)
165 {
166     Q_UNUSED(dragRef);
167     Q_UNUSED(event);
168     return false;
169 }
170
171 /**
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. 
175 */
176 void qt_mac_copy_answer_rect(const QDragMoveEvent &event)
177 {
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();
183     }    
184 }
185
186 bool qt_mac_mouse_inside_answer_rect(QPoint mouse)
187 {
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)
192         return true;
193     else
194         return false;
195 }
196
197 bool QWidgetPrivate::qt_mac_dnd_event(uint kind, DragRef dragRef)
198 {
199     Q_UNUSED(kind);
200     Q_UNUSED(dragRef);
201     return false;
202 }
203
204 void QDragManager::updatePixmap()
205 {
206 }
207
208 QCocoaDropData::QCocoaDropData(CFStringRef pasteboard)
209     : QInternalMimeData()
210 {
211     NSString* pasteboardName = (NSString*)pasteboard;
212     [pasteboardName retain];
213     dropPasteboard = pasteboard;
214 }
215
216 QCocoaDropData::~QCocoaDropData()
217 {
218     NSString* pasteboardName = (NSString*)dropPasteboard;
219     [pasteboardName release];
220 }
221
222 QStringList QCocoaDropData::formats_sys() const
223 {
224     QStringList formats; 
225     OSPasteboardRef board;
226     if (PasteboardCreate(dropPasteboard, &board) != noErr) {
227         qDebug("DnD: Cannot get PasteBoard!");
228         return formats;
229     }
230     formats = QMacPasteboard(board, QMacPasteboardMime::MIME_DND).formats();
231     return formats;
232 }
233
234 QVariant QCocoaDropData::retrieveData_sys(const QString &mimeType, QVariant::Type type) const
235 {
236     QVariant data;
237     OSPasteboardRef board;
238     if (PasteboardCreate(dropPasteboard, &board) != noErr) {
239         qDebug("DnD: Cannot get PasteBoard!");
240         return data;
241     }
242     data = QMacPasteboard(board, QMacPasteboardMime::MIME_DND).retrieveData(mimeType, type);
243     CFRelease(board);
244     return data;
245 }
246
247 bool QCocoaDropData::hasFormat_sys(const QString &mimeType) const
248 {
249     bool has = false;
250     OSPasteboardRef board;
251     if (PasteboardCreate(dropPasteboard, &board) != noErr) {
252         qDebug("DnD: Cannot get PasteBoard!");
253         return has;
254     }
255     has = QMacPasteboard(board, QMacPasteboardMime::MIME_DND).hasFormat(mimeType);
256     CFRelease(board);
257     return has;
258 }
259
260 #endif // QT_NO_DRAGANDDROP
261 QT_END_NAMESPACE