Changeset 846 for trunk/src/gui/kernel/qwidget_mac.mm
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/kernel/qwidget_mac.mm
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 115 115 QT_BEGIN_NAMESPACE 116 116 117 // qmainwindow.cpp 118 extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *window); 119 117 120 #define XCOORD_MAX 16383 118 121 #define WRECT_MAX 8191 … … 461 464 bool qt_isGenuineQWidget(const QWidget *window) 462 465 { 463 return window && qt_isGenuineQWidget(OSViewRef(window->winId())); 466 if (!window) 467 return false; 468 469 if (!window->internalWinId()) 470 return true; //alien 471 472 return qt_isGenuineQWidget(OSViewRef(window->internalWinId())); 464 473 } 465 474 … … 747 756 } 748 757 758 #ifndef QT_NO_GESTURES 749 759 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6 750 760 /* We build the release package against the 10.4 SDK. … … 763 773 }; 764 774 #endif 775 #endif // QT_NO_GESTURES 765 776 766 777 // window events … … 1071 1082 break; } 1072 1083 1084 #ifndef QT_NO_GESTURES 1073 1085 case kEventClassGesture: { 1074 1086 // First, find the widget that was under … … 1137 1149 QApplication::sendSpontaneousEvent(widget, &qNGEvent); 1138 1150 break; } 1151 #endif // QT_NO_GESTURES 1139 1152 1140 1153 default: … … 1590 1603 QWidget *widget = static_cast<QWidget*>(object); 1591 1604 if(qt_mac_is_macdrawer(widget)) { 1605 bool oldState = widget->testAttribute(Qt::WA_WState_ExplicitShowHide); 1592 1606 if(visible) { 1593 1607 if (!widget->testAttribute(Qt::WA_WState_ExplicitShowHide)) … … 1595 1609 } else { 1596 1610 widget->hide(); 1597 widget->setAttribute(Qt::WA_WState_ExplicitShowHide, false); 1611 if(!oldState) 1612 widget->setAttribute(Qt::WA_WState_ExplicitShowHide, false); 1598 1613 } 1599 1614 } … … 1913 1928 else if(popup || (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5 && type == Qt::SplashScreen)) 1914 1929 wclass = kModalWindowClass; 1915 else if( q->testAttribute(Qt::WA_ShowModal) ||type == Qt::Dialog)1930 else if(type == Qt::Dialog) 1916 1931 wclass = kMovableModalWindowClass; 1917 1932 else if(type == Qt::ToolTip) … … 1920 1935 && type == Qt::SplashScreen)) 1921 1936 wclass = kFloatingWindowClass; 1937 else if(q->testAttribute(Qt::WA_ShowModal)) 1938 wclass = kMovableModalWindowClass; 1922 1939 else 1923 1940 wclass = kDocumentWindowClass; … … 2023 2040 if((tmp_wattr & known_attribs[i].tag) == known_attribs[i].tag) { 2024 2041 tmp_wattr ^= known_attribs[i].tag; 2025 qDebug("Qt: internal: * %s %s", known_attribs[i].name,2026 (GetAvailableWindowAttributes(wclass) & known_attribs[i].tag) ? "" : "(*)");2027 2042 } 2028 2043 } … … 2219 2234 } 2220 2235 #else // QT_MAC_USE_COCOA 2236 2237 void QWidgetPrivate::setWindowLevel() 2238 { 2239 Q_Q(QWidget); 2240 const QWidget * const windowParent = q->window()->parentWidget(); 2241 const QWidget * const primaryWindow = windowParent ? windowParent->window() : 0; 2242 NSInteger winLevel = -1; 2243 2244 if (q->windowType() == Qt::Popup) { 2245 winLevel = NSPopUpMenuWindowLevel; 2246 // Popup should be in at least the same level as its parent. 2247 if (primaryWindow) { 2248 OSWindowRef parentRef = qt_mac_window_for(primaryWindow); 2249 winLevel = qMax([parentRef level], winLevel); 2250 } 2251 } else if (q->windowType() == Qt::Tool) { 2252 winLevel = NSFloatingWindowLevel; 2253 } else if (q->windowType() == Qt::Dialog) { 2254 // Correct modality level (NSModalPanelWindowLevel) will be 2255 // set by cocoa when creating a modal session later. 2256 winLevel = NSNormalWindowLevel; 2257 } 2258 2259 // StayOnTop window should appear above Tool windows. 2260 if (data.window_flags & Qt::WindowStaysOnTopHint) 2261 winLevel = NSPopUpMenuWindowLevel; 2262 // Tooltips should appear above StayOnTop windows. 2263 if (q->windowType() == Qt::ToolTip) 2264 winLevel = NSScreenSaverWindowLevel; 2265 // All other types are Normal level. 2266 if (winLevel == -1) 2267 winLevel = NSNormalWindowLevel; 2268 [qt_mac_window_for(q) setLevel:winLevel]; 2269 } 2270 2221 2271 void QWidgetPrivate::finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ voidWindowRef) 2222 2272 { … … 2260 2310 registerDropSite(true); 2261 2311 transferChildren(); 2312 2313 // Tell Cocoa explicit that we wan't the view to receive key events 2314 // (regardless of focus policy) because this is how it works on other 2315 // platforms (and in the carbon port): 2316 if (!qApp->focusWidget()) 2317 [windowRef makeFirstResponder:nsview]; 2262 2318 } 2263 2319 … … 2291 2347 } 2292 2348 2349 if (qApp->overrideCursor()) 2350 [windowRef disableCursorRects]; 2351 2352 setWindowLevel(); 2293 2353 macUpdateHideOnSuspend(); 2294 2354 macUpdateOpaqueSizeGrip(); … … 2319 2379 determineWindowClass(); 2320 2380 createWindow_sys(); 2321 if (QMainWindowLayout *mwl = qobject_cast<QMainWindowLayout *>(q->layout())) { 2381 2382 if (QMainWindowLayout *mwl = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q))) { 2322 2383 mwl->updateHIToolBarStatus(); 2323 2384 } … … 2565 2626 } else { 2566 2627 data.fstrut_dirty = false; // non-toplevel widgets don't have a frame, so no need to update the strut 2567 if(OSViewRef osview = qt_mac_create_widget(q, this, qt_mac_nativeview_for(parentWidget))) { 2628 2629 #ifdef QT_MAC_USE_COCOA 2630 if (q->testAttribute(Qt::WA_NativeWindow) == false || 2631 q->internalWinId() != 0) { 2632 #ifdef ALIEN_DEBUG 2633 qDebug() << "Skipping native widget creation for" << this; 2634 #endif 2635 } else 2636 #endif 2637 if (OSViewRef osview = qt_mac_create_widget(q, this, qt_mac_nativeview_for(parentWidget))) { 2568 2638 #ifndef QT_MAC_USE_COCOA 2569 2639 HIRect bounds = CGRectMake(data.crect.x(), data.crect.y(), data.crect.width(), data.crect.height()); … … 2625 2695 { 2626 2696 Q_D(QWidget); 2697 d->aboutToDestroy(); 2627 2698 if (!isWindow() && parentWidget()) 2628 2699 parentWidget()->d_func()->invalidateBuffer(d->effectiveRectFor(geometry())); … … 2721 2792 } 2722 2793 2794 #ifdef QT_MAC_USE_COCOA 2795 void QWidgetPrivate::setSubWindowStacking(bool set) 2796 { 2797 // This will set/remove a visual relationship between parent and child on screen. 2798 // The reason for doing this is to ensure that a child always stacks infront of 2799 // its parent. Unfortunatly is turns out that [NSWindow addChildWindow] has 2800 // several unwanted side-effects, one of them being the moving of a child when 2801 // moving the parent, which we choose to accept. A way tougher side-effect is 2802 // that Cocoa will hide the parent if you hide the child. And in the case of 2803 // a tool window, since it will normally hide when you deactivate the 2804 // application, Cocoa will hide the parent upon deactivate as well. The result often 2805 // being no more visible windows on screen. So, to make a long story short, we only 2806 // allow parent-child relationships between windows that both are either a plain window 2807 // or a dialog. 2808 2809 Q_Q(QWidget); 2810 if (!q->isWindow()) 2811 return; 2812 NSWindow *qwin = [qt_mac_nativeview_for(q) window]; 2813 if (!qwin) 2814 return; 2815 Qt::WindowType qtype = q->windowType(); 2816 if (set && !(qtype == Qt::Window || qtype == Qt::Dialog)) 2817 return; 2818 if (set && ![qwin isVisible]) 2819 return; 2820 2821 if (QWidget *parent = q->parentWidget()) { 2822 if (NSWindow *pwin = [qt_mac_nativeview_for(parent) window]) { 2823 if (set) { 2824 Qt::WindowType ptype = parent->window()->windowType(); 2825 if ([pwin isVisible] && (ptype == Qt::Window || ptype == Qt::Dialog) && ![qwin parentWindow]) { 2826 NSInteger level = [qwin level]; 2827 [pwin addChildWindow:qwin ordered:NSWindowAbove]; 2828 if ([qwin level] < level) 2829 [qwin setLevel:level]; 2830 } 2831 } else { 2832 [pwin removeChildWindow:qwin]; 2833 } 2834 } 2835 } 2836 2837 QObjectList widgets = q->children(); 2838 for (int i=0; i<widgets.size(); ++i) { 2839 QWidget *child = qobject_cast<QWidget *>(widgets.at(i)); 2840 if (child && child->isWindow()) { 2841 if (NSWindow *cwin = [qt_mac_nativeview_for(child) window]) { 2842 if (set) { 2843 Qt::WindowType ctype = child->window()->windowType(); 2844 if ([cwin isVisible] && (ctype == Qt::Window || ctype == Qt::Dialog) && ![cwin parentWindow]) { 2845 NSInteger level = [cwin level]; 2846 [qwin addChildWindow:cwin ordered:NSWindowAbove]; 2847 if ([cwin level] < level) 2848 [cwin setLevel:level]; 2849 } 2850 } else { 2851 [qwin removeChildWindow:qt_mac_window_for(child)]; 2852 } 2853 } 2854 } 2855 } 2856 } 2857 #endif 2858 2723 2859 void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f) 2724 2860 { … … 2768 2904 if (wasWindow) { 2769 2905 oldToolbar = [oldWindow toolbar]; 2770 [oldToolbar retain]; 2771 oldToolbarVisible = [oldToolbar isVisible]; 2772 [oldWindow setToolbar:nil]; 2906 if (oldToolbar) { 2907 [oldToolbar retain]; 2908 oldToolbarVisible = [oldToolbar isVisible]; 2909 [oldWindow setToolbar:nil]; 2910 } 2773 2911 } 2774 2912 #endif … … 2781 2919 //recreate and setup flags 2782 2920 QObjectPrivate::setParent_helper(parent); 2783 QPoint pt = q->pos();2784 2921 bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide); 2785 2922 if (wasCreated && !qt_isGenuineQWidget(q)) 2786 2923 return; 2787 2924 2788 if ( (data.window_flags & Qt::Sheet) && topData && topData->opacity == 242)2925 if (!q->testAttribute(Qt::WA_WState_WindowOpacitySet)) { 2789 2926 q->setWindowOpacity(1.0f); 2927 q->setAttribute(Qt::WA_WState_WindowOpacitySet, false); 2928 } 2790 2929 2791 2930 setWinId(0); //do after the above because they may want the id … … 2796 2935 q->setAttribute(Qt::WA_WState_Hidden, false); 2797 2936 adjustFlags(data.window_flags, q); 2798 // keep compatibility with previous versions, we need to preserve the created state 2799 // (but we recreate the winId for the widget being reparented, again for compatibility) 2800 if (wasCreated || (!q->isWindow() && parent->testAttribute(Qt::WA_WState_Created))) { 2937 // keep compatibility with previous versions, we need to preserve the created state. 2938 // (but we recreate the winId for the widget being reparented, again for compatibility, 2939 // unless this is an alien widget. ) 2940 const bool nonWindowWithCreatedParent = !q->isWindow() && parent->testAttribute(Qt::WA_WState_Created); 2941 const bool nativeWidget = q->internalWinId() != 0; 2942 if (wasCreated || nativeWidget && nonWindowWithCreatedParent) { 2801 2943 createWinId(); 2802 2944 if (q->isWindow()) { … … 2805 2947 // (only for performance, it gets called a lot anyway). 2806 2948 if (!wasCreated) { 2807 if (QMainWindowLayout *mwl = q object_cast<QMainWindowLayout *>(q->layout())) {2949 if (QMainWindowLayout *mwl = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q))) { 2808 2950 mwl->updateHIToolBarStatus(); 2809 2951 } … … 2830 2972 // So redo the status one more time. It apparently is not an issue with Cocoa. 2831 2973 if (q->isWindow()) { 2832 if (QMainWindowLayout *mwl = q object_cast<QMainWindowLayout *>(q->layout())) {2974 if (QMainWindowLayout *mwl = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q))) { 2833 2975 mwl->updateHIToolBarStatus(); 2834 2976 } … … 2875 3017 } 2876 3018 } 2877 2878 3019 invalidateBuffer(q->rect()); 2879 3020 qt_event_request_window_change(q); … … 2883 3024 { 2884 3025 Q_D(const QWidget); 2885 if (!testAttribute(Qt::WA_WState_Created) ) {3026 if (!testAttribute(Qt::WA_WState_Created) || !internalWinId()) { 2886 3027 QPoint p = pos + data->crect.topLeft(); 2887 3028 return isWindow() ? p : parentWidget()->mapToGlobal(p); … … 2910 3051 { 2911 3052 Q_D(const QWidget); 2912 if (!testAttribute(Qt::WA_WState_Created) ) {3053 if (!testAttribute(Qt::WA_WState_Created) || !internalWinId()) { 2913 3054 QPoint p = isWindow() ? pos : parentWidget()->mapFromGlobal(pos); 2914 3055 return p - data->crect.topLeft(); … … 3181 3322 #ifndef QT_MAC_USE_COCOA 3182 3323 ActivateWindow(win, true); 3324 qApp->setActiveWindow(tlw); 3183 3325 #else 3184 3326 [win makeKeyWindow]; 3185 3327 #endif 3186 qApp->setActiveWindow(tlw);3187 3328 } else if(!isMinimized()) { 3188 3329 #ifndef QT_MAC_USE_COCOA … … 3209 3350 HIViewSetNeedsDisplay(qt_mac_nativeview_for(q), true); 3210 3351 #else 3211 [qt_mac_nativeview_for(q) setNeedsDisplay:YES];3352 qt_mac_set_needs_display(q, QRegion()); 3212 3353 #endif 3213 3354 return; … … 3247 3388 } 3248 3389 #else 3249 // Cocoa doesn't do regions, it seems more efficient to just update the bounding rect instead of a potential number of message passes for each rect. 3250 const QRect &boundingRect = rgn.boundingRect(); 3251 [qt_mac_nativeview_for(q) setNeedsDisplayInRect:NSMakeRect(boundingRect.x(), 3252 boundingRect.y(), boundingRect.width(), 3253 boundingRect.height())]; 3390 // Alien support: get the first native ancestor widget (will be q itself in the non-alien case), 3391 // map the coordinates from q space to NSView space and invalidate the rect. 3392 QWidget *nativeParent = q->internalWinId() ? q : q->nativeParentWidget(); 3393 if (nativeParent == 0) 3394 return; 3395 3396 QVector<QRect> rects = rgn.rects(); 3397 for (int i = 0; i < rects.count(); ++i) { 3398 const QRect &rect = rects.at(i); 3399 3400 const QRect nativeBoundingRect = QRect( 3401 QPoint(q->mapTo(nativeParent, rect.topLeft())), 3402 QSize(rect.size())); 3403 3404 [qt_mac_nativeview_for(nativeParent) setNeedsDisplayInRect:NSMakeRect(nativeBoundingRect.x(), 3405 nativeBoundingRect.y(), nativeBoundingRect.width(), 3406 nativeBoundingRect.height())]; 3407 } 3254 3408 #endif 3255 3409 } … … 3275 3429 3276 3430 bool realWindow = isRealWindow(); 3431 #ifndef QT_MAC_USE_COCOA 3277 3432 if (realWindow && !q->testAttribute(Qt::WA_Moved)) { 3433 if (qt_mac_is_macsheet(q)) 3434 recreateMacWindow(); 3278 3435 q->createWinId(); 3279 3436 if (QWidget *p = q->parentWidget()) { 3280 3437 p->createWinId(); 3281 #ifndef QT_MAC_USE_COCOA3282 3438 RepositionWindow(qt_mac_window_for(q), qt_mac_window_for(p), kWindowCenterOnParentWindow); 3283 #else3284 CGRect parentFrame = NSRectToCGRect([qt_mac_window_for(p) frame]);3285 OSWindowRef windowRef = qt_mac_window_for(q);3286 NSRect windowFrame = [windowRef frame];3287 NSPoint parentCenter = NSMakePoint(CGRectGetMidX(parentFrame), CGRectGetMidY(parentFrame));3288 [windowRef setFrameTopLeftPoint:NSMakePoint(parentCenter.x - (windowFrame.size.width / 2),3289 (parentCenter.y + (windowFrame.size.height / 2)))];3290 #endif3291 3439 } else { 3292 #ifndef QT_MAC_USE_COCOA3293 3440 RepositionWindow(qt_mac_window_for(q), 0, kWindowCenterOnMainScreen); 3294 #else 3295 // Ideally we would do a "center" here, but NSWindow's center is more equivalent to 3296 // kWindowAlertPositionOnMainScreen instead of kWindowCenterOnMainScreen. 3297 QRect availGeo = QApplication::desktop()->availableGeometry(q); 3298 // Center the content only. 3299 data.crect.moveCenter(availGeo.center()); 3300 QRect fStrut = frameStrut(); 3301 QRect frameRect(data.crect.x() - fStrut.left(), data.crect.y() - fStrut.top(), 3302 fStrut.left() + fStrut.right() + data.crect.width(), 3303 fStrut.top() + fStrut.bottom() + data.crect.height()); 3304 NSRect cocoaFrameRect = NSMakeRect(frameRect.x(), flipYCoordinate(frameRect.bottom() + 1), frameRect.width(), frameRect.height()); 3305 [qt_mac_window_for(q) setFrame:cocoaFrameRect display:NO]; 3306 #endif 3307 } 3308 } 3441 } 3442 } 3443 #endif 3444 3309 3445 data.fstrut_dirty = true; 3310 3446 if (realWindow) { … … 3337 3473 // sync the opacity value back (in case of a fade). 3338 3474 [window setAlphaValue:q->windowOpacity()]; 3339 [window makeKeyAndOrderFront:window]; 3340 3341 // If this window is app modal, we need to start spinning 3342 // a modal session for it. Interrupting 3343 // the event dispatcher will make this happend: 3344 if (data.window_modality == Qt::ApplicationModal) 3345 QEventDispatcherMac::instance()->interrupt(); 3475 3476 QWidget *top = 0; 3477 if (QApplicationPrivate::tryModalHelper(q, &top)) { 3478 [window makeKeyAndOrderFront:window]; 3479 // If this window is app modal, we need to start spinning 3480 // a modal session for it. Interrupting 3481 // the event dispatcher will make this happend: 3482 if (data.window_modality == Qt::ApplicationModal) 3483 QEventDispatcherMac::instance()->interrupt(); 3484 } else { 3485 // The window is modally shaddowed, so we need to make 3486 // sure that we don't pop in front of the modal window: 3487 [window orderFront:window]; 3488 if (!top->testAttribute(Qt::WA_DontShowOnScreen)) { 3489 if (NSWindow *modalWin = qt_mac_window_for(top)) 3490 [modalWin orderFront:window]; 3491 } 3492 } 3493 setSubWindowStacking(true); 3346 3494 #endif 3347 3495 if (q->windowType() == Qt::Popup) { … … 3362 3510 #ifndef QT_MAC_USE_COCOA 3363 3511 qt_event_request_activate(q); 3364 #else3365 [qt_mac_window_for(q) makeKeyWindow];3366 3512 #endif 3367 3513 } … … 3405 3551 QMacCocoaAutoReleasePool pool; 3406 3552 if(q->isWindow()) { 3553 #ifdef QT_MAC_USE_COCOA 3554 setSubWindowStacking(false); 3555 #endif 3407 3556 OSWindowRef window = qt_mac_window_for(q); 3408 3557 if(qt_mac_is_macsheet(q)) { … … 3470 3619 #endif 3471 3620 } 3472 if(q->isActiveWindow() && !(q->windowType() == Qt::Popup)) { 3621 #ifndef QT_MAC_USE_COCOA 3622 // If the window we now hide was the active window, we need 3623 // to find, and activate another window on screen. NB: Cocoa takes care of this 3624 // logic for us (and distinquishes between main windows and key windows) 3625 if (q->isActiveWindow() && !(q->windowType() == Qt::Popup)) { 3473 3626 QWidget *w = 0; 3474 3627 if(q->parentWidget()) 3475 3628 w = q->parentWidget()->window(); 3476 3629 if(!w || (!w->isVisible() && !w->isMinimized())) { 3477 #ifndef QT_MAC_USE_COCOA3478 3630 for (WindowPtr wp = GetFrontWindowOfClass(kMovableModalWindowClass, true); 3479 3631 wp; wp = GetNextWindowOfClass(wp, kMovableModalWindowClass, true)) { … … 3495 3647 } 3496 3648 } 3497 #else3498 NSArray *windows = [NSApp windows];3499 NSUInteger totalWindows = [windows count];3500 for (NSUInteger i = 0; i < totalWindows; ++i) {3501 OSWindowRef wp = [windows objectAtIndex:i];3502 if ((w = qt_mac_find_window(wp)))3503 break;3504 }3505 #endif3506 3649 } 3507 3650 if(w && w->isVisible() && !w->isMinimized()) { 3508 #ifndef QT_MAC_USE_COCOA 3509 qt_event_request_activate(w); 3510 #else 3511 [qt_mac_window_for(w) makeKeyWindow]; 3512 #endif 3513 } 3514 } 3651 qt_event_request_activate(w); 3652 } 3653 } 3654 #endif 3515 3655 } else { 3516 3656 invalidateBuffer(q->rect()); … … 3734 3874 QMacCocoaAutoReleasePool pool; 3735 3875 if (isRealWindow()) { 3736 // Calling orderFront shows the window on Cocoa too. 3876 // With the introduction of spaces it is not as simple as just raising the window. 3877 // First we need to check if we are in the right space. If we are, then we just continue 3878 // as usual. The problem comes when we are not in the active space. There are two main cases: 3879 // 1. Our parent was moved to a new space. In this case we want the window to be raised 3880 // in the same space as its parent. 3881 // 2. We don't have a parent. For this case we will just raise the window and let Cocoa 3882 // switch to the corresponding space. 3883 // NOTICE: There are a lot of corner cases here. We are keeping this simple for now, if 3884 // required we will introduce special handling for some of them. 3737 3885 if (!q->testAttribute(Qt::WA_DontShowOnScreen) && q->isVisible()) { 3738 [qt_mac_window_for(q) orderFront:qt_mac_window_for(q)]; 3886 OSWindowRef window = qt_mac_window_for(q); 3887 // isOnActiveSpace is available only from 10.6 onwards, so we need to check if it is 3888 // available before calling it. 3889 if([window respondsToSelector:@selector(isOnActiveSpace)]) { 3890 if(![window performSelector:@selector(isOnActiveSpace)]) { 3891 QWidget *parentWidget = q->parentWidget(); 3892 if(parentWidget) { 3893 OSWindowRef parentWindow = qt_mac_window_for(parentWidget); 3894 if(parentWindow && [parentWindow isOnActiveSpace]) { 3895 // The window was created in a different space. Therefore if we want 3896 // to show it in the current space we need to recreate it in the new 3897 // space. 3898 recreateMacWindow(); 3899 window = qt_mac_window_for(q); 3900 } 3901 } 3902 } 3903 } 3904 [window orderFront:window]; 3739 3905 } 3740 3906 if (qt_mac_raise_process) { //we get to be the active process now … … 3849 4015 flag 3850 4016 */ 3851 static void qt_mac_update_widget_posi siton(QWidget *q, QRect oldRect, QRect newRect)4017 static void qt_mac_update_widget_position(QWidget *q, QRect oldRect, QRect newRect) 3852 4018 { 3853 4019 #ifndef QT_MAC_USE_COCOA … … 3874 4040 3875 4041 // the position update is a part of a drag-and-drop operation 3876 QDragManager::self()->object || 3877 3878 // we are on Panther (no HIViewSetNeedsDisplayInRect) 3879 QSysInfo::MacintoshVersion < QSysInfo::MV_10_4 4042 QDragManager::self()->object || 4043 4044 // we are on Panther (no HIViewSetNeedsDisplayInRect) 4045 QSysInfo::MacintoshVersion < QSysInfo::MV_10_4 3880 4046 ){ 3881 4047 HIViewSetFrame(view, &bounds); … … 3946 4112 Q_UNUSED(oldRect); 3947 4113 NSRect bounds = NSMakeRect(newRect.x(), newRect.y(), 3948 4114 newRect.width(), newRect.height()); 3949 4115 [qt_mac_nativeview_for(q) setFrame:bounds]; 3950 4116 #endif … … 3983 4149 3984 4150 QRect parentWRect; 3985 if (q->isWindow() && topData()->embedded) { 4151 bool isEmbeddedWindow = (q->isWindow() && topData()->embedded); 4152 if (isEmbeddedWindow) { 3986 4153 #ifndef QT_MAC_USE_COCOA 3987 4154 HIViewRef parentView = HIViewGetSuperview(qt_mac_nativeview_for(q)); … … 4008 4175 if (parentWRect.isValid()) { 4009 4176 // parent is clipped, and we have to clip to the same limit as parent 4010 if (!parentWRect.contains(xrect) ) {4177 if (!parentWRect.contains(xrect) && !isEmbeddedWindow) { 4011 4178 xrect &= parentWRect; 4012 4179 wrect = xrect; … … 4110 4277 } 4111 4278 4112 qt_mac_update_widget_posi siton(q, oldRect, xrect);4279 qt_mac_update_widget_position(q, oldRect, xrect); 4113 4280 4114 4281 if (jump) … … 4182 4349 QMacCocoaAutoReleasePool pool; 4183 4350 bool realWindow = isRealWindow(); 4351 BOOL needDisplay = realWindow ? YES : NO; 4184 4352 4185 4353 if (realWindow && !q->testAttribute(Qt::WA_DontShowOnScreen)){ … … 4196 4364 } 4197 4365 #else 4366 if (!isMove && !q->testAttribute(Qt::WA_Moved) && !q->isVisible()) { 4367 // INVARIANT: The location of the window has not yet been set. The default will 4368 // instead be to center it on the desktop, or over the parent, if any. Since we now 4369 // resize the window, we need to adjust the top left position to keep the window 4370 // centeralized. And we need to to this now (and before show) in case the positioning 4371 // of other windows (e.g. sub-windows) depend on this position: 4372 if (QWidget *p = q->parentWidget()) { 4373 x = p->geometry().center().x() - (w / 2); 4374 y = p->geometry().center().y() - (h / 2); 4375 } else { 4376 QRect availGeo = QApplication::desktop()->availableGeometry(q); 4377 x = availGeo.center().x() - (w / 2); 4378 y = availGeo.center().y() - (h / 2); 4379 } 4380 } 4381 4198 4382 QSize olds = q->size(); 4199 4383 const bool isResize = (olds != QSize(w, h)); … … 4213 4397 && cocoaFrameRect.size.width != 0 4214 4398 && cocoaFrameRect.size.height != 0) { 4215 [window setFrame:cocoaFrameRect display: NO];4399 [window setFrame:cocoaFrameRect display:needDisplay]; 4216 4400 } else { 4217 4401 // The window is moved and resized (or resized to zero). … … 4222 4406 // window back and forth inbetween. 4223 4407 cocoaFrameRect.origin.y += 1; 4224 [window setFrame:cocoaFrameRect display: NO];4408 [window setFrame:cocoaFrameRect display:needDisplay]; 4225 4409 cocoaFrameRect.origin.y -= 1; 4226 4410 [window setFrameOrigin:cocoaFrameRect.origin]; … … 4248 4432 4249 4433 const bool visible = q->isVisible(); 4434 // Apply size restrictions, applicable for Windows & Widgets. 4435 if (QWExtra *extra = extraData()) { 4436 w = qMin(w, extra->maxw); 4437 h = qMin(h, extra->maxh); 4438 w = qMax(w, extra->minw); 4439 h = qMax(h, extra->minh); 4440 } 4250 4441 data.crect = QRect(x, y, w, h); 4251 4442 … … 4612 4803 SetControlDragTrackingEnabled(qt_mac_nativeview_for(q), on); 4613 4804 #else 4614 NSView *view = qt_mac_nativeview_for(q); 4615 if (on && [view isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaView) class]]) { 4616 [static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(view) registerDragTypes]; 4805 NSWindow *win = qt_mac_window_for(q); 4806 if (on) { 4807 if ([win isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaWindow) class]]) 4808 [static_cast<QT_MANGLE_NAMESPACE(QCocoaWindow) *>(win) registerDragTypes]; 4809 else if ([win isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaPanel) class]]) 4810 [static_cast<QT_MANGLE_NAMESPACE(QCocoaPanel) *>(win) registerDragTypes]; 4617 4811 } 4618 4812 #endif … … 4730 4924 [window invalidateShadow]; 4731 4925 } 4732 [qt_mac_nativeview_for(q) setNeedsDisplay:YES];4926 qt_mac_set_needs_display(q, QRegion()); 4733 4927 } 4734 4928 #endif … … 4770 4964 4771 4965 if (windowParent && q->windowModality() == Qt::WindowModal){ 4772 // Window should be window-modal, which implies a sheet.4966 // INVARIANT: Window should be window-modal (which implies a sheet). 4773 4967 if (!alreadySheet) { 4774 4968 // NB: the following call will call setModal_sys recursivly: … … 4787 4981 } 4788 4982 } else { 4789 // Window shold not be window-modal, and as such, not a sheet.4983 // INVARIANT: Window shold _not_ be window-modal (and as such, not a sheet). 4790 4984 if (alreadySheet){ 4791 4985 // NB: the following call will call setModal_sys recursivly: … … 4793 4987 windowRef = qt_mac_window_for(q); 4794 4988 } 4795 if (q->windowModality() == Qt::ApplicationModal) { 4796 [windowRef setLevel:NSModalPanelWindowLevel]; 4797 } else if (primaryWindow && primaryWindow->windowModality() == Qt::ApplicationModal) { 4798 // INVARIANT: Our window is a dialog that has a dialog parent that is 4799 // application modal, or . This means that q is supposed to be on top of this 4800 // dialog and not be modally shaddowed: 4801 [windowRef setLevel:NSModalPanelWindowLevel]; 4989 if (q->windowModality() == Qt::NonModal 4990 && primaryWindow && primaryWindow->windowModality() == Qt::ApplicationModal) { 4991 // INVARIANT: Our window has a parent that is application modal. 4992 // This means that q is supposed to be on top of this window and 4993 // not be modally shaddowed: 4802 4994 if ([windowRef isKindOfClass:[NSPanel class]]) 4803 4995 [static_cast<NSPanel *>(windowRef) setWorksWhenModal:YES]; 4804 } else {4805 // INVARIANT: q should not be modal.4806 NSInteger winLevel = -1;4807 if (q->windowType() == Qt::Popup) {4808 winLevel = NSPopUpMenuWindowLevel;4809 // Popup should be in at least the same level as its parent.4810 if (primaryWindow) {4811 OSWindowRef parentRef = qt_mac_window_for(primaryWindow);4812 winLevel = qMax([parentRef level], winLevel);4813 }4814 } else if (q->windowType() == Qt::Tool) {4815 winLevel = NSFloatingWindowLevel;4816 } else if (q->windowType() == Qt::Dialog) {4817 winLevel = NSModalPanelWindowLevel;4818 }4819 4820 // StayOnTop window should appear above Tool windows.4821 if (data.window_flags & Qt::WindowStaysOnTopHint)4822 winLevel = NSPopUpMenuWindowLevel;4823 // Tooltips should appear above StayOnTop windows.4824 if (q->windowType() == Qt::ToolTip)4825 winLevel = NSScreenSaverWindowLevel;4826 // All other types are Normal level.4827 if (winLevel == -1)4828 winLevel = NSNormalWindowLevel;4829 [windowRef setLevel:winLevel];4830 4996 } 4831 4997 } … … 5007 5173 recreateMacWindow(); 5008 5174 #else 5009 QMainWindowLayout *layout = q object_cast<QMainWindowLayout *>(q->layout());5175 QMainWindowLayout *layout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q)); 5010 5176 if (q->testAttribute(Qt::WA_MacBrushedMetal)) { 5011 5177 if (layout)
Note:
See TracChangeset
for help on using the changeset viewer.