1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
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.
56 #include "qmacdefines_mac.h"
59 #include <Cocoa/Cocoa.h>
60 #include <objc/runtime.h>
63 #include <CoreServices/CoreServices.h>
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"
72 #include "QtGui/qpainter.h"
74 #include <Carbon/Carbon.h>
85 typeAEClipboardChanged = 1,
87 typeQWidget = 1, /* QWidget * */
89 kEventParamQWidget = 'qwid', /* typeQWidget */
91 kEventQtRequestContext = 13,
92 kEventQtRequestMenubarUpdate = 14,
93 kEventQtRequestShowSheet = 17,
94 kEventQtRequestActivate = 18,
95 kEventQtRequestWindowChange = 20
98 // Simple class to manage short-lived regions
99 class QMacSmartQuickDrawRegion
102 Q_DISABLE_COPY(QMacSmartQuickDrawRegion)
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);
109 operator RgnHandle() {
114 // Class for chaining to gether a bunch of fades. It pretty much is only used for qmenu fading.
115 class QMacWindowFader
117 QWidgetList m_windowsToFade;
119 Q_DISABLE_COPY(QMacWindowFader)
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; }
129 class Q_WIDGETS_EXPORT QMacCocoaAutoReleasePool
134 QMacCocoaAutoReleasePool();
135 ~QMacCocoaAutoReleasePool();
137 inline void *handle() const { return pool; }
140 QString qt_mac_removeMnemonics(const QString &original); //implemented in qmacstyle_mac.cpp
142 class Q_WIDGETS_EXPORT QMacWindowChangeEvent
145 static QList<QMacWindowChangeEvent*> *change_events;
147 QMacWindowChangeEvent() {
149 virtual ~QMacWindowChangeEvent() {
151 static inline void exec(bool ) {
154 virtual void windowChanged() = 0;
155 virtual void flushWindowChanged() = 0;
160 CGContextRef context;
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);
168 inline QMacCGContext(CGContextRef cg, bool takeOwnership=false) {
171 CGContextRetain(context);
173 inline QMacCGContext(const QMacCGContext ©) : context(0) { *this = copy; }
174 inline ~QMacCGContext() {
176 CGContextRelease(context);
178 inline bool isNull() const { return context; }
179 inline operator CGContextRef() { return context; }
180 inline QMacCGContext &operator=(const QMacCGContext ©) {
182 CGContextRelease(context);
183 context = copy.context;
184 CGContextRetain(context);
187 inline QMacCGContext &operator=(CGContextRef cg) {
189 CGContextRelease(context);
191 CGContextRetain(context); //we do not take ownership
196 class QMacPasteboardMime;
200 extern QPaintDevice *qt_mac_safe_pdev; //qapplication_mac.cpp
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
210 QFont qfontForThemeFont(ThemeFontID themeID);
212 QColor qcolorForTheme(ThemeBrush brush);
214 QColor qcolorForThemeTextColor(ThemeTextColor themeColor);
216 struct QMacDndAnswerRecord {
218 Qt::KeyboardModifiers modifiers;
219 Qt::MouseButtons buttons;
220 Qt::DropAction lastAction;
221 unsigned int lastOperation;
224 modifiers = Qt::NoModifier;
225 buttons = Qt::NoButton;
226 lastAction = Qt::IgnoreAction;
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);