Delete src/widgets/platforms/mac
[profile/ivi/qtbase.git] / src / plugins / platforms / cocoa / qt_mac_p.h
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 #ifndef QT_MAC_P_H
43 #define QT_MAC_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists purely as an
50 // implementation detail.  This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55
56 #include "qmacdefines_mac.h"
57
58 #ifdef __OBJC__
59 #include <Cocoa/Cocoa.h>
60 #include <objc/runtime.h>
61 #endif
62
63 #include <CoreServices/CoreServices.h>
64
65 #include "QtCore/qglobal.h"
66 #include "QtCore/qvariant.h"
67 #include "QtCore/qmimedata.h"
68 #include "QtCore/qpointer.h"
69 #include "private/qcore_mac_p.h"
70
71
72 #include "QtGui/qpainter.h"
73
74 #include <Carbon/Carbon.h>
75
76 QT_BEGIN_NAMESPACE
77 class QWidget;
78 class QDragMoveEvent;
79
80 /* Event masks */
81 // internal Qt types
82
83  // Event class for our own Carbon events.
84 #if defined(QT_NAMESPACE) && defined(QT_NAMESPACE_MAC_CRC)
85 // Take the CRC we generated at configure time. This *may* result in a
86 // collision with another value If that is the case, please change the value
87 // here to something other than 'Cute'.
88 const UInt32 kEventClassQt = QT_NAMESPACE_MAC_CRC;
89 #else
90 const UInt32 kEventClassQt = 'Cute';
91 #endif
92
93 enum {
94     //AE types
95     typeAEClipboardChanged = 1,
96     //types
97     typeQWidget = 1,  /* QWidget *  */
98     //params
99     kEventParamQWidget = 'qwid',   /* typeQWidget */
100     //events
101     kEventQtRequestContext = 13,
102     kEventQtRequestMenubarUpdate = 14,
103     kEventQtRequestShowSheet = 17,
104     kEventQtRequestActivate = 18,
105     kEventQtRequestWindowChange = 20
106 };
107
108 // Simple class to manage short-lived regions
109 class QMacSmartQuickDrawRegion
110 {
111     RgnHandle qdRgn;
112     Q_DISABLE_COPY(QMacSmartQuickDrawRegion)
113 public:
114     explicit QMacSmartQuickDrawRegion(RgnHandle rgn) : qdRgn(rgn) {}
115     ~QMacSmartQuickDrawRegion() {
116         extern void qt_mac_dispose_rgn(RgnHandle); // qregion_mac.cpp
117         qt_mac_dispose_rgn(qdRgn);
118     }
119     operator RgnHandle() {
120         return qdRgn;
121     }
122 };
123
124 // Class for chaining to gether a bunch of fades. It pretty much is only used for qmenu fading.
125 class QMacWindowFader
126 {
127     QWidgetList m_windowsToFade;
128     float m_duration;
129     Q_DISABLE_COPY(QMacWindowFader)
130 public:
131     QMacWindowFader(); // PLEASE DON'T CALL THIS.
132     static QMacWindowFader *currentFader();
133     void registerWindowToFade(QWidget *window);
134     void setFadeDuration(float durationInSecs) { m_duration = durationInSecs; }
135     float fadeDuration() const { return m_duration; }
136     void performFade();
137 };
138
139 class Q_WIDGETS_EXPORT QMacCocoaAutoReleasePool
140 {
141 private:
142     void *pool;
143 public:
144     QMacCocoaAutoReleasePool();
145     ~QMacCocoaAutoReleasePool();
146
147     inline void *handle() const { return pool; }
148 };
149
150 QString qt_mac_removeMnemonics(const QString &original); //implemented in qmacstyle_mac.cpp
151
152 class Q_WIDGETS_EXPORT QMacWindowChangeEvent
153 {
154 private:
155     static QList<QMacWindowChangeEvent*> *change_events;
156 public:
157     QMacWindowChangeEvent() {
158     }
159     virtual ~QMacWindowChangeEvent() {
160     }
161     static inline void exec(bool ) {
162     }
163 protected:
164     virtual void windowChanged() = 0;
165     virtual void flushWindowChanged() = 0;
166 };
167
168 class QMacCGContext
169 {
170     CGContextRef context;
171 public:
172     QMacCGContext(QPainter *p); //qpaintengine_mac.cpp
173     inline QMacCGContext() { context = 0; }
174     inline QMacCGContext(const QPaintDevice *pdev) {
175         extern CGContextRef qt_mac_cg_context(const QPaintDevice *);
176         context = qt_mac_cg_context(pdev);
177     }
178     inline QMacCGContext(CGContextRef cg, bool takeOwnership=false) {
179         context = cg;
180         if(!takeOwnership)
181             CGContextRetain(context);
182     }
183     inline QMacCGContext(const QMacCGContext &copy) : context(0) { *this = copy; }
184     inline ~QMacCGContext() {
185         if(context)
186             CGContextRelease(context);
187     }
188     inline bool isNull() const { return context; }
189     inline operator CGContextRef() { return context; }
190     inline QMacCGContext &operator=(const QMacCGContext &copy) {
191         if(context)
192             CGContextRelease(context);
193         context = copy.context;
194         CGContextRetain(context);
195         return *this;
196     }
197     inline QMacCGContext &operator=(CGContextRef cg) {
198         if(context)
199             CGContextRelease(context);
200         context = cg;
201         CGContextRetain(context); //we do not take ownership
202         return *this;
203     }
204 };
205
206 class QMacPasteboardMime;
207 class QMimeData;
208
209 class QMacPasteboard
210 {
211     struct Promise {
212         Promise() : itemId(0), convertor(0) { }
213         Promise(int itemId, QMacPasteboardMime *c, QString m, QVariant d, int o=0) : itemId(itemId), offset(o), convertor(c), mime(m), data(d) { }
214         int itemId, offset;
215         QMacPasteboardMime *convertor;
216         QString mime;
217         QVariant data;
218     };
219     QList<Promise> promises;
220
221     OSPasteboardRef paste;
222     uchar mime_type;
223     mutable QPointer<QMimeData> mime;
224     mutable bool mac_mime_source;
225     static OSStatus promiseKeeper(OSPasteboardRef, PasteboardItemID, CFStringRef, void *);
226     void clear_helper();
227 public:
228     QMacPasteboard(OSPasteboardRef p, uchar mime_type=0);
229     QMacPasteboard(uchar mime_type);
230     QMacPasteboard(CFStringRef name=0, uchar mime_type=0);
231     ~QMacPasteboard();
232
233     bool hasFlavor(QString flavor) const;
234     bool hasOSType(int c_flavor) const;
235
236     OSPasteboardRef pasteBoard() const;
237     QMimeData *mimeData() const;
238     void setMimeData(QMimeData *mime);
239
240     QStringList formats() const;
241     bool hasFormat(const QString &format) const;
242     QVariant retrieveData(const QString &format, QVariant::Type) const;
243
244     void clear();
245     bool sync() const;
246 };
247
248 extern QPaintDevice *qt_mac_safe_pdev; //qapplication_mac.cpp
249
250 extern OSWindowRef qt_mac_window_for(const QWidget*); //qwidget_mac.mm
251 extern OSViewRef qt_mac_nativeview_for(const QWidget *); //qwidget_mac.mm
252 extern QPoint qt_mac_nativeMapFromParent(const QWidget *child, const QPoint &pt); //qwidget_mac.mm
253
254 #ifdef check
255 # undef check
256 #endif
257
258 QFont qfontForThemeFont(ThemeFontID themeID);
259
260 QColor qcolorForTheme(ThemeBrush brush);
261
262 QColor qcolorForThemeTextColor(ThemeTextColor themeColor);
263
264 struct QMacDndAnswerRecord {
265     QRect rect;
266     Qt::KeyboardModifiers modifiers;
267     Qt::MouseButtons buttons;
268     Qt::DropAction lastAction;
269     unsigned int lastOperation;
270     void clear() {
271         rect = QRect();
272         modifiers = Qt::NoModifier;
273         buttons = Qt::NoButton;
274         lastAction = Qt::IgnoreAction;
275         lastOperation = 0;
276     }
277 };
278 extern QMacDndAnswerRecord qt_mac_dnd_answer_rec;
279 void qt_mac_copy_answer_rect(const QDragMoveEvent &event);
280 bool qt_mac_mouse_inside_answer_rect(QPoint mouse);
281
282 QT_END_NAMESPACE
283
284 #endif // QT_MAC_P_H