Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/kernel/qwidget_mac.mm

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    115115QT_BEGIN_NAMESPACE
    116116
     117// qmainwindow.cpp
     118extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *window);
     119
    117120#define XCOORD_MAX 16383
    118121#define WRECT_MAX 8191
     
    461464bool qt_isGenuineQWidget(const QWidget *window)
    462465{
    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()));
    464473}
    465474
     
    747756}
    748757
     758#ifndef QT_NO_GESTURES
    749759#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
    750760/* We build the release package against the 10.4 SDK.
     
    763773};
    764774#endif
     775#endif // QT_NO_GESTURES
    765776
    766777// window events
     
    10711082        break; }
    10721083
     1084#ifndef QT_NO_GESTURES
    10731085    case kEventClassGesture: {
    10741086        // First, find the widget that was under
     
    11371149        QApplication::sendSpontaneousEvent(widget, &qNGEvent);
    11381150    break; }
     1151#endif // QT_NO_GESTURES
    11391152
    11401153    default:
     
    15901603        QWidget *widget = static_cast<QWidget*>(object);
    15911604        if(qt_mac_is_macdrawer(widget)) {
     1605            bool oldState = widget->testAttribute(Qt::WA_WState_ExplicitShowHide);
    15921606            if(visible) {
    15931607                if (!widget->testAttribute(Qt::WA_WState_ExplicitShowHide))
     
    15951609            } else {
    15961610                widget->hide();
    1597                 widget->setAttribute(Qt::WA_WState_ExplicitShowHide, false);
     1611                if(!oldState)
     1612                    widget->setAttribute(Qt::WA_WState_ExplicitShowHide, false);
    15981613            }
    15991614        }
     
    19131928    else if(popup || (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5 && type == Qt::SplashScreen))
    19141929        wclass = kModalWindowClass;
    1915     else if(q->testAttribute(Qt::WA_ShowModal) || type == Qt::Dialog)
     1930    else if(type == Qt::Dialog)
    19161931        wclass = kMovableModalWindowClass;
    19171932    else if(type == Qt::ToolTip)
     
    19201935                                 && type == Qt::SplashScreen))
    19211936        wclass = kFloatingWindowClass;
     1937    else if(q->testAttribute(Qt::WA_ShowModal))
     1938        wclass = kMovableModalWindowClass;
    19221939    else
    19231940        wclass = kDocumentWindowClass;
     
    20232040            if((tmp_wattr & known_attribs[i].tag) == known_attribs[i].tag) {
    20242041                tmp_wattr ^= known_attribs[i].tag;
    2025                 qDebug("Qt: internal: * %s %s", known_attribs[i].name,
    2026                         (GetAvailableWindowAttributes(wclass) & known_attribs[i].tag) ? "" : "(*)");
    20272042            }
    20282043        }
     
    22192234}
    22202235#else  // QT_MAC_USE_COCOA
     2236
     2237void 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
    22212271void QWidgetPrivate::finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ voidWindowRef)
    22222272{
     
    22602310            registerDropSite(true);
    22612311        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];
    22622318    }
    22632319
     
    22912347    }
    22922348
     2349    if (qApp->overrideCursor())
     2350        [windowRef disableCursorRects];
     2351
     2352    setWindowLevel();
    22932353    macUpdateHideOnSuspend();
    22942354    macUpdateOpaqueSizeGrip();
     
    23192379    determineWindowClass();
    23202380    createWindow_sys();
    2321     if (QMainWindowLayout *mwl = qobject_cast<QMainWindowLayout *>(q->layout())) {
     2381
     2382    if (QMainWindowLayout *mwl = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q))) {
    23222383        mwl->updateHIToolBarStatus();
    23232384    }
     
    25652626    } else {
    25662627        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))) {
    25682638#ifndef QT_MAC_USE_COCOA
    25692639            HIRect bounds = CGRectMake(data.crect.x(), data.crect.y(), data.crect.width(), data.crect.height());
     
    26252695{
    26262696    Q_D(QWidget);
     2697    d->aboutToDestroy();
    26272698    if (!isWindow() && parentWidget())
    26282699        parentWidget()->d_func()->invalidateBuffer(d->effectiveRectFor(geometry()));
     
    27212792}
    27222793
     2794#ifdef QT_MAC_USE_COCOA
     2795void 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
    27232859void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f)
    27242860{
     
    27682904        if (wasWindow) {
    27692905            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            }
    27732911        }
    27742912#endif
     
    27812919    //recreate and setup flags
    27822920    QObjectPrivate::setParent_helper(parent);
    2783     QPoint pt = q->pos();
    27842921    bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide);
    27852922    if (wasCreated && !qt_isGenuineQWidget(q))
    27862923        return;
    27872924
    2788     if ((data.window_flags & Qt::Sheet) && topData && topData->opacity == 242)
     2925    if (!q->testAttribute(Qt::WA_WState_WindowOpacitySet)) {
    27892926        q->setWindowOpacity(1.0f);
     2927        q->setAttribute(Qt::WA_WState_WindowOpacitySet, false);
     2928    }
    27902929
    27912930    setWinId(0); //do after the above because they may want the id
     
    27962935    q->setAttribute(Qt::WA_WState_Hidden, false);
    27972936    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) {
    28012943        createWinId();
    28022944        if (q->isWindow()) {
     
    28052947            // (only for performance, it gets called a lot anyway).
    28062948            if (!wasCreated) {
    2807                 if (QMainWindowLayout *mwl = qobject_cast<QMainWindowLayout *>(q->layout())) {
     2949                if (QMainWindowLayout *mwl = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q))) {
    28082950                    mwl->updateHIToolBarStatus();
    28092951                }
     
    28302972        // So redo the status one more time. It apparently is not an issue with Cocoa.
    28312973        if (q->isWindow()) {
    2832             if (QMainWindowLayout *mwl = qobject_cast<QMainWindowLayout *>(q->layout())) {
     2974            if (QMainWindowLayout *mwl = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q))) {
    28332975                mwl->updateHIToolBarStatus();
    28342976            }
     
    28753017        }
    28763018    }
    2877 
    28783019    invalidateBuffer(q->rect());
    28793020    qt_event_request_window_change(q);
     
    28833024{
    28843025    Q_D(const QWidget);
    2885     if (!testAttribute(Qt::WA_WState_Created)) {
     3026    if (!testAttribute(Qt::WA_WState_Created) || !internalWinId()) {
    28863027        QPoint p = pos + data->crect.topLeft();
    28873028        return isWindow() ?  p : parentWidget()->mapToGlobal(p);
     
    29103051{
    29113052    Q_D(const QWidget);
    2912     if (!testAttribute(Qt::WA_WState_Created)) {
     3053    if (!testAttribute(Qt::WA_WState_Created) || !internalWinId()) {
    29133054        QPoint p = isWindow() ?  pos : parentWidget()->mapFromGlobal(pos);
    29143055        return p - data->crect.topLeft();
     
    31813322#ifndef QT_MAC_USE_COCOA
    31823323        ActivateWindow(win, true);
     3324        qApp->setActiveWindow(tlw);
    31833325#else
    31843326        [win makeKeyWindow];
    31853327#endif
    3186         qApp->setActiveWindow(tlw);
    31873328    } else if(!isMinimized()) {
    31883329#ifndef QT_MAC_USE_COCOA
     
    32093350            HIViewSetNeedsDisplay(qt_mac_nativeview_for(q), true);
    32103351#else
    3211             [qt_mac_nativeview_for(q) setNeedsDisplay:YES];
     3352            qt_mac_set_needs_display(q, QRegion());
    32123353#endif
    32133354        return;
     
    32473388    }
    32483389#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    }
    32543408#endif
    32553409}
     
    32753429
    32763430    bool realWindow = isRealWindow();
     3431#ifndef QT_MAC_USE_COCOA
    32773432    if (realWindow && !q->testAttribute(Qt::WA_Moved)) {
     3433        if (qt_mac_is_macsheet(q))
     3434            recreateMacWindow();
    32783435        q->createWinId();
    32793436        if (QWidget *p = q->parentWidget()) {
    32803437            p->createWinId();
    3281 #ifndef QT_MAC_USE_COCOA
    32823438            RepositionWindow(qt_mac_window_for(q), qt_mac_window_for(p), kWindowCenterOnParentWindow);
    3283 #else
    3284             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 #endif
    32913439        } else {
    3292 #ifndef QT_MAC_USE_COCOA
    32933440            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
    33093445    data.fstrut_dirty = true;
    33103446    if (realWindow) {
     
    33373473            // sync the opacity value back (in case of a fade).
    33383474            [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);
    33463494#endif
    33473495            if (q->windowType() == Qt::Popup) {
     
    33623510#ifndef QT_MAC_USE_COCOA
    33633511            qt_event_request_activate(q);
    3364 #else
    3365             [qt_mac_window_for(q) makeKeyWindow];
    33663512#endif
    33673513        }
     
    34053551    QMacCocoaAutoReleasePool pool;
    34063552    if(q->isWindow()) {
     3553#ifdef QT_MAC_USE_COCOA
     3554        setSubWindowStacking(false);
     3555#endif
    34073556        OSWindowRef window = qt_mac_window_for(q);
    34083557        if(qt_mac_is_macsheet(q)) {
     
    34703619#endif
    34713620        }
    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)) {
    34733626            QWidget *w = 0;
    34743627            if(q->parentWidget())
    34753628                w = q->parentWidget()->window();
    34763629            if(!w || (!w->isVisible() && !w->isMinimized())) {
    3477 #ifndef QT_MAC_USE_COCOA
    34783630                for (WindowPtr wp = GetFrontWindowOfClass(kMovableModalWindowClass, true);
    34793631                    wp; wp = GetNextWindowOfClass(wp, kMovableModalWindowClass, true)) {
     
    34953647                    }
    34963648                }
    3497 #else
    3498                 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 #endif
    35063649            }
    35073650            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
    35153655    } else {
    35163656         invalidateBuffer(q->rect());
     
    37343874    QMacCocoaAutoReleasePool pool;
    37353875    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.
    37373885        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];
    37393905        }
    37403906        if (qt_mac_raise_process) { //we get to be the active process now
     
    38494015    flag
    38504016*/
    3851 static void qt_mac_update_widget_posisiton(QWidget *q, QRect oldRect, QRect newRect)
     4017static void qt_mac_update_widget_position(QWidget *q, QRect oldRect, QRect newRect)
    38524018{
    38534019#ifndef QT_MAC_USE_COCOA
     
    38744040
    38754041        // 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
    38804046    ){
    38814047        HIViewSetFrame(view, &bounds);
     
    39464112    Q_UNUSED(oldRect);
    39474113    NSRect bounds = NSMakeRect(newRect.x(), newRect.y(),
    3948                                newRect.width(), newRect.height());
     4114            newRect.width(), newRect.height());
    39494115    [qt_mac_nativeview_for(q) setFrame:bounds];
    39504116#endif
     
    39834149
    39844150    QRect parentWRect;
    3985     if (q->isWindow() && topData()->embedded) {
     4151    bool isEmbeddedWindow = (q->isWindow() && topData()->embedded);
     4152    if (isEmbeddedWindow) {
    39864153#ifndef QT_MAC_USE_COCOA
    39874154        HIViewRef parentView = HIViewGetSuperview(qt_mac_nativeview_for(q));
     
    40084175    if (parentWRect.isValid()) {
    40094176        // 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) {
    40114178            xrect &= parentWRect;
    40124179            wrect = xrect;
     
    41104277    }
    41114278
    4112     qt_mac_update_widget_posisiton(q, oldRect, xrect);
     4279    qt_mac_update_widget_position(q, oldRect, xrect);
    41134280
    41144281    if  (jump)
     
    41824349    QMacCocoaAutoReleasePool pool;
    41834350    bool realWindow = isRealWindow();
     4351    BOOL needDisplay = realWindow ? YES : NO;
    41844352
    41854353    if (realWindow && !q->testAttribute(Qt::WA_DontShowOnScreen)){
     
    41964364        }
    41974365#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
    41984382        QSize  olds = q->size();
    41994383        const bool isResize = (olds != QSize(w, h));
     
    42134397                && cocoaFrameRect.size.width != 0
    42144398                && cocoaFrameRect.size.height != 0) {
    4215             [window setFrame:cocoaFrameRect display:NO];
     4399            [window setFrame:cocoaFrameRect display:needDisplay];
    42164400        } else {
    42174401            // The window is moved and resized (or resized to zero).
     
    42224406            // window back and forth inbetween.
    42234407            cocoaFrameRect.origin.y += 1;
    4224             [window setFrame:cocoaFrameRect display:NO];
     4408            [window setFrame:cocoaFrameRect display:needDisplay];
    42254409            cocoaFrameRect.origin.y -= 1;
    42264410            [window setFrameOrigin:cocoaFrameRect.origin];
     
    42484432
    42494433    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    }
    42504441    data.crect = QRect(x, y, w, h);
    42514442
     
    46124803    SetControlDragTrackingEnabled(qt_mac_nativeview_for(q), on);
    46134804#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];
    46174811    }
    46184812#endif
     
    47304924        [window invalidateShadow];
    47314925    }
    4732     [qt_mac_nativeview_for(q) setNeedsDisplay:YES];
     4926    qt_mac_set_needs_display(q, QRegion());
    47334927}
    47344928#endif
     
    47704964
    47714965    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).
    47734967        if (!alreadySheet) {
    47744968            // NB: the following call will call setModal_sys recursivly:
     
    47874981        }
    47884982    } 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).
    47904984        if (alreadySheet){
    47914985            // NB: the following call will call setModal_sys recursivly:
     
    47934987            windowRef = qt_mac_window_for(q);
    47944988        }
    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:
    48024994            if ([windowRef isKindOfClass:[NSPanel class]])
    48034995                [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];
    48304996        }
    48314997    }
     
    50075173        recreateMacWindow();
    50085174#else
    5009         QMainWindowLayout *layout = qobject_cast<QMainWindowLayout *>(q->layout());
     5175        QMainWindowLayout *layout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q));
    50105176        if (q->testAttribute(Qt::WA_MacBrushedMetal)) {
    50115177            if (layout)
Note: See TracChangeset for help on using the changeset viewer.