Qt 4.8
qt_mac_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 #ifdef QT_MAC_USE_COCOA
61 #include <objc/runtime.h>
62 #endif // QT_MAC_USE_COCOA
63 #endif
64 
65 #include <CoreServices/CoreServices.h>
66 
67 #include "QtCore/qglobal.h"
68 #include "QtCore/qvariant.h"
69 #include "QtCore/qmimedata.h"
70 #include "QtCore/qpointer.h"
71 #include "private/qcore_mac_p.h"
72 
73 
74 #include "QtGui/qpainter.h"
75 
76 #include <Carbon/Carbon.h>
77 
79 class QWidget;
80 class QDragMoveEvent;
81 
82 /* Event masks */
83 // internal Qt types
84 
85  // Event class for our own Carbon events.
86 #if defined(QT_NAMESPACE) && defined(QT_NAMESPACE_MAC_CRC)
87 // Take the CRC we generated at configure time. This *may* result in a
88 // collision with another value If that is the case, please change the value
89 // here to something other than 'Cute'.
90 const UInt32 kEventClassQt = QT_NAMESPACE_MAC_CRC;
91 #else
92 const UInt32 kEventClassQt = 'Cute';
93 #endif
94 
95 enum {
96  //AE types
98  //types
99  typeQWidget = 1, /* QWidget * */
100  //params
101  kEventParamQWidget = 'qwid', /* typeQWidget */
102  //events
108 };
109 
110 // Simple class to manage short-lived regions
112 {
115 public:
116  explicit QMacSmartQuickDrawRegion(RgnHandle rgn) : qdRgn(rgn) {}
118  extern void qt_mac_dispose_rgn(RgnHandle); // qregion_mac.cpp
119  qt_mac_dispose_rgn(qdRgn);
120  }
121  operator RgnHandle() {
122  return qdRgn;
123  }
124 };
125 
126 // Class for chaining to gether a bunch of fades. It pretty much is only used for qmenu fading.
128 {
130  float m_duration;
132 public:
133  QMacWindowFader(); // PLEASE DON'T CALL THIS.
134  static QMacWindowFader *currentFader();
135  void registerWindowToFade(QWidget *window);
136  void setFadeDuration(float durationInSecs) { m_duration = durationInSecs; }
137  float fadeDuration() const { return m_duration; }
138  void performFade();
139 };
140 
142 {
143 private:
144  void *pool;
145 public:
148 
149  inline void *handle() const { return pool; }
150 };
151 
152 QString qt_mac_removeMnemonics(const QString &original); //implemented in qmacstyle_mac.cpp
153 
155 {
156 private:
158 public:
160  }
162  }
163  static inline void exec(bool ) {
164  }
165 protected:
166  virtual void windowChanged() = 0;
167  virtual void flushWindowChanged() = 0;
168 };
169 
171 {
173 public:
174  QMacCGContext(QPainter *p); //qpaintengine_mac.cpp
175  inline QMacCGContext() { context = 0; }
176  inline QMacCGContext(const QPaintDevice *pdev) {
178  context = qt_mac_cg_context(pdev);
179  }
180  inline QMacCGContext(CGContextRef cg, bool takeOwnership=false) {
181  context = cg;
182  if(!takeOwnership)
183  CGContextRetain(context);
184  }
185  inline QMacCGContext(const QMacCGContext &copy) : context(0) { *this = copy; }
186  inline ~QMacCGContext() {
187  if(context)
188  CGContextRelease(context);
189  }
190  inline bool isNull() const { return context; }
191  inline operator CGContextRef() { return context; }
192  inline QMacCGContext &operator=(const QMacCGContext &copy) {
193  if(context)
194  CGContextRelease(context);
195  context = copy.context;
196  CGContextRetain(context);
197  return *this;
198  }
200  if(context)
201  CGContextRelease(context);
202  context = cg;
203  CGContextRetain(context); //we do not take ownership
204  return *this;
205  }
206 };
207 
208 class QMacPasteboardMime;
209 class QMimeData;
210 
212 {
213  struct Promise {
214  Promise() : itemId(0), convertor(0) { }
215  Promise(int itemId, QMacPasteboardMime *c, QString m, QVariant d, int o=0) : itemId(itemId), offset(o), convertor(c), mime(m), data(d) { }
216  int itemId, offset;
220  };
222 
226  mutable bool mac_mime_source;
227  static OSStatus promiseKeeper(OSPasteboardRef, PasteboardItemID, CFStringRef, void *);
228  void clear_helper();
229 public:
230  QMacPasteboard(OSPasteboardRef p, uchar mime_type=0);
231  QMacPasteboard(uchar mime_type);
232  QMacPasteboard(CFStringRef name=0, uchar mime_type=0);
233  ~QMacPasteboard();
234 
235  bool hasFlavor(QString flavor) const;
236  bool hasOSType(int c_flavor) const;
237 
238  OSPasteboardRef pasteBoard() const;
239  QMimeData *mimeData() const;
240  void setMimeData(QMimeData *mime);
241 
242  QStringList formats() const;
243  bool hasFormat(const QString &format) const;
244  QVariant retrieveData(const QString &format, QVariant::Type) const;
245 
246  void clear();
247  bool sync() const;
248 };
249 
250 extern QPaintDevice *qt_mac_safe_pdev; //qapplication_mac.cpp
251 
252 extern OSWindowRef qt_mac_window_for(const QWidget*); //qwidget_mac.mm
253 extern OSViewRef qt_mac_nativeview_for(const QWidget *); //qwidget_mac.mm
254 extern QPoint qt_mac_nativeMapFromParent(const QWidget *child, const QPoint &pt); //qwidget_mac.mm
255 
256 #ifdef check
257 # undef check
258 #endif
259 
260 QFont qfontForThemeFont(ThemeFontID themeID);
261 
262 QColor qcolorForTheme(ThemeBrush brush);
263 
264 QColor qcolorForThemeTextColor(ThemeTextColor themeColor);
265 
268  Qt::KeyboardModifiers modifiers;
269  Qt::MouseButtons buttons;
271  unsigned int lastOperation;
272  void clear() {
273  rect = QRect();
274  modifiers = Qt::NoModifier;
275  buttons = Qt::NoButton;
276  lastAction = Qt::IgnoreAction;
277  lastOperation = 0;
278  }
279 };
283 
285 
286 #endif // QT_MAC_P_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
Promise(int itemId, QMacPasteboardMime *c, QString m, QVariant d, int o=0)
Definition: qt_mac_p.h:215
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
const struct __CFString * CFStringRef
float m_duration
Definition: qt_mac_p.h:130
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
EventRef event
QMacCGContext & operator=(CGContextRef cg)
Definition: qt_mac_p.h:199
QMacCGContext(CGContextRef cg, bool takeOwnership=false)
Definition: qt_mac_p.h:180
PasteboardRef OSPasteboardRef
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QColor qcolorForThemeTextColor(ThemeTextColor themeColor)
Definition: qt_mac.cpp:128
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
const char * mime
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
QMacCGContext(const QPaintDevice *pdev)
Definition: qt_mac_p.h:176
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void exec(bool)
Definition: qt_mac_p.h:163
The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress...
Definition: qevent.h:530
Qt::KeyboardModifiers modifiers
Definition: qt_mac_p.h:268
bool isNull() const
Definition: qt_mac_p.h:190
QString qt_mac_removeMnemonics(const QString &original)
OSPasteboardRef paste
Definition: qt_mac_p.h:223
uchar mime_type
Definition: qt_mac_p.h:224
QColor qcolorForTheme(ThemeBrush brush)
Definition: qt_mac.cpp:110
CGContextRef context
Definition: qt_mac_p.h:172
unsigned char uchar
Definition: qglobal.h:994
NSWindow * window
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QPoint qt_mac_nativeMapFromParent(const QWidget *child, const QPoint &pt)
QList< Promise > promises
Definition: qt_mac_p.h:221
WindowRef OSWindowRef
CGContextRef qt_mac_cg_context(const QPaintDevice *pdev)
Returns the CoreGraphics CGContextRef of the paint device.
const char * name
QPointer< QMimeData > mime
Definition: qt_mac_p.h:225
void setFadeDuration(float durationInSecs)
Definition: qt_mac_p.h:136
void qt_mac_copy_answer_rect(const QDragMoveEvent &event)
Definition: qdnd_mac.mm:318
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
bool mac_mime_source
Definition: qt_mac_p.h:226
static const char * data(const QByteArray &arr)
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
DropAction
Definition: qnamespace.h:1597
QWidgetList m_windowsToFade
Definition: qt_mac_p.h:129
signed long OSStatus
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
struct OpaqueRgnHandle * RgnHandle
void * handle() const
Definition: qt_mac_p.h:149
Qt::MouseButtons buttons
Definition: qt_mac_p.h:269
QMacDndAnswerRecord qt_mac_dnd_answer_rec
Definition: qdnd_mac.mm:67
QFont qfontForThemeFont(ThemeFontID themeID)
Definition: qt_mac.cpp:56
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
static QList< QMacWindowChangeEvent * > * change_events
Definition: qt_mac_p.h:157
unsigned int lastOperation
Definition: qt_mac_p.h:271
QMacPasteboardMime * convertor
Definition: qt_mac_p.h:217
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
const UInt32 kEventClassQt
Definition: qt_mac_p.h:92
QMacCGContext & operator=(const QMacCGContext &copy)
Definition: qt_mac_p.h:192
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
OSViewRef qt_mac_nativeview_for(const QWidget *)
Definition: qwidget_mac.mm:419
QMacSmartQuickDrawRegion(RgnHandle rgn)
Definition: qt_mac_p.h:116
Qt::DropAction lastAction
Definition: qt_mac_p.h:270
virtual ~QMacWindowChangeEvent()
Definition: qt_mac_p.h:161
struct CGContext * CGContextRef
HIViewRef OSViewRef
float fadeDuration() const
Definition: qt_mac_p.h:137
OSWindowRef qt_mac_window_for(const QWidget *)
Definition: qwidget_mac.mm:484
QMacCGContext(const QMacCGContext &copy)
Definition: qt_mac_p.h:185
The QMacPasteboardMime class converts between a MIME type and a.
Definition: qmime.h:141
bool qt_mac_mouse_inside_answer_rect(QPoint mouse)
Definition: qdnd_mac.mm:328
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
void qt_mac_dispose_rgn(RgnHandle r)
QPaintDevice * qt_mac_safe_pdev