Changeset 561 for trunk/src/gui/kernel/qwidget_mac.mm
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/kernel/qwidget_mac.mm
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 73 73 ** 74 74 ****************************************************************************/ 75 //#define QT_RASTER_PAINTENGINE76 75 77 76 #include <private/qt_mac_p.h> … … 84 83 #include "qdesktopwidget.h" 85 84 #include "qevent.h" 85 86 86 #include "qimage.h" 87 87 #include "qlayout.h" 88 88 #include "qmenubar.h" 89 89 #include <private/qbackingstore_p.h> 90 #ifdef QT_RASTER_PAINTENGINE91 # include <private/qpaintengine_raster_p.h>92 #endif93 90 #include <private/qwindowsurface_mac_p.h> 94 91 #include <private/qpaintengine_mac_p.h> … … 111 108 112 109 #include "qwidget_p.h" 110 113 111 #include "qdnd_p.h" 114 112 #include <QtGui/qgraphicsproxywidget.h> … … 123 121 extern "C" { 124 122 extern OSStatus _HIViewScrollRectWithOptions(HIViewRef, const HIRect *, CGFloat, CGFloat, 125 OptionBits) ;123 OptionBits); 126 124 } 127 125 #define kHIViewScrollRectAdjustInvalid 1 … … 304 302 } 305 303 304 305 306 307 308 309 310 311 312 313 306 314 bool qt_mac_set_drawer_preferred_edge(QWidget *w, Qt::DockWidgetArea where) //users of Qt for Mac OS X can use this.. 307 315 { … … 391 399 inline static void qt_mac_set_fullscreen_mode(bool b) 392 400 { 393 extern bool qt_mac_app_fullscreen; //qapplication_mac. cpp401 extern bool qt_mac_app_fullscreen; //qapplication_mac. 394 402 if(qt_mac_app_fullscreen == b) 395 403 return; 396 404 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 { 401 408 SetSystemUIMode(kUIModeNormal, 0); 402 #else 403 if(b) 404 HideMenuBar(); 405 else 406 ShowMenuBar(); 407 #endif 409 } 408 410 } 409 411 … … 512 514 { 513 515 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; 524 519 return group_level; 525 520 } … … 731 726 } 732 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 733 745 // window events 734 746 static EventTypeSpec window_events[] = { 735 747 { kEventClassWindow, kEventWindowClose }, 736 748 { kEventClassWindow, kEventWindowExpanded }, 749 750 737 751 { kEventClassWindow, kEventWindowZoomed }, 738 752 { kEventClassWindow, kEventWindowCollapsed }, … … 742 756 { kEventClassWindow, kEventWindowResizeCompleted }, 743 757 { kEventClassWindow, kEventWindowBoundsChanging }, 744 { kEventClassWindow, kEventWindowBoundsChanged },745 758 { kEventClassWindow, kEventWindowGetRegion }, 746 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4747 759 { kEventClassWindow, kEventWindowGetClickModality }, 748 #endif749 760 { kEventClassWindow, kEventWindowTransitionCompleted }, 761 762 763 764 765 750 766 { kEventClassMouse, kEventMouseDown } 751 767 }; … … 776 792 if(!widget) { 777 793 handled_event = false; 778 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4779 794 } else if(ekind == kEventWindowGetClickModality) { 780 795 // Carbon will send us kEventWindowGetClickModality before every … … 787 802 // help Carbon determining which window is supposed to be raised. 788 803 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 #endif800 804 } else if(ekind == kEventWindowClose) { 801 805 widget->d_func()->close_helper(QWidgetPrivate::CloseWithSpontaneousEvent); … … 825 829 QShowEvent qse; 826 830 QApplication::sendSpontaneousEvent(widget, &qse); 831 832 833 827 834 } else if(ekind == kEventWindowZoomed) { 828 835 WindowPartCode windowPart; … … 871 878 qt_button_down = 0; 872 879 } else if(ekind == kEventWindowToolbarSwitchMode) { 873 QToolBarChangeEvent ev(!(GetCurrentKeyModifiers() & cmdKey)); 874 QApplication::sendSpontaneousEvent(widget, &ev); 880 macSendToolbarChangeEvent(widget); 875 881 HIToolbarRef toolbar; 876 882 if (GetWindowToolbar(wid, &toolbar) == noErr) { … … 920 926 SendEventToApplication(mouseUpEvent); 921 927 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 929 952 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); 952 959 } 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); 961 978 } 962 979 } 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); 1003 1000 } 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1004 1014 } 1005 1015 } … … 1041 1051 handled_event = false; 1042 1052 break; } 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1043 1121 default: 1044 1122 handled_event = false; … … 1140 1218 GrafPtr qd = 0; 1141 1219 CGContextRef cg = 0; 1142 #ifndef QT_MAC_NO_QUICKDRAW1143 {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 #else1155 1220 if(GetEventParameter(event, kEventParamCGContextRef, typeCGContextRef, 0, sizeof(cg), 0, &cg) != noErr) { 1156 1221 Q_ASSERT(false); 1157 1222 } 1158 #endif1159 1223 widget->d_func()->hd = cg; 1160 1224 widget->d_func()->qd_hd = qd; … … 1222 1286 if(was_unclipped) 1223 1287 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); 1234 1289 if (widget->testAttribute(Qt::WA_TintedBackground)) { 1235 1290 QColor tint = widget->palette().window().color(); … … 1237 1292 const QVector<QRect> &rects = qrgn.rects(); 1238 1293 for (int i = 0; i < rects.size(); ++i) 1239 p.fillRect(rects.at(i) .translated(scrollAreaOffset), tint);1294 p.fillRect(rects.at(i), tint); 1240 1295 } 1241 1296 p.end(); … … 1267 1322 if (!redirectionOffset.isNull()) 1268 1323 widget->d_func()->restoreRedirected(); 1269 #ifdef QT_RASTER_PAINTENGINE1270 if(engine && engine->type() == QPaintEngine::Raster)1271 static_cast<QRasterPaintEngine*>(engine)->flush(widget,1272 qrgn.boundingRect().topLeft());1273 #endif1274 1324 1275 1325 //cleanup … … 1285 1335 widget->d_func()->qd_hd = 0; 1286 1336 CGContextRestoreGState(cg); 1287 #ifndef QT_MAC_NO_QUICKDRAW1288 if(end_cg_context)1289 QDEndCGContext(qd, &cg);1290 #endif1291 1337 } else if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget)) { 1292 1338 CallNextEventHandler(er, event); … … 1393 1439 // doesn't get called a second time below: 1394 1440 dropWidget = 0; 1441 1442 1443 1444 1445 1446 1447 1448 1395 1449 } 1396 1450 } … … 1537 1591 bool QWidgetPrivate::qt_mac_update_sizer(QWidget *w, int up) 1538 1592 { 1593 1539 1594 if(!w || !w->isWindow()) 1540 1595 return false; … … 1542 1597 QTLWExtra *topData = w->d_func()->topData(); 1543 1598 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; 1545 1603 OSWindowRef windowRef = qt_mac_window_for(OSViewRef(w->winId())); 1546 1604 { … … 1555 1613 || (extraData->maxw && extraData->maxh && 1556 1614 extraData->maxw == extraData->minw && extraData->maxh == extraData->minh)); 1557 1558 1615 #ifndef QT_MAC_USE_COCOA 1559 1616 WindowAttributes attr; … … 1603 1660 return false; 1604 1661 qAddPostRoutine(qt_clean_root_win); 1605 return true;1606 }1607 1608 bool QWidgetPrivate::qt_recreate_root_win()1609 {1610 if(!qt_root_win) //sanity check1611 return false;1612 //store old1613 OSWindowRef old_root_win = qt_root_win;1614 //recreate1615 qt_root_win = 0;1616 qt_create_root_win();1617 //cleanup old window1618 #ifdef QT_MAC_USE_COCOA1619 [old_root_win release];1620 #else1621 CFRelease(old_root_win);1622 #endif1623 1662 return true; 1624 1663 } … … 1724 1763 if (framelessWindow) { 1725 1764 if(wclass == kDocumentWindowClass) { 1726 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) 1727 wattr |= kWindowNoTitleBarAttribute; 1728 else 1729 wclass = kPlainWindowClass; 1765 wattr |= kWindowNoTitleBarAttribute; 1730 1766 } else if(wclass == kFloatingWindowClass) { 1731 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) 1732 wattr |= kWindowNoTitleBarAttribute; 1733 else 1734 wclass = kToolbarWindowClass; 1767 wattr |= kWindowNoTitleBarAttribute; 1735 1768 } else if (wclass == kMovableModalWindowClass) { 1736 1769 wclass = kModalWindowClass; 1737 1770 } 1738 1771 } else { … … 2032 2065 SetAutomaticControlDragTrackingEnabledForWindow(windowRef, true); 2033 2066 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); 2042 2071 if ((flags & Qt::WindowStaysOnTopHint)) 2043 2072 ChangeWindowAttributes(windowRef, kWindowNoAttributes, kWindowHideOnSuspendAttribute); … … 2163 2192 updateFrameStrut(); 2164 2193 qt_mac_update_sizer(q); 2194 2165 2195 } 2166 2196 #else // QT_MAC_USE_COCOA … … 2183 2213 if ((popup || type == Qt::Tool || type == Qt::ToolTip) && !q->isModal()) { 2184 2214 [windowRef setHidesOnDeactivate:YES]; 2185 [windowRef setHasShadow:YES]; 2186 } 2215 } else { 2216 [windowRef setHidesOnDeactivate:NO]; 2217 } 2218 [windowRef setHasShadow:YES]; 2187 2219 Q_UNUSED(parentWidget); 2188 2220 Q_UNUSED(dialog); … … 2245 2277 macUpdateIsOpaque(); 2246 2278 qt_mac_update_sizer(q); 2279 2247 2280 } 2248 2281 … … 2309 2342 OSWindowRef windowRef = qt_mac_create_window(q, topExtra->wclass, wattr, data.crect); 2310 2343 if (windowRef == 0) 2311 qWarning("QWidget: Internal error: %s:%d: If you reach this error please contact Trolltechand include the\n"2344 qWarning("QWidget: Internal error: %s:%d: If you reach this error please contact and include the\n" 2312 2345 " WidgetFlags used in creating the widget.", __FILE__, __LINE__); 2313 2346 #ifndef QT_MAC_USE_COCOA … … 2528 2561 if (!topLevel && initializeWindow) 2529 2562 setWSGeometry(); 2530 2531 2563 if (destroyid) 2532 2564 qt_mac_destructView(destroyid); 2565 2566 2533 2567 } 2534 2568 … … 2568 2602 Q_D(QWidget); 2569 2603 if (!isWindow() && parentWidget()) 2570 parentWidget()->d_func()->invalidateBuffer( geometry());2604 parentWidget()->d_func()->invalidateBuffer()); 2571 2605 d->deactivateWidgetCleanup(); 2572 2606 qt_mac_event_release(this); … … 2584 2618 if(mac_keyboard_grabber == this) 2585 2619 releaseKeyboard(); 2586 if(acceptDrops())2587 setAcceptDrops(false);2588 2620 2589 2621 if(testAttribute(Qt::WA_ShowModal)) // just be sure we leave modal … … 2619 2651 } 2620 2652 } 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 } 2622 2658 } 2623 2659 } … … 2649 2685 bool oldRegistered = w->testAttribute(Qt::WA_DropSiteRegistered); 2650 2686 w->setAttribute(Qt::WA_DropSiteRegistered, false); 2687 2688 2651 2689 [qt_mac_nativeview_for(q) addSubview:qt_mac_nativeview_for(w)]; 2690 2652 2691 w->setAttribute(Qt::WA_DropSiteRegistered, oldRegistered); 2653 2692 #endif … … 2670 2709 2671 2710 if (q->isVisible() && q->parentWidget() && parent != q->parentWidget()) 2672 q->parentWidget()->d_func()->invalidateBuffer( q->geometry());2711 q->parentWidget()->d_func()->invalidateBuffer()); 2673 2712 2674 2713 // Maintain the glWidgets list on parent change: remove "our" gl widgets … … 2737 2776 if (q->isWindow()) { 2738 2777 #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. 2743 2787 if (oldToolbar && !(f & Qt::FramelessWindowHint)) { 2744 2788 OSWindowRef newWindow = qt_mac_window_for(q); … … 2755 2799 if (wasCreated) { 2756 2800 transferChildren(); 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2757 2811 if (topData && 2758 2812 (!topData->caption.isEmpty() || !topData->filePath.isEmpty())) … … 2856 2910 void QWidgetPrivate::setCursor_sys(const QCursor &) 2857 2911 { 2912 2858 2913 qt_mac_update_cursor(); 2914 2915 2916 2917 2918 2919 2920 2859 2921 } 2860 2922 2861 2923 void QWidgetPrivate::unsetCursor_sys() 2862 2924 { 2925 2863 2926 qt_mac_update_cursor(); 2927 2928 2929 2930 2931 2932 2933 2864 2934 } 2865 2935 … … 2872 2942 #else 2873 2943 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)]; 2876 2945 #endif 2877 2946 } … … 2895 2964 #ifdef QT_MAC_USE_COCOA 2896 2965 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) : @""]; 2898 2968 #else 2899 2969 bool validRef = false; … … 2908 2978 // Set the proxy regardless, since this is our way of clearing it as well, but ignore the 2909 2979 // 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); 2916 2982 } 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)); 2925 2984 } 2926 2985 if (status != noErr) … … 2977 3036 QMacCocoaAutoReleasePool pool; 2978 3037 NSButton *iconButton = [qt_mac_window_for(q) standardWindowButton:NSWindowDocumentIconButton]; 3038 3039 3040 3041 3042 3043 2979 3044 if (icon.isNull()) { 2980 3045 [iconButton setImage:nil]; 2981 3046 } 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)); 2983 3049 [iconButton setImage:image]; 2984 3050 [image release]; … … 2996 3062 #else 2997 3063 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)]; 3000 3065 #endif 3001 3066 } … … 3011 3076 } 3012 3077 3078 3013 3079 void QWidget::grabMouse(const QCursor &) 3014 3080 { … … 3019 3085 } 3020 3086 } 3087 3021 3088 3022 3089 void QWidget::releaseMouse() … … 3130 3197 return; 3131 3198 #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); 3142 3202 #else 3143 3203 [qt_mac_nativeview_for(q) setNeedsDisplayInRect:NSMakeRect(x, y, w, h)]; … … 3153 3213 dirtyOnWidget += rgn; 3154 3214 #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 } 3156 3221 #else 3157 3222 // 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. … … 3224 3289 SizeWindow(window, q->width(), q->height(), true); 3225 3290 #endif 3291 3292 3293 3294 3295 3296 3226 3297 if(qt_mac_is_macsheet(q)) { 3227 3298 qt_event_request_showsheet(q); … … 3239 3310 // sync the opacity value back (in case of a fade). 3240 3311 [window setAlphaValue:q->windowOpacity()]; 3241 3242 3312 [window makeKeyAndOrderFront:window]; 3313 3314 3315 3316 3243 3317 if (data.window_modality == Qt::ApplicationModal) 3244 Q CoreApplication::postEvent(qApp, new QEvent(QEvent::CocoaRequestModal));3318 Q); 3245 3319 #endif 3246 3320 if (q->windowType() == Qt::Popup) { … … 3259 3333 #endif 3260 3334 } else if (!q->testAttribute(Qt::WA_ShowWithoutActivating)) { 3335 3261 3336 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]; 3268 3339 #endif 3269 3340 } … … 3347 3418 if(!w || (!w->isVisible() && !w->isMinimized())) { 3348 3419 #ifndef QT_MAC_USE_COCOA 3349 for (WindowPtr wp = GetFrontWindowOfClass(kDocumentWindowClass, true);3350 wp; wp = GetNextWindowOfClass(wp, k DocumentWindowClass, true)) {3420 forWindowClass, true); 3421 wp; wp = GetNextWindowOfClass(wp, kWindowClass, true)) { 3351 3422 if((w = qt_mac_find_window(wp))) 3352 3423 break; 3424 3425 3426 3427 3428 3429 3430 3353 3431 } 3354 3432 if (!w){ … … 3369 3447 #endif 3370 3448 } 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 } 3373 3456 } 3374 3457 } else { … … 3423 3506 } else { 3424 3507 needShow = isVisible(); 3508 3509 3425 3510 setParent(parentWidget(), d->topData()->savedFlags); 3426 3511 setGeometry(d->topData()->normalGeometry); 3427 if(!qApp->desktop()->screenNumber(this))3428 qt_mac_set_fullscreen_mode(false);3429 3512 d->topData()->normalGeometry.setRect(0, 0, -1, -1); 3430 3513 } … … 3528 3611 #endif 3529 3612 needSendStateChange = oldstate == windowState(); // Zoom didn't change flags. 3530 } else if(oldstate & Qt::WindowMaximized ) {3613 } else if(oldstate & Qt::WindowMaximized) { 3531 3614 #ifndef QT_MAC_USE_COCOA 3532 3615 Point idealSize; … … 3572 3655 } 3573 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3574 3667 void QWidgetPrivate::raise_sys() 3575 3668 { … … 3579 3672 3580 3673 #if QT_MAC_USE_COCOA 3581 QMacCocoaAutoReleasePool pool;3582 3674 if (isRealWindow()) { 3583 3675 // Calling orderFront shows the window on Cocoa too. 3584 if (!q->testAttribute(Qt::WA_DontShowOnScreen) ) {3676 if (!q->testAttribute(Qt::WA_DontShowOnScreen)) { 3585 3677 [qt_mac_window_for(q) orderFront:qt_mac_window_for(q)]; 3586 3678 } … … 3591 3683 } 3592 3684 } else { 3593 // Cocoa doesn't really have an idea of Z-ordering, but you can3594 // fake it by changing the order of it.3595 3685 NSView *view = qt_mac_nativeview_for(q); 3596 3686 NSView *parentView = [view superview]; 3597 [view removeFromSuperview]; 3598 [parentView addSubview:view]; 3687 [parentView sortSubviewsUsingFunction:compareViews2Raise context:reinterpret_cast<void *>(view)]; 3599 3688 } 3600 3689 #else … … 3614 3703 } 3615 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3616 3715 void QWidgetPrivate::lower_sys() 3617 3716 { … … 3620 3719 return; 3621 3720 #ifdef QT_MAC_USE_COCOA 3622 QMacCocoaAutoReleasePool pool;3623 3721 if (isRealWindow()) { 3624 3722 OSWindowRef window = qt_mac_window_for(q); 3625 3723 [window orderBack:window]; 3626 3724 } 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)]; 3655 3728 } 3656 3729 #else … … 3665 3738 } 3666 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3667 3750 void QWidgetPrivate::stackUnder_sys(QWidget *w) 3668 3751 { … … 3673 3756 #ifdef QT_MAC_USE_COCOA 3674 3757 // 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); 3677 3759 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. 3687 3768 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); 3693 3770 ++index; 3694 3771 } 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)]; 3706 3775 #else 3707 3776 QWidget *p = q->parentWidget(); … … 3717 3786 Modifies the bounds for a widgets backing HIView during moves and resizes. Also updates the 3718 3787 widget, either by scrolling its contents or repainting, depending on the WA_StaticContents 3719 and QWidgetPrivate::isOpaque flags.3788 3720 3789 */ 3721 3790 static void qt_mac_update_widget_posisiton(QWidget *q, QRect oldRect, QRect newRect) … … 3734 3803 // Perform a normal (complete repaint) update in some cases: 3735 3804 if ( 3736 // move-by-scroll requires QWidgetPrivate::isOpaque set3737 (isMove && qd->isOpaque == false) ||3805 // 3806 (isMove) || 3738 3807 3739 3808 // limited update on resize requires WA_StaticContents. … … 3744 3813 3745 3814 // 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 3747 3819 ){ 3748 3820 HIViewSetFrame(view, &bounds); … … 3845 3917 X coordinate system for parent (relative to parent's wrect). 3846 3918 */ 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);3849 3919 QRect wrect; 3850 3920 //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) … … 3868 3938 tmpRect.size.width, tmpRect.size.height); 3869 3939 } else { 3940 3870 3941 parentWRect = wrectRange; 3871 3942 } … … 3923 3994 } 3924 3995 3996 3925 3997 if (!validRange.contains(xrect)) { 3926 3998 // 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; 3928 4011 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 } 3934 4014 } 3935 4015 … … 3971 4051 qt_mac_update_widget_posisiton(q, oldRect, xrect); 3972 4052 3973 if (jump) { 3974 updateSystemBackground(); 4053 if (jump) 3975 4054 q->update(); 3976 } 4055 3977 4056 if (mapWindow && !dontShow) { 3978 4057 q->setAttribute(Qt::WA_Mapped); … … 3985 4064 } 3986 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 3987 4113 void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove) 3988 4114 { … … 3995 4121 QMacCocoaAutoReleasePool pool; 3996 4122 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)); 4004 4139 NSWindow *window = qt_mac_window_for(q); 4005 4140 const QRect &fStrut = frameStrut(); … … 4009 4144 NSRect cocoaFrameRect = NSMakeRect(frameRect.x(), flipYCoordinate(frameRect.bottom() + 1), 4010 4145 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 4014 4168 } else { 4015 4169 setGeometry_sys_helper(x, y, w, h, isMove); … … 4021 4175 Q_Q(QWidget); 4022 4176 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_COCOA4028 OSWindowRef window = qt_mac_window_for(q);4029 if(extra->maxw && extra->maxh && extra->maxw == extra->minw4030 && extra->maxh == extra->minh) {4031 ChangeWindowAttributes(window, kWindowNoAttributes, kWindowFullZoomAttribute);4032 } else {4033 ChangeWindowAttributes(window, kWindowFullZoomAttribute, kWindowNoAttributes);4034 }4035 #endif4036 }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 increment4045 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 }4061 4177 4062 4178 QPoint oldp = q->pos(); 4063 4179 QSize olds = q->size(); 4064 4180 const bool isResize = (olds != QSize(w, h)); 4065 if(!realWindow && !isResize && QPoint(x, y) == oldp) 4181 4182 if (!realWindow && !isResize && QPoint(x, y) == oldp) 4066 4183 return; 4067 if(isResize && q->isMaximized()) 4184 4185 if (isResize) 4068 4186 data.window_state = data.window_state & ~Qt::WindowMaximized; 4187 4069 4188 const bool visible = q->isVisible(); 4070 4189 data.crect = QRect(x, y, w, h); 4071 4190 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 } 4091 4205 HIRect bounds = CGRectMake(0, 0, w, h); 4092 4206 HIViewSetFrame(qt_mac_nativeview_for(q), &bounds); … … 4101 4215 if (isResize && QApplicationPrivate::graphicsSystem()) { 4102 4216 invalidateBuffer(q->rect()); 4103 if (extra && ! extra->mask.isEmpty()) {4217 if (extra && !extra->mask.isEmpty()) { 4104 4218 QRegion oldRegion(extra->mask.translated(oldp)); 4105 4219 oldRegion &= oldRect; 4106 4220 q->parentWidget()->d_func()->invalidateBuffer(oldRegion); 4107 4221 } else { 4108 q->parentWidget()->d_func()->invalidateBuffer( oldRect);4222 q->parentWidget()->d_func()->invalidateBuffer(); 4109 4223 } 4110 4224 } … … 4134 4248 { 4135 4249 updateMaximizeButton_sys(); 4250 4136 4251 } 4137 4252 … … 4228 4343 w->data->crect.width(), w->data->crect.height()); 4229 4344 HIViewRef hiview = qt_mac_nativeview_for(w); 4230 const bool opaque = q t_widget_private(w)->isOpaque;4345 const bool opaque = q; 4231 4346 4232 4347 if (opaque) … … 4259 4374 #ifndef QT_MAC_USE_COCOA 4260 4375 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); 4285 4383 } 4286 # endif4287 4384 #else 4288 4385 NSRect scrollRect = valid_rect ? NSMakeRect(r.x(), r.y(), r.width(), r.height()) … … 4312 4409 } 4313 4410 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]; 4328 4414 [view setNeedsDisplayInRect:deltaXRect]; 4329 4415 [view setNeedsDisplayInRect:deltaYRect]; … … 4395 4481 void QWidgetPrivate::createTLSysExtra() 4396 4482 { 4483 4484 4485 4486 4397 4487 extra->topextra->wclass = 0; 4398 4488 extra->topextra->group = 0; 4399 4489 extra->topextra->windowIcon = 0; 4400 extra->topextra->resizer = 0;4401 extra->topextra->isSetGeometry = 0;4402 4490 extra->topextra->savedWindowAttributesFromMaximized = 0; 4403 4491 } … … 4406 4494 { 4407 4495 #ifndef QT_MAC_USE_COCOA 4408 if (extra->topextra->group) {4496 if(extra->topextra->group) { 4409 4497 qt_mac_release_window_group(extra->topextra->group); 4410 4498 extra->topextra->group = 0; 4499 4500 4501 4502 4411 4503 } 4412 4504 #endif … … 4448 4540 #else 4449 4541 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 4548 void 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 4453 4562 #endif 4454 4563 } … … 4474 4583 } 4475 4584 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 4484 4585 void QWidgetPrivate::setWindowOpacity_sys(qreal level) 4485 4586 { … … 4494 4595 return; 4495 4596 4597 4496 4598 #if QT_MAC_USE_COCOA 4497 OSWindowRef oswindow = qt_mac_window_for(q);4498 4599 [oswindow setAlphaValue:level]; 4499 4600 #else 4500 CGSSetWindowAlpha(_CGSDefaultConnection(), 4501 GetNativeWindowFromWindowRef(qt_mac_window_for(q)), level); 4601 SetWindowAlpha(oswindow, level); 4502 4602 #endif 4503 4603 } … … 4571 4671 { 4572 4672 QPaintEngine *&pe = engineHandler()->engine; 4573 #ifdef QT_RASTER_PAINTENGINE4574 if (!pe) {4575 if(qgetenv("QT_MAC_USE_COREGRAPHICS").isNull())4576 pe = new QRasterPaintEngine();4577 else4578 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 #else4588 4673 if (!pe) 4589 4674 pe = new QCoreGraphicsPaintEngine(); … … 4593 4678 return engine; 4594 4679 } 4595 #endif4596 4680 return pe; 4597 4681 } … … 4607 4691 4608 4692 #ifdef QT_MAC_USE_COCOA 4693 4609 4694 bool alreadySheet = [windowRef styleMask] & NSDocModalWindowMask; 4610 4695 … … 4683 4768 // Window should be window-modal (which implies a sheet). 4684 4769 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: 4686 4772 recreateMacWindow(); 4687 4773 return; 4688 4774 } 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 } 4710 4804 } 4711 4805 } else if (windowRef) { … … 4843 4937 layout->updateHIToolBarStatus(); 4844 4938 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); 4847 4940 } 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); 4850 4942 ChangeWindowAttributes(qt_mac_window_for(q), 0, kWindowMetalAttribute); 4851 4943 if (layout)
Note:
See TracChangeset
for help on using the changeset viewer.