Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

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

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    7373**
    7474****************************************************************************/
    75 //#define QT_RASTER_PAINTENGINE
    7675
    7776#include <private/qt_mac_p.h>
     
    8483#include "qdesktopwidget.h"
    8584#include "qevent.h"
     85#include "qfileinfo.h"
    8686#include "qimage.h"
    8787#include "qlayout.h"
    8888#include "qmenubar.h"
    8989#include <private/qbackingstore_p.h>
    90 #ifdef QT_RASTER_PAINTENGINE
    91 # include <private/qpaintengine_raster_p.h>
    92 #endif
    9390#include <private/qwindowsurface_mac_p.h>
    9491#include <private/qpaintengine_mac_p.h>
     
    111108
    112109#include "qwidget_p.h"
     110#include "qevent_p.h"
    113111#include "qdnd_p.h"
    114112#include <QtGui/qgraphicsproxywidget.h>
     
    123121extern "C" {
    124122    extern OSStatus _HIViewScrollRectWithOptions(HIViewRef, const HIRect *, CGFloat, CGFloat,
    125                                                  OptionBits);
     123                                                 OptionBits) __attribute__ ((weak));
    126124}
    127125#define kHIViewScrollRectAdjustInvalid 1
     
    304302}
    305303
     304bool qt_mac_insideKeyWindow(const QWidget *w)
     305{
     306#ifdef QT_MAC_USE_COCOA
     307    return [[reinterpret_cast<NSView *>(w->winId()) window] isKeyWindow];
     308#else
     309    Q_UNUSED(w);
     310#endif
     311    return false;
     312}
     313
    306314bool qt_mac_set_drawer_preferred_edge(QWidget *w, Qt::DockWidgetArea where) //users of Qt for Mac OS X can use this..
    307315{
     
    391399inline static void qt_mac_set_fullscreen_mode(bool b)
    392400{
    393     extern bool qt_mac_app_fullscreen; //qapplication_mac.cpp
     401    extern bool qt_mac_app_fullscreen; //qapplication_mac.mm
    394402    if(qt_mac_app_fullscreen == b)
    395403        return;
    396404    qt_mac_app_fullscreen = b;
    397 #if QT_MAC_USE_COCOA
    398     if(b)
    399         SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar);
    400     else
     405    if (b) {
     406        SetSystemUIMode(kUIModeAllSuppressed, 0);
     407    } else {
    401408        SetSystemUIMode(kUIModeNormal, 0);
    402 #else
    403     if(b)
    404         HideMenuBar();
    405     else
    406         ShowMenuBar();
    407 #endif
     409    }
    408410}
    409411
     
    512514{
    513515    SInt32 group_level;
    514 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
    515     if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
    516         CGWindowLevel tmpLevel;
    517         GetWindowGroupLevelOfType(GetWindowGroupOfClass(wclass), kWindowGroupLevelActive, &tmpLevel);
    518         group_level = tmpLevel;
    519     } else
    520 #endif
    521     {
    522         GetWindowGroupLevel(GetWindowGroupOfClass(wclass), &group_level);
    523     }
     516    CGWindowLevel tmpLevel;
     517    GetWindowGroupLevelOfType(GetWindowGroupOfClass(wclass), kWindowGroupLevelActive, &tmpLevel);
     518    group_level = tmpLevel;
    524519    return group_level;
    525520}
     
    731726}
    732727
     728#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
     729/* We build the release package against the 10.4 SDK.
     730   So, to enable gestures for applications running on
     731   10.6+, we define the missing constants here: */
     732enum {
     733    kEventClassGesture              = 'gest',
     734    kEventGestureStarted            = 1,
     735    kEventGestureEnded              = 2,
     736    kEventGestureMagnify            = 4,
     737    kEventGestureSwipe              = 5,
     738    kEventGestureRotate             = 6,
     739    kEventParamRotationAmount       = 'rota',
     740    kEventParamSwipeDirection       = 'swip',
     741    kEventParamMagnificationAmount  = 'magn'
     742};
     743#endif
     744
    733745// window events
    734746static EventTypeSpec window_events[] = {
    735747    { kEventClassWindow, kEventWindowClose },
    736748    { kEventClassWindow, kEventWindowExpanded },
     749    { kEventClassWindow, kEventWindowHidden },
     750    { kEventClassWindow, kEventWindowZoom },
    737751    { kEventClassWindow, kEventWindowZoomed },
    738752    { kEventClassWindow, kEventWindowCollapsed },
     
    742756    { kEventClassWindow, kEventWindowResizeCompleted },
    743757    { kEventClassWindow, kEventWindowBoundsChanging },
    744     { kEventClassWindow, kEventWindowBoundsChanged },
    745758    { kEventClassWindow, kEventWindowGetRegion },
    746 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
    747759    { kEventClassWindow, kEventWindowGetClickModality },
    748 #endif
    749760    { kEventClassWindow, kEventWindowTransitionCompleted },
     761    { kEventClassGesture, kEventGestureStarted },
     762    { kEventClassGesture, kEventGestureEnded },
     763    { kEventClassGesture, kEventGestureMagnify },
     764    { kEventClassGesture, kEventGestureSwipe },
     765    { kEventClassGesture, kEventGestureRotate },
    750766    { kEventClassMouse, kEventMouseDown }
    751767};
     
    776792        if(!widget) {
    777793            handled_event = false;
    778 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
    779794        } else if(ekind == kEventWindowGetClickModality) {
    780795            // Carbon will send us kEventWindowGetClickModality before every
     
    787802            // help Carbon determining which window is supposed to be raised.
    788803            handled_event = qApp->activePopupWidget() ? true : false;
    789             QWidget *top = 0;
    790             if (!QApplicationPrivate::tryModalHelper(widget, &top) && top && top != widget){
    791                 if(!qt_mac_is_macsheet(top) || top->parentWidget() != widget) {
    792                     handled_event = true;
    793                     WindowPtr topWindowRef = qt_mac_window_for(top);
    794                     SetEventParameter(event, kEventParamModalWindow, typeWindowRef, sizeof(topWindowRef), &topWindowRef);
    795                     HIModalClickResult clickResult = kHIModalClickIsModal;
    796                     SetEventParameter(event, kEventParamModalClickResult, typeModalClickResult, sizeof(clickResult), &clickResult);
    797                 }
    798             }
    799 #endif
    800804        } else if(ekind == kEventWindowClose) {
    801805            widget->d_func()->close_helper(QWidgetPrivate::CloseWithSpontaneousEvent);
     
    825829            QShowEvent qse;
    826830            QApplication::sendSpontaneousEvent(widget, &qse);
     831        } else if(ekind == kEventWindowZoom) {
     832            widget->d_func()->topData()->normalGeometry = widget->geometry();
     833            handled_event = false;
    827834        } else if(ekind == kEventWindowZoomed) {
    828835            WindowPartCode windowPart;
     
    871878            qt_button_down = 0;
    872879        } else if(ekind == kEventWindowToolbarSwitchMode) {
    873             QToolBarChangeEvent ev(!(GetCurrentKeyModifiers() & cmdKey));
    874             QApplication::sendSpontaneousEvent(widget, &ev);
     880            macSendToolbarChangeEvent(widget);
    875881            HIToolbarRef toolbar;
    876882            if (GetWindowToolbar(wid, &toolbar) == noErr) {
     
    920926            SendEventToApplication(mouseUpEvent);
    921927            ReleaseEvent(mouseUpEvent);
    922         } else if(ekind == kEventWindowBoundsChanging || ekind == kEventWindowBoundsChanged) {
    923             // Panther doesn't send Changing for sheets, only changed, so only
    924             // bother handling Changed event if we are on 10.3 and we are a
    925             // sheet.
    926             if (ekind == kEventWindowBoundsChanged
    927                     && (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4
    928                         || !(widget->windowFlags() & Qt::Sheet))) {
     928        } else if(ekind == kEventWindowBoundsChanging) {
     929            UInt32 flags = 0;
     930            GetEventParameter(event, kEventParamAttributes, typeUInt32, 0,
     931                                  sizeof(flags), 0, &flags);
     932            Rect nr;
     933            GetEventParameter(event, kEventParamCurrentBounds, typeQDRectangle, 0,
     934                                  sizeof(nr), 0, &nr);
     935
     936            QRect newRect(nr.left, nr.top, nr.right - nr.left, nr.bottom - nr.top);
     937
     938            QTLWExtra * const tlwExtra = widget->d_func()->maybeTopData();
     939            if (tlwExtra && tlwExtra->isSetGeometry == 1) {
     940                widget->d_func()->setGeometry_sys_helper(newRect.left(), newRect.top(), newRect.width(), newRect.height(), tlwExtra->isMove);
     941            } else {
     942                //implicitly removes the maximized bit
     943                if((widget->data->window_state & Qt::WindowMaximized) &&
     944                   IsWindowInStandardState(wid, 0, 0)) {
     945                    widget->data->window_state &= ~Qt::WindowMaximized;
     946                    QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state
     947                                                | Qt::WindowMaximized));
     948                    QApplication::sendSpontaneousEvent(widget, &e);
     949
     950                }
     951
    929952                handled_event = false;
    930             } else {
    931                 UInt32 flags = 0;
    932                 GetEventParameter(event, kEventParamAttributes, typeUInt32, 0,
    933                                       sizeof(flags), 0, &flags);
    934                 Rect nr;
    935                 GetEventParameter(event, kEventParamCurrentBounds, typeQDRectangle, 0,
    936                                       sizeof(nr), 0, &nr);
    937 
    938                 QRect newRect(nr.left, nr.top, nr.right - nr.left, nr.bottom - nr.top);
    939 
    940                 QTLWExtra * const tlwExtra = widget->d_func()->maybeTopData();
    941                 if (tlwExtra && tlwExtra->isSetGeometry == 1) {
    942                     widget->d_func()->setGeometry_sys_helper(newRect.left(), newRect.top(), newRect.width(), newRect.height(), tlwExtra->isMove);
    943                 } else {
    944                     //implicitly removes the maximized bit
    945                     if((widget->data->window_state & Qt::WindowMaximized) &&
    946                        IsWindowInStandardState(wid, 0, 0)) {
    947                         widget->data->window_state &= ~Qt::WindowMaximized;
    948                         QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state
    949                                                     | Qt::WindowMaximized));
    950                         QApplication::sendSpontaneousEvent(widget, &e);
    951 
     953                const QRect oldRect = widget->data->crect;
     954                if((flags & kWindowBoundsChangeOriginChanged)) {
     955                    if(nr.left != oldRect.x() || nr.top != oldRect.y()) {
     956                        widget->data->crect.moveTo(nr.left, nr.top);
     957                        QMoveEvent qme(widget->data->crect.topLeft(), oldRect.topLeft());
     958                        QApplication::sendSpontaneousEvent(widget, &qme);
    952959                    }
    953 
    954                     handled_event = false;
    955                     const QRect oldRect = widget->data->crect;
    956                     if((flags & kWindowBoundsChangeOriginChanged)) {
    957                         if(nr.left != oldRect.x() || nr.top != oldRect.y()) {
    958                             widget->data->crect.moveTo(nr.left, nr.top);
    959                             QMoveEvent qme(widget->data->crect.topLeft(), oldRect.topLeft());
    960                             QApplication::sendSpontaneousEvent(widget, &qme);
     960                }
     961                if((flags & kWindowBoundsChangeSizeChanged)) {
     962                    if (widget->isWindow()) {
     963                        QSize newSize = QLayout::closestAcceptableSize(widget, newRect.size());
     964                        int dh = newSize.height() - newRect.height();
     965                        int dw = newSize.width() - newRect.width();
     966                        if (dw != 0 || dh != 0) {
     967                            handled_event = true;  // We want to change the bounds, so we handle the event
     968
     969                            // set the rect, so we can also do the resize down below (yes, we need to resize).
     970                            newRect.setBottom(newRect.bottom() + dh);
     971                            newRect.setRight(newRect.right() + dw);
     972
     973                            nr.left = newRect.x();
     974                            nr.top = newRect.y();
     975                            nr.right = nr.left + newRect.width();
     976                            nr.bottom = nr.top + newRect.height();
     977                            SetEventParameter(event, kEventParamCurrentBounds, typeQDRectangle, sizeof(Rect), &nr);
    961978                        }
    962979                    }
    963                     if((flags & kWindowBoundsChangeSizeChanged)) {
    964                         if (widget->isWindow()) {
    965                             QSize newSize = QLayout::closestAcceptableSize(widget, newRect.size());
    966                             int dh = newSize.height() - newRect.height();
    967                             int dw = newSize.width() - newRect.width();
    968                             if (dw != 0 || dh != 0) {
    969                                 handled_event = true;  // We want to change the bounds, so we handle the event
    970 
    971                                 // set the rect, so we can also do the resize down below (yes, we need to resize).
    972                                 newRect.setBottom(newRect.bottom() + dh);
    973                                 newRect.setRight(newRect.right() + dw);
    974 
    975                                 nr.left = newRect.x();
    976                                 nr.top = newRect.y();
    977                                 nr.right = nr.left + newRect.width();
    978                                 nr.bottom = nr.top + newRect.height();
    979                                 SetEventParameter(event, kEventParamCurrentBounds, typeQDRectangle, sizeof(Rect), &nr);
    980                             }
    981                         }
    982 
    983                         if (oldRect.width() != newRect.width() || oldRect.height() != newRect.height()) {
    984                             widget->data->crect.setSize(newRect.size());
    985                             HIRect bounds = CGRectMake(0, 0, newRect.width(), newRect.height());
    986 
    987                             // If the WA_StaticContents attribute is set we can optimize the resize
    988                             // by only repainting the newly exposed area. We do this by disabling
    989                             // painting when setting the size of the view. The OS will invalidate
    990                             // the newly exposed area for us.
    991                             const bool staticContents = widget->testAttribute(Qt::WA_StaticContents);
    992                             const HIViewRef view = qt_mac_nativeview_for(widget);
    993                             if (staticContents)
    994                                 HIViewSetDrawingEnabled(view, false);
    995                             HIViewSetFrame(view, &bounds);
    996                             if (staticContents)
    997                                 HIViewSetDrawingEnabled(view, true);
    998 
    999                             QResizeEvent qre(newRect.size(), oldRect.size());
    1000                             QApplication::sendSpontaneousEvent(widget, &qre);
    1001                             qt_event_request_window_change(widget);
    1002                         }
     980
     981                    if (oldRect.width() != newRect.width() || oldRect.height() != newRect.height()) {
     982                        widget->data->crect.setSize(newRect.size());
     983                        HIRect bounds = CGRectMake(0, 0, newRect.width(), newRect.height());
     984
     985                        // If the WA_StaticContents attribute is set we can optimize the resize
     986                        // by only repainting the newly exposed area. We do this by disabling
     987                        // painting when setting the size of the view. The OS will invalidate
     988                        // the newly exposed area for us.
     989                        const bool staticContents = widget->testAttribute(Qt::WA_StaticContents);
     990                        const HIViewRef view = qt_mac_nativeview_for(widget);
     991                        if (staticContents)
     992                            HIViewSetDrawingEnabled(view, false);
     993                        HIViewSetFrame(view, &bounds);
     994                        if (staticContents)
     995                            HIViewSetDrawingEnabled(view, true);
     996
     997                        QResizeEvent qre(newRect.size(), oldRect.size());
     998                        QApplication::sendSpontaneousEvent(widget, &qre);
     999                        qt_event_request_window_change(widget);
    10031000                    }
     1001                }
     1002            }
     1003        } else if (ekind == kEventWindowHidden) {
     1004            // Make sure that we also hide any visible sheets on our window.
     1005            // Cocoa does the right thing for us.
     1006            const QObjectList children = widget->children();
     1007            const int childCount = children.count();
     1008            for (int i = 0; i < childCount; ++i) {
     1009                QObject *obj = children.at(i);
     1010                if (obj->isWidgetType()) {
     1011                    QWidget *widget = static_cast<QWidget *>(obj);
     1012                    if (qt_mac_is_macsheet(widget) && widget->isVisible())
     1013                        widget->hide();
    10041014                }
    10051015            }
     
    10411051        handled_event = false;
    10421052        break; }
     1053
     1054    case kEventClassGesture: {
     1055        // First, find the widget that was under
     1056        // the mouse when the gesture happened:
     1057        HIPoint screenLocation;
     1058        if (GetEventParameter(event, kEventParamMouseLocation, typeHIPoint, 0,
     1059                    sizeof(screenLocation), 0, &screenLocation) != noErr) {
     1060            handled_event = false;
     1061            break;
     1062        }
     1063        QWidget *widget = QApplication::widgetAt(screenLocation.x, screenLocation.y);
     1064        if (!widget) {
     1065            handled_event = false;
     1066            break;
     1067        }
     1068
     1069        QNativeGestureEvent qNGEvent;
     1070        qNGEvent.position = QPoint(screenLocation.x, screenLocation.y);
     1071
     1072        switch (ekind) {
     1073            case kEventGestureStarted:
     1074                qNGEvent.gestureType = QNativeGestureEvent::GestureBegin;
     1075                break;
     1076            case kEventGestureEnded:
     1077                qNGEvent.gestureType = QNativeGestureEvent::GestureEnd;
     1078                break;
     1079            case kEventGestureRotate: {
     1080                CGFloat amount;
     1081                if (GetEventParameter(event, kEventParamRotationAmount, 'cgfl', 0,
     1082                            sizeof(amount), 0, &amount) != noErr) {
     1083                    handled_event = false;
     1084                    break;
     1085                }
     1086                qNGEvent.gestureType = QNativeGestureEvent::Rotate;
     1087                qNGEvent.percentage = float(-amount);
     1088                break; }
     1089            case kEventGestureSwipe: {
     1090                HIPoint swipeDirection;
     1091                if (GetEventParameter(event, kEventParamSwipeDirection, typeHIPoint, 0,
     1092                            sizeof(swipeDirection), 0, &swipeDirection) != noErr) {
     1093                    handled_event = false;
     1094                    break;
     1095                }
     1096                qNGEvent.gestureType = QNativeGestureEvent::Swipe;
     1097                if (swipeDirection.x == 1)
     1098                    qNGEvent.angle = 180.0f;
     1099                else if (swipeDirection.x == -1)
     1100                    qNGEvent.angle = 0.0f;
     1101                else if (swipeDirection.y == 1)
     1102                    qNGEvent.angle = 90.0f;
     1103                else if (swipeDirection.y == -1)
     1104                    qNGEvent.angle = 270.0f;
     1105                break; }
     1106            case kEventGestureMagnify: {
     1107                CGFloat amount;
     1108                if (GetEventParameter(event, kEventParamMagnificationAmount, 'cgfl', 0,
     1109                            sizeof(amount), 0, &amount) != noErr) {
     1110                    handled_event = false;
     1111                    break;
     1112                }
     1113                qNGEvent.gestureType = QNativeGestureEvent::Zoom;
     1114                qNGEvent.percentage = float(amount);
     1115                break; }
     1116        }
     1117
     1118        QApplication::sendSpontaneousEvent(widget, &qNGEvent);
     1119    break; }
     1120
    10431121    default:
    10441122        handled_event = false;
     
    11401218                GrafPtr qd = 0;
    11411219                CGContextRef cg = 0;
    1142 #ifndef QT_MAC_NO_QUICKDRAW
    1143                 {
    1144                     if(GetEventParameter(event, kEventParamGrafPort, typeGrafPtr, 0, sizeof(qd), 0, &qd) != noErr) {
    1145                         GDHandle dev = 0;
    1146                         GetGWorld(&qd, &dev); //just use the global port..
    1147                     }
    1148                 }
    1149                 bool end_cg_context = false;
    1150                 if(GetEventParameter(event, kEventParamCGContextRef, typeCGContextRef, 0, sizeof(cg), 0, &cg) != noErr && qd) {
    1151                     end_cg_context = true;
    1152                     QDBeginCGContext(qd, &cg);
    1153                 }
    1154 #else
    11551220                if(GetEventParameter(event, kEventParamCGContextRef, typeCGContextRef, 0, sizeof(cg), 0, &cg) != noErr) {
    11561221                    Q_ASSERT(false);
    11571222                }
    1158 #endif
    11591223                widget->d_func()->hd = cg;
    11601224                widget->d_func()->qd_hd = qd;
     
    12221286                        if(was_unclipped)
    12231287                            widget->setAttribute(Qt::WA_PaintUnclipped);
    1224 
    1225                         QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(widget->parent());
    1226                         QPoint scrollAreaOffset;
    1227                         if (scrollArea && scrollArea->viewport() == widget) {
    1228                             QAbstractScrollAreaPrivate *priv = static_cast<QAbstractScrollAreaPrivate *>(static_cast<QWidget *>(scrollArea)->d_ptr);
    1229                             scrollAreaOffset = priv->contentsOffset();
    1230                             p.translate(-scrollAreaOffset);
    1231                         }
    1232 
    1233                         widget->d_func()->paintBackground(&p, qrgn, scrollAreaOffset, widget->isWindow() ? DrawAsRoot : 0);
     1288                        widget->d_func()->paintBackground(&p, qrgn, widget->isWindow() ? DrawAsRoot : 0);
    12341289                        if (widget->testAttribute(Qt::WA_TintedBackground)) {
    12351290                            QColor tint = widget->palette().window().color();
     
    12371292                            const QVector<QRect> &rects = qrgn.rects();
    12381293                            for (int i = 0; i < rects.size(); ++i)
    1239                                 p.fillRect(rects.at(i).translated(scrollAreaOffset), tint);
     1294                                p.fillRect(rects.at(i), tint);
    12401295                        }
    12411296                        p.end();
     
    12671322                    if (!redirectionOffset.isNull())
    12681323                        widget->d_func()->restoreRedirected();
    1269 #ifdef QT_RASTER_PAINTENGINE
    1270                     if(engine && engine->type() == QPaintEngine::Raster)
    1271                         static_cast<QRasterPaintEngine*>(engine)->flush(widget,
    1272                                                                         qrgn.boundingRect().topLeft());
    1273 #endif
    12741324
    12751325                    //cleanup
     
    12851335                widget->d_func()->qd_hd = 0;
    12861336                CGContextRestoreGState(cg);
    1287 #ifndef QT_MAC_NO_QUICKDRAW
    1288                 if(end_cg_context)
    1289                     QDEndCGContext(qd, &cg);
    1290 #endif
    12911337            } else if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget)) {
    12921338                CallNextEventHandler(er, event);
     
    13931439                        // doesn't get called a second time below:
    13941440                        dropWidget = 0;
     1441                    } else if (ekind == kEventControlDragLeave) {
     1442                        dropWidget = QDragManager::self()->currentTarget();
     1443                        if (dropWidget) {
     1444                            dropWidget->d_func()->qt_mac_dnd_event(kEventControlDragLeave, drag);
     1445                        }
     1446                        // Set dropWidget to zero, so qt_mac_dnd_event
     1447                        // doesn't get called a second time below:
     1448                        dropWidget = 0;
    13951449                    }
    13961450                }
     
    15371591bool QWidgetPrivate::qt_mac_update_sizer(QWidget *w, int up)
    15381592{
     1593    // I'm not sure what "up" is
    15391594    if(!w || !w->isWindow())
    15401595        return false;
     
    15421597    QTLWExtra *topData = w->d_func()->topData();
    15431598    QWExtra *extraData = w->d_func()->extraData();
    1544     topData->resizer += up;
     1599    // topData->resizer is only 4 bits, so subtracting -1 from zero causes bad stuff
     1600    // to happen, prevent that here (you really want the thing hidden).
     1601    if (up >= 0 || topData->resizer != 0)
     1602        topData->resizer += up;
    15451603    OSWindowRef windowRef = qt_mac_window_for(OSViewRef(w->winId()));
    15461604    {
     
    15551613                        || (extraData->maxw && extraData->maxh &&
    15561614                            extraData->maxw == extraData->minw && extraData->maxh == extraData->minh));
    1557 
    15581615#ifndef QT_MAC_USE_COCOA
    15591616    WindowAttributes attr;
     
    16031660        return false;
    16041661    qAddPostRoutine(qt_clean_root_win);
    1605     return true;
    1606 }
    1607 
    1608 bool QWidgetPrivate::qt_recreate_root_win()
    1609 {
    1610     if(!qt_root_win) //sanity check
    1611         return false;
    1612     //store old
    1613     OSWindowRef old_root_win = qt_root_win;
    1614     //recreate
    1615     qt_root_win = 0;
    1616     qt_create_root_win();
    1617     //cleanup old window
    1618 #ifdef QT_MAC_USE_COCOA
    1619     [old_root_win release];
    1620 #else
    1621     CFRelease(old_root_win);
    1622 #endif
    16231662    return true;
    16241663}
     
    17241763        if (framelessWindow) {
    17251764            if(wclass == kDocumentWindowClass) {
    1726                 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4)
    1727                     wattr |= kWindowNoTitleBarAttribute;
    1728                 else
    1729                     wclass = kPlainWindowClass;
     1765                wattr |= kWindowNoTitleBarAttribute;
    17301766            } else if(wclass == kFloatingWindowClass) {
    1731                 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4)
    1732                     wattr |= kWindowNoTitleBarAttribute;
    1733                 else
    1734                     wclass = kToolbarWindowClass;
     1767                wattr |= kWindowNoTitleBarAttribute;
    17351768            } else if (wclass  == kMovableModalWindowClass) {
    1736                     wclass = kModalWindowClass;
     1769                wclass = kModalWindowClass;
    17371770            }
    17381771        } else {
     
    20322065        SetAutomaticControlDragTrackingEnabledForWindow(windowRef, true);
    20332066    HIWindowChangeFeatures(windowRef, kWindowCanCollapse, 0);
    2034 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4)
    2035     if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
    2036         if (wattr & kWindowHideOnSuspendAttribute)
    2037             HIWindowChangeAvailability(windowRef, kHIWindowExposeHidden, 0);
    2038         else
    2039             HIWindowChangeAvailability(windowRef, 0, kHIWindowExposeHidden);
    2040     }
    2041 #endif
     2067    if (wattr & kWindowHideOnSuspendAttribute)
     2068        HIWindowChangeAvailability(windowRef, kHIWindowExposeHidden, 0);
     2069    else
     2070        HIWindowChangeAvailability(windowRef, 0, kHIWindowExposeHidden);
    20422071    if ((flags & Qt::WindowStaysOnTopHint))
    20432072        ChangeWindowAttributes(windowRef, kWindowNoAttributes, kWindowHideOnSuspendAttribute);
     
    21632192    updateFrameStrut();
    21642193    qt_mac_update_sizer(q);
     2194    applyMaxAndMinSizeOnWindow();
    21652195}
    21662196#else  // QT_MAC_USE_COCOA
     
    21832213    if ((popup || type == Qt::Tool || type == Qt::ToolTip) && !q->isModal()) {
    21842214        [windowRef setHidesOnDeactivate:YES];
    2185         [windowRef setHasShadow:YES];
    2186     }
     2215    } else {
     2216        [windowRef setHidesOnDeactivate:NO];
     2217    }
     2218    [windowRef setHasShadow:YES];
    21872219    Q_UNUSED(parentWidget);
    21882220    Q_UNUSED(dialog);
     
    22452277    macUpdateIsOpaque();
    22462278    qt_mac_update_sizer(q);
     2279    applyMaxAndMinSizeOnWindow();
    22472280}
    22482281
     
    23092342    OSWindowRef windowRef = qt_mac_create_window(q, topExtra->wclass, wattr, data.crect);
    23102343    if (windowRef == 0)
    2311         qWarning("QWidget: Internal error: %s:%d: If you reach this error please contact Trolltech and include the\n"
     2344        qWarning("QWidget: Internal error: %s:%d: If you reach this error please contact Qt Support and include the\n"
    23122345                "      WidgetFlags used in creating the widget.", __FILE__, __LINE__);
    23132346#ifndef QT_MAC_USE_COCOA
     
    25282561    if (!topLevel && initializeWindow)
    25292562        setWSGeometry();
    2530 
    25312563    if (destroyid)
    25322564        qt_mac_destructView(destroyid);
     2565    if (q->testAttribute(Qt::WA_AcceptTouchEvents))
     2566        registerTouchWindow();
    25332567}
    25342568
     
    25682602    Q_D(QWidget);
    25692603    if (!isWindow() && parentWidget())
    2570         parentWidget()->d_func()->invalidateBuffer(geometry());
     2604        parentWidget()->d_func()->invalidateBuffer(d->effectiveRectFor(geometry()));
    25712605    d->deactivateWidgetCleanup();
    25722606    qt_mac_event_release(this);
     
    25842618        if(mac_keyboard_grabber == this)
    25852619            releaseKeyboard();
    2586         if(acceptDrops())
    2587             setAcceptDrops(false);
    25882620
    25892621        if(testAttribute(Qt::WA_ShowModal))          // just be sure we leave modal
     
    26192651            }
    26202652        }
    2621         d->setWinId(0);
     2653        QT_TRY {
     2654            d->setWinId(0);
     2655        } QT_CATCH (const std::bad_alloc &) {
     2656            // swallow - destructors must not throw
     2657        }
    26222658    }
    26232659}
     
    26492685                    bool oldRegistered = w->testAttribute(Qt::WA_DropSiteRegistered);
    26502686                    w->setAttribute(Qt::WA_DropSiteRegistered, false);
     2687                    [qt_mac_nativeview_for(w) retain];
     2688                    [qt_mac_nativeview_for(w) removeFromSuperview];
    26512689                    [qt_mac_nativeview_for(q) addSubview:qt_mac_nativeview_for(w)];
     2690                    [qt_mac_nativeview_for(w) release];
    26522691                    w->setAttribute(Qt::WA_DropSiteRegistered, oldRegistered);
    26532692#endif
     
    26702709
    26712710    if (q->isVisible() && q->parentWidget() && parent != q->parentWidget())
    2672         q->parentWidget()->d_func()->invalidateBuffer(q->geometry());
     2711        q->parentWidget()->d_func()->invalidateBuffer(effectiveRectFor(q->geometry()));
    26732712
    26742713    // Maintain the glWidgets list on parent change: remove "our" gl widgets
     
    27372776        if (q->isWindow()) {
    27382777#ifndef QT_MAC_USE_COCOA
    2739             if (QMainWindowLayout *mwl = qobject_cast<QMainWindowLayout *>(q->layout())) {
    2740                 mwl->updateHIToolBarStatus();
    2741             }
    2742 #else
     2778            // We do this down below for wasCreated, so avoid doing this twice
     2779            // (only for performance, it gets called a lot anyway).
     2780            if (!wasCreated) {
     2781                if (QMainWindowLayout *mwl = qobject_cast<QMainWindowLayout *>(q->layout())) {
     2782                    mwl->updateHIToolBarStatus();
     2783                }
     2784            }
     2785#else
     2786            // Simply transfer our toolbar over. Everything should stay put, unlike in Carbon.
    27432787            if (oldToolbar && !(f & Qt::FramelessWindowHint)) {
    27442788                OSWindowRef newWindow = qt_mac_window_for(q);
     
    27552799    if (wasCreated) {
    27562800        transferChildren();
     2801#ifndef QT_MAC_USE_COCOA
     2802        // If we were a unified window, We just transfered our toolbars out of the unified toolbar.
     2803        // So redo the status one more time. It apparently is not an issue with Cocoa.
     2804        if (q->isWindow()) {
     2805            if (QMainWindowLayout *mwl = qobject_cast<QMainWindowLayout *>(q->layout())) {
     2806                mwl->updateHIToolBarStatus();
     2807            }
     2808        }
     2809#endif
     2810
    27572811        if (topData &&
    27582812                (!topData->caption.isEmpty() || !topData->filePath.isEmpty()))
     
    28562910void QWidgetPrivate::setCursor_sys(const QCursor &)
    28572911{
     2912#ifndef QT_MAC_USE_COCOA
    28582913    qt_mac_update_cursor();
     2914#else
     2915     Q_Q(QWidget);
     2916    if (q->testAttribute(Qt::WA_WState_Created)) {
     2917        QMacCocoaAutoReleasePool pool;
     2918        [qt_mac_window_for(q) invalidateCursorRectsForView:qt_mac_nativeview_for(q)];
     2919    }
     2920#endif
    28592921}
    28602922
    28612923void QWidgetPrivate::unsetCursor_sys()
    28622924{
     2925#ifndef QT_MAC_USE_COCOA
    28632926    qt_mac_update_cursor();
     2927#else
     2928     Q_Q(QWidget);
     2929    if (q->testAttribute(Qt::WA_WState_Created)) {
     2930        QMacCocoaAutoReleasePool pool;
     2931        [qt_mac_window_for(q) invalidateCursorRectsForView:qt_mac_nativeview_for(q)];
     2932    }
     2933#endif
    28642934}
    28652935
     
    28722942#else
    28732943        QMacCocoaAutoReleasePool pool;
    2874         [qt_mac_window_for(q)
    2875           setTitle:reinterpret_cast<const NSString *>(static_cast<CFStringRef>(QCFString(caption)))];
     2944        [qt_mac_window_for(q) setTitle:qt_mac_QStringToNSString(caption)];
    28762945#endif
    28772946    }
     
    28952964#ifdef QT_MAC_USE_COCOA
    28962965    QMacCocoaAutoReleasePool pool;
    2897     [qt_mac_window_for(q) setRepresentedFilename:reinterpret_cast<const NSString *>(static_cast<CFStringRef>(QCFString(filePath)))];
     2966    QFileInfo fi(filePath);
     2967    [qt_mac_window_for(q) setRepresentedFilename:fi.exists() ? qt_mac_QStringToNSString(filePath) : @""];
    28982968#else
    28992969    bool validRef = false;
     
    29082978    // Set the proxy regardless, since this is our way of clearing it as well, but ignore the
    29092979    // return value as well.
    2910     if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
    2911         if (validRef) {
    2912             status = HIWindowSetProxyFSRef(qt_mac_window_for(q), &ref);
    2913         } else {
    2914             status = RemoveWindowProxy(qt_mac_window_for(q));
    2915         }
     2980    if (validRef) {
     2981        status = HIWindowSetProxyFSRef(qt_mac_window_for(q), &ref);
    29162982    } else {
    2917         // Convert to an FSSpec and set it. It's deprecated but it works for where we don't have the other call.
    2918         if (validRef) {
    2919             FSSpec fsspec;
    2920             FSGetCatalogInfo(&ref, kFSCatInfoNone, 0, 0, &fsspec, 0);
    2921             status = SetWindowProxyFSSpec(qt_mac_window_for(q), &fsspec);
    2922         } else {
    2923             status = RemoveWindowProxy(qt_mac_window_for(q));
    2924         }
     2983        status = RemoveWindowProxy(qt_mac_window_for(q));
    29252984    }
    29262985    if (status != noErr)
     
    29773036        QMacCocoaAutoReleasePool pool;
    29783037        NSButton *iconButton = [qt_mac_window_for(q) standardWindowButton:NSWindowDocumentIconButton];
     3038        if (iconButton == nil) {
     3039            QCFString string(q->windowTitle());
     3040            const NSString *tmpString = reinterpret_cast<const NSString *>((CFStringRef)string);
     3041            [qt_mac_window_for(q) setRepresentedURL:[NSURL fileURLWithPath:tmpString]];
     3042            iconButton = [qt_mac_window_for(q) standardWindowButton:NSWindowDocumentIconButton];
     3043        }
    29793044        if (icon.isNull()) {
    29803045            [iconButton setImage:nil];
    29813046        } else {
    2982             NSImage *image = static_cast<NSImage *>(qt_mac_create_nsimage(*pm));
     3047            QPixmap scaled = pm->scaled(QSize(16,16), Qt::KeepAspectRatio, Qt::SmoothTransformation);
     3048            NSImage *image = static_cast<NSImage *>(qt_mac_create_nsimage(scaled));
    29833049            [iconButton setImage:image];
    29843050            [image release];
     
    29963062#else
    29973063        QMacCocoaAutoReleasePool pool;
    2998         [qt_mac_window_for(q)
    2999             setMiniwindowTitle:reinterpret_cast<const NSString *>(static_cast<CFStringRef>(QCFString(iconText)))];
     3064        [qt_mac_window_for(q) setMiniwindowTitle:qt_mac_QStringToNSString(iconText)];
    30003065#endif
    30013066    }
     
    30113076}
    30123077
     3078#ifndef QT_NO_CURSOR
    30133079void QWidget::grabMouse(const QCursor &)
    30143080{
     
    30193085    }
    30203086}
     3087#endif
    30213088
    30223089void QWidget::releaseMouse()
     
    31303197            return;
    31313198#ifndef QT_MAC_USE_COCOA
    3132 #    if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
    3133         if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
    3134             dirtyOnWidget += updateRect;
    3135             HIRect r = CGRectMake(x, y, w, h);
    3136             HIViewSetNeedsDisplayInRect(qt_mac_nativeview_for(q), &r, true);
    3137         } else
    3138     #endif
    3139         {
    3140             q->update(QRegion(updateRect));
    3141         }
     3199        dirtyOnWidget += updateRect;
     3200        HIRect r = CGRectMake(x, y, w, h);
     3201        HIViewSetNeedsDisplayInRect(qt_mac_nativeview_for(q), &r, true);
    31423202#else
    31433203        [qt_mac_nativeview_for(q) setNeedsDisplayInRect:NSMakeRect(x, y, w, h)];
     
    31533213    dirtyOnWidget += rgn;
    31543214#ifndef QT_MAC_USE_COCOA
    3155     HIViewSetNeedsDisplayInRegion(qt_mac_nativeview_for(q), QMacSmartQuickDrawRegion(rgn.toQDRgn()), true);
     3215    RgnHandle rgnHandle = rgn.toQDRgnForUpdate_sys();
     3216    if (rgnHandle)
     3217        HIViewSetNeedsDisplayInRegion(qt_mac_nativeview_for(q), QMacSmartQuickDrawRegion(rgnHandle), true);
     3218    else {
     3219        HIViewSetNeedsDisplay(qt_mac_nativeview_for(q), true); // do a complete repaint on overflow.
     3220    }
    31563221#else
    31573222    // 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.
     
    32243289        SizeWindow(window, q->width(), q->height(), true);
    32253290#endif
     3291
     3292#ifdef QT_MAC_USE_COCOA
     3293        // Make sure that we end up sending a repaint event to
     3294        // the widget if the window has been visible one before:
     3295        [qt_mac_get_contentview_for(window) setNeedsDisplay:YES];
     3296#endif
    32263297        if(qt_mac_is_macsheet(q)) {
    32273298            qt_event_request_showsheet(q);
     
    32393310            // sync the opacity value back (in case of a fade).
    32403311            [window setAlphaValue:q->windowOpacity()];
    3241 
    32423312            [window makeKeyAndOrderFront:window];
     3313
     3314            // If this window is app modal, we need to start spinning
     3315            // a modal session for it. Interrupting
     3316            // the event dispatcher will make this happend:
    32433317            if (data.window_modality == Qt::ApplicationModal)
    3244                 QCoreApplication::postEvent(qApp, new QEvent(QEvent::CocoaRequestModal));
     3318                QEventDispatcherMac::instance()->interrupt();
    32453319#endif
    32463320            if (q->windowType() == Qt::Popup) {
     
    32593333#endif
    32603334        } else if (!q->testAttribute(Qt::WA_ShowWithoutActivating)) {
     3335#ifndef QT_MAC_USE_COCOA
    32613336            qt_event_request_activate(q);
    3262 #ifdef QT_MAC_USE_COCOA
    3263             if (q->windowModality() == Qt::ApplicationModal) {
    3264                 // We call 'activeModalSession' early to force creation of q's modal
    3265                 // session. This seems neccessary for child dialogs to pop to front:
    3266                 QEventDispatcherMacPrivate::activeModalSession();
    3267             }
     3337#else
     3338            [qt_mac_window_for(q) makeKeyWindow];
    32683339#endif
    32693340        }
     
    33473418            if(!w || (!w->isVisible() && !w->isMinimized())) {
    33483419#ifndef QT_MAC_USE_COCOA
    3349                 for(WindowPtr wp = GetFrontWindowOfClass(kDocumentWindowClass, true);
    3350                     wp; wp = GetNextWindowOfClass(wp, kDocumentWindowClass, true)) {
     3420                for (WindowPtr wp = GetFrontWindowOfClass(kMovableModalWindowClass, true);
     3421                    wp; wp = GetNextWindowOfClass(wp, kMovableModalWindowClass, true)) {
    33513422                    if((w = qt_mac_find_window(wp)))
    33523423                        break;
     3424                }
     3425                if (!w){
     3426                    for (WindowPtr wp = GetFrontWindowOfClass(kDocumentWindowClass, true);
     3427                            wp; wp = GetNextWindowOfClass(wp, kDocumentWindowClass, true)) {
     3428                        if((w = qt_mac_find_window(wp)))
     3429                            break;
     3430                    }
    33533431                }
    33543432                if (!w){
     
    33693447#endif
    33703448            }
    3371             if(w && w->isVisible() && !w->isMinimized())
    3372                 qt_event_request_activate(w);
     3449            if(w && w->isVisible() && !w->isMinimized()) {
     3450#ifndef QT_MAC_USE_COCOA
     3451            qt_event_request_activate(w);
     3452#else
     3453            [qt_mac_window_for(w) makeKeyWindow];
     3454#endif
     3455            }
    33733456        }
    33743457    } else {
     
    34233506            } else {
    34243507                needShow = isVisible();
     3508                if(!qApp->desktop()->screenNumber(this))
     3509                    qt_mac_set_fullscreen_mode(false);
    34253510                setParent(parentWidget(), d->topData()->savedFlags);
    34263511                setGeometry(d->topData()->normalGeometry);
    3427                 if(!qApp->desktop()->screenNumber(this))
    3428                     qt_mac_set_fullscreen_mode(false);
    34293512                d->topData()->normalGeometry.setRect(0, 0, -1, -1);
    34303513            }
     
    35283611#endif
    35293612                needSendStateChange = oldstate == windowState(); // Zoom didn't change flags.
    3530             } else if(oldstate & Qt::WindowMaximized) {
     3613            } else if(oldstate & Qt::WindowMaximized && !(oldstate & Qt::WindowFullScreen)) {
    35313614#ifndef QT_MAC_USE_COCOA
    35323615                Point idealSize;
     
    35723655}
    35733656
     3657NSComparisonResult compareViews2Raise(id view1, id view2, void *context)
     3658{
     3659    id topView = reinterpret_cast<id>(context);
     3660    if (view1 == topView)
     3661        return NSOrderedDescending;
     3662    if (view2 == topView)
     3663        return NSOrderedAscending;
     3664    return NSOrderedSame;
     3665}
     3666
    35743667void QWidgetPrivate::raise_sys()
    35753668{
     
    35793672
    35803673#if QT_MAC_USE_COCOA
    3581     QMacCocoaAutoReleasePool pool;
    35823674    if (isRealWindow()) {
    35833675        // Calling orderFront shows the window on Cocoa too.
    3584         if (!q->testAttribute(Qt::WA_DontShowOnScreen)) {
     3676        if (!q->testAttribute(Qt::WA_DontShowOnScreen) && q->isVisible()) {
    35853677            [qt_mac_window_for(q) orderFront:qt_mac_window_for(q)];
    35863678        }
     
    35913683        }
    35923684    } else {
    3593         // Cocoa doesn't really have an idea of Z-ordering, but you can
    3594         // fake it by changing the order of it.
    35953685        NSView *view = qt_mac_nativeview_for(q);
    35963686        NSView *parentView = [view superview];
    3597         [view removeFromSuperview];
    3598         [parentView addSubview:view];
     3687        [parentView sortSubviewsUsingFunction:compareViews2Raise context:reinterpret_cast<void *>(view)];
    35993688    }
    36003689#else
     
    36143703}
    36153704
     3705NSComparisonResult compareViews2Lower(id view1, id view2, void *context)
     3706{
     3707    id topView = reinterpret_cast<id>(context);
     3708    if (view1 == topView)
     3709        return NSOrderedAscending;
     3710    if (view2 == topView)
     3711        return NSOrderedDescending;
     3712    return NSOrderedSame;
     3713}
     3714
    36163715void QWidgetPrivate::lower_sys()
    36173716{
     
    36203719        return;
    36213720#ifdef QT_MAC_USE_COCOA
    3622     QMacCocoaAutoReleasePool pool;
    36233721    if (isRealWindow()) {
    36243722        OSWindowRef window = qt_mac_window_for(q);
    36253723        [window orderBack:window];
    36263724    } else {
    3627         // Cocoa doesn't really have an idea of Z-ordering, but you can
    3628         // fake it by changing the order of it. In this case
    3629         // we put the item at the beginning of the list, but that means
    3630         // we must re-insert everything since we cannot modify the list directly.
    3631         NSView *myview = qt_mac_nativeview_for(q);
    3632         NSView *parentView = [myview superview];
    3633         NSArray *tmpViews = [parentView subviews];
    3634         NSMutableArray *subviews = [[NSMutableArray alloc] initWithCapacity:[tmpViews count]];
    3635         [subviews addObjectsFromArray:tmpViews];
    3636         // Implicit assumption that myViewIndex is included in subviews, that's why I'm not checking
    3637         // myViewIndex.
    3638         NSUInteger index = 0;
    3639         NSUInteger myViewIndex = 0;
    3640         bool foundMyView = false;
    3641         for (NSView *subview in subviews) {
    3642             [subview removeFromSuperview];
    3643             if (subview == myview) {
    3644                 foundMyView = true;
    3645                 myViewIndex = index;
    3646             }
    3647             ++index;
    3648         }
    3649         [parentView addSubview:myview];
    3650         if (foundMyView)
    3651             [subviews removeObjectAtIndex:myViewIndex];
    3652         for (NSView *subview in subviews)
    3653             [parentView addSubview:subview];
    3654         [subviews release];
     3725        NSView *view = qt_mac_nativeview_for(q);
     3726        NSView *parentView = [view superview];
     3727        [parentView sortSubviewsUsingFunction:compareViews2Lower context:reinterpret_cast<void *>(view)];
    36553728    }
    36563729#else
     
    36653738}
    36663739
     3740NSComparisonResult compareViews2StackUnder(id view1, id view2, void *context)
     3741{
     3742    const QHash<NSView *, int> &viewOrder = *reinterpret_cast<QHash<NSView *, int> *>(context);
     3743    if (viewOrder[view1] < viewOrder[view2])
     3744        return NSOrderedAscending;
     3745    if (viewOrder[view1] > viewOrder[view2])
     3746        return NSOrderedDescending;
     3747    return NSOrderedSame;
     3748}
     3749
    36673750void QWidgetPrivate::stackUnder_sys(QWidget *w)
    36683751{
     
    36733756#ifdef QT_MAC_USE_COCOA
    36743757    // Do the same trick as lower_sys() and put this widget before the widget passed in.
    3675     QMacCocoaAutoReleasePool pool;
    3676     NSView *myview = qt_mac_nativeview_for(q);
     3758    NSView *myView = qt_mac_nativeview_for(q);
    36773759    NSView *wView = qt_mac_nativeview_for(w);
    3678     NSView *parentView = [myview superview];
    3679     NSArray *tmpViews = [parentView subviews];
    3680     NSMutableArray *subviews = [[NSMutableArray alloc] initWithCapacity:[tmpViews count]];
    3681     [subviews addObjectsFromArray:tmpViews];
    3682     // Implicit assumption that myViewIndex and wViewIndex is included in subviews,
    3683     // that's why I'm not checking myViewIndex.
    3684     NSUInteger index = 0;
    3685     NSUInteger myViewIndex = 0;
    3686     NSUInteger wViewIndex = 0;
     3760
     3761    QHash<NSView *, int> viewOrder;
     3762    NSView *parentView = [myView superview];
     3763    NSArray *subviews = [parentView subviews];
     3764    NSUInteger index = 1;
     3765    // make a hash of view->zorderindex and make sure z-value is always odd,
     3766    // so that when we modify the order we create a new (even) z-value which
     3767    // will not interfere with others.
    36873768    for (NSView *subview in subviews) {
    3688         [subview removeFromSuperview];
    3689         if (subview == myview)
    3690             myViewIndex = index;
    3691         else if (subview == wView)
    3692             wViewIndex = index;
     3769        viewOrder.insert(subview, index * 2);
    36933770        ++index;
    36943771    }
    3695 
    3696     index = 0;
    3697     for (NSView *subview in subviews) {
    3698         if (index == myViewIndex)
    3699             continue;
    3700         if (index == wViewIndex)
    3701             [parentView addSubview:myview];
    3702         [parentView addSubview:subview];
    3703         ++index;
    3704     }
    3705     [subviews release];
     3772    viewOrder[myView] = viewOrder[wView] - 1;
     3773
     3774    [parentView sortSubviewsUsingFunction:compareViews2StackUnder context:reinterpret_cast<void *>(&viewOrder)];
    37063775#else
    37073776    QWidget *p = q->parentWidget();
     
    37173786    Modifies the bounds for a widgets backing HIView during moves and resizes. Also updates the
    37183787    widget, either by scrolling its contents or repainting, depending on the WA_StaticContents
    3719     and QWidgetPrivate::isOpaque flags.
     3788    flag
    37203789*/
    37213790static void qt_mac_update_widget_posisiton(QWidget *q, QRect oldRect, QRect newRect)
     
    37343803    // Perform a normal (complete repaint) update in some cases:
    37353804    if (
    3736         // move-by-scroll requires QWidgetPrivate::isOpaque set
    3737         (isMove && qd->isOpaque == false) ||
     3805        // always repaint on move.
     3806        (isMove) ||
    37383807
    37393808        // limited update on resize requires WA_StaticContents.
     
    37443813
    37453814        // the position update is a part of a drag-and-drop operation
    3746         QDragManager::self()->object
     3815        QDragManager::self()->object ||
     3816       
     3817        // we are on Panther (no HIViewSetNeedsDisplayInRect)
     3818        QSysInfo::MacintoshVersion < QSysInfo::MV_10_4
    37473819    ){
    37483820        HIViewSetFrame(view, &bounds);
     
    38453917      X coordinate system for parent (relative to parent's wrect).
    38463918    */
    3847     QRect validRange(-XCOORD_MAX,-XCOORD_MAX, 2*XCOORD_MAX, 2*XCOORD_MAX);
    3848     QRect wrectRange(-WRECT_MAX,-WRECT_MAX, 2*WRECT_MAX, 2*WRECT_MAX);
    38493919    QRect wrect;
    38503920    //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)
     
    38683938                                tmpRect.size.width, tmpRect.size.height);
    38693939        } else {
     3940            const QRect wrectRange(-WRECT_MAX,-WRECT_MAX, 2*WRECT_MAX, 2*WRECT_MAX);
    38703941            parentWRect = wrectRange;
    38713942        }
     
    39233994        }
    39243995
     3996        const QRect validRange(-XCOORD_MAX,-XCOORD_MAX, 2*XCOORD_MAX, 2*XCOORD_MAX);
    39253997        if (!validRange.contains(xrect)) {
    39263998            // we are too big, and must clip
    3927             xrect &=wrectRange;
     3999            QPoint screenOffset(0, 0); // offset of the part being on screen
     4000            const QWidget *parentWidget = q->parentWidget();
     4001            while (parentWidget && !parentWidget->isWindow()) {
     4002                screenOffset -= parentWidget->data->crect.topLeft();
     4003                parentWidget = parentWidget->parentWidget();
     4004            }
     4005            QRect cropRect(screenOffset.x() - WRECT_MAX,
     4006                           screenOffset.y() - WRECT_MAX,
     4007                           2*WRECT_MAX,
     4008                           2*WRECT_MAX);
     4009
     4010            xrect &=cropRect;
    39284011            wrect = xrect;
    3929             wrect.translate(-data.crect.topLeft());
    3930             //parent's X coord system is equal to parent's Qt coord
    3931             //sys, so we don't need to map xrect.
    3932         }
    3933 
     4012            wrect.translate(-data.crect.topLeft()); // translate wrect in my Qt coordinates
     4013        }
    39344014    }
    39354015
     
    39714051    qt_mac_update_widget_posisiton(q, oldRect, xrect);
    39724052
    3973     if  (jump) {
    3974         updateSystemBackground();
     4053    if  (jump)
    39754054        q->update();
    3976     }
     4055
    39774056    if (mapWindow && !dontShow) {
    39784057        q->setAttribute(Qt::WA_Mapped);
     
    39854064}
    39864065
     4066void QWidgetPrivate::adjustWithinMaxAndMinSize(int &w, int &h)
     4067{
     4068    if (QWExtra *extra = extraData()) {
     4069        w = qMin(w, extra->maxw);
     4070        h = qMin(h, extra->maxh);
     4071        w = qMax(w, extra->minw);
     4072        h = qMax(h, extra->minh);
     4073
     4074        // Deal with size increment
     4075        if (QTLWExtra *top = topData()) {
     4076            if(top->incw) {
     4077                w = w/top->incw;
     4078                w *= top->incw;
     4079            }
     4080            if(top->inch) {
     4081                h = h/top->inch;
     4082                h *= top->inch;
     4083            }
     4084        }
     4085    }
     4086
     4087    if (isRealWindow()) {
     4088        w = qMax(0, w);
     4089        h = qMax(0, h);
     4090    }
     4091}
     4092
     4093void QWidgetPrivate::applyMaxAndMinSizeOnWindow()
     4094{
     4095    Q_Q(QWidget);
     4096    const float max_f(20000);
     4097#ifndef QT_MAC_USE_COCOA
     4098#define SF(x) ((x > max_f) ? max_f : x)
     4099    HISize max = CGSizeMake(SF(extra->maxw), SF(extra->maxh));
     4100    HISize min = CGSizeMake(SF(extra->minw), SF(extra->minh));
     4101#undef SF
     4102    SetWindowResizeLimits(qt_mac_window_for(q), &min, &max);
     4103#else
     4104#define SF(x) ((x > max_f) ? max_f : x)
     4105    NSSize max = NSMakeSize(SF(extra->maxw), SF(extra->maxh));
     4106    NSSize min = NSMakeSize(SF(extra->minw), SF(extra->minh));
     4107#undef SF
     4108    [qt_mac_window_for(q) setContentMinSize:min];
     4109    [qt_mac_window_for(q) setContentMaxSize:max];
     4110#endif
     4111}
     4112
    39874113void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove)
    39884114{
     
    39954121    QMacCocoaAutoReleasePool pool;
    39964122    bool realWindow = isRealWindow();
    3997     if (realWindow && !(w == 0 && h == 0) && !q->testAttribute(Qt::WA_DontShowOnScreen)) {
    3998         topData()->isSetGeometry = 1;
    3999         topData()->isMove = isMove;
    4000 #ifndef QT_MAC_USE_COCOA
    4001         Rect r; SetRect(&r, x, y, x + w, y + h);
    4002         SetWindowBounds(qt_mac_window_for(q), kWindowContentRgn, &r);
    4003 #else
     4123
     4124    if (realWindow && !q->testAttribute(Qt::WA_DontShowOnScreen)){
     4125        adjustWithinMaxAndMinSize(w, h);
     4126#ifndef QT_MAC_USE_COCOA
     4127        if (w != 0 && h != 0) {
     4128            topData()->isSetGeometry = 1;
     4129            topData()->isMove = isMove;
     4130            Rect r; SetRect(&r, x, y, x + w, y + h);
     4131            SetWindowBounds(qt_mac_window_for(q), kWindowContentRgn, &r);
     4132            topData()->isSetGeometry = 0;
     4133        } else {
     4134            setGeometry_sys_helper(x, y, w, h, isMove);
     4135        }
     4136#else
     4137        QSize  olds = q->size();
     4138        const bool isResize = (olds != QSize(w, h));
    40044139        NSWindow *window = qt_mac_window_for(q);
    40054140        const QRect &fStrut = frameStrut();
     
    40094144        NSRect cocoaFrameRect = NSMakeRect(frameRect.x(), flipYCoordinate(frameRect.bottom() + 1),
    40104145                                           frameRect.width(), frameRect.height());
    4011         [window setFrame:cocoaFrameRect display:NO];
    4012 #endif
    4013         topData()->isSetGeometry = 0;
     4146        // The setFrame call will trigger a 'windowDidResize' notification for the corresponding
     4147        // NSWindow. The pending flag is set, so that the resize event can be send as non-spontaneous.
     4148        if (isResize)
     4149            q->setAttribute(Qt::WA_PendingResizeEvent);
     4150        QPoint currTopLeft = data.crect.topLeft();
     4151        if (currTopLeft.x() == x && currTopLeft.y() == y
     4152                && cocoaFrameRect.size.width != 0
     4153                && cocoaFrameRect.size.height != 0) {
     4154            [window setFrame:cocoaFrameRect display:NO];
     4155        } else {
     4156            // The window is moved and resized (or resized to zero).
     4157            // Since Cocoa usually only sends us a resize callback after
     4158            // setting a window frame, we issue an explicit move as
     4159            // well. To stop Cocoa from optimize away the move (since the move
     4160            // would have the same origin as the setFrame call) we shift the
     4161            // window back and forth inbetween.
     4162            cocoaFrameRect.origin.y += 1;
     4163            [window setFrame:cocoaFrameRect display:NO];
     4164            cocoaFrameRect.origin.y -= 1;
     4165            [window setFrameOrigin:cocoaFrameRect.origin];
     4166        }
     4167#endif
    40144168    } else {
    40154169        setGeometry_sys_helper(x, y, w, h, isMove);
     
    40214175    Q_Q(QWidget);
    40224176    bool realWindow = isRealWindow();
    4023     if(QWExtra *extra = extraData()) {        // any size restrictions?
    4024         if(realWindow) {
    4025             qt_mac_update_sizer(q);
    4026             if(q->windowFlags() & Qt::WindowMaximizeButtonHint) {
    4027 #ifndef QT_MAC_USE_COCOA
    4028                 OSWindowRef window = qt_mac_window_for(q);
    4029                 if(extra->maxw && extra->maxh && extra->maxw == extra->minw
    4030                         && extra->maxh == extra->minh) {
    4031                     ChangeWindowAttributes(window, kWindowNoAttributes, kWindowFullZoomAttribute);
    4032                 } else {
    4033                     ChangeWindowAttributes(window, kWindowFullZoomAttribute, kWindowNoAttributes);
    4034                 }
    4035 #endif
    4036             }
    4037         }
    4038 
    4039         w = qMin(w,extra->maxw);
    4040         h = qMin(h,extra->maxh);
    4041         w = qMax(w,extra->minw);
    4042         h = qMax(h,extra->minh);
    4043 
    4044         // Deal with size increment
    4045         if(QTLWExtra *top = topData()) {
    4046             if(top->incw) {
    4047                 w = w/top->incw;
    4048                 w *= top->incw;
    4049             }
    4050             if(top->inch) {
    4051                 h = h/top->inch;
    4052                 h *= top->inch;
    4053             }
    4054         }
    4055     }
    4056 
    4057     if (realWindow) {
    4058         w = qMax(0, w);
    4059         h = qMax(0, h);
    4060     }
    40614177
    40624178    QPoint oldp = q->pos();
    40634179    QSize  olds = q->size();
    40644180    const bool isResize = (olds != QSize(w, h));
    4065     if(!realWindow && !isResize && QPoint(x, y) == oldp)
     4181
     4182    if (!realWindow && !isResize && QPoint(x, y) == oldp)
    40664183        return;
    4067     if(isResize && q->isMaximized())
     4184
     4185    if (isResize)
    40684186        data.window_state = data.window_state & ~Qt::WindowMaximized;
     4187
    40694188    const bool visible = q->isVisible();
    40704189    data.crect = QRect(x, y, w, h);
    40714190
    4072     if(realWindow) {
    4073         if(QWExtra *extra = extraData()) { //set constraints
    4074             const float max_f(20000);
    4075 #ifndef QT_MAC_USE_COCOA
    4076 #define SF(x) ((x > max_f) ? max_f : x)
    4077             HISize max = CGSizeMake(SF(extra->maxw), SF(extra->maxh));
    4078             HISize min = CGSizeMake(SF(extra->minw), SF(extra->minh));
    4079 #undef SF
    4080             SetWindowResizeLimits(qt_mac_window_for(q), &min, &max);
    4081 #else
    4082 #define SF(x) ((x > max_f) ? max_f : x)
    4083             NSSize max = NSMakeSize(SF(extra->maxw), SF(extra->maxh));
    4084             NSSize min = NSMakeSize(SF(extra->minw), SF(extra->minh));
    4085 #undef SF
    4086             [qt_mac_window_for(q) setMinSize:min];
    4087             [qt_mac_window_for(q) setMaxSize:max];
    4088 #endif
    4089         }
    4090 #ifndef QT_MAC_USE_COCOA
     4191    if (realWindow) {
     4192        adjustWithinMaxAndMinSize(w, h);
     4193        qt_mac_update_sizer(q);
     4194
     4195#ifndef QT_MAC_USE_COCOA
     4196        if (q->windowFlags() & Qt::WindowMaximizeButtonHint) {
     4197            OSWindowRef window = qt_mac_window_for(q);
     4198            if (extra->maxw && extra->maxh && extra->maxw == extra->minw
     4199                    && extra->maxh == extra->minh) {
     4200                ChangeWindowAttributes(window, kWindowNoAttributes, kWindowFullZoomAttribute);
     4201            } else {
     4202                ChangeWindowAttributes(window, kWindowFullZoomAttribute, kWindowNoAttributes);
     4203            }
     4204        }
    40914205        HIRect bounds = CGRectMake(0, 0, w, h);
    40924206        HIViewSetFrame(qt_mac_nativeview_for(q), &bounds);
     
    41014215        if (isResize && QApplicationPrivate::graphicsSystem()) {
    41024216            invalidateBuffer(q->rect());
    4103             if (extra && !extra->mask.isEmpty()) {
     4217            if (extra && !graphicsEffect && !extra->mask.isEmpty()) {
    41044218                QRegion oldRegion(extra->mask.translated(oldp));
    41054219                oldRegion &= oldRect;
    41064220                q->parentWidget()->d_func()->invalidateBuffer(oldRegion);
    41074221            } else {
    4108                 q->parentWidget()->d_func()->invalidateBuffer(oldRect);
     4222                q->parentWidget()->d_func()->invalidateBuffer(effectiveRectFor(oldRect));
    41094223            }
    41104224        }
     
    41344248{
    41354249    updateMaximizeButton_sys();
     4250    applyMaxAndMinSizeOnWindow();
    41364251}
    41374252
     
    42284343                                                   w->data->crect.width(), w->data->crect.height());
    42294344                        HIViewRef hiview = qt_mac_nativeview_for(w);
    4230                         const bool opaque = qt_widget_private(w)->isOpaque;
     4345                        const bool opaque = q->testAttribute(Qt::WA_OpaquePaintEvent);
    42314346
    42324347                        if (opaque)
     
    42594374#ifndef QT_MAC_USE_COCOA
    42604375    HIRect scrollrect = CGRectMake(r.x(), r.y(), r.width(), r.height());
    4261 #  if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
    4262    if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
    4263        OSStatus err = _HIViewScrollRectWithOptions(view, valid_rect ? &scrollrect : 0, dx, dy, kHIViewScrollRectAdjustInvalid);
    4264        if (err) {
    4265            // The only parameter that can go wrong, is the rect.
    4266            qWarning("QWidget::scroll: Your rectangle was too big for the widget, clipping rect");
    4267            scrollrect = CGRectMake(qMax(r.x(), 0), qMax(r.y(), 0),
    4268                                    qMin(r.width(), q->width()), qMin(r.height(), q->height()));
    4269            _HIViewScrollRectWithOptions(view, valid_rect ? &scrollrect : 0, dx, dy, kHIViewScrollRectAdjustInvalid);
    4270        }
    4271    } else {
    4272        if (HIViewGetNeedsDisplay(view)) {
    4273            q->update(valid_rect ? r : q->rect());
    4274            return;
    4275        }
    4276        HIRect scrollrect = CGRectMake(r.x(), r.y(), r.width(), r.height());
    4277        OSStatus err = HIViewScrollRect(view, valid_rect ? &scrollrect : 0, dx, dy);
    4278        if (err) {
    4279            // The only parameter that can go wrong, is the rect.
    4280            qWarning("QWidget::scroll: Your rectangle was too big for the widget, clipping rect");
    4281            scrollrect = CGRectMake(qMax(r.x(), 0), qMax(r.y(), 0),
    4282                    qMin(r.width(), q->width()), qMin(r.height(), q->height()));
    4283            HIViewScrollRect(view, valid_rect ? &scrollrect : 0, dx, dy);
    4284        }
     4376   OSStatus err = _HIViewScrollRectWithOptions(view, valid_rect ? &scrollrect : 0, dx, dy, kHIViewScrollRectAdjustInvalid);
     4377   if (err) {
     4378       // The only parameter that can go wrong, is the rect.
     4379       qWarning("QWidget::scroll: Your rectangle was too big for the widget, clipping rect");
     4380       scrollrect = CGRectMake(qMax(r.x(), 0), qMax(r.y(), 0),
     4381                               qMin(r.width(), q->width()), qMin(r.height(), q->height()));
     4382       _HIViewScrollRectWithOptions(view, valid_rect ? &scrollrect : 0, dx, dy, kHIViewScrollRectAdjustInvalid);
    42854383   }
    4286 #  endif
    42874384#else
    42884385    NSRect scrollRect = valid_rect ? NSMakeRect(r.x(), r.y(), r.width(), r.height())
     
    43124409    }
    43134410
    4314     // ### Scroll the dirty regions as well, the following is not correct.
    4315     QRegion displayRegion = r.isNull() ? dirtyOnWidget : (dirtyOnWidget & r);
    4316     const QVector<QRect> &rects = dirtyOnWidget.rects();
    4317     const QVector<QRect>::const_iterator end = rects.end();
    4318     QVector<QRect>::const_iterator it = rects.begin();
    4319     while (it != end) {
    4320          const QRect rect = *it;
    4321          const NSRect dirtyRect = NSMakeRect(rect.x() + dx, rect.y() + dy,
    4322                                              rect.width(), rect.height());
    4323          [view setNeedsDisplayInRect:dirtyRect];
    4324          ++it;
    4325     }
    4326     [view scrollRect:scrollRect by:NSMakeSize(dx, dy)];
    4327     // Yes, we potentially send a duplicate area, but I think Cocoa can handle it.
     4411    NSSize deltaSize = NSMakeSize(dx, dy);
     4412    [view translateRectsNeedingDisplayInRect:scrollRect by:deltaSize];
     4413    [view scrollRect:scrollRect by:deltaSize];
    43284414    [view setNeedsDisplayInRect:deltaXRect];
    43294415    [view setNeedsDisplayInRect:deltaYRect];
     
    43954481void QWidgetPrivate::createTLSysExtra()
    43964482{
     4483    extra->topextra->resizer = 0;
     4484    extra->topextra->isSetGeometry = 0;
     4485    extra->topextra->isMove = 0;
     4486    extra->topextra->wattr = 0;
    43974487    extra->topextra->wclass = 0;
    43984488    extra->topextra->group = 0;
    43994489    extra->topextra->windowIcon = 0;
    4400     extra->topextra->resizer = 0;
    4401     extra->topextra->isSetGeometry = 0;
    44024490    extra->topextra->savedWindowAttributesFromMaximized = 0;
    44034491}
     
    44064494{
    44074495#ifndef QT_MAC_USE_COCOA
    4408     if(extra->topextra->group) {
     4496    if (extra->topextra->group) {
    44094497        qt_mac_release_window_group(extra->topextra->group);
    44104498        extra->topextra->group = 0;
     4499    }
     4500    if (extra->topextra->windowIcon) {
     4501        ReleaseIconRef(extra->topextra->windowIcon);
     4502        extra->topextra->windowIcon = 0;
    44114503    }
    44124504#endif
     
    44484540#else
    44494541    NSView *view = qt_mac_nativeview_for(q);
    4450     if ([view isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaView) class]]) {
    4451         [static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(view) registerDragTypes:on];
    4452     }
     4542    if (on && [view isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaView) class]]) {
     4543        [static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(view) registerDragTypes];
     4544    }
     4545#endif
     4546}
     4547
     4548void QWidgetPrivate::registerTouchWindow()
     4549{
     4550#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
     4551    if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_6)
     4552        return;
     4553    Q_Q(QWidget);
     4554    if (!q->testAttribute(Qt::WA_WState_Created))
     4555        return;
     4556#ifndef QT_MAC_USE_COCOA
     4557    // Needs implementation!
     4558#else
     4559    NSView *view = qt_mac_nativeview_for(q);
     4560    [view setAcceptsTouchEvents:YES];
     4561#endif
    44534562#endif
    44544563}
     
    44744583}
    44754584
    4476 extern "C" {
    4477     typedef struct CGSConnection *CGSConnectionRef;
    4478     typedef struct CGSWindow *CGSWindowRef;
    4479     extern OSStatus CGSSetWindowAlpha(CGSConnectionRef, CGSWindowRef, float);
    4480     extern CGSWindowRef GetNativeWindowFromWindowRef(WindowRef);
    4481     extern CGSConnectionRef _CGSDefaultConnection();
    4482 }
    4483 
    44844585void QWidgetPrivate::setWindowOpacity_sys(qreal level)
    44854586{
     
    44944595        return;
    44954596
     4597    OSWindowRef oswindow = qt_mac_window_for(q);
    44964598#if QT_MAC_USE_COCOA
    4497     OSWindowRef oswindow = qt_mac_window_for(q);
    44984599    [oswindow setAlphaValue:level];
    44994600#else
    4500     CGSSetWindowAlpha(_CGSDefaultConnection(),
    4501                       GetNativeWindowFromWindowRef(qt_mac_window_for(q)), level);
     4601    SetWindowAlpha(oswindow, level);
    45024602#endif
    45034603}
     
    45714671{
    45724672    QPaintEngine *&pe = engineHandler()->engine;
    4573 #ifdef QT_RASTER_PAINTENGINE
    4574     if (!pe) {
    4575         if(qgetenv("QT_MAC_USE_COREGRAPHICS").isNull())
    4576             pe = new QRasterPaintEngine();
    4577         else
    4578             pe = new QCoreGraphicsPaintEngine();
    4579     }
    4580     if (pe->isActive()) {
    4581         QPaintEngine *engine =
    4582             qgetenv("QT_MAC_USE_COREGRAPHICS").isNull()
    4583             ? (QPaintEngine*)new QRasterPaintEngine() : (QPaintEngine*)new QCoreGraphicsPaintEngine();
    4584         engine->setAutoDestruct(true);
    4585         return engine;
    4586     }
    4587 #else
    45884673    if (!pe)
    45894674        pe = new QCoreGraphicsPaintEngine();
     
    45934678        return engine;
    45944679    }
    4595 #endif
    45964680    return pe;
    45974681}
     
    46074691
    46084692#ifdef QT_MAC_USE_COCOA
     4693    QMacCocoaAutoReleasePool pool;
    46094694    bool alreadySheet = [windowRef styleMask] & NSDocModalWindowMask;
    46104695
     
    46834768            // Window should be window-modal (which implies a sheet).
    46844769            if (old_wclass != kSheetWindowClass){
    4685                 // We cannot convert a created window to a sheet. So we recreate the window:
     4770                // We cannot convert a created window to a sheet.
     4771                // So we recreate the window:
    46864772                recreateMacWindow();
    46874773                return;
    46884774            }
    4689         } else if (!(q->data->window_flags & Qt::CustomizeWindowHint)) {
    4690             if (old_wclass == kDocumentWindowClass || old_wclass == kFloatingWindowClass || old_wclass == kUtilityWindowClass){
    4691                 // Only change the class to kMovableModalWindowClass if the no explicit jewels
    4692                 // are set (kMovableModalWindowClass can't contain them), and the current window class
    4693                 // can be converted to modal (according to carbon doc). Mind the order of
    4694                 // HIWindowChangeClass and ChangeWindowAttributes.
    4695                 WindowGroupRef group = GetWindowGroup(windowRef);
    4696                 HIWindowChangeClass(windowRef, kMovableModalWindowClass);
    4697                 quint32 tmpWattr = kWindowCloseBoxAttribute | kWindowHorizontalZoomAttribute;
    4698                 ChangeWindowAttributes(windowRef, tmpWattr, kWindowNoAttributes);
    4699                 ChangeWindowAttributes(windowRef, kWindowNoAttributes, tmpWattr);
    4700                 // If the window belongs to a qt-created group, set that group once more:
    4701                 if (data.window_flags & Qt::WindowStaysOnTopHint
    4702                         || q->windowType() == Qt::Popup
    4703                         || q->windowType() == Qt::ToolTip)
    4704                     SetWindowGroup(windowRef, group);
    4705             }
    4706             // Popups are usually handled "special" and are never modal.
    4707             Qt::WindowType winType = q->windowType();
    4708             if (winType != Qt::Popup && winType != Qt::ToolTip)
    4709                 SetWindowModality(windowRef, kWindowModalityAppModal, 0);
     4775        } else {
     4776            // Window should be application-modal (which implies NOT using a sheet).
     4777            if (old_wclass == kSheetWindowClass){
     4778                // We cannot convert a sheet to a window.
     4779                // So we recreate the window:
     4780                recreateMacWindow();
     4781                return;
     4782            } else if (!(q->data->window_flags & Qt::CustomizeWindowHint)) {
     4783                if (old_wclass == kDocumentWindowClass || old_wclass == kFloatingWindowClass || old_wclass == kUtilityWindowClass){
     4784                    // Only change the class to kMovableModalWindowClass if the no explicit jewels
     4785                    // are set (kMovableModalWindowClass can't contain them), and the current window class
     4786                    // can be converted to modal (according to carbon doc). Mind the order of
     4787                    // HIWindowChangeClass and ChangeWindowAttributes.
     4788                    WindowGroupRef group = GetWindowGroup(windowRef);
     4789                    HIWindowChangeClass(windowRef, kMovableModalWindowClass);
     4790                    quint32 tmpWattr = kWindowCloseBoxAttribute | kWindowHorizontalZoomAttribute;
     4791                    ChangeWindowAttributes(windowRef, tmpWattr, kWindowNoAttributes);
     4792                    ChangeWindowAttributes(windowRef, kWindowNoAttributes, tmpWattr);
     4793                    // If the window belongs to a qt-created group, set that group once more:
     4794                    if (data.window_flags & Qt::WindowStaysOnTopHint
     4795                            || q->windowType() == Qt::Popup
     4796                            || q->windowType() == Qt::ToolTip)
     4797                        SetWindowGroup(windowRef, group);
     4798                }
     4799                // Popups are usually handled "special" and are never modal.
     4800                Qt::WindowType winType = q->windowType();
     4801                if (winType != Qt::Popup && winType != Qt::ToolTip)
     4802                    SetWindowModality(windowRef, kWindowModalityAppModal, 0);
     4803            }
    47104804        }
    47114805    } else if (windowRef) {
     
    48434937                layout->updateHIToolBarStatus();
    48444938            ChangeWindowAttributes(qt_mac_window_for(q), kWindowMetalAttribute, 0);
    4845             if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4)
    4846                 ChangeWindowAttributes(qt_mac_window_for(q), kWindowMetalNoContentSeparatorAttribute, 0);
     4939            ChangeWindowAttributes(qt_mac_window_for(q), kWindowMetalNoContentSeparatorAttribute, 0);
    48474940        } else {
    4848             if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4)
    4849                 ChangeWindowAttributes(qt_mac_window_for(q), 0, kWindowMetalNoContentSeparatorAttribute);
     4941            ChangeWindowAttributes(qt_mac_window_for(q), 0, kWindowMetalNoContentSeparatorAttribute);
    48504942            ChangeWindowAttributes(qt_mac_window_for(q), 0, kWindowMetalAttribute);
    48514943            if (layout)
Note: See TracChangeset for help on using the changeset viewer.