src/gui/kernel/qwidget_mac.mm
changeset 19 fcece45ef507
parent 18 2f34d5167611
child 30 5dc02b23752f
equal deleted inserted replaced
18:2f34d5167611 19:fcece45ef507
   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.
   864                 widget->data->window_state = widget->data->window_state | Qt::WindowMaximized;
   865                 widget->data->window_state = widget->data->window_state | Qt::WindowMaximized;
   865                 QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state
   866                 QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state
   866                                                            & ~Qt::WindowMaximized));
   867                                                            & ~Qt::WindowMaximized));
   867                 QApplication::sendSpontaneousEvent(widget, &e);
   868                 QApplication::sendSpontaneousEvent(widget, &e);
   868             }
   869             }
   869             extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp
       
   870             qt_button_down = 0;
   870             qt_button_down = 0;
   871         } else if(ekind == kEventWindowCollapsed) {
   871         } else if(ekind == kEventWindowCollapsed) {
   872             if (!widget->isMinimized()) {
   872             if (!widget->isMinimized()) {
   873                 widget->data->window_state = widget->data->window_state | Qt::WindowMinimized;
   873                 widget->data->window_state = widget->data->window_state | Qt::WindowMinimized;
   874                 QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state & ~Qt::WindowMinimized));
   874                 QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state & ~Qt::WindowMinimized));
   892             }
   892             }
   893 
   893 
   894             //we send a hide to be like X11/Windows
   894             //we send a hide to be like X11/Windows
   895             QEvent e(QEvent::Hide);
   895             QEvent e(QEvent::Hide);
   896             QApplication::sendSpontaneousEvent(widget, &e);
   896             QApplication::sendSpontaneousEvent(widget, &e);
   897             extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp
       
   898             qt_button_down = 0;
   897             qt_button_down = 0;
   899         } else if(ekind == kEventWindowToolbarSwitchMode) {
   898         } else if(ekind == kEventWindowToolbarSwitchMode) {
   900             macSendToolbarChangeEvent(widget);
   899             macSendToolbarChangeEvent(widget);
   901             HIToolbarRef toolbar;
   900             HIToolbarRef toolbar;
   902             if (GetWindowToolbar(wid, &toolbar) == noErr) {
   901             if (GetWindowToolbar(wid, &toolbar) == noErr) {
  1266                 }
  1265                 }
  1267 #endif
  1266 #endif
  1268                 if (widget->isVisible() && widget->updatesEnabled()) { //process the actual paint event.
  1267                 if (widget->isVisible() && widget->updatesEnabled()) { //process the actual paint event.
  1269                     if(widget->testAttribute(Qt::WA_WState_InPaintEvent))
  1268                     if(widget->testAttribute(Qt::WA_WState_InPaintEvent))
  1270                         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                     }
  1271 
  1275 
  1272                     QPoint redirectionOffset(0, 0);
  1276                     QPoint redirectionOffset(0, 0);
  1273                     QWidget *tl = widget->window();
  1277                     QWidget *tl = widget->window();
  1274                     if (tl) {
  1278                     if (tl) {
  1275                         Qt::WindowFlags flags = tl->windowFlags();
  1279                         Qt::WindowFlags flags = tl->windowFlags();
  1315                         }
  1319                         }
  1316                         p.end();
  1320                         p.end();
  1317                         if (!redirectionOffset.isNull())
  1321                         if (!redirectionOffset.isNull())
  1318                             widget->d_func()->restoreRedirected();
  1322                             widget->d_func()->restoreRedirected();
  1319                     }
  1323                     }
  1320 
       
  1321                     if (widget->isWindow() && !widget->d_func()->isOpaque
       
  1322                            && !widget->testAttribute(Qt::WA_MacBrushedMetal)) {
       
  1323                         QRect qrgnRect = qrgn.boundingRect();
       
  1324                         CGContextClearRect(cg, CGRectMake(qrgnRect.x(), qrgnRect.y(), qrgnRect.width(), qrgnRect.height()));
       
  1325                     }
       
  1326 
       
  1327 
  1324 
  1328                     if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget))
  1325                     if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget))
  1329                         CallNextEventHandler(er, event);
  1326                         CallNextEventHandler(er, event);
  1330 
  1327 
  1331                     //send the paint
  1328                     //send the paint
  1519         } else if (ekind == kEventControlVisibilityChanged) {
  1516         } else if (ekind == kEventControlVisibilityChanged) {
  1520             handled_event = false;
  1517             handled_event = false;
  1521             if (widget) {
  1518             if (widget) {
  1522                 qt_event_request_window_change(widget);
  1519                 qt_event_request_window_change(widget);
  1523                 if (!HIViewIsVisible(HIViewRef(widget->winId()))) {
  1520                 if (!HIViewIsVisible(HIViewRef(widget->winId()))) {
  1524                     extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp
       
  1525                     if (widget == qt_button_down)
  1521                     if (widget == qt_button_down)
  1526                         qt_button_down = 0;
  1522                         qt_button_down = 0;
  1527                 }
  1523                 }
  1528             }
  1524             }
  1529         }
  1525         }
  1530         break; }
  1526         break; }
  1531     case kEventClassMouse: {
  1527     case kEventClassMouse: {
  1532         bool send_to_app = false;
  1528         bool send_to_app = false;
  1533         extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp
       
  1534         if(qt_button_down)
  1529         if(qt_button_down)
  1535             send_to_app = true;
  1530             send_to_app = true;
  1536         if(send_to_app) {
  1531         if(send_to_app) {
  1537             OSStatus err = SendEventToApplication(event);
  1532             OSStatus err = SendEventToApplication(event);
  1538             if(err != noErr)
  1533             if(err != noErr)
  3405 void QWidgetPrivate::hide_sys()
  3400 void QWidgetPrivate::hide_sys()
  3406 {
  3401 {
  3407     Q_Q(QWidget);
  3402     Q_Q(QWidget);
  3408     if((q->windowType() == Qt::Desktop)) //you can't hide the desktop!
  3403     if((q->windowType() == Qt::Desktop)) //you can't hide the desktop!
  3409         return;
  3404         return;
  3410 
       
  3411     QMacCocoaAutoReleasePool pool;
  3405     QMacCocoaAutoReleasePool pool;
  3412     if(q->isWindow()) {
  3406     if(q->isWindow()) {
  3413         OSWindowRef window = qt_mac_window_for(q);
  3407         OSWindowRef window = qt_mac_window_for(q);
  3414         if(qt_mac_is_macsheet(q)) {
  3408         if(qt_mac_is_macsheet(q)) {
  3415 #ifndef QT_MAC_USE_COCOA
  3409 #ifndef QT_MAC_USE_COCOA
  4473             deltaXRect.size.width = -dx;
  4467             deltaXRect.size.width = -dx;
  4474             deltaXRect.origin.x = scrollRect.size.width + dx;
  4468             deltaXRect.origin.x = scrollRect.size.width + dx;
  4475         }
  4469         }
  4476     }
  4470     }
  4477 
  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 
  4478     NSSize deltaSize = NSMakeSize(dx, dy);
  4485     NSSize deltaSize = NSMakeSize(dx, dy);
  4479     [view translateRectsNeedingDisplayInRect:scrollRect by:deltaSize];
       
  4480     [view scrollRect:scrollRect by:deltaSize];
  4486     [view scrollRect:scrollRect by:deltaSize];
  4481     [view setNeedsDisplayInRect:deltaXRect];
  4487     [view setNeedsDisplayInRect:deltaXRect];
  4482     [view setNeedsDisplayInRect:deltaYRect];
  4488     [view setNeedsDisplayInRect:deltaYRect];
  4483 #endif // QT_MAC_USE_COCOA
  4489 #endif // QT_MAC_USE_COCOA
  4484 }
  4490 }
  4674 {
  4680 {
  4675     Q_Q(QWidget);
  4681     Q_Q(QWidget);
  4676     if (!q->testAttribute(Qt::WA_WState_Created) || !extra)
  4682     if (!q->testAttribute(Qt::WA_WState_Created) || !extra)
  4677         return;
  4683         return;
  4678 
  4684 
  4679     if (extra->hasMask && extra->maskBits.size() != q->size()) {
  4685     if (extra->hasMask) {
  4680         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         }
  4681         extra->maskBits.fill(QColor(Qt::color1).rgba());
  4689         extra->maskBits.fill(QColor(Qt::color1).rgba());
  4682         extra->maskBits.setNumColors(2);
  4690         extra->maskBits.setNumColors(2);
  4683         extra->maskBits.setColor(0, QColor(Qt::color0).rgba());
  4691         extra->maskBits.setColor(0, QColor(Qt::color0).rgba());
  4684         extra->maskBits.setColor(1, QColor(Qt::color1).rgba());
  4692         extra->maskBits.setColor(1, QColor(Qt::color1).rgba());
  4685         QPainter painter(&extra->maskBits);
  4693         QPainter painter(&extra->maskBits);