src/gui/kernel/qwidget_mac.mm
changeset 18 2f34d5167611
parent 3 41300fa6a67c
child 19 fcece45ef507
equal deleted inserted replaced
3:41300fa6a67c 18:2f34d5167611
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     8 **
     8 **
   108 
   108 
   109 #include "qwidget_p.h"
   109 #include "qwidget_p.h"
   110 #include "qevent_p.h"
   110 #include "qevent_p.h"
   111 #include "qdnd_p.h"
   111 #include "qdnd_p.h"
   112 #include <QtGui/qgraphicsproxywidget.h>
   112 #include <QtGui/qgraphicsproxywidget.h>
       
   113 #include "qmainwindow.h"
   113 
   114 
   114 QT_BEGIN_NAMESPACE
   115 QT_BEGIN_NAMESPACE
   115 
   116 
   116 #define XCOORD_MAX 16383
   117 #define XCOORD_MAX 16383
   117 #define WRECT_MAX 8191
   118 #define WRECT_MAX 8191
   401     extern bool qt_mac_app_fullscreen; //qapplication_mac.mm
   402     extern bool qt_mac_app_fullscreen; //qapplication_mac.mm
   402     if(qt_mac_app_fullscreen == b)
   403     if(qt_mac_app_fullscreen == b)
   403         return;
   404         return;
   404     qt_mac_app_fullscreen = b;
   405     qt_mac_app_fullscreen = b;
   405     if (b) {
   406     if (b) {
   406         SetSystemUIMode(kUIModeAllSuppressed, 0);
   407         SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar);
   407     } else {
   408     } else {
   408         SetSystemUIMode(kUIModeNormal, 0);
   409         SetSystemUIMode(kUIModeNormal, 0);
   409     }
   410     }
   410 }
   411 }
   411 
   412 
   559     // In Qt, a popup is seen as a 'stay on top' window.
   560     // In Qt, a popup is seen as a 'stay on top' window.
   560     // Since new groups are created for 'stays on top' windows, the
   561     // Since new groups are created for 'stays on top' windows, the
   561     // same must be done for popups. Otherwise, popups would be drawn
   562     // same must be done for popups. Otherwise, popups would be drawn
   562     // below 'stays on top' windows. Add 1 to get above pure stay-on-top windows.
   563     // below 'stays on top' windows. Add 1 to get above pure stay-on-top windows.
   563     qt_mac_set_window_group(window, Qt::Popup, qt_mac_get_group_level(kOverlayWindowClass)+1);
   564     qt_mac_set_window_group(window, Qt::Popup, qt_mac_get_group_level(kOverlayWindowClass)+1);
       
   565 }
       
   566 #endif
       
   567 
       
   568 #ifdef QT_MAC_USE_COCOA
       
   569 void qt_mac_set_needs_display(QWidget *widget, QRegion region)
       
   570 {
       
   571     NSView *theNSView = qt_mac_nativeview_for(widget);
       
   572     if (region.isEmpty()) {
       
   573         [theNSView setNeedsDisplay:YES];
       
   574         return;
       
   575     }
       
   576 
       
   577     QVector<QRect> rects = region.rects();
       
   578     for (int i = 0; i<rects.count(); ++i) {
       
   579         const QRect &rect = rects.at(i);
       
   580         NSRect nsrect = NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height());
       
   581         [theNSView setNeedsDisplayInRect:nsrect];
       
   582     }
       
   583 
   564 }
   584 }
   565 #endif
   585 #endif
   566 
   586 
   567 inline static bool updateRedirectedToGraphicsProxyWidget(QWidget *widget, const QRect &rect)
   587 inline static bool updateRedirectedToGraphicsProxyWidget(QWidget *widget, const QRect &rect)
   568 {
   588 {
  1719   QWidget member functions
  1739   QWidget member functions
  1720  *****************************************************************************/
  1740  *****************************************************************************/
  1721 void QWidgetPrivate::determineWindowClass()
  1741 void QWidgetPrivate::determineWindowClass()
  1722 {
  1742 {
  1723     Q_Q(QWidget);
  1743     Q_Q(QWidget);
       
  1744 #if !defined(QT_NO_MAINWINDOW) && !defined(QT_NO_TOOLBAR)
       
  1745     // Make sure that QMainWindow has the MacWindowToolBarButtonHint when the
       
  1746     // unifiedTitleAndToolBarOnMac property is ON. This is to avoid reentry of
       
  1747     // setParent() triggered by the QToolBar::event(QEvent::ParentChange).
       
  1748     QMainWindow *mainWindow = qobject_cast<QMainWindow *>(q);
       
  1749     if (mainWindow && mainWindow->unifiedTitleAndToolBarOnMac()) {
       
  1750         data.window_flags |= Qt::MacWindowToolBarButtonHint;
       
  1751     }
       
  1752 #endif
  1724 #ifndef QT_MAC_USE_COCOA
  1753 #ifndef QT_MAC_USE_COCOA
  1725 // ### COCOA:Interleave these better!
  1754 // ### COCOA:Interleave these better!
  1726 
  1755 
  1727     const Qt::WindowType type = q->windowType();
  1756     const Qt::WindowType type = q->windowType();
  1728     Qt::WindowFlags &flags = data.window_flags;
  1757     Qt::WindowFlags &flags = data.window_flags;
  2741         if (qt_mac_is_macdrawer(q)) {
  2770         if (qt_mac_is_macdrawer(q)) {
  2742             oldDrawer = qt_mac_drawer_for(q);
  2771             oldDrawer = qt_mac_drawer_for(q);
  2743         }
  2772         }
  2744         if (wasWindow) {
  2773         if (wasWindow) {
  2745             oldToolbar = [oldWindow toolbar];
  2774             oldToolbar = [oldWindow toolbar];
       
  2775             [oldToolbar retain];
  2746             oldToolbarVisible = [oldToolbar isVisible];
  2776             oldToolbarVisible = [oldToolbar isVisible];
       
  2777             [oldWindow setToolbar:nil];
  2747         }
  2778         }
  2748 #endif
  2779 #endif
  2749     }
  2780     }
  2750     QWidget* oldtlw = q->window();
  2781     QWidget* oldtlw = q->window();
  2751 
  2782 
  2785 #else
  2816 #else
  2786             // Simply transfer our toolbar over. Everything should stay put, unlike in Carbon.
  2817             // Simply transfer our toolbar over. Everything should stay put, unlike in Carbon.
  2787             if (oldToolbar && !(f & Qt::FramelessWindowHint)) {
  2818             if (oldToolbar && !(f & Qt::FramelessWindowHint)) {
  2788                 OSWindowRef newWindow = qt_mac_window_for(q);
  2819                 OSWindowRef newWindow = qt_mac_window_for(q);
  2789                 [newWindow setToolbar:oldToolbar];
  2820                 [newWindow setToolbar:oldToolbar];
       
  2821                 [oldToolbar release];
  2790                 [oldToolbar setVisible:oldToolbarVisible];
  2822                 [oldToolbar setVisible:oldToolbarVisible];
  2791             }
  2823             }
  2792 #endif
  2824 #endif
  2793         }
  2825         }
  2794     }
  2826     }
  3399         } else {
  3431         } else {
  3400 #ifndef QT_MAC_USE_COCOA
  3432 #ifndef QT_MAC_USE_COCOA
  3401             ShowHide(window, false);
  3433             ShowHide(window, false);
  3402 #else
  3434 #else
  3403             [window orderOut:window];
  3435             [window orderOut:window];
       
  3436             // Unfortunately it is not as easy as just hiding the window, we need
       
  3437             // to find out if we were in full screen mode. If we were and this is
       
  3438             // the last window in full screen mode then we need to unset the full screen
       
  3439             // mode. If this is not the last visible window in full screen mode then we
       
  3440             // don't change the full screen mode.
       
  3441             if(q->isFullScreen())
       
  3442             {
       
  3443                 bool keepFullScreen = false;
       
  3444                 QWidgetList windowList = qApp->topLevelWidgets();
       
  3445                 int windowCount = windowList.count();
       
  3446                 for(int i = 0; i < windowCount; i++)
       
  3447                 {
       
  3448                     QWidget *w = windowList[i];
       
  3449                     // If it is the same window, we don't need to check :-)
       
  3450                     if(q == w)
       
  3451                         continue;
       
  3452                     // If they are not visible or if they are minimized then
       
  3453                     // we just ignore them.
       
  3454                     if(!w->isVisible() || w->isMinimized())
       
  3455                         continue;
       
  3456                     // Is it full screen?
       
  3457                     // Notice that if there is one window in full screen mode then we
       
  3458                     // cannot switch the full screen mode off, therefore we just abort.
       
  3459                     if(w->isFullScreen()) {
       
  3460                         keepFullScreen = true;
       
  3461                         break;
       
  3462                     }
       
  3463                 }
       
  3464                 // No windows in full screen mode, so let just unset that flag.
       
  3465                 if(!keepFullScreen)
       
  3466                     qt_mac_set_fullscreen_mode(false);
       
  3467             }
  3404 #endif
  3468 #endif
  3405             toggleDrawers(false);
  3469             toggleDrawers(false);
  3406 #ifndef QT_MAC_USE_COCOA
  3470 #ifndef QT_MAC_USE_COCOA
  3407             // Clear modality (because it seems something that we've always done).
  3471             // Clear modality (because it seems something that we've always done).
  3408             if (data.window_modality != Qt::NonModal) {
  3472             if (data.window_modality != Qt::NonModal) {
  3463 #endif
  3527 #endif
  3464     }
  3528     }
  3465 
  3529 
  3466     if (!QWidget::mouseGrabber()){
  3530     if (!QWidget::mouseGrabber()){
  3467         QWidget *enterWidget = QApplication::widgetAt(QCursor::pos());
  3531         QWidget *enterWidget = QApplication::widgetAt(QCursor::pos());
       
  3532         if (enterWidget && enterWidget->data->in_destructor)
       
  3533             enterWidget = 0;
  3468         QApplicationPrivate::dispatchEnterLeave(enterWidget, qt_mouseover);
  3534         QApplicationPrivate::dispatchEnterLeave(enterWidget, qt_mouseover);
  3469         qt_mouseover = enterWidget;
  3535         qt_mouseover = enterWidget;
  3470     }
  3536     }
  3471 
  3537 
  3472     qt_event_request_window_change(q);
  3538     qt_event_request_window_change(q);
  3669     Q_Q(QWidget);
  3735     Q_Q(QWidget);
  3670     if((q->windowType() == Qt::Desktop))
  3736     if((q->windowType() == Qt::Desktop))
  3671         return;
  3737         return;
  3672 
  3738 
  3673 #if QT_MAC_USE_COCOA
  3739 #if QT_MAC_USE_COCOA
       
  3740     QMacCocoaAutoReleasePool pool;
  3674     if (isRealWindow()) {
  3741     if (isRealWindow()) {
  3675         // Calling orderFront shows the window on Cocoa too.
  3742         // Calling orderFront shows the window on Cocoa too.
  3676         if (!q->testAttribute(Qt::WA_DontShowOnScreen) && q->isVisible()) {
  3743         if (!q->testAttribute(Qt::WA_DontShowOnScreen) && q->isVisible()) {
  3677             [qt_mac_window_for(q) orderFront:qt_mac_window_for(q)];
  3744             [qt_mac_window_for(q) orderFront:qt_mac_window_for(q)];
  3678         }
  3745         }
  4491 }
  4558 }
  4492 
  4559 
  4493 void QWidgetPrivate::deleteTLSysExtra()
  4560 void QWidgetPrivate::deleteTLSysExtra()
  4494 {
  4561 {
  4495 #ifndef QT_MAC_USE_COCOA
  4562 #ifndef QT_MAC_USE_COCOA
  4496     if(extra->topextra->group) {
  4563     if (extra->topextra->group) {
  4497         qt_mac_release_window_group(extra->topextra->group);
  4564         qt_mac_release_window_group(extra->topextra->group);
  4498         extra->topextra->group = 0;
  4565         extra->topextra->group = 0;
       
  4566     }
       
  4567     if (extra->topextra->windowIcon) {
       
  4568         ReleaseIconRef(extra->topextra->windowIcon);
       
  4569         extra->topextra->windowIcon = 0;
  4499     }
  4570     }
  4500 #endif
  4571 #endif
  4501 }
  4572 }
  4502 
  4573 
  4503 void QWidgetPrivate::updateFrameStrut()
  4574 void QWidgetPrivate::updateFrameStrut()