source: trunk/src/gui/kernel/qwidget_mac.mm@ 603

Last change on this file since 603 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

File size: 190.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42/****************************************************************************
43**
44** Copyright (c) 2007-2008, Apple, Inc.
45**
46** All rights reserved.
47**
48** Redistribution and use in source and binary forms, with or without
49** modification, are permitted provided that the following conditions are met:
50**
51** * Redistributions of source code must retain the above copyright notice,
52** this list of conditions and the following disclaimer.
53**
54** * Redistributions in binary form must reproduce the above copyright notice,
55** this list of conditions and the following disclaimer in the documentation
56** and/or other materials provided with the distribution.
57**
58** * Neither the name of Apple, Inc. nor the names of its contributors
59** may be used to endorse or promote products derived from this software
60** without specific prior written permission.
61**
62** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
63** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
64** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
65** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
66** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
67** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
68** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
69** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
70** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
71** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
72** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
73**
74****************************************************************************/
75
76#include <private/qt_mac_p.h>
77#include <private/qeventdispatcher_mac_p.h>
78
79#include "qapplication.h"
80#include "qapplication_p.h"
81#include "qbitmap.h"
82#include "qcursor.h"
83#include "qdesktopwidget.h"
84#include "qevent.h"
85#include "qfileinfo.h"
86#include "qimage.h"
87#include "qlayout.h"
88#include "qmenubar.h"
89#include <private/qbackingstore_p.h>
90#include <private/qwindowsurface_mac_p.h>
91#include <private/qpaintengine_mac_p.h>
92#include "qpainter.h"
93#include "qstyle.h"
94#include "qtimer.h"
95#include "qfocusframe.h"
96#include "qdebug.h"
97#include <private/qmainwindowlayout_p.h>
98
99#include <private/qabstractscrollarea_p.h>
100#include <qabstractscrollarea.h>
101#include <ApplicationServices/ApplicationServices.h>
102#include <limits.h>
103#include <private/qt_cocoa_helpers_mac_p.h>
104#include <private/qcocoaview_mac_p.h>
105#include <private/qcocoawindow_mac_p.h>
106#include <private/qcocoawindowdelegate_mac_p.h>
107#include <private/qcocoapanel_mac_p.h>
108
109#include "qwidget_p.h"
110#include "qevent_p.h"
111#include "qdnd_p.h"
112#include <QtGui/qgraphicsproxywidget.h>
113
114QT_BEGIN_NAMESPACE
115
116#define XCOORD_MAX 16383
117#define WRECT_MAX 8191
118
119#ifndef QT_MAC_USE_COCOA
120
121extern "C" {
122 extern OSStatus _HIViewScrollRectWithOptions(HIViewRef, const HIRect *, CGFloat, CGFloat,
123 OptionBits) __attribute__ ((weak));
124}
125#define kHIViewScrollRectAdjustInvalid 1
126#define kHIViewScrollRectDontInvalidateRevealedArea 2
127#endif
128
129
130/*****************************************************************************
131 QWidget debug facilities
132 *****************************************************************************/
133//#define DEBUG_WINDOW_RGNS
134//#define DEBUG_WINDOW_CREATE
135//#define DEBUG_WINDOW_STATE
136//#define DEBUG_WIDGET_PAINT
137
138/*****************************************************************************
139 QWidget globals
140 *****************************************************************************/
141#ifndef QT_MAC_USE_COCOA
142typedef QHash<Qt::WindowFlags, WindowGroupRef> WindowGroupHash;
143Q_GLOBAL_STATIC(WindowGroupHash, qt_mac_window_groups)
144const UInt32 kWidgetCreatorQt = kEventClassQt;
145enum {
146 kWidgetPropertyQWidget = 'QWId' //QWidget *
147};
148#endif
149
150static bool qt_mac_raise_process = true;
151static OSWindowRef qt_root_win = 0;
152QWidget *mac_mouse_grabber = 0;
153QWidget *mac_keyboard_grabber = 0;
154
155#ifndef QT_MAC_USE_COCOA
156#ifdef QT_NAMESPACE
157
158// produce the string "com.trolltech.qt-namespace.widget", where "namespace" is the contents of QT_NAMESPACE.
159#define SS(x) #x
160#define S0(x) SS(x)
161#define S "com.trolltech.qt-" S0(QT_NAMESPACE) ".widget"
162
163static CFStringRef kObjectQWidget = CFSTR(S);
164
165#undef SS
166#undef S0
167#undef S
168
169#else
170static CFStringRef kObjectQWidget = CFSTR("com.trolltech.qt.widget");
171#endif // QT_NAMESPACE
172#endif // QT_MAC_USE_COCOA
173
174/*****************************************************************************
175 Externals
176 *****************************************************************************/
177extern QWidget *qt_mac_modal_blocked(QWidget *); //qapplication_mac.mm
178extern void qt_event_request_activate(QWidget *); //qapplication_mac.mm
179extern bool qt_event_remove_activate(); //qapplication_mac.mm
180extern void qt_mac_event_release(QWidget *w); //qapplication_mac.mm
181extern void qt_event_request_showsheet(QWidget *); //qapplication_mac.mm
182extern void qt_event_request_window_change(QWidget *); //qapplication_mac.mm
183extern QPointer<QWidget> qt_mouseover; //qapplication_mac.mm
184extern IconRef qt_mac_create_iconref(const QPixmap &); //qpixmap_mac.cpp
185extern void qt_mac_set_cursor(const QCursor *, const QPoint &); //qcursor_mac.mm
186extern void qt_mac_update_cursor(); //qcursor_mac.mm
187extern bool qt_nograb();
188extern CGImageRef qt_mac_create_cgimage(const QPixmap &, bool); //qpixmap_mac.cpp
189extern RgnHandle qt_mac_get_rgn(); //qregion_mac.cpp
190extern QRegion qt_mac_convert_mac_region(RgnHandle rgn); //qregion_mac.cpp
191
192/*****************************************************************************
193 QWidget utility functions
194 *****************************************************************************/
195void Q_GUI_EXPORT qt_mac_set_raise_process(bool b) { qt_mac_raise_process = b; }
196static QSize qt_mac_desktopSize()
197{
198 int w = 0, h = 0;
199 CGDisplayCount cg_count;
200 CGGetActiveDisplayList(0, 0, &cg_count);
201 QVector<CGDirectDisplayID> displays(cg_count);
202 CGGetActiveDisplayList(cg_count, displays.data(), &cg_count);
203 Q_ASSERT(cg_count == (CGDisplayCount)displays.size());
204 for(int i = 0; i < (int)cg_count; ++i) {
205 CGRect r = CGDisplayBounds(displays.at(i));
206 w = qMax<int>(w, qRound(r.origin.x + r.size.width));
207 h = qMax<int>(h, qRound(r.origin.y + r.size.height));
208 }
209 return QSize(w, h);
210}
211
212#ifdef QT_MAC_USE_COCOA
213static NSDrawer *qt_mac_drawer_for(const QWidget *widget)
214{
215 // This only goes one level below the content view so start with the window.
216 // This works fine for straight Qt stuff, but runs into problems if we are
217 // embedding, but if that's the case, they probably want to be using
218 // NSDrawer directly.
219 NSView *widgetView = reinterpret_cast<NSView *>(widget->window()->winId());
220 NSArray *windows = [NSApp windows];
221 for (NSWindow *window in windows) {
222 NSArray *drawers = [window drawers];
223 for (NSDrawer *drawer in drawers) {
224 NSArray *views = [[drawer contentView] subviews];
225 for (NSView *view in views) {
226 if (view == widgetView)
227 return drawer;
228 }
229 }
230 }
231 return 0;
232}
233#endif
234
235static void qt_mac_destructView(OSViewRef view)
236{
237#ifdef QT_MAC_USE_COCOA
238 [view removeFromSuperview];
239 [view release];
240#else
241 HIViewRemoveFromSuperview(view);
242 CFRelease(view);
243#endif
244}
245
246static void qt_mac_destructWindow(OSWindowRef window)
247{