src/gui/kernel/qwidget_mac.mm
branchRCL_3
changeset 8 3f74d0d4af4c
parent 5 d3bac044e0f0
equal deleted inserted replaced
6:dee5afe5301f 8:3f74d0d4af4c
   150 
   150 
   151 static bool qt_mac_raise_process = true;
   151 static bool qt_mac_raise_process = true;
   152 static OSWindowRef qt_root_win = 0;
   152 static OSWindowRef qt_root_win = 0;
   153 QWidget *mac_mouse_grabber = 0;
   153 QWidget *mac_mouse_grabber = 0;
   154 QWidget *mac_keyboard_grabber = 0;
   154 QWidget *mac_keyboard_grabber = 0;
       
   155 extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp
   155 
   156 
   156 #ifndef QT_MAC_USE_COCOA
   157 #ifndef QT_MAC_USE_COCOA
   157 #ifdef QT_NAMESPACE
   158 #ifdef QT_NAMESPACE
   158 
   159 
   159 // produce the string "com.trolltech.qt-namespace.widget", where "namespace" is the contents of QT_NAMESPACE.
   160 // produce the string "com.trolltech.qt-namespace.widget", where "namespace" is the contents of QT_NAMESPACE.
   560     // In Qt, a popup is seen as a 'stay on top' window.
   561     // In Qt, a popup is seen as a 'stay on top' window.
   561     // Since new groups are created for 'stays on top' windows, the
   562     // Since new groups are created for 'stays on top' windows, the
   562     // same must be done for popups. Otherwise, popups would be drawn
   563     // same must be done for popups. Otherwise, popups would be drawn
   563     // below 'stays on top' windows. Add 1 to get above pure stay-on-top windows.
   564     // below 'stays on top' windows. Add 1 to get above pure stay-on-top windows.
   564     qt_mac_set_window_group(window, Qt::Popup, qt_mac_get_group_level(kOverlayWindowClass)+1);
   565     qt_mac_set_window_group(window, Qt::Popup, qt_mac_get_group_level(kOverlayWindowClass)+1);
       
   566 }
       
   567 #endif
       
   568 
       
   569 #ifdef QT_MAC_USE_COCOA
       
   570 void qt_mac_set_needs_display(QWidget *widget, QRegion region)
       
   571 {
       
   572     NSView *theNSView = qt_mac_nativeview_for(widget);
       
   573     if (region.isEmpty()) {
       
   574         [theNSView setNeedsDisplay:YES];
       
   575         return;
       
   576     }
       
   577 
       
   578     QVector<QRect> rects = region.rects();
       
   579     for (int i = 0; i<rects.count(); ++i) {
       
   580         const QRect &rect = rects.at(i);
       
   581         NSRect nsrect = NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height());
       
   582         [theNSView setNeedsDisplayInRect:nsrect];
       
   583     }
       
   584 
   565 }
   585 }
   566 #endif
   586 #endif
   567 
   587 
   568 inline static bool updateRedirectedToGraphicsProxyWidget(QWidget *widget, const QRect &rect)
   588 inline static bool updateRedirectedToGraphicsProxyWidget(QWidget *widget, const QRect &rect)
   569 {
   589 {
   845                 widget->data->window_state = widget->data->window_state | Qt::WindowMaximized;
   865                 widget->data->window_state = widget->data->window_state | Qt::WindowMaximized;
   846                 QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state
   866                 QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state
   847                                                            & ~Qt::WindowMaximized));
   867                                                            & ~Qt::WindowMaximized));
   848                 QApplication::sendSpontaneousEvent(widget, &e);
   868                 QApplication::sendSpontaneousEvent(widget, &e);
   849             }
   869             }
   850             extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp
       
   851             qt_button_down = 0;
   870             qt_button_down = 0;
   852         } else if(ekind == kEventWindowCollapsed) {
   871         } else if(ekind == kEventWindowCollapsed) {
   853             if (!widget->isMinimized()) {
   872             if (!widget->isMinimized()) {
   854                 widget->data->window_state = widget->data->window_state | Qt::WindowMinimized;
   873                 widget->data->window_state = widget->data->window_state | Qt::WindowMinimized;
   855                 QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state & ~Qt::WindowMinimized));
   874                 QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state & ~Qt::WindowMinimized));
   873             }
   892             }
   874 
   893 
   875             //we send a hide to be like X11/Windows
   894             //we send a hide to be like X11/Windows
   876             QEvent e(QEvent::Hide);
   895             QEvent e(QEvent::Hide);
   877             QApplication::sendSpontaneousEvent(widget, &e);
   896             QApplication::sendSpontaneousEvent(widget, &e);
   878             extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp
       
   879             qt_button_down = 0;
   897             qt_button_down = 0;
   880         } else if(ekind == kEventWindowToolbarSwitchMode) {
   898         } else if(ekind == kEventWindowToolbarSwitchMode) {
   881             macSendToolbarChangeEvent(widget);
   899             macSendToolbarChangeEvent(widget);
   882             HIToolbarRef toolbar;
   900             HIToolbarRef toolbar;
   883             if (GetWindowToolbar(wid, &toolbar) == noErr) {
   901             if (GetWindowToolbar(wid, &toolbar) == noErr) {
  1247                 }
  1265                 }
  1248 #endif
  1266 #endif
  1249                 if (widget->isVisible() && widget->updatesEnabled()) { //process the actual paint event.
  1267                 if (widget->isVisible() && widget->updatesEnabled()) { //process the actual paint event.
  1250                     if(widget->testAttribute(Qt::WA_WState_InPaintEvent))
  1268                     if(widget->testAttribute(Qt::WA_WState_InPaintEvent))
  1251                         qWarning("QWidget::repaint: Recursive repaint detected");
  1269                         qWarning("QWidget::repaint: Recursive repaint detected");
       
  1270                     if (widget->isWindow() && !widget->d_func()->isOpaque
       
  1271                         && !widget->testAttribute(Qt::WA_MacBrushedMetal)) {
       
  1272                         QRect qrgnRect = qrgn.boundingRect();
       
  1273                         CGContextClearRect(cg, CGRectMake(qrgnRect.x(), qrgnRect.y(), qrgnRect.width(), qrgnRect.height()));
       
  1274                     }
  1252 
  1275 
  1253                     QPoint redirectionOffset(0, 0);
  1276                     QPoint redirectionOffset(0, 0);
  1254                     QWidget *tl = widget->window();
  1277                     QWidget *tl = widget->window();
  1255                     if (tl) {
  1278                     if (tl) {
  1256                         Qt::WindowFlags flags = tl->windowFlags();
  1279                         Qt::WindowFlags flags = tl->windowFlags();
  1296                         }
  1319                         }
  1297                         p.end();
  1320                         p.end();
  1298                         if (!redirectionOffset.isNull())
  1321                         if (!redirectionOffset.isNull())
  1299                             widget->d_func()->restoreRedirected();
  1322                             widget->d_func()->restoreRedirected();
  1300                     }
  1323                     }
  1301 
       
  1302                     if (widget->isWindow() && !widget->d_func()->isOpaque
       
  1303                            && !widget->testAttribute(Qt::WA_MacBrushedMetal)) {
       
  1304                         QRect qrgnRect = qrgn.boundingRect();
       
  1305                         CGContextClearRect(cg, CGRectMake(qrgnRect.x(), qrgnRect.y(), qrgnRect.width(), qrgnRect.height()));
       
  1306                     }
       
  1307 
       
  1308 
  1324 
  1309                     if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget))
  1325                     if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget))
  1310                         CallNextEventHandler(er, event);
  1326                         CallNextEventHandler(er, event);
  1311 
  1327 
  1312                     //send the paint
  1328                     //send the paint
  1500         } else if (ekind == kEventControlVisibilityChanged) {
  1516         } else if (ekind == kEventControlVisibilityChanged) {
  1501             handled_event = false;
  1517             handled_event = false;
  1502             if (widget) {
  1518             if (widget) {
  1503                 qt_event_request_window_change(widget);
  1519                 qt_event_request_window_change(widget);
  1504                 if (!HIViewIsVisible(HIViewRef(widget->winId()))) {
  1520                 if (!HIViewIsVisible(HIViewRef(widget->winId()))) {
  1505                     extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp
       
  1506                     if (widget == qt_button_down)
  1521                     if (widget == qt_button_down)
  1507                         qt_button_down = 0;
  1522                         qt_button_down = 0;
  1508                 }
  1523                 }
  1509             }
  1524             }
  1510         }
  1525         }
  1511         break; }
  1526         break; }
  1512     case kEventClassMouse: {
  1527     case kEventClassMouse: {
  1513         bool send_to_app = false;
  1528         bool send_to_app = false;
  1514         extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp
       
  1515         if(qt_button_down)
  1529         if(qt_button_down)
  1516             send_to_app = true;
  1530             send_to_app = true;
  1517         if(send_to_app) {
  1531         if(send_to_app) {
  1518             OSStatus err = SendEventToApplication(event);
  1532             OSStatus err = SendEventToApplication(event);
  1519             if(err != noErr)
  1533             if(err != noErr)
  3386 void QWidgetPrivate::hide_sys()
  3400 void QWidgetPrivate::hide_sys()
  3387 {
  3401 {
  3388     Q_Q(QWidget);
  3402     Q_Q(QWidget);
  3389     if((q->windowType() == Qt::Desktop)) //you can't hide the desktop!
  3403     if((q->windowType() == Qt::Desktop)) //you can't hide the desktop!
  3390         return;
  3404         return;
  3391 
       
  3392     QMacCocoaAutoReleasePool pool;
  3405     QMacCocoaAutoReleasePool pool;
  3393     if(q->isWindow()) {
  3406     if(q->isWindow()) {
  3394         OSWindowRef window = qt_mac_window_for(q);
  3407         OSWindowRef window = qt_mac_window_for(q);
  3395         if(qt_mac_is_macsheet(q)) {
  3408         if(qt_mac_is_macsheet(q)) {
  3396 #ifndef QT_MAC_USE_COCOA
  3409 #ifndef QT_MAC_USE_COCOA
  4454             deltaXRect.size.width = -dx;
  4467             deltaXRect.size.width = -dx;
  4455             deltaXRect.origin.x = scrollRect.size.width + dx;
  4468             deltaXRect.origin.x = scrollRect.size.width + dx;
  4456         }
  4469         }
  4457     }
  4470     }
  4458 
  4471 
       
  4472     // ### Scroll the dirty regions as well, the following is not correct.
       
  4473     QRegion displayRegion = r.isNull() ? dirtyOnWidget : (dirtyOnWidget & r);
       
  4474     const QVector<QRect> &rects = dirtyOnWidget.rects();
       
  4475     const QVector<QRect>::const_iterator end = rects.end();
       
  4476     QVector<QRect>::const_iterator it = rects.begin();
       
  4477     while (it != end) {
       
  4478 	const QRect rect = *it;
       
  4479 	const NSRect dirtyRect = NSMakeRect(rect.x() + dx, rect.y() + dy,
       
  4480 		rect.width(), rect.height());
       
  4481 	[view setNeedsDisplayInRect:dirtyRect];
       
  4482 	++it;
       
  4483     }
       
  4484 
  4459     NSSize deltaSize = NSMakeSize(dx, dy);
  4485     NSSize deltaSize = NSMakeSize(dx, dy);
  4460     [view translateRectsNeedingDisplayInRect:scrollRect by:deltaSize];
       
  4461     [view scrollRect:scrollRect by:deltaSize];
  4486     [view scrollRect:scrollRect by:deltaSize];
  4462     [view setNeedsDisplayInRect:deltaXRect];
  4487     [view setNeedsDisplayInRect:deltaXRect];
  4463     [view setNeedsDisplayInRect:deltaYRect];
  4488     [view setNeedsDisplayInRect:deltaYRect];
  4464 #endif // QT_MAC_USE_COCOA
  4489 #endif // QT_MAC_USE_COCOA
  4465 }
  4490 }
  4655 {
  4680 {
  4656     Q_Q(QWidget);
  4681     Q_Q(QWidget);
  4657     if (!q->testAttribute(Qt::WA_WState_Created) || !extra)
  4682     if (!q->testAttribute(Qt::WA_WState_Created) || !extra)
  4658         return;
  4683         return;
  4659 
  4684 
  4660     if (extra->hasMask && extra->maskBits.size() != q->size()) {
  4685     if (extra->hasMask) {
  4661         extra->maskBits = QImage(q->size(), QImage::Format_Mono);
  4686         if(extra->maskBits.size() != q->size()) {
       
  4687             extra->maskBits = QImage(q->size(), QImage::Format_Mono);
       
  4688         }
  4662         extra->maskBits.fill(QColor(Qt::color1).rgba());
  4689         extra->maskBits.fill(QColor(Qt::color1).rgba());
  4663         extra->maskBits.setNumColors(2);
  4690         extra->maskBits.setNumColors(2);
  4664         extra->maskBits.setColor(0, QColor(Qt::color0).rgba());
  4691         extra->maskBits.setColor(0, QColor(Qt::color0).rgba());
  4665         extra->maskBits.setColor(1, QColor(Qt::color1).rgba());
  4692         extra->maskBits.setColor(1, QColor(Qt::color1).rgba());
  4666         QPainter painter(&extra->maskBits);
  4693         QPainter painter(&extra->maskBits);