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 ** |
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; |
2121 qt_mac_dblclick.last_button = button; |
2141 qt_mac_dblclick.last_button = button; |
2122 qt_mac_dblclick.last_time = GetEventTime(event); |
2142 qt_mac_dblclick.last_time = GetEventTime(event); |
2123 } |
2143 } |
2124 |
2144 |
2125 if (wheel_deltaX || wheel_deltaY) { |
2145 if (wheel_deltaX || wheel_deltaY) { |
|
2146 #ifndef QT_NO_WHEELEVENT |
2126 if (wheel_deltaX) { |
2147 if (wheel_deltaX) { |
2127 QWheelEvent qwe(plocal, p, wheel_deltaX, buttons, modifiers, Qt::Horizontal); |
2148 QWheelEvent qwe(plocal, p, wheel_deltaX, buttons, modifiers, Qt::Horizontal); |
2128 QApplication::sendSpontaneousEvent(widget, &qwe); |
2149 QApplication::sendSpontaneousEvent(widget, &qwe); |
2129 if (!qwe.isAccepted() && QApplicationPrivate::focus_widget && QApplicationPrivate::focus_widget != widget) { |
2150 if (!qwe.isAccepted() && QApplicationPrivate::focus_widget && QApplicationPrivate::focus_widget != widget) { |
2130 QWheelEvent qwe2(QApplicationPrivate::focus_widget->mapFromGlobal(p), p, |
2151 QWheelEvent qwe2(QApplicationPrivate::focus_widget->mapFromGlobal(p), p, |
2143 QApplication::sendSpontaneousEvent(QApplicationPrivate::focus_widget, &qwe2); |
2164 QApplication::sendSpontaneousEvent(QApplicationPrivate::focus_widget, &qwe2); |
2144 if (!qwe2.isAccepted()) |
2165 if (!qwe2.isAccepted()) |
2145 handled_event = false; |
2166 handled_event = false; |
2146 } |
2167 } |
2147 } |
2168 } |
|
2169 #endif // QT_NO_WHEELEVENT |
2148 } else { |
2170 } else { |
2149 #ifdef QMAC_SPEAK_TO_ME |
2171 #ifdef QMAC_SPEAK_TO_ME |
2150 const int speak_keys = Qt::AltModifier | Qt::ShiftModifier; |
2172 const int speak_keys = Qt::AltModifier | Qt::ShiftModifier; |
2151 if(etype == QMouseEvent::MouseButtonDblClick && ((modifiers & speak_keys) == speak_keys)) { |
2173 if(etype == QMouseEvent::MouseButtonDblClick && ((modifiers & speak_keys) == speak_keys)) { |
2152 QVariant v = widget->property("displayText"); |
2174 QVariant v = widget->property("displayText"); |
2574 if (popup == qt_button_down) |
2596 if (popup == qt_button_down) |
2575 qt_button_down = 0; |
2597 qt_button_down = 0; |
2576 if (QApplicationPrivate::popupWidgets->isEmpty()) { // this was the last popup |
2598 if (QApplicationPrivate::popupWidgets->isEmpty()) { // this was the last popup |
2577 delete QApplicationPrivate::popupWidgets; |
2599 delete QApplicationPrivate::popupWidgets; |
2578 QApplicationPrivate::popupWidgets = 0; |
2600 QApplicationPrivate::popupWidgets = 0; |
2579 |
2601 |
2580 // Special case for Tool windows: since they are activated and deactived together |
2602 // Special case for Tool windows: since they are activated and deactived together |
2581 // with a normal window they never become the QApplicationPrivate::active_window. |
2603 // with a normal window they never become the QApplicationPrivate::active_window. |
2582 QWidget *appFocusWidget = QApplication::focusWidget(); |
2604 QWidget *appFocusWidget = QApplication::focusWidget(); |
2583 if (appFocusWidget && appFocusWidget->window()->windowType() == Qt::Tool) { |
2605 if (appFocusWidget && appFocusWidget->window()->windowType() == Qt::Tool) { |
2584 appFocusWidget->setFocus(Qt::PopupFocusReason); |
2606 appFocusWidget->setFocus(Qt::PopupFocusReason); |
2695 { |
2717 { |
2696 // FIXME: get from the system |
2718 // FIXME: get from the system |
2697 return QApplicationPrivate::keyboard_input_time; |
2719 return QApplicationPrivate::keyboard_input_time; |
2698 } |
2720 } |
2699 |
2721 |
|
2722 #ifndef QT_NO_WHEELEVENT |
2700 void QApplication::setWheelScrollLines(int n) |
2723 void QApplication::setWheelScrollLines(int n) |
2701 { |
2724 { |
2702 QApplicationPrivate::wheel_scroll_lines = n; |
2725 QApplicationPrivate::wheel_scroll_lines = n; |
2703 } |
2726 } |
2704 |
2727 |
2705 int QApplication::wheelScrollLines() |
2728 int QApplication::wheelScrollLines() |
2706 { |
2729 { |
2707 return QApplicationPrivate::wheel_scroll_lines; |
2730 return QApplicationPrivate::wheel_scroll_lines; |
2708 } |
2731 } |
|
2732 #endif |
2709 |
2733 |
2710 void QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable) |
2734 void QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable) |
2711 { |
2735 { |
2712 switch (effect) { |
2736 switch (effect) { |
2713 case Qt::UI_FadeMenu: |
2737 case Qt::UI_FadeMenu: |
2866 |
2890 |
2867 num = settings.value(QLatin1String("cursorFlashTime"), |
2891 num = settings.value(QLatin1String("cursorFlashTime"), |
2868 QApplication::cursorFlashTime()).toInt(); |
2892 QApplication::cursorFlashTime()).toInt(); |
2869 QApplication::setCursorFlashTime(num); |
2893 QApplication::setCursorFlashTime(num); |
2870 |
2894 |
|
2895 #ifndef QT_NO_WHEELEVENT |
2871 num = settings.value(QLatin1String("wheelScrollLines"), |
2896 num = settings.value(QLatin1String("wheelScrollLines"), |
2872 QApplication::wheelScrollLines()).toInt(); |
2897 QApplication::wheelScrollLines()).toInt(); |
2873 QApplication::setWheelScrollLines(num); |
2898 QApplication::setWheelScrollLines(num); |
|
2899 #endif |
2874 |
2900 |
2875 QString colorspec = settings.value(QLatin1String("colorSpec"), |
2901 QString colorspec = settings.value(QLatin1String("colorSpec"), |
2876 QVariant(QLatin1String("default"))).toString(); |
2902 QVariant(QLatin1String("default"))).toString(); |
2877 if (colorspec == QLatin1String("normal")) |
2903 if (colorspec == QLatin1String("normal")) |
2878 QApplication::setColorSpec(QApplication::NormalColor); |
2904 QApplication::setColorSpec(QApplication::NormalColor); |