src/gui/kernel/qapplication_mac.mm
branchRCL_3
changeset 5 d3bac044e0f0
parent 4 3b1da2848fc7
child 8 3f74d0d4af4c
equal deleted inserted replaced
4:3b1da2848fc7 5:d3bac044e0f0
   225 void onApplicationWindowChangedActivation( QWidget*widget, bool activated );
   225 void onApplicationWindowChangedActivation( QWidget*widget, bool activated );
   226 void onApplicationChangedActivation( bool activated );
   226 void onApplicationChangedActivation( bool activated );
   227 
   227 
   228 static void qt_mac_read_fontsmoothing_settings()
   228 static void qt_mac_read_fontsmoothing_settings()
   229 {
   229 {
   230     NSInteger appleFontSmoothing = [[NSUserDefaults standardUserDefaults] integerForKey:@"AppleFontSmoothing"];
   230     qt_applefontsmoothing_enabled = true;
   231     qt_applefontsmoothing_enabled = (appleFontSmoothing > 0);
   231     int w = 10, h = 10;
       
   232     QImage image(w, h, QImage::Format_RGB32);
       
   233     image.fill(0xffffffff);
       
   234     QPainter p(&image);
       
   235     p.drawText(0, h, "X\\");
       
   236     p.end();
       
   237 
       
   238     const int *bits = (const int *) ((const QImage &) image).bits();
       
   239     int bpl = image.bytesPerLine() / 4;
       
   240     for (int y=0; y<w; ++y) {
       
   241         for (int x=0; x<h; ++x) {
       
   242             int r = qRed(bits[x]);
       
   243             int g = qGreen(bits[x]);
       
   244             int b = qBlue(bits[x]);
       
   245             if (r != g || r != b) {
       
   246                 qt_applefontsmoothing_enabled = true;
       
   247                 return;
       
   248             }
       
   249         }
       
   250         bits += bpl;
       
   251     }
       
   252     qt_applefontsmoothing_enabled = false;
   232 }
   253 }
   233 
   254 
   234 Q_GUI_EXPORT bool qt_mac_execute_apple_script(const char *script, long script_len, AEDesc *ret) {
   255 Q_GUI_EXPORT bool qt_mac_execute_apple_script(const char *script, long script_len, AEDesc *ret) {
   235     OSStatus err;
   256     OSStatus err;
   236     AEDesc scriptTextDesc;
   257     AEDesc scriptTextDesc;
   770         const QRect globalGlWidgetRect = QRect(glWidget->mapToGlobal(QPoint(0, 0)), glWidget->size());
   791         const QRect globalGlWidgetRect = QRect(glWidget->mapToGlobal(QPoint(0, 0)), glWidget->size());
   771         if (globalWidgetRect.intersects(globalGlWidgetRect)) {
   792         if (globalWidgetRect.intersects(globalGlWidgetRect)) {
   772             qt_post_window_change_event(glWidget);
   793             qt_post_window_change_event(glWidget);
   773             it->lastUpdateWidget = widget;
   794             it->lastUpdateWidget = widget;
   774         } else if (it->lastUpdateWidget == widget) {
   795         } else if (it->lastUpdateWidget == widget) {
   775             // Update the gl wigets that the widget intersected the last time around, 
   796             // Update the gl wigets that the widget intersected the last time around,
   776             // and that we are not intersecting now. This prevents paint errors when the 
   797             // and that we are not intersecting now. This prevents paint errors when the
   777             // intersecting widget leaves a gl widget.
   798             // intersecting widget leaves a gl widget.
   778             qt_post_window_change_event(glWidget);
   799             qt_post_window_change_event(glWidget);
   779             it->lastUpdateWidget = 0;            
   800             it->lastUpdateWidget = 0;
   780         }
   801         }
   781     }
   802     }
   782 #else
   803 #else
   783     Q_UNUSED(widget);
   804     Q_UNUSED(widget);
   784 #endif
   805 #endif
   806         return;
   827         return;
   807 
   828 
   808     // Post a kEventQtRequestWindowChange event. This event is semi-public,
   829     // Post a kEventQtRequestWindowChange event. This event is semi-public,
   809     // don't remove this line!
   830     // don't remove this line!
   810     qt_event_request_window_change();
   831     qt_event_request_window_change();
   811     
   832 
   812     // Post update request on gl widgets unconditionally. 
   833     // Post update request on gl widgets unconditionally.
   813     if (qt_widget_private(widget)->isGLWidget == true) {
   834     if (qt_widget_private(widget)->isGLWidget == true) {
   814         qt_post_window_change_event(widget);
   835         qt_post_window_change_event(widget);
   815         return;
   836         return;
   816     }
   837     }
   817 
   838 
  1212         }
  1233         }
  1213     }
  1234     }
  1214     if (QApplication::desktopSettingsAware())
  1235     if (QApplication::desktopSettingsAware())
  1215         QApplicationPrivate::qt_mac_apply_settings();
  1236         QApplicationPrivate::qt_mac_apply_settings();
  1216 
  1237 
  1217     qt_mac_read_fontsmoothing_settings();
       
  1218 
       
  1219     // Cocoa application delegate
  1238     // Cocoa application delegate
  1220 #ifdef QT_MAC_USE_COCOA
  1239 #ifdef QT_MAC_USE_COCOA
  1221     NSApplication *cocoaApp = [NSApplication sharedApplication];
  1240     NSApplication *cocoaApp = [NSApplication sharedApplication];
  1222     QMacCocoaAutoReleasePool pool;
  1241     QMacCocoaAutoReleasePool pool;
  1223     NSObject *oldDelegate = [cocoaApp delegate];
  1242     NSObject *oldDelegate = [cocoaApp delegate];
  1251         tablet_proximity_UPP = NewEventHandlerUPP(QApplicationPrivate::tabletProximityCallback);
  1270         tablet_proximity_UPP = NewEventHandlerUPP(QApplicationPrivate::tabletProximityCallback);
  1252         qt_init_tablet_proximity_handler();
  1271         qt_init_tablet_proximity_handler();
  1253     }
  1272     }
  1254    priv->native_modal_dialog_active = false;
  1273    priv->native_modal_dialog_active = false;
  1255 
  1274 
       
  1275    qt_mac_read_fontsmoothing_settings();
  1256 }
  1276 }
  1257 
  1277 
  1258 void qt_release_apple_event_handler()
  1278 void qt_release_apple_event_handler()
  1259 {
  1279 {
  1260     if(app_proc_ae_handlerUPP) {
  1280     if(app_proc_ae_handlerUPP) {
  1703             // in much smoother scrolling when using Mighty Mouse or TrackPad. For
  1723             // in much smoother scrolling when using Mighty Mouse or TrackPad. For
  1704             // compatibility with older applications, carbon will also send us
  1724             // compatibility with older applications, carbon will also send us
  1705             // kEventMouseWheelMoved events if we dont eat this event
  1725             // kEventMouseWheelMoved events if we dont eat this event
  1706             // (actually two events; one for horizontal and one for vertical).
  1726             // (actually two events; one for horizontal and one for vertical).
  1707             // As a results of this, and to make sure we dont't receive duplicate events,
  1727             // As a results of this, and to make sure we dont't receive duplicate events,
  1708             // we try to detect when this happend by checking the 'compatibilityEvent'. 
  1728             // we try to detect when this happend by checking the 'compatibilityEvent'.
  1709             SInt32 mdelt = 0;
  1729             SInt32 mdelt = 0;
  1710             GetEventParameter(event, kEventParamMouseWheelSmoothHorizontalDelta, typeSInt32, 0,
  1730             GetEventParameter(event, kEventParamMouseWheelSmoothHorizontalDelta, typeSInt32, 0,
  1711                               sizeof(mdelt), 0, &mdelt);
  1731                               sizeof(mdelt), 0, &mdelt);
  1712             wheel_deltaX = mdelt;
  1732             wheel_deltaX = mdelt;
  1713             mdelt = 0;
  1733             mdelt = 0;
  2574     if (popup == qt_button_down)
  2594     if (popup == qt_button_down)
  2575         qt_button_down = 0;
  2595         qt_button_down = 0;
  2576     if (QApplicationPrivate::popupWidgets->isEmpty()) {  // this was the last popup
  2596     if (QApplicationPrivate::popupWidgets->isEmpty()) {  // this was the last popup
  2577         delete QApplicationPrivate::popupWidgets;
  2597         delete QApplicationPrivate::popupWidgets;
  2578         QApplicationPrivate::popupWidgets = 0;
  2598         QApplicationPrivate::popupWidgets = 0;
  2579         
  2599 
  2580         // Special case for Tool windows: since they are activated and deactived together
  2600         // Special case for Tool windows: since they are activated and deactived together
  2581         // with a normal window they never become the QApplicationPrivate::active_window.
  2601         // with a normal window they never become the QApplicationPrivate::active_window.
  2582         QWidget *appFocusWidget = QApplication::focusWidget();
  2602         QWidget *appFocusWidget = QApplication::focusWidget();
  2583         if (appFocusWidget && appFocusWidget->window()->windowType() == Qt::Tool) {
  2603         if (appFocusWidget && appFocusWidget->window()->windowType() == Qt::Tool) {
  2584             appFocusWidget->setFocus(Qt::PopupFocusReason);
  2604             appFocusWidget->setFocus(Qt::PopupFocusReason);