137 } |
137 } |
138 |
138 |
139 extern bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); // qapplication.cpp; |
139 extern bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); // qapplication.cpp; |
140 extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); // qcocoaview.mm |
140 extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); // qcocoaview.mm |
141 extern QWidget * mac_mouse_grabber; |
141 extern QWidget * mac_mouse_grabber; |
|
142 extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp |
142 |
143 |
143 void macWindowFade(void * /*OSWindowRef*/ window, float durationSeconds) |
144 void macWindowFade(void * /*OSWindowRef*/ window, float durationSeconds) |
144 { |
145 { |
145 OSWindowRef wnd = static_cast<OSWindowRef>(window); |
146 OSWindowRef wnd = static_cast<OSWindowRef>(window); |
146 if (wnd) { |
147 if (wnd) { |
746 NSPoint windowPoint = [event locationInWindow]; |
747 NSPoint windowPoint = [event locationInWindow]; |
747 NSPoint globalPoint = [[event window] convertBaseToScreen:windowPoint]; |
748 NSPoint globalPoint = [[event window] convertBaseToScreen:windowPoint]; |
748 NSRect frameRect = [window frame]; |
749 NSRect frameRect = [window frame]; |
749 if (fakeNCEvents || NSMouseInRect(globalPoint, frameRect, NO)) { |
750 if (fakeNCEvents || NSMouseInRect(globalPoint, frameRect, NO)) { |
750 NSRect contentRect = [window contentRectForFrameRect:frameRect]; |
751 NSRect contentRect = [window contentRectForFrameRect:frameRect]; |
751 if (fakeNCEvents || !NSMouseInRect(globalPoint, contentRect, NO)) { |
752 qglobalPoint = QPoint(flipPoint(globalPoint).toPoint()); |
|
753 QWidget *w = widgetToGetEvent->childAt(widgetToGetEvent->mapFromGlobal(qglobalPoint)); |
|
754 // check that the mouse pointer is on the non-client area and |
|
755 // there are not widgets in it. |
|
756 if (fakeNCEvents || (!NSMouseInRect(globalPoint, contentRect, NO) && !w)) { |
752 qglobalPoint = QPoint(flipPoint(globalPoint).toPoint()); |
757 qglobalPoint = QPoint(flipPoint(globalPoint).toPoint()); |
753 qlocalPoint = widgetToGetEvent->mapFromGlobal(qglobalPoint); |
758 qlocalPoint = widgetToGetEvent->mapFromGlobal(qglobalPoint); |
754 processThisEvent = true; |
759 processThisEvent = true; |
755 } |
760 } |
756 } |
761 } |
757 } |
762 } |
758 } |
763 } |
759 // This is not an NC area mouse message. |
764 // This is not an NC area mouse message. |
760 if (!processThisEvent) |
765 if (!processThisEvent) |
761 return; |
766 return; |
|
767 |
762 // If the window is frame less, generate fake mouse events instead. (floating QToolBar) |
768 // If the window is frame less, generate fake mouse events instead. (floating QToolBar) |
763 if (fakeNCEvents && (widgetToGetEvent->window()->windowFlags() & Qt::FramelessWindowHint)) |
769 // or if someone already got an explicit or implicit grab |
|
770 if (mac_mouse_grabber || qt_button_down || |
|
771 (fakeNCEvents && (widgetToGetEvent->window()->windowFlags() & Qt::FramelessWindowHint))) |
764 fakeMouseEvents = true; |
772 fakeMouseEvents = true; |
765 |
773 |
766 Qt::MouseButton button; |
774 Qt::MouseButton button; |
767 QEvent::Type eventType; |
775 QEvent::Type eventType; |
768 // Convert to Qt::Event type |
776 // Convert to Qt::Event type |
836 if (button == Qt::LeftButton && leftButtonIsRightButton) { |
844 if (button == Qt::LeftButton && leftButtonIsRightButton) { |
837 button = Qt::RightButton; |
845 button = Qt::RightButton; |
838 leftButtonIsRightButton = false; |
846 leftButtonIsRightButton = false; |
839 } |
847 } |
840 } |
848 } |
|
849 |
841 QMouseEvent qme(eventType, qlocalPoint, qglobalPoint, button, button, keyMods); |
850 QMouseEvent qme(eventType, qlocalPoint, qglobalPoint, button, button, keyMods); |
842 qt_sendSpontaneousEvent(widgetToGetEvent, &qme); |
851 qt_sendSpontaneousEvent(widgetToGetEvent, &qme); |
|
852 |
|
853 // We don't need to set the implicit grab widget here because we won't |
|
854 // reach this point if then event type is Press over a Qt widget. |
|
855 // However we might need to unset it if the event is Release. |
|
856 if (eventType == QEvent::MouseButtonRelease) |
|
857 qt_button_down = 0; |
843 #endif |
858 #endif |
844 } |
859 } |
845 |
860 |
846 bool qt_mac_handleMouseEvent(void * /* NSView * */view, void * /* NSEvent * */event, QEvent::Type eventType, Qt::MouseButton button) |
861 bool qt_mac_handleMouseEvent(void * /* NSView * */view, void * /* NSEvent * */event, QEvent::Type eventType, Qt::MouseButton button) |
847 { |
862 { |
871 NSPoint globalPoint = [[theEvent window] convertBaseToScreen:windowPoint]; |
886 NSPoint globalPoint = [[theEvent window] convertBaseToScreen:windowPoint]; |
872 |
887 |
873 // Find the widget that *should* get the event (e.g., maybe it was a pop-up, |
888 // Find the widget that *should* get the event (e.g., maybe it was a pop-up, |
874 // they always get the mouse event). |
889 // they always get the mouse event). |
875 QWidget *qwidget = [theView qt_qwidget]; |
890 QWidget *qwidget = [theView qt_qwidget]; |
876 QWidget *widgetToGetMouse = qwidget; |
891 QWidget *widgetToGetMouse = 0; |
|
892 NSView *tmpView = 0; |
877 QWidget *popup = qAppInstance()->activePopupWidget(); |
893 QWidget *popup = qAppInstance()->activePopupWidget(); |
878 NSView *tmpView = theView; |
894 QPoint qglobalPoint(flipPoint(globalPoint).toPoint()); |
879 if (mac_mouse_grabber && mac_mouse_grabber != widgetToGetMouse) { |
895 |
880 widgetToGetMouse = mac_mouse_grabber; |
896 if (popup) { |
881 tmpView = qt_mac_nativeview_for(widgetToGetMouse); |
|
882 } |
|
883 |
|
884 if (popup && popup != qwidget->window()) { |
|
885 widgetToGetMouse = popup; |
897 widgetToGetMouse = popup; |
886 tmpView = qt_mac_nativeview_for(popup); |
898 tmpView = qt_mac_nativeview_for(popup); |
887 windowPoint = [[tmpView window] convertScreenToBase:globalPoint]; |
899 windowPoint = [[tmpView window] convertScreenToBase:globalPoint]; |
888 |
900 |
889 QPoint qWindowPoint(windowPoint.x, windowPoint.y); |
901 QPoint qWindowPoint(windowPoint.x, windowPoint.y); |
897 if (!tmpView) |
909 if (!tmpView) |
898 return false; |
910 return false; |
899 widgetToGetMouse = |
911 widgetToGetMouse = |
900 [static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(tmpView) qt_qwidget]; |
912 [static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(tmpView) qt_qwidget]; |
901 } |
913 } |
902 } |
914 } else { |
|
915 extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp |
|
916 QPoint pos; |
|
917 widgetToGetMouse = QApplicationPrivate::pickMouseReceiver(qwidget, qglobalPoint, |
|
918 pos, eventType, |
|
919 button, qt_button_down, 0); |
|
920 if (widgetToGetMouse) |
|
921 tmpView = qt_mac_nativeview_for(widgetToGetMouse); |
|
922 } |
|
923 if (!widgetToGetMouse) |
|
924 return false; |
903 |
925 |
904 NSPoint localPoint = [tmpView convertPoint:windowPoint fromView:nil]; |
926 NSPoint localPoint = [tmpView convertPoint:windowPoint fromView:nil]; |
905 QPoint qlocalPoint(localPoint.x, localPoint.y); |
927 QPoint qlocalPoint(localPoint.x, localPoint.y); |
906 |
928 |
907 EventRef carbonEvent = static_cast<EventRef>(const_cast<void *>([theEvent eventRef])); |
929 EventRef carbonEvent = static_cast<EventRef>(const_cast<void *>([theEvent eventRef])); |
943 [theView qt_setLeftButtonIsRightButton: false]; |
965 [theView qt_setLeftButtonIsRightButton: false]; |
944 } |
966 } |
945 break; |
967 break; |
946 } |
968 } |
947 [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->localPoint = localPoint; |
969 [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->localPoint = localPoint; |
948 QPoint qglobalPoint(flipPoint(globalPoint).toPoint()); |
|
949 QMouseEvent qme(eventType, qlocalPoint, qglobalPoint, button, buttons, keyMods); |
970 QMouseEvent qme(eventType, qlocalPoint, qglobalPoint, button, buttons, keyMods); |
950 qt_sendSpontaneousEvent(widgetToGetMouse, &qme); |
971 qt_sendSpontaneousEvent(widgetToGetMouse, &qme); |
951 if (eventType == QEvent::MouseButtonPress && button == Qt::RightButton) { |
972 if (eventType == QEvent::MouseButtonPress && button == Qt::RightButton) { |
952 QContextMenuEvent qcme(QContextMenuEvent::Mouse, qlocalPoint, qglobalPoint, keyMods); |
973 QContextMenuEvent qcme(QContextMenuEvent::Mouse, qlocalPoint, qglobalPoint, keyMods); |
953 qt_sendSpontaneousEvent(widgetToGetMouse, &qcme); |
974 qt_sendSpontaneousEvent(widgetToGetMouse, &qcme); |
954 } |
975 } |
955 return qme.isAccepted(); |
976 return true; |
956 #endif |
977 #endif |
957 } |
978 } |
958 |
979 |
959 bool qt_mac_handleTabletEvent(void * /*QCocoaView * */view, void * /*NSEvent * */tabletEvent) |
980 bool qt_mac_handleTabletEvent(void * /*QCocoaView * */view, void * /*NSEvent * */tabletEvent) |
960 { |
981 { |
1150 #else |
1171 #else |
1151 return [[NSScreen mainScreen] userSpaceScaleFactor]; |
1172 return [[NSScreen mainScreen] userSpaceScaleFactor]; |
1152 #endif |
1173 #endif |
1153 } |
1174 } |
1154 |
1175 |
1155 QString qt_mac_get_pasteboardString() |
1176 QString qt_mac_get_pasteboardString(OSPasteboardRef paste) |
1156 { |
1177 { |
1157 QMacCocoaAutoReleasePool pool; |
1178 QMacCocoaAutoReleasePool pool; |
1158 NSPasteboard *pb = [NSPasteboard generalPasteboard]; |
1179 NSPasteboard *pb = nil; |
1159 NSString *text = [pb stringForType:NSStringPboardType]; |
1180 CFStringRef pbname; |
1160 if (text) { |
1181 if (PasteboardCopyName (paste, &pbname)) { |
1161 return qt_mac_NSStringToQString(text); |
1182 pb = [NSPasteboard generalPasteboard]; |
1162 } else { |
1183 } else { |
1163 return QString(); |
1184 pb = [NSPasteboard pasteboardWithName:reinterpret_cast<const NSString *>(pbname)]; |
1164 } |
1185 CFRelease (pbname); |
|
1186 } |
|
1187 if (pb) { |
|
1188 NSString *text = [pb stringForType:NSStringPboardType]; |
|
1189 if (text) |
|
1190 return qt_mac_NSStringToQString(text); |
|
1191 } |
|
1192 return QString(); |
1165 } |
1193 } |
1166 |
1194 |
1167 QPixmap qt_mac_convert_iconref(const IconRef icon, int width, int height) |
1195 QPixmap qt_mac_convert_iconref(const IconRef icon, int width, int height) |
1168 { |
1196 { |
1169 QPixmap ret(width, height); |
1197 QPixmap ret(width, height); |