48 #import <private/qcocoawindowcustomthemeframe_mac_p.h> |
48 #import <private/qcocoawindowcustomthemeframe_mac_p.h> |
49 |
49 |
50 #include <QtGui/QWidget> |
50 #include <QtGui/QWidget> |
51 |
51 |
52 QT_FORWARD_DECLARE_CLASS(QWidget); |
52 QT_FORWARD_DECLARE_CLASS(QWidget); |
53 QT_BEGIN_NAMESPACE |
|
54 extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); // qcocoaview.mm |
|
55 QT_END_NAMESPACE |
|
56 QT_USE_NAMESPACE |
53 QT_USE_NAMESPACE |
57 |
|
58 |
|
59 @interface NSWindow (QtCoverForHackWithCategory) |
|
60 + (Class)frameViewClassForStyleMask:(NSUInteger)styleMask; |
|
61 @end |
|
62 |
|
63 |
54 |
64 @implementation QT_MANGLE_NAMESPACE(QCocoaPanel) |
55 @implementation QT_MANGLE_NAMESPACE(QCocoaPanel) |
65 |
56 |
66 - (BOOL)canBecomeKeyWindow |
|
67 { |
|
68 QWidget *widget = [self QT_MANGLE_NAMESPACE(qt_qwidget)]; |
|
69 |
|
70 bool isToolTip = (widget->windowType() == Qt::ToolTip); |
|
71 bool isPopup = (widget->windowType() == Qt::Popup); |
|
72 return !(isPopup || isToolTip); |
|
73 } |
|
74 |
|
75 /*********************************************************************** |
57 /*********************************************************************** |
76 BEGIN Copy and Paste between QCocoaWindow and QCocoaPanel |
58 Copy and Paste between QCocoaWindow and QCocoaPanel |
77 This is a bit unfortunate, but thanks to the dynamic dispatch we |
59 This is a bit unfortunate, but thanks to the dynamic dispatch we |
78 have to duplicate this code or resort to really silly forwarding methods |
60 have to duplicate this code or resort to really silly forwarding methods |
79 **************************************************************************/ |
61 **************************************************************************/ |
80 |
62 #include "qcocoasharedwindowmethods_mac_p.h" |
81 /* |
|
82 The methods keyDown, keyUp, and flagsChanged... These really shouldn't ever |
|
83 get hit. We automatically say we can be first responder if we are a window. |
|
84 So, the handling should get handled by the view. This is here more as a |
|
85 last resort (i.e., this is code that can potentially be removed). |
|
86 */ |
|
87 |
|
88 - (void)toggleToolbarShown:(id)sender |
|
89 { |
|
90 macSendToolbarChangeEvent([self QT_MANGLE_NAMESPACE(qt_qwidget)]); |
|
91 [super toggleToolbarShown:sender]; |
|
92 } |
|
93 |
|
94 - (void)keyDown:(NSEvent *)theEvent |
|
95 { |
|
96 bool keyOK = qt_dispatchKeyEvent(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]); |
|
97 if (!keyOK) |
|
98 [super keyDown:theEvent]; |
|
99 } |
|
100 |
|
101 - (void)keyUp:(NSEvent *)theEvent |
|
102 { |
|
103 bool keyOK = qt_dispatchKeyEvent(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]); |
|
104 if (!keyOK) |
|
105 [super keyUp:theEvent]; |
|
106 } |
|
107 |
|
108 - (void)flagsChanged:(NSEvent *)theEvent |
|
109 { |
|
110 qt_dispatchModifiersChanged(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]); |
|
111 [super flagsChanged:theEvent]; |
|
112 } |
|
113 |
|
114 |
|
115 - (void)tabletProximity:(NSEvent *)tabletEvent |
|
116 { |
|
117 qt_dispatchTabletProximityEvent(tabletEvent); |
|
118 } |
|
119 |
|
120 - (void)sendEvent:(NSEvent *)event |
|
121 { |
|
122 QWidget *widget = [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] qt_qwidgetForWindow:self]; |
|
123 |
|
124 // Cocoa can hold onto the window after we've disavowed its knowledge. So, |
|
125 // if we get sent an event afterwards just have it go through the super's |
|
126 // version and don't do any stuff with Qt. |
|
127 if (!widget) { |
|
128 [super sendEvent:event]; |
|
129 return; |
|
130 } |
|
131 [self retain]; |
|
132 QT_MANGLE_NAMESPACE(QCocoaView) *view = static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(qt_mac_nativeview_for(widget)); |
|
133 Qt::MouseButton mouseButton = cocoaButton2QtButton([event buttonNumber]); |
|
134 |
|
135 // sometimes need to redirect mouse events to the popup. |
|
136 QWidget *popup = qAppInstance()->activePopupWidget(); |
|
137 if (popup && popup != widget) { |
|
138 switch([event type]) |
|
139 { |
|
140 case NSLeftMouseDown: |
|
141 qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonPress, mouseButton); |
|
142 // Don't call super here. This prevents us from getting the mouseUp event, |
|
143 // which we need to send even if the mouseDown event was not accepted. |
|
144 // (this is standard Qt behavior.) |
|
145 break; |
|
146 case NSRightMouseDown: |
|
147 case NSOtherMouseDown: |
|
148 if (!qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonPress, mouseButton)) |
|
149 [super sendEvent:event]; |
|
150 break; |
|
151 case NSLeftMouseUp: |
|
152 case NSRightMouseUp: |
|
153 case NSOtherMouseUp: |
|
154 if (!qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonRelease, mouseButton)) |
|
155 [super sendEvent:event]; |
|
156 break; |
|
157 case NSMouseMoved: |
|
158 qt_mac_handleMouseEvent(view, event, QEvent::MouseMove, Qt::NoButton); |
|
159 break; |
|
160 case NSLeftMouseDragged: |
|
161 case NSRightMouseDragged: |
|
162 case NSOtherMouseDragged: |
|
163 [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->view = view; |
|
164 [QT_MANGLE_NAMESPACE(QCocoaView) currentMouseEvent]->theEvent = event; |
|
165 if (!qt_mac_handleMouseEvent(view, event, QEvent::MouseMove, mouseButton)) |
|
166 [super sendEvent:event]; |
|
167 break; |
|
168 default: |
|
169 [super sendEvent:event]; |
|
170 break; |
|
171 } |
|
172 } else { |
|
173 [super sendEvent:event]; |
|
174 } |
|
175 qt_mac_dispatchNCMouseMessage(self, event, [self QT_MANGLE_NAMESPACE(qt_qwidget)], leftButtonIsRightButton); |
|
176 |
|
177 |
|
178 [self release]; |
|
179 } |
|
180 |
|
181 - (BOOL)makeFirstResponder:(NSResponder *)responder |
|
182 { |
|
183 // For some reason Cocoa wants to flip the first responder |
|
184 // when Qt doesn't want to, sorry, but "No" :-) |
|
185 if (responder == nil && qApp->focusWidget()) |
|
186 return NO; |
|
187 return [super makeFirstResponder:responder]; |
|
188 } |
|
189 |
|
190 /*********************************************************************** |
|
191 END Copy and Paste between QCocoaWindow and QCocoaPanel |
|
192 ***********************************************************************/ |
|
193 + (Class)frameViewClassForStyleMask:(NSUInteger)styleMask |
|
194 { |
|
195 if (styleMask & QtMacCustomizeWindow) |
|
196 return [QT_MANGLE_NAMESPACE(QCocoaWindowCustomThemeFrame) class]; |
|
197 return [super frameViewClassForStyleMask:styleMask]; |
|
198 } |
|
199 |
63 |
200 @end |
64 @end |
201 #endif |
65 #endif |