]>
Commit | Line | Data |
---|---|---|
a15eb0a5 SC |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: mac/toplevel.cpp | |
d66c3960 SC |
3 | // Purpose: implements wxTopLevelWindow for Mac |
4 | // Author: Stefan Csomor | |
a15eb0a5 SC |
5 | // Modified by: |
6 | // Created: 24.09.01 | |
7 | // RCS-ID: $Id$ | |
d66c3960 | 8 | // Copyright: (c) 2001-2004 Stefan Csomor |
65571936 | 9 | // License: wxWindows licence |
a15eb0a5 SC |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
3d1a4878 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
a15eb0a5 SC |
21 | #pragma implementation "toplevel.h" |
22 | #endif | |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
31 | #ifndef WX_PRECOMP | |
32 | #include "wx/app.h" | |
33 | #include "wx/toplevel.h" | |
422644a3 | 34 | #include "wx/frame.h" |
a15eb0a5 SC |
35 | #include "wx/string.h" |
36 | #include "wx/log.h" | |
37 | #include "wx/intl.h" | |
37ec2bd3 | 38 | #include "wx/settings.h" |
2d17efa9 | 39 | #include "wx/strconv.h" |
179e085f | 40 | #include "wx/control.h" |
a15eb0a5 SC |
41 | #endif //WX_PRECOMP |
42 | ||
5f0b2f22 | 43 | #include "wx/mac/uma.h" |
422644a3 | 44 | #include "wx/mac/aga.h" |
7c091673 | 45 | #include "wx/app.h" |
5f0b2f22 | 46 | #include "wx/tooltip.h" |
a07c1212 | 47 | #include "wx/dnd.h" |
1f90939c SC |
48 | #if wxUSE_SYSTEM_OPTIONS |
49 | #include "wx/sysopt.h" | |
50 | #endif | |
5f0b2f22 | 51 | |
7f0c3a63 | 52 | #include <ToolUtils.h> |
dd49c691 | 53 | |
eab19a7c RN |
54 | //For targeting OSX |
55 | #include "wx/mac/private.h" | |
56 | ||
a15eb0a5 SC |
57 | // ---------------------------------------------------------------------------- |
58 | // globals | |
59 | // ---------------------------------------------------------------------------- | |
60 | ||
61 | // list of all frames and modeless dialogs | |
32b5be3d RR |
62 | wxWindowList wxModelessWindows; |
63 | ||
6a7e6411 RD |
64 | static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param); |
65 | ||
a15eb0a5 SC |
66 | // ============================================================================ |
67 | // wxTopLevelWindowMac implementation | |
68 | // ============================================================================ | |
69 | ||
facd6764 SC |
70 | BEGIN_EVENT_TABLE(wxTopLevelWindowMac, wxTopLevelWindowBase) |
71 | END_EVENT_TABLE() | |
72 | ||
73 | ||
851b3a88 SC |
74 | // --------------------------------------------------------------------------- |
75 | // Carbon Events | |
76 | // --------------------------------------------------------------------------- | |
77 | ||
851b3a88 SC |
78 | extern long wxMacTranslateKey(unsigned char key, unsigned char code) ; |
79 | ||
1542ea39 | 80 | static const EventTypeSpec eventList[] = |
851b3a88 | 81 | { |
facd6764 | 82 | // TODO remove control related event like key and mouse (except for WindowLeave events) |
949cb163 | 83 | #if 1 |
851b3a88 | 84 | { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } , |
c5c9378c | 85 | |
e40298d5 | 86 | { kEventClassKeyboard, kEventRawKeyDown } , |
c5c9378c SC |
87 | { kEventClassKeyboard, kEventRawKeyRepeat } , |
88 | { kEventClassKeyboard, kEventRawKeyUp } , | |
89 | { kEventClassKeyboard, kEventRawKeyModifiersChanged } , | |
facd6764 | 90 | #endif |
c5c9378c | 91 | |
16a76184 | 92 | { kEventClassWindow , kEventWindowShown } , |
851b3a88 SC |
93 | { kEventClassWindow , kEventWindowActivated } , |
94 | { kEventClassWindow , kEventWindowDeactivated } , | |
95 | { kEventClassWindow , kEventWindowBoundsChanging } , | |
96 | { kEventClassWindow , kEventWindowBoundsChanged } , | |
97 | { kEventClassWindow , kEventWindowClose } , | |
98 | ||
facd6764 SC |
99 | // we have to catch these events on the toplevel window level, as controls don't get the |
100 | // raw mouse events anymore | |
101 | ||
851b3a88 SC |
102 | { kEventClassMouse , kEventMouseDown } , |
103 | { kEventClassMouse , kEventMouseUp } , | |
de127c69 | 104 | { kEventClassMouse , kEventMouseWheelMoved } , |
851b3a88 SC |
105 | { kEventClassMouse , kEventMouseMoved } , |
106 | { kEventClassMouse , kEventMouseDragged } , | |
851b3a88 SC |
107 | } ; |
108 | ||
109 | static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
110 | { | |
111 | OSStatus result = eventNotHandledErr ; | |
851b3a88 | 112 | |
c5c9378c | 113 | wxWindow* focus = wxWindow::FindFocus() ; |
e40298d5 | 114 | char charCode ; |
1542ea39 | 115 | UInt32 keyCode ; |
c5c9378c | 116 | UInt32 modifiers ; |
e40298d5 | 117 | Point point ; |
c5c9378c SC |
118 | |
119 | EventRef rawEvent ; | |
1542ea39 | 120 | |
c5c9378c | 121 | GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ; |
1542ea39 | 122 | |
e40298d5 JS |
123 | GetEventParameter( rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); |
124 | GetEventParameter( rawEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
125 | GetEventParameter( rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); | |
126 | GetEventParameter( rawEvent, kEventParamMouseLocation, typeQDPoint, NULL, | |
127 | sizeof( Point ), NULL, &point ); | |
128 | ||
e40298d5 JS |
129 | switch ( GetEventKind( event ) ) |
130 | { | |
131 | case kEventTextInputUnicodeForKeyEvent : | |
ace07c80 | 132 | // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not |
5d2e69e8 | 133 | // get its own kEventTextInputUnicodeForKeyEvent, so we route back the |
ace07c80 SC |
134 | wxControl* control = wxDynamicCast( focus , wxControl ) ; |
135 | if ( control ) | |
136 | { | |
facd6764 | 137 | ControlRef macControl = (ControlRef) control->GetHandle() ; |
ace07c80 SC |
138 | if ( macControl ) |
139 | { | |
140 | ::HandleControlKey( macControl , keyCode , charCode , modifiers ) ; | |
141 | result = noErr ; | |
142 | } | |
143 | } | |
144 | /* | |
145 | // this may lead to double events sent to a window in case all handlers have skipped the key down event | |
77a4354e VZ |
146 | UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; |
147 | UInt32 message = (keyCode << 8) + charCode; | |
148 | ||
1542ea39 | 149 | if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( |
e40298d5 JS |
150 | focus , message , modifiers , when , point.h , point.v ) ) |
151 | { | |
152 | result = noErr ; | |
153 | } | |
ace07c80 | 154 | */ |
e40298d5 JS |
155 | break ; |
156 | } | |
c5c9378c SC |
157 | |
158 | return result ; | |
159 | } | |
160 | ||
161 | static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
162 | { | |
163 | OSStatus result = eventNotHandledErr ; | |
b3bd613a RR |
164 | // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl) |
165 | // FindFocus does not return the actual focus window,but the enclosing window | |
166 | wxWindow* focus = wxWindow::DoFindFocus(); | |
92a7272f SC |
167 | if ( focus == NULL ) |
168 | return result ; | |
169 | ||
e40298d5 | 170 | char charCode ; |
2d17efa9 | 171 | wxChar uniChar = 0 ; |
1542ea39 | 172 | UInt32 keyCode ; |
c5c9378c | 173 | UInt32 modifiers ; |
e40298d5 JS |
174 | Point point ; |
175 | UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; | |
176 | ||
2d17efa9 SC |
177 | #if wxUSE_UNICODE |
178 | UInt32 dataSize = 0 ; | |
179 | if ( GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, 0 , &dataSize , NULL ) == noErr ) | |
180 | { | |
181 | UniChar buf[2] ; | |
182 | ||
183 | UniChar* charBuf = buf ; | |
184 | ||
185 | if ( dataSize > 4 ) | |
186 | charBuf = new UniChar[ dataSize / sizeof( UniChar) ] ; | |
187 | GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, dataSize , NULL , charBuf ) ; | |
188 | #if SIZEOF_WCHAR_T == 2 | |
189 | uniChar = charBuf[0] ; | |
190 | #else | |
191 | wxMBConvUTF16BE converter ; | |
192 | converter.MB2WC( &uniChar , (const char*)charBuf , 1 ) ; | |
193 | #endif | |
194 | if ( dataSize > 4 ) | |
195 | delete[] charBuf ; | |
196 | } | |
197 | #endif | |
198 | ||
e40298d5 JS |
199 | GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); |
200 | GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
201 | GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); | |
202 | GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, | |
203 | sizeof( Point ), NULL, &point ); | |
2d17efa9 | 204 | |
e40298d5 JS |
205 | UInt32 message = (keyCode << 8) + charCode; |
206 | switch( GetEventKind( event ) ) | |
207 | { | |
208 | case kEventRawKeyRepeat : | |
209 | case kEventRawKeyDown : | |
e40298d5 | 210 | { |
404f1d80 SC |
211 | WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ; |
212 | WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ; | |
213 | wxTheApp->MacSetCurrentEvent( event , handler ) ; | |
214 | if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( | |
2d17efa9 | 215 | focus , message , modifiers , when , point.h , point.v , uniChar ) ) |
404f1d80 SC |
216 | { |
217 | result = noErr ; | |
218 | } | |
219 | wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ; | |
e40298d5 JS |
220 | } |
221 | break ; | |
222 | case kEventRawKeyUp : | |
1542ea39 | 223 | if ( (focus != NULL) && wxTheApp->MacSendKeyUpEvent( |
2d17efa9 | 224 | focus , message , modifiers , when , point.h , point.v , uniChar ) ) |
e40298d5 JS |
225 | { |
226 | result = noErr ; | |
227 | } | |
228 | break ; | |
229 | case kEventRawKeyModifiersChanged : | |
230 | { | |
231 | wxKeyEvent event(wxEVT_KEY_DOWN); | |
232 | ||
233 | event.m_shiftDown = modifiers & shiftKey; | |
234 | event.m_controlDown = modifiers & controlKey; | |
235 | event.m_altDown = modifiers & optionKey; | |
236 | event.m_metaDown = modifiers & cmdKey; | |
2d17efa9 SC |
237 | #if wxUSE_UNICODE |
238 | event.m_uniChar = uniChar ; | |
239 | #endif | |
e40298d5 JS |
240 | event.m_x = point.h; |
241 | event.m_y = point.v; | |
687706f5 | 242 | event.SetTimestamp(when); |
e40298d5 JS |
243 | event.SetEventObject(focus); |
244 | ||
2a1f999f | 245 | if ( focus && (modifiers ^ wxApp::s_lastModifiers ) & controlKey ) |
e40298d5 JS |
246 | { |
247 | event.m_keyCode = WXK_CONTROL ; | |
248 | event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
249 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
250 | } | |
2a1f999f | 251 | if ( focus && (modifiers ^ wxApp::s_lastModifiers ) & shiftKey ) |
e40298d5 JS |
252 | { |
253 | event.m_keyCode = WXK_SHIFT ; | |
254 | event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
255 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
256 | } | |
2a1f999f | 257 | if ( focus && (modifiers ^ wxApp::s_lastModifiers ) & optionKey ) |
e40298d5 JS |
258 | { |
259 | event.m_keyCode = WXK_ALT ; | |
260 | event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
261 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
262 | } | |
2a1f999f | 263 | if ( focus && (modifiers ^ wxApp::s_lastModifiers ) & cmdKey ) |
b7aec135 SC |
264 | { |
265 | event.m_keyCode = WXK_COMMAND ; | |
266 | event.SetEventType( ( modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
267 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
268 | } | |
2a1f999f | 269 | wxApp::s_lastModifiers = modifiers ; |
e40298d5 JS |
270 | } |
271 | break ; | |
272 | } | |
851b3a88 SC |
273 | |
274 | return result ; | |
275 | } | |
276 | ||
facd6764 SC |
277 | // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr |
278 | // for windows that we didn't create (like eg Scrollbars in a databrowser) , or for controls where we did not handle the | |
279 | // mouse down at all | |
851b3a88 | 280 | |
facd6764 | 281 | // This handler can also be called from app level where data (ie target window) may be null or a non wx window |
1542ea39 | 282 | |
facd6764 | 283 | wxWindow* g_MacLastWindow = NULL ; |
a3195b73 | 284 | |
86a9144f SC |
285 | static EventMouseButton lastButton = 0 ; |
286 | ||
facd6764 SC |
287 | static void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent ) |
288 | { | |
289 | UInt32 modifiers = cEvent.GetParameter<UInt32>(kEventParamKeyModifiers, typeUInt32) ; | |
290 | Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ; | |
67245665 | 291 | |
facd6764 SC |
292 | // this parameter are not given for all events |
293 | EventMouseButton button = 0 ; | |
294 | UInt32 clickCount = 0 ; | |
295 | cEvent.GetParameter<EventMouseButton>(kEventParamMouseButton, typeMouseButton , &button) ; | |
296 | cEvent.GetParameter<UInt32>(kEventParamClickCount, typeUInt32 , &clickCount ) ; | |
297 | ||
298 | wxevent.m_x = screenMouseLocation.h; | |
299 | wxevent.m_y = screenMouseLocation.v; | |
300 | wxevent.m_shiftDown = modifiers & shiftKey; | |
301 | wxevent.m_controlDown = modifiers & controlKey; | |
302 | wxevent.m_altDown = modifiers & optionKey; | |
303 | wxevent.m_metaDown = modifiers & cmdKey; | |
304 | wxevent.SetTimestamp( cEvent.GetTicks() ) ; | |
305 | // a control click is interpreted as a right click | |
306 | if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) ) | |
851b3a88 | 307 | { |
facd6764 SC |
308 | button = kEventMouseButtonSecondary ; |
309 | } | |
86a9144f SC |
310 | |
311 | // we must make sure that our synthetic 'right' button corresponds in | |
312 | // mouse down, moved and mouse up, and does not deliver a right down and left up | |
313 | ||
314 | if ( cEvent.GetKind() == kEventMouseDown ) | |
315 | lastButton = button ; | |
4e4e6dce SC |
316 | |
317 | if ( button == 0 ) | |
318 | lastButton = 0 ; | |
86a9144f SC |
319 | else if ( lastButton ) |
320 | button = lastButton ; | |
facd6764 SC |
321 | |
322 | // determinate the correct down state, wx does not want a 'down' for a mouseUp event, while mac delivers | |
323 | // this button | |
324 | if ( button != 0 && cEvent.GetKind() != kEventMouseUp ) | |
325 | { | |
326 | switch( button ) | |
e40298d5 | 327 | { |
facd6764 SC |
328 | case kEventMouseButtonPrimary : |
329 | wxevent.m_leftDown = true ; | |
e40298d5 | 330 | break ; |
facd6764 SC |
331 | case kEventMouseButtonSecondary : |
332 | wxevent.m_rightDown = true ; | |
e40298d5 | 333 | break ; |
facd6764 SC |
334 | case kEventMouseButtonTertiary : |
335 | wxevent.m_middleDown = true ; | |
e40298d5 | 336 | break ; |
facd6764 SC |
337 | } |
338 | } | |
90ff87d7 SC |
339 | // translate into wx types |
340 | switch ( cEvent.GetKind() ) | |
facd6764 | 341 | { |
90ff87d7 SC |
342 | case kEventMouseDown : |
343 | switch( button ) | |
344 | { | |
345 | case kEventMouseButtonPrimary : | |
346 | wxevent.SetEventType(clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ; | |
347 | break ; | |
348 | case kEventMouseButtonSecondary : | |
349 | wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ; | |
350 | break ; | |
351 | case kEventMouseButtonTertiary : | |
352 | wxevent.SetEventType(clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ; | |
353 | break ; | |
354 | } | |
355 | break ; | |
356 | case kEventMouseUp : | |
357 | switch( button ) | |
358 | { | |
359 | case kEventMouseButtonPrimary : | |
360 | wxevent.SetEventType( wxEVT_LEFT_UP ) ; | |
361 | break ; | |
362 | case kEventMouseButtonSecondary : | |
363 | wxevent.SetEventType( wxEVT_RIGHT_UP ) ; | |
364 | break ; | |
365 | case kEventMouseButtonTertiary : | |
366 | wxevent.SetEventType( wxEVT_MIDDLE_UP ) ; | |
367 | break ; | |
368 | } | |
369 | break ; | |
2cce9b11 JS |
370 | case kEventMouseWheelMoved : |
371 | { | |
facd6764 SC |
372 | wxevent.SetEventType(wxEVT_MOUSEWHEEL ) ; |
373 | ||
374 | // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ; | |
375 | SInt32 delta = cEvent.GetParameter<SInt32>(kEventParamMouseWheelDelta, typeLongInteger) ; | |
376 | ||
377 | wxevent.m_wheelRotation = delta; | |
378 | wxevent.m_wheelDelta = 1; | |
379 | wxevent.m_linesPerAction = 1; | |
90ff87d7 | 380 | break ; |
2cce9b11 | 381 | } |
90ff87d7 | 382 | default : |
facd6764 | 383 | wxevent.SetEventType(wxEVT_MOTION ) ; |
90ff87d7 SC |
384 | break ; |
385 | } | |
facd6764 SC |
386 | } |
387 | ||
789ae0cf | 388 | ControlRef wxMacFindSubControl( wxTopLevelWindowMac* toplevelWindow, Point location , ControlRef superControl , ControlPartCode *outPart ) |
facd6764 SC |
389 | { |
390 | if ( superControl ) | |
391 | { | |
392 | UInt16 childrenCount = 0 ; | |
393 | OSStatus err = CountSubControls( superControl , &childrenCount ) ; | |
394 | if ( err == errControlIsNotEmbedder ) | |
395 | return NULL ; | |
396 | wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ; | |
397 | ||
398 | for ( UInt16 i = childrenCount ; i >=1 ; --i ) | |
399 | { | |
400 | ControlHandle sibling ; | |
401 | err = GetIndexedSubControl( superControl , i , & sibling ) ; | |
402 | if ( err == errControlIsNotEmbedder ) | |
403 | return NULL ; | |
404 | ||
405 | wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ; | |
406 | if ( IsControlVisible( sibling ) ) | |
407 | { | |
408 | Rect r ; | |
d6fd667b | 409 | UMAGetControlBoundsInWindowCoords( sibling , &r ) ; |
facd6764 | 410 | if ( MacPtInRect( location , &r ) ) |
de127c69 | 411 | { |
789ae0cf | 412 | ControlHandle child = wxMacFindSubControl( toplevelWindow , location , sibling , outPart ) ; |
facd6764 SC |
413 | if ( child ) |
414 | return child ; | |
415 | else | |
de127c69 | 416 | { |
d6fd667b | 417 | Point testLocation = location ; |
789ae0cf SC |
418 | |
419 | if ( toplevelWindow && toplevelWindow->MacUsesCompositing() ) | |
420 | { | |
421 | testLocation.h -= r.left ; | |
422 | testLocation.v -= r.top ; | |
423 | } | |
424 | ||
d6fd667b | 425 | *outPart = TestControl( sibling , testLocation ) ; |
facd6764 | 426 | return sibling ; |
de127c69 GD |
427 | } |
428 | } | |
facd6764 | 429 | } |
e40298d5 JS |
430 | } |
431 | } | |
facd6764 SC |
432 | return NULL ; |
433 | } | |
1542ea39 | 434 | |
789ae0cf | 435 | ControlRef wxMacFindControlUnderMouse( wxTopLevelWindowMac* toplevelWindow , Point location , WindowRef window , ControlPartCode *outPart ) |
facd6764 SC |
436 | { |
437 | #if TARGET_API_MAC_OSX | |
789ae0cf | 438 | if ( UMAGetSystemVersion() >= 0x1030 && ( toplevelWindow == 0 || toplevelWindow->MacUsesCompositing() ) ) |
30e0b1c9 SC |
439 | return FindControlUnderMouse( location , window , outPart ) ; |
440 | #endif | |
facd6764 SC |
441 | ControlRef rootControl = NULL ; |
442 | verify_noerr( GetRootControl( window , &rootControl ) ) ; | |
789ae0cf | 443 | return wxMacFindSubControl( toplevelWindow , location , rootControl , outPart ) ; |
30e0b1c9 | 444 | |
facd6764 SC |
445 | } |
446 | pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
447 | { | |
789ae0cf | 448 | wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; |
facd6764 SC |
449 | |
450 | OSStatus result = eventNotHandledErr ; | |
451 | ||
452 | wxMacCarbonEvent cEvent( event ) ; | |
453 | ||
454 | Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ; | |
455 | Point windowMouseLocation = screenMouseLocation ; | |
456 | ||
457 | WindowRef window ; | |
458 | short windowPart = ::FindWindow(screenMouseLocation, &window); | |
459 | ||
460 | wxWindow* currentMouseWindow = NULL ; | |
d88ffaaa SC |
461 | ControlRef control = NULL ; |
462 | ||
facd6764 SC |
463 | if ( window ) |
464 | { | |
d6fd667b | 465 | QDGlobalToLocalPoint( UMAGetWindowPort(window ) , &windowMouseLocation ) ; |
facd6764 | 466 | |
2a1f999f | 467 | if ( wxApp::s_captureWindow && wxApp::s_captureWindow->MacGetTopLevelWindowRef() == (WXWindow) window && windowPart == inContent ) |
facd6764 | 468 | { |
2a1f999f | 469 | currentMouseWindow = wxApp::s_captureWindow ; |
facd6764 SC |
470 | } |
471 | else if ( (IsWindowActive(window) && windowPart == inContent) ) | |
472 | { | |
473 | ControlPartCode part ; | |
789ae0cf | 474 | control = wxMacFindControlUnderMouse( toplevelWindow , windowMouseLocation , window , &part ) ; |
d88ffaaa | 475 | // if there is no control below the mouse position, send the event to the toplevel window itself |
b19bf058 SC |
476 | if ( control == 0 ) |
477 | currentMouseWindow = (wxWindow*) data ; | |
478 | else | |
b16f4bfa | 479 | { |
b19bf058 | 480 | currentMouseWindow = wxFindControlFromMacControl( control ) ; |
8198ae50 | 481 | if ( currentMouseWindow == NULL && cEvent.GetKind() == kEventMouseMoved ) |
b16f4bfa | 482 | { |
179e085f | 483 | #if wxUSE_TOOLBAR |
b16f4bfa SC |
484 | // for wxToolBar to function we have to send certaint events to it |
485 | // instead of its children (wxToolBarTools) | |
486 | ControlRef parent ; | |
487 | GetSuperControl(control, &parent ); | |
488 | wxWindow *wxParent = wxFindControlFromMacControl( parent ) ; | |
489 | if ( wxParent && wxParent->IsKindOf( CLASSINFO( wxToolBar ) ) ) | |
490 | currentMouseWindow = wxParent ; | |
179e085f | 491 | #endif |
b16f4bfa SC |
492 | } |
493 | } | |
facd6764 SC |
494 | } |
495 | } | |
d88ffaaa | 496 | |
facd6764 SC |
497 | wxMouseEvent wxevent(wxEVT_LEFT_DOWN); |
498 | SetupMouseEvent( wxevent , cEvent ) ; | |
499 | ||
500 | // handle all enter / leave events | |
501 | ||
502 | if ( currentMouseWindow != g_MacLastWindow ) | |
503 | { | |
504 | if ( g_MacLastWindow ) | |
505 | { | |
506 | wxMouseEvent eventleave(wxevent); | |
507 | eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); | |
508 | g_MacLastWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); | |
509 | eventleave.SetEventObject( g_MacLastWindow ) ; | |
510 | ||
511 | #if wxUSE_TOOLTIPS | |
512 | wxToolTip::RelayEvent( g_MacLastWindow , eventleave); | |
513 | #endif // wxUSE_TOOLTIPS | |
514 | g_MacLastWindow->GetEventHandler()->ProcessEvent(eventleave); | |
515 | } | |
516 | if ( currentMouseWindow ) | |
517 | { | |
518 | wxMouseEvent evententer(wxevent); | |
519 | evententer.SetEventType( wxEVT_ENTER_WINDOW ); | |
520 | currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); | |
521 | evententer.SetEventObject( currentMouseWindow ) ; | |
522 | #if wxUSE_TOOLTIPS | |
523 | wxToolTip::RelayEvent( currentMouseWindow , evententer); | |
524 | #endif // wxUSE_TOOLTIPS | |
525 | currentMouseWindow->GetEventHandler()->ProcessEvent(evententer); | |
526 | } | |
527 | g_MacLastWindow = currentMouseWindow ; | |
528 | } | |
529 | ||
530 | if ( windowPart == inMenuBar ) | |
531 | { | |
532 | // special case menu bar, as we are having a low-level runloop we must do it ourselves | |
533 | if ( cEvent.GetKind() == kEventMouseDown ) | |
534 | { | |
535 | ::MenuSelect( screenMouseLocation ) ; | |
536 | result = noErr ; | |
537 | } | |
538 | } // if ( windowPart == inMenuBar ) | |
539 | else if ( currentMouseWindow ) | |
540 | { | |
e10e9469 | 541 | wxWindow *currentMouseWindowParent = currentMouseWindow->GetParent(); |
62ade180 RR |
542 | |
543 | currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ; | |
facd6764 SC |
544 | |
545 | wxevent.SetEventObject( currentMouseWindow ) ; | |
546 | ||
facd6764 SC |
547 | // make tooltips current |
548 | ||
549 | #if wxUSE_TOOLTIPS | |
550 | if ( wxevent.GetEventType() == wxEVT_MOTION | |
551 | || wxevent.GetEventType() == wxEVT_ENTER_WINDOW | |
552 | || wxevent.GetEventType() == wxEVT_LEAVE_WINDOW ) | |
553 | wxToolTip::RelayEvent( currentMouseWindow , wxevent); | |
554 | #endif // wxUSE_TOOLTIPS | |
555 | if ( currentMouseWindow->GetEventHandler()->ProcessEvent(wxevent) ) | |
62ade180 RR |
556 | { |
557 | if ((currentMouseWindowParent != NULL) && | |
558 | (currentMouseWindowParent->GetChildren().Find(currentMouseWindow) == NULL)) | |
559 | currentMouseWindow = NULL; | |
560 | ||
facd6764 | 561 | result = noErr; |
62ade180 | 562 | } |
30e0b1c9 SC |
563 | else |
564 | { | |
f90387b4 VZ |
565 | // if the user code did _not_ handle the event, then perform the |
566 | // default processing | |
567 | if ( wxevent.GetEventType() == wxEVT_LEFT_DOWN ) | |
568 | { | |
569 | // ... that is set focus to this window | |
570 | if (currentMouseWindow->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow) | |
571 | currentMouseWindow->SetFocus(); | |
572 | } | |
573 | ||
30e0b1c9 SC |
574 | ControlPartCode dummyPart ; |
575 | // if built-in find control is finding the wrong control (ie static box instead of overlaid | |
576 | // button, we cannot let the standard handler do its job, but must handle manually | |
577 | ||
23ad132c SC |
578 | if ( ( cEvent.GetKind() == kEventMouseDown ) |
579 | #ifdef __WXMAC_OSX__ | |
580 | && | |
30e0b1c9 | 581 | (FindControlUnderMouse(windowMouseLocation , window , &dummyPart) != |
789ae0cf | 582 | wxMacFindControlUnderMouse( toplevelWindow , windowMouseLocation , window , &dummyPart ) ) |
23ad132c SC |
583 | #endif |
584 | ) | |
30e0b1c9 | 585 | { |
7ce1a4e1 SC |
586 | if ( currentMouseWindow->MacIsReallyEnabled() ) |
587 | { | |
588 | EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ; | |
589 | Point clickLocation = windowMouseLocation ; | |
789ae0cf SC |
590 | |
591 | if ( toplevelWindow->MacUsesCompositing() ) | |
592 | currentMouseWindow->MacRootWindowToWindow( &clickLocation.h , &clickLocation.v ) ; | |
593 | ||
7ce1a4e1 SC |
594 | HandleControlClick( (ControlRef) currentMouseWindow->GetHandle() , clickLocation , |
595 | modifiers , (ControlActionUPP ) -1 ) ; | |
e10e9469 | 596 | |
62ade180 RR |
597 | if ((currentMouseWindowParent != NULL) && |
598 | (currentMouseWindowParent->GetChildren().Find(currentMouseWindow) == NULL)) | |
e10e9469 | 599 | currentMouseWindow = NULL; |
7ce1a4e1 | 600 | } |
30e0b1c9 SC |
601 | result = noErr ; |
602 | } | |
603 | } | |
2a1f999f | 604 | if ( cEvent.GetKind() == kEventMouseUp && wxApp::s_captureWindow ) |
facd6764 | 605 | { |
2a1f999f | 606 | wxApp::s_captureWindow = NULL ; |
facd6764 SC |
607 | // update cursor ? |
608 | } | |
6d63e2fc SC |
609 | |
610 | // update cursor | |
611 | ||
612 | wxWindow* cursorTarget = currentMouseWindow ; | |
613 | wxPoint cursorPoint( wxevent.m_x , wxevent.m_y ) ; | |
614 | ||
615 | while( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) ) | |
616 | { | |
617 | cursorTarget = cursorTarget->GetParent() ; | |
618 | if ( cursorTarget ) | |
e10e9469 | 619 | cursorPoint += cursorTarget->GetPosition(); |
6d63e2fc SC |
620 | } |
621 | ||
facd6764 | 622 | } // else if ( currentMouseWindow ) |
d88ffaaa SC |
623 | else |
624 | { | |
625 | // don't mess with controls we don't know about | |
626 | // for some reason returning eventNotHandledErr does not lead to the correct behaviour | |
627 | // so we try sending them the correct control directly | |
e4b7e0b4 | 628 | if ( cEvent.GetKind() == kEventMouseDown && toplevelWindow && control ) |
d88ffaaa SC |
629 | { |
630 | EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ; | |
631 | Point clickLocation = windowMouseLocation ; | |
789ae0cf SC |
632 | if ( toplevelWindow->MacUsesCompositing() ) |
633 | { | |
634 | #ifdef __WXMAC_OSX__ | |
635 | HIPoint hiPoint ; | |
636 | hiPoint.x = clickLocation.h ; | |
637 | hiPoint.y = clickLocation.v ; | |
638 | HIViewConvertPoint( &hiPoint , (ControlRef) toplevelWindow->GetHandle() , control ) ; | |
639 | clickLocation.h = (int)hiPoint.x ; | |
640 | clickLocation.v = (int)hiPoint.y ; | |
d88ffaaa | 641 | #endif |
789ae0cf | 642 | } |
d88ffaaa SC |
643 | HandleControlClick( control , clickLocation , |
644 | modifiers , (ControlActionUPP ) -1 ) ; | |
645 | result = noErr ; | |
646 | } | |
647 | } | |
facd6764 | 648 | return result ; |
851b3a88 | 649 | } |
facd6764 SC |
650 | |
651 | static pascal OSStatus wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
851b3a88 SC |
652 | { |
653 | OSStatus result = eventNotHandledErr ; | |
851b3a88 | 654 | |
facd6764 SC |
655 | wxMacCarbonEvent cEvent( event ) ; |
656 | ||
657 | // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ; | |
e40298d5 | 658 | wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; |
1542ea39 | 659 | |
e40298d5 JS |
660 | switch( GetEventKind( event ) ) |
661 | { | |
e40298d5 | 662 | case kEventWindowActivated : |
facd6764 SC |
663 | { |
664 | toplevelWindow->MacActivate( cEvent.GetTicks() , true) ; | |
facd6764 SC |
665 | wxActivateEvent wxevent(wxEVT_ACTIVATE, true , toplevelWindow->GetId()); |
666 | wxevent.SetTimestamp( cEvent.GetTicks() ) ; | |
667 | wxevent.SetEventObject(toplevelWindow); | |
668 | toplevelWindow->GetEventHandler()->ProcessEvent(wxevent); | |
73fe67bd | 669 | // we still sending an eventNotHandledErr in order to allow for default processing |
e40298d5 | 670 | break ; |
facd6764 | 671 | } |
e40298d5 | 672 | case kEventWindowDeactivated : |
facd6764 SC |
673 | { |
674 | toplevelWindow->MacActivate(cEvent.GetTicks() , false) ; | |
675 | wxActivateEvent wxevent(wxEVT_ACTIVATE, false , toplevelWindow->GetId()); | |
676 | wxevent.SetTimestamp( cEvent.GetTicks() ) ; | |
677 | wxevent.SetEventObject(toplevelWindow); | |
678 | toplevelWindow->GetEventHandler()->ProcessEvent(wxevent); | |
73fe67bd | 679 | // we still sending an eventNotHandledErr in order to allow for default processing |
e40298d5 | 680 | break ; |
facd6764 | 681 | } |
16a76184 SC |
682 | case kEventWindowShown : |
683 | toplevelWindow->Refresh() ; | |
684 | result = noErr ; | |
685 | break ; | |
e40298d5 JS |
686 | case kEventWindowClose : |
687 | toplevelWindow->Close() ; | |
688 | result = noErr ; | |
689 | break ; | |
690 | case kEventWindowBoundsChanged : | |
facd6764 SC |
691 | { |
692 | UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ; | |
693 | Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ; | |
694 | wxRect r( newRect.left , newRect.top , newRect.right - newRect.left , newRect.bottom - newRect.top ) ; | |
695 | if ( attributes & kWindowBoundsChangeSizeChanged ) | |
e40298d5 | 696 | { |
facd6764 SC |
697 | // according to the other ports we handle this within the OS level |
698 | // resize event, not within a wxSizeEvent | |
699 | wxFrame *frame = wxDynamicCast( toplevelWindow , wxFrame ) ; | |
700 | if ( frame ) | |
701 | { | |
702 | #if wxUSE_STATUSBAR | |
703 | frame->PositionStatusBar(); | |
704 | #endif | |
705 | #if wxUSE_TOOLBAR | |
706 | frame->PositionToolBar(); | |
707 | #endif | |
708 | } | |
1542ea39 | 709 | |
facd6764 SC |
710 | wxSizeEvent event( r.GetSize() , toplevelWindow->GetId() ) ; |
711 | event.SetEventObject( toplevelWindow ) ; | |
851b3a88 | 712 | |
facd6764 | 713 | toplevelWindow->GetEventHandler()->ProcessEvent(event) ; |
e40298d5 | 714 | } |
facd6764 SC |
715 | if ( attributes & kWindowBoundsChangeOriginChanged ) |
716 | { | |
717 | wxMoveEvent event( r.GetLeftTop() , toplevelWindow->GetId() ) ; | |
718 | event.SetEventObject( toplevelWindow ) ; | |
719 | toplevelWindow->GetEventHandler()->ProcessEvent(event) ; | |
720 | } | |
721 | result = noErr ; | |
e40298d5 | 722 | break ; |
facd6764 | 723 | } |
f81bfef9 | 724 | case kEventWindowBoundsChanging : |
facd6764 SC |
725 | { |
726 | UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ; | |
727 | Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ; | |
83901ec2 | 728 | |
facd6764 SC |
729 | if ( (attributes & kWindowBoundsChangeSizeChanged) || (attributes & kWindowBoundsChangeOriginChanged) ) |
730 | { | |
29281095 SC |
731 | // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates |
732 | int left , top , right , bottom ; | |
733 | toplevelWindow->MacGetContentAreaInset( left , top , right , bottom ) ; | |
734 | wxRect r( newRect.left - left , newRect.top - top , | |
735 | newRect.right - newRect.left + left + right , newRect.bottom - newRect.top + top + bottom ) ; | |
facd6764 SC |
736 | // this is a EVT_SIZING not a EVT_SIZE type ! |
737 | wxSizeEvent wxevent( r , toplevelWindow->GetId() ) ; | |
738 | wxevent.SetEventObject( toplevelWindow ) ; | |
739 | wxRect adjustR = r ; | |
740 | if ( toplevelWindow->GetEventHandler()->ProcessEvent(wxevent) ) | |
facd6764 | 741 | adjustR = wxevent.GetRect() ; |
29281095 | 742 | |
facd6764 SC |
743 | if ( toplevelWindow->GetMaxWidth() != -1 && adjustR.GetWidth() > toplevelWindow->GetMaxWidth() ) |
744 | adjustR.SetWidth( toplevelWindow->GetMaxWidth() ) ; | |
2c25bd55 | 745 | if ( toplevelWindow->GetMaxHeight() != -1 && adjustR.GetHeight() > toplevelWindow->GetMaxHeight() ) |
facd6764 SC |
746 | adjustR.SetHeight( toplevelWindow->GetMaxHeight() ) ; |
747 | if ( toplevelWindow->GetMinWidth() != -1 && adjustR.GetWidth() < toplevelWindow->GetMinWidth() ) | |
748 | adjustR.SetWidth( toplevelWindow->GetMinWidth() ) ; | |
2c25bd55 | 749 | if ( toplevelWindow->GetMinHeight() != -1 && adjustR.GetHeight() < toplevelWindow->GetMinHeight() ) |
facd6764 | 750 | adjustR.SetHeight( toplevelWindow->GetMinHeight() ) ; |
4a5f2351 | 751 | const Rect adjustedRect = { adjustR.y + top , adjustR.x + left , adjustR.y + adjustR.height - bottom , adjustR.x + adjustR.width - right } ; |
facd6764 | 752 | if ( !EqualRect( &newRect , &adjustedRect ) ) |
1f919f38 | 753 | cEvent.SetParameter<Rect>( kEventParamCurrentBounds , &adjustedRect ) ; |
f81bfef9 | 754 | } |
facd6764 | 755 | |
789ae0cf | 756 | result = noErr ; |
f81bfef9 | 757 | break ; |
facd6764 | 758 | } |
e40298d5 JS |
759 | default : |
760 | break ; | |
761 | } | |
762 | return result ; | |
851b3a88 SC |
763 | } |
764 | ||
facd6764 | 765 | pascal OSStatus wxMacTopLevelEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) |
851b3a88 SC |
766 | { |
767 | OSStatus result = eventNotHandledErr ; | |
768 | ||
769 | switch ( GetEventClass( event ) ) | |
770 | { | |
c5c9378c | 771 | case kEventClassKeyboard : |
e40298d5 | 772 | result = KeyboardEventHandler( handler, event , data ) ; |
c5c9378c | 773 | break ; |
851b3a88 | 774 | case kEventClassTextInput : |
e40298d5 | 775 | result = TextInputEventHandler( handler, event , data ) ; |
851b3a88 SC |
776 | break ; |
777 | case kEventClassWindow : | |
facd6764 | 778 | result = wxMacTopLevelWindowEventHandler( handler, event , data ) ; |
e40298d5 | 779 | break ; |
851b3a88 | 780 | case kEventClassMouse : |
facd6764 | 781 | result = wxMacTopLevelMouseEventHandler( handler, event , data ) ; |
e40298d5 | 782 | break ; |
851b3a88 SC |
783 | default : |
784 | break ; | |
785 | } | |
786 | return result ; | |
787 | } | |
788 | ||
facd6764 | 789 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler ) |
851b3a88 | 790 | |
5f0b2f22 SC |
791 | // --------------------------------------------------------------------------- |
792 | // wxWindowMac utility functions | |
793 | // --------------------------------------------------------------------------- | |
794 | ||
795 | // Find an item given the Macintosh Window Reference | |
796 | ||
71f2fb52 | 797 | #if KEY_wxList_DEPRECATED |
facd6764 SC |
798 | wxList wxWinMacWindowList(wxKEY_INTEGER); |
799 | wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef) | |
5f0b2f22 | 800 | { |
facd6764 | 801 | wxNode *node = wxWinMacWindowList.Find((long)inWindowRef); |
5f0b2f22 SC |
802 | if (!node) |
803 | return NULL; | |
eb22f2a6 | 804 | return (wxTopLevelWindowMac *)node->GetData(); |
5f0b2f22 SC |
805 | } |
806 | ||
facd6764 SC |
807 | void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) ; |
808 | void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) | |
5f0b2f22 SC |
809 | { |
810 | // adding NULL WindowRef is (first) surely a result of an error and | |
811 | // (secondly) breaks menu command processing | |
427ff662 | 812 | wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); |
5f0b2f22 | 813 | |
facd6764 SC |
814 | if ( !wxWinMacWindowList.Find((long)inWindowRef) ) |
815 | wxWinMacWindowList.Append((long)inWindowRef, win); | |
5f0b2f22 SC |
816 | } |
817 | ||
facd6764 | 818 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) ; |
5f0b2f22 SC |
819 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) |
820 | { | |
facd6764 | 821 | wxWinMacWindowList.DeleteObject(win); |
5f0b2f22 | 822 | } |
71f2fb52 | 823 | #else |
5f0b2f22 | 824 | |
71f2fb52 RN |
825 | WX_DECLARE_HASH_MAP(WindowRef, wxTopLevelWindowMac*, wxPointerHash, wxPointerEqual, MacWindowMap); |
826 | ||
827 | static MacWindowMap wxWinMacWindowList; | |
828 | ||
829 | wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef) | |
830 | { | |
831 | MacWindowMap::iterator node = wxWinMacWindowList.find(inWindowRef); | |
832 | ||
833 | return (node == wxWinMacWindowList.end()) ? NULL : node->second; | |
834 | } | |
835 | ||
836 | void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) ; | |
837 | void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) | |
838 | { | |
839 | // adding NULL WindowRef is (first) surely a result of an error and | |
840 | // nothing else :-) | |
841 | wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); | |
842 | ||
843 | wxWinMacWindowList[inWindowRef] = win; | |
844 | } | |
845 | ||
846 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) ; | |
847 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) | |
848 | { | |
849 | MacWindowMap::iterator it; | |
850 | for ( it = wxWinMacWindowList.begin(); it != wxWinMacWindowList.end(); ++it ) | |
851 | { | |
852 | if ( it->second == win ) | |
853 | { | |
854 | wxWinMacWindowList.erase(it); | |
855 | break; | |
856 | } | |
857 | } | |
858 | } | |
859 | #endif // deprecated wxList | |
5f0b2f22 | 860 | |
a15eb0a5 SC |
861 | // ---------------------------------------------------------------------------- |
862 | // wxTopLevelWindowMac creation | |
863 | // ---------------------------------------------------------------------------- | |
864 | ||
245f3581 | 865 | wxTopLevelWindowMac *wxTopLevelWindowMac::s_macDeactivateWindow = NULL; |
5f0b2f22 | 866 | |
c5985061 SC |
867 | typedef struct |
868 | { | |
869 | wxPoint m_position ; | |
870 | wxSize m_size ; | |
871 | } FullScreenData ; | |
872 | ||
a15eb0a5 SC |
873 | void wxTopLevelWindowMac::Init() |
874 | { | |
875 | m_iconized = | |
876 | m_maximizeOnShow = FALSE; | |
6a17ca35 | 877 | m_macWindow = NULL ; |
facd6764 | 878 | #if TARGET_API_MAC_OSX |
789ae0cf SC |
879 | if ( UMAGetSystemVersion() >= 0x1030 ) |
880 | { | |
881 | m_macUsesCompositing = TRUE; | |
882 | } | |
883 | else | |
facd6764 | 884 | #endif |
789ae0cf SC |
885 | { |
886 | m_macUsesCompositing = FALSE; | |
887 | } | |
7c091673 | 888 | m_macEventHandler = NULL ; |
c5985061 | 889 | m_macFullScreenData = NULL ; |
a15eb0a5 SC |
890 | } |
891 | ||
118f012e SC |
892 | class wxMacDeferredWindowDeleter : public wxObject |
893 | { | |
894 | public : | |
1542ea39 RD |
895 | wxMacDeferredWindowDeleter( WindowRef windowRef ) |
896 | { | |
897 | m_macWindow = windowRef ; | |
118f012e | 898 | } |
1542ea39 RD |
899 | virtual ~wxMacDeferredWindowDeleter() |
900 | { | |
901 | UMADisposeWindow( (WindowRef) m_macWindow ) ; | |
118f012e SC |
902 | } |
903 | protected : | |
904 | WindowRef m_macWindow ; | |
905 | } ; | |
906 | ||
a15eb0a5 SC |
907 | bool wxTopLevelWindowMac::Create(wxWindow *parent, |
908 | wxWindowID id, | |
909 | const wxString& title, | |
910 | const wxPoint& pos, | |
911 | const wxSize& size, | |
912 | long style, | |
913 | const wxString& name) | |
914 | { | |
915 | // init our fields | |
916 | Init(); | |
917 | ||
918 | m_windowStyle = style; | |
919 | ||
920 | SetName(name); | |
921 | ||
922 | m_windowId = id == -1 ? NewControlId() : id; | |
c2bc1e2a | 923 | wxWindow::SetTitle( title ) ; |
a15eb0a5 | 924 | |
facd6764 SC |
925 | MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; |
926 | ||
94d1d0f4 | 927 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); |
5bd78bbc JS |
928 | |
929 | if (GetExtraStyle() & wxFRAME_EX_METAL) | |
930 | MacSetMetalAppearance(true); | |
94d1d0f4 | 931 | |
a15eb0a5 SC |
932 | wxTopLevelWindows.Append(this); |
933 | ||
934 | if ( parent ) | |
935 | parent->AddChild(this); | |
936 | ||
937 | return TRUE; | |
938 | } | |
939 | ||
940 | wxTopLevelWindowMac::~wxTopLevelWindowMac() | |
941 | { | |
6a17ca35 SC |
942 | if ( m_macWindow ) |
943 | { | |
c81c6d54 | 944 | #if wxUSE_TOOLTIPS |
6a17ca35 | 945 | wxToolTip::NotifyWindowDelete(m_macWindow) ; |
c81c6d54 | 946 | #endif |
118f012e | 947 | wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ; |
6a17ca35 | 948 | } |
1542ea39 | 949 | |
7c091673 SC |
950 | if ( m_macEventHandler ) |
951 | { | |
952 | ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); | |
953 | m_macEventHandler = NULL ; | |
954 | } | |
851b3a88 | 955 | |
5f0b2f22 SC |
956 | wxRemoveMacWindowAssociation( this ) ; |
957 | ||
a15eb0a5 SC |
958 | if ( wxModelessWindows.Find(this) ) |
959 | wxModelessWindows.DeleteObject(this); | |
c5985061 SC |
960 | |
961 | FullScreenData *data = (FullScreenData *) m_macFullScreenData ; | |
962 | delete data ; | |
963 | m_macFullScreenData = NULL ; | |
a15eb0a5 SC |
964 | } |
965 | ||
966 | ||
967 | // ---------------------------------------------------------------------------- | |
968 | // wxTopLevelWindowMac maximize/minimize | |
969 | // ---------------------------------------------------------------------------- | |
970 | ||
971 | void wxTopLevelWindowMac::Maximize(bool maximize) | |
972 | { | |
1f90939c SC |
973 | wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ; |
974 | wxMacWindowClipper clip (this); | |
b7aec135 | 975 | ZoomWindow( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , false ) ; |
a15eb0a5 SC |
976 | } |
977 | ||
978 | bool wxTopLevelWindowMac::IsMaximized() const | |
979 | { | |
b7aec135 | 980 | return IsWindowInStandardState( (WindowRef)m_macWindow , NULL , NULL ) ; |
a15eb0a5 SC |
981 | } |
982 | ||
983 | void wxTopLevelWindowMac::Iconize(bool iconize) | |
984 | { | |
b7aec135 SC |
985 | if ( IsWindowCollapsable((WindowRef)m_macWindow) ) |
986 | CollapseWindow((WindowRef)m_macWindow , iconize ) ; | |
a15eb0a5 SC |
987 | } |
988 | ||
989 | bool wxTopLevelWindowMac::IsIconized() const | |
990 | { | |
b7aec135 | 991 | return IsWindowCollapsed((WindowRef)m_macWindow ) ; |
a15eb0a5 SC |
992 | } |
993 | ||
994 | void wxTopLevelWindowMac::Restore() | |
995 | { | |
996 | // not available on mac | |
997 | } | |
998 | ||
999 | // ---------------------------------------------------------------------------- | |
1000 | // wxTopLevelWindowMac misc | |
1001 | // ---------------------------------------------------------------------------- | |
1002 | ||
facd6764 SC |
1003 | wxPoint wxTopLevelWindowMac::GetClientAreaOrigin() const |
1004 | { | |
1005 | return wxPoint(0,0) ; | |
1006 | } | |
1007 | ||
a15eb0a5 SC |
1008 | void wxTopLevelWindowMac::SetIcon(const wxIcon& icon) |
1009 | { | |
1010 | // this sets m_icon | |
1011 | wxTopLevelWindowBase::SetIcon(icon); | |
1012 | } | |
5f0b2f22 | 1013 | |
facd6764 SC |
1014 | void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush &brush ) |
1015 | { | |
1016 | wxTopLevelWindowBase::MacSetBackgroundBrush( brush ) ; | |
1017 | ||
1018 | if ( m_macBackgroundBrush.Ok() && m_macBackgroundBrush.GetStyle() != wxTRANSPARENT && m_macBackgroundBrush.MacGetBrushKind() == kwxMacBrushTheme ) | |
1019 | { | |
1020 | SetThemeWindowBackground( (WindowRef) m_macWindow , m_macBackgroundBrush.MacGetTheme() , false ) ; | |
1021 | } | |
1022 | } | |
1023 | ||
949cb163 SC |
1024 | void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler() |
1025 | { | |
1026 | if ( m_macEventHandler != NULL ) | |
1027 | { | |
1028 | verify_noerr( ::RemoveEventHandler( (EventHandlerRef) m_macEventHandler ) ) ; | |
1029 | } | |
1030 | InstallWindowEventHandler(MAC_WXHWND(m_macWindow), GetwxMacTopLevelEventHandlerUPP(), | |
1031 | GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macEventHandler); | |
1032 | } | |
1033 | ||
5f0b2f22 SC |
1034 | void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, |
1035 | const wxPoint& pos, | |
1036 | const wxSize& size, | |
1037 | long style, | |
1542ea39 | 1038 | const wxString& name ) |
5f0b2f22 | 1039 | { |
47ac4f9b | 1040 | OSStatus err = noErr ; |
e40298d5 JS |
1041 | SetName(name); |
1042 | m_windowStyle = style; | |
1043 | m_isShown = FALSE; | |
1542ea39 | 1044 | |
e40298d5 | 1045 | // create frame. |
1542ea39 | 1046 | |
5f0b2f22 | 1047 | Rect theBoundsRect; |
1542ea39 | 1048 | |
facd6764 SC |
1049 | int x = (int)pos.x; |
1050 | int y = (int)pos.y; | |
5a486641 SC |
1051 | |
1052 | wxRect display = wxGetClientDisplayRect() ; | |
1053 | ||
1054 | if ( x == wxDefaultPosition.x ) | |
1055 | x = display.x ; | |
1056 | ||
1057 | if ( y == wxDefaultPosition.y ) | |
1058 | y = display.y ; | |
1542ea39 | 1059 | |
facd6764 SC |
1060 | int w = WidthDefault(size.x); |
1061 | int h = HeightDefault(size.y); | |
1542ea39 | 1062 | |
facd6764 | 1063 | ::SetRect(&theBoundsRect, x, y , x + w, y + h); |
1542ea39 | 1064 | |
5f0b2f22 | 1065 | // translate the window attributes in the appropriate window class and attributes |
1542ea39 | 1066 | |
5f0b2f22 SC |
1067 | WindowClass wclass = 0; |
1068 | WindowAttributes attr = kWindowNoAttributes ; | |
e353795e | 1069 | WindowGroupRef group = NULL ; |
1542ea39 | 1070 | |
f5744893 | 1071 | if ( HasFlag( wxFRAME_TOOL_WINDOW) ) |
5f0b2f22 | 1072 | { |
1542ea39 | 1073 | if ( |
f5744893 SC |
1074 | HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
1075 | HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) || | |
1076 | HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) | |
e40298d5 | 1077 | ) |
5f0b2f22 | 1078 | { |
f5744893 SC |
1079 | wclass = kFloatingWindowClass ; |
1080 | if ( HasFlag(wxTINY_CAPTION_VERT) ) | |
1081 | { | |
1082 | attr |= kWindowSideTitlebarAttribute ; | |
1083 | } | |
1084 | } | |
1085 | else | |
1086 | { | |
1087 | wclass = kPlainWindowClass ; | |
5f0b2f22 SC |
1088 | } |
1089 | } | |
1090 | else if ( HasFlag( wxCAPTION ) ) | |
1091 | { | |
1542ea39 | 1092 | wclass = kDocumentWindowClass ; |
5f0b2f22 | 1093 | } |
eab19a7c | 1094 | #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 ) |
3e17bc3f RN |
1095 | else if ( HasFlag( wxFRAME_DRAWER ) ) |
1096 | { | |
1097 | wclass = kDrawerWindowClass; | |
789ae0cf SC |
1098 | // we must force compositing on a drawer |
1099 | m_macUsesCompositing = TRUE ; | |
3e17bc3f RN |
1100 | } |
1101 | #endif //10.2 and up | |
5f0b2f22 SC |
1102 | else |
1103 | { | |
f5744893 | 1104 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
47ac4f9b | 1105 | HasFlag( wxCLOSE_BOX ) || HasFlag( wxSYSTEM_MENU ) ) |
f5744893 SC |
1106 | { |
1107 | wclass = kDocumentWindowClass ; | |
1108 | } | |
1109 | else | |
1110 | { | |
1111 | wclass = kPlainWindowClass ; | |
1112 | } | |
5f0b2f22 | 1113 | } |
1542ea39 | 1114 | |
38e605eb | 1115 | if ( HasFlag( wxMINIMIZE_BOX ) && wclass != kPlainWindowClass ) |
5f0b2f22 | 1116 | { |
5f0b2f22 SC |
1117 | attr |= kWindowCollapseBoxAttribute ; |
1118 | } | |
38e605eb | 1119 | if ( HasFlag( wxMAXIMIZE_BOX ) && wclass != kPlainWindowClass ) |
47ac4f9b SC |
1120 | { |
1121 | attr |= kWindowFullZoomAttribute ; | |
1122 | } | |
38e605eb | 1123 | if ( HasFlag( wxRESIZE_BORDER ) && wclass != kPlainWindowClass ) |
5f0b2f22 SC |
1124 | { |
1125 | attr |= kWindowResizableAttribute ; | |
1126 | } | |
38e605eb | 1127 | if ( HasFlag( wxCLOSE_BOX) && wclass != kPlainWindowClass ) |
5f0b2f22 SC |
1128 | { |
1129 | attr |= kWindowCloseBoxAttribute ; | |
1130 | } | |
1542ea39 | 1131 | |
eb630bf1 DS |
1132 | if (UMAGetSystemVersion() >= 0x1000) |
1133 | { | |
facd6764 | 1134 | // turn on live resizing (OS X only) |
eb630bf1 DS |
1135 | attr |= kWindowLiveResizeAttribute; |
1136 | } | |
1137 | ||
e353795e SC |
1138 | if ( HasFlag(wxSTAY_ON_TOP) ) |
1139 | { | |
1140 | group = GetWindowGroupOfClass(kUtilityWindowClass) ; | |
1141 | } | |
6a7e6411 | 1142 | |
facd6764 | 1143 | #if TARGET_API_MAC_OSX |
789ae0cf SC |
1144 | if ( m_macUsesCompositing ) |
1145 | attr |= kWindowCompositingAttribute; | |
d66c3960 | 1146 | #endif |
1f90939c | 1147 | |
6a7e6411 RD |
1148 | if ( HasFlag(wxFRAME_SHAPED) ) |
1149 | { | |
1150 | WindowDefSpec customWindowDefSpec; | |
1151 | customWindowDefSpec.defType = kWindowDefProcPtr; | |
1152 | customWindowDefSpec.u.defProc = NewWindowDefUPP(wxShapedMacWindowDef); | |
1153 | ||
47ac4f9b | 1154 | err = ::CreateCustomWindow( &customWindowDefSpec, wclass, |
6a7e6411 RD |
1155 | attr, &theBoundsRect, |
1156 | (WindowRef*) &m_macWindow); | |
1157 | } | |
1158 | else | |
1159 | { | |
47ac4f9b | 1160 | err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ; |
6a7e6411 RD |
1161 | } |
1162 | ||
e353795e SC |
1163 | if ( err == noErr && m_macWindow != NULL && group != NULL ) |
1164 | SetWindowGroup( (WindowRef) m_macWindow , group ) ; | |
1165 | ||
47ac4f9b | 1166 | wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") ); |
f83b6761 SC |
1167 | |
1168 | // the create commands are only for content rect, so we have to set the size again as | |
1169 | // structure bounds | |
1170 | SetWindowBounds( (WindowRef) m_macWindow , kWindowStructureRgn , &theBoundsRect ) ; | |
1171 | ||
facd6764 SC |
1172 | wxAssociateWinWithMacWindow( (WindowRef) m_macWindow , this ) ; |
1173 | UMASetWTitle( (WindowRef) m_macWindow , title , m_font.GetEncoding() ) ; | |
1f1c8bd4 | 1174 | m_peer = new wxMacControl(this , true /*isRootControl*/) ; |
3a9dc061 | 1175 | #if TARGET_API_MAC_OSX |
789ae0cf SC |
1176 | |
1177 | if ( m_macUsesCompositing ) | |
f57d9215 | 1178 | { |
789ae0cf SC |
1179 | // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of |
1180 | // the content view, so we have to retrieve it explicitely | |
1181 | HIViewFindByID( HIViewGetRoot( (WindowRef) m_macWindow ) , kHIViewWindowContentID , | |
1182 | m_peer->GetControlRefAddr() ) ; | |
1183 | if ( !m_peer->Ok() ) | |
1184 | { | |
1185 | // compatibility mode fallback | |
1186 | GetRootControl( (WindowRef) m_macWindow , m_peer->GetControlRefAddr() ) ; | |
1187 | } | |
f57d9215 | 1188 | } |
3a9dc061 | 1189 | #endif |
789ae0cf SC |
1190 | { |
1191 | ::CreateRootControl( (WindowRef)m_macWindow , m_peer->GetControlRefAddr() ) ; | |
1192 | } | |
73fe67bd | 1193 | // the root control level handleer |
5ca0d812 | 1194 | MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ) ; |
facd6764 | 1195 | |
73fe67bd | 1196 | // the frame window event handler |
e40298d5 | 1197 | InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ; |
949cb163 | 1198 | MacInstallTopLevelWindowEventHandler() ; |
b19bf058 | 1199 | |
facd6764 | 1200 | m_macFocus = NULL ; |
6a7e6411 RD |
1201 | |
1202 | if ( HasFlag(wxFRAME_SHAPED) ) | |
1203 | { | |
1204 | // default shape matches the window size | |
facd6764 | 1205 | wxRegion rgn(0, 0, w, h); |
6a7e6411 RD |
1206 | SetShape(rgn); |
1207 | } | |
3dfafdb9 RD |
1208 | |
1209 | wxWindowCreateEvent event(this); | |
1210 | GetEventHandler()->ProcessEvent(event); | |
5f0b2f22 SC |
1211 | } |
1212 | ||
5d2e69e8 | 1213 | void wxTopLevelWindowMac::ClearBackground() |
5f0b2f22 | 1214 | { |
5d2e69e8 | 1215 | wxWindow::ClearBackground() ; |
5f0b2f22 SC |
1216 | } |
1217 | ||
5f0b2f22 SC |
1218 | // Raise the window to the top of the Z order |
1219 | void wxTopLevelWindowMac::Raise() | |
1220 | { | |
7f3c339c | 1221 | ::SelectWindow( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
1222 | } |
1223 | ||
1224 | // Lower the window to the bottom of the Z order | |
1225 | void wxTopLevelWindowMac::Lower() | |
1226 | { | |
76a5e5d2 | 1227 | ::SendBehind( (WindowRef)m_macWindow , NULL ) ; |
5f0b2f22 SC |
1228 | } |
1229 | ||
851b3a88 | 1230 | |
245f3581 DE |
1231 | void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp) |
1232 | { | |
1233 | if(s_macDeactivateWindow) | |
1234 | { | |
365796b1 | 1235 | wxLogDebug(wxT("Doing delayed deactivation of %p"),s_macDeactivateWindow); |
245f3581 DE |
1236 | s_macDeactivateWindow->MacActivate(timestamp, false); |
1237 | } | |
1238 | } | |
1239 | ||
851b3a88 | 1240 | void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating ) |
5f0b2f22 | 1241 | { |
17f8d2a7 VZ |
1242 | // wxLogDebug(wxT("TopLevel=%p::MacActivate"),this); |
1243 | ||
245f3581 DE |
1244 | if(s_macDeactivateWindow==this) |
1245 | s_macDeactivateWindow=NULL; | |
1246 | MacDelayedDeactivation(timestamp); | |
8ab50549 | 1247 | MacPropagateHiliteChanged() ; |
5f0b2f22 SC |
1248 | } |
1249 | ||
1250 | void wxTopLevelWindowMac::SetTitle(const wxString& title) | |
1251 | { | |
1252 | wxWindow::SetTitle( title ) ; | |
16a76184 | 1253 | UMASetWTitle( (WindowRef)m_macWindow , title , m_font.GetEncoding() ) ; |
5f0b2f22 SC |
1254 | } |
1255 | ||
1256 | bool wxTopLevelWindowMac::Show(bool show) | |
1257 | { | |
facd6764 | 1258 | if ( !wxTopLevelWindowBase::Show(show) ) |
5f0b2f22 SC |
1259 | return FALSE; |
1260 | ||
1261 | if (show) | |
1542ea39 | 1262 | { |
1f90939c SC |
1263 | #if wxUSE_SYSTEM_OPTIONS //code contributed by Ryan Wilcox December 18, 2003 |
1264 | if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1) ) | |
1265 | { | |
1266 | ::ShowWindow( (WindowRef)m_macWindow ); | |
1267 | } | |
1268 | else | |
1269 | #endif | |
1270 | { | |
1271 | ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowShowTransitionAction,nil); | |
1272 | } | |
1273 | ::SelectWindow( (WindowRef)m_macWindow ) ; | |
facd6764 SC |
1274 | // as apps expect a size event to occur at this moment |
1275 | wxSizeEvent event( GetSize() , m_windowId); | |
1f90939c SC |
1276 | event.SetEventObject(this); |
1277 | GetEventHandler()->ProcessEvent(event); | |
5f0b2f22 SC |
1278 | } |
1279 | else | |
1280 | { | |
1f90939c SC |
1281 | #if wxUSE_SYSTEM_OPTIONS |
1282 | if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1) ) | |
1283 | { | |
1284 | ::HideWindow((WindowRef) m_macWindow ); | |
1285 | } | |
1286 | else | |
1287 | #endif | |
1288 | { | |
1289 | ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowHideTransitionAction,nil); | |
1290 | } | |
5f0b2f22 SC |
1291 | } |
1292 | ||
facd6764 | 1293 | MacPropagateVisibilityChanged() ; |
5f0b2f22 | 1294 | |
facd6764 | 1295 | return TRUE ; |
5f0b2f22 SC |
1296 | } |
1297 | ||
c5985061 SC |
1298 | bool wxTopLevelWindowMac::ShowFullScreen(bool show, long style) |
1299 | { | |
1300 | if ( show ) | |
1301 | { | |
1302 | FullScreenData *data = (FullScreenData *)m_macFullScreenData ; | |
1303 | delete data ; | |
1304 | data = new FullScreenData() ; | |
1305 | ||
1306 | m_macFullScreenData = data ; | |
1307 | data->m_position = GetPosition() ; | |
1308 | data->m_size = GetSize() ; | |
1309 | ||
1310 | if ( style & wxFULLSCREEN_NOMENUBAR ) | |
1311 | { | |
1312 | HideMenuBar() ; | |
1313 | } | |
1314 | int left , top , right , bottom ; | |
1315 | wxRect client = wxGetClientDisplayRect() ; | |
1316 | ||
1317 | int x, y, w, h ; | |
1318 | ||
1319 | x = client.x ; | |
1320 | y = client.y ; | |
1321 | w = client.width ; | |
1322 | h = client.height ; | |
1323 | ||
1324 | MacGetContentAreaInset( left , top , right , bottom ) ; | |
1325 | ||
1326 | if ( style & wxFULLSCREEN_NOCAPTION ) | |
1327 | { | |
1328 | y -= top ; | |
1329 | h += top ; | |
1330 | } | |
1331 | if ( style & wxFULLSCREEN_NOBORDER ) | |
1332 | { | |
1333 | x -= left ; | |
1334 | w += left + right ; | |
1335 | h += bottom ; | |
1336 | } | |
1337 | if ( style & wxFULLSCREEN_NOTOOLBAR ) | |
1338 | { | |
3c86150d SC |
1339 | // TODO |
1340 | } | |
1341 | if ( style & wxFULLSCREEN_NOSTATUSBAR ) | |
1342 | { | |
1343 | // TODO | |
c5985061 SC |
1344 | } |
1345 | SetSize( x , y , w, h ) ; | |
1346 | } | |
1347 | else | |
1348 | { | |
1349 | ShowMenuBar() ; | |
1350 | FullScreenData *data = (FullScreenData *) m_macFullScreenData ; | |
1351 | SetPosition( data->m_position ) ; | |
1352 | SetSize( data->m_size ) ; | |
1353 | delete data ; | |
1354 | m_macFullScreenData = NULL ; | |
1355 | } | |
1356 | return FALSE; | |
1357 | } | |
1358 | ||
1359 | bool wxTopLevelWindowMac::IsFullScreen() const | |
1360 | { | |
1361 | return m_macFullScreenData != NULL ; | |
1362 | } | |
1363 | ||
facd6764 SC |
1364 | // we are still using coordinates of the content view, todo switch to structure bounds |
1365 | ||
29281095 SC |
1366 | void wxTopLevelWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) |
1367 | { | |
1368 | Rect content ; | |
1369 | Rect structure ; | |
1370 | GetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &structure ) ; | |
1371 | GetWindowBounds( (WindowRef) m_macWindow, kWindowContentRgn , &content ) ; | |
1372 | ||
1373 | left = content.left - structure.left ; | |
1374 | top = content.top - structure.top ; | |
1375 | right = structure.right - content.right ; | |
1376 | bottom = structure.bottom - content.bottom ; | |
1377 | } | |
1378 | ||
5f0b2f22 SC |
1379 | void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height) |
1380 | { | |
facd6764 SC |
1381 | Rect bounds = { y , x , y + height , x + width } ; |
1382 | verify_noerr(SetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
5f0b2f22 SC |
1383 | } |
1384 | ||
facd6764 | 1385 | void wxTopLevelWindowMac::DoGetPosition( int *x, int *y ) const |
5f0b2f22 | 1386 | { |
facd6764 SC |
1387 | Rect bounds ; |
1388 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
1389 | if(x) *x = bounds.left ; | |
1390 | if(y) *y = bounds.top ; | |
1391 | } | |
1392 | void wxTopLevelWindowMac::DoGetSize( int *width, int *height ) const | |
1393 | { | |
1394 | Rect bounds ; | |
1395 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
1396 | if(width) *width = bounds.right - bounds.left ; | |
1397 | if(height) *height = bounds.bottom - bounds.top ; | |
1398 | } | |
1542ea39 | 1399 | |
facd6764 SC |
1400 | void wxTopLevelWindowMac::DoGetClientSize( int *width, int *height ) const |
1401 | { | |
1402 | Rect bounds ; | |
1403 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowContentRgn , &bounds )) ; | |
1404 | if(width) *width = bounds.right - bounds.left ; | |
1405 | if(height) *height = bounds.bottom - bounds.top ; | |
1406 | } | |
1542ea39 | 1407 | |
facd6764 SC |
1408 | void wxTopLevelWindowMac::MacSetMetalAppearance( bool set ) |
1409 | { | |
1410 | #if TARGET_API_MAC_OSX | |
789ae0cf | 1411 | wxASSERT_MSG( m_macUsesCompositing , |
facd6764 SC |
1412 | wxT("Cannot set metal appearance on a non-compositing window") ) ; |
1413 | ||
1414 | MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes , | |
1415 | set ? kWindowNoAttributes : kWindowMetalAttribute ) ; | |
1416 | #endif | |
1417 | } | |
1542ea39 | 1418 | |
6aab345b SC |
1419 | bool wxTopLevelWindowMac::MacGetMetalAppearance() const |
1420 | { | |
1421 | #if TARGET_API_MAC_OSX | |
1422 | return MacGetWindowAttributes() & kWindowMetalAttribute ; | |
1423 | #else | |
1424 | return false ; | |
1425 | #endif | |
1426 | } | |
1427 | ||
facd6764 SC |
1428 | void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet , wxUint32 attributesToClear ) |
1429 | { | |
1430 | ChangeWindowAttributes ( (WindowRef) m_macWindow , attributesToSet, attributesToClear ) ; | |
1431 | } | |
1542ea39 | 1432 | |
facd6764 SC |
1433 | wxUint32 wxTopLevelWindowMac::MacGetWindowAttributes() const |
1434 | { | |
1435 | UInt32 attr = 0 ; | |
1436 | GetWindowAttributes((WindowRef) m_macWindow , &attr ) ; | |
1437 | return attr ; | |
5f0b2f22 | 1438 | } |
a07c1212 | 1439 | |
92346151 SC |
1440 | void wxTopLevelWindowMac::MacPerformUpdates() |
1441 | { | |
1442 | #if TARGET_API_MAC_OSX | |
1443 | if ( m_macUsesCompositing ) | |
1444 | { | |
1445 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 | |
1446 | // for composited windows this also triggers a redraw of all | |
1447 | // invalid views in the window | |
1448 | if( UMAGetSystemVersion() >= 0x1030 ) | |
1449 | HIWindowFlush((WindowRef) m_macWindow) ; | |
1450 | else | |
1451 | #endif | |
1452 | { | |
1453 | // the only way to trigger the redrawing on earlier systems is to call | |
1454 | // ReceiveNextEvent | |
1455 | ||
1456 | EventRef currentEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ; | |
1457 | UInt32 currentEventClass = 0 ; | |
1458 | UInt32 currentEventKind = 0 ; | |
1459 | if ( currentEvent != NULL ) | |
1460 | { | |
1461 | currentEventClass = ::GetEventClass( currentEvent ) ; | |
1462 | currentEventKind = ::GetEventKind( currentEvent ) ; | |
1463 | } | |
1464 | if ( currentEventClass != kEventClassMenu ) | |
1465 | { | |
1466 | // when tracking a menu, strange redraw errors occur if we flush now, so leave.. | |
1467 | EventRef theEvent; | |
1468 | OSStatus status = noErr ; | |
1469 | status = ReceiveNextEvent( 0 , NULL , kEventDurationNoWait , false , &theEvent ) ; | |
1470 | } | |
1471 | } | |
1472 | } | |
1473 | else | |
1474 | #endif | |
1475 | { | |
1476 | BeginUpdate( (WindowRef) m_macWindow ) ; | |
1477 | ||
1478 | RgnHandle updateRgn = NewRgn(); | |
1479 | if ( updateRgn ) | |
1480 | { | |
1481 | GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn ); | |
1482 | UpdateControls( (WindowRef)m_macWindow , updateRgn ) ; | |
1483 | // if ( !EmptyRgn( updateRgn ) ) | |
1484 | // MacDoRedraw( updateRgn , 0 , true) ; | |
1485 | DisposeRgn( updateRgn ); | |
1486 | } | |
1487 | EndUpdate( (WindowRef)m_macWindow ) ; | |
1488 | QDFlushPortBuffer( GetWindowPort( (WindowRef)m_macWindow ) , NULL ) ; | |
1489 | } | |
1490 | } | |
1491 | ||
3feeb1e1 SC |
1492 | // Attracts the users attention to this window if the application is |
1493 | // inactive (should be called when a background event occurs) | |
1494 | ||
1495 | static pascal void wxMacNMResponse( NMRecPtr ptr ) | |
1496 | { | |
1497 | NMRemove( ptr ) ; | |
1498 | DisposePtr( (Ptr) ptr ) ; | |
1499 | } | |
1500 | ||
1501 | ||
1502 | void wxTopLevelWindowMac::RequestUserAttention(int flags ) | |
1503 | { | |
1504 | NMRecPtr notificationRequest = (NMRecPtr) NewPtr( sizeof( NMRec) ) ; | |
1505 | static wxMacNMUPP nmupp( wxMacNMResponse ) | |
1506 | ; | |
1507 | memset( notificationRequest , 0 , sizeof(*notificationRequest) ) ; | |
1508 | notificationRequest->qType = nmType ; | |
1509 | notificationRequest->nmMark = 1 ; | |
1510 | notificationRequest->nmIcon = 0 ; | |
1511 | notificationRequest->nmSound = 0 ; | |
1512 | notificationRequest->nmStr = NULL ; | |
1513 | notificationRequest->nmResp = nmupp ; | |
1514 | verify_noerr( NMInstall( notificationRequest ) ) ; | |
1515 | } | |
1516 | ||
facd6764 SC |
1517 | // --------------------------------------------------------------------------- |
1518 | // Shape implementation | |
1519 | // --------------------------------------------------------------------------- | |
1520 | ||
6a7e6411 | 1521 | |
1542ea39 RD |
1522 | bool wxTopLevelWindowMac::SetShape(const wxRegion& region) |
1523 | { | |
6a7e6411 RD |
1524 | wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE, |
1525 | _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); | |
1526 | ||
1527 | // The empty region signifies that the shape should be removed from the | |
1528 | // window. | |
1529 | if ( region.IsEmpty() ) | |
1530 | { | |
1531 | wxSize sz = GetClientSize(); | |
1532 | wxRegion rgn(0, 0, sz.x, sz.y); | |
1533 | return SetShape(rgn); | |
1534 | } | |
1535 | ||
1536 | // Make a copy of the region | |
1537 | RgnHandle shapeRegion = NewRgn(); | |
1538 | CopyRgn( (RgnHandle)region.GetWXHRGN(), shapeRegion ); | |
1539 | ||
1540 | // Dispose of any shape region we may already have | |
1541 | RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() ); | |
1542 | if ( oldRgn ) | |
1543 | DisposeRgn(oldRgn); | |
1544 | ||
1545 | // Save the region so we can use it later | |
1546 | SetWRefCon((WindowRef)MacGetWindowRef(), (SInt32)shapeRegion); | |
1547 | ||
1548 | // Tell the window manager that the window has changed shape | |
1549 | ReshapeCustomWindow((WindowRef)MacGetWindowRef()); | |
1550 | return TRUE; | |
1551 | } | |
1552 | ||
6a7e6411 RD |
1553 | // --------------------------------------------------------------------------- |
1554 | // Support functions for shaped windows, based on Apple's CustomWindow sample at | |
1555 | // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm | |
1556 | // --------------------------------------------------------------------------- | |
1557 | ||
6a7e6411 RD |
1558 | static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect) |
1559 | { | |
1560 | GetWindowPortBounds(window, inRect); | |
1561 | Point pt = {inRect->left, inRect->top}; | |
d6fd667b | 1562 | QDLocalToGlobalPoint( GetWindowPort(window) , &pt ) ; |
6a7e6411 RD |
1563 | inRect->top = pt.v; |
1564 | inRect->left = pt.h; | |
1565 | inRect->bottom += pt.v; | |
1566 | inRect->right += pt.h; | |
1567 | } | |
1568 | ||
1569 | ||
1570 | static SInt32 wxShapedMacWindowGetFeatures(WindowRef window, SInt32 param) | |
1571 | { | |
1572 | /*------------------------------------------------------ | |
1573 | Define which options your custom window supports. | |
1574 | --------------------------------------------------------*/ | |
1575 | //just enable everything for our demo | |
1576 | *(OptionBits*)param=//kWindowCanGrow| | |
1577 | //kWindowCanZoom| | |
1578 | //kWindowCanCollapse| | |
1579 | //kWindowCanGetWindowRegion| | |
1580 | //kWindowHasTitleBar| | |
1581 | //kWindowSupportsDragHilite| | |
1582 | kWindowCanDrawInCurrentPort| | |
1583 | //kWindowCanMeasureTitle| | |
1584 | kWindowWantsDisposeAtProcessDeath| | |
ae53adb4 | 1585 | kWindowSupportsGetGrowImageRegion| |
6a7e6411 RD |
1586 | kWindowDefSupportsColorGrafPort; |
1587 | return 1; | |
1542ea39 | 1588 | } |
6a7e6411 RD |
1589 | |
1590 | // The content region is left as a rectangle matching the window size, this is | |
1591 | // so the origin in the paint event, and etc. still matches what the | |
1592 | // programmer expects. | |
1593 | static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn) | |
1594 | { | |
1595 | SetEmptyRgn(rgn); | |
1596 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow(window); | |
1597 | if (win) | |
1598 | { | |
b19bf058 SC |
1599 | Rect r ; |
1600 | wxShapedMacWindowGetPos(window, &r ) ; | |
1601 | RectRgn( rgn , &r ) ; | |
6a7e6411 RD |
1602 | } |
1603 | } | |
1604 | ||
1605 | // The structure region is set to the shape given to the SetShape method. | |
1606 | static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn) | |
1607 | { | |
1608 | RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window); | |
1609 | ||
1610 | SetEmptyRgn(rgn); | |
1611 | if (cachedRegion) | |
1612 | { | |
1613 | Rect windowRect; | |
1614 | wxShapedMacWindowGetPos(window, &windowRect); //how big is the window | |
1615 | CopyRgn(cachedRegion, rgn); //make a copy of our cached region | |
1616 | OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window | |
1617 | //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size | |
1618 | } | |
1619 | } | |
1620 | ||
1621 | ||
1622 | ||
1623 | static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param) | |
1624 | { | |
1625 | GetWindowRegionPtr rgnRec=(GetWindowRegionPtr)param; | |
1626 | ||
1627 | switch(rgnRec->regionCode) | |
1628 | { | |
1629 | case kWindowStructureRgn: | |
1630 | wxShapedMacWindowStructureRegion(window, rgnRec->winRgn); | |
1631 | break; | |
1632 | case kWindowContentRgn: | |
1633 | wxShapedMacWindowContentRegion(window, rgnRec->winRgn); | |
1634 | break; | |
1635 | default: | |
1636 | SetEmptyRgn(rgnRec->winRgn); | |
1637 | } //switch | |
1638 | ||
1639 | return noErr; | |
1640 | } | |
1641 | ||
1642 | ||
1643 | static SInt32 wxShapedMacWindowHitTest(WindowRef window,SInt32 param) | |
1644 | { | |
1645 | /*------------------------------------------------------ | |
1646 | Determine the region of the window which was hit | |
1647 | --------------------------------------------------------*/ | |
1648 | Point hitPoint; | |
1649 | static RgnHandle tempRgn=nil; | |
1650 | ||
1651 | if(!tempRgn) | |
1652 | tempRgn=NewRgn(); | |
1653 | ||
1654 | SetPt(&hitPoint,LoWord(param),HiWord(param));//get the point clicked | |
1655 | ||
1656 | //Mac OS 8.5 or later | |
1657 | wxShapedMacWindowStructureRegion(window, tempRgn); | |
1658 | if (PtInRgn(hitPoint, tempRgn)) //in window content region? | |
1659 | return wInContent; | |
1660 | ||
1661 | return wNoHit;//no significant area was hit. | |
1662 | } | |
1663 | ||
1664 | ||
1665 | static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param) | |
1666 | { | |
1667 | switch(message) | |
1668 | { | |
1669 | case kWindowMsgHitTest: | |
1670 | return wxShapedMacWindowHitTest(window,param); | |
1671 | ||
1672 | case kWindowMsgGetFeatures: | |
1673 | return wxShapedMacWindowGetFeatures(window,param); | |
1674 | ||
1675 | // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow | |
1676 | case kWindowMsgGetRegion: | |
1677 | return wxShapedMacWindowGetRegion(window,param); | |
1678 | } | |
1679 | ||
1680 | return 0; | |
1681 | } | |
1925be65 | 1682 | |
6a7e6411 | 1683 | // --------------------------------------------------------------------------- |
1925be65 | 1684 |