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