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 ****************************************************************************/
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>
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;
90 const UInt32 kEventClassQt = 'Cute';
95 typeAEClipboardChanged = 1,
97 typeQWidget = 1, /* QWidget * */
99 kEventParamQWidget = 'qwid', /* typeQWidget */
101 kEventQtRequestContext = 13,
102 kEventQtRequestMenubarUpdate = 14,
103 kEventQtRequestShowSheet = 17,
104 kEventQtRequestActivate = 18,
105 kEventQtRequestWindowChange = 20
108 // Simple class to manage short-lived regions
109 class QMacSmartQuickDrawRegion
112 Q_DISABLE_COPY(QMacSmartQuickDrawRegion)
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);
119 operator RgnHandle() {
124 // Class for chaining to gether a bunch of fades. It pretty much is only used for qmenu fading.
125 class QMacWindowFader
127 QWidgetList m_windowsToFade;
129 Q_DISABLE_COPY(QMacWindowFader)
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; }
139 class Q_WIDGETS_EXPORT QMacCocoaAutoReleasePool
144 QMacCocoaAutoReleasePool();
145 ~QMacCocoaAutoReleasePool();
147 inline void *handle() const { return pool; }
150 QString qt_mac_removeMnemonics(const QString &original); //implemented in qmacstyle_mac.cpp
152 class Q_WIDGETS_EXPORT QMacWindowChangeEvent
155 static QList<QMacWindowChangeEvent*> *change_events;
157 QMacWindowChangeEvent() {
159 virtual ~QMacWindowChangeEvent() {
161 static inline void exec(bool ) {
164 virtual void windowChanged() = 0;
165 virtual void flushWindowChanged() = 0;
170 CGContextRef context;
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);
178 inline QMacCGContext(CGContextRef cg, bool takeOwnership=false) {
181 CGContextRetain(context);
183 inline QMacCGContext(const QMacCGContext ©) : context(0) { *this = copy; }
184 inline ~QMacCGContext() {
186 CGContextRelease(context);
188 inline bool isNull() const { return context; }
189 inline operator CGContextRef() { return context; }
190 inline QMacCGContext &operator=(const QMacCGContext ©) {
192 CGContextRelease(context);
193 context = copy.context;
194 CGContextRetain(context);
197 inline QMacCGContext &operator=(CGContextRef cg) {
199 CGContextRelease(context);
201 CGContextRetain(context); //we do not take ownership
206 class QMacPasteboardMime;
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) { }
215 QMacPasteboardMime *convertor;
219 QList<Promise> promises;
221 OSPasteboardRef paste;
223 mutable QPointer<QMimeData> mime;
224 mutable bool mac_mime_source;
225 static OSStatus promiseKeeper(OSPasteboardRef, PasteboardItemID, CFStringRef, void *);
228 QMacPasteboard(OSPasteboardRef p, uchar mime_type=0);
229 QMacPasteboard(uchar mime_type);
230 QMacPasteboard(CFStringRef name=0, uchar mime_type=0);
233 bool hasFlavor(QString flavor) const;
234 bool hasOSType(int c_flavor) const;
236 OSPasteboardRef pasteBoard() const;
237 QMimeData *mimeData() const;
238 void setMimeData(QMimeData *mime);
240 QStringList formats() const;
241 bool hasFormat(const QString &format) const;
242 QVariant retrieveData(const QString &format, QVariant::Type) const;
248 extern QPaintDevice *qt_mac_safe_pdev; //qapplication_mac.cpp
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
258 QFont qfontForThemeFont(ThemeFontID themeID);
260 QColor qcolorForTheme(ThemeBrush brush);
262 QColor qcolorForThemeTextColor(ThemeTextColor themeColor);
264 struct QMacDndAnswerRecord {
266 Qt::KeyboardModifiers modifiers;
267 Qt::MouseButtons buttons;
268 Qt::DropAction lastAction;
269 unsigned int lastOperation;
272 modifiers = Qt::NoModifier;
273 buttons = Qt::NoButton;
274 lastAction = Qt::IgnoreAction;
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);