author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 15:10:48 +0300 | |
changeset 30 | 5dc02b23752f |
parent 19 | fcece45ef507 |
child 33 | 3e2da88830cd |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
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> |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
113 |
#include "qmainwindow.h" |
0 | 114 |
|
115 |
QT_BEGIN_NAMESPACE |
|
116 |
||
117 |
#define XCOORD_MAX 16383 |
|
118 |
#define WRECT_MAX 8191 |
|
119 |
||
120 |
#ifndef QT_MAC_USE_COCOA |
|
121 |
||
122 |
extern "C" { |
|
123 |
extern OSStatus _HIViewScrollRectWithOptions(HIViewRef, const HIRect *, CGFloat, CGFloat, |
|
124 |
OptionBits) __attribute__ ((weak)); |
|
125 |
} |
|
126 |
#define kHIViewScrollRectAdjustInvalid 1 |
|
127 |
#define kHIViewScrollRectDontInvalidateRevealedArea 2 |
|
128 |
#endif |
|
129 |
||
130 |
||
131 |
/***************************************************************************** |
|
132 |
QWidget debug facilities |
|
133 |
*****************************************************************************/ |
|
134 |
//#define DEBUG_WINDOW_RGNS |
|
135 |
//#define DEBUG_WINDOW_CREATE |
|
136 |
//#define DEBUG_WINDOW_STATE |
|
137 |
//#define DEBUG_WIDGET_PAINT |
|
138 |
||
139 |
/***************************************************************************** |
|
140 |
QWidget globals |
|
141 |
*****************************************************************************/ |
|
142 |
#ifndef QT_MAC_USE_COCOA |
|
143 |
typedef QHash<Qt::WindowFlags, WindowGroupRef> WindowGroupHash; |
|
144 |
Q_GLOBAL_STATIC(WindowGroupHash, qt_mac_window_groups) |
|
145 |
const UInt32 kWidgetCreatorQt = kEventClassQt; |
|
146 |
enum { |
|
147 |
kWidgetPropertyQWidget = 'QWId' //QWidget * |
|
148 |
}; |
|
149 |
#endif |
|
150 |
||
151 |
static bool qt_mac_raise_process = true; |
|
152 |
static OSWindowRef qt_root_win = 0; |
|
153 |
QWidget *mac_mouse_grabber = 0; |
|
154 |
QWidget *mac_keyboard_grabber = 0; |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
155 |
extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp |
0 | 156 |
|
157 |
#ifndef QT_MAC_USE_COCOA |
|
158 |
#ifdef QT_NAMESPACE |
|
159 |
||
160 |
// produce the string "com.trolltech.qt-namespace.widget", where "namespace" is the contents of QT_NAMESPACE. |
|
161 |
#define SS(x) #x |
|
162 |
#define S0(x) SS(x) |
|
163 |
#define S "com.trolltech.qt-" S0(QT_NAMESPACE) ".widget" |
|
164 |
||
165 |
static CFStringRef kObjectQWidget = CFSTR(S); |
|
166 |
||
167 |
#undef SS |
|
168 |
#undef S0 |
|
169 |
#undef S |
|
170 |
||
171 |
#else |
|
172 |
static CFStringRef kObjectQWidget = CFSTR("com.trolltech.qt.widget"); |
|
173 |
#endif // QT_NAMESPACE |
|
174 |
#endif // QT_MAC_USE_COCOA |
|
175 |
||
176 |
/***************************************************************************** |
|
177 |
Externals |
|
178 |
*****************************************************************************/ |
|
179 |
extern QWidget *qt_mac_modal_blocked(QWidget *); //qapplication_mac.mm |
|
180 |
extern void qt_event_request_activate(QWidget *); //qapplication_mac.mm |
|
181 |
extern bool qt_event_remove_activate(); //qapplication_mac.mm |
|
182 |
extern void qt_mac_event_release(QWidget *w); //qapplication_mac.mm |
|
183 |
extern void qt_event_request_showsheet(QWidget *); //qapplication_mac.mm |
|
184 |
extern void qt_event_request_window_change(QWidget *); //qapplication_mac.mm |
|
185 |
extern QPointer<QWidget> qt_mouseover; //qapplication_mac.mm |
|
186 |
extern IconRef qt_mac_create_iconref(const QPixmap &); //qpixmap_mac.cpp |
|
187 |
extern void qt_mac_set_cursor(const QCursor *, const QPoint &); //qcursor_mac.mm |
|
188 |
extern void qt_mac_update_cursor(); //qcursor_mac.mm |
|
189 |
extern bool qt_nograb(); |
|
190 |
extern CGImageRef qt_mac_create_cgimage(const QPixmap &, bool); //qpixmap_mac.cpp |
|
191 |
extern RgnHandle qt_mac_get_rgn(); //qregion_mac.cpp |
|
192 |
extern QRegion qt_mac_convert_mac_region(RgnHandle rgn); //qregion_mac.cpp |
|
193 |
||
194 |
/***************************************************************************** |
|
195 |
QWidget utility functions |
|
196 |
*****************************************************************************/ |
|
197 |
void Q_GUI_EXPORT qt_mac_set_raise_process(bool b) { qt_mac_raise_process = b; } |
|
198 |
static QSize qt_mac_desktopSize() |
|
199 |
{ |
|
200 |
int w = 0, h = 0; |
|
201 |
CGDisplayCount cg_count; |
|
202 |
CGGetActiveDisplayList(0, 0, &cg_count); |
|
203 |
QVector<CGDirectDisplayID> displays(cg_count); |
|
204 |
CGGetActiveDisplayList(cg_count, displays.data(), &cg_count); |
|
205 |
Q_ASSERT(cg_count == (CGDisplayCount)displays.size()); |
|
206 |
for(int i = 0; i < (int)cg_count; ++i) { |
|
207 |
CGRect r = CGDisplayBounds(displays.at(i)); |
|
208 |
w = qMax<int>(w, qRound(r.origin.x + r.size.width)); |
|
209 |
h = qMax<int>(h, qRound(r.origin.y + r.size.height)); |
|
210 |
} |
|
211 |
return QSize(w, h); |
|
212 |
} |
|
213 |
||
214 |
#ifdef QT_MAC_USE_COCOA |
|
215 |
static NSDrawer *qt_mac_drawer_for(const QWidget *widget) |
|
216 |
{ |
|
217 |
// This only goes one level below the content view so start with the window. |
|
218 |
// This works fine for straight Qt stuff, but runs into problems if we are |
|
219 |
// embedding, but if that's the case, they probably want to be using |
|
220 |
// NSDrawer directly. |
|
221 |
NSView *widgetView = reinterpret_cast<NSView *>(widget->window()->winId()); |
|
222 |
NSArray *windows = [NSApp windows]; |
|
223 |
for (NSWindow *window in windows) { |
|
224 |
NSArray *drawers = [window drawers]; |
|
225 |
for (NSDrawer *drawer in drawers) { |
|
226 |
NSArray *views = [[drawer contentView] subviews]; |
|
227 |
for (NSView *view in views) { |
|
228 |
if (view == widgetView) |
|
229 |
return drawer; |
|
230 |
} |
|
231 |
} |
|
232 |
} |
|
233 |
return 0; |
|
234 |
} |
|
235 |
#endif |
|
236 |
||
237 |
static void qt_mac_destructView(OSViewRef view) |
|
238 |
{ |
|
239 |
#ifdef QT_MAC_USE_COCOA |
|
240 |
[view removeFromSuperview]; |
|
241 |
[view release]; |
|
242 |
#else |
|
243 |
HIViewRemoveFromSuperview(view); |
|
244 |
CFRelease(view); |
|
245 |
#endif |
|
246 |
} |
|
247 |
||
248 |
static void qt_mac_destructWindow(OSWindowRef window) |
|
249 |
{ |
|
250 |
#ifdef QT_MAC_USE_COCOA |
|
251 |
if ([window isVisible] && [window isSheet]){ |
|
252 |
[NSApp endSheet:window]; |
|
253 |
[window orderOut:window]; |
|
254 |
} |
|
255 |
||
256 |
[[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] resignDelegateForWindow:window]; |
|
257 |
[window release]; |
|
258 |
#else |
|
259 |
// Remove property to clean up memory: |
|
260 |
RemoveWindowProperty(window, kWidgetCreatorQt, kWidgetPropertyQWidget); |
|
261 |
CFRelease(window); |
|
262 |
#endif |
|
263 |
} |
|
264 |
||
265 |
static void qt_mac_destructDrawer(NSDrawer *drawer) |
|
266 |
{ |
|
267 |
#ifdef QT_MAC_USE_COCOA |
|
268 |
[[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] resignDelegateForDrawer:drawer]; |
|
269 |
[drawer release]; |
|
270 |
#else |
|
271 |
Q_UNUSED(drawer); |
|
272 |
#endif |
|
273 |
} |
|
274 |
||
275 |
bool qt_mac_can_clickThrough(const QWidget *w) |
|
276 |
{ |
|
277 |
static int qt_mac_carbon_clickthrough = -1; |
|
278 |
if (qt_mac_carbon_clickthrough < 0) |
|
279 |
qt_mac_carbon_clickthrough = !qgetenv("QT_MAC_NO_COCOA_CLICKTHROUGH").isEmpty(); |
|
280 |
bool ret = !qt_mac_carbon_clickthrough; |
|
281 |
for ( ; w; w = w->parentWidget()) { |
|
282 |
if (w->testAttribute(Qt::WA_MacNoClickThrough)) { |
|
283 |
ret = false; |
|
284 |
break; |
|
285 |
} |
|
286 |
} |
|
287 |
return ret; |
|
288 |
} |
|
289 |
||
290 |
bool qt_mac_is_macsheet(const QWidget *w) |
|
291 |
{ |
|
292 |
if (!w) |
|
293 |
return false; |
|
294 |
||
295 |
Qt::WindowModality modality = w->windowModality(); |
|
296 |
if (modality == Qt::ApplicationModal) |
|
297 |
return false; |
|
298 |
return w->parentWidget() && (modality == Qt::WindowModal || w->windowType() == Qt::Sheet); |
|
299 |
} |
|
300 |
||
301 |
bool qt_mac_is_macdrawer(const QWidget *w) |
|
302 |
{ |
|
303 |
return (w && w->parentWidget() && w->windowType() == Qt::Drawer); |
|
304 |
} |
|
305 |
||
306 |
bool qt_mac_insideKeyWindow(const QWidget *w) |
|
307 |
{ |
|
308 |
#ifdef QT_MAC_USE_COCOA |
|
309 |
return [[reinterpret_cast<NSView *>(w->winId()) window] isKeyWindow]; |
|
310 |
#else |
|
311 |
Q_UNUSED(w); |
|
312 |
#endif |
|
313 |
return false; |
|
314 |
} |
|
315 |
||
316 |
bool qt_mac_set_drawer_preferred_edge(QWidget *w, Qt::DockWidgetArea where) //users of Qt for Mac OS X can use this.. |
|
317 |
{ |
|
318 |
if(!qt_mac_is_macdrawer(w)) |
|
319 |
return false; |
|
320 |
||
321 |
#if QT_MAC_USE_COCOA |
|
322 |
NSDrawer *drawer = qt_mac_drawer_for(w); |
|
323 |
if (!drawer) |
|
324 |
return false; |
|
325 |
NSRectEdge edge; |
|
326 |
if (where & Qt::LeftDockWidgetArea) |
|
327 |
edge = NSMinXEdge; |
|
328 |
else if (where & Qt::RightDockWidgetArea) |
|
329 |
edge = NSMaxXEdge; |
|
330 |
else if (where & Qt::TopDockWidgetArea) |
|
331 |
edge = NSMaxYEdge; |
|
332 |
else if (where & Qt::BottomDockWidgetArea) |
|
333 |
edge = NSMinYEdge; |
|
334 |
else |
|
335 |
return false; |
|
336 |
||
337 |
if (edge == [drawer preferredEdge]) //no-op |
|
338 |
return false; |
|
339 |
||
340 |
if (w->isVisible()) { |
|
341 |
[drawer close]; |
|
342 |
[drawer openOnEdge:edge]; |
|
343 |
} |
|
344 |
[drawer setPreferredEdge:edge]; |
|
345 |
#else |
|
346 |
OSWindowRef window = qt_mac_window_for(w); |
|
347 |
OptionBits edge; |
|
348 |
if(where & Qt::LeftDockWidgetArea) |
|
349 |
edge = kWindowEdgeLeft; |
|
350 |
else if(where & Qt::RightDockWidgetArea) |
|
351 |
edge = kWindowEdgeRight; |
|
352 |
else if(where & Qt::TopDockWidgetArea) |
|
353 |
edge = kWindowEdgeTop; |
|
354 |
else if(where & Qt::BottomDockWidgetArea) |
|
355 |
edge = kWindowEdgeBottom; |
|
356 |
else |
|
357 |
return false; |
|
358 |
||
359 |
if(edge == GetDrawerPreferredEdge(window)) //no-op |
|
360 |
return false; |
|
361 |
||
362 |
//do it |
|
363 |
SetDrawerPreferredEdge(window, edge); |
|
364 |
if(w->isVisible()) { |
|
365 |
CloseDrawer(window, false); |
|
366 |
OpenDrawer(window, edge, true); |
|
367 |
} |
|
368 |
#endif |
|
369 |
return true; |
|
370 |
} |
|
371 |
||
372 |
#ifndef QT_MAC_USE_COCOA |
|
373 |
Q_GUI_EXPORT |
|
374 |
#endif |
|
375 |
QPoint qt_mac_posInWindow(const QWidget *w) |
|
376 |
{ |
|
377 |
QPoint ret = w->data->wrect.topLeft(); |
|
378 |
while(w && !w->isWindow()) { |
|
379 |
ret += w->pos(); |
|
380 |
w = w->parentWidget(); |
|
381 |
} |
|
382 |
return ret; |
|
383 |
} |
|
384 |
||
385 |
//find a QWidget from a OSWindowRef |
|
386 |
QWidget *qt_mac_find_window(OSWindowRef window) |
|
387 |
{ |
|
388 |
#ifdef QT_MAC_USE_COCOA |
|
389 |
return [window QT_MANGLE_NAMESPACE(qt_qwidget)]; |
|
390 |
#else |
|
391 |
if(!window) |
|
392 |
return 0; |
|
393 |
||
394 |
QWidget *ret; |
|
395 |
if(GetWindowProperty(window, kWidgetCreatorQt, kWidgetPropertyQWidget, sizeof(ret), 0, &ret) == noErr) |
|
396 |
return ret; |
|
397 |
return 0; |
|
398 |
#endif |
|
399 |
} |
|
400 |
||
401 |
inline static void qt_mac_set_fullscreen_mode(bool b) |
|
402 |
{ |
|
403 |
extern bool qt_mac_app_fullscreen; //qapplication_mac.mm |
|
404 |
if(qt_mac_app_fullscreen == b) |
|
405 |
return; |
|
406 |
qt_mac_app_fullscreen = b; |
|
407 |
if (b) { |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
408 |
SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar); |
0 | 409 |
} else { |
410 |
SetSystemUIMode(kUIModeNormal, 0); |
|
411 |
} |
|
412 |
} |
|
413 |
||
414 |
Q_GUI_EXPORT OSViewRef qt_mac_nativeview_for(const QWidget *w) |
|
415 |
{ |
|
416 |
return reinterpret_cast<OSViewRef>(w->data->winid); |
|
417 |
} |
|
418 |
||
419 |
Q_GUI_EXPORT OSViewRef qt_mac_get_contentview_for(OSWindowRef w) |
|
420 |
{ |
|
421 |
#ifdef QT_MAC_USE_COCOA |
|
422 |
return [w contentView]; |
|
423 |
#else |
|
424 |
HIViewRef contentView = 0; |
|
425 |
OSStatus err = GetRootControl(w, &contentView); // Returns the window's content view (Apple QA1214) |
|
426 |
if (err == errUnknownControl) { |
|
427 |
contentView = HIViewGetRoot(w); |
|
428 |
} else if (err != noErr) { |
|
429 |
qWarning("Qt:Could not get content or root view of window! %s:%d [%ld]", |
|
430 |
__FILE__, __LINE__, err); |
|
431 |
} |
|
432 |
return contentView; |
|
433 |
#endif |
|
434 |
} |
|
435 |
||
436 |
bool qt_mac_sendMacEventToWidget(QWidget *widget, EventRef ref) |
|
437 |
{ |
|
438 |
return widget->macEvent(0, ref); |
|
439 |
} |
|
440 |
||
441 |
Q_GUI_EXPORT OSWindowRef qt_mac_window_for(OSViewRef view) |
|
442 |
{ |
|
443 |
#ifdef QT_MAC_USE_COCOA |
|
444 |
if (view) |
|
445 |
return [view window]; |
|
446 |
return 0; |
|
447 |
#else |
|
448 |
return HIViewGetWindow(view); |
|
449 |
#endif |
|
450 |
} |
|
451 |
||
452 |
static bool qt_isGenuineQWidget(OSViewRef ref) |
|
453 |
{ |
|
454 |
#ifdef QT_MAC_USE_COCOA |
|
455 |
return [ref isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaView) class]]; |
|
456 |
#else |
|
457 |
return HIObjectIsOfClass(HIObjectRef(ref), kObjectQWidget); |
|
458 |
#endif |
|
459 |
} |
|
460 |
||
461 |
bool qt_isGenuineQWidget(const QWidget *window) |
|
462 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
463 |
if (!window) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
464 |
return false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
465 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
466 |
if (!window->internalWinId()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
467 |
return true; //alien |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
468 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
469 |
return qt_isGenuineQWidget(OSViewRef(window->internalWinId())); |
0 | 470 |
} |
471 |
||
472 |
Q_GUI_EXPORT OSWindowRef qt_mac_window_for(const QWidget *w) |
|
473 |
{ |
|
474 |
OSViewRef hiview = qt_mac_nativeview_for(w); |
|
475 |
if (hiview){ |
|
476 |
OSWindowRef window = qt_mac_window_for(hiview); |
|
477 |
if (!window && qt_isGenuineQWidget(hiview)) { |
|
478 |
QWidget *myWindow = w->window(); |
|
479 |
// This is a workaround for NSToolbar. When a widget is hidden |
|
480 |
// by clicking the toolbar button, Cocoa reparents the widgets |
|
481 |
// to another window (but Qt doesn't know about it). |
|
482 |
// When we start showing them, it reparents back, |
|
483 |
// but at this point it's window is nil, but the window it's being brought |
|
484 |
// into (the Qt one) is for sure created. |
|
485 |
// This stops the hierarchy moving under our feet. |
|
486 |
if (myWindow != w && qt_mac_window_for(qt_mac_nativeview_for(myWindow))) |
|
487 |
return qt_mac_window_for(qt_mac_nativeview_for(myWindow)); |
|
488 |
||
489 |
myWindow->d_func()->createWindow_sys(); |
|
490 |
// Reget the hiview since the "create window could potentially move the view (I guess). |
|
491 |
hiview = qt_mac_nativeview_for(w); |
|
492 |
window = qt_mac_window_for(hiview); |
|
493 |
} |
|
494 |
return window; |
|
495 |
} |
|
496 |
return 0; |
|
497 |
} |
|
498 |
#ifndef QT_MAC_USE_COCOA |
|
499 |
/* Checks if the current group is a 'stay on top' group. If so, the |
|
500 |
group gets removed from the hash table */ |
|
501 |
static void qt_mac_release_stays_on_top_group(WindowGroupRef group) |
|
502 |
{ |
|
503 |
for (WindowGroupHash::iterator it = qt_mac_window_groups()->begin(); it != qt_mac_window_groups()->end(); ++it) { |
|
504 |
if (it.value() == group) { |
|
505 |
qt_mac_window_groups()->remove(it.key()); |
|
506 |
return; |
|
507 |
} |
|
508 |
} |
|
509 |
} |
|
510 |
||
511 |
/* Use this function instead of ReleaseWindowGroup, this will be sure to release the |
|
512 |
stays on top window group (created with qt_mac_get_stays_on_top_group below) */ |
|
513 |
static void qt_mac_release_window_group(WindowGroupRef group) |
|
514 |
{ |
|
515 |
ReleaseWindowGroup(group); |
|
516 |
if (GetWindowGroupRetainCount(group) == 0) |
|
517 |
qt_mac_release_stays_on_top_group(group); |
|
518 |
} |
|
519 |
#define ReleaseWindowGroup(x) Are you sure you wanted to do that? (you wanted qt_mac_release_window_group) |
|
520 |
||
521 |
SInt32 qt_mac_get_group_level(WindowClass wclass) |
|
522 |
{ |
|
523 |
SInt32 group_level; |
|
524 |
CGWindowLevel tmpLevel; |
|
525 |
GetWindowGroupLevelOfType(GetWindowGroupOfClass(wclass), kWindowGroupLevelActive, &tmpLevel); |
|
526 |
group_level = tmpLevel; |
|
527 |
return group_level; |
|
528 |
} |
|
529 |
#endif |
|
530 |
||
531 |
#ifndef QT_MAC_USE_COCOA |
|
532 |
static void qt_mac_set_window_group(OSWindowRef window, Qt::WindowFlags flags, int level) |
|
533 |
{ |
|
534 |
WindowGroupRef group = 0; |
|
535 |
if (qt_mac_window_groups()->contains(flags)) { |
|
536 |
group = qt_mac_window_groups()->value(flags); |
|
537 |
RetainWindowGroup(group); |
|
538 |
} else { |
|
539 |
CreateWindowGroup(kWindowActivationScopeNone, &group); |
|
540 |
SetWindowGroupLevel(group, level); |
|
541 |
SetWindowGroupParent(group, GetWindowGroupOfClass(kAllWindowClasses)); |
|
542 |
qt_mac_window_groups()->insert(flags, group); |
|
543 |
} |
|
544 |
SetWindowGroup(window, group); |
|
545 |
} |
|
546 |
||
547 |
inline static void qt_mac_set_window_group_to_stays_on_top(OSWindowRef window, Qt::WindowType type) |
|
548 |
{ |
|
549 |
// We create one static stays on top window group so that |
|
550 |
// all stays on top (aka popups) will fall into the same |
|
551 |
// group and be able to be raise()'d with releation to one another (from |
|
552 |
// within the same window group). |
|
553 |
qt_mac_set_window_group(window, type|Qt::WindowStaysOnTopHint, qt_mac_get_group_level(kOverlayWindowClass)); |
|
554 |
} |
|
555 |
||
556 |
inline static void qt_mac_set_window_group_to_tooltip(OSWindowRef window) |
|
557 |
{ |
|
558 |
// Since new groups are created for 'stays on top' windows, the |
|
559 |
// same must be done for tooltips. Otherwise, tooltips would be drawn |
|
560 |
// below 'stays on top' widgets even tough they are on the same level. |
|
561 |
// Also, add 'two' to the group level to make sure they also get on top of popups. |
|
562 |
qt_mac_set_window_group(window, Qt::ToolTip, qt_mac_get_group_level(kHelpWindowClass)+2); |
|
563 |
} |
|
564 |
||
565 |
inline static void qt_mac_set_window_group_to_popup(OSWindowRef window) |
|
566 |
{ |
|
567 |
// In Qt, a popup is seen as a 'stay on top' window. |
|
568 |
// Since new groups are created for 'stays on top' windows, the |
|
569 |
// same must be done for popups. Otherwise, popups would be drawn |
|
570 |
// below 'stays on top' windows. Add 1 to get above pure stay-on-top windows. |
|
571 |
qt_mac_set_window_group(window, Qt::Popup, qt_mac_get_group_level(kOverlayWindowClass)+1); |
|
572 |
} |
|
573 |
#endif |
|
574 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
575 |
#ifdef QT_MAC_USE_COCOA |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
576 |
void qt_mac_set_needs_display(QWidget *widget, QRegion region) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
577 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
578 |
NSView *theNSView = qt_mac_nativeview_for(widget); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
579 |
if (region.isEmpty()) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
580 |
[theNSView setNeedsDisplay:YES]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
581 |
return; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
582 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
583 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
584 |
QVector<QRect> rects = region.rects(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
585 |
for (int i = 0; i<rects.count(); ++i) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
586 |
const QRect &rect = rects.at(i); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
587 |
NSRect nsrect = NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
588 |
[theNSView setNeedsDisplayInRect:nsrect]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
589 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
590 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
591 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
592 |
#endif |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
593 |
|
0 | 594 |
inline static bool updateRedirectedToGraphicsProxyWidget(QWidget *widget, const QRect &rect) |
595 |
{ |
|
596 |
if (!widget) |
|
597 |
return false; |
|
598 |
||
599 |
#ifndef QT_NO_GRAPHICSVIEW |
|
600 |
QWidget *tlw = widget->window(); |
|
601 |
QWExtra *extra = qt_widget_private(tlw)->extra; |
|
602 |
if (extra && extra->proxyWidget) { |
|
603 |
extra->proxyWidget->update(rect.translated(widget->mapTo(tlw, QPoint()))); |
|
604 |
return true; |
|
605 |
} |
|
606 |
#endif |
|
607 |
||
608 |
return false; |
|
609 |
} |
|
610 |
||
611 |
inline static bool updateRedirectedToGraphicsProxyWidget(QWidget *widget, const QRegion &rgn) |
|
612 |
{ |
|
613 |
if (!widget) |
|
614 |
return false; |
|
615 |
||
616 |
#ifndef QT_NO_GRAPHICSVIEW |
|
617 |
QWidget *tlw = widget->window(); |
|
618 |
QWExtra *extra = qt_widget_private(tlw)->extra; |
|
619 |
if (extra && extra->proxyWidget) { |
|
620 |
const QPoint offset(widget->mapTo(tlw, QPoint())); |
|
621 |
const QVector<QRect> rects = rgn.rects(); |
|
622 |
for (int i = 0; i < rects.size(); ++i) |
|
623 |
extra->proxyWidget->update(rects.at(i).translated(offset)); |
|
624 |
return true; |
|
625 |
} |
|
626 |
#endif |
|
627 |
||
628 |
return false; |
|
629 |
} |
|
630 |
||
631 |
void QWidgetPrivate::macUpdateIsOpaque() |
|
632 |
{ |
|
633 |
Q_Q(QWidget); |
|
634 |
if (!q->testAttribute(Qt::WA_WState_Created)) |
|
635 |
return; |
|
636 |
#ifndef QT_MAC_USE_COCOA |
|
637 |
HIViewFeatures bits; |
|
638 |
HIViewRef hiview = qt_mac_nativeview_for(q); |
|
639 |
HIViewGetFeatures(hiview, &bits); |
|
640 |
if ((bits & kHIViewIsOpaque) == isOpaque) |
|
641 |
return; |
|
642 |
if (isOpaque) { |
|
643 |
HIViewChangeFeatures(hiview, kHIViewIsOpaque, 0); |
|
644 |
} else { |
|
645 |
HIViewChangeFeatures(hiview, 0, kHIViewIsOpaque); |
|
646 |
} |
|
647 |
if (q->isVisible()) |
|
648 |
HIViewReshapeStructure(qt_mac_nativeview_for(q)); |
|
649 |
#else |
|
650 |
if (isRealWindow() && !q->testAttribute(Qt::WA_MacBrushedMetal)) { |
|
651 |
bool opaque = isOpaque; |
|
652 |
if (extra && extra->imageMask) |
|
653 |
opaque = false; // we are never opaque when we have a mask. |
|
654 |
[qt_mac_window_for(q) setOpaque:opaque]; |
|
655 |
} |
|
656 |
#endif |
|
657 |
} |
|
658 |
#ifdef QT_MAC_USE_COCOA |
|
659 |
static OSWindowRef qt_mac_create_window(QWidget *widget, WindowClass wclass, |
|
660 |
NSUInteger wattr, const QRect &crect) |
|
661 |
{ |
|
662 |
// Determine if we need to add in our "custom window" attribute. Cocoa is rather clever |
|
663 |
// in deciding if we need the maximize button or not (i.e., it's resizeable, so you |
|
664 |
// must need a maximize button). So, the only buttons we have control over are the |
|
665 |
// close and minimize buttons. If someone wants to customize and NOT have the maximize |
|
666 |
// button, then we have to do our hack. We only do it for these cases because otherwise |
|
667 |
// the window looks different when activated. This "QtMacCustomizeWindow" attribute is |
|
668 |
// intruding on a public space and WILL BREAK in the future. |
|
669 |
// One can hope that there is a more public API available by that time. |
|
670 |
Qt::WindowFlags flags = widget ? widget->windowFlags() : Qt::WindowFlags(0); |
|
671 |
if ((flags & Qt::CustomizeWindowHint)) { |
|
672 |
if ((flags & (Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint |
|
673 |
| Qt::WindowMinimizeButtonHint | Qt::WindowTitleHint)) |
|
674 |
&& !(flags & Qt::WindowMaximizeButtonHint)) |
|
675 |
wattr |= QtMacCustomizeWindow; |
|
676 |
} |
|
677 |
||
678 |
// If we haven't created the desktop widget, you have to pass the rectangle |
|
679 |
// in "cocoa coordinates" (i.e., top points to the lower left coordinate). |
|
680 |
// Otherwise, we do the conversion for you. Since we are the only ones that |
|
681 |
// create the desktop widget, this is OK (but confusing). |
|
682 |
NSRect geo = NSMakeRect(crect.left(), |
|
683 |
(qt_root_win != 0) ? flipYCoordinate(crect.bottom() + 1) : crect.top(), |
|
684 |
crect.width(), crect.height()); |
|
685 |
QMacCocoaAutoReleasePool pool; |
|
686 |
OSWindowRef window; |
|
687 |
switch (wclass) { |
|
688 |
case kMovableModalWindowClass: |
|
689 |
case kModalWindowClass: |
|
690 |
case kSheetWindowClass: |
|
691 |
case kFloatingWindowClass: |
|
692 |
case kOverlayWindowClass: |
|
693 |
case kHelpWindowClass: { |
|
694 |
NSPanel *panel; |
|
695 |
BOOL needFloating = NO; |
|
696 |
BOOL worksWhenModal = widget && (widget->windowType() == Qt::Popup); |
|
697 |
// Add in the extra flags if necessary. |
|
698 |
switch (wclass) { |
|
699 |
case kSheetWindowClass: |
|
700 |
wattr |= NSDocModalWindowMask; |
|
701 |
break; |
|
702 |
case kFloatingWindowClass: |
|
703 |
case kHelpWindowClass: |
|
704 |
needFloating = YES; |
|
705 |
wattr |= NSUtilityWindowMask; |
|
706 |
break; |
|
707 |
default: |
|
708 |
break; |
|
709 |
} |
|
710 |
panel = [[QT_MANGLE_NAMESPACE(QCocoaPanel) alloc] QT_MANGLE_NAMESPACE(qt_initWithQWidget):widget contentRect:geo styleMask:wattr]; |
|
711 |
[panel setFloatingPanel:needFloating]; |
|
712 |
[panel setWorksWhenModal:worksWhenModal]; |
|
713 |
window = panel; |
|
714 |
break; |
|
715 |
} |
|
716 |
case kDrawerWindowClass: { |
|
717 |
NSDrawer *drawer = [[NSDrawer alloc] initWithContentSize:geo.size preferredEdge:NSMinXEdge]; |
|
718 |
[[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] becomeDelegateForDrawer:drawer widget:widget]; |
|
719 |
QWidget *parentWidget = widget->parentWidget(); |
|
720 |
if (parentWidget) |
|
721 |
[drawer setParentWindow:qt_mac_window_for(parentWidget)]; |
|
722 |
[drawer setLeadingOffset:0.0]; |
|
723 |
[drawer setTrailingOffset:25.0]; |
|
724 |
window = [[drawer contentView] window]; // Just to make sure we actually return a window |
|
725 |
break; |
|
726 |
} |
|
727 |
default: |
|
728 |
window = [[QT_MANGLE_NAMESPACE(QCocoaWindow) alloc] QT_MANGLE_NAMESPACE(qt_initWithQWidget):widget contentRect:geo styleMask:wattr]; |
|
729 |
break; |
|
730 |
} |
|
731 |
qt_syncCocoaTitleBarButtons(window, widget); |
|
732 |
return window; |
|
733 |
} |
|
734 |
#else |
|
735 |
static OSWindowRef qt_mac_create_window(QWidget *, WindowClass wclass, WindowAttributes wattr, |
|
736 |
const QRect &crect) |
|
737 |
{ |
|
738 |
OSWindowRef window; |
|
739 |
Rect geo; |
|
740 |
SetRect(&geo, crect.left(), crect.top(), crect.right() + 1, crect.bottom() + 1); |
|
741 |
OSStatus err; |
|
742 |
if(geo.right <= geo.left) geo.right = geo.left + 1; |
|
743 |
if(geo.bottom <= geo.top) geo.bottom = geo.top + 1; |
|
744 |
Rect null_rect; |
|
745 |
SetRect(&null_rect, 0, 0, 1, 1); |
|
746 |
err = CreateNewWindow(wclass, wattr, &null_rect, &window); |
|
747 |
if(err == noErr) { |
|
748 |
err = SetWindowBounds(window, kWindowContentRgn, &geo); |
|
749 |
if(err != noErr) |
|
750 |
qWarning("QWidget: Internal error (%s:%d)", __FILE__, __LINE__); |
|
751 |
} |
|
752 |
return window; |
|
753 |
} |
|
754 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
755 |
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
756 |
/* We build the release package against the 10.4 SDK. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
757 |
So, to enable gestures for applications running on |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
758 |
10.6+, we define the missing constants here: */ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
759 |
enum { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
760 |
kEventClassGesture = 'gest', |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
761 |
kEventGestureStarted = 1, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
762 |
kEventGestureEnded = 2, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
763 |
kEventGestureMagnify = 4, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
764 |
kEventGestureSwipe = 5, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
765 |
kEventGestureRotate = 6, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
766 |
kEventParamRotationAmount = 'rota', |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
767 |
kEventParamSwipeDirection = 'swip', |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
768 |
kEventParamMagnificationAmount = 'magn' |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
769 |
}; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
770 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
771 |
|
0 | 772 |
// window events |
773 |
static EventTypeSpec window_events[] = { |
|
774 |
{ kEventClassWindow, kEventWindowClose }, |
|
775 |
{ kEventClassWindow, kEventWindowExpanded }, |
|
776 |
{ kEventClassWindow, kEventWindowHidden }, |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
777 |
{ kEventClassWindow, kEventWindowZoom }, |
0 | 778 |
{ kEventClassWindow, kEventWindowZoomed }, |
779 |
{ kEventClassWindow, kEventWindowCollapsed }, |
|
780 |
{ kEventClassWindow, kEventWindowToolbarSwitchMode }, |
|
781 |
{ kEventClassWindow, kEventWindowProxyBeginDrag }, |
|
782 |
{ kEventClassWindow, kEventWindowProxyEndDrag }, |
|
783 |
{ kEventClassWindow, kEventWindowResizeCompleted }, |
|
784 |
{ kEventClassWindow, kEventWindowBoundsChanging }, |
|
785 |
{ kEventClassWindow, kEventWindowGetRegion }, |
|
786 |
{ kEventClassWindow, kEventWindowGetClickModality }, |
|
787 |
{ kEventClassWindow, kEventWindowTransitionCompleted }, |
|
788 |
{ kEventClassGesture, kEventGestureStarted }, |
|
789 |
{ kEventClassGesture, kEventGestureEnded }, |
|
790 |
{ kEventClassGesture, kEventGestureMagnify }, |
|
791 |
{ kEventClassGesture, kEventGestureSwipe }, |
|
792 |
{ kEventClassGesture, kEventGestureRotate }, |
|
793 |
{ kEventClassMouse, kEventMouseDown } |
|
794 |
}; |
|
795 |
static EventHandlerUPP mac_win_eventUPP = 0; |
|
796 |
static void cleanup_win_eventUPP() |
|
797 |
{ |
|
798 |
DisposeEventHandlerUPP(mac_win_eventUPP); |
|
799 |
mac_win_eventUPP = 0; |
|
800 |
} |
|
801 |
static const EventHandlerUPP make_win_eventUPP() |
|
802 |
{ |
|
803 |
if(mac_win_eventUPP) |
|
804 |
return mac_win_eventUPP; |
|
805 |
qAddPostRoutine(cleanup_win_eventUPP); |
|
806 |
return mac_win_eventUPP = NewEventHandlerUPP(QWidgetPrivate::qt_window_event); |
|
807 |
} |
|
808 |
OSStatus QWidgetPrivate::qt_window_event(EventHandlerCallRef er, EventRef event, void *) |
|
809 |
{ |
|
810 |
QScopedLoopLevelCounter loopLevelCounter(qApp->d_func()->threadData); |
|
811 |
bool handled_event = true; |
|
812 |
UInt32 ekind = GetEventKind(event), eclass = GetEventClass(event); |
|
813 |
switch(eclass) { |
|
814 |
case kEventClassWindow: { |
|
815 |
WindowRef wid = 0; |
|
816 |
GetEventParameter(event, kEventParamDirectObject, typeWindowRef, 0, |
|
817 |
sizeof(WindowRef), 0, &wid); |
|
818 |
QWidget *widget = qt_mac_find_window(wid); |
|
819 |
if(!widget) { |
|
820 |
handled_event = false; |
|
821 |
} else if(ekind == kEventWindowGetClickModality) { |
|
822 |
// Carbon will send us kEventWindowGetClickModality before every |
|
823 |
// mouse press / release event. By returning 'true', we tell Carbon |
|
824 |
// that we would like the event target to receive the mouse event even |
|
825 |
// if the target is modally shaddowed. In Qt, this makes sense when we |
|
826 |
// e.g. have a popup showing, as the popup will grab the event |
|
827 |
// and perhaps use it to close itself. |
|
828 |
// By also setting the current modal window back into the event, we |
|
829 |
// help Carbon determining which window is supposed to be raised. |
|
830 |
handled_event = qApp->activePopupWidget() ? true : false; |
|
831 |
} else if(ekind == kEventWindowClose) { |
|
832 |
widget->d_func()->close_helper(QWidgetPrivate::CloseWithSpontaneousEvent); |
|
833 |
QMenuBar::macUpdateMenuBar(); |
|
834 |
} else if (ekind == kEventWindowTransitionCompleted) { |
|
835 |
WindowTransitionAction transitionAction; |
|
836 |
GetEventParameter(event, kEventParamWindowTransitionAction, typeWindowTransitionAction, |
|
837 |
0, sizeof(transitionAction), 0, &transitionAction); |
|
838 |
if (transitionAction == kWindowHideTransitionAction) |
|
839 |
widget->hide(); |
|
840 |
} else if(ekind == kEventWindowExpanded) { |
|
841 |
Qt::WindowStates currState = Qt::WindowStates(widget->data->window_state); |
|
842 |
Qt::WindowStates newState = currState; |
|
843 |
if (currState & Qt::WindowMinimized) |
|
844 |
newState &= ~Qt::WindowMinimized; |
|
845 |
if (!(currState & Qt::WindowActive)) |
|
846 |
newState |= Qt::WindowActive; |
|
847 |
if (newState != currState) { |
|
848 |
// newState will differ from currState if the window |
|
849 |
// was expanded after clicking on the jewels (as opposed |
|
850 |
// to calling QWidget::setWindowState) |
|
851 |
widget->data->window_state = newState; |
|
852 |
QWindowStateChangeEvent e(currState); |
|
853 |
QApplication::sendSpontaneousEvent(widget, &e); |
|
854 |
} |
|
855 |
||
856 |
QShowEvent qse; |
|
857 |
QApplication::sendSpontaneousEvent(widget, &qse); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
858 |
} else if(ekind == kEventWindowZoom) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
859 |
widget->d_func()->topData()->normalGeometry = widget->geometry(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
860 |
handled_event = false; |
0 | 861 |
} else if(ekind == kEventWindowZoomed) { |
862 |
WindowPartCode windowPart; |
|
863 |
GetEventParameter(event, kEventParamWindowPartCode, |
|
864 |
typeWindowPartCode, 0, sizeof(windowPart), 0, &windowPart); |
|
865 |
if(windowPart == inZoomIn && widget->isMaximized()) { |
|
866 |
||
867 |
widget->data->window_state = widget->data->window_state & ~Qt::WindowMaximized; |
|
868 |
QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state | Qt::WindowMaximized)); |
|
869 |
QApplication::sendSpontaneousEvent(widget, &e); |
|
870 |
} else if(windowPart == inZoomOut && !widget->isMaximized()) { |
|
871 |
widget->data->window_state = widget->data->window_state | Qt::WindowMaximized; |
|
872 |
QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state |
|
873 |
& ~Qt::WindowMaximized)); |
|
874 |
QApplication::sendSpontaneousEvent(widget, &e); |
|
875 |
} |
|
876 |
qt_button_down = 0; |
|
877 |
} else if(ekind == kEventWindowCollapsed) { |
|
878 |
if (!widget->isMinimized()) { |
|
879 |
widget->data->window_state = widget->data->window_state | Qt::WindowMinimized; |
|
880 |
QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state & ~Qt::WindowMinimized)); |
|
881 |
QApplication::sendSpontaneousEvent(widget, &e); |
|
882 |
} |
|
883 |
||
884 |
// Deactivate this window: |
|
885 |
if (widget->isActiveWindow() && !(widget->windowType() == Qt::Popup)) { |
|
886 |
QWidget *w = 0; |
|
887 |
if (widget->parentWidget()) |
|
888 |
w = widget->parentWidget()->window(); |
|
889 |
if (!w || (!w->isVisible() && !w->isMinimized())) { |
|
890 |
for (WindowPtr wp = GetFrontWindowOfClass(kDocumentWindowClass, true); |
|
891 |
wp; wp = GetNextWindowOfClass(wp, kDocumentWindowClass, true)) { |
|
892 |
if ((w = qt_mac_find_window(wp))) |
|
893 |
break; |
|
894 |
} |
|
895 |
} |
|
896 |
if(!(w && w->isVisible() && !w->isMinimized())) |
|
897 |
qApp->setActiveWindow(0); |
|
898 |
} |
|
899 |
||
900 |
//we send a hide to be like X11/Windows |
|
901 |
QEvent e(QEvent::Hide); |
|
902 |
QApplication::sendSpontaneousEvent(widget, &e); |
|
903 |
qt_button_down = 0; |
|
904 |
} else if(ekind == kEventWindowToolbarSwitchMode) { |
|
905 |
macSendToolbarChangeEvent(widget); |
|
906 |
HIToolbarRef toolbar; |
|
907 |
if (GetWindowToolbar(wid, &toolbar) == noErr) { |
|
908 |
if (toolbar) { |
|
909 |
// Let HIToolbar do its thang, but things like the OpenGL context |
|
910 |
// needs to know about it. |
|
911 |
CallNextEventHandler(er, event); |
|
912 |
qt_event_request_window_change(widget); |
|
913 |
widget->data->fstrut_dirty = true; |
|
914 |
} |
|
915 |
} |
|
916 |
} else if(ekind == kEventWindowGetRegion) { |
|
917 |
WindowRef window; |
|
918 |
GetEventParameter(event, kEventParamDirectObject, typeWindowRef, 0, |
|
919 |
sizeof(window), 0, &window); |
|
920 |
WindowRegionCode wcode; |
|
921 |
GetEventParameter(event, kEventParamWindowRegionCode, typeWindowRegionCode, 0, |
|
922 |
sizeof(wcode), 0, &wcode); |
|
923 |
if (wcode != kWindowOpaqueRgn){ |
|
924 |
// If the region is kWindowOpaqueRgn, don't call next |
|
925 |
// event handler cause this will make the shadow of |
|
926 |
// masked windows become offset. Unfortunately, we're not sure why. |
|
927 |
CallNextEventHandler(er, event); |
|
928 |
} |
|
929 |
RgnHandle rgn; |
|
930 |
GetEventParameter(event, kEventParamRgnHandle, typeQDRgnHandle, 0, |
|
931 |
sizeof(rgn), 0, &rgn); |
|
932 |
||
933 |
if(QWidgetPrivate::qt_widget_rgn(qt_mac_find_window(window), wcode, rgn, false)) |
|
934 |
SetEventParameter(event, kEventParamRgnHandle, typeQDRgnHandle, sizeof(rgn), &rgn); |
|
935 |
} else if(ekind == kEventWindowProxyBeginDrag) { |
|
936 |
QIconDragEvent e; |
|
937 |
QApplication::sendSpontaneousEvent(widget, &e); |
|
938 |
} else if(ekind == kEventWindowResizeCompleted) { |
|
939 |
// Create a mouse up event, since such an event is not send by carbon to the |
|
940 |
// application event handler (while a mouse down <b>is</b> on kEventWindowResizeStarted) |
|
941 |
EventRef mouseUpEvent; |
|
942 |
CreateEvent(0, kEventClassMouse, kEventMouseUp, 0, kEventAttributeUserEvent, &mouseUpEvent); |
|
943 |
UInt16 mbutton = kEventMouseButtonPrimary; |
|
944 |
SetEventParameter(mouseUpEvent, kEventParamMouseButton, typeMouseButton, sizeof(mbutton), &mbutton); |
|
945 |
WindowRef window; |
|
946 |
GetEventParameter(event, kEventParamDirectObject, typeWindowRef, 0, sizeof(window), 0, &window); |
|
947 |
Rect dragRect; |
|
948 |
GetWindowBounds(window, kWindowGrowRgn, &dragRect); |
|
949 |
Point pos = {dragRect.bottom, dragRect.right}; |
|
950 |
SetEventParameter(mouseUpEvent, kEventParamMouseLocation, typeQDPoint, sizeof(pos), &pos); |
|
951 |
SendEventToApplication(mouseUpEvent); |
|
952 |
ReleaseEvent(mouseUpEvent); |
|
953 |
} else if(ekind == kEventWindowBoundsChanging) { |
|
954 |
UInt32 flags = 0; |
|
955 |
GetEventParameter(event, kEventParamAttributes, typeUInt32, 0, |
|
956 |
sizeof(flags), 0, &flags); |
|
957 |
Rect nr; |
|
958 |
GetEventParameter(event, kEventParamCurrentBounds, typeQDRectangle, 0, |
|
959 |
sizeof(nr), 0, &nr); |
|
960 |
||
961 |
QRect newRect(nr.left, nr.top, nr.right - nr.left, nr.bottom - nr.top); |
|
962 |
||
963 |
QTLWExtra * const tlwExtra = widget->d_func()->maybeTopData(); |
|
964 |
if (tlwExtra && tlwExtra->isSetGeometry == 1) { |
|
965 |
widget->d_func()->setGeometry_sys_helper(newRect.left(), newRect.top(), newRect.width(), newRect.height(), tlwExtra->isMove); |
|
966 |
} else { |
|
967 |
//implicitly removes the maximized bit |
|
968 |
if((widget->data->window_state & Qt::WindowMaximized) && |
|
969 |
IsWindowInStandardState(wid, 0, 0)) { |
|
970 |
widget->data->window_state &= ~Qt::WindowMaximized; |
|
971 |
QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state |
|
972 |
| Qt::WindowMaximized)); |
|
973 |
QApplication::sendSpontaneousEvent(widget, &e); |
|
974 |
||
975 |
} |
|
976 |
||
977 |
handled_event = false; |
|
978 |
const QRect oldRect = widget->data->crect; |
|
979 |
if((flags & kWindowBoundsChangeOriginChanged)) { |
|
980 |
if(nr.left != oldRect.x() || nr.top != oldRect.y()) { |
|
981 |
widget->data->crect.moveTo(nr.left, nr.top); |
|
982 |
QMoveEvent qme(widget->data->crect.topLeft(), oldRect.topLeft()); |
|
983 |
QApplication::sendSpontaneousEvent(widget, &qme); |
|
984 |
} |
|
985 |
} |
|
986 |
if((flags & kWindowBoundsChangeSizeChanged)) { |
|
987 |
if (widget->isWindow()) { |
|
988 |
QSize newSize = QLayout::closestAcceptableSize(widget, newRect.size()); |
|
989 |
int dh = newSize.height() - newRect.height(); |
|
990 |
int dw = newSize.width() - newRect.width(); |
|
991 |
if (dw != 0 || dh != 0) { |
|
992 |
handled_event = true; // We want to change the bounds, so we handle the event |
|
993 |
||
994 |
// set the rect, so we can also do the resize down below (yes, we need to resize). |
|
995 |
newRect.setBottom(newRect.bottom() + dh); |
|
996 |
newRect.setRight(newRect.right() + dw); |
|
997 |
||
998 |
nr.left = newRect.x(); |
|
999 |
nr.top = newRect.y(); |
|
1000 |
nr.right = nr.left + newRect.width(); |
|
1001 |
nr.bottom = nr.top + newRect.height(); |
|
1002 |
SetEventParameter(event, kEventParamCurrentBounds, typeQDRectangle, sizeof(Rect), &nr); |
|
1003 |
} |
|
1004 |
} |
|
1005 |
||
1006 |
if (oldRect.width() != newRect.width() || oldRect.height() != newRect.height()) { |
|
1007 |
widget->data->crect.setSize(newRect.size()); |
|
1008 |
HIRect bounds = CGRectMake(0, 0, newRect.width(), newRect.height()); |
|
1009 |
||
1010 |
// If the WA_StaticContents attribute is set we can optimize the resize |
|
1011 |
// by only repainting the newly exposed area. We do this by disabling |
|
1012 |
// painting when setting the size of the view. The OS will invalidate |
|
1013 |
// the newly exposed area for us. |
|
1014 |
const bool staticContents = widget->testAttribute(Qt::WA_StaticContents); |
|
1015 |
const HIViewRef view = qt_mac_nativeview_for(widget); |
|
1016 |
if (staticContents) |
|
1017 |
HIViewSetDrawingEnabled(view, false); |
|
1018 |
HIViewSetFrame(view, &bounds); |
|
1019 |
if (staticContents) |
|
1020 |
HIViewSetDrawingEnabled(view, true); |
|
1021 |
||
1022 |
QResizeEvent qre(newRect.size(), oldRect.size()); |
|
1023 |
QApplication::sendSpontaneousEvent(widget, &qre); |
|
1024 |
qt_event_request_window_change(widget); |
|
1025 |
} |
|
1026 |
} |
|
1027 |
} |
|
1028 |
} else if (ekind == kEventWindowHidden) { |
|
1029 |
// Make sure that we also hide any visible sheets on our window. |
|
1030 |
// Cocoa does the right thing for us. |
|
1031 |
const QObjectList children = widget->children(); |
|
1032 |
const int childCount = children.count(); |
|
1033 |
for (int i = 0; i < childCount; ++i) { |
|
1034 |
QObject *obj = children.at(i); |
|
1035 |
if (obj->isWidgetType()) { |
|
1036 |
QWidget *widget = static_cast<QWidget *>(obj); |
|
1037 |
if (qt_mac_is_macsheet(widget) && widget->isVisible()) |
|
1038 |
widget->hide(); |
|
1039 |
} |
|
1040 |
} |
|
1041 |
} else { |
|
1042 |
handled_event = false; |
|
1043 |
} |
|
1044 |
break; } |
|
1045 |
case kEventClassMouse: { |
|
1046 |
#if 0 |
|
1047 |
return SendEventToApplication(event); |
|
1048 |
#endif |
|
1049 |
||
1050 |
bool send_to_app = false; |
|
1051 |
{ |
|
1052 |
WindowPartCode wpc; |
|
1053 |
if (GetEventParameter(event, kEventParamWindowPartCode, typeWindowPartCode, 0, |
|
1054 |
sizeof(wpc), 0, &wpc) == noErr && wpc != inContent) |
|
1055 |
send_to_app = true; |
|
1056 |
} |
|
1057 |
if(!send_to_app) { |
|
1058 |
WindowRef window; |
|
1059 |
if(GetEventParameter(event, kEventParamWindowRef, typeWindowRef, 0, |
|
1060 |
sizeof(window), 0, &window) == noErr) { |
|
1061 |
HIViewRef hiview; |
|
1062 |
if(HIViewGetViewForMouseEvent(HIViewGetRoot(window), event, &hiview) == noErr) { |
|
1063 |
if(QWidget *w = QWidget::find((WId)hiview)) { |
|
1064 |
#if 0 |
|
1065 |
send_to_app = !w->isActiveWindow(); |
|
1066 |
#else |
|
1067 |
Q_UNUSED(w); |
|
1068 |
send_to_app = true; |
|
1069 |
#endif |
|
1070 |
} |
|
1071 |
} |
|
1072 |
} |
|
1073 |
} |
|
1074 |
if(send_to_app) |
|
1075 |
return SendEventToApplication(event); |
|
1076 |
handled_event = false; |
|
1077 |
break; } |
|
1078 |
||
1079 |
case kEventClassGesture: { |
|
1080 |
// First, find the widget that was under |
|
1081 |
// the mouse when the gesture happened: |
|
1082 |
HIPoint screenLocation; |
|
1083 |
if (GetEventParameter(event, kEventParamMouseLocation, typeHIPoint, 0, |
|
1084 |
sizeof(screenLocation), 0, &screenLocation) != noErr) { |
|
1085 |
handled_event = false; |
|
1086 |
break; |
|
1087 |
} |
|
1088 |
QWidget *widget = QApplication::widgetAt(screenLocation.x, screenLocation.y); |
|
1089 |
if (!widget) { |
|
1090 |
handled_event = false; |
|
1091 |
break; |
|
1092 |
} |
|
1093 |
||
1094 |
QNativeGestureEvent qNGEvent; |
|
1095 |
qNGEvent.position = QPoint(screenLocation.x, screenLocation.y); |
|
1096 |
||
1097 |
switch (ekind) { |
|
1098 |
case kEventGestureStarted: |
|
1099 |
qNGEvent.gestureType = QNativeGestureEvent::GestureBegin; |
|
1100 |
break; |
|
1101 |
case kEventGestureEnded: |
|
1102 |
qNGEvent.gestureType = QNativeGestureEvent::GestureEnd; |
|
1103 |
break; |
|
1104 |
case kEventGestureRotate: { |
|
1105 |
CGFloat amount; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1106 |
if (GetEventParameter(event, kEventParamRotationAmount, 'cgfl', 0, |
0 | 1107 |
sizeof(amount), 0, &amount) != noErr) { |
1108 |
handled_event = false; |
|
1109 |
break; |
|
1110 |
} |
|
1111 |
qNGEvent.gestureType = QNativeGestureEvent::Rotate; |
|
1112 |
qNGEvent.percentage = float(-amount); |
|
1113 |
break; } |
|
1114 |
case kEventGestureSwipe: { |
|
1115 |
HIPoint swipeDirection; |
|
1116 |
if (GetEventParameter(event, kEventParamSwipeDirection, typeHIPoint, 0, |
|
1117 |
sizeof(swipeDirection), 0, &swipeDirection) != noErr) { |
|
1118 |
handled_event = false; |
|
1119 |
break; |
|
1120 |
} |
|
1121 |
qNGEvent.gestureType = QNativeGestureEvent::Swipe; |
|
1122 |
if (swipeDirection.x == 1) |
|
1123 |
qNGEvent.angle = 180.0f; |
|
1124 |
else if (swipeDirection.x == -1) |
|
1125 |
qNGEvent.angle = 0.0f; |
|
1126 |
else if (swipeDirection.y == 1) |
|
1127 |
qNGEvent.angle = 90.0f; |
|
1128 |
else if (swipeDirection.y == -1) |
|
1129 |
qNGEvent.angle = 270.0f; |
|
1130 |
break; } |
|
1131 |
case kEventGestureMagnify: { |
|
1132 |
CGFloat amount; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1133 |
if (GetEventParameter(event, kEventParamMagnificationAmount, 'cgfl', 0, |
0 | 1134 |
sizeof(amount), 0, &amount) != noErr) { |
1135 |
handled_event = false; |
|
1136 |
break; |
|
1137 |
} |
|
1138 |
qNGEvent.gestureType = QNativeGestureEvent::Zoom; |
|
1139 |
qNGEvent.percentage = float(amount); |
|
1140 |
break; } |
|
1141 |
} |
|
1142 |
||
1143 |
QApplication::sendSpontaneousEvent(widget, &qNGEvent); |
|
1144 |
break; } |
|
1145 |
||
1146 |
default: |
|
1147 |
handled_event = false; |
|
1148 |
} |
|
1149 |
if(!handled_event) //let the event go through |
|
1150 |
return eventNotHandledErr; |
|
1151 |
return noErr; //we eat the event |
|
1152 |
} |
|
1153 |
||
1154 |
// widget events |
|
1155 |
static HIObjectClassRef widget_class = 0; |
|
1156 |
static EventTypeSpec widget_events[] = { |
|
1157 |
{ kEventClassHIObject, kEventHIObjectConstruct }, |
|
1158 |
{ kEventClassHIObject, kEventHIObjectDestruct }, |
|
1159 |
||
1160 |
{ kEventClassControl, kEventControlDraw }, |
|
1161 |
{ kEventClassControl, kEventControlInitialize }, |
|
1162 |
{ kEventClassControl, kEventControlGetPartRegion }, |
|
1163 |
{ kEventClassControl, kEventControlGetClickActivation }, |
|
1164 |
{ kEventClassControl, kEventControlSetFocusPart }, |
|
1165 |
{ kEventClassControl, kEventControlDragEnter }, |
|
1166 |
{ kEventClassControl, kEventControlDragWithin }, |
|
1167 |
{ kEventClassControl, kEventControlDragLeave }, |
|
1168 |
{ kEventClassControl, kEventControlDragReceive }, |
|
1169 |
{ kEventClassControl, kEventControlOwningWindowChanged }, |
|
1170 |
{ kEventClassControl, kEventControlBoundsChanged }, |
|
1171 |
{ kEventClassControl, kEventControlGetSizeConstraints }, |
|
1172 |
{ kEventClassControl, kEventControlVisibilityChanged }, |
|
1173 |
||
1174 |
{ kEventClassMouse, kEventMouseDown }, |
|
1175 |
{ kEventClassMouse, kEventMouseUp }, |
|
1176 |
{ kEventClassMouse, kEventMouseMoved }, |
|
1177 |
{ kEventClassMouse, kEventMouseDragged } |
|
1178 |
}; |
|
1179 |
static EventHandlerUPP mac_widget_eventUPP = 0; |
|
1180 |
static void cleanup_widget_eventUPP() |
|
1181 |
{ |
|
1182 |
DisposeEventHandlerUPP(mac_widget_eventUPP); |
|
1183 |
mac_widget_eventUPP = 0; |
|
1184 |
} |
|
1185 |
static const EventHandlerUPP make_widget_eventUPP() |
|
1186 |
{ |
|
1187 |
if(mac_widget_eventUPP) |
|
1188 |
return mac_widget_eventUPP; |
|
1189 |
qAddPostRoutine(cleanup_widget_eventUPP); |
|
1190 |
return mac_widget_eventUPP = NewEventHandlerUPP(QWidgetPrivate::qt_widget_event); |
|
1191 |
} |
|
1192 |
OSStatus QWidgetPrivate::qt_widget_event(EventHandlerCallRef er, EventRef event, void *) |
|
1193 |
{ |
|
1194 |
QScopedLoopLevelCounter loopLevelCounter(QApplicationPrivate::instance()->threadData); |
|
1195 |
||
1196 |
bool handled_event = true; |
|
1197 |
UInt32 ekind = GetEventKind(event), eclass = GetEventClass(event); |
|
1198 |
switch(eclass) { |
|
1199 |
case kEventClassHIObject: { |
|
1200 |
HIViewRef view = 0; |
|
1201 |
GetEventParameter(event, kEventParamHIObjectInstance, typeHIObjectRef, |
|
1202 |
0, sizeof(view), 0, &view); |
|
1203 |
if(ekind == kEventHIObjectConstruct) { |
|
1204 |
if(view) { |
|
1205 |
HIViewChangeFeatures(view, kHIViewAllowsSubviews, 0); |
|
1206 |
SetEventParameter(event, kEventParamHIObjectInstance, |
|
1207 |
typeVoidPtr, sizeof(view), &view); |
|
1208 |
} |
|
1209 |
} else if(ekind == kEventHIObjectDestruct) { |
|
1210 |
//nothing to really do.. or is there? |
|
1211 |
} else { |
|
1212 |
handled_event = false; |
|
1213 |
} |
|
1214 |
break; } |
|
1215 |
case kEventClassControl: { |
|
1216 |
QWidget *widget = 0; |
|
1217 |
HIViewRef hiview = 0; |
|
1218 |
if(GetEventParameter(event, kEventParamDirectObject, typeControlRef, |
|
1219 |
0, sizeof(hiview), 0, &hiview) == noErr) |
|
1220 |
widget = QWidget::find((WId)hiview); |
|
1221 |
if (widget && widget->macEvent(er, event)) |
|
1222 |
return noErr; |
|
1223 |
if(ekind == kEventControlDraw) { |
|
1224 |
if(widget && qt_isGenuineQWidget(hiview)) { |
|
1225 |
||
1226 |
// if there is a window change event pending for any gl child wigets, |
|
1227 |
// send it immediately. (required for flicker-free resizing) |
|
1228 |
extern void qt_mac_send_posted_gl_updates(QWidget *widget); |
|
1229 |
qt_mac_send_posted_gl_updates(widget); |
|
1230 |
||
1231 |
if (QApplicationPrivate::graphicsSystem() && !widget->d_func()->paintOnScreen()) { |
|
1232 |
widget->d_func()->syncBackingStore(); |
|
1233 |
widget->d_func()->dirtyOnWidget = QRegion(); |
|
1234 |
return noErr; |
|
1235 |
} |
|
1236 |
||
1237 |
//requested rgn |
|
1238 |
RgnHandle rgn; |
|
1239 |
GetEventParameter(event, kEventParamRgnHandle, typeQDRgnHandle, 0, sizeof(rgn), 0, &rgn); |
|
1240 |
QRegion qrgn(qt_mac_convert_mac_region(rgn)); |
|
1241 |
||
1242 |
//update handles |
|
1243 |
GrafPtr qd = 0; |
|
1244 |
CGContextRef cg = 0; |
|
1245 |
if(GetEventParameter(event, kEventParamCGContextRef, typeCGContextRef, 0, sizeof(cg), 0, &cg) != noErr) { |
|
1246 |
Q_ASSERT(false); |
|
1247 |
} |
|
1248 |
widget->d_func()->hd = cg; |
|
1249 |
widget->d_func()->qd_hd = qd; |
|
1250 |
CGContextSaveGState(cg); |
|
1251 |
||
1252 |
#ifdef DEBUG_WIDGET_PAINT |
|
1253 |
const bool doDebug = true; |
|
1254 |
if(doDebug) { |
|
1255 |
qDebug("asked to draw %p[%p] [%s::%s] %p[%p] [%d] [%dx%d]", widget, hiview, widget->metaObject()->className(), |
|
1256 |
widget->objectName().local8Bit().data(), widget->parentWidget(), |
|
1257 |
(HIViewRef)(widget->parentWidget() ? qt_mac_nativeview_for(widget->parentWidget()) : (HIViewRef)0), |
|
1258 |
HIViewIsCompositingEnabled(hiview), qt_mac_posInWindow(widget).x(), qt_mac_posInWindow(widget).y()); |
|
1259 |
#if 0 |
|
1260 |
QVector<QRect> region_rects = qrgn.rects(); |
|
1261 |
qDebug("Region! %d", region_rects.count()); |
|
1262 |
for(int i = 0; i < region_rects.count(); i++) |
|
1263 |
qDebug("%d %d %d %d", region_rects[i].x(), region_rects[i].y(), |
|
1264 |
region_rects[i].width(), region_rects[i].height()); |
|
1265 |
region_rects = widget->d_func()->clp.rects(); |
|
1266 |
qDebug("Widget Region! %d", region_rects.count()); |
|
1267 |
for(int i = 0; i < region_rects.count(); i++) |
|
1268 |
qDebug("%d %d %d %d", region_rects[i].x(), region_rects[i].y(), |
|
1269 |
region_rects[i].width(), region_rects[i].height()); |
|
1270 |
#endif |
|
1271 |
} |
|
1272 |
#endif |
|
1273 |
if (widget->isVisible() && widget->updatesEnabled()) { //process the actual paint event. |
|
1274 |
if(widget->testAttribute(Qt::WA_WState_InPaintEvent)) |
|
1275 |
qWarning("QWidget::repaint: Recursive repaint detected"); |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1276 |
if (widget->isWindow() && !widget->d_func()->isOpaque |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1277 |
&& !widget->testAttribute(Qt::WA_MacBrushedMetal)) { |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1278 |
QRect qrgnRect = qrgn.boundingRect(); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1279 |
CGContextClearRect(cg, CGRectMake(qrgnRect.x(), qrgnRect.y(), qrgnRect.width(), qrgnRect.height())); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1280 |
} |
0 | 1281 |
|
1282 |
QPoint redirectionOffset(0, 0); |
|
1283 |
QWidget *tl = widget->window(); |
|
1284 |
if (tl) { |
|
1285 |
Qt::WindowFlags flags = tl->windowFlags(); |
|
1286 |
if (flags & Qt::FramelessWindowHint |
|
1287 |
|| (flags & Qt::CustomizeWindowHint && !(flags & Qt::WindowTitleHint))) { |
|
1288 |
if(tl->d_func()->extra && !tl->d_func()->extra->mask.isEmpty()) |
|
1289 |
redirectionOffset += tl->d_func()->extra->mask.boundingRect().topLeft(); |
|
1290 |
} |
|
1291 |
} |
|
1292 |
||
1293 |
//setup the context |
|
1294 |
widget->setAttribute(Qt::WA_WState_InPaintEvent); |
|
1295 |
QPaintEngine *engine = widget->paintEngine(); |
|
1296 |
if (engine) |
|
1297 |
engine->setSystemClip(qrgn); |
|
1298 |
||
1299 |
//handle the erase |
|
1300 |
if (engine && (!widget->testAttribute(Qt::WA_NoSystemBackground) |
|
1301 |
&& (widget->isWindow() || widget->autoFillBackground()) |
|
1302 |
|| widget->testAttribute(Qt::WA_TintedBackground) |
|
1303 |
|| widget->testAttribute(Qt::WA_StyledBackground))) { |
|
1304 |
#ifdef DEBUG_WIDGET_PAINT |
|
1305 |
if(doDebug) |
|
1306 |
qDebug(" Handling erase for [%s::%s]", widget->metaObject()->className(), |
|
1307 |
widget->objectName().local8Bit().data()); |
|
1308 |
#endif |
|
1309 |
if (!redirectionOffset.isNull()) |
|
1310 |
widget->d_func()->setRedirected(widget, redirectionOffset); |
|
1311 |
||
1312 |
bool was_unclipped = widget->testAttribute(Qt::WA_PaintUnclipped); |
|
1313 |
widget->setAttribute(Qt::WA_PaintUnclipped, false); |
|
1314 |
QPainter p(widget); |
|
1315 |
p.setClipping(false); |
|
1316 |
if(was_unclipped) |
|
1317 |
widget->setAttribute(Qt::WA_PaintUnclipped); |
|
1318 |
widget->d_func()->paintBackground(&p, qrgn, widget->isWindow() ? DrawAsRoot : 0); |
|
1319 |
if (widget->testAttribute(Qt::WA_TintedBackground)) { |
|
1320 |
QColor tint = widget->palette().window().color(); |
|
1321 |
tint.setAlphaF(.6); |
|
1322 |
const QVector<QRect> &rects = qrgn.rects(); |
|
1323 |
for (int i = 0; i < rects.size(); ++i) |
|
1324 |
p.fillRect(rects.at(i), tint); |
|
1325 |
} |
|
1326 |
p.end(); |
|
1327 |
if (!redirectionOffset.isNull()) |
|
1328 |
widget->d_func()->restoreRedirected(); |
|
1329 |
} |
|
1330 |
||
1331 |
if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget)) |
|
1332 |
CallNextEventHandler(er, event); |
|
1333 |
||
1334 |
//send the paint |
|
1335 |
redirectionOffset += widget->data->wrect.topLeft(); // Map from system to qt coordinates |
|
1336 |
if (!redirectionOffset.isNull()) |
|
1337 |
widget->d_func()->setRedirected(widget, redirectionOffset); |
|
1338 |
qrgn.translate(redirectionOffset); |
|
1339 |
QPaintEvent e(qrgn); |
|
1340 |
widget->d_func()->dirtyOnWidget = QRegion(); |
|
1341 |
#ifdef QT3_SUPPORT |
|
1342 |
e.setErased(true); |
|
1343 |
#endif |
|
1344 |
QApplication::sendSpontaneousEvent(widget, &e); |
|
1345 |
if (!redirectionOffset.isNull()) |
|
1346 |
widget->d_func()->restoreRedirected(); |
|
1347 |
||
1348 |
//cleanup |
|
1349 |
if (engine) |
|
1350 |
engine->setSystemClip(QRegion()); |
|
1351 |
||
1352 |
widget->setAttribute(Qt::WA_WState_InPaintEvent, false); |
|
1353 |
if(!widget->testAttribute(Qt::WA_PaintOutsidePaintEvent) && widget->paintingActive()) |
|
1354 |
qWarning("QWidget: It is dangerous to leave painters active on a widget outside of the PaintEvent"); |
|
1355 |
} |
|
1356 |
||
1357 |
widget->d_func()->hd = 0; |
|
1358 |
widget->d_func()->qd_hd = 0; |
|
1359 |
CGContextRestoreGState(cg); |
|
1360 |
} else if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget)) { |
|
1361 |
CallNextEventHandler(er, event); |
|
1362 |
} |
|
1363 |
} else if(ekind == kEventControlInitialize) { |
|
1364 |
if(HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget)) { |
|
1365 |
UInt32 features = kControlSupportsDragAndDrop | kControlSupportsClickActivation | kControlSupportsFocus; |
|
1366 |
SetEventParameter(event, kEventParamControlFeatures, typeUInt32, sizeof(features), &features); |
|
1367 |
} else { |
|
1368 |
handled_event = false; |
|
1369 |
} |
|
1370 |
} else if(ekind == kEventControlSetFocusPart) { |
|
1371 |
if(widget) { |
|
1372 |
ControlPartCode part; |
|
1373 |
GetEventParameter(event, kEventParamControlPart, typeControlPartCode, 0, |
|
1374 |
sizeof(part), 0, &part); |
|
1375 |
if(part == kControlFocusNoPart){ |
|
1376 |
if (widget->hasFocus()) |
|
1377 |
QApplicationPrivate::setFocusWidget(0, Qt::OtherFocusReason); |
|
1378 |
} else |
|
1379 |
widget->setFocus(); |
|
1380 |
} |
|
1381 |
if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget)) |
|
1382 |
CallNextEventHandler(er, event); |
|
1383 |
} else if(ekind == kEventControlGetClickActivation) { |
|
1384 |
ClickActivationResult clickT = kActivateAndIgnoreClick; |
|
1385 |
SetEventParameter(event, kEventParamClickActivation, typeClickActivationResult, |
|
1386 |
sizeof(clickT), &clickT); |
|
1387 |
} else if(ekind == kEventControlGetPartRegion) { |
|
1388 |
handled_event = false; |
|
1389 |
if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget) && CallNextEventHandler(er, event) == noErr) { |
|
1390 |
handled_event = true; |
|
1391 |
break; |
|
1392 |
} |
|
1393 |
if(widget && !widget->isWindow()) { |
|
1394 |
ControlPartCode part; |
|
1395 |
GetEventParameter(event, kEventParamControlPart, typeControlPartCode, 0, |
|
1396 |
sizeof(part), 0, &part); |
|
1397 |
if(part == kControlClickableMetaPart && widget->testAttribute(Qt::WA_TransparentForMouseEvents)) { |
|
1398 |
RgnHandle rgn; |
|
1399 |
GetEventParameter(event, kEventParamControlRegion, typeQDRgnHandle, 0, |
|
1400 |
sizeof(rgn), 0, &rgn); |
|
1401 |
SetEmptyRgn(rgn); |
|
1402 |
handled_event = true; |
|
1403 |
} else if(part == kControlStructureMetaPart || part == kControlClickableMetaPart) { |
|
1404 |
RgnHandle rgn; |
|
1405 |
GetEventParameter(event, kEventParamControlRegion, typeQDRgnHandle, 0, |
|
1406 |
sizeof(rgn), 0, &rgn); |
|
1407 |
SetRectRgn(rgn, 0, 0, widget->width(), widget->height()); |
|
1408 |
if(QWidgetPrivate::qt_widget_rgn(widget, kWindowStructureRgn, rgn, false)) |
|
1409 |
handled_event = true; |
|
1410 |
} else if(part == kControlOpaqueMetaPart) { |
|
1411 |
if(widget->d_func()->isOpaque) { |
|
1412 |
RgnHandle rgn; |
|
1413 |
GetEventParameter(event, kEventParamControlRegion, typeQDRgnHandle, 0, |
|
1414 |
sizeof(RgnHandle), 0, &rgn); |
|
1415 |
SetRectRgn(rgn, 0, 0, widget->width(), widget->height()); |
|
1416 |
QWidgetPrivate::qt_widget_rgn(widget, kWindowStructureRgn, rgn, false); |
|
1417 |
SetEventParameter(event, kEventParamControlRegion, typeQDRgnHandle, |
|
1418 |
sizeof(RgnHandle), &rgn); |
|
1419 |
handled_event = true; |
|
1420 |
} |
|
1421 |
} |
|
1422 |
} |
|
1423 |
} else if(ekind == kEventControlOwningWindowChanged) { |
|
1424 |
if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget)) |
|
1425 |
CallNextEventHandler(er, event); |
|
1426 |
if(widget && qt_mac_window_for(hiview)) { |
|
1427 |
WindowRef foo = 0; |
|
1428 |
GetEventParameter(event, kEventParamControlCurrentOwningWindow, typeWindowRef, 0, |
|
1429 |
sizeof(foo), 0, &foo); |
|
1430 |
widget->d_func()->initWindowPtr(); |
|
1431 |
} |
|
1432 |
if (widget) |
|
1433 |
qt_event_request_window_change(widget); |
|
1434 |
} else if(ekind == kEventControlDragEnter || ekind == kEventControlDragWithin || |
|
1435 |
ekind == kEventControlDragLeave || ekind == kEventControlDragReceive) { |
|
1436 |
// dnd are really handled in qdnd_mac.cpp, |
|
1437 |
// just modularize the code a little... |
|
1438 |
DragRef drag; |
|
1439 |
GetEventParameter(event, kEventParamDragRef, typeDragRef, 0, sizeof(drag), 0, &drag); |
|
1440 |
handled_event = false; |
|
1441 |
bool drag_allowed = false; |
|
1442 |
||
1443 |
QWidget *dropWidget = widget; |
|
1444 |
if (qobject_cast<QFocusFrame *>(widget)){ |
|
1445 |
// We might shadow widgets underneath the focus |
|
1446 |
// frame, so stay interrested, and let the dnd through |
|
1447 |
drag_allowed = true; |
|
1448 |
handled_event = true; |
|
1449 |
Point where; |
|
1450 |
GetDragMouse(drag, &where, 0); |
|
1451 |
dropWidget = QApplication::widgetAt(QPoint(where.h, where.v)); |
|
1452 |
||
1453 |
if (dropWidget != QDragManager::self()->currentTarget()) { |
|
1454 |
// We have to 'fake' enter and leave events for the shaddowed widgets: |
|
1455 |
if (ekind == kEventControlDragEnter) { |
|
1456 |
if (QDragManager::self()->currentTarget()) |
|
1457 |
QDragManager::self()->currentTarget()->d_func()->qt_mac_dnd_event(kEventControlDragLeave, drag); |
|
1458 |
if (dropWidget) { |
|
1459 |
dropWidget->d_func()->qt_mac_dnd_event(kEventControlDragEnter, drag); |
|
1460 |
} |
|
1461 |
// Set dropWidget to zero, so qt_mac_dnd_event |
|
1462 |
// doesn't get called a second time below: |
|
1463 |
dropWidget = 0; |
|
1464 |
} else if (ekind == kEventControlDragLeave) { |
|
1465 |
dropWidget = QDragManager::self()->currentTarget(); |
|
1466 |
if (dropWidget) { |
|
1467 |
dropWidget->d_func()->qt_mac_dnd_event(kEventControlDragLeave, drag); |
|
1468 |
} |
|
1469 |
// Set dropWidget to zero, so qt_mac_dnd_event |
|
1470 |
// doesn't get called a second time below: |
|
1471 |
dropWidget = 0; |
|
1472 |
} |
|
1473 |
} |
|
1474 |
} |
|
1475 |
||
1476 |
// Send the dnd event to the widget: |
|
1477 |
if (dropWidget && dropWidget->d_func()->qt_mac_dnd_event(ekind, drag)) { |
|
1478 |
drag_allowed = true; |
|
1479 |
handled_event = true; |
|
1480 |
} |
|
1481 |
||
1482 |
if (ekind == kEventControlDragEnter) { |
|
1483 |
// If we don't accept the enter event, we will |
|
1484 |
// receive no more drag events for this widget |
|
1485 |
const Boolean wouldAccept = drag_allowed ? true : false; |
|
1486 |
SetEventParameter(event, kEventParamControlWouldAcceptDrop, typeBoolean, |
|
1487 |
sizeof(wouldAccept), &wouldAccept); |
|
1488 |
} |
|
1489 |
} else if (ekind == kEventControlBoundsChanged) { |
|
1490 |
if (!widget || widget->isWindow() || widget->testAttribute(Qt::WA_Moved) || widget->testAttribute(Qt::WA_Resized)) { |
|
1491 |
handled_event = false; |
|
1492 |
} else { |
|
1493 |
// Sync our view in case some other (non-Qt) view is controlling us. |
|
1494 |
handled_event = true; |
|
1495 |
Rect newBounds; |
|
1496 |
GetEventParameter(event, kEventParamCurrentBounds, |
|
1497 |
typeQDRectangle, 0, sizeof(Rect), 0, &newBounds); |
|
1498 |
QRect rect(newBounds.left, newBounds.top, |
|
1499 |
newBounds.right - newBounds.left, newBounds.bottom - newBounds.top); |
|
1500 |
||
1501 |
bool moved = widget->testAttribute(Qt::WA_Moved); |
|
1502 |
bool resized = widget->testAttribute(Qt::WA_Resized); |
|
1503 |
widget->setGeometry(rect); |
|
1504 |
widget->setAttribute(Qt::WA_Moved, moved); |
|
1505 |
widget->setAttribute(Qt::WA_Resized, resized); |
|
1506 |
qt_event_request_window_change(widget); |
|
1507 |
} |
|
1508 |
} else if (ekind == kEventControlGetSizeConstraints) { |
|
1509 |
if (!widget || !qt_isGenuineQWidget(widget)) { |
|
1510 |
handled_event = false; |
|
1511 |
} else { |
|
1512 |
handled_event = true; |
|
1513 |
QWidgetItem item(widget); |
|
1514 |
QSize size = item.minimumSize(); |
|
1515 |
HISize hisize = { size.width(), size.height() }; |
|
1516 |
SetEventParameter(event, kEventParamMinimumSize, typeHISize, sizeof(HISize), &hisize); |
|
1517 |
size = item.maximumSize(); |
|
1518 |
hisize.width = size.width() + 2; // ### shouldn't have to add 2 (but it works). |
|
1519 |
hisize.height = size.height(); |
|
1520 |
SetEventParameter(event, kEventParamMaximumSize, typeHISize, sizeof(HISize), &hisize); |
|
1521 |
} |
|
1522 |
} else if (ekind == kEventControlVisibilityChanged) { |
|
1523 |
handled_event = false; |
|
1524 |
if (widget) { |
|
1525 |
qt_event_request_window_change(widget); |
|
1526 |
if (!HIViewIsVisible(HIViewRef(widget->winId()))) { |
|
1527 |
if (widget == qt_button_down) |
|
1528 |
qt_button_down = 0; |
|
1529 |
} |
|
1530 |
} |
|
1531 |
} |
|
1532 |
break; } |
|
1533 |
case kEventClassMouse: { |
|
1534 |
bool send_to_app = false; |
|
1535 |
if(qt_button_down) |
|
1536 |
send_to_app = true; |
|
1537 |
if(send_to_app) { |
|
1538 |
OSStatus err = SendEventToApplication(event); |
|
1539 |
if(err != noErr) |
|
1540 |
handled_event = false; |
|
1541 |
} else { |
|
1542 |
CallNextEventHandler(er, event); |
|
1543 |
} |
|
1544 |
break; } |
|
1545 |
default: |
|
1546 |
handled_event = false; |
|
1547 |
break; |
|
1548 |
} |
|
1549 |
if(!handled_event) //let the event go through |
|
1550 |
return eventNotHandledErr; |
|
1551 |
return noErr; //we eat the event |
|
1552 |
} |
|
1553 |
#endif |
|
1554 |
||
1555 |
OSViewRef qt_mac_create_widget(QWidget *widget, QWidgetPrivate *widgetPrivate, OSViewRef parent) |
|
1556 |
{ |
|
1557 |
#ifdef QT_MAC_USE_COCOA |
|
1558 |
QMacCocoaAutoReleasePool pool; |
|
1559 |
QT_MANGLE_NAMESPACE(QCocoaView) *view = [[QT_MANGLE_NAMESPACE(QCocoaView) alloc] initWithQWidget:widget widgetPrivate:widgetPrivate]; |
|
1560 |
if (view && parent) |
|
1561 |
[parent addSubview:view]; |
|
1562 |
return view; |
|
1563 |
#else |
|
1564 |
Q_UNUSED(widget); |
|
1565 |
Q_UNUSED(widgetPrivate); |
|
1566 |
if(!widget_class) { |
|
1567 |
OSStatus err = HIObjectRegisterSubclass(kObjectQWidget, kHIViewClassID, 0, make_widget_eventUPP(), |
|
1568 |
GetEventTypeCount(widget_events), widget_events, |
|
1569 |
0, &widget_class); |
|
1570 |
if (err && err != hiObjectClassExistsErr) |
|
1571 |
qWarning("QWidget: Internal error (%d)", __LINE__); |
|
1572 |
} |
|
1573 |
HIViewRef ret = 0; |
|
1574 |
if(HIObjectCreate(kObjectQWidget, 0, (HIObjectRef*)&ret) != noErr) |
|
1575 |
qWarning("QWidget: Internal error (%d)", __LINE__); |
|
1576 |
if(ret && parent) |
|
1577 |
HIViewAddSubview(parent, ret); |
|
1578 |
return ret; |
|
1579 |
#endif |
|
1580 |
} |
|
1581 |
||
1582 |
void qt_mac_unregister_widget() |
|
1583 |
{ |
|
1584 |
#ifndef QT_MAC_USE_COCOA |
|
1585 |
HIObjectUnregisterClass(widget_class); |
|
1586 |
widget_class = 0; |
|
1587 |
#endif |
|
1588 |
} |
|
1589 |
||
1590 |
void QWidgetPrivate::toggleDrawers(bool visible) |
|
1591 |
{ |
|
1592 |
for (int i = 0; i < children.size(); ++i) { |
|
1593 |
register QObject *object = children.at(i); |
|
1594 |
if (!object->isWidgetType()) |
|
1595 |
continue; |
|
1596 |
QWidget *widget = static_cast<QWidget*>(object); |
|
1597 |
if(qt_mac_is_macdrawer(widget)) { |
|
1598 |
if(visible) { |
|
1599 |
if (!widget->testAttribute(Qt::WA_WState_ExplicitShowHide)) |
|
1600 |
widget->show(); |
|
1601 |
} else { |
|
1602 |
widget->hide(); |
|
1603 |
widget->setAttribute(Qt::WA_WState_ExplicitShowHide, false); |
|
1604 |
} |
|
1605 |
} |
|
1606 |
} |
|
1607 |
} |
|
1608 |
||
1609 |
/***************************************************************************** |
|
1610 |
QWidgetPrivate member functions |
|
1611 |
*****************************************************************************/ |
|
1612 |
bool QWidgetPrivate::qt_mac_update_sizer(QWidget *w, int up) |
|
1613 |
{ |
|
1614 |
// I'm not sure what "up" is |
|
1615 |
if(!w || !w->isWindow()) |
|
1616 |
return false; |
|
1617 |
||
1618 |
QTLWExtra *topData = w->d_func()->topData(); |
|
1619 |
QWExtra *extraData = w->d_func()->extraData(); |
|
1620 |
// topData->resizer is only 4 bits, so subtracting -1 from zero causes bad stuff |
|
1621 |
// to happen, prevent that here (you really want the thing hidden). |
|
1622 |
if (up >= 0 || topData->resizer != 0) |
|
1623 |
topData->resizer += up; |
|
1624 |
OSWindowRef windowRef = qt_mac_window_for(OSViewRef(w->winId())); |
|
1625 |
{ |
|
1626 |
#ifndef QT_MAC_USE_COCOA |
|
1627 |
WindowClass wclass; |
|
1628 |
GetWindowClass(windowRef, &wclass); |
|
1629 |
if(!(GetAvailableWindowAttributes(wclass) & kWindowResizableAttribute)) |
|
1630 |
return true; |
|
1631 |
#endif |
|
1632 |
} |
|
1633 |
bool remove_grip = (topData->resizer || (w->windowFlags() & Qt::FramelessWindowHint) |
|
1634 |
|| (extraData->maxw && extraData->maxh && |
|
1635 |
extraData->maxw == extraData->minw && extraData->maxh == extraData->minh)); |
|
1636 |
#ifndef QT_MAC_USE_COCOA |
|
1637 |
WindowAttributes attr; |
|
1638 |
GetWindowAttributes(windowRef, &attr); |
|
1639 |
if(remove_grip) { |
|
1640 |
if(attr & kWindowResizableAttribute) { |
|
1641 |
ChangeWindowAttributes(qt_mac_window_for(w), kWindowNoAttributes, |
|
1642 |
kWindowResizableAttribute); |
|
1643 |
ReshapeCustomWindow(qt_mac_window_for(w)); |
|
1644 |
} |
|
1645 |
} else if(!(attr & kWindowResizableAttribute)) { |
|
1646 |
ChangeWindowAttributes(windowRef, kWindowResizableAttribute, |
|
1647 |
kWindowNoAttributes); |
|
1648 |
ReshapeCustomWindow(windowRef); |
|
1649 |
} |
|
1650 |
#else |
|
1651 |
[windowRef setShowsResizeIndicator:!remove_grip]; |
|
1652 |
#endif |
|
1653 |
return true; |
|
1654 |
} |
|
1655 |
||
1656 |
void QWidgetPrivate::qt_clean_root_win() |
|
1657 |
{ |
|
1658 |
#ifdef QT_MAC_USE_COCOA |
|
1659 |
[qt_root_win release]; |
|
1660 |
#else |
|
1661 |
if(!qt_root_win) |
|
1662 |
return; |
|
1663 |
CFRelease(qt_root_win); |
|
1664 |
#endif |
|
1665 |
qt_root_win = 0; |
|
1666 |
} |
|
1667 |
||
1668 |
bool QWidgetPrivate::qt_create_root_win() |
|
1669 |
{ |
|
1670 |
if(qt_root_win) |
|
1671 |
return false; |
|
1672 |
const QSize desktopSize = qt_mac_desktopSize(); |
|
1673 |
QRect desktopRect(QPoint(0, 0), desktopSize); |
|
1674 |
#ifdef QT_MAC_USE_COCOA |
|
1675 |
qt_root_win = qt_mac_create_window(0, kOverlayWindowClass, NSBorderlessWindowMask, desktopRect); |
|
1676 |
#else |
|
1677 |
WindowAttributes wattr = (kWindowCompositingAttribute | kWindowStandardHandlerAttribute); |
|
1678 |
qt_root_win = qt_mac_create_window(0, kOverlayWindowClass, wattr, desktopRect); |
|
1679 |
#endif |
|
1680 |
if(!qt_root_win) |
|
1681 |
return false; |
|
1682 |
qAddPostRoutine(qt_clean_root_win); |
|
1683 |
return true; |
|
1684 |
} |
|
1685 |
||
1686 |
bool QWidgetPrivate::qt_widget_rgn(QWidget *widget, short wcode, RgnHandle rgn, bool force = false) |
|
1687 |
{ |
|
1688 |
bool ret = false; |
|
1689 |
#ifndef QT_MAC_USE_COCOA |
|
1690 |
switch(wcode) { |
|
1691 |
case kWindowStructureRgn: { |
|
1692 |
if(widget) { |
|
1693 |
if(widget->d_func()->extra && !widget->d_func()->extra->mask.isEmpty()) { |
|
1694 |
QRegion rin = qt_mac_convert_mac_region(rgn); |
|
1695 |
if(!rin.isEmpty()) { |
|
1696 |
QPoint rin_tl = rin.boundingRect().topLeft(); //in offset |
|
1697 |
rin.translate(-rin_tl.x(), -rin_tl.y()); //bring into same space as below |
|
1698 |
QRegion mask = widget->d_func()->extra->mask; |
|
1699 |
Qt::WindowFlags flags = widget->windowFlags(); |
|
1700 |
if(widget->isWindow() |
|
1701 |
&& !(flags & Qt::FramelessWindowHint |
|
1702 |
|| (flags & Qt::CustomizeWindowHint && !(flags & Qt::WindowTitleHint)))) { |
|
1703 |
QRegion title; |
|
1704 |
{ |
|
1705 |
QMacSmartQuickDrawRegion rgn(qt_mac_get_rgn()); |
|
1706 |
GetWindowRegion(qt_mac_window_for(widget), kWindowTitleBarRgn, rgn); |
|
1707 |
title = qt_mac_convert_mac_region(rgn); |
|
1708 |
} |
|
1709 |
QRect br = title.boundingRect(); |
|
1710 |
mask.translate(0, br.height()); //put the mask 'under' the title bar.. |
|
1711 |
title.translate(-br.x(), -br.y()); |
|
1712 |
mask += title; |
|
1713 |
} |
|
1714 |
||
1715 |
QRegion cr = rin & mask; |
|
1716 |
cr.translate(rin_tl.x(), rin_tl.y()); //translate back to incoming space |
|
1717 |
CopyRgn(QMacSmartQuickDrawRegion(cr.toQDRgn()), rgn); |
|
1718 |
} |
|
1719 |
ret = true; |
|
1720 |
} else if(force) { |
|
1721 |
QRegion cr(widget->geometry()); |
|
1722 |
CopyRgn(QMacSmartQuickDrawRegion(cr.toQDRgn()), rgn); |
|
1723 |
ret = true; |
|
1724 |
} |
|
1725 |
} |
|
1726 |
break; } |
|
1727 |
default: break; |
|
1728 |
} |
|
1729 |
//qDebug() << widget << ret << wcode << qt_mac_convert_mac_region(rgn); |
|
1730 |
#else |
|
1731 |
Q_UNUSED(widget); |
|
1732 |
Q_UNUSED(wcode); |
|
1733 |
Q_UNUSED(rgn); |
|
1734 |
Q_UNUSED(force); |
|
1735 |
#endif |
|
1736 |
return ret; |
|
1737 |
} |
|
1738 |
||
1739 |
/***************************************************************************** |
|
1740 |
QWidget member functions |
|
1741 |
*****************************************************************************/ |
|
1742 |
void QWidgetPrivate::determineWindowClass() |
|
1743 |
{ |
|
1744 |
Q_Q(QWidget); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1745 |
#if !defined(QT_NO_MAINWINDOW) && !defined(QT_NO_TOOLBAR) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1746 |
// Make sure that QMainWindow has the MacWindowToolBarButtonHint when the |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1747 |
// unifiedTitleAndToolBarOnMac property is ON. This is to avoid reentry of |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1748 |
// setParent() triggered by the QToolBar::event(QEvent::ParentChange). |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1749 |
QMainWindow *mainWindow = qobject_cast<QMainWindow *>(q); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1750 |
if (mainWindow && mainWindow->unifiedTitleAndToolBarOnMac()) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1751 |
data.window_flags |= Qt::MacWindowToolBarButtonHint; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1752 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1753 |
#endif |
0 | 1754 |
#ifndef QT_MAC_USE_COCOA |
1755 |
// ### COCOA:Interleave these better! |
|
1756 |
||
1757 |
const Qt::WindowType type = q->windowType(); |
|
1758 |
Qt::WindowFlags &flags = data.window_flags; |
|
1759 |
const bool popup = (type == Qt::Popup); |
|
1760 |
if (type == Qt::ToolTip || type == Qt::SplashScreen || popup) |
|
1761 |
flags |= Qt::FramelessWindowHint; |
|
1762 |
||
1763 |
WindowClass wclass = kSheetWindowClass; |
|
1764 |
if(qt_mac_is_macdrawer(q)) |
|
1765 |
wclass = kDrawerWindowClass; |
|
1766 |
else if (q->testAttribute(Qt::WA_ShowModal) && flags & Qt::CustomizeWindowHint) |
|
1767 |
wclass = kDocumentWindowClass; |
|
1768 |
else if(popup || (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5 && type == Qt::SplashScreen)) |
|
1769 |
wclass = kModalWindowClass; |
|
1770 |
else if(q->testAttribute(Qt::WA_ShowModal)) |
|
1771 |
wclass = kMovableModalWindowClass; |
|
1772 |
else if(type == Qt::ToolTip) |
|
1773 |
wclass = kHelpWindowClass; |
|
1774 |
else if(type == Qt::Tool || (QSysInfo::MacintoshVersion < QSysInfo::MV_10_5 |
|
1775 |
&& type == Qt::SplashScreen)) |
|
1776 |
wclass = kFloatingWindowClass; |
|
1777 |
else |
|
1778 |
wclass = kDocumentWindowClass; |
|
1779 |
||
1780 |
WindowGroupRef grp = 0; |
|
1781 |
WindowAttributes wattr = (kWindowCompositingAttribute | kWindowStandardHandlerAttribute); |
|
1782 |
if (q->testAttribute(Qt::WA_MacFrameworkScaled)) |
|
1783 |
wattr |= kWindowFrameworkScaledAttribute; |
|
1784 |
if(qt_mac_is_macsheet(q)) { |
|
1785 |
//grp = GetWindowGroupOfClass(kMovableModalWindowClass); |
|
1786 |
wclass = kSheetWindowClass; |
|
1787 |
} else { |
|
1788 |
grp = GetWindowGroupOfClass(wclass); |
|
1789 |
// Shift things around a bit to get the correct window class based on the presence |
|
1790 |
// (or lack) of the border. |
|
1791 |
bool customize = flags & Qt::CustomizeWindowHint; |
|
1792 |
bool framelessWindow = (flags & Qt::FramelessWindowHint || (customize && !(flags & Qt::WindowTitleHint))); |
|
1793 |
if (framelessWindow) { |
|
1794 |
if(wclass == kDocumentWindowClass) { |
|
1795 |
wattr |= kWindowNoTitleBarAttribute; |
|
1796 |
} else if(wclass == kFloatingWindowClass) { |
|
1797 |
wattr |= kWindowNoTitleBarAttribute; |
|
1798 |
} else if (wclass == kMovableModalWindowClass) { |
|
1799 |
wclass = kModalWindowClass; |
|
1800 |
} |
|
1801 |
} else { |
|
1802 |
if(wclass != kModalWindowClass) |
|
1803 |
wattr |= kWindowResizableAttribute; |
|
1804 |
} |
|
1805 |
// Only add extra decorations (well, buttons) for widgets that can have them |
|
1806 |
// and have an actual border we can put them on. |
|
1807 |
if(wclass != kModalWindowClass && wclass != kMovableModalWindowClass |
|
1808 |
&& wclass != kSheetWindowClass && wclass != kPlainWindowClass |
|
1809 |
&& !framelessWindow && wclass != kDrawerWindowClass |
|
1810 |
&& wclass != kHelpWindowClass) { |
|
1811 |
if (flags & Qt::WindowMaximizeButtonHint) |
|
1812 |
wattr |= kWindowFullZoomAttribute; |
|
1813 |
if (flags & Qt::WindowMinimizeButtonHint) |
|
1814 |
wattr |= kWindowCollapseBoxAttribute; |
|
1815 |
if (flags & Qt::WindowSystemMenuHint || flags & Qt::WindowCloseButtonHint) |
|
1816 |
wattr |= kWindowCloseBoxAttribute; |
|
1817 |
if (flags & Qt::MacWindowToolBarButtonHint) |
|
1818 |
wattr |= kWindowToolbarButtonAttribute; |
|
1819 |
} else { |
|
1820 |
// Clear these hints so that we aren't call them on invalid windows |
|
1821 |
flags &= ~(Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint |
|
1822 |
| Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint); |
|
1823 |
} |
|
1824 |
} |
|
1825 |
if((popup || type == Qt::Tool) && !q->isModal()) |
|
1826 |
wattr |= kWindowHideOnSuspendAttribute; |
|
1827 |
wattr |= kWindowLiveResizeAttribute; |
|
1828 |
||
1829 |
#ifdef DEBUG_WINDOW_CREATE |
|
1830 |
#define ADD_DEBUG_WINDOW_NAME(x) { x, #x } |
|
1831 |
struct { |
|
1832 |
UInt32 tag; |
|
1833 |
const char *name; |
|
1834 |
} known_attribs[] = { |
|
1835 |
ADD_DEBUG_WINDOW_NAME(kWindowCompositingAttribute), |
|
1836 |
ADD_DEBUG_WINDOW_NAME(kWindowStandardHandlerAttribute), |
|
1837 |
ADD_DEBUG_WINDOW_NAME(kWindowMetalAttribute), |
|
1838 |
ADD_DEBUG_WINDOW_NAME(kWindowHideOnSuspendAttribute), |
|
1839 |
ADD_DEBUG_WINDOW_NAME(kWindowStandardHandlerAttribute), |
|
1840 |
ADD_DEBUG_WINDOW_NAME(kWindowCollapseBoxAttribute), |
|
1841 |
ADD_DEBUG_WINDOW_NAME(kWindowHorizontalZoomAttribute), |
|
1842 |
ADD_DEBUG_WINDOW_NAME(kWindowVerticalZoomAttribute), |
|
1843 |
ADD_DEBUG_WINDOW_NAME(kWindowResizableAttribute), |
|
1844 |
ADD_DEBUG_WINDOW_NAME(kWindowNoActivatesAttribute), |
|
1845 |
ADD_DEBUG_WINDOW_NAME(kWindowNoUpdatesAttribute), |
|
1846 |
ADD_DEBUG_WINDOW_NAME(kWindowOpaqueForEventsAttribute), |
|
1847 |
ADD_DEBUG_WINDOW_NAME(kWindowLiveResizeAttribute), |
|
1848 |
ADD_DEBUG_WINDOW_NAME(kWindowCloseBoxAttribute), |
|
1849 |
ADD_DEBUG_WINDOW_NAME(kWindowHideOnSuspendAttribute), |
|
1850 |
{ 0, 0 } |
|
1851 |
}, known_classes[] = { |
|
1852 |
ADD_DEBUG_WINDOW_NAME(kHelpWindowClass), |
|
1853 |
ADD_DEBUG_WINDOW_NAME(kPlainWindowClass), |
|
1854 |
ADD_DEBUG_WINDOW_NAME(kDrawerWindowClass), |
|
1855 |
ADD_DEBUG_WINDOW_NAME(kUtilityWindowClass), |
|
1856 |
ADD_DEBUG_WINDOW_NAME(kToolbarWindowClass), |
|
1857 |
ADD_DEBUG_WINDOW_NAME(kSheetWindowClass), |
|
1858 |
ADD_DEBUG_WINDOW_NAME(kFloatingWindowClass), |
|
1859 |
ADD_DEBUG_WINDOW_NAME(kUtilityWindowClass), |
|
1860 |
ADD_DEBUG_WINDOW_NAME(kDocumentWindowClass), |
|
1861 |
ADD_DEBUG_WINDOW_NAME(kToolbarWindowClass), |
|
1862 |
ADD_DEBUG_WINDOW_NAME(kMovableModalWindowClass), |
|
1863 |
ADD_DEBUG_WINDOW_NAME(kModalWindowClass), |
|
1864 |
{ 0, 0 } |
|
1865 |
}; |
|
1866 |
qDebug("Qt: internal: ************* Creating new window %p (%s::%s)", q, q->metaObject()->className(), |
|
1867 |
q->objectName().toLocal8Bit().constData()); |
|
1868 |
bool found_class = false; |
|
1869 |
for(int i = 0; known_classes[i].name; i++) { |
|
1870 |
if(wclass == known_classes[i].tag) { |
|
1871 |
found_class = true; |
|
1872 |
qDebug("Qt: internal: ** Class: %s", known_classes[i].name); |
|
1873 |
break; |
|
1874 |
} |
|
1875 |
} |
|
1876 |
if(!found_class) |
|
1877 |
qDebug("Qt: internal: !! Class: Unknown! (%d)", (int)wclass); |
|
1878 |
if(wattr) { |
|
1879 |
WindowAttributes tmp_wattr = wattr; |
|
1880 |
qDebug("Qt: internal: ** Attributes:"); |
|
1881 |
for(int i = 0; tmp_wattr && known_attribs[i].name; i++) { |
|
1882 |
if((tmp_wattr & known_attribs[i].tag) == known_attribs[i].tag) { |
|
1883 |
tmp_wattr ^= known_attribs[i].tag; |
|
1884 |
qDebug("Qt: internal: * %s %s", known_attribs[i].name, |
|
1885 |
(GetAvailableWindowAttributes(wclass) & known_attribs[i].tag) ? "" : "(*)"); |
|
1886 |
} |
|
1887 |
} |
|
1888 |
if(tmp_wattr) |
|
1889 |
qDebug("Qt: internal: !! Attributes: Unknown (%d)", (int)tmp_wattr); |
|
1890 |
} |
|
1891 |
#endif |
|
1892 |
||
1893 |
/* Just to be extra careful we will change to the kUtilityWindowClass if the |
|
1894 |
requested attributes cannot be used */ |
|
1895 |
if((GetAvailableWindowAttributes(wclass) & wattr) != wattr) { |
|
1896 |
WindowClass tmp_class = wclass; |
|
1897 |
if(wclass == kToolbarWindowClass || wclass == kUtilityWindowClass) |
|
1898 |
wclass = kFloatingWindowClass; |
|
1899 |
if(tmp_class != wclass) { |
|
1900 |
if(!grp) |
|
1901 |
grp = GetWindowGroupOfClass(wclass); |
|
1902 |
wclass = tmp_class; |
|
1903 |
} |
|
1904 |
} |
|
1905 |
topData()->wclass = wclass; |
|
1906 |
topData()->wattr = wattr; |
|
1907 |
#else |
|
1908 |
const Qt::WindowType type = q->windowType(); |
|
1909 |
Qt::WindowFlags &flags = data.window_flags; |
|
1910 |
const bool popup = (type == Qt::Popup); |
|
1911 |
if (type == Qt::ToolTip || type == Qt::SplashScreen || popup) |
|
1912 |
flags |= Qt::FramelessWindowHint; |
|
1913 |
||
1914 |
WindowClass wclass = kSheetWindowClass; |
|
1915 |
if(qt_mac_is_macdrawer(q)) |
|
1916 |
wclass = kDrawerWindowClass; |
|
1917 |
else if (q->testAttribute(Qt::WA_ShowModal) && flags & Qt::CustomizeWindowHint) |
|
1918 |
wclass = kDocumentWindowClass; |
|
1919 |
else if(popup || (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5 && type == Qt::SplashScreen)) |
|
1920 |
wclass = kModalWindowClass; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1921 |
else if(type == Qt::Dialog) |
0 | 1922 |
wclass = kMovableModalWindowClass; |
1923 |
else if(type == Qt::ToolTip) |
|
1924 |
wclass = kHelpWindowClass; |
|
1925 |
else if(type == Qt::Tool || (QSysInfo::MacintoshVersion < QSysInfo::MV_10_5 |
|
1926 |
&& type == Qt::SplashScreen)) |
|
1927 |
wclass = kFloatingWindowClass; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1928 |
else if(q->testAttribute(Qt::WA_ShowModal)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1929 |
wclass = kMovableModalWindowClass; |
0 | 1930 |
else |
1931 |
wclass = kDocumentWindowClass; |
|
1932 |
||
1933 |
WindowAttributes wattr = NSBorderlessWindowMask; |
|
1934 |
if(qt_mac_is_macsheet(q)) { |
|
1935 |
//grp = GetWindowGroupOfClass(kMovableModalWindowClass); |
|
1936 |
wclass = kSheetWindowClass; |
|
1937 |
wattr = NSTitledWindowMask | NSResizableWindowMask; |
|
1938 |
} else { |
|
1939 |
#ifndef QT_MAC_USE_COCOA |
|
1940 |
grp = GetWindowGroupOfClass(wclass); |
|
1941 |
#endif |
|
1942 |
// Shift things around a bit to get the correct window class based on the presence |
|
1943 |
// (or lack) of the border. |
|
1944 |
bool customize = flags & Qt::CustomizeWindowHint; |
|
1945 |
bool framelessWindow = (flags & Qt::FramelessWindowHint || (customize && !(flags & Qt::WindowTitleHint))); |
|
1946 |
if (framelessWindow) { |
|
1947 |
if (wclass == kDocumentWindowClass) { |
|
1948 |
wclass = kSimpleWindowClass; |
|
1949 |
} else if (wclass == kFloatingWindowClass) { |
|
1950 |
wclass = kToolbarWindowClass; |
|
1951 |
} else if (wclass == kMovableModalWindowClass) { |
|
1952 |
wclass = kModalWindowClass; |
|
1953 |
} |
|
1954 |
} else { |
|
1955 |
wattr |= NSTitledWindowMask; |
|
1956 |
if (wclass != kModalWindowClass) |
|
1957 |
wattr |= NSResizableWindowMask; |
|
1958 |
} |
|
1959 |
// Only add extra decorations (well, buttons) for widgets that can have them |
|
1960 |
// and have an actual border we can put them on. |
|
1961 |
if (wclass != kModalWindowClass |
|
1962 |
&& wclass != kSheetWindowClass && wclass != kPlainWindowClass |
|
1963 |
&& !framelessWindow && wclass != kDrawerWindowClass |
|
1964 |
&& wclass != kHelpWindowClass) { |
|
1965 |
if (flags & Qt::WindowMinimizeButtonHint) |
|
1966 |
wattr |= NSMiniaturizableWindowMask; |
|
1967 |
if (flags & Qt::WindowSystemMenuHint || flags & Qt::WindowCloseButtonHint) |
|
1968 |
wattr |= NSClosableWindowMask; |
|
1969 |
} else { |
|
1970 |
// Clear these hints so that we aren't call them on invalid windows |
|
1971 |
flags &= ~(Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint |
|
1972 |
| Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint); |
|
1973 |
} |
|
1974 |
} |
|
1975 |
if (q->testAttribute(Qt::WA_MacBrushedMetal)) |
|
1976 |
wattr |= NSTexturedBackgroundWindowMask; |
|
1977 |
||
1978 |
#ifdef DEBUG_WINDOW_CREATE |
|
1979 |
#define ADD_DEBUG_WINDOW_NAME(x) { x, #x } |
|
1980 |
struct { |
|
1981 |
UInt32 tag; |
|
1982 |
const char *name; |
|
1983 |
} known_attribs[] = { |
|
1984 |
ADD_DEBUG_WINDOW_NAME(kWindowCompositingAttribute), |
|
1985 |
ADD_DEBUG_WINDOW_NAME(kWindowStandardHandlerAttribute), |
|
1986 |
ADD_DEBUG_WINDOW_NAME(kWindowMetalAttribute), |
|
1987 |
ADD_DEBUG_WINDOW_NAME(kWindowHideOnSuspendAttribute), |
|
1988 |
ADD_DEBUG_WINDOW_NAME(kWindowStandardHandlerAttribute), |
|
1989 |
ADD_DEBUG_WINDOW_NAME(kWindowCollapseBoxAttribute), |
|
1990 |
ADD_DEBUG_WINDOW_NAME(kWindowHorizontalZoomAttribute), |
|
1991 |
ADD_DEBUG_WINDOW_NAME(kWindowVerticalZoomAttribute), |
|
1992 |
ADD_DEBUG_WINDOW_NAME(kWindowResizableAttribute), |
|
1993 |
ADD_DEBUG_WINDOW_NAME(kWindowNoActivatesAttribute), |
|
1994 |
ADD_DEBUG_WINDOW_NAME(kWindowNoUpdatesAttribute), |
|
1995 |
ADD_DEBUG_WINDOW_NAME(kWindowOpaqueForEventsAttribute), |
|
1996 |
ADD_DEBUG_WINDOW_NAME(kWindowLiveResizeAttribute), |
|
1997 |
ADD_DEBUG_WINDOW_NAME(kWindowCloseBoxAttribute), |
|
1998 |
ADD_DEBUG_WINDOW_NAME(kWindowHideOnSuspendAttribute), |
|
1999 |
{ 0, 0 } |
|
2000 |
}, known_classes[] = { |
|
2001 |
ADD_DEBUG_WINDOW_NAME(kHelpWindowClass), |
|
2002 |
ADD_DEBUG_WINDOW_NAME(kPlainWindowClass), |
|
2003 |
ADD_DEBUG_WINDOW_NAME(kDrawerWindowClass), |
|
2004 |
ADD_DEBUG_WINDOW_NAME(kUtilityWindowClass), |
|
2005 |
ADD_DEBUG_WINDOW_NAME(kToolbarWindowClass), |
|
2006 |
ADD_DEBUG_WINDOW_NAME(kSheetWindowClass), |
|
2007 |
ADD_DEBUG_WINDOW_NAME(kFloatingWindowClass), |
|
2008 |
ADD_DEBUG_WINDOW_NAME(kUtilityWindowClass), |
|
2009 |
ADD_DEBUG_WINDOW_NAME(kDocumentWindowClass), |
|
2010 |
ADD_DEBUG_WINDOW_NAME(kToolbarWindowClass), |
|
2011 |
ADD_DEBUG_WINDOW_NAME(kMovableModalWindowClass), |
|
2012 |
ADD_DEBUG_WINDOW_NAME(kModalWindowClass), |
|
2013 |
{ 0, 0 } |
|
2014 |
}; |
|
2015 |
qDebug("Qt: internal: ************* Creating new window %p (%s::%s)", q, q->metaObject()->className(), |
|
2016 |
q->objectName().toLocal8Bit().constData()); |
|
2017 |
bool found_class = false; |
|
2018 |
for(int i = 0; known_classes[i].name; i++) { |
|
2019 |
if(wclass == known_classes[i].tag) { |
|
2020 |
found_class = true; |
|
2021 |
qDebug("Qt: internal: ** Class: %s", known_classes[i].name); |
|
2022 |
break; |
|
2023 |
} |
|
2024 |
} |
|
2025 |
if(!found_class) |
|
2026 |
qDebug("Qt: internal: !! Class: Unknown! (%d)", (int)wclass); |
|
2027 |
if(wattr) { |
|
2028 |
WindowAttributes tmp_wattr = wattr; |
|
2029 |
qDebug("Qt: internal: ** Attributes:"); |
|
2030 |
for(int i = 0; tmp_wattr && known_attribs[i].name; i++) { |
|
2031 |
if((tmp_wattr & known_attribs[i].tag) == known_attribs[i].tag) { |
|
2032 |
tmp_wattr ^= known_attribs[i].tag; |
|
2033 |
} |
|
2034 |
} |
|
2035 |
if(tmp_wattr) |
|
2036 |
qDebug("Qt: internal: !! Attributes: Unknown (%d)", (int)tmp_wattr); |
|
2037 |
} |
|
2038 |
#endif |
|
2039 |
||
2040 |
#ifndef QT_MAC_USE_COCOA |
|
2041 |
/* Just to be extra careful we will change to the kUtilityWindowClass if the |
|
2042 |
requested attributes cannot be used */ |
|
2043 |
if((GetAvailableWindowAttributes(wclass) & wattr) != wattr) { |
|
2044 |
WindowClass tmp_class = wclass; |
|
2045 |
if(wclass == kToolbarWindowClass || wclass == kUtilityWindowClass) |
|
2046 |
wclass = kFloatingWindowClass; |
|
2047 |
if(tmp_class != wclass) { |
|
2048 |
if(!grp) |
|
2049 |
grp = GetWindowGroupOfClass(wclass); |
|
2050 |
wclass = tmp_class; |
|
2051 |
} |
|
2052 |
} |
|
2053 |
#endif |
|
2054 |
#endif |
|
2055 |
topData()->wclass = wclass; |
|
2056 |
topData()->wattr = wattr; |
|
2057 |
} |
|
2058 |
||
2059 |
#ifndef QT_MAC_USE_COCOA // This is handled in Cocoa via our category. |
|
2060 |
void QWidgetPrivate::initWindowPtr() |
|
2061 |
{ |
|
2062 |
Q_Q(QWidget); |
|
2063 |
OSWindowRef windowRef = qt_mac_window_for(qt_mac_nativeview_for(q)); //do not create! |
|
2064 |
if(!windowRef) |
|
2065 |
return; |
|
2066 |
QWidget *window = q->window(), *oldWindow = 0; |
|
2067 |
if(GetWindowProperty(windowRef, kWidgetCreatorQt, kWidgetPropertyQWidget, sizeof(oldWindow), 0, &oldWindow) == noErr) { |
|
2068 |
Q_ASSERT(window == oldWindow); |
|
2069 |
return; |
|
2070 |
} |
|
2071 |
||
2072 |
if(SetWindowProperty(windowRef, kWidgetCreatorQt, kWidgetPropertyQWidget, sizeof(window), &window) != noErr) |
|
2073 |
qWarning("Qt:Internal error (%s:%d)", __FILE__, __LINE__); //no real way to recover |
|
2074 |
if(!q->windowType() != Qt::Desktop) { //setup an event callback handler on the window |
|
2075 |
InstallWindowEventHandler(windowRef, make_win_eventUPP(), GetEventTypeCount(window_events), |
|
2076 |
window_events, static_cast<void *>(qApp), &window_event); |
|
2077 |
} |
|
2078 |
} |
|
2079 |
||
2080 |
void QWidgetPrivate::finishCreateWindow_sys_Carbon(OSWindowRef windowRef) |
|
2081 |
{ |
|
2082 |
Q_Q(QWidget); |
|
2083 |
const Qt::WindowType type = q->windowType(); |
|
2084 |
Qt::WindowFlags &flags = data.window_flags; |
|
2085 |
QWidget *parentWidget = q->parentWidget(); |
|
2086 |
||
2087 |
const bool desktop = (type == Qt::Desktop); |
|
2088 |
const bool dialog = (type == Qt::Dialog |
|
2089 |
|| type == Qt::Sheet |
|
2090 |
|| type == Qt::Drawer |
|
2091 |
|| (flags & Qt::MSWindowsFixedSizeDialogHint)); |
|
2092 |
QTLWExtra *topExtra = topData(); |
|
2093 |
quint32 wattr = topExtra->wattr; |
|
2094 |
if (!desktop) |
|
2095 |
SetAutomaticControlDragTrackingEnabledForWindow(windowRef, true); |
|
2096 |
HIWindowChangeFeatures(windowRef, kWindowCanCollapse, 0); |
|
2097 |
if (wattr & kWindowHideOnSuspendAttribute) |
|
2098 |
HIWindowChangeAvailability(windowRef, kHIWindowExposeHidden, 0); |
|
2099 |
else |
|
2100 |
HIWindowChangeAvailability(windowRef, 0, kHIWindowExposeHidden); |
|
2101 |
if ((flags & Qt::WindowStaysOnTopHint)) |
|
2102 |
ChangeWindowAttributes(windowRef, kWindowNoAttributes, kWindowHideOnSuspendAttribute); |
|
2103 |
if (qt_mac_is_macdrawer(q) && parentWidget) |
|
2104 |
SetDrawerParent(windowRef, qt_mac_window_for (parentWidget)); |
|
2105 |
if (topExtra->group) { |
|
2106 |
qt_mac_release_window_group(topExtra->group); |
|
2107 |
topExtra->group = 0; |
|
2108 |
} |
|
2109 |
if (type == Qt::ToolTip) |
|
2110 |
qt_mac_set_window_group_to_tooltip(windowRef); |
|
2111 |
else if (type == Qt::Popup && (flags & Qt::WindowStaysOnTopHint)) |
|
2112 |
qt_mac_set_window_group_to_popup(windowRef); |
|
2113 |
else if (flags & Qt::WindowStaysOnTopHint) |
|
2114 |
qt_mac_set_window_group_to_stays_on_top(windowRef, type); |
|
2115 |
else if (dialog) |
|
2116 |
SetWindowGroup(windowRef, GetWindowGroupOfClass(kMovableModalWindowClass)); |
|
2117 |
||
2118 |
#ifdef DEBUG_WINDOW_CREATE |
|
2119 |
if (WindowGroupRef grpf = GetWindowGroup(windowRef)) { |
|
2120 |
QCFString cfname; |
|
2121 |
CopyWindowGroupName(grpf, &cfname); |
|
2122 |
SInt32 lvl; |
|
2123 |
GetWindowGroupLevel(grpf, &lvl); |
|
2124 |
const char *from = "Default"; |
|
2125 |
if (topExtra && grpf == topData()->group) |
|
2126 |
from = "Created"; |
|
2127 |
else if (grpf == grp) |
|
2128 |
from = "Copied"; |
|
2129 |
qDebug("Qt: internal: With window group '%s' [%p] @ %d: %s", |
|
2130 |
static_cast<QString>(cfname).toLatin1().constData(), grpf, (int)lvl, from); |
|
2131 |
} else { |
|
2132 |
qDebug("Qt: internal: No window group!!!"); |
|
2133 |
} |
|
2134 |
HIWindowAvailability hi_avail = 0; |
|
2135 |
if (HIWindowGetAvailability(windowRef, &hi_avail) == noErr) { |
|
2136 |
struct { |
|
2137 |
UInt32 tag; |
|
2138 |
const char *name; |
|
2139 |
} known_avail[] = { |
|
2140 |
ADD_DEBUG_WINDOW_NAME(kHIWindowExposeHidden), |
|
2141 |
{ 0, 0 } |
|
2142 |
}; |
|
2143 |
qDebug("Qt: internal: ** HIWindowAvailibility:"); |
|
2144 |
for (int i = 0; hi_avail && known_avail[i].name; i++) { |
|
2145 |
if ((hi_avail & known_avail[i].tag) == known_avail[i].tag) { |
|
2146 |
hi_avail ^= known_avail[i].tag; |
|
2147 |
qDebug("Qt: internal: * %s", known_avail[i].name); |
|
2148 |
} |
|
2149 |
} |
|
2150 |
if (hi_avail) |
|
2151 |
qDebug("Qt: internal: !! Attributes: Unknown (%d)", (int)hi_avail); |
|
2152 |
} |
|
2153 |
#undef ADD_DEBUG_WINDOW_NAME |
|
2154 |
#endif |
|
2155 |
if (extra && !extra->mask.isEmpty()) |
|
2156 |
ReshapeCustomWindow(windowRef); |
|
2157 |
SetWindowModality(windowRef, kWindowModalityNone, 0); |
|
2158 |
if (qt_mac_is_macdrawer(q)) |
|
2159 |
SetDrawerOffsets(windowRef, 0.0, 25.0); |
|
2160 |
data.fstrut_dirty = true; // when we create a toplevel widget, the frame strut should be dirty |
|
2161 |
HIViewRef hiview = (HIViewRef)data.winid; |
|
2162 |
HIViewRef window_hiview = qt_mac_get_contentview_for(windowRef); |
|
2163 |
if(!hiview) { |
|
2164 |
hiview = qt_mac_create_widget(q, this, window_hiview); |
|
2165 |
setWinId((WId)hiview); |
|
2166 |
} else { |
|
2167 |
HIViewAddSubview(window_hiview, hiview); |
|
2168 |
} |
|
2169 |
if (hiview) { |
|
2170 |
Rect win_rect; |
|
2171 |
GetWindowBounds(qt_mac_window_for (window_hiview), kWindowContentRgn, &win_rect); |
|
2172 |
HIRect bounds = CGRectMake(0, 0, win_rect.right-win_rect.left, win_rect.bottom-win_rect.top); |
|
2173 |
HIViewSetFrame(hiview, &bounds); |
|
2174 |
HIViewSetVisible(hiview, true); |
|
2175 |
if (q->testAttribute(Qt::WA_DropSiteRegistered)) |
|
2176 |
registerDropSite(true); |
|
2177 |
transferChildren(); |
|
2178 |
} |
|
2179 |
initWindowPtr(); |
|
2180 |
||
2181 |
if (topExtra->posFromMove) { |
|
2182 |
updateFrameStrut(); |
|
2183 |
const QRect &fStrut = frameStrut(); |
|
2184 |
Rect r; |
|
2185 |
SetRect(&r, data.crect.left(), data.crect.top(), data.crect.right() + 1, data.crect.bottom() + 1); |
|
2186 |
SetRect(&r, r.left + fStrut.left(), r.top + fStrut.top(), |
|
2187 |
(r.left + fStrut.left() + data.crect.width()) - fStrut.right(), |
|
2188 |
(r.top + fStrut.top() + data.crect.height()) - fStrut.bottom()); |
|
2189 |
SetWindowBounds(windowRef, kWindowContentRgn, &r); |
|
2190 |
topExtra->posFromMove = false; |
|
2191 |
} |
|
2192 |
||
2193 |
if (q->testAttribute(Qt::WA_WState_WindowOpacitySet)){ |
|
2194 |
q->setWindowOpacity(topExtra->opacity / 255.0f); |
|
2195 |
} else if (qt_mac_is_macsheet(q)){ |
|
2196 |
SetThemeWindowBackground(qt_mac_window_for(q), kThemeBrushSheetBackgroundTransparent, true); |
|
2197 |
CGFloat alpha = 0; |
|
2198 |
GetWindowAlpha(qt_mac_window_for(q), &alpha); |
|
2199 |
if (alpha == 1){ |
|
2200 |
// For some reason the 'SetThemeWindowBackground' does not seem |
|
2201 |
// to work. So we do this little hack until it hopefully starts to |
|
2202 |
// work in newer versions of mac OS. |
|
2203 |
q->setWindowOpacity(0.95f); |
|
2204 |
q->setAttribute(Qt::WA_WState_WindowOpacitySet, false); |
|
2205 |
} |
|
2206 |
} else{ |
|
2207 |
// If the window has been recreated after beeing e.g. a sheet, |
|
2208 |
// make sure that we don't report a faulty opacity: |
|
2209 |
q->setWindowOpacity(1.0f); |
|
2210 |
q->setAttribute(Qt::WA_WState_WindowOpacitySet, false); |
|
2211 |
} |
|
2212 |
||
2213 |
// Since we only now have a window, sync our state. |
|
2214 |
macUpdateHideOnSuspend(); |
|
2215 |
macUpdateOpaqueSizeGrip(); |
|
2216 |
macUpdateMetalAttribute(); |
|
2217 |
macUpdateIgnoreMouseEvents(); |
|
2218 |
setWindowTitle_helper(extra->topextra->caption); |
|
2219 |
setWindowIconText_helper(extra->topextra->iconText); |
|
2220 |
setWindowFilePath_helper(extra->topextra->filePath); |
|
2221 |
setWindowModified_sys(q->isWindowModified()); |
|
2222 |
updateFrameStrut(); |
|
2223 |
qt_mac_update_sizer(q); |
|
2224 |
applyMaxAndMinSizeOnWindow(); |
|
2225 |
} |
|
2226 |
#else // QT_MAC_USE_COCOA |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2227 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2228 |
void QWidgetPrivate::setWindowLevel() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2229 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2230 |
Q_Q(QWidget); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2231 |
const QWidget * const windowParent = q->window()->parentWidget(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2232 |
const QWidget * const primaryWindow = windowParent ? windowParent->window() : 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2233 |
NSInteger winLevel = -1; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2234 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2235 |
if (q->windowType() == Qt::Popup) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2236 |
winLevel = NSPopUpMenuWindowLevel; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2237 |
// Popup should be in at least the same level as its parent. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2238 |
if (primaryWindow) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2239 |
OSWindowRef parentRef = qt_mac_window_for(primaryWindow); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2240 |
winLevel = qMax([parentRef level], winLevel); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2241 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2242 |
} else if (q->windowType() == Qt::Tool) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2243 |
winLevel = NSFloatingWindowLevel; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2244 |
} else if (q->windowType() == Qt::Dialog) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2245 |
// Correct modality level (NSModalPanelWindowLevel) will be |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2246 |
// set by cocoa when creating a modal session later. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2247 |
winLevel = NSNormalWindowLevel; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2248 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2249 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2250 |
// StayOnTop window should appear above Tool windows. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2251 |
if (data.window_flags & Qt::WindowStaysOnTopHint) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2252 |
winLevel = NSPopUpMenuWindowLevel; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2253 |
// Tooltips should appear above StayOnTop windows. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2254 |
if (q->windowType() == Qt::ToolTip) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2255 |
winLevel = NSScreenSaverWindowLevel; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2256 |
// All other types are Normal level. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2257 |
if (winLevel == -1) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2258 |
winLevel = NSNormalWindowLevel; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2259 |
[qt_mac_window_for(q) setLevel:winLevel]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2260 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2261 |
|
0 | 2262 |
void QWidgetPrivate::finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ voidWindowRef) |
2263 |
{ |
|
2264 |
Q_Q(QWidget); |
|
2265 |
QMacCocoaAutoReleasePool pool; |
|
2266 |
NSWindow *windowRef = static_cast<NSWindow *>(voidWindowRef); |
|
2267 |
const Qt::WindowType type = q->windowType(); |
|
2268 |
Qt::WindowFlags &flags = data.window_flags; |
|
2269 |
QWidget *parentWidget = q->parentWidget(); |
|
2270 |
||
2271 |
const bool popup = (type == Qt::Popup); |
|
2272 |
const bool dialog = (type == Qt::Dialog |
|
2273 |
|| type == Qt::Sheet |
|
2274 |
|| type == Qt::Drawer |
|
2275 |
|| (flags & Qt::MSWindowsFixedSizeDialogHint)); |
|
2276 |
QTLWExtra *topExtra = topData(); |
|
2277 |
||
2278 |
if ((popup || type == Qt::Tool || type == Qt::ToolTip) && !q->isModal()) { |
|
2279 |
[windowRef setHidesOnDeactivate:YES]; |
|
2280 |
} else { |
|
2281 |
[windowRef setHidesOnDeactivate:NO]; |
|
2282 |
} |
|
2283 |
[windowRef setHasShadow:YES]; |
|
2284 |
Q_UNUSED(parentWidget); |
|
2285 |
Q_UNUSED(dialog); |
|
2286 |
||
2287 |
data.fstrut_dirty = true; // when we create a toplevel widget, the frame strut should be dirty |
|
2288 |
OSViewRef nsview = (OSViewRef)data.winid; |
|
2289 |
OSViewRef window_contentview = qt_mac_get_contentview_for(windowRef); |
|
2290 |
if (!nsview) { |
|
2291 |
nsview = qt_mac_create_widget(q, this, window_contentview); |
|
2292 |
setWinId(WId(nsview)); |
|
2293 |
} else { |
|
2294 |
[window_contentview addSubview:nsview]; |
|
2295 |
} |
|
2296 |
if (nsview) { |
|
2297 |
NSRect bounds = [window_contentview bounds]; |
|
2298 |
[nsview setFrame:bounds]; |
|
2299 |
[nsview setHidden:NO]; |
|
2300 |
if (q->testAttribute(Qt::WA_DropSiteRegistered)) |
|
2301 |
registerDropSite(true); |
|
2302 |
transferChildren(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2303 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2304 |
// Tell Cocoa explicit that we wan't the view to receive key events |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2305 |
// (regardless of focus policy) because this is how it works on other |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2306 |
// platforms (and in the carbon port): |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2307 |
if (!qApp->focusWidget()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2308 |
[windowRef makeFirstResponder:nsview]; |
0 | 2309 |
} |
2310 |
||
2311 |
if (topExtra->posFromMove) { |
|
2312 |
updateFrameStrut(); |
|
2313 |
||
2314 |
const QRect &fStrut = frameStrut(); |
|
2315 |
const QRect &crect = data.crect; |
|
2316 |
const QRect frameRect(QPoint(crect.left(), crect.top()), |
|
2317 |
QSize(fStrut.left() + fStrut.right() + crect.width(), |
|
2318 |
fStrut.top() + fStrut.bottom() + crect.height())); |
|
2319 |
NSRect cocoaFrameRect = NSMakeRect(frameRect.x(), flipYCoordinate(frameRect.bottom() + 1), |
|
2320 |
frameRect.width(), frameRect.height()); |
|
2321 |
[windowRef setFrame:cocoaFrameRect display:NO]; |
|
2322 |
topExtra->posFromMove = false; |
|
2323 |
} |
|
2324 |
||
2325 |
if (q->testAttribute(Qt::WA_WState_WindowOpacitySet)){ |
|
2326 |
q->setWindowOpacity(topExtra->opacity / 255.0f); |
|
2327 |
} else if (qt_mac_is_macsheet(q)){ |
|
2328 |
CGFloat alpha = [qt_mac_window_for(q) alphaValue]; |
|
2329 |
if (alpha >= 1.0) { |
|
2330 |
q->setWindowOpacity(0.95f); |
|
2331 |
q->setAttribute(Qt::WA_WState_WindowOpacitySet, false); |
|
2332 |
} |
|
2333 |
} else{ |
|
2334 |
// If the window has been recreated after beeing e.g. a sheet, |
|
2335 |
// make sure that we don't report a faulty opacity: |
|
2336 |
q->setWindowOpacity(1.0f); |
|
2337 |
q->setAttribute(Qt::WA_WState_WindowOpacitySet, false); |
|
2338 |
} |
|
2339 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2340 |
if (qApp->overrideCursor()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2341 |
[windowRef disableCursorRects]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2342 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2343 |
setWindowLevel(); |
0 | 2344 |
macUpdateHideOnSuspend(); |
2345 |
macUpdateOpaqueSizeGrip(); |
|
2346 |
macUpdateIgnoreMouseEvents(); |
|
2347 |
setWindowTitle_helper(extra->topextra->caption); |
|
2348 |
setWindowIconText_helper(extra->topextra->iconText); |
|
2349 |
setWindowModified_sys(q->isWindowModified()); |
|
2350 |
updateFrameStrut(); |
|
2351 |
syncCocoaMask(); |
|
2352 |
macUpdateIsOpaque(); |
|
2353 |
qt_mac_update_sizer(q); |
|
2354 |
applyMaxAndMinSizeOnWindow(); |
|
2355 |
} |
|
2356 |
||
2357 |
#endif // QT_MAC_USE_COCOA |
|
2358 |
||
2359 |
/* |
|
2360 |
Recreates widget window. Useful if immutable |
|
2361 |
properties for it has changed. |
|
2362 |
*/ |
|
2363 |
void QWidgetPrivate::recreateMacWindow() |
|
2364 |
{ |
|
2365 |
Q_Q(QWidget); |
|
2366 |
OSViewRef myView = qt_mac_nativeview_for(q); |
|
2367 |
OSWindowRef oldWindow = qt_mac_window_for(myView); |
|
2368 |
#ifndef QT_MAC_USE_COCOA |
|
2369 |
HIViewRemoveFromSuperview(myView); |
|
2370 |
determineWindowClass(); |
|
2371 |
createWindow_sys(); |
|
2372 |
if (QMainWindowLayout *mwl = qobject_cast<QMainWindowLayout *>(q->layout())) { |
|
2373 |
mwl->updateHIToolBarStatus(); |
|
2374 |
} |
|
2375 |
||
2376 |
if (IsWindowVisible(oldWindow)) |
|
2377 |
show_sys(); |
|
2378 |
#else |
|
2379 |
QMacCocoaAutoReleasePool pool; |
|
2380 |
[myView removeFromSuperview]; |
|
2381 |
determineWindowClass(); |
|
2382 |
createWindow_sys(); |
|
2383 |
if (NSToolbar *toolbar = [oldWindow toolbar]) { |
|
2384 |
OSWindowRef newWindow = qt_mac_window_for(myView); |
|
2385 |
[newWindow setToolbar:toolbar]; |
|
2386 |
[toolbar setVisible:[toolbar isVisible]]; |
|
2387 |
} |
|
2388 |
if ([oldWindow isVisible]){ |
|
2389 |
if ([oldWindow isSheet]) |
|
2390 |
[NSApp endSheet:oldWindow]; |
|
2391 |
[oldWindow orderOut:oldWindow]; |
|
2392 |
show_sys(); |
|
2393 |
} |
|
2394 |
#endif // QT_MAC_USE_COCOA |
|
2395 |
||
2396 |
// Release the window after creating the new window, because releasing it early |
|
2397 |
// may cause the app to quit ("close on last window closed attribute") |
|
2398 |
qt_mac_destructWindow(oldWindow); |
|
2399 |
} |
|
2400 |
||
2401 |
void QWidgetPrivate::createWindow_sys() |
|
2402 |
{ |
|
2403 |
Q_Q(QWidget); |
|
2404 |
Qt::WindowFlags &flags = data.window_flags; |
|
2405 |
QWidget *parentWidget = q->parentWidget(); |
|
2406 |
||
2407 |
QTLWExtra *topExtra = topData(); |
|
2408 |
if (topExtra->embedded) |
|
2409 |
return; // Simply return because this view "is" the top window. |
|
2410 |
quint32 wattr = topExtra->wattr; |
|
2411 |
||
2412 |
if(parentWidget && (parentWidget->window()->windowFlags() & Qt::WindowStaysOnTopHint)) // If our parent has Qt::WStyle_StaysOnTop, so must we |
|
2413 |
flags |= Qt::WindowStaysOnTopHint; |
|
2414 |
||
2415 |
data.fstrut_dirty = true; |
|
2416 |
||
2417 |
OSWindowRef windowRef = qt_mac_create_window(q, topExtra->wclass, wattr, data.crect); |
|
2418 |
if (windowRef == 0) |
|
2419 |
qWarning("QWidget: Internal error: %s:%d: If you reach this error please contact Qt Support and include the\n" |
|
2420 |
" WidgetFlags used in creating the widget.", __FILE__, __LINE__); |
|
2421 |
#ifndef QT_MAC_USE_COCOA |
|
2422 |
finishCreateWindow_sys_Carbon(windowRef); |
|
2423 |
#else |
|
2424 |
finishCreateWindow_sys_Cocoa(windowRef); |
|
2425 |
#endif |
|
2426 |
} |
|
2427 |
||
2428 |
void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyOldWindow) |
|
2429 |
{ |
|
2430 |
Q_Q(QWidget); |
|
2431 |
OSViewRef destroyid = 0; |
|
2432 |
#ifndef QT_MAC_USE_COCOA |
|
2433 |
window_event = 0; |
|
2434 |
#endif |
|
2435 |
||
2436 |
Qt::WindowType type = q->windowType(); |
|
2437 |
Qt::WindowFlags flags = data.window_flags; |
|
2438 |
QWidget *parentWidget = q->parentWidget(); |
|
2439 |
||
2440 |
bool topLevel = (flags & Qt::Window); |
|
2441 |
bool popup = (type == Qt::Popup); |
|
2442 |
bool dialog = (type == Qt::Dialog |
|
2443 |
|| type == Qt::Sheet |
|
2444 |
|| type == Qt::Drawer |
|
2445 |
|| (flags & Qt::MSWindowsFixedSizeDialogHint)); |
|
2446 |
bool desktop = (type == Qt::Desktop); |
|
2447 |
||
2448 |
// Determine this early for top-levels so, we can use it later. |
|
2449 |
if (topLevel) |
|
2450 |
determineWindowClass(); |
|
2451 |
||
2452 |
if (desktop) { |
|
2453 |
QSize desktopSize = qt_mac_desktopSize(); |
|
2454 |
q->setAttribute(Qt::WA_WState_Visible); |
|
2455 |
data.crect.setRect(0, 0, desktopSize.width(), desktopSize.height()); |
|
2456 |
dialog = popup = false; // force these flags off |
|
2457 |
} else { |
|
2458 |
q->setAttribute(Qt::WA_WState_Visible, false); |
|
2459 |
||
2460 |
if (topLevel && (type != Qt::Drawer)) { |
|
2461 |
if (QDesktopWidget *dsk = QApplication::desktop()) { // calc pos/size from screen |
|
2462 |
const bool wasResized = q->testAttribute(Qt::WA_Resized); |
|
2463 |
const bool wasMoved = q->testAttribute(Qt::WA_Moved); |
|
2464 |
int deskn = dsk->primaryScreen(); |
|
2465 |
if (parentWidget && parentWidget->windowType() != Qt::Desktop) |
|
2466 |
deskn = dsk->screenNumber(parentWidget); |
|
2467 |
QRect screenGeo = dsk->screenGeometry(deskn); |
|
2468 |
if (!wasResized) { |
|
2469 |
#ifndef QT_MAC_USE_COCOA |
|
2470 |
data.crect.setSize(QSize(screenGeo.width()/2, 4*screenGeo.height()/10)); |
|
2471 |
#else |
|
2472 |
NSRect newRect = [NSWindow frameRectForContentRect:NSMakeRect(0, 0, |
|
2473 |
screenGeo.width() / 2., |
|
2474 |
4 * screenGeo.height() / 10.) |
|
2475 |
styleMask:topData()->wattr]; |
|
2476 |
data.crect.setSize(QSize(newRect.size.width, newRect.size.height)); |
|
2477 |
#endif |
|
2478 |
// Constrain to minimums and maximums we've set |
|
2479 |
if (extra->minw > 0) |
|
2480 |
data.crect.setWidth(qMax(extra->minw, data.crect.width())); |
|
2481 |
if (extra->minh > 0) |
|
2482 |
data.crect.setHeight(qMax(extra->minh, data.crect.height())); |
|
2483 |
if (extra->maxw > 0) |
|
2484 |
data.crect.setWidth(qMin(extra->maxw, data.crect.width())); |
|
2485 |
if (extra->maxh > 0) |
|
2486 |
data.crect.setHeight(qMin(extra->maxh, data.crect.height())); |
|
2487 |
} |
|
2488 |
if (!wasMoved && !q->testAttribute(Qt::WA_DontShowOnScreen)) |
|
2489 |
data.crect.moveTopLeft(QPoint(screenGeo.width()/4, |
|
2490 |
3 * screenGeo.height() / 10)); |
|
2491 |
} |
|
2492 |
} |
|
2493 |
} |
|
2494 |
||
2495 |
||
2496 |
if(!window) // always initialize |
|
2497 |
initializeWindow=true; |
|
2498 |
||
2499 |
hd = 0; |
|
2500 |
if(window) { // override the old window (with a new NSView) |
|
2501 |
OSViewRef nativeView = OSViewRef(window); |
|
2502 |
OSViewRef parent = 0; |
|
2503 |
#ifndef QT_MAC_USE_COCOA |
|
2504 |
CFRetain(nativeView); |
|
2505 |
#else |
|
2506 |
[nativeView retain]; |
|
2507 |
#endif |
|
2508 |
if (destroyOldWindow) |
|
2509 |
destroyid = qt_mac_nativeview_for(q); |
|
2510 |
bool transfer = false; |
|
2511 |
setWinId((WId)nativeView); |
|
2512 |
#ifndef QT_MAC_USE_COCOA |
|
2513 |
#ifndef HIViewInstallEventHandler |
|
2514 |
// Macro taken from the CarbonEvents Header on Tiger |
|
2515 |
#define HIViewInstallEventHandler( target, handler, numTypes, list, userData, outHandlerRef ) \ |
|
2516 |
InstallEventHandler( HIObjectGetEventTarget( (HIObjectRef) (target) ), (handler), (numTypes), (list), (userData), (outHandlerRef) ) |
|
2517 |
#endif |
|
2518 |
HIViewInstallEventHandler(nativeView, make_widget_eventUPP(), GetEventTypeCount(widget_events), widget_events, 0, 0); |
|
2519 |
#endif |
|
2520 |
if(topLevel) { |
|
2521 |
for(int i = 0; i < 2; ++i) { |
|
2522 |
if(i == 1) { |
|
2523 |
if(!initializeWindow) |
|
2524 |
break; |
|
2525 |
createWindow_sys(); |
|
2526 |
} |
|
2527 |
if(OSWindowRef windowref = qt_mac_window_for(nativeView)) { |
|
2528 |
#ifndef QT_MAC_USE_COCOA |
|
2529 |
CFRetain(windowref); |
|
2530 |
#else |
|
2531 |
[windowref retain]; |
|
2532 |
#endif |
|
2533 |
if (initializeWindow) { |
|
2534 |
parent = qt_mac_get_contentview_for(windowref); |
|
2535 |
} else { |
|
2536 |
#ifndef QT_MAC_USE_COCOA |
|
2537 |
parent = HIViewGetSuperview(nativeView); |
|
2538 |
#else |
|
2539 |
parent = [nativeView superview]; |
|
2540 |
#endif |
|
2541 |
} |
|
2542 |
break; |
|
2543 |
} |
|
2544 |
} |
|
2545 |
if(!parent) |
|
2546 |
transfer = true; |
|
2547 |
} else if (parentWidget) { |
|
2548 |
// I need to be added to my parent, therefore my parent needs an NSView |
|
2549 |
parentWidget->createWinId(); |
|
2550 |
parent = qt_mac_nativeview_for(parentWidget); |
|
2551 |
} |
|
2552 |
if(parent != nativeView && parent) { |
|
2553 |
#ifndef QT_MAC_USE_COCOA |
|
2554 |
HIViewAddSubview(parent, nativeView); |
|
2555 |
#else |
|
2556 |
[parent addSubview:nativeView]; |
|
2557 |
#endif |
|
2558 |
} |
|
2559 |
if(transfer) |
|
2560 |
transferChildren(); |
|
2561 |
data.fstrut_dirty = true; // we'll re calculate this later |
|
2562 |
q->setAttribute(Qt::WA_WState_Visible, |
|
2563 |
#ifndef QT_MAC_USE_COCOA |
|
2564 |
HIViewIsVisible(nativeView) |
|
2565 |
#else |
|
2566 |
![nativeView isHidden] |
|
2567 |
#endif |
|
2568 |
); |
|
2569 |
if(initializeWindow) { |
|
2570 |
#ifndef QT_MAC_USE_COCOA |
|
2571 |
HIRect bounds = CGRectMake(data.crect.x(), data.crect.y(), data.crect.width(), data.crect.height()); |
|
2572 |
HIViewSetFrame(nativeView, &bounds); |
|
2573 |
q->setAttribute(Qt::WA_WState_Visible, HIViewIsVisible(nativeView)); |
|
2574 |
#else |
|
2575 |
NSRect bounds = NSMakeRect(data.crect.x(), data.crect.y(), data.crect.width(), data.crect.height()); |
|
2576 |
[nativeView setFrame:bounds]; |
|
2577 |
q->setAttribute(Qt::WA_WState_Visible, [nativeView isHidden]); |
|
2578 |
#endif |
|
2579 |
} |
|
2580 |
#ifndef QT_MAC_USE_COCOA |
|
2581 |
initWindowPtr(); |
|
2582 |
#endif |
|
2583 |
} else if (desktop) { // desktop widget |
|
2584 |
if (!qt_root_win) |
|
2585 |
QWidgetPrivate::qt_create_root_win(); |
|
2586 |
Q_ASSERT(qt_root_win); |
|
2587 |
WId rootWinID = 0; |
|
2588 |
#ifndef QT_MAC_USE_COCOA |
|
2589 |
CFRetain(qt_root_win); |
|
2590 |
if(HIViewRef rootContentView = HIViewGetRoot(qt_root_win)) { |
|
2591 |
rootWinID = (WId)rootContentView; |
|
2592 |
CFRetain(rootContentView); |
|
2593 |
} |
|
2594 |
#else |
|
2595 |
[qt_root_win retain]; |
|
2596 |
if (OSViewRef rootContentView = [qt_root_win contentView]) { |
|
2597 |
rootWinID = (WId)rootContentView; |
|
2598 |
[rootContentView retain]; |
|
2599 |
} |
|
2600 |
#endif |
|
2601 |
setWinId(rootWinID); |
|
2602 |
} else if (topLevel) { |
|
2603 |
determineWindowClass(); |
|
2604 |
if(OSViewRef osview = qt_mac_create_widget(q, this, 0)) { |
|
2605 |
#ifndef QT_MAC_USE_COCOA |
|
2606 |
HIRect bounds = CGRectMake(data.crect.x(), data.crect.y(), |
|
2607 |
data.crect.width(), data.crect.height()); |
|
2608 |
HIViewSetFrame(osview, &bounds); |
|
2609 |
#else |
|
2610 |
NSRect bounds = NSMakeRect(data.crect.x(), flipYCoordinate(data.crect.y()), |
|
2611 |
data.crect.width(), data.crect.height()); |
|
2612 |
[osview setFrame:bounds]; |
|
2613 |
#endif |
|
2614 |
setWinId((WId)osview); |
|
2615 |
} |
|
2616 |
} else { |
|
2617 |
data.fstrut_dirty = false; // non-toplevel widgets don't have a frame, so no need to update the strut |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2618 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2619 |
#ifdef QT_MAC_USE_COCOA |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2620 |
if (q->testAttribute(Qt::WA_NativeWindow) == false || |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2621 |
q->internalWinId() != 0) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2622 |
#ifdef ALIEN_DEBUG |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2623 |
qDebug() << "Skipping native widget creation for" << this; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2624 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2625 |
} else |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2626 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2627 |
if (OSViewRef osview = qt_mac_create_widget(q, this, qt_mac_nativeview_for(parentWidget))) { |
0 | 2628 |
#ifndef QT_MAC_USE_COCOA |
2629 |
HIRect bounds = CGRectMake(data.crect.x(), data.crect.y(), data.crect.width(), data.crect.height()); |
|
2630 |
HIViewSetFrame(osview, &bounds); |
|
2631 |
setWinId((WId)osview); |
|
2632 |
#else |
|
2633 |
NSRect bounds = NSMakeRect(data.crect.x(), data.crect.y(), data.crect.width(), data.crect.height()); |
|
2634 |
[osview setFrame:bounds]; |
|
2635 |
setWinId((WId)osview); |
|
2636 |
#endif |
|
2637 |
if (q->testAttribute(Qt::WA_DropSiteRegistered)) |
|
2638 |
registerDropSite(true); |
|
2639 |
} |
|
2640 |
} |
|
2641 |
||
2642 |
updateIsOpaque(); |
|
2643 |
if (q->hasFocus()) |
|
2644 |
setFocus_sys(); |
|
2645 |
if (!topLevel && initializeWindow) |
|
2646 |
setWSGeometry(); |
|
2647 |
if (destroyid) |
|
2648 |
qt_mac_destructView(destroyid); |
|
2649 |
if (q->testAttribute(Qt::WA_AcceptTouchEvents)) |
|
2650 |
registerTouchWindow(); |
|
2651 |
} |
|
2652 |
||
2653 |
/*! |
|
2654 |
Returns the QuickDraw handle of the widget. Use of this function is not |
|
2655 |
portable. This function will return 0 if QuickDraw is not supported, or |
|
2656 |
if the handle could not be created. |
|
2657 |
||
2658 |
\warning This function is only available on Mac OS X. |
|
2659 |
*/ |
|
2660 |
||
2661 |
Qt::HANDLE |
|
2662 |
QWidget::macQDHandle() const |
|
2663 |
{ |
|
2664 |
#ifndef QT_MAC_USE_COCOA |
|
2665 |
return d_func()->qd_hd; |
|
2666 |
#else |
|
2667 |
return 0; |
|
2668 |
#endif |
|
2669 |
} |
|
2670 |
||
2671 |
/*! |
|
2672 |
Returns the CoreGraphics handle of the widget. Use of this function is |
|
2673 |
not portable. This function will return 0 if no painter context can be |
|
2674 |
established, or if the handle could not be created. |
|
2675 |
||
2676 |
\warning This function is only available on Mac OS X. |
|
2677 |
*/ |
|
2678 |
Qt::HANDLE |
|
2679 |
QWidget::macCGHandle() const |
|
2680 |
{ |
|
2681 |
return handle(); |
|
2682 |
} |
|
2683 |
||
2684 |
void QWidget::destroy(bool destroyWindow, bool destroySubWindows) |
|
2685 |
{ |
|
2686 |
Q_D(QWidget); |
|
2687 |
if (!isWindow() && parentWidget()) |
|
2688 |
parentWidget()->d_func()->invalidateBuffer(d->effectiveRectFor(geometry())); |
|
2689 |
d->deactivateWidgetCleanup(); |
|
2690 |
qt_mac_event_release(this); |
|
2691 |
if(testAttribute(Qt::WA_WState_Created)) { |
|
2692 |
QMacCocoaAutoReleasePool pool; |
|
2693 |
setAttribute(Qt::WA_WState_Created, false); |
|
2694 |
QObjectList chldrn = children(); |
|
2695 |
for(int i = 0; i < chldrn.size(); i++) { // destroy all widget children |
|
2696 |
QObject *obj = chldrn.at(i); |
|
2697 |
if(obj->isWidgetType()) |
|
2698 |
static_cast<QWidget*>(obj)->destroy(destroySubWindows, destroySubWindows); |
|
2699 |
} |
|
2700 |
if(mac_mouse_grabber == this) |
|
2701 |
releaseMouse(); |
|
2702 |
if(mac_keyboard_grabber == this) |
|
2703 |
releaseKeyboard(); |
|
2704 |
||
2705 |
if(testAttribute(Qt::WA_ShowModal)) // just be sure we leave modal |
|
2706 |
QApplicationPrivate::leaveModal(this); |
|
2707 |
else if((windowType() == Qt::Popup)) |
|
2708 |
qApp->d_func()->closePopup(this); |
|
2709 |
if (destroyWindow) { |
|
2710 |
if(OSViewRef hiview = qt_mac_nativeview_for(this)) { |
|
2711 |
OSWindowRef window = 0; |
|
2712 |
NSDrawer *drawer = nil; |
|
2713 |
#ifdef QT_MAC_USE_COCOA |
|
2714 |
if (qt_mac_is_macdrawer(this)) { |
|
2715 |
drawer = qt_mac_drawer_for(this); |
|
2716 |
} else |
|
2717 |
#endif |
|
2718 |
if (isWindow()) |
|
2719 |
window = qt_mac_window_for(hiview); |
|
2720 |
||
2721 |
// Because of how "destruct" works, we have to do just a normal release for the root_win. |
|
2722 |
if (window && window == qt_root_win) { |
|
2723 |
#ifndef QT_MAC_USE_COCOA |
|
2724 |
CFRelease(hiview); |
|
2725 |
#else |
|
2726 |
[hiview release]; |
|
2727 |
#endif |
|
2728 |
} else { |
|
2729 |
qt_mac_destructView(hiview); |
|
2730 |
} |
|
2731 |
if (drawer) |
|
2732 |
qt_mac_destructDrawer(drawer); |
|
2733 |
if (window) |
|
2734 |
qt_mac_destructWindow(window); |
|
2735 |
} |
|
2736 |
} |
|
2737 |
QT_TRY { |
|
2738 |
d->setWinId(0); |
|
2739 |
} QT_CATCH (const std::bad_alloc &) { |
|
2740 |
// swallow - destructors must not throw |
|
2741 |
} |
|
2742 |
} |
|
2743 |
} |
|
2744 |
||
2745 |
void QWidgetPrivate::transferChildren() |
|
2746 |
{ |
|
2747 |
Q_Q(QWidget); |
|
2748 |
if (!q->testAttribute(Qt::WA_WState_Created)) |
|
2749 |
return; // Can't add any views anyway |
|
2750 |
||
2751 |
QObjectList chlist = q->children(); |
|
2752 |
for (int i = 0; i < chlist.size(); ++i) { |
|
2753 |
QObject *obj = chlist.at(i); |
|
2754 |
if (obj->isWidgetType()) { |
|
2755 |
QWidget *w = (QWidget *)obj; |
|
2756 |
if (!w->isWindow()) { |
|
2757 |
// This seems weird, no need to call it in a loop right? |
|
2758 |
if (!topData()->caption.isEmpty()) |
|
2759 |
setWindowTitle_helper(extra->topextra->caption); |
|
2760 |
if (w->testAttribute(Qt::WA_WState_Created)) { |
|
2761 |
#ifndef QT_MAC_USE_COCOA |
|
2762 |
HIViewAddSubview(qt_mac_nativeview_for(q), qt_mac_nativeview_for(w)); |
|
2763 |
#else |
|
2764 |
// New NSWindows get an extra reference when drops are |
|
2765 |
// registered (at least in 10.5) which means that we may |
|
2766 |
// access the window later and get a crash (becasue our |
|
2767 |
// widget is dead). Work around this be having the drop |
|
2768 |
// site disabled until it is part of the new hierarchy. |
|
2769 |
bool oldRegistered = w->testAttribute(Qt::WA_DropSiteRegistered); |
|
2770 |
w->setAttribute(Qt::WA_DropSiteRegistered, false); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2771 |
[qt_mac_nativeview_for(w) retain]; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2772 |
[qt_mac_nativeview_for(w) removeFromSuperview]; |
0 | 2773 |
[qt_mac_nativeview_for(q) addSubview:qt_mac_nativeview_for(w)]; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2774 |
[qt_mac_nativeview_for(w) release]; |
0 | 2775 |
w->setAttribute(Qt::WA_DropSiteRegistered, oldRegistered); |
2776 |
#endif |
|
2777 |
} |
|
2778 |
} |
|
2779 |
} |
|
2780 |
} |
|
2781 |
} |
|
2782 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2783 |
#ifdef QT_MAC_USE_COCOA |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2784 |
void QWidgetPrivate::setSubWindowStacking(bool set) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2785 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2786 |
Q_Q(QWidget); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2787 |
if (!q->isWindow() || !q->testAttribute(Qt::WA_WState_Created)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2788 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2789 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2790 |
if (QWidget *parent = q->parentWidget()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2791 |
if (parent->testAttribute(Qt::WA_WState_Created)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2792 |
if (set) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2793 |
[qt_mac_window_for(parent) addChildWindow:qt_mac_window_for(q) ordered:NSWindowAbove]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2794 |
else |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2795 |
[qt_mac_window_for(parent) removeChildWindow:qt_mac_window_for(q)]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2796 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2797 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2798 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2799 |
QList<QWidget *> widgets = q->findChildren<QWidget *>(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2800 |
for (int i=0; i<widgets.size(); ++i) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2801 |
QWidget *child = widgets.at(i); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2802 |
if (child->isWindow() && child->testAttribute(Qt::WA_WState_Created)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2803 |
if (set) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2804 |
[qt_mac_window_for(q) addChildWindow:qt_mac_window_for(child) ordered:NSWindowAbove]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2805 |
else |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2806 |
[qt_mac_window_for(q) removeChildWindow:qt_mac_window_for(child)]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2807 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2808 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2809 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2810 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2811 |
|
0 | 2812 |
void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f) |
2813 |
{ |
|
2814 |
Q_Q(QWidget); |
|
2815 |
QMacCocoaAutoReleasePool pool; |
|
2816 |
QTLWExtra *topData = maybeTopData(); |
|
2817 |
bool wasCreated = q->testAttribute(Qt::WA_WState_Created); |
|
2818 |
#ifdef QT_MAC_USE_COCOA |
|
2819 |
bool wasWindow = q->isWindow(); |
|
2820 |
#endif |
|
2821 |
OSViewRef old_id = 0; |
|
2822 |
||
2823 |
if (q->isVisible() && q->parentWidget() && parent != q->parentWidget()) |
|
2824 |
q->parentWidget()->d_func()->invalidateBuffer(effectiveRectFor(q->geometry())); |
|
2825 |
||
2826 |
// Maintain the glWidgets list on parent change: remove "our" gl widgets |
|
2827 |
// from the list on the old parent and grandparents. |
|
2828 |
if (glWidgets.isEmpty() == false) { |
|
2829 |
QWidget *current = q->parentWidget(); |
|
2830 |
while (current) { |
|
2831 |
for (QList<QWidgetPrivate::GlWidgetInfo>::const_iterator it = glWidgets.constBegin(); |
|
2832 |
it != glWidgets.constEnd(); ++it) |
|
2833 |
current->d_func()->glWidgets.removeAll(*it); |
|
2834 |
||
2835 |
if (current->isWindow()) |
|
2836 |
break; |
|
2837 |
current = current->parentWidget(); |
|
2838 |
} |
|
2839 |
} |
|
2840 |
||
2841 |
#ifndef QT_MAC_USE_COCOA |
|
2842 |
EventHandlerRef old_window_event = 0; |
|
2843 |
#else |
|
2844 |
bool oldToolbarVisible = false; |
|
2845 |
NSDrawer *oldDrawer = nil; |
|
2846 |
NSToolbar *oldToolbar = 0; |
|
2847 |
#endif |
|
2848 |
if (wasCreated && !(q->windowType() == Qt::Desktop)) { |
|
2849 |
old_id = qt_mac_nativeview_for(q); |
|
2850 |
#ifndef QT_MAC_USE_COCOA |
|
2851 |
old_window_event = window_event; |
|
2852 |
#else |
|
2853 |
OSWindowRef oldWindow = qt_mac_window_for(old_id); |
|
2854 |
if (qt_mac_is_macdrawer(q)) { |
|
2855 |
oldDrawer = qt_mac_drawer_for(q); |
|
2856 |
} |
|
2857 |
if (wasWindow) { |
|
2858 |
oldToolbar = [oldWindow toolbar]; |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2859 |
[oldToolbar retain]; |
0 | 2860 |
oldToolbarVisible = [oldToolbar isVisible]; |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2861 |
[oldWindow setToolbar:nil]; |
0 | 2862 |
} |
2863 |
#endif |
|
2864 |
} |
|
2865 |
QWidget* oldtlw = q->window(); |
|
2866 |
||
2867 |
if (q->testAttribute(Qt::WA_DropSiteRegistered)) |
|
2868 |
q->setAttribute(Qt::WA_DropSiteRegistered, false); |
|
2869 |
||
2870 |
//recreate and setup flags |
|
2871 |
QObjectPrivate::setParent_helper(parent); |
|
2872 |
bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide); |
|
2873 |
if (wasCreated && !qt_isGenuineQWidget(q)) |
|
2874 |
return; |
|
2875 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2876 |
if (!q->testAttribute(Qt::WA_WState_WindowOpacitySet)) { |
0 | 2877 |
q->setWindowOpacity(1.0f); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2878 |
q->setAttribute(Qt::WA_WState_WindowOpacitySet, false); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2879 |
} |
0 | 2880 |
|
2881 |
setWinId(0); //do after the above because they may want the id |
|
2882 |
||
2883 |
data.window_flags = f; |
|
2884 |
q->setAttribute(Qt::WA_WState_Created, false); |
|
2885 |
q->setAttribute(Qt::WA_WState_Visible, false); |
|
2886 |
q->setAttribute(Qt::WA_WState_Hidden, false); |
|
2887 |
adjustFlags(data.window_flags, q); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2888 |
// keep compatibility with previous versions, we need to preserve the created state. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2889 |
// (but we recreate the winId for the widget being reparented, again for compatibility, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2890 |
// unless this is an alien widget. ) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2891 |
const bool nonWindowWithCreatedParent = !q->isWindow() && parent->testAttribute(Qt::WA_WState_Created); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2892 |
const bool nativeWidget = q->internalWinId() != 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2893 |
if (wasCreated || nativeWidget && nonWindowWithCreatedParent) { |
0 | 2894 |
createWinId(); |
2895 |
if (q->isWindow()) { |
|
2896 |
#ifndef QT_MAC_USE_COCOA |
|
2897 |
// We do this down below for wasCreated, so avoid doing this twice |
|
2898 |
// (only for performance, it gets called a lot anyway). |
|
2899 |
if (!wasCreated) { |
|
2900 |
if (QMainWindowLayout *mwl = qobject_cast<QMainWindowLayout *>(q->layout())) { |
|
2901 |
mwl->updateHIToolBarStatus(); |
|
2902 |
} |
|
2903 |
} |
|
2904 |
#else |
|
2905 |
// Simply transfer our toolbar over. Everything should stay put, unlike in Carbon. |
|
2906 |
if (oldToolbar && !(f & Qt::FramelessWindowHint)) { |
|
2907 |
OSWindowRef newWindow = qt_mac_window_for(q); |
|
2908 |
[newWindow setToolbar:oldToolbar]; |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2909 |
[oldToolbar release]; |
0 | 2910 |
[oldToolbar setVisible:oldToolbarVisible]; |
2911 |
} |
|
2912 |
#endif |
|
2913 |
} |
|
2914 |
} |
|
2915 |
if (q->isWindow() || (!parent || parent->isVisible()) || explicitlyHidden) |
|
2916 |
q->setAttribute(Qt::WA_WState_Hidden); |
|
2917 |
q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden); |
|
2918 |
||
2919 |
if (wasCreated) { |
|
2920 |
transferChildren(); |
|
2921 |
#ifndef QT_MAC_USE_COCOA |
|
2922 |
// If we were a unified window, We just transfered our toolbars out of the unified toolbar. |
|
2923 |
// So redo the status one more time. It apparently is not an issue with Cocoa. |
|
2924 |
if (q->isWindow()) { |
|
2925 |
if (QMainWindowLayout *mwl = qobject_cast<QMainWindowLayout *>(q->layout())) { |
|
2926 |
mwl->updateHIToolBarStatus(); |
|
2927 |
} |
|
2928 |
} |
|
2929 |
#endif |
|
2930 |
||
2931 |
if (topData && |
|
2932 |
(!topData->caption.isEmpty() || !topData->filePath.isEmpty())) |
|
2933 |
setWindowTitle_helper(q->windowTitle()); |
|
2934 |
} |
|
2935 |
||
2936 |
if (q->testAttribute(Qt::WA_AcceptDrops) |
|
2937 |
|| (!q->isWindow() && q->parentWidget() |
|
2938 |
&& q->parentWidget()->testAttribute(Qt::WA_DropSiteRegistered))) |
|
2939 |
q->setAttribute(Qt::WA_DropSiteRegistered, true); |
|
2940 |
||
2941 |
//cleanup |
|
2942 |
#ifndef QT_MAC_USE_COCOA |
|
2943 |
if (old_window_event) |
|
2944 |
RemoveEventHandler(old_window_event); |
|
2945 |
#endif |
|
2946 |
if (old_id) { //don't need old window anymore |
|
2947 |
OSWindowRef window = (oldtlw == q) ? qt_mac_window_for(old_id) : 0; |
|
2948 |
qt_mac_destructView(old_id); |
|
2949 |
||
2950 |
#ifdef QT_MAC_USE_COCOA |
|
2951 |
if (oldDrawer) { |
|
2952 |
qt_mac_destructDrawer(oldDrawer); |
|
2953 |
} else |
|
2954 |
#endif |
|
2955 |
if (window) |
|
2956 |
qt_mac_destructWindow(window); |
|
2957 |
} |
|
2958 |
||
2959 |
// Maintain the glWidgets list on parent change: add "our" gl widgets |
|
2960 |
// to the list on the new parent and grandparents. |
|
2961 |
if (glWidgets.isEmpty() == false) { |
|
2962 |
QWidget *current = q->parentWidget(); |
|
2963 |
while (current) { |
|
2964 |
current->d_func()->glWidgets += glWidgets; |
|
2965 |
if (current->isWindow()) |
|
2966 |
break; |
|
2967 |
current = current->parentWidget(); |
|
2968 |
} |
|
2969 |
} |
|
2970 |
invalidateBuffer(q->rect()); |
|
2971 |
qt_event_request_window_change(q); |
|
2972 |
} |
|
2973 |
||
2974 |
QPoint QWidget::mapToGlobal(const QPoint &pos) const |
|
2975 |
{ |
|
2976 |
Q_D(const QWidget); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2977 |
if (!testAttribute(Qt::WA_WState_Created) || !internalWinId()) { |
0 | 2978 |
QPoint p = pos + data->crect.topLeft(); |
2979 |
return isWindow() ? p : parentWidget()->mapToGlobal(p); |
|
2980 |
} |
|
2981 |
#ifndef QT_MAC_USE_COCOA |
|
2982 |
QPoint tmp = d->mapToWS(pos); |
|
2983 |
HIPoint hi_pos = CGPointMake(tmp.x(), tmp.y()); |
|
2984 |
HIViewConvertPoint(&hi_pos, qt_mac_nativeview_for(this), 0); |
|
2985 |
Rect win_rect; |
|
2986 |
GetWindowBounds(qt_mac_window_for(this), kWindowStructureRgn, &win_rect); |
|
2987 |
return QPoint((int)hi_pos.x+win_rect.left, (int)hi_pos.y+win_rect.top); |
|
2988 |
#else |
|
2989 |
QPoint tmp = d->mapToWS(pos); |
|
2990 |
NSPoint hi_pos = NSMakePoint(tmp.x(), tmp.y()); |
|
2991 |
hi_pos = [qt_mac_nativeview_for(this) convertPoint:hi_pos toView:nil]; |
|
2992 |
NSRect win_rect = [qt_mac_window_for(this) frame]; |
|
2993 |
hi_pos.x += win_rect.origin.x; |
|
2994 |
hi_pos.y += win_rect.origin.y; |
|
2995 |
// If we aren't the desktop we need to flip, if you flip the desktop on itself, you get the other problem. |
|
2996 |
return ((window()->windowFlags() & Qt::Desktop) == Qt::Desktop) ? QPointF(hi_pos.x, hi_pos.y).toPoint() |
|
2997 |
: flipPoint(hi_pos).toPoint(); |
|
2998 |
#endif |
|
2999 |
} |
|
3000 |
||
3001 |
QPoint QWidget::mapFromGlobal(const QPoint &pos) const |
|
3002 |
{ |
|
3003 |
Q_D(const QWidget); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3004 |
if (!testAttribute(Qt::WA_WState_Created) || !internalWinId()) { |
0 | 3005 |
QPoint p = isWindow() ? pos : parentWidget()->mapFromGlobal(pos); |
3006 |
return p - data->crect.topLeft(); |
|
3007 |
} |
|
3008 |
#ifndef QT_MAC_USE_COCOA |
|
3009 |
Rect win_rect; |
|
3010 |
GetWindowBounds(qt_mac_window_for(this), kWindowStructureRgn, &win_rect); |
|
3011 |
HIPoint hi_pos = CGPointMake(pos.x()-win_rect.left, pos.y()-win_rect.top); |
|
3012 |
HIViewConvertPoint(&hi_pos, 0, qt_mac_nativeview_for(this)); |
|
3013 |
return d->mapFromWS(QPoint((int)hi_pos.x, (int)hi_pos.y)); |
|
3014 |
#else |
|
3015 |
NSRect win_rect = [qt_mac_window_for(this) frame]; |
|
3016 |
// The Window point is in "Cocoa coordinates," but the view is in "Qt coordinates" |
|
3017 |
// so make sure to keep them in sync. |
|
3018 |
NSPoint hi_pos = NSMakePoint(pos.x()-win_rect.origin.x, |
|
3019 |
flipYCoordinate(pos.y())-win_rect.origin.y); |
|
3020 |
hi_pos = [qt_mac_nativeview_for(this) convertPoint:hi_pos fromView:0]; |
|
3021 |
return d->mapFromWS(QPoint(qRound(hi_pos.x), qRound(hi_pos.y))); |
|
3022 |
#endif |
|
3023 |
} |
|
3024 |
||
3025 |
void QWidgetPrivate::updateSystemBackground() |
|
3026 |
{ |
|
3027 |
} |
|
3028 |
||
3029 |
void QWidgetPrivate::setCursor_sys(const QCursor &) |
|
3030 |
{ |
|
3031 |
#ifndef QT_MAC_USE_COCOA |
|
3032 |
qt_mac_update_cursor(); |
|
3033 |
#else |
|
3034 |
Q_Q(QWidget); |
|
3035 |
if (q->testAttribute(Qt::WA_WState_Created)) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3036 |
QMacCocoaAutoReleasePool pool; |
0 | 3037 |
[qt_mac_window_for(q) invalidateCursorRectsForView:qt_mac_nativeview_for(q)]; |
3038 |
} |
|
3039 |
#endif |
|
3040 |
} |
|
3041 |
||
3042 |
void QWidgetPrivate::unsetCursor_sys() |
|
3043 |
{ |
|
3044 |
#ifndef QT_MAC_USE_COCOA |
|
3045 |
qt_mac_update_cursor(); |
|
3046 |
#else |
|
3047 |
Q_Q(QWidget); |
|
3048 |
if (q->testAttribute(Qt::WA_WState_Created)) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3049 |
QMacCocoaAutoReleasePool pool; |
0 | 3050 |
[qt_mac_window_for(q) invalidateCursorRectsForView:qt_mac_nativeview_for(q)]; |
3051 |
} |
|
3052 |
#endif |
|
3053 |
} |
|
3054 |
||
3055 |
void QWidgetPrivate::setWindowTitle_sys(const QString &caption) |
|
3056 |
{ |
|
3057 |
Q_Q(QWidget); |
|
3058 |
if (q->isWindow()) { |
|
3059 |
#ifndef QT_MAC_USE_COCOA |
|
3060 |
SetWindowTitleWithCFString(qt_mac_window_for(q), QCFString(caption)); |
|
3061 |
#else |
|
3062 |
QMacCocoaAutoReleasePool pool; |
|
3063 |
[qt_mac_window_for(q) setTitle:qt_mac_QStringToNSString(caption)]; |
|
3064 |
#endif |
|
3065 |
} |
|
3066 |
} |
|
3067 |
||
3068 |
void QWidgetPrivate::setWindowModified_sys(bool mod) |
|
3069 |
{ |
|
3070 |
Q_Q(QWidget); |
|
3071 |
if (q->isWindow() && q->testAttribute(Qt::WA_WState_Created)) { |
|
3072 |
#ifndef QT_MAC_USE_COCOA |
|
3073 |
SetWindowModified(qt_mac_window_for(q), mod); |
|
3074 |
#else |
|
3075 |
[qt_mac_window_for(q) setDocumentEdited:mod]; |
|
3076 |
#endif |
|
3077 |
} |
|
3078 |
} |
|
3079 |
||
3080 |
void QWidgetPrivate::setWindowFilePath_sys(const QString &filePath) |
|
3081 |
{ |
|
3082 |
Q_Q(QWidget); |
|
3083 |
#ifdef QT_MAC_USE_COCOA |
|
3084 |
QMacCocoaAutoReleasePool pool; |
|
3085 |
QFileInfo fi(filePath); |
|
3086 |
[qt_mac_window_for(q) setRepresentedFilename:fi.exists() ? qt_mac_QStringToNSString(filePath) : @""]; |
|
3087 |
#else |
|
3088 |
bool validRef = false; |
|
3089 |
FSRef ref; |
|
3090 |
bzero(&ref, sizeof(ref)); |
|
3091 |
OSStatus status; |
|
3092 |
||
3093 |
if (!filePath.isEmpty()) { |
|
3094 |
status = FSPathMakeRef(reinterpret_cast<const UInt8 *>(filePath.toUtf8().constData()), &ref, 0); |
|
3095 |
validRef = (status == noErr); |
|
3096 |
} |
|
3097 |
// Set the proxy regardless, since this is our way of clearing it as well, but ignore the |
|
3098 |
// return value as well. |
|
3099 |
if (validRef) { |
|
3100 |
status = HIWindowSetProxyFSRef(qt_mac_window_for(q), &ref); |
|
3101 |
} else { |
|
3102 |
status = RemoveWindowProxy(qt_mac_window_for(q)); |
|
3103 |
} |
|
3104 |
if (status != noErr) |
|
3105 |
qWarning("QWidget::setWindowFilePath: Error setting proxyicon for path (%s):%ld", |
|
3106 |
qPrintable(filePath), status); |
|
3107 |
#endif |
|
3108 |
} |
|
3109 |
||
3110 |
void QWidgetPrivate::setWindowIcon_sys(bool forceReset) |
|
3111 |
{ |
|
3112 |
Q_Q(QWidget); |
|
3113 |
||
3114 |
if (!q->testAttribute(Qt::WA_WState_Created)) |
|
3115 |
return; |
|
3116 |
||
3117 |
QTLWExtra *topData = this->topData(); |
|
3118 |
if (topData->iconPixmap && !forceReset) // already set |
|
3119 |
return; |
|
3120 |
||
3121 |
QIcon icon = q->windowIcon(); |
|
3122 |
QPixmap *pm = 0; |
|
3123 |
if (!icon.isNull()) { |
|
3124 |
// now create the extra |
|
3125 |
if (!topData->iconPixmap) { |
|
3126 |
pm = new QPixmap(icon.pixmap(QSize(22, 22))); |
|
3127 |
topData->iconPixmap = pm; |
|
3128 |
} else { |
|
3129 |
pm = topData->iconPixmap; |
|
3130 |
} |
|
3131 |
} |
|
3132 |
if (q->isWindow()) { |
|
3133 |
#ifndef QT_MAC_USE_COCOA |
|
3134 |
IconRef previousIcon = 0; |
|
3135 |
if (icon.isNull()) { |
|
3136 |
RemoveWindowProxy(qt_mac_window_for(q)); |
|
3137 |
previousIcon = topData->windowIcon; |
|
3138 |
topData->windowIcon = 0; |
|
3139 |
} else { |
|
3140 |
WindowClass wclass; |
|
3141 |
GetWindowClass(qt_mac_window_for(q), &wclass); |
|
3142 |
||
3143 |
if (wclass == kDocumentWindowClass) { |
|
3144 |
IconRef newIcon = qt_mac_create_iconref(*pm); |
|
3145 |
previousIcon = topData->windowIcon; |
|
3146 |
topData->windowIcon = newIcon; |
|
3147 |
SetWindowProxyIcon(qt_mac_window_for(q), newIcon); |
|
3148 |
} |
|
3149 |
} |
|
3150 |
||
3151 |
// Release the previous icon if it was set by this function. |
|
3152 |
if (previousIcon != 0) |
|
3153 |
ReleaseIconRef(previousIcon); |
|
3154 |
#else |
|
3155 |
QMacCocoaAutoReleasePool pool; |
|
3156 |
NSButton *iconButton = [qt_mac_window_for(q) standardWindowButton:NSWindowDocumentIconButton]; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3157 |
if (iconButton == nil) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3158 |
QCFString string(q->windowTitle()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3159 |
const NSString *tmpString = reinterpret_cast<const NSString *>((CFStringRef)string); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3160 |
[qt_mac_window_for(q) setRepresentedURL:[NSURL fileURLWithPath:tmpString]]; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3161 |
iconButton = [qt_mac_window_for(q) standardWindowButton:NSWindowDocumentIconButton]; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3162 |
} |
0 | 3163 |
if (icon.isNull()) { |
3164 |
[iconButton setImage:nil]; |
|
3165 |
} else { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3166 |
QPixmap scaled = pm->scaled(QSize(16,16), Qt::KeepAspectRatio, Qt::SmoothTransformation); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3167 |
NSImage *image = static_cast<NSImage *>(qt_mac_create_nsimage(scaled)); |
0 | 3168 |
[iconButton setImage:image]; |
3169 |
[image release]; |
|
3170 |
} |
|
3171 |
#endif |
|
3172 |
} |
|
3173 |
} |
|
3174 |
||
3175 |
void QWidgetPrivate::setWindowIconText_sys(const QString &iconText) |
|
3176 |
{ |
|
3177 |
Q_Q(QWidget); |
|
3178 |
if(q->isWindow() && !iconText.isEmpty()) { |
|
3179 |
#ifndef QT_MAC_USE_COCOA |
|
3180 |
SetWindowAlternateTitle(qt_mac_window_for(q), QCFString(iconText)); |
|
3181 |
#else |
|
3182 |
QMacCocoaAutoReleasePool pool; |
|
3183 |
[qt_mac_window_for(q) setMiniwindowTitle:qt_mac_QStringToNSString(iconText)]; |
|
3184 |
#endif |
|
3185 |
} |
|
3186 |
} |
|
3187 |
||
3188 |
void QWidget::grabMouse() |
|
3189 |
{ |
|
3190 |
if(isVisible() && !qt_nograb()) { |
|
3191 |
if(mac_mouse_grabber) |
|
3192 |
mac_mouse_grabber->releaseMouse(); |
|
3193 |
mac_mouse_grabber=this; |
|
3194 |
} |
|
3195 |
} |
|
3196 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3197 |
#ifndef QT_NO_CURSOR |
0 | 3198 |
void QWidget::grabMouse(const QCursor &) |
3199 |
{ |
|
3200 |
if(isVisible() && !qt_nograb()) { |
|
3201 |
if(mac_mouse_grabber) |
|
3202 |
mac_mouse_grabber->releaseMouse(); |
|
3203 |
mac_mouse_grabber=this; |
|
3204 |
} |
|
3205 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3206 |
#endif |
0 | 3207 |
|
3208 |
void QWidget::releaseMouse() |
|
3209 |
{ |
|
3210 |
if(!qt_nograb() && mac_mouse_grabber == this) |
|
3211 |
mac_mouse_grabber = 0; |
|
3212 |
} |
|
3213 |
||
3214 |
void QWidget::grabKeyboard() |
|
3215 |
{ |
|
3216 |
if(!qt_nograb()) { |
|
3217 |
if(mac_keyboard_grabber) |
|
3218 |
mac_keyboard_grabber->releaseKeyboard(); |
|
3219 |
mac_keyboard_grabber = this; |
|
3220 |
} |
|
3221 |
} |
|
3222 |
||
3223 |
void QWidget::releaseKeyboard() |
|
3224 |
{ |
|
3225 |
if(!qt_nograb() && mac_keyboard_grabber == this) |
|
3226 |
mac_keyboard_grabber = 0; |
|
3227 |
} |
|
3228 |
||
3229 |
QWidget *QWidget::mouseGrabber() |
|
3230 |
{ |
|
3231 |
return mac_mouse_grabber; |
|
3232 |
} |
|
3233 |
||
3234 |
QWidget *QWidget::keyboardGrabber() |
|
3235 |
{ |
|
3236 |
return mac_keyboard_grabber; |
|
3237 |
} |
|
3238 |
||
3239 |
void QWidget::activateWindow() |
|
3240 |
{ |
|
3241 |
QWidget *tlw = window(); |
|
3242 |
if(!tlw->isVisible() || !tlw->isWindow() || (tlw->windowType() == Qt::Desktop)) |
|
3243 |
return; |
|
3244 |
qt_event_remove_activate(); |
|
3245 |
||
3246 |
QWidget *fullScreenWidget = tlw; |
|
3247 |
QWidget *parentW = tlw; |
|
3248 |
// Find the oldest parent or the parent with fullscreen, whichever comes first. |
|
3249 |
while (parentW) { |
|
3250 |
fullScreenWidget = parentW->window(); |
|
3251 |
if (fullScreenWidget->windowState() & Qt::WindowFullScreen) |
|
3252 |
break; |
|
3253 |
parentW = fullScreenWidget->parentWidget(); |
|
3254 |
} |
|
3255 |
||
3256 |
if (fullScreenWidget->windowType() != Qt::ToolTip) { |
|
3257 |
qt_mac_set_fullscreen_mode((fullScreenWidget->windowState() & Qt::WindowFullScreen) && |
|
3258 |
qApp->desktop()->screenNumber(this) == 0); |
|
3259 |
} |
|
3260 |
||
3261 |
bool windowActive; |
|
3262 |
OSWindowRef win = qt_mac_window_for(tlw); |
|
3263 |
#ifndef QT_MAC_USE_COCOA |
|
3264 |
windowActive = IsWindowActive(win); |
|
3265 |
#else |
|
3266 |
QMacCocoaAutoReleasePool pool; |
|
3267 |
windowActive = [win isKeyWindow]; |
|
3268 |
#endif |
|
3269 |
if ((tlw->windowType() == Qt::Popup) |
|
3270 |
|| (tlw->windowType() == Qt::Tool) |
|
3271 |
|| qt_mac_is_macdrawer(tlw) |
|
3272 |
|| windowActive) { |
|
3273 |
#ifndef QT_MAC_USE_COCOA |
|
3274 |
ActivateWindow(win, true); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3275 |
qApp->setActiveWindow(tlw); |
0 | 3276 |
#else |
3277 |
[win makeKeyWindow]; |
|
3278 |
#endif |
|
3279 |
} else if(!isMinimized()) { |
|
3280 |
#ifndef QT_MAC_USE_COCOA |
|
3281 |
SelectWindow(win); |
|
3282 |
#else |
|
3283 |
[win makeKeyAndOrderFront:win]; |
|
3284 |
#endif |
|
3285 |
} |
|
3286 |
} |
|
3287 |
||
3288 |
QWindowSurface *QWidgetPrivate::createDefaultWindowSurface_sys() |
|
3289 |
{ |
|
3290 |
return new QMacWindowSurface(q_func()); |
|
3291 |
} |
|
3292 |
||
3293 |
void QWidgetPrivate::update_sys(const QRect &r) |
|
3294 |
{ |
|
3295 |
Q_Q(QWidget); |
|
3296 |
if (r == q->rect()) { |
|
3297 |
if (updateRedirectedToGraphicsProxyWidget(q, r)) |
|
3298 |
return; |
|
3299 |
dirtyOnWidget += r; |
|
3300 |
#ifndef QT_MAC_USE_COCOA |
|
3301 |
HIViewSetNeedsDisplay(qt_mac_nativeview_for(q), true); |
|
3302 |
#else |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3303 |
qt_mac_set_needs_display(q, QRegion()); |
0 | 3304 |
#endif |
3305 |
return; |
|
3306 |
} |
|
3307 |
||
3308 |
int x = r.x(), y = r.y(), w = r.width(), h = r.height(); |
|
3309 |
if (w < 0) |
|
3310 |
w = q->data->crect.width() - x; |
|
3311 |
if (h < 0) |
|
3312 |
h = q->data->crect.height() - y; |
|
3313 |
if (w && h) { |
|
3314 |
const QRect updateRect = QRect(x, y, w, h); |
|
3315 |
if (updateRedirectedToGraphicsProxyWidget(q, updateRect)) |
|
3316 |
return; |
|
3317 |
#ifndef QT_MAC_USE_COCOA |
|
3318 |
dirtyOnWidget += updateRect; |
|
3319 |
HIRect r = CGRectMake(x, y, w, h); |
|
3320 |
HIViewSetNeedsDisplayInRect(qt_mac_nativeview_for(q), &r, true); |
|
3321 |
#else |
|
3322 |
[qt_mac_nativeview_for(q) setNeedsDisplayInRect:NSMakeRect(x, y, w, h)]; |
|
3323 |
#endif |
|
3324 |
} |
|
3325 |
} |
|
3326 |
||
3327 |
void QWidgetPrivate::update_sys(const QRegion &rgn) |
|
3328 |
{ |
|
3329 |
Q_Q(QWidget); |
|
3330 |
if (updateRedirectedToGraphicsProxyWidget(q, rgn)) |
|
3331 |
return; |
|
3332 |
dirtyOnWidget += rgn; |
|
3333 |
#ifndef QT_MAC_USE_COCOA |
|
3334 |
RgnHandle rgnHandle = rgn.toQDRgnForUpdate_sys(); |
|
3335 |
if (rgnHandle) |
|
3336 |
HIViewSetNeedsDisplayInRegion(qt_mac_nativeview_for(q), QMacSmartQuickDrawRegion(rgnHandle), true); |
|
3337 |
else { |
|
3338 |
HIViewSetNeedsDisplay(qt_mac_nativeview_for(q), true); // do a complete repaint on overflow. |
|
3339 |
} |
|
3340 |
#else |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3341 |
// Alien support: get the first native ancestor widget (will be q itself in the non-alien case), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3342 |
// map the coordinates from q space to NSView space and invalidate the rect. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3343 |
QWidget *nativeParent = q->internalWinId() ? q : q->nativeParentWidget(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3344 |
if (nativeParent == 0) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3345 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3346 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3347 |
QVector<QRect> rects = rgn.rects(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3348 |
for (int i = 0; i < rects.count(); ++i) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3349 |
const QRect &rect = rects.at(i); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3350 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3351 |
const QRect nativeBoundingRect = QRect( |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3352 |
QPoint(q->mapTo(nativeParent, rect.topLeft())), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3353 |
QSize(rect.size())); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3354 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3355 |
[qt_mac_nativeview_for(nativeParent) setNeedsDisplayInRect:NSMakeRect(nativeBoundingRect.x(), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3356 |
nativeBoundingRect.y(), nativeBoundingRect.width(), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3357 |
nativeBoundingRect.height())]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3358 |
} |
0 | 3359 |
#endif |
3360 |
} |
|
3361 |
||
3362 |
bool QWidgetPrivate::isRealWindow() const |
|
3363 |
{ |
|
3364 |
return q_func()->isWindow() && !topData()->embedded; |
|
3365 |
} |
|
3366 |
||
3367 |
void QWidgetPrivate::show_sys() |
|
3368 |
{ |
|
3369 |
Q_Q(QWidget); |
|
3370 |
if ((q->windowType() == Qt::Desktop)) //desktop is always visible |
|
3371 |
return; |
|
3372 |
||
3373 |
invalidateBuffer(q->rect()); |
|
3374 |
if (q->testAttribute(Qt::WA_OutsideWSRange)) |
|
3375 |
return; |
|
3376 |
QMacCocoaAutoReleasePool pool; |
|
3377 |
q->setAttribute(Qt::WA_Mapped); |
|
3378 |
if (q->testAttribute(Qt::WA_DontShowOnScreen)) |
|
3379 |
return; |
|
3380 |
||
3381 |
bool realWindow = isRealWindow(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3382 |
#ifndef QT_MAC_USE_COCOA |
0 | 3383 |
if (realWindow && !q->testAttribute(Qt::WA_Moved)) { |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3384 |
if (qt_mac_is_macsheet(q)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3385 |
recreateMacWindow(); |
0 | 3386 |
q->createWinId(); |
3387 |
if (QWidget *p = q->parentWidget()) { |
|
3388 |
p->createWinId(); |
|
3389 |
RepositionWindow(qt_mac_window_for(q), qt_mac_window_for(p), kWindowCenterOnParentWindow); |
|
3390 |
} else { |
|
3391 |
RepositionWindow(qt_mac_window_for(q), 0, kWindowCenterOnMainScreen); |
|
3392 |
} |
|
3393 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3394 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3395 |
|
0 | 3396 |
data.fstrut_dirty = true; |
3397 |
if (realWindow) { |
|
3398 |
// Delegates can change window state, so record some things earlier. |
|
3399 |
bool isCurrentlyMinimized = (q->windowState() & Qt::WindowMinimized); |
|
3400 |
setModal_sys(); |
|
3401 |
OSWindowRef window = qt_mac_window_for(q); |
|
3402 |
#ifndef QT_MAC_USE_COCOA |
|
3403 |
SizeWindow(window, q->width(), q->height(), true); |
|
3404 |
#endif |
|
3405 |
||
3406 |
#ifdef QT_MAC_USE_COCOA |
|
3407 |
// Make sure that we end up sending a repaint event to |
|
3408 |
// the widget if the window has been visible one before: |
|
3409 |
[qt_mac_get_contentview_for(window) setNeedsDisplay:YES]; |
|
3410 |
#endif |
|
3411 |
if(qt_mac_is_macsheet(q)) { |
|
3412 |
qt_event_request_showsheet(q); |
|
3413 |
} else if(qt_mac_is_macdrawer(q)) { |
|
3414 |
#ifndef QT_MAC_USE_COCOA |
|
3415 |
OpenDrawer(window, kWindowEdgeDefault, false); |
|
3416 |
#else |
|
3417 |
NSDrawer *drawer = qt_mac_drawer_for(q); |
|
3418 |
[drawer openOnEdge:[drawer preferredEdge]]; |
|
3419 |
#endif |
|
3420 |
} else { |
|
3421 |
#ifndef QT_MAC_USE_COCOA |
|
3422 |
ShowHide(window, true); |
|
3423 |
#else |
|
3424 |
// sync the opacity value back (in case of a fade). |
|
3425 |
[window setAlphaValue:q->windowOpacity()]; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3426 |
setSubWindowStacking(true); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3427 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3428 |
QWidget *top = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3429 |
if (QApplicationPrivate::tryModalHelper(q, &top)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3430 |
[window makeKeyAndOrderFront:window]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3431 |
// If this window is app modal, we need to start spinning |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3432 |
// a modal session for it. Interrupting |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3433 |
// the event dispatcher will make this happend: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3434 |
if (data.window_modality == Qt::ApplicationModal) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3435 |
QEventDispatcherMac::instance()->interrupt(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3436 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3437 |
// The window is modally shaddowed, so we need to make |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3438 |
// sure that we don't pop in front of the modal window: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3439 |
[window orderFront:window]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3440 |
if (!top->testAttribute(Qt::WA_DontShowOnScreen)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3441 |
if (NSWindow *modalWin = qt_mac_window_for(top)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3442 |
[modalWin orderFront:window]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3443 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3444 |
} |
0 | 3445 |
#endif |
3446 |
if (q->windowType() == Qt::Popup) { |
|
3447 |
if (q->focusWidget()) |
|
3448 |
q->focusWidget()->d_func()->setFocus_sys(); |
|
3449 |
else |
|
3450 |
setFocus_sys(); |
|
3451 |
} |
|
3452 |
toggleDrawers(true); |
|
3453 |
} |
|
3454 |
if (isCurrentlyMinimized) { //show in collapsed state |
|
3455 |
#ifndef QT_MAC_USE_COCOA |
|
3456 |
CollapseWindow(window, true); |
|
3457 |
#else |
|
3458 |
[window miniaturize:window]; |
|
3459 |
#endif |
|
3460 |
} else if (!q->testAttribute(Qt::WA_ShowWithoutActivating)) { |
|
3461 |
#ifndef QT_MAC_USE_COCOA |
|
3462 |
qt_event_request_activate(q); |
|
3463 |
#endif |
|
3464 |
} |
|
3465 |
} else if(topData()->embedded || !q->parentWidget() || q->parentWidget()->isVisible()) { |
|
3466 |
#ifndef QT_MAC_USE_COCOA |
|
3467 |
HIViewSetVisible(qt_mac_nativeview_for(q), true); |
|
3468 |
#else |
|
3469 |
[qt_mac_nativeview_for(q) setHidden:NO]; |
|
3470 |
||
3471 |
#endif |
|
3472 |
} |
|
3473 |
||
3474 |
if (!QWidget::mouseGrabber()){ |
|
3475 |
QWidget *enterWidget = QApplication::widgetAt(QCursor::pos()); |
|
3476 |
QApplicationPrivate::dispatchEnterLeave(enterWidget, qt_mouseover); |
|
3477 |
qt_mouseover = enterWidget; |
|
3478 |
} |
|
3479 |
||
3480 |
qt_event_request_window_change(q); |
|
3481 |
} |
|
3482 |
||
3483 |
||
3484 |
QPoint qt_mac_nativeMapFromParent(const QWidget *child, const QPoint &pt) |
|
3485 |
{ |
|
3486 |
#ifndef QT_MAC_USE_COCOA |
|
3487 |
CGPoint nativePoint = CGPointMake(pt.x(), pt.y()); |
|
3488 |
HIViewConvertPoint(&nativePoint, qt_mac_nativeview_for(child->parentWidget()), |
|
3489 |
qt_mac_nativeview_for(child)); |
|
3490 |
#else |
|
3491 |
NSPoint nativePoint = [qt_mac_nativeview_for(child) convertPoint:NSMakePoint(pt.x(), pt.y()) fromView:qt_mac_nativeview_for(child->parentWidget())]; |
|
3492 |
#endif |
|
3493 |
return QPoint(nativePoint.x, nativePoint.y); |
|
3494 |
} |
|
3495 |
||
3496 |
||
3497 |
void QWidgetPrivate::hide_sys() |
|
3498 |
{ |
|
3499 |
Q_Q(QWidget); |
|
3500 |
if((q->windowType() == Qt::Desktop)) //you can't hide the desktop! |
|
3501 |
return; |
|
3502 |
QMacCocoaAutoReleasePool pool; |
|
3503 |
if(q->isWindow()) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3504 |
#ifdef QT_MAC_USE_COCOA |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3505 |
setSubWindowStacking(false); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3506 |
#endif |
0 | 3507 |
OSWindowRef window = qt_mac_window_for(q); |
3508 |
if(qt_mac_is_macsheet(q)) { |
|
3509 |
#ifndef QT_MAC_USE_COCOA |
|
3510 |
WindowRef parent = 0; |
|
3511 |
if(GetSheetWindowParent(window, &parent) != noErr || !parent) |
|
3512 |
ShowHide(window, false); |
|
3513 |
else |
|
3514 |
HideSheetWindow(window); |
|
3515 |
#else |
|
3516 |
[NSApp endSheet:window]; |
|
3517 |
[window orderOut:window]; |
|
3518 |
#endif |
|
3519 |
} else if(qt_mac_is_macdrawer(q)) { |
|
3520 |
#ifndef QT_MAC_USE_COCOA |
|
3521 |
CloseDrawer(window, false); |
|
3522 |
#else |
|
3523 |
[qt_mac_drawer_for(q) close]; |
|
3524 |
#endif |
|
3525 |
} else { |
|
3526 |
#ifndef QT_MAC_USE_COCOA |
|
3527 |
ShowHide(window, false); |
|
3528 |
#else |
|
3529 |
[window orderOut:window]; |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3530 |
// Unfortunately it is not as easy as just hiding the window, we need |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3531 |
// to find out if we were in full screen mode. If we were and this is |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3532 |
// the last window in full screen mode then we need to unset the full screen |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3533 |
// mode. If this is not the last visible window in full screen mode then we |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3534 |
// don't change the full screen mode. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3535 |
if(q->isFullScreen()) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3536 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3537 |
bool keepFullScreen = false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3538 |
QWidgetList windowList = qApp->topLevelWidgets(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3539 |
int windowCount = windowList.count(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3540 |
for(int i = 0; i < windowCount; i++) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3541 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3542 |
QWidget *w = windowList[i]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3543 |
// If it is the same window, we don't need to check :-) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3544 |
if(q == w) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3545 |
continue; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3546 |
// If they are not visible or if they are minimized then |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3547 |
// we just ignore them. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3548 |
if(!w->isVisible() || w->isMinimized()) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3549 |
continue; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3550 |
// Is it full screen? |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3551 |
// Notice that if there is one window in full screen mode then we |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3552 |
// cannot switch the full screen mode off, therefore we just abort. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3553 |
if(w->isFullScreen()) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3554 |
keepFullScreen = true; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3555 |
break; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3556 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3557 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3558 |
// No windows in full screen mode, so let just unset that flag. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3559 |
if(!keepFullScreen) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3560 |
qt_mac_set_fullscreen_mode(false); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3561 |
} |
0 | 3562 |
#endif |
3563 |
toggleDrawers(false); |
|
3564 |
#ifndef QT_MAC_USE_COCOA |
|
3565 |
// Clear modality (because it seems something that we've always done). |
|
3566 |
if (data.window_modality != Qt::NonModal) { |
|
3567 |
SetWindowModality(window, kWindowModalityNone, |
|
3568 |
q->parentWidget() ? qt_mac_window_for(q->parentWidget()->window()) : 0); |
|
3569 |
} |
|
3570 |
#endif |
|
3571 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3572 |
#ifndef QT_MAC_USE_COCOA |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3573 |
// If the window we now hide was the active window, we need |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3574 |
// to find, and activate another window on screen. NB: Cocoa takes care of this |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3575 |
// logic for us (and distinquishes between main windows and key windows) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3576 |
if (q->isActiveWindow() && !(q->windowType() == Qt::Popup)) { |
0 | 3577 |
QWidget *w = 0; |
3578 |
if(q->parentWidget()) |
|
3579 |
w = q->parentWidget()->window(); |
|
3580 |
if(!w || (!w->isVisible() && !w->isMinimized())) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3581 |
for (WindowPtr wp = GetFrontWindowOfClass(kMovableModalWindowClass, true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3582 |
wp; wp = GetNextWindowOfClass(wp, kMovableModalWindowClass, true)) { |
0 | 3583 |
if((w = qt_mac_find_window(wp))) |
3584 |
break; |
|
3585 |
} |
|
3586 |
if (!w){ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3587 |
for (WindowPtr wp = GetFrontWindowOfClass(kDocumentWindowClass, true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3588 |
wp; wp = GetNextWindowOfClass(wp, kDocumentWindowClass, true)) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3589 |
if((w = qt_mac_find_window(wp))) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3590 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3591 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3592 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3593 |
if (!w){ |
0 | 3594 |
for(WindowPtr wp = GetFrontWindowOfClass(kSimpleWindowClass, true); |
3595 |
wp; wp = GetNextWindowOfClass(wp, kSimpleWindowClass, true)) { |
|
3596 |
if((w = qt_mac_find_window(wp))) |
|
3597 |
break; |
|
3598 |
} |
|
3599 |
} |
|
3600 |
} |
|
3601 |
if(w && w->isVisible() && !w->isMinimized()) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3602 |
qt_event_request_activate(w); |
0 | 3603 |
} |
3604 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3605 |
#endif |
0 | 3606 |
} else { |
3607 |
invalidateBuffer(q->rect()); |
|
3608 |
#ifndef QT_MAC_USE_COCOA |
|
3609 |
HIViewSetVisible(qt_mac_nativeview_for(q), false); |
|
3610 |
#else |
|
3611 |
[qt_mac_nativeview_for(q) setHidden:YES]; |
|
3612 |
#endif |
|
3613 |
} |
|
3614 |
||
3615 |
if (!QWidget::mouseGrabber()){ |
|
3616 |
QWidget *enterWidget = QApplication::widgetAt(QCursor::pos()); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3617 |
if (enterWidget && enterWidget->data->in_destructor) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3618 |
enterWidget = 0; |
0 | 3619 |
QApplicationPrivate::dispatchEnterLeave(enterWidget, qt_mouseover); |
3620 |
qt_mouseover = enterWidget; |
|
3621 |
} |
|
3622 |
||
3623 |
qt_event_request_window_change(q); |
|
3624 |
deactivateWidgetCleanup(); |
|
3625 |
qt_mac_event_release(q); |
|
3626 |
} |
|
3627 |
||
3628 |
void QWidget::setWindowState(Qt::WindowStates newstate) |
|
3629 |
{ |
|
3630 |
Q_D(QWidget); |
|
3631 |
bool needShow = false; |
|
3632 |
Qt::WindowStates oldstate = windowState(); |
|
3633 |
if (oldstate == newstate) |
|
3634 |
return; |
|
3635 |
||
3636 |
#ifdef QT_MAC_USE_COCOA |
|
3637 |
QMacCocoaAutoReleasePool pool; |
|
3638 |
#endif |
|
3639 |
bool needSendStateChange = true; |
|
3640 |
if(isWindow()) { |
|
3641 |
if((oldstate & Qt::WindowFullScreen) != (newstate & Qt::WindowFullScreen)) { |
|
3642 |
if(newstate & Qt::WindowFullScreen) { |
|
3643 |
if(QTLWExtra *tlextra = d->topData()) { |
|
3644 |
if(tlextra->normalGeometry.width() < 0) { |
|
3645 |
if(!testAttribute(Qt::WA_Resized)) |
|
3646 |
adjustSize(); |
|
3647 |
tlextra->normalGeometry = geometry(); |
|
3648 |
} |
|
3649 |
tlextra->savedFlags = windowFlags(); |
|
3650 |
} |
|
3651 |
needShow = isVisible(); |
|
3652 |
const QRect fullscreen(qApp->desktop()->screenGeometry(qApp->desktop()->screenNumber(this))); |
|
3653 |
setParent(parentWidget(), Qt::Window | Qt::FramelessWindowHint | (windowFlags() & 0xffff0000)); //save |
|
3654 |
setGeometry(fullscreen); |
|
3655 |
if(!qApp->desktop()->screenNumber(this)) |
|
3656 |
qt_mac_set_fullscreen_mode(true); |
|
3657 |
} else { |
|
3658 |
needShow = isVisible(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3659 |
if(!qApp->desktop()->screenNumber(this)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3660 |
qt_mac_set_fullscreen_mode(false); |
0 | 3661 |
setParent(parentWidget(), d->topData()->savedFlags); |
3662 |
setGeometry(d->topData()->normalGeometry); |
|
3663 |
d->topData()->normalGeometry.setRect(0, 0, -1, -1); |
|
3664 |
} |
|
3665 |
} |
|
3666 |
||
3667 |
d->createWinId(); |
|
3668 |
||
3669 |
OSWindowRef window = qt_mac_window_for(this); |
|
3670 |
if((oldstate & Qt::WindowMinimized) != (newstate & Qt::WindowMinimized)) { |
|
3671 |
if (newstate & Qt::WindowMinimized) { |
|
3672 |
#ifndef QT_MAC_USE_COCOA |
|
3673 |
CollapseWindow(window, true); |
|
3674 |
#else |
|
3675 |
[window miniaturize:window]; |
|
3676 |
#endif |
|
3677 |
} else { |
|
3678 |
#ifndef QT_MAC_USE_COCOA |
|
3679 |
CollapseWindow(window, false); |
|
3680 |
#else |
|
3681 |
[window deminiaturize:window]; |
|
3682 |
#endif |
|
3683 |
} |
|
3684 |
needSendStateChange = oldstate == windowState(); // Collapse didn't change our flags. |
|
3685 |
} |
|
3686 |
||
3687 |
if((newstate & Qt::WindowMaximized) && !((newstate & Qt::WindowFullScreen))) { |
|
3688 |
if(QTLWExtra *tlextra = d->topData()) { |
|
3689 |
if(tlextra->normalGeometry.width() < 0) { |
|
3690 |
if(!testAttribute(Qt::WA_Resized)) |
|
3691 |
adjustSize(); |
|
3692 |
tlextra->normalGeometry = geometry(); |
|
3693 |
} |
|
3694 |
} |
|
3695 |
} else if(!(newstate & Qt::WindowFullScreen)) { |
|
3696 |
// d->topData()->normalGeometry = QRect(0, 0, -1, -1); |
|
3697 |
} |
|
3698 |
||
3699 |
#ifdef DEBUG_WINDOW_STATE |
|
3700 |
#define WSTATE(x) qDebug("%s -- %s --> %s", #x, (oldstate & x) ? "true" : "false", (newstate & x) ? "true" : "false") |
|
3701 |
WSTATE(Qt::WindowMinimized); |
|
3702 |
WSTATE(Qt::WindowMaximized); |
|
3703 |
WSTATE(Qt::WindowFullScreen); |
|
3704 |
#undef WSTATE |
|
3705 |
#endif |
|
3706 |
if(!(newstate & (Qt::WindowMinimized|Qt::WindowFullScreen)) && |
|
3707 |
((oldstate & Qt::WindowFullScreen) || (oldstate & Qt::WindowMinimized) || |
|
3708 |
(oldstate & Qt::WindowMaximized) != (newstate & Qt::WindowMaximized))) { |
|
3709 |
if(newstate & Qt::WindowMaximized) { |
|
3710 |
data->fstrut_dirty = true; |
|
3711 |
#ifndef QT_MAC_USE_COCOA |
|
3712 |
HIToolbarRef toolbarRef; |
|
3713 |
if (GetWindowToolbar(window, &toolbarRef) == noErr && toolbarRef |
|
3714 |
&& !isVisible() && !IsWindowToolbarVisible(window)) { |
|
3715 |
// HIToolbar, needs to be shown so that it's in the structure window |
|
3716 |
// Typically this is part of a main window and will get shown |
|
3717 |
// during the show, but it's will make the maximize all wrong. |
|
3718 |
ShowHideWindowToolbar(window, true, false); |
|
3719 |
d->updateFrameStrut(); // In theory the dirty would work, but it's optimized out if the window is not visible :( |
|
3720 |
} |
|
3721 |
Rect bounds; |
|
3722 |
QDesktopWidget *dsk = QApplication::desktop(); |
|
3723 |
QRect avail = dsk->availableGeometry(dsk->screenNumber(this)); |
|
3724 |
SetRect(&bounds, avail.x(), avail.y(), avail.x() + avail.width(), avail.y() + avail.height()); |
|
3725 |
if(QWExtra *extra = d->extraData()) { |
|
3726 |
if(bounds.right - bounds.left > extra->maxw) |
|
3727 |
bounds.right = bounds.left + extra->maxw; |
|
3728 |
if(bounds.bottom - bounds.top > extra->maxh) |
|
3729 |
bounds.bottom = bounds.top + extra->maxh; |
|
3730 |
} |
|
3731 |
if(d->topData()) { |
|
3732 |
QRect fs = d->frameStrut(); |
|
3733 |
bounds.left += fs.left(); |
|
3734 |
if(bounds.right < avail.x()+avail.width()) |
|
3735 |
bounds.right = qMin<short>((uint)avail.x()+avail.width(), bounds.right+fs.left()); |
|
3736 |
if(bounds.bottom < avail.y()+avail.height()) |
|
3737 |
bounds.bottom = qMin<short>((uint)avail.y()+avail.height(), bounds.bottom+fs.top()); |
|
3738 |
bounds.top += fs.top(); |
|
3739 |
bounds.right -= fs.right(); |
|
3740 |
bounds.bottom -= fs.bottom(); |
|
3741 |
} |
|
3742 |
QRect orect(geometry().x(), geometry().y(), width(), height()), |
|
3743 |
nrect(bounds.left, bounds.top, bounds.right - bounds.left, |
|
3744 |
bounds.bottom - bounds.top); |
|
3745 |
if(orect != nrect) { // the new rect differ from the old |
|
3746 |
Point idealSize = { nrect.height(), nrect.width() }; |
|
3747 |
ZoomWindowIdeal(window, inZoomOut, &idealSize); |
|
3748 |
} |
|
3749 |
#else |
|
3750 |
NSToolbar *toolbarRef = [window toolbar]; |
|
3751 |
if (toolbarRef && !isVisible() && ![toolbarRef isVisible]) { |
|
3752 |
// HIToolbar, needs to be shown so that it's in the structure window |
|
3753 |
// Typically this is part of a main window and will get shown |
|
3754 |
// during the show, but it's will make the maximize all wrong. |
|
3755 |
// ### Not sure this is right for NSToolbar... |
|
3756 |
[toolbarRef setVisible:true]; |
|
3757 |
// ShowHideWindowToolbar(window, true, false); |
|
3758 |
d->updateFrameStrut(); // In theory the dirty would work, but it's optimized out if the window is not visible :( |
|
3759 |
} |
|
3760 |
// Everything should be handled by Cocoa. |
|
3761 |
[window zoom:window]; |
|
3762 |
#endif |
|
3763 |
needSendStateChange = oldstate == windowState(); // Zoom didn't change flags. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3764 |
} else if(oldstate & Qt::WindowMaximized && !(oldstate & Qt::WindowFullScreen)) { |
0 | 3765 |
#ifndef QT_MAC_USE_COCOA |
3766 |
Point idealSize; |
|
3767 |
ZoomWindowIdeal(window, inZoomIn, &idealSize); |
|
3768 |
#else |
|
3769 |
[window zoom:window]; |
|
3770 |
#endif |
|
3771 |
if(QTLWExtra *tlextra = d->topData()) { |
|
3772 |
setGeometry(tlextra->normalGeometry); |
|
3773 |
tlextra->normalGeometry.setRect(0, 0, -1, -1); |
|
3774 |
} |
|
3775 |
} |
|
3776 |
} |
|
3777 |
} |
|
3778 |
||
3779 |
data->window_state = newstate; |
|
3780 |
||
3781 |
if(needShow) |
|
3782 |
show(); |
|
3783 |
||
3784 |
if(newstate & Qt::WindowActive) |
|
3785 |
activateWindow(); |
|
3786 |
||
3787 |
qt_event_request_window_change(this); |
|
3788 |
if (needSendStateChange) { |
|
3789 |
QWindowStateChangeEvent e(oldstate); |
|
3790 |
QApplication::sendEvent(this, &e); |
|
3791 |
} |
|
3792 |
} |
|
3793 |
||
3794 |
void QWidgetPrivate::setFocus_sys() |
|
3795 |
{ |
|
3796 |
Q_Q(QWidget); |
|
3797 |
if (q->testAttribute(Qt::WA_WState_Created)) { |
|
3798 |
#ifdef QT_MAC_USE_COCOA |
|
3799 |
QMacCocoaAutoReleasePool pool; |
|
3800 |
NSView *view = qt_mac_nativeview_for(q); |
|
3801 |
[[view window] makeFirstResponder:view]; |
|
3802 |
#else |
|
3803 |
SetKeyboardFocus(qt_mac_window_for(q), qt_mac_nativeview_for(q), 1); |
|
3804 |
#endif |
|
3805 |
} |
|
3806 |
} |
|
3807 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3808 |
NSComparisonResult compareViews2Raise(id view1, id view2, void *context) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3809 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3810 |
id topView = reinterpret_cast<id>(context); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3811 |
if (view1 == topView) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3812 |
return NSOrderedDescending; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3813 |
if (view2 == topView) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3814 |
return NSOrderedAscending; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3815 |
return NSOrderedSame; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3816 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3817 |
|
0 | 3818 |
void QWidgetPrivate::raise_sys() |
3819 |
{ |
|
3820 |
Q_Q(QWidget); |
|
3821 |
if((q->windowType() == Qt::Desktop)) |
|
3822 |
return; |
|
3823 |
||
3824 |
#if QT_MAC_USE_COCOA |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3825 |
QMacCocoaAutoReleasePool pool; |
0 | 3826 |
if (isRealWindow()) { |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3827 |
// With the introduction of spaces it is not as simple as just raising the window. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3828 |
// First we need to check if we are in the right space. If we are, then we just continue |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3829 |
// as usual. The problem comes when we are not in the active space. There are two main cases: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3830 |
// 1. Our parent was moved to a new space. In this case we want the window to be raised |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3831 |
// in the same space as its parent. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3832 |
// 2. We don't have a parent. For this case we will just raise the window and let Cocoa |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3833 |
// switch to the corresponding space. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3834 |
// NOTICE: There are a lot of corner cases here. We are keeping this simple for now, if |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3835 |
// required we will introduce special handling for some of them. |
0 | 3836 |
if (!q->testAttribute(Qt::WA_DontShowOnScreen) && q->isVisible()) { |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3837 |
OSWindowRef window = qt_mac_window_for(q); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3838 |
// isOnActiveSpace is available only from 10.6 onwards, so we need to check if it is |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3839 |
// available before calling it. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3840 |
if([window respondsToSelector:@selector(isOnActiveSpace)]) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3841 |
if(![window performSelector:@selector(isOnActiveSpace)]) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3842 |
QWidget *parentWidget = q->parentWidget(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3843 |
if(parentWidget) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3844 |
OSWindowRef parentWindow = qt_mac_window_for(parentWidget); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3845 |
if(parentWindow && [parentWindow isOnActiveSpace]) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3846 |
// The window was created in a different space. Therefore if we want |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3847 |
// to show it in the current space we need to recreate it in the new |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3848 |
// space. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3849 |
recreateMacWindow(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3850 |
window = qt_mac_window_for(q); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3851 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3852 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3853 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3854 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3855 |
[window orderFront:window]; |
0 | 3856 |
} |
3857 |
if (qt_mac_raise_process) { //we get to be the active process now |
|
3858 |
ProcessSerialNumber psn; |
|
3859 |
GetCurrentProcess(&psn); |
|
3860 |
SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly); |
|
3861 |
} |
|
3862 |
} else { |
|
3863 |
NSView *view = qt_mac_nativeview_for(q); |
|
3864 |
NSView *parentView = [view superview]; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3865 |
[parentView sortSubviewsUsingFunction:compareViews2Raise context:reinterpret_cast<void *>(view)]; |
0 | 3866 |
} |
3867 |
#else |
|
3868 |
if(q->isWindow()) { |
|
3869 |
//raise this window |
|
3870 |
BringToFront(qt_mac_window_for(q)); |
|
3871 |
if(qt_mac_raise_process) { //we get to be the active process now |
|
3872 |
ProcessSerialNumber psn; |
|
3873 |
GetCurrentProcess(&psn); |
|
3874 |
SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly); |
|
3875 |
} |
|
3876 |
} else if(q->parentWidget()) { |
|
3877 |
HIViewSetZOrder(qt_mac_nativeview_for(q), kHIViewZOrderAbove, 0); |
|
3878 |
qt_event_request_window_change(q); |
|
3879 |
} |
|
3880 |
#endif |
|
3881 |
} |
|
3882 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3883 |
NSComparisonResult compareViews2Lower(id view1, id view2, void *context) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3884 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3885 |
id topView = reinterpret_cast<id>(context); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3886 |
if (view1 == topView) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3887 |
return NSOrderedAscending; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3888 |
if (view2 == topView) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3889 |
return NSOrderedDescending; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3890 |
return NSOrderedSame; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3891 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3892 |
|
0 | 3893 |
void QWidgetPrivate::lower_sys() |
3894 |
{ |
|
3895 |
Q_Q(QWidget); |
|
3896 |
if((q->windowType() == Qt::Desktop)) |
|
3897 |
return; |
|
3898 |
#ifdef QT_MAC_USE_COCOA |
|
3899 |
if (isRealWindow()) { |
|
3900 |
OSWindowRef window = qt_mac_window_for(q); |
|
3901 |
[window orderBack:window]; |
|
3902 |
} else { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3903 |
NSView *view = qt_mac_nativeview_for(q); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3904 |
NSView *parentView = [view superview]; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3905 |
[parentView sortSubviewsUsingFunction:compareViews2Lower context:reinterpret_cast<void *>(view)]; |
0 | 3906 |
} |
3907 |
#else |
|
3908 |
if(q->isWindow()) { |
|
3909 |
SendBehind(qt_mac_window_for(q), 0); |
|
3910 |
} else if(q->parentWidget()) { |
|
3911 |
invalidateBuffer(q->rect()); |
|
3912 |
HIViewSetZOrder(qt_mac_nativeview_for(q), kHIViewZOrderBelow, 0); |
|
3913 |
qt_event_request_window_change(q); |
|
3914 |
} |
|
3915 |
#endif |
|
3916 |
} |
|
3917 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3918 |
NSComparisonResult compareViews2StackUnder(id view1, id view2, void *context) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3919 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3920 |
const QHash<NSView *, int> &viewOrder = *reinterpret_cast<QHash<NSView *, int> *>(context); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3921 |
if (viewOrder[view1] < viewOrder[view2]) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3922 |
return NSOrderedAscending; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3923 |
if (viewOrder[view1] > viewOrder[view2]) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3924 |
return NSOrderedDescending; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3925 |
return NSOrderedSame; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3926 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3927 |
|
0 | 3928 |
void QWidgetPrivate::stackUnder_sys(QWidget *w) |
3929 |
{ |
|
3930 |
// stackUnder |
|
3931 |
Q_Q(QWidget); |
|
3932 |
if(!w || q->isWindow() || (q->windowType() == Qt::Desktop)) |
|
3933 |
return; |
|
3934 |
#ifdef QT_MAC_USE_COCOA |
|
3935 |
// Do the same trick as lower_sys() and put this widget before the widget passed in. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3936 |
NSView *myView = qt_mac_nativeview_for(q); |
0 | 3937 |
NSView *wView = qt_mac_nativeview_for(w); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3938 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3939 |
QHash<NSView *, int> viewOrder; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3940 |
NSView *parentView = [myView superview]; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3941 |
NSArray *subviews = [parentView subviews]; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3942 |
NSUInteger index = 1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3943 |
// make a hash of view->zorderindex and make sure z-value is always odd, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3944 |
// so that when we modify the order we create a new (even) z-value which |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3945 |
// will not interfere with others. |
0 | 3946 |
for (NSView *subview in subviews) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3947 |
viewOrder.insert(subview, index * 2); |
0 | 3948 |
++index; |
3949 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3950 |
viewOrder[myView] = viewOrder[wView] - 1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3951 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3952 |
[parentView sortSubviewsUsingFunction:compareViews2StackUnder context:reinterpret_cast<void *>(&viewOrder)]; |
0 | 3953 |
#else |
3954 |
QWidget *p = q->parentWidget(); |
|
3955 |
if(!p || p != w->parentWidget()) |
|
3956 |
return; |
|
3957 |
invalidateBuffer(q->rect()); |
|
3958 |
HIViewSetZOrder(qt_mac_nativeview_for(q), kHIViewZOrderBelow, qt_mac_nativeview_for(w)); |
|
3959 |
qt_event_request_window_change(q); |
|
3960 |
#endif |
|
3961 |
} |
|
3962 |
||
3963 |
/* |
|
3964 |
Modifies the bounds for a widgets backing HIView during moves and resizes. Also updates the |
|
3965 |
widget, either by scrolling its contents or repainting, depending on the WA_StaticContents |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3966 |
flag |
0 | 3967 |
*/ |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
3968 |
static void qt_mac_update_widget_position(QWidget *q, QRect oldRect, QRect newRect) |
0 | 3969 |
{ |
3970 |
#ifndef QT_MAC_USE_COCOA |
|
3971 |
HIRect bounds = CGRectMake(newRect.x(), newRect.y(), |
|
3972 |
newRect.width(), newRect.height()); |
|
3973 |
||
3974 |
const HIViewRef view = qt_mac_nativeview_for(q); |
|
3975 |
const bool isMove = (oldRect.topLeft() != newRect.topLeft()); |
|
3976 |
const bool isResize = (oldRect.size() != newRect.size()); |
|
3977 |
||
3978 |
// qDebug() << oldRect << newRect << isMove << isResize << q->testAttribute(Qt::WA_OpaquePaintEvent) << q->testAttribute(Qt::WA_StaticContents); |
|
3979 |
QWidgetPrivate *qd = qt_widget_private(q); |
|
3980 |
||
3981 |
// Perform a normal (complete repaint) update in some cases: |
|
3982 |
if ( |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3983 |
// always repaint on move. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3984 |
(isMove) || |
0 | 3985 |
|
3986 |
// limited update on resize requires WA_StaticContents. |
|
3987 |
(isResize && q->testAttribute(Qt::WA_StaticContents) == false) || |
|
3988 |
||
3989 |
// one of the rects are invalid |
|
3990 |
(oldRect.isValid() == false || newRect.isValid() == false) || |
|
3991 |
||
3992 |
// the position update is a part of a drag-and-drop operation |
|
3993 |
QDragManager::self()->object || |
|
3994 |
||
3995 |
// we are on Panther (no HIViewSetNeedsDisplayInRect) |
|
3996 |
QSysInfo::MacintoshVersion < QSysInfo::MV_10_4 |
|
3997 |
){ |
|
3998 |
HIViewSetFrame(view, &bounds); |
|
3999 |
return; |
|
4000 |
} |
|
4001 |
||
4002 |
const int dx = newRect.x() - oldRect.x(); |
|
4003 |
const int dy = newRect.y() - oldRect.y(); |
|
4004 |
||
4005 |
if (isMove) { |
|
4006 |
// HIViewScrollRect silently fails if we try to scroll anything under the grow box. |
|
4007 |
// Check if there's one present within the widget rect, and if there is fall back |
|
4008 |
// to repainting the entire widget. |
|
4009 |
QWidget const * const parentWidget = q->parentWidget(); |
|
4010 |
const HIViewRef parentView = qt_mac_nativeview_for(parentWidget); |
|
4011 |
HIViewRef nativeSizeGrip = 0; |
|
4012 |
if (q->testAttribute(Qt::WA_WState_Created)) |
|
4013 |
HIViewFindByID(HIViewGetRoot(HIViewGetWindow(HIViewRef(q->winId()))), kHIViewWindowGrowBoxID, &nativeSizeGrip); |
|
4014 |
if (nativeSizeGrip) { |
|
4015 |
QWidget * const window = q->window(); |
|
4016 |
||
4017 |
const int sizeGripSize = 20; |
|
4018 |
const QRect oldWidgetRect = QRect(q->mapTo(window, QPoint(0, 0)), QSize(oldRect.width(), oldRect.height())); |
|
4019 |
const QRect newWidgetRect = QRect(q->mapTo(window, QPoint(0, 0)), QSize(newRect.width(), newRect.height())); |
|
4020 |
const QRect sizeGripRect = QRect(window->rect().bottomRight() - QPoint(sizeGripSize, sizeGripSize), |
|
4021 |
window->rect().bottomRight()); |
|
4022 |
||
4023 |
if (sizeGripRect.intersects(oldWidgetRect) || sizeGripRect.intersects(newWidgetRect)) { |
|
4024 |
HIViewSetFrame(view, &bounds); |
|
4025 |
return; |
|
4026 |
} |
|
4027 |
} |
|
4028 |
||
4029 |
// Don't scroll anything outside the parent widget rect. |
|
4030 |
const QRect scrollRect = (oldRect | newRect) & parentWidget->rect(); |
|
4031 |
const HIRect scrollBounds = |
|
4032 |
CGRectMake(scrollRect.x(), scrollRect.y(), scrollRect.width(), scrollRect.height()); |
|
4033 |
||
4034 |
// We cannot scroll when the widget has a mask as that would |
|
4035 |
// scroll the masked out areas too |
|
4036 |
if (qd->extra && qd->extra->hasMask) { |
|
4037 |
HIViewMoveBy(view, dx, dy); |
|
4038 |
return; |
|
4039 |
} |
|
4040 |
||
4041 |
OSStatus err = HIViewScrollRect(parentView, &scrollBounds, dx, dy); |
|
4042 |
if (err != noErr) { |
|
4043 |
HIViewSetNeedsDisplay(view, true); |
|
4044 |
qWarning("QWidget: Internal error (%s:%d)", __FILE__, __LINE__); |
|
4045 |
} |
|
4046 |
} |
|
4047 |
// Set the view bounds with drawing disabled to prevent repaints. |
|
4048 |
HIViewSetDrawingEnabled(view, false); |
|
4049 |
HIViewSetFrame(view, &bounds); |
|
4050 |
HIViewSetDrawingEnabled(view, true); |
|
4051 |
||
4052 |
// Update any newly exposed areas due to resizing. |
|
4053 |
const int startx = oldRect.width(); |
|
4054 |
const int stopx = newRect.width(); |
|
4055 |
const int starty = oldRect.height(); |
|
4056 |
const int stopy = newRect.height(); |
|
4057 |
||
4058 |
const HIRect verticalSlice = CGRectMake(startx, 0, stopx , stopy); |
|
4059 |
HIViewSetNeedsDisplayInRect(view, &verticalSlice, true); |
|
4060 |
const HIRect horizontalSlice = CGRectMake(0, starty, startx, stopy); |
|
4061 |
HIViewSetNeedsDisplayInRect(view, &horizontalSlice, true); |
|
4062 |
#else |
|
4063 |
Q_UNUSED(oldRect); |
|
4064 |
NSRect bounds = NSMakeRect(newRect.x(), newRect.y(), |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4065 |
newRect.width(), newRect.height()); |
0 | 4066 |
[qt_mac_nativeview_for(q) setFrame:bounds]; |
4067 |
#endif |
|
4068 |
} |
|
4069 |
||
4070 |
/* |
|
4071 |
Helper function for non-toplevel widgets. Helps to map Qt's 32bit |
|
4072 |
coordinate system to OS X's 16bit coordinate system. |
|
4073 |
||
4074 |
Sets the geometry of the widget to data.crect, but clipped to sizes |
|
4075 |
that OS X can handle. Unmaps widgets that are completely outside the |
|
4076 |
valid range. |
|
4077 |
||
4078 |
Maintains data.wrect, which is the geometry of the OS X widget, |
|
4079 |
measured in this widget's coordinate system. |
|
4080 |
||
4081 |
if the parent is not clipped, parentWRect is empty, otherwise |
|
4082 |
parentWRect is the geometry of the parent's OS X rect, measured in |
|
4083 |
parent's coord sys |
|
4084 |
*/ |
|
4085 |
void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &oldRect) |
|
4086 |
{ |
|
4087 |
Q_Q(QWidget); |
|
4088 |
Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); |
|
4089 |
Q_UNUSED(oldRect); |
|
4090 |
/* |
|
4091 |
There are up to four different coordinate systems here: |
|
4092 |
Qt coordinate system for this widget. |
|
4093 |
X coordinate system for this widget (relative to wrect). |
|
4094 |
Qt coordinate system for parent |
|
4095 |
X coordinate system for parent (relative to parent's wrect). |
|
4096 |
*/ |
|
4097 |
QRect wrect; |
|
4098 |
//xrect is the X geometry of my X widget. (starts out in parent's Qt coord sys, and ends up in parent's X coord sys) |
|
4099 |
QRect xrect = data.crect; |
|
4100 |
||
4101 |
QRect parentWRect; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4102 |
bool isEmbeddedWindow = (q->isWindow() && topData()->embedded); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4103 |
if (isEmbeddedWindow) { |
0 | 4104 |
#ifndef QT_MAC_USE_COCOA |
4105 |
HIViewRef parentView = HIViewGetSuperview(qt_mac_nativeview_for(q)); |
|
4106 |
#else |
|
4107 |
NSView *parentView = [qt_mac_nativeview_for(q) superview]; |
|
4108 |
#endif |
|
4109 |
if (parentView) { |
|
4110 |
#ifndef QT_MAC_USE_COCOA |
|
4111 |
HIRect tmpRect; |
|
4112 |
HIViewGetFrame(parentView, &tmpRect); |
|
4113 |
#else |
|
4114 |
NSRect tmpRect = [parentView frame]; |
|
4115 |
#endif |
|
4116 |
parentWRect = QRect(tmpRect.origin.x, tmpRect.origin.y, |
|
4117 |
tmpRect.size.width, tmpRect.size.height); |
|
4118 |
} else { |
|
4119 |
const QRect wrectRange(-WRECT_MAX,-WRECT_MAX, 2*WRECT_MAX, 2*WRECT_MAX); |
|
4120 |
parentWRect = wrectRange; |
|
4121 |
} |
|
4122 |
} else { |
|
4123 |
parentWRect = q->parentWidget()->data->wrect; |
|
4124 |
} |
|
4125 |
||
4126 |
if (parentWRect.isValid()) { |
|
4127 |
// parent is clipped, and we have to clip to the same limit as parent |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4128 |
if (!parentWRect.contains(xrect) && !isEmbeddedWindow) { |
0 | 4129 |
xrect &= parentWRect; |
4130 |
wrect = xrect; |
|
4131 |
//translate from parent's to my Qt coord sys |
|
4132 |
wrect.translate(-data.crect.topLeft()); |
|
4133 |
} |
|
4134 |
//translate from parent's Qt coords to parent's X coords |
|
4135 |
xrect.translate(-parentWRect.topLeft()); |
|
4136 |
||
4137 |
} else { |
|
4138 |
// parent is not clipped, we may or may not have to clip |
|
4139 |
||
4140 |
if (data.wrect.isValid() && QRect(QPoint(),data.crect.size()).contains(data.wrect)) { |
|
4141 |
// This is where the main optimization is: we are already |
|
4142 |
// clipped, and if our clip is still valid, we can just |
|
4143 |
// move our window, and do not need to move or clip |
|
4144 |
// children |
|
4145 |
||
4146 |
QRect vrect = xrect & q->parentWidget()->rect(); |
|
4147 |
vrect.translate(-data.crect.topLeft()); //the part of me that's visible through parent, in my Qt coords |
|
4148 |
if (data.wrect.contains(vrect)) { |
|
4149 |
xrect = data.wrect; |
|
4150 |
xrect.translate(data.crect.topLeft()); |
|
4151 |
#ifndef QT_MAC_USE_COCOA |
|
4152 |
HIRect bounds = CGRectMake(xrect.x(), xrect.y(), |
|
4153 |
xrect.width(), xrect.height()); |
|
4154 |
HIViewSetFrame(qt_mac_nativeview_for(q), &bounds); |
|
4155 |
#else |
|
4156 |
NSRect bounds = NSMakeRect(xrect.x(), xrect.y(), |
|
4157 |
xrect.width(), xrect.height()); |
|
4158 |
[qt_mac_nativeview_for(q) setFrame:bounds]; |
|
4159 |
#endif |
|
4160 |
if (q->testAttribute(Qt::WA_OutsideWSRange)) { |
|
4161 |
q->setAttribute(Qt::WA_OutsideWSRange, false); |
|
4162 |
if (!dontShow) { |
|
4163 |
q->setAttribute(Qt::WA_Mapped); |
|
4164 |
#ifndef QT_MAC_USE_COCOA |
|
4165 |
HIViewSetVisible(qt_mac_nativeview_for(q), true); |
|
4166 |
#else |
|
4167 |
[qt_mac_nativeview_for(q) setHidden:NO]; |
|
4168 |
#endif |
|
4169 |
} |
|
4170 |
} |
|
4171 |
return; |
|
4172 |
} |
|
4173 |
} |
|
4174 |
||
4175 |
const QRect validRange(-XCOORD_MAX,-XCOORD_MAX, 2*XCOORD_MAX, 2*XCOORD_MAX); |
|
4176 |
if (!validRange.contains(xrect)) { |
|
4177 |
// we are too big, and must clip |
|
4178 |
QPoint screenOffset(0, 0); // offset of the part being on screen |
|
4179 |
const QWidget *parentWidget = q->parentWidget(); |
|
4180 |
while (parentWidget && !parentWidget->isWindow()) { |
|
4181 |
screenOffset -= parentWidget->data->crect.topLeft(); |
|
4182 |
parentWidget = parentWidget->parentWidget(); |
|
4183 |
} |
|
4184 |
QRect cropRect(screenOffset.x() - WRECT_MAX, |
|
4185 |
screenOffset.y() - WRECT_MAX, |
|
4186 |
2*WRECT_MAX, |
|
4187 |
2*WRECT_MAX); |
|
4188 |
||
4189 |
xrect &=cropRect; |
|
4190 |
wrect = xrect; |
|
4191 |
wrect.translate(-data.crect.topLeft()); // translate wrect in my Qt coordinates |
|
4192 |
} |
|
4193 |
} |
|
4194 |
||
4195 |
// unmap if we are outside the valid window system coord system |
|
4196 |
bool outsideRange = !xrect.isValid(); |
|
4197 |
bool mapWindow = false; |
|
4198 |
if (q->testAttribute(Qt::WA_OutsideWSRange) != outsideRange) { |
|
4199 |
q->setAttribute(Qt::WA_OutsideWSRange, outsideRange); |
|
4200 |
if (outsideRange) { |
|
4201 |
#ifndef QT_MAC_USE_COCOA |
|
4202 |
HIViewSetVisible(qt_mac_nativeview_for(q), false); |
|
4203 |
#else |
|
4204 |
[qt_mac_nativeview_for(q) setHidden:YES]; |
|
4205 |
#endif |
|
4206 |
q->setAttribute(Qt::WA_Mapped, false); |
|
4207 |
} else if (!q->isHidden()) { |
|
4208 |
mapWindow = true; |
|
4209 |
} |
|
4210 |
} |
|
4211 |
||
4212 |
if (outsideRange) |
|
4213 |
return; |
|
4214 |
||
4215 |
bool jump = (data.wrect != wrect); |
|
4216 |
data.wrect = wrect; |
|
4217 |
||
4218 |
||
4219 |
// and now recursively for all children... |
|
4220 |
// ### can be optimized |
|
4221 |
for (int i = 0; i < children.size(); ++i) { |
|
4222 |
QObject *object = children.at(i); |
|
4223 |
if (object->isWidgetType()) { |
|
4224 |
QWidget *w = static_cast<QWidget *>(object); |
|
4225 |
if (!w->isWindow() && w->testAttribute(Qt::WA_WState_Created)) |
|
4226 |
w->d_func()->setWSGeometry(); |
|
4227 |
} |
|
4228 |
} |
|
4229 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4230 |
qt_mac_update_widget_position(q, oldRect, xrect); |
0 | 4231 |
|
4232 |
if (jump) |
|
4233 |
q->update(); |
|
4234 |
||
4235 |
if (mapWindow && !dontShow) { |
|
4236 |
q->setAttribute(Qt::WA_Mapped); |
|
4237 |
#ifndef QT_MAC_USE_COCOA |
|
4238 |
HIViewSetVisible(qt_mac_nativeview_for(q), true); |
|
4239 |
#else |
|
4240 |
[qt_mac_nativeview_for(q) setHidden:NO]; |
|
4241 |
#endif |
|
4242 |
} |
|
4243 |
} |
|
4244 |
||
4245 |
void QWidgetPrivate::adjustWithinMaxAndMinSize(int &w, int &h) |
|
4246 |
{ |
|
4247 |
if (QWExtra *extra = extraData()) { |
|
4248 |
w = qMin(w, extra->maxw); |
|
4249 |
h = qMin(h, extra->maxh); |
|
4250 |
w = qMax(w, extra->minw); |
|
4251 |
h = qMax(h, extra->minh); |
|
4252 |
||
4253 |
// Deal with size increment |
|
4254 |
if (QTLWExtra *top = topData()) { |
|
4255 |
if(top->incw) { |
|
4256 |
w = w/top->incw; |
|
4257 |
w *= top->incw; |
|
4258 |
} |
|
4259 |
if(top->inch) { |
|
4260 |
h = h/top->inch; |
|
4261 |
h *= top->inch; |
|
4262 |
} |
|
4263 |
} |
|
4264 |
} |
|
4265 |
||
4266 |
if (isRealWindow()) { |
|
4267 |
w = qMax(0, w); |
|
4268 |
h = qMax(0, h); |
|
4269 |
} |
|
4270 |
} |
|
4271 |
||
4272 |
void QWidgetPrivate::applyMaxAndMinSizeOnWindow() |
|
4273 |
{ |
|
4274 |
Q_Q(QWidget); |
|
4275 |
const float max_f(20000); |
|
4276 |
#ifndef QT_MAC_USE_COCOA |
|
4277 |
#define SF(x) ((x > max_f) ? max_f : x) |
|
4278 |
HISize max = CGSizeMake(SF(extra->maxw), SF(extra->maxh)); |
|
4279 |
HISize min = CGSizeMake(SF(extra->minw), SF(extra->minh)); |
|
4280 |
#undef SF |
|
4281 |
SetWindowResizeLimits(qt_mac_window_for(q), &min, &max); |
|
4282 |
#else |
|
4283 |
#define SF(x) ((x > max_f) ? max_f : x) |
|
4284 |
NSSize max = NSMakeSize(SF(extra->maxw), SF(extra->maxh)); |
|
4285 |
NSSize min = NSMakeSize(SF(extra->minw), SF(extra->minh)); |
|
4286 |
#undef SF |
|
4287 |
[qt_mac_window_for(q) setContentMinSize:min]; |
|
4288 |
[qt_mac_window_for(q) setContentMaxSize:max]; |
|
4289 |
#endif |
|
4290 |
} |
|
4291 |
||
4292 |
void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove) |
|
4293 |
{ |
|
4294 |
Q_Q(QWidget); |
|
4295 |
Q_ASSERT(q->testAttribute(Qt::WA_WState_Created)); |
|
4296 |
||
4297 |
if(q->windowType() == Qt::Desktop) |
|
4298 |
return; |
|
4299 |
||
4300 |
QMacCocoaAutoReleasePool pool; |
|
4301 |
bool realWindow = isRealWindow(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4302 |
BOOL needDisplay = realWindow ? YES : NO; |
0 | 4303 |
|
4304 |
if (realWindow && !q->testAttribute(Qt::WA_DontShowOnScreen)){ |
|
4305 |
adjustWithinMaxAndMinSize(w, h); |
|
4306 |
#ifndef QT_MAC_USE_COCOA |
|
4307 |
if (w != 0 && h != 0) { |
|
4308 |
topData()->isSetGeometry = 1; |
|
4309 |
topData()->isMove = isMove; |
|
4310 |
Rect r; SetRect(&r, x, y, x + w, y + h); |
|
4311 |
SetWindowBounds(qt_mac_window_for(q), kWindowContentRgn, &r); |
|
4312 |
topData()->isSetGeometry = 0; |
|
4313 |
} else { |
|
4314 |
setGeometry_sys_helper(x, y, w, h, isMove); |
|
4315 |
} |
|
4316 |
#else |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4317 |
if (!isMove && !q->testAttribute(Qt::WA_Moved) && !q->isVisible()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4318 |
// INVARIANT: The location of the window has not yet been set. The default will |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4319 |
// instead be to center it on the desktop, or over the parent, if any. Since we now |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4320 |
// resize the window, we need to adjust the top left position to keep the window |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4321 |
// centeralized. And we need to to this now (and before show) in case the positioning |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4322 |
// of other windows (e.g. sub-windows) depend on this position: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4323 |
if (QWidget *p = q->parentWidget()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4324 |
x = p->geometry().center().x() - (w / 2); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4325 |
y = p->geometry().center().y() - (h / 2); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4326 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4327 |
QRect availGeo = QApplication::desktop()->availableGeometry(q); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4328 |
x = availGeo.center().x() - (w / 2); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4329 |
y = availGeo.center().y() - (h / 2); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4330 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4331 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4332 |
|
0 | 4333 |
QSize olds = q->size(); |
4334 |
const bool isResize = (olds != QSize(w, h)); |
|
4335 |
NSWindow *window = qt_mac_window_for(q); |
|
4336 |
const QRect &fStrut = frameStrut(); |
|
4337 |
const QRect frameRect(QPoint(x - fStrut.left(), y - fStrut.top()), |
|
4338 |
QSize(fStrut.left() + fStrut.right() + w, |
|
4339 |
fStrut.top() + fStrut.bottom() + h)); |
|
4340 |
NSRect cocoaFrameRect = NSMakeRect(frameRect.x(), flipYCoordinate(frameRect.bottom() + 1), |
|
4341 |
frameRect.width(), frameRect.height()); |
|
4342 |
// The setFrame call will trigger a 'windowDidResize' notification for the corresponding |
|
4343 |
// NSWindow. The pending flag is set, so that the resize event can be send as non-spontaneous. |
|
4344 |
if (isResize) |
|
4345 |
q->setAttribute(Qt::WA_PendingResizeEvent); |
|
4346 |
QPoint currTopLeft = data.crect.topLeft(); |
|
4347 |
if (currTopLeft.x() == x && currTopLeft.y() == y |
|
4348 |
&& cocoaFrameRect.size.width != 0 |
|
4349 |
&& cocoaFrameRect.size.height != 0) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4350 |
[window setFrame:cocoaFrameRect display:needDisplay]; |
0 | 4351 |
} else { |
4352 |
// The window is moved and resized (or resized to zero). |
|
4353 |
// Since Cocoa usually only sends us a resize callback after |
|
4354 |
// setting a window frame, we issue an explicit move as |
|
4355 |
// well. To stop Cocoa from optimize away the move (since the move |
|
4356 |
// would have the same origin as the setFrame call) we shift the |
|
4357 |
// window back and forth inbetween. |
|
4358 |
cocoaFrameRect.origin.y += 1; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4359 |
[window setFrame:cocoaFrameRect display:needDisplay]; |
0 | 4360 |
cocoaFrameRect.origin.y -= 1; |
4361 |
[window setFrameOrigin:cocoaFrameRect.origin]; |
|
4362 |
} |
|
4363 |
#endif |
|
4364 |
} else { |
|
4365 |
setGeometry_sys_helper(x, y, w, h, isMove); |
|
4366 |
} |
|
4367 |
} |
|
4368 |
||
4369 |
void QWidgetPrivate::setGeometry_sys_helper(int x, int y, int w, int h, bool isMove) |
|
4370 |
{ |
|
4371 |
Q_Q(QWidget); |
|
4372 |
bool realWindow = isRealWindow(); |
|
4373 |
||
4374 |
QPoint oldp = q->pos(); |
|
4375 |
QSize olds = q->size(); |
|
4376 |
const bool isResize = (olds != QSize(w, h)); |
|
4377 |
||
4378 |
if (!realWindow && !isResize && QPoint(x, y) == oldp) |
|
4379 |
return; |
|
4380 |
||
4381 |
if (isResize) |
|
4382 |
data.window_state = data.window_state & ~Qt::WindowMaximized; |
|
4383 |
||
4384 |
const bool visible = q->isVisible(); |
|
4385 |
data.crect = QRect(x, y, w, h); |
|
4386 |
||
4387 |
if (realWindow) { |
|
4388 |
adjustWithinMaxAndMinSize(w, h); |
|
4389 |
qt_mac_update_sizer(q); |
|
4390 |
||
4391 |
#ifndef QT_MAC_USE_COCOA |
|
4392 |
if (q->windowFlags() & Qt::WindowMaximizeButtonHint) { |
|
4393 |
OSWindowRef window = qt_mac_window_for(q); |
|
4394 |
if (extra->maxw && extra->maxh && extra->maxw == extra->minw |
|
4395 |
&& extra->maxh == extra->minh) { |
|
4396 |
ChangeWindowAttributes(window, kWindowNoAttributes, kWindowFullZoomAttribute); |
|
4397 |
} else { |
|
4398 |
ChangeWindowAttributes(window, kWindowFullZoomAttribute, kWindowNoAttributes); |
|
4399 |
} |
|
4400 |
} |
|
4401 |
HIRect bounds = CGRectMake(0, 0, w, h); |
|
4402 |
HIViewSetFrame(qt_mac_nativeview_for(q), &bounds); |
|
4403 |
#else |
|
4404 |
[qt_mac_nativeview_for(q) setFrame:NSMakeRect(0, 0, w, h)]; |
|
4405 |
#endif |
|
4406 |
} else { |
|
4407 |
const QRect oldRect(oldp, olds); |
|
4408 |
if (!isResize && QApplicationPrivate::graphicsSystem()) |
|
4409 |
moveRect(oldRect, x - oldp.x(), y - oldp.y()); |
|
4410 |
setWSGeometry(false, oldRect); |
|
4411 |
if (isResize && QApplicationPrivate::graphicsSystem()) { |
|
4412 |
invalidateBuffer(q->rect()); |
|
4413 |
if (extra && !graphicsEffect && !extra->mask.isEmpty()) { |
|
4414 |
QRegion oldRegion(extra->mask.translated(oldp)); |
|
4415 |
oldRegion &= oldRect; |
|
4416 |
q->parentWidget()->d_func()->invalidateBuffer(oldRegion); |
|
4417 |
} else { |
|
4418 |
q->parentWidget()->d_func()->invalidateBuffer(effectiveRectFor(oldRect)); |
|
4419 |
} |
|
4420 |
} |
|
4421 |
} |
|
4422 |
||
4423 |
if(isMove || isResize) { |
|
4424 |
if(!visible) { |
|
4425 |
if(isMove && q->pos() != oldp) |
|
4426 |
q->setAttribute(Qt::WA_PendingMoveEvent, true); |
|
4427 |
if(isResize) |
|
4428 |
q->setAttribute(Qt::WA_PendingResizeEvent, true); |
|
4429 |
} else { |
|
4430 |
if(isResize) { //send the resize event.. |
|
4431 |
QResizeEvent e(q->size(), olds); |
|
4432 |
QApplication::sendEvent(q, &e); |
|
4433 |
} |
|
4434 |
if(isMove && q->pos() != oldp) { //send the move event.. |
|
4435 |
QMoveEvent e(q->pos(), oldp); |
|
4436 |
QApplication::sendEvent(q, &e); |
|
4437 |
} |
|
4438 |
} |
|
4439 |
} |
|
4440 |
qt_event_request_window_change(q); |
|
4441 |
} |
|
4442 |
||
4443 |
void QWidgetPrivate::setConstraints_sys() |
|
4444 |
{ |
|
4445 |
updateMaximizeButton_sys(); |
|
4446 |
applyMaxAndMinSizeOnWindow(); |
|
4447 |
} |
|
4448 |
||
4449 |
void QWidgetPrivate::updateMaximizeButton_sys() |
|
4450 |
{ |
|
4451 |
Q_Q(QWidget); |
|
4452 |
if (q->data->window_flags & Qt::CustomizeWindowHint) |
|
4453 |
return; |
|
4454 |
||
4455 |
OSWindowRef window = qt_mac_window_for(q); |
|
4456 |
QTLWExtra * tlwExtra = topData(); |
|
4457 |
#ifdef QT_MAC_USE_COCOA |
|
4458 |
QMacCocoaAutoReleasePool pool; |
|
4459 |
NSButton *maximizeButton = [window standardWindowButton:NSWindowZoomButton]; |
|
4460 |
#endif |
|
4461 |
if (extra->maxw && extra->maxh |
|
4462 |
&& extra->maxw == extra->minw |
|
4463 |
&& extra->maxh == extra->minh) { |
|
4464 |
// The window has a fixed size, so gray out the maximize button: |
|
4465 |
if (!tlwExtra->savedWindowAttributesFromMaximized) { |
|
4466 |
#ifndef QT_MAC_USE_COCOA |
|
4467 |
GetWindowAttributes(window, |
|
4468 |
(WindowAttributes*)&extra->topextra->savedWindowAttributesFromMaximized); |
|
4469 |
||
4470 |
#else |
|
4471 |
tlwExtra->savedWindowAttributesFromMaximized = (![maximizeButton isHidden] && [maximizeButton isEnabled]); |
|
4472 |
#endif |
|
4473 |
} |
|
4474 |
#ifndef QT_MAC_USE_COCOA |
|
4475 |
ChangeWindowAttributes(window, kWindowNoAttributes, kWindowFullZoomAttribute); |
|
4476 |
#else |
|
4477 |
[maximizeButton setEnabled:NO]; |
|
4478 |
#endif |
|
4479 |
||
4480 |
||
4481 |
} else { |
|
4482 |
if (tlwExtra->savedWindowAttributesFromMaximized) { |
|
4483 |
#ifndef QT_MAC_USE_COCOA |
|
4484 |
ChangeWindowAttributes(window, |
|
4485 |
extra->topextra->savedWindowAttributesFromMaximized, |
|
4486 |
kWindowNoAttributes); |
|
4487 |
#else |
|
4488 |
[maximizeButton setEnabled:YES]; |
|
4489 |
#endif |
|
4490 |
tlwExtra->savedWindowAttributesFromMaximized = 0; |
|
4491 |
} |
|
4492 |
} |
|
4493 |
||
4494 |
||
4495 |
} |
|
4496 |
||
4497 |
void QWidgetPrivate::scroll_sys(int dx, int dy) |
|
4498 |
{ |
|
4499 |
if (QApplicationPrivate::graphicsSystem() && !paintOnScreen()) { |
|
4500 |
scrollChildren(dx, dy); |
|
4501 |
scrollRect(q_func()->rect(), dx, dy); |
|
4502 |
} else { |
|
4503 |
scroll_sys(dx, dy, QRect()); |
|
4504 |
} |
|
4505 |
} |
|
4506 |
||
4507 |
void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &r) |
|
4508 |
{ |
|
4509 |
Q_Q(QWidget); |
|
4510 |
||
4511 |
if (QApplicationPrivate::graphicsSystem() && !paintOnScreen()) { |
|
4512 |
scrollRect(r, dx, dy); |
|
4513 |
return; |
|
4514 |
} |
|
4515 |
||
4516 |
const bool valid_rect = r.isValid(); |
|
4517 |
if (!q->updatesEnabled() && (valid_rect || q->children().isEmpty())) |
|
4518 |
return; |
|
4519 |
||
4520 |
qt_event_request_window_change(q); |
|
4521 |
||
4522 |
#ifdef QT_MAC_USE_COCOA |
|
4523 |
QMacCocoaAutoReleasePool pool; |
|
4524 |
#endif |
|
4525 |
||
4526 |
if(!valid_rect) { // scroll children |
|
4527 |
QPoint pd(dx, dy); |
|
4528 |
QWidgetList moved; |
|
4529 |
QObjectList chldrn = q->children(); |
|
4530 |
for(int i = 0; i < chldrn.size(); i++) { //first move all children |
|
4531 |
QObject *obj = chldrn.at(i); |
|
4532 |
if(obj->isWidgetType()) { |
|
4533 |
QWidget *w = (QWidget*)obj; |
|
4534 |
if(!w->isWindow()) { |
|
4535 |
w->data->crect = QRect(w->pos() + pd, w->size()); |
|
4536 |
if (w->testAttribute(Qt::WA_WState_Created)) { |
|
4537 |
#ifndef QT_MAC_USE_COCOA |
|
4538 |
HIRect bounds = CGRectMake(w->data->crect.x(), w->data->crect.y(), |
|
4539 |
w->data->crect.width(), w->data->crect.height()); |
|
4540 |
HIViewRef hiview = qt_mac_nativeview_for(w); |
|
4541 |
const bool opaque = q->testAttribute(Qt::WA_OpaquePaintEvent); |
|
4542 |
||
4543 |
if (opaque) |
|
4544 |
HIViewSetDrawingEnabled(hiview, false); |
|
4545 |
HIViewSetFrame(hiview, &bounds); |
|
4546 |
if (opaque) |
|
4547 |
HIViewSetDrawingEnabled(hiview, true); |
|
4548 |
#else |
|
4549 |
[qt_mac_nativeview_for(w) |
|
4550 |
setFrame:NSMakeRect(w->data->crect.x(), w->data->crect.y(), |
|
4551 |
w->data->crect.width(), w->data->crect.height())]; |
|
4552 |
#endif |
|
4553 |
} |
|
4554 |
moved.append(w); |
|
4555 |
} |
|
4556 |
} |
|
4557 |
} |
|
4558 |
//now send move events (do not do this in the above loop, breaks QAquaFocusWidget) |
|
4559 |
for(int i = 0; i < moved.size(); i++) { |
|
4560 |
QWidget *w = moved.at(i); |
|
4561 |
QMoveEvent e(w->pos(), w->pos() - pd); |
|
4562 |
QApplication::sendEvent(w, &e); |
|
4563 |
} |
|
4564 |
} |
|
4565 |
||
4566 |
if (!q->testAttribute(Qt::WA_WState_Created) || !q->isVisible()) |
|
4567 |
return; |
|
4568 |
||
4569 |
OSViewRef view = qt_mac_nativeview_for(q); |
|
4570 |
#ifndef QT_MAC_USE_COCOA |
|
4571 |
HIRect scrollrect = CGRectMake(r.x(), r.y(), r.width(), r.height()); |
|
4572 |
OSStatus err = _HIViewScrollRectWithOptions(view, valid_rect ? &scrollrect : 0, dx, dy, kHIViewScrollRectAdjustInvalid); |
|
4573 |
if (err) { |
|
4574 |
// The only parameter that can go wrong, is the rect. |
|
4575 |
qWarning("QWidget::scroll: Your rectangle was too big for the widget, clipping rect"); |
|
4576 |
scrollrect = CGRectMake(qMax(r.x(), 0), qMax(r.y(), 0), |
|
4577 |
qMin(r.width(), q->width()), qMin(r.height(), q->height())); |
|
4578 |
_HIViewScrollRectWithOptions(view, valid_rect ? &scrollrect : 0, dx, dy, kHIViewScrollRectAdjustInvalid); |
|
4579 |
} |
|
4580 |
#else |
|
4581 |
NSRect scrollRect = valid_rect ? NSMakeRect(r.x(), r.y(), r.width(), r.height()) |
|
4582 |
: NSMakeRect(0, 0, q->width(), q->height()); |
|
4583 |
||
4584 |
||
4585 |
// calc the updateRect |
|
4586 |
NSRect deltaXRect = { {0, 0}, {0, 0} }; |
|
4587 |
NSRect deltaYRect = { {0, 0}, {0, 0} }; |
|
4588 |
if (dy != 0) { |
|
4589 |
deltaYRect.size.width = scrollRect.size.width; |
|
4590 |
if (dy > 0) { |
|
4591 |
deltaYRect.size.height = dy; |
|
4592 |
} else { |
|
4593 |
deltaYRect.size.height = -dy; |
|
4594 |
deltaYRect.origin.y = scrollRect.size.height + dy; |
|
4595 |
} |
|
4596 |
} |
|
4597 |
if (dx != 0) { |
|
4598 |
deltaXRect.size.height = scrollRect.size.height; |
|
4599 |
if (dx > 0) { |
|
4600 |
deltaXRect.size.width = dx; |
|
4601 |
} else { |
|
4602 |
deltaXRect.size.width = -dx; |
|
4603 |
deltaXRect.origin.x = scrollRect.size.width + dx; |
|
4604 |
} |
|
4605 |
} |
|
4606 |
||
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
4607 |
// ### Scroll the dirty regions as well, the following is not correct. |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
4608 |
QRegion displayRegion = r.isNull() ? dirtyOnWidget : (dirtyOnWidget & r); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
4609 |
const QVector<QRect> &rects = dirtyOnWidget.rects(); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
4610 |
const QVector<QRect>::const_iterator end = rects.end(); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
4611 |
QVector<QRect>::const_iterator it = rects.begin(); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
4612 |
while (it != end) { |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
4613 |
const QRect rect = *it; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
4614 |
const NSRect dirtyRect = NSMakeRect(rect.x() + dx, rect.y() + dy, |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
4615 |
rect.width(), rect.height()); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
4616 |
[view setNeedsDisplayInRect:dirtyRect]; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
4617 |
++it; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
4618 |
} |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
4619 |
|
0 | 4620 |
NSSize deltaSize = NSMakeSize(dx, dy); |
4621 |
[view scrollRect:scrollRect by:deltaSize]; |
|
4622 |
[view setNeedsDisplayInRect:deltaXRect]; |
|
4623 |
[view setNeedsDisplayInRect:deltaYRect]; |
|
4624 |
#endif // QT_MAC_USE_COCOA |
|
4625 |
} |
|
4626 |
||
4627 |
int QWidget::metric(PaintDeviceMetric m) const |
|
4628 |
{ |
|
4629 |
switch(m) { |
|
4630 |
case PdmHeightMM: |
|
4631 |
return qRound(metric(PdmHeight) * 25.4 / qreal(metric(PdmDpiY))); |
|
4632 |
case PdmWidthMM: |
|
4633 |
return qRound(metric(PdmWidth) * 25.4 / qreal(metric(PdmDpiX))); |
|
4634 |
case PdmHeight: |
|
4635 |
case PdmWidth: { |
|
4636 |
#ifndef QT_MAC_USE_COCOA |
|
4637 |
HIRect rect; |
|
4638 |
HIViewGetFrame(qt_mac_nativeview_for(this), &rect); |
|
4639 |
#else |
|
4640 |
NSRect rect = [qt_mac_nativeview_for(this) frame]; |
|
4641 |
#endif |
|
4642 |
if(m == PdmWidth) |
|
4643 |
return (int)rect.size.width; |
|
4644 |
return (int)rect.size.height; } |
|
4645 |
case PdmDepth: |
|
4646 |
return 32; |
|
4647 |
case PdmNumColors: |
|
4648 |
return INT_MAX; |
|
4649 |
case PdmDpiX: |
|
4650 |
case PdmPhysicalDpiX: { |
|
4651 |
Q_D(const QWidget); |
|
4652 |
if (d->extra && d->extra->customDpiX) |
|
4653 |
return d->extra->customDpiX; |
|
4654 |
else if (d->parent) |
|
4655 |
return static_cast<QWidget *>(d->parent)->metric(m); |
|
4656 |
extern float qt_mac_defaultDpi_x(); //qpaintdevice_mac.cpp |
|
4657 |
return int(qt_mac_defaultDpi_x()); } |
|
4658 |
case PdmDpiY: |
|
4659 |
case PdmPhysicalDpiY: { |
|
4660 |
Q_D(const QWidget); |
|
4661 |
if (d->extra && d->extra->customDpiY) |
|
4662 |
return d->extra->customDpiY; |
|
4663 |
else if (d->parent) |
|
4664 |
return static_cast<QWidget *>(d->parent)->metric(m); |
|
4665 |
extern float qt_mac_defaultDpi_y(); //qpaintdevice_mac.cpp |
|
4666 |
return int(qt_mac_defaultDpi_y()); } |
|
4667 |
default: //leave this so the compiler complains when new ones are added |
|
4668 |
qWarning("QWidget::metric: Unhandled parameter %d", m); |
|
4669 |
return QPaintDevice::metric(m); |
|
4670 |
} |
|
4671 |
return 0; |
|
4672 |
} |
|
4673 |
||
4674 |
void QWidgetPrivate::createSysExtra() |
|
4675 |
{ |
|
4676 |
#ifdef QT_MAC_USE_COCOA |
|
4677 |
extra->imageMask = 0; |
|
4678 |
#endif |
|
4679 |
} |
|
4680 |
||
4681 |
void QWidgetPrivate::deleteSysExtra() |
|
4682 |
{ |
|
4683 |
#ifdef QT_MAC_USE_COCOA |
|
4684 |
if (extra->imageMask) |
|
4685 |
CFRelease(extra->imageMask); |
|
4686 |
#endif |
|
4687 |
} |
|
4688 |
||
4689 |
void QWidgetPrivate::createTLSysExtra() |
|
4690 |
{ |
|
4691 |
extra->topextra->resizer = 0; |
|
4692 |
extra->topextra->isSetGeometry = 0; |
|
4693 |
extra->topextra->isMove = 0; |
|
4694 |
extra->topextra->wattr = 0; |
|
4695 |
extra->topextra->wclass = 0; |
|
4696 |
extra->topextra->group = 0; |
|
4697 |
extra->topextra->windowIcon = 0; |
|
4698 |
extra->topextra->savedWindowAttributesFromMaximized = 0; |
|
4699 |
} |
|
4700 |
||
4701 |
void QWidgetPrivate::deleteTLSysExtra() |
|
4702 |
{ |
|
4703 |
#ifndef QT_MAC_USE_COCOA |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4704 |
if (extra->topextra->group) { |
0 | 4705 |
qt_mac_release_window_group(extra->topextra->group); |
4706 |
extra->topextra->group = 0; |
|
4707 |
} |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4708 |
if (extra->topextra->windowIcon) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4709 |
ReleaseIconRef(extra->topextra->windowIcon); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4710 |
extra->topextra->windowIcon = 0; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
4711 |
} |
0 | 4712 |
#endif |
4713 |
} |
|
4714 |
||
4715 |
void QWidgetPrivate::updateFrameStrut() |
|
4716 |
{ |
|
4717 |
Q_Q(QWidget); |
|
4718 |
||
4719 |
QWidgetPrivate *that = const_cast<QWidgetPrivate*>(this); |
|
4720 |
||
4721 |
that->data.fstrut_dirty = false; |
|
4722 |
QTLWExtra *top = that->topData(); |
|
4723 |
||
4724 |
#if QT_MAC_USE_COCOA |
|
4725 |
// 1 Get the window frame |
|
4726 |
OSWindowRef oswnd = qt_mac_window_for(q); |
|
4727 |
NSRect frameW = [oswnd frame]; |
|
4728 |
// 2 Get the content frame - so now |
|
4729 |
NSRect frameC = [oswnd contentRectForFrameRect:frameW]; |
|
4730 |
top->frameStrut.setCoords(frameC.origin.x - frameW.origin.x, |
|
4731 |
(frameW.origin.y + frameW.size.height) - (frameC.origin.y + frameC.size.height), |
|
4732 |
(frameW.origin.x + frameW.size.width) - (frameC.origin.x + frameC.size.width), |
|
4733 |
frameC.origin.y - frameW.origin.y); |
|
4734 |
#else |
|
4735 |
Rect window_r; |
|
4736 |
GetWindowStructureWidths(qt_mac_window_for(q), &window_r); |
|
4737 |
top->frameStrut.setCoords(window_r.left, window_r.top, window_r.right, window_r.bottom); |
|
4738 |
#endif |
|
4739 |
} |
|
4740 |
||
4741 |
void QWidgetPrivate::registerDropSite(bool on) |
|
4742 |
{ |
|
4743 |
Q_Q(QWidget); |
|
4744 |
if (!q->testAttribute(Qt::WA_WState_Created)) |
|
4745 |
return; |
|
4746 |
#ifndef QT_MAC_USE_COCOA |
|
4747 |
SetControlDragTrackingEnabled(qt_mac_nativeview_for(q), on); |
|
4748 |
#else |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4749 |
NSWindow *win = qt_mac_window_for(q); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4750 |
if (on) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4751 |
if ([win isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaWindow) class]]) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4752 |
[static_cast<QT_MANGLE_NAMESPACE(QCocoaWindow) *>(win) registerDragTypes]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4753 |
else if ([win isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaPanel) class]]) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4754 |
[static_cast<QT_MANGLE_NAMESPACE(QCocoaPanel) *>(win) registerDragTypes]; |
0 | 4755 |
} |
4756 |
#endif |
|
4757 |
} |
|
4758 |
||
4759 |
void QWidgetPrivate::registerTouchWindow() |
|
4760 |
{ |
|
4761 |
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 |
|
4762 |
if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_6) |
|
4763 |
return; |
|
4764 |
Q_Q(QWidget); |
|
4765 |
if (!q->testAttribute(Qt::WA_WState_Created)) |
|
4766 |
return; |
|
4767 |
#ifndef QT_MAC_USE_COCOA |
|
4768 |
// Needs implementation! |
|
4769 |
#else |
|
4770 |
NSView *view = qt_mac_nativeview_for(q); |
|
4771 |
[view setAcceptsTouchEvents:YES]; |
|
4772 |
#endif |
|
4773 |
#endif |
|
4774 |
} |
|
4775 |
||
4776 |
void QWidgetPrivate::setMask_sys(const QRegion ®ion) |
|
4777 |
{ |
|
4778 |
Q_UNUSED(region); |
|
4779 |
#ifndef QT_MAC_USE_COCOA |
|
4780 |
Q_Q(QWidget); |
|
4781 |
if (q->isWindow()) |
|
4782 |
ReshapeCustomWindow(qt_mac_window_for(q)); |
|
4783 |
else |
|
4784 |
HIViewReshapeStructure(qt_mac_nativeview_for(q)); |
|
4785 |
#else |
|
4786 |
if (extra->mask.isEmpty()) { |
|
4787 |
extra->maskBits = QImage(); |
|
4788 |
finishCocoaMaskSetup(); |
|
4789 |
} else { |
|
4790 |
syncCocoaMask(); |
|
4791 |
} |
|
4792 |
||
4793 |
#endif |
|
4794 |
} |
|
4795 |
||
4796 |
void QWidgetPrivate::setWindowOpacity_sys(qreal level) |
|
4797 |
{ |
|
4798 |
Q_Q(QWidget); |
|
4799 |
||
4800 |
if (!q->isWindow()) |
|
4801 |
return; |
|
4802 |
||
4803 |
level = qBound(0.0, level, 1.0); |
|
4804 |
topData()->opacity = (uchar)(level * 255); |
|
4805 |
if (!q->testAttribute(Qt::WA_WState_Created)) |
|
4806 |
return; |
|
4807 |
||
4808 |
OSWindowRef oswindow = qt_mac_window_for(q); |
|
4809 |
#if QT_MAC_USE_COCOA |
|
4810 |
[oswindow setAlphaValue:level]; |
|
4811 |
#else |
|
4812 |
SetWindowAlpha(oswindow, level); |
|
4813 |
#endif |
|
4814 |
} |
|
4815 |
||
4816 |
#ifdef QT_MAC_USE_COCOA |
|
4817 |
void QWidgetPrivate::syncCocoaMask() |
|
4818 |
{ |
|
4819 |
Q_Q(QWidget); |
|
4820 |
if (!q->testAttribute(Qt::WA_WState_Created) || !extra) |
|
4821 |
return; |
|
4822 |
||
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
4823 |
if (extra->hasMask) { |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
4824 |
if(extra->maskBits.size() != q->size()) { |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
4825 |
extra->maskBits = QImage(q->size(), QImage::Format_Mono); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
4826 |
} |
0 | 4827 |
extra->maskBits.fill(QColor(Qt::color1).rgba()); |
4828 |
extra->maskBits.setNumColors(2); |
|
4829 |
extra->maskBits.setColor(0, QColor(Qt::color0).rgba()); |
|
4830 |
extra->maskBits.setColor(1, QColor(Qt::color1).rgba()); |
|
4831 |
QPainter painter(&extra->maskBits); |
|
4832 |
painter.setBrush(Qt::color1); |
|
4833 |
painter.setPen(Qt::NoPen); |
|
4834 |
painter.drawRects(extra->mask.rects()); |
|
4835 |
painter.end(); |
|
4836 |
finishCocoaMaskSetup(); |
|
4837 |
} |
|
4838 |
} |
|
4839 |
||
4840 |
void QWidgetPrivate::finishCocoaMaskSetup() |
|
4841 |
{ |
|
4842 |
Q_Q(QWidget); |
|
4843 |
||
4844 |
if (!q->testAttribute(Qt::WA_WState_Created) || !extra) |
|
4845 |
return; |
|
4846 |
||
4847 |
// Technically this is too late to release, because the data behind the image |
|
4848 |
// has already been released. But it's more tidy to do it here. |
|
4849 |
// If you are seeing a crash, consider doing a CFRelease before changing extra->maskBits. |
|
4850 |
if (extra->imageMask) { |
|
4851 |
CFRelease(extra->imageMask); |
|
4852 |
extra->imageMask = 0; |
|
4853 |
} |
|
4854 |
||
4855 |
if (!extra->maskBits.isNull()) { |
|
4856 |
QCFType<CGDataProviderRef> dataProvider = CGDataProviderCreateWithData(0, |
|
4857 |
extra->maskBits.bits(), |
|
4858 |
extra->maskBits.numBytes(), |
|
4859 |
0); // shouldn't need to release. |
|
4860 |
CGFloat decode[2] = {1, 0}; |
|
4861 |
extra->imageMask = CGImageMaskCreate(extra->maskBits.width(), extra->maskBits.height(), |
|
4862 |
1, 1, extra->maskBits.bytesPerLine(), dataProvider, |
|
4863 |
decode, false); |
|
4864 |
} |
|
4865 |
if (q->isWindow()) { |
|
4866 |
NSWindow *window = qt_mac_window_for(q); |
|
4867 |
[window setOpaque:(extra->imageMask == 0)]; |
|
4868 |
[window invalidateShadow]; |
|
4869 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4870 |
qt_mac_set_needs_display(q, QRegion()); |
0 | 4871 |
} |
4872 |
#endif |
|
4873 |
||
4874 |
struct QPaintEngineCleanupHandler |
|
4875 |
{ |
|
4876 |
inline QPaintEngineCleanupHandler() : engine(0) {} |
|
4877 |
inline ~QPaintEngineCleanupHandler() { delete engine; } |
|
4878 |
QPaintEngine *engine; |
|
4879 |
}; |
|
4880 |
||
4881 |
Q_GLOBAL_STATIC(QPaintEngineCleanupHandler, engineHandler) |
|
4882 |
||
4883 |
QPaintEngine *QWidget::paintEngine() const |
|
4884 |
{ |
|
4885 |
QPaintEngine *&pe = engineHandler()->engine; |
|
4886 |
if (!pe) |
|
4887 |
pe = new QCoreGraphicsPaintEngine(); |
|
4888 |
if (pe->isActive()) { |
|
4889 |
QPaintEngine *engine = new QCoreGraphicsPaintEngine(); |
|
4890 |
engine->setAutoDestruct(true); |
|
4891 |
return engine; |
|
4892 |
} |
|
4893 |
return pe; |
|
4894 |
} |
|
4895 |
||
4896 |
void QWidgetPrivate::setModal_sys() |
|
4897 |
{ |
|
4898 |
Q_Q(QWidget); |
|
4899 |
if (!q->testAttribute(Qt::WA_WState_Created) || !q->isWindow()) |
|
4900 |
return; |
|
4901 |
const QWidget * const windowParent = q->window()->parentWidget(); |
|
4902 |
const QWidget * const primaryWindow = windowParent ? windowParent->window() : 0; |
|
4903 |
OSWindowRef windowRef = qt_mac_window_for(q); |
|
4904 |
||
4905 |
#ifdef QT_MAC_USE_COCOA |
|
4906 |
QMacCocoaAutoReleasePool pool; |
|
4907 |
bool alreadySheet = [windowRef styleMask] & NSDocModalWindowMask; |
|
4908 |
||
4909 |
if (windowParent && q->windowModality() == Qt::WindowModal){ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4910 |
// INVARIANT: Window should be window-modal (which implies a sheet). |
0 | 4911 |
if (!alreadySheet) { |
4912 |
// NB: the following call will call setModal_sys recursivly: |
|
4913 |
recreateMacWindow(); |
|
4914 |
windowRef = qt_mac_window_for(q); |
|
4915 |
} |
|
4916 |
if ([windowRef isKindOfClass:[NSPanel class]]){ |
|
4917 |
// If the primary window of the sheet parent is a child of a modal dialog, |
|
4918 |
// the sheet parent should not be modally shaddowed. |
|
4919 |
// This goes for the sheet as well: |
|
4920 |
OSWindowRef ref = primaryWindow ? qt_mac_window_for(primaryWindow) : 0; |
|
4921 |
bool isDialog = ref ? [ref isKindOfClass:[NSPanel class]] : false; |
|
4922 |
bool worksWhenModal = isDialog ? [static_cast<NSPanel *>(ref) worksWhenModal] : false; |
|
4923 |
if (worksWhenModal) |
|
4924 |
[static_cast<NSPanel *>(windowRef) setWorksWhenModal:YES]; |
|
4925 |
} |
|
4926 |
} else { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4927 |
// INVARIANT: Window shold _not_ be window-modal (and as such, not a sheet). |
0 | 4928 |
if (alreadySheet){ |
4929 |
// NB: the following call will call setModal_sys recursivly: |
|
4930 |
recreateMacWindow(); |
|
4931 |
windowRef = qt_mac_window_for(q); |
|
4932 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4933 |
if (q->windowModality() == Qt::NonModal |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4934 |
&& primaryWindow && primaryWindow->windowModality() == Qt::ApplicationModal) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4935 |
// INVARIANT: Our window has a parent that is application modal. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4936 |
// This means that q is supposed to be on top of this window and |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
4937 |
// not be modally shaddowed: |
0 | 4938 |
if ([windowRef isKindOfClass:[NSPanel class]]) |
4939 |
[static_cast<NSPanel *>(windowRef) setWorksWhenModal:YES]; |
|
4940 |
} |
|
4941 |
} |
|
4942 |
||
4943 |
#else |
|
4944 |
const bool primaryWindowModal = primaryWindow ? primaryWindow->testAttribute(Qt::WA_ShowModal) : false; |
|
4945 |
const bool modal = q->testAttribute(Qt::WA_ShowModal); |
|
4946 |
||
4947 |
WindowClass old_wclass; |
|
4948 |
GetWindowClass(windowRef, &old_wclass); |
|
4949 |
||
4950 |
if (modal || primaryWindowModal) { |
|
4951 |
if (q->windowModality() == Qt::WindowModal |
|
4952 |
|| (primaryWindow && primaryWindow->windowModality() == Qt::WindowModal)){ |
|
4953 |
// Window should be window-modal (which implies a sheet). |
|
4954 |
if (old_wclass != kSheetWindowClass){ |
|
4955 |
// We cannot convert a created window to a sheet. |
|
4956 |
// So we recreate the window: |
|
4957 |
recreateMacWindow(); |
|
4958 |
return; |
|
4959 |
} |
|
4960 |
} else { |
|
4961 |
// Window should be application-modal (which implies NOT using a sheet). |
|
4962 |
if (old_wclass == kSheetWindowClass){ |
|
4963 |
// We cannot convert a sheet to a window. |
|
4964 |
// So we recreate the window: |
|
4965 |
recreateMacWindow(); |
|
4966 |
return; |
|
4967 |
} else if (!(q->data->window_flags & Qt::CustomizeWindowHint)) { |
|
4968 |
if (old_wclass == kDocumentWindowClass || old_wclass == kFloatingWindowClass || old_wclass == kUtilityWindowClass){ |
|
4969 |
// Only change the class to kMovableModalWindowClass if the no explicit jewels |
|
4970 |
// are set (kMovableModalWindowClass can't contain them), and the current window class |
|
4971 |
// can be converted to modal (according to carbon doc). Mind the order of |
|
4972 |
// HIWindowChangeClass and ChangeWindowAttributes. |
|
4973 |
WindowGroupRef group = GetWindowGroup(windowRef); |
|
4974 |
HIWindowChangeClass(windowRef, kMovableModalWindowClass); |
|
4975 |
quint32 tmpWattr = kWindowCloseBoxAttribute | kWindowHorizontalZoomAttribute; |
|
4976 |
ChangeWindowAttributes(windowRef, tmpWattr, kWindowNoAttributes); |
|
4977 |
ChangeWindowAttributes(windowRef, kWindowNoAttributes, tmpWattr); |
|
4978 |
// If the window belongs to a qt-created group, set that group once more: |
|
4979 |
if (data.window_flags & Qt::WindowStaysOnTopHint |
|
4980 |
|| q->windowType() == Qt::Popup |
|
4981 |
|| q->windowType() == Qt::ToolTip) |
|
4982 |
SetWindowGroup(windowRef, group); |
|
4983 |
} |
|
4984 |
// Popups are usually handled "special" and are never modal. |
|
4985 |
Qt::WindowType winType = q->windowType(); |
|
4986 |
if (winType != Qt::Popup && winType != Qt::ToolTip) |
|
4987 |
SetWindowModality(windowRef, kWindowModalityAppModal, 0); |
|
4988 |
} |
|
4989 |
} |
|
4990 |
} else if (windowRef) { |
|
4991 |
if (old_wclass == kSheetWindowClass){ |
|
4992 |
// Converting a sheet to a window is complex. It's easier to recreate: |
|
4993 |
recreateMacWindow(); |
|
4994 |
return; |
|
4995 |
} |
|
4996 |
||
4997 |
SetWindowModality(windowRef, kWindowModalityNone, 0); |
|
4998 |
if (!(q->data->window_flags & Qt::CustomizeWindowHint)) { |
|
4999 |
if (q->window()->d_func()->topData()->wattr |= kWindowCloseBoxAttribute) |
|
5000 |
ChangeWindowAttributes(windowRef, kWindowCloseBoxAttribute, kWindowNoAttributes); |
|
5001 |
if (q->window()->d_func()->topData()->wattr |= kWindowHorizontalZoomAttribute) |
|
5002 |
ChangeWindowAttributes(windowRef, kWindowHorizontalZoomAttribute, kWindowNoAttributes); |
|
5003 |
if (q->window()->d_func()->topData()->wattr |= kWindowCollapseBoxAttribute) |
|
5004 |
ChangeWindowAttributes(windowRef, kWindowCollapseBoxAttribute, kWindowNoAttributes); |
|
5005 |
} |
|
5006 |
||
5007 |
WindowClass newClass = q->window()->d_func()->topData()->wclass; |
|
5008 |
if (old_wclass != newClass && newClass != 0){ |
|
5009 |
WindowGroupRef group = GetWindowGroup(windowRef); |
|
5010 |
HIWindowChangeClass(windowRef, newClass); |
|
5011 |
// If the window belongs to a qt-created group, set that group once more: |
|
5012 |
if (data.window_flags & Qt::WindowStaysOnTopHint |
|
5013 |
|| q->windowType() == Qt::Popup |
|
5014 |
|| q->windowType() == Qt::ToolTip) |
|
5015 |
SetWindowGroup(windowRef, group); |
|
5016 |
} |
|
5017 |
} |
|
5018 |
||
5019 |
// Make sure that HIWindowChangeClass didn't remove drag support |
|
5020 |
// or reset the opaque size grip setting: |
|
5021 |
SetAutomaticControlDragTrackingEnabledForWindow(windowRef, true); |
|
5022 |
macUpdateOpaqueSizeGrip(); |
|
5023 |
#endif |
|
5024 |
} |
|
5025 |
||
5026 |
void QWidgetPrivate::macUpdateHideOnSuspend() |
|
5027 |
{ |
|
5028 |
Q_Q(QWidget); |
|
5029 |
if (!q->testAttribute(Qt::WA_WState_Created) || !q->isWindow() || q->windowType() != Qt::Tool) |
|
5030 |
return; |
|
5031 |
#ifndef QT_MAC_USE_COCOA |
|
5032 |
if(q->testAttribute(Qt::WA_MacAlwaysShowToolWindow)) |
|
5033 |
ChangeWindowAttributes(qt_mac_window_for(q), 0, kWindowHideOnSuspendAttribute); |
|
5034 |
else |
|
5035 |
ChangeWindowAttributes(qt_mac_window_for(q), kWindowHideOnSuspendAttribute, 0); |
|
5036 |
#else |
|
5037 |
if(q->testAttribute(Qt::WA_MacAlwaysShowToolWindow)) |
|
5038 |
[qt_mac_window_for(q) setHidesOnDeactivate:NO]; |
|
5039 |
else |
|
5040 |
[qt_mac_window_for(q) setHidesOnDeactivate:YES]; |
|
5041 |
#endif |
|
5042 |
} |
|
5043 |
||
5044 |
void QWidgetPrivate::macUpdateOpaqueSizeGrip() |
|
5045 |
{ |
|
5046 |
Q_Q(QWidget); |
|
5047 |
||
5048 |
if (!q->testAttribute(Qt::WA_WState_Created) || !q->isWindow()) |
|
5049 |
return; |
|
5050 |
||
5051 |
#ifndef QT_MAC_USE_COCOA // Growbox is always transparent on Cocoa. Can emulate with setting a QSizeGrip |
|
5052 |
HIViewRef growBox; |
|
5053 |
HIViewFindByID(HIViewGetRoot(qt_mac_window_for(q)), kHIViewWindowGrowBoxID, &growBox); |
|
5054 |
if (!growBox) |
|
5055 |
return; |
|
5056 |
HIGrowBoxViewSetTransparent(growBox, !q->testAttribute(Qt::WA_MacOpaqueSizeGrip)); |
|
5057 |
#endif |
|
5058 |
} |
|
5059 |
||
5060 |
void QWidgetPrivate::macUpdateSizeAttribute() |
|
5061 |
{ |
|
5062 |
Q_Q(QWidget); |
|
5063 |
QEvent event(QEvent::MacSizeChange); |
|
5064 |
QApplication::sendEvent(q, &event); |
|
5065 |
for (int i = 0; i < children.size(); ++i) { |
|
5066 |
QWidget *w = qobject_cast<QWidget *>(children.at(i)); |
|
5067 |
if (w && (!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation)) |
|
5068 |
&& !q->testAttribute(Qt::WA_MacMiniSize) // no attribute set? inherit from parent |
|
5069 |
&& !w->testAttribute(Qt::WA_MacSmallSize) |
|
5070 |
&& !w->testAttribute(Qt::WA_MacNormalSize)) |
|
5071 |
w->d_func()->macUpdateSizeAttribute(); |
|
5072 |
} |
|
5073 |
resolveFont(); |
|
5074 |
} |
|
5075 |
||
5076 |
void QWidgetPrivate::macUpdateIgnoreMouseEvents() |
|
5077 |
{ |
|
5078 |
#ifndef QT_MAC_USE_COCOA // This is handled inside the mouse handler on Cocoa. |
|
5079 |
Q_Q(QWidget); |
|
5080 |
if (!q->testAttribute(Qt::WA_WState_Created)) |
|
5081 |
return; |
|
5082 |
||
5083 |
if(q->isWindow()) |
|
5084 |
{ |
|
5085 |
if(q->testAttribute(Qt::WA_TransparentForMouseEvents)) |
|
5086 |
ChangeWindowAttributes(qt_mac_window_for(q), kWindowIgnoreClicksAttribute, 0); |
|
5087 |
else |
|
5088 |
ChangeWindowAttributes(qt_mac_window_for(q), 0, kWindowIgnoreClicksAttribute); |
|
5089 |
ReshapeCustomWindow(qt_mac_window_for(q)); |
|
5090 |
} else { |
|
5091 |
#ifndef kHIViewFeatureIgnoresClicks |
|
5092 |
#define kHIViewFeatureIgnoresClicks kHIViewIgnoresClicks |
|
5093 |
#endif |
|
5094 |
if(q->testAttribute(Qt::WA_TransparentForMouseEvents)) |
|
5095 |
HIViewChangeFeatures(qt_mac_nativeview_for(q), kHIViewFeatureIgnoresClicks, 0); |
|
5096 |
else |
|
5097 |
HIViewChangeFeatures(qt_mac_nativeview_for(q), 0, kHIViewFeatureIgnoresClicks); |
|
5098 |
HIViewReshapeStructure(qt_mac_nativeview_for(q)); |
|
5099 |
} |
|
5100 |
#endif |
|
5101 |
} |
|
5102 |
||
5103 |
void QWidgetPrivate::macUpdateMetalAttribute() |
|
5104 |
{ |
|
5105 |
Q_Q(QWidget); |
|
5106 |
bool realWindow = isRealWindow(); |
|
5107 |
if (!q->testAttribute(Qt::WA_WState_Created) || !realWindow) |
|
5108 |
return; |
|
5109 |
||
5110 |
if (realWindow) { |
|
5111 |
#if QT_MAC_USE_COCOA |
|
5112 |
// Cocoa doesn't let us change the style mask once it's been changed |
|
5113 |
// So, that means we need to recreate the window. |
|
5114 |
OSWindowRef cocoaWindow = qt_mac_window_for(q); |
|
5115 |
if ([cocoaWindow styleMask] & NSTexturedBackgroundWindowMask) |
|
5116 |
return; |
|
5117 |
recreateMacWindow(); |
|
5118 |
#else |
|
5119 |
QMainWindowLayout *layout = qobject_cast<QMainWindowLayout *>(q->layout()); |
|
5120 |
if (q->testAttribute(Qt::WA_MacBrushedMetal)) { |
|
5121 |
if (layout) |
|
5122 |
layout->updateHIToolBarStatus(); |
|
5123 |
ChangeWindowAttributes(qt_mac_window_for(q), kWindowMetalAttribute, 0); |
|
5124 |
ChangeWindowAttributes(qt_mac_window_for(q), kWindowMetalNoContentSeparatorAttribute, 0); |
|
5125 |
} else { |
|
5126 |
ChangeWindowAttributes(qt_mac_window_for(q), 0, kWindowMetalNoContentSeparatorAttribute); |
|
5127 |
ChangeWindowAttributes(qt_mac_window_for(q), 0, kWindowMetalAttribute); |
|
5128 |
if (layout) |
|
5129 |
layout->updateHIToolBarStatus(); |
|
5130 |
} |
|
5131 |
#endif |
|
5132 |
} |
|
5133 |
} |
|
5134 |
||
5135 |
void QWidgetPrivate::setEnabled_helper_sys(bool enable) |
|
5136 |
{ |
|
5137 |
#ifdef QT_MAC_USE_COCOA |
|
5138 |
Q_Q(QWidget); |
|
5139 |
NSView *view = qt_mac_nativeview_for(q); |
|
5140 |
if ([view isKindOfClass:[NSControl class]]) |
|
5141 |
[static_cast<NSControl *>(view) setEnabled:enable]; |
|
5142 |
#else |
|
5143 |
Q_UNUSED(enable); |
|
5144 |
#endif |
|
5145 |
} |
|
5146 |
||
5147 |
QT_END_NAMESPACE |