Port QMacPrintEngine and QCoreGraphicsPaintEngine from Qt 4 to Qt 5
[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 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
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 enum {
84     //AE types
85     typeAEClipboardChanged = 1,
86     //types
87     typeQWidget = 1,  /* QWidget *  */
88     //params
89     kEventParamQWidget = 'qwid',   /* typeQWidget */
90     //events
91     kEventQtRequestContext = 13,
92     kEventQtRequestMenubarUpdate = 14,
93     kEventQtRequestShowSheet = 17,
94     kEventQtRequestActivate = 18,
95     kEventQtRequestWindowChange = 20
96 };
97
98 // Simple class to manage short-lived regions
99 class QMacSmartQuickDrawRegion
100 {
101     RgnHandle qdRgn;
102     Q_DISABLE_COPY(QMacSmartQuickDrawRegion)
103 public:
104     explicit QMacSmartQuickDrawRegion(RgnHandle rgn) : qdRgn(rgn) {}
105     ~QMacSmartQuickDrawRegion() {
106         extern void qt_mac_dispose_rgn(RgnHandle); // qregion_mac.cpp
107         qt_mac_dispose_rgn(qdRgn);
108     }
109     operator RgnHandle() {
110         return qdRgn;
111     }
112 };
113
114 // Class for chaining to gether a bunch of fades. It pretty much is only used for qmenu fading.
115 class QMacWindowFader
116 {
117     QWidgetList m_windowsToFade;
118     float m_duration;
119     Q_DISABLE_COPY(QMacWindowFader)
120 public:
121     QMacWindowFader(); // PLEASE DON'T CALL THIS.
122     static QMacWindowFader *currentFader();
123     void registerWindowToFade(QWidget *window);
124     void setFadeDuration(float durationInSecs) { m_duration = durationInSecs; }
125     float fadeDuration() const { return m_duration; }
126     void performFade();
127 };
128
129 class Q_WIDGETS_EXPORT QMacCocoaAutoReleasePool
130 {
131 private:
132     void *pool;
133 public:
134     QMacCocoaAutoReleasePool();
135     ~QMacCocoaAutoReleasePool();
136
137     inline void *handle() const { return pool; }
138 };
139
140 QString qt_mac_removeMnemonics(const QString &original); //implemented in qmacstyle_mac.cpp
141
142 class Q_WIDGETS_EXPORT QMacWindowChangeEvent
143 {
144 private:
145     static QList<QMacWindowChangeEvent*> *change_events;
146 public:
147     QMacWindowChangeEvent() {
148     }
149     virtual ~QMacWindowChangeEvent() {
150     }
151     static inline void exec(bool ) {
152     }
153 protected:
154     virtual void windowChanged() = 0;
155     virtual void flushWindowChanged() = 0;
156 };
157
158 class QMacCGContext
159 {
160     CGContextRef context;
161 public:
162     QMacCGContext(QPainter *p); //qpaintengine_mac.mm
163     inline QMacCGContext() { context = 0; }
164     inline QMacCGContext(const QPaintDevice *pdev) {
165         extern CGContextRef qt_mac_cg_context(const QPaintDevice *);
166         context = qt_mac_cg_context(pdev);
167     }
168     inline QMacCGContext(CGContextRef cg, bool takeOwnership=false) {
169         context = cg;
170         if(!takeOwnership)
171             CGContextRetain(context);
172     }
173     inline QMacCGContext(const QMacCGContext &copy) : context(0) { *this = copy; }
174     inline ~QMacCGContext() {
175         if(context)
176             CGContextRelease(context);
177     }
178     inline bool isNull() const { return context; }
179     inline operator CGContextRef() { return context; }
180     inline QMacCGContext &operator=(const QMacCGContext &copy) {
181         if(context)
182             CGContextRelease(context);
183         context = copy.context;
184         CGContextRetain(context);
185         return *this;
186     }
187     inline QMacCGContext &operator=(CGContextRef cg) {
188         if(context)
189             CGContextRelease(context);
190         context = cg;
191         CGContextRetain(context); //we do not take ownership
192         return *this;
193     }
194 };
195
196 class QMacPasteboardMime;
197 class QMimeData;
198
199
200 extern QPaintDevice *qt_mac_safe_pdev; //qapplication_mac.cpp
201
202 extern OSWindowRef qt_mac_window_for(const QWidget*); //qwidget_mac.mm
203 extern OSViewRef qt_mac_nativeview_for(const QWidget *); //qwidget_mac.mm
204 extern QPoint qt_mac_nativeMapFromParent(const QWidget *child, const QPoint &pt); //qwidget_mac.mm
205
206 #ifdef check
207 # undef check
208 #endif
209
210 QFont qfontForThemeFont(ThemeFontID themeID);
211
212 QColor qcolorForTheme(ThemeBrush brush);
213
214 QColor qcolorForThemeTextColor(ThemeTextColor themeColor);
215
216 struct QMacDndAnswerRecord {
217     QRect rect;
218     Qt::KeyboardModifiers modifiers;
219     Qt::MouseButtons buttons;
220     Qt::DropAction lastAction;
221     unsigned int lastOperation;
222     void clear() {
223         rect = QRect();
224         modifiers = Qt::NoModifier;
225         buttons = Qt::NoButton;
226         lastAction = Qt::IgnoreAction;
227         lastOperation = 0;
228     }
229 };
230 extern QMacDndAnswerRecord qt_mac_dnd_answer_rec;
231 void qt_mac_copy_answer_rect(const QDragMoveEvent &event);
232 bool qt_mac_mouse_inside_answer_rect(QPoint mouse);
233
234 QT_END_NAMESPACE
235
236 #endif // QT_MAC_P_H