Update spec to build Qt 5.0
[profile/ivi/qtbase.git] / src / plugins / platforms / cocoa / qcocoahelpers.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the plugins 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 QCOCOAHELPERS_H
43 #define QCOCOAHELPERS_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It provides helper functions
50 // for the Cocoa lighthouse plugin. This header file may
51 // change from version to version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 #include "qt_mac_p.h"
56 #include <private/qguiapplication_p.h>
57 #include <QtGui/qscreen.h>
58
59 QT_BEGIN_NAMESPACE
60
61 class QPixmap;
62 class QString;
63
64 // Conversion functions
65 QStringList qt_mac_NSArrayToQStringList(void *nsarray);
66 void *qt_mac_QStringListToNSMutableArrayVoid(const QStringList &list);
67
68 inline NSMutableArray *qt_mac_QStringListToNSMutableArray(const QStringList &qstrlist)
69 { return reinterpret_cast<NSMutableArray *>(qt_mac_QStringListToNSMutableArrayVoid(qstrlist)); }
70
71 CGImageRef qt_mac_image_to_cgimage(const QImage &image);
72 NSImage *qt_mac_cgimage_to_nsimage(CGImageRef iamge);
73 NSImage *qt_mac_create_nsimage(const QPixmap &pm);
74
75 NSSize qt_mac_toNSSize(const QSize &qtSize);
76 NSRect qt_mac_toNSRect(const QRect &rect);
77 QRect qt_mac_toQRect(const NSRect &rect);
78
79 QColor qt_mac_toQColor(const NSColor *color);
80
81
82 // Creates a mutable shape, it's the caller's responsibility to release.
83 HIMutableShapeRef qt_mac_QRegionToHIMutableShape(const QRegion &region);
84
85 OSStatus qt_mac_drawCGImage(CGContextRef inContext, const CGRect *inBounds, CGImageRef inImage);
86
87 CGFloat qt_mac_get_scalefactor();
88
89 QChar qt_mac_qtKey2CocoaKey(Qt::Key key);
90 Qt::Key qt_mac_cocoaKey2QtKey(QChar keyCode);
91
92 NSDragOperation qt_mac_mapDropAction(Qt::DropAction action);
93 NSDragOperation qt_mac_mapDropActions(Qt::DropActions actions);
94 Qt::DropAction qt_mac_mapNSDragOperation(NSDragOperation nsActions);
95 Qt::DropActions qt_mac_mapNSDragOperations(NSDragOperation nsActions);
96
97 // Misc
98 void qt_mac_transformProccessToForegroundApplication();
99 QString qt_mac_removeMnemonics(const QString &original);
100 CGColorSpaceRef qt_mac_genericColorSpace();
101 CGColorSpaceRef qt_mac_displayColorSpace(const QWidget *widget);
102 CGColorSpaceRef qt_mac_colorSpaceForDeviceType(const QPaintDevice *paintDevice);
103 QString qt_mac_applicationName();
104
105 inline int qt_mac_flipYCoordinate(int y)
106 { return QGuiApplication::primaryScreen()->geometry().height() - y; }
107
108 inline qreal qt_mac_flipYCoordinate(qreal y)
109 { return QGuiApplication::primaryScreen()->geometry().height() - y; }
110
111 inline QPointF qt_mac_flipPoint(const NSPoint &p)
112 { return QPointF(p.x, qt_mac_flipYCoordinate(p.y)); }
113
114 inline NSPoint qt_mac_flipPoint(const QPoint &p)
115 { return NSMakePoint(p.x(), qt_mac_flipYCoordinate(p.y())); }
116
117 inline NSPoint qt_mac_flipPoint(const QPointF &p)
118 { return NSMakePoint(p.x(), qt_mac_flipYCoordinate(p.y())); }
119
120 NSRect qt_mac_flipRect(const QRect &rect, QWindow *window);
121
122 Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum);
123
124 bool qt_mac_execute_apple_script(const char *script, long script_len, AEDesc *ret);
125 bool qt_mac_execute_apple_script(const char *script, AEDesc *ret);
126 bool qt_mac_execute_apple_script(const QString &script, AEDesc *ret);
127
128 // strip out '&' characters, and convert "&&" to a single '&', in menu
129 // text - since menu text is sometimes decorated with these for Windows
130 // accelerators.
131 QString qt_mac_removeAmpersandEscapes(QString s);
132
133 enum {
134     QtCocoaEventSubTypeWakeup       = SHRT_MAX,
135     QtCocoaEventSubTypePostMessage  = SHRT_MAX-1
136 };
137
138 class QCocoaPostMessageArgs {
139 public:
140     id target;
141     SEL selector;
142     int argCount;
143     id arg1;
144     id arg2;
145     QCocoaPostMessageArgs(id target, SEL selector, int argCount=0, id arg1=0, id arg2=0)
146         : target(target), selector(selector), argCount(argCount), arg1(arg1), arg2(arg2)
147     {
148         [target retain];
149         [arg1 retain];
150         [arg2 retain];
151     }
152
153     ~QCocoaPostMessageArgs()
154     {
155         [arg2 release];
156         [arg1 release];
157         [target release];
158     }
159 };
160
161 CGContextRef qt_mac_cg_context(const QPaintDevice *pdev);
162 CGImageRef qt_mac_toCGImage(const QImage &qImage, bool isMask, uchar **dataCopy);
163
164 QT_END_NAMESPACE
165
166 #endif //QCOCOAHELPERS_H
167