]>
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 | ||
20 | #ifdef __GNUG__ | |
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" |
a15eb0a5 SC |
39 | #endif //WX_PRECOMP |
40 | ||
5f0b2f22 | 41 | #include "wx/mac/uma.h" |
422644a3 | 42 | #include "wx/mac/aga.h" |
7c091673 | 43 | #include "wx/app.h" |
5f0b2f22 | 44 | #include "wx/tooltip.h" |
a07c1212 | 45 | #include "wx/dnd.h" |
1f90939c SC |
46 | #if wxUSE_SYSTEM_OPTIONS |
47 | #include "wx/sysopt.h" | |
48 | #endif | |
5f0b2f22 | 49 | |
7f0c3a63 | 50 | #include <ToolUtils.h> |
dd49c691 | 51 | |
a15eb0a5 SC |
52 | // ---------------------------------------------------------------------------- |
53 | // globals | |
54 | // ---------------------------------------------------------------------------- | |
55 | ||
56 | // list of all frames and modeless dialogs | |
32b5be3d RR |
57 | wxWindowList wxModelessWindows; |
58 | ||
6a7e6411 RD |
59 | static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param); |
60 | ||
a15eb0a5 SC |
61 | // ============================================================================ |
62 | // wxTopLevelWindowMac implementation | |
63 | // ============================================================================ | |
64 | ||
facd6764 SC |
65 | BEGIN_EVENT_TABLE(wxTopLevelWindowMac, wxTopLevelWindowBase) |
66 | END_EVENT_TABLE() | |
67 | ||
68 | ||
851b3a88 SC |
69 | // --------------------------------------------------------------------------- |
70 | // Carbon Events | |
71 | // --------------------------------------------------------------------------- | |
72 | ||
851b3a88 SC |
73 | extern long wxMacTranslateKey(unsigned char key, unsigned char code) ; |
74 | ||
1542ea39 | 75 | static const EventTypeSpec eventList[] = |
851b3a88 | 76 | { |
facd6764 | 77 | // TODO remove control related event like key and mouse (except for WindowLeave events) |
949cb163 | 78 | #if 1 |
851b3a88 | 79 | { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } , |
c5c9378c | 80 | |
e40298d5 | 81 | { kEventClassKeyboard, kEventRawKeyDown } , |
c5c9378c SC |
82 | { kEventClassKeyboard, kEventRawKeyRepeat } , |
83 | { kEventClassKeyboard, kEventRawKeyUp } , | |
84 | { kEventClassKeyboard, kEventRawKeyModifiersChanged } , | |
facd6764 | 85 | #endif |
c5c9378c | 86 | |
16a76184 | 87 | { kEventClassWindow , kEventWindowShown } , |
851b3a88 SC |
88 | { kEventClassWindow , kEventWindowActivated } , |
89 | { kEventClassWindow , kEventWindowDeactivated } , | |
90 | { kEventClassWindow , kEventWindowBoundsChanging } , | |
91 | { kEventClassWindow , kEventWindowBoundsChanged } , | |
92 | { kEventClassWindow , kEventWindowClose } , | |
93 | ||
facd6764 SC |
94 | // we have to catch these events on the toplevel window level, as controls don't get the |
95 | // raw mouse events anymore | |
96 | ||
851b3a88 SC |
97 | { kEventClassMouse , kEventMouseDown } , |
98 | { kEventClassMouse , kEventMouseUp } , | |
de127c69 | 99 | { kEventClassMouse , kEventMouseWheelMoved } , |
851b3a88 SC |
100 | { kEventClassMouse , kEventMouseMoved } , |
101 | { kEventClassMouse , kEventMouseDragged } , | |
851b3a88 SC |
102 | } ; |
103 | ||
104 | static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
105 | { | |
106 | OSStatus result = eventNotHandledErr ; | |
851b3a88 | 107 | |
c5c9378c | 108 | wxWindow* focus = wxWindow::FindFocus() ; |
e40298d5 | 109 | char charCode ; |
1542ea39 | 110 | UInt32 keyCode ; |
c5c9378c | 111 | UInt32 modifiers ; |
e40298d5 | 112 | Point point ; |
c5c9378c SC |
113 | |
114 | EventRef rawEvent ; | |
1542ea39 | 115 | |
c5c9378c | 116 | GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ; |
1542ea39 | 117 | |
e40298d5 JS |
118 | GetEventParameter( rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); |
119 | GetEventParameter( rawEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
120 | GetEventParameter( rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); | |
121 | GetEventParameter( rawEvent, kEventParamMouseLocation, typeQDPoint, NULL, | |
122 | sizeof( Point ), NULL, &point ); | |
123 | ||
e40298d5 JS |
124 | switch ( GetEventKind( event ) ) |
125 | { | |
126 | case kEventTextInputUnicodeForKeyEvent : | |
ace07c80 | 127 | // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not |
5d2e69e8 | 128 | // get its own kEventTextInputUnicodeForKeyEvent, so we route back the |
ace07c80 SC |
129 | wxControl* control = wxDynamicCast( focus , wxControl ) ; |
130 | if ( control ) | |
131 | { | |
facd6764 | 132 | ControlRef macControl = (ControlRef) control->GetHandle() ; |
ace07c80 SC |
133 | if ( macControl ) |
134 | { | |
135 | ::HandleControlKey( macControl , keyCode , charCode , modifiers ) ; | |
136 | result = noErr ; | |
137 | } | |
138 | } | |
139 | /* | |
140 | // this may lead to double events sent to a window in case all handlers have skipped the key down event | |
77a4354e VZ |
141 | UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; |
142 | UInt32 message = (keyCode << 8) + charCode; | |
143 | ||
1542ea39 | 144 | if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( |
e40298d5 JS |
145 | focus , message , modifiers , when , point.h , point.v ) ) |
146 | { | |
147 | result = noErr ; | |
148 | } | |
ace07c80 | 149 | */ |
e40298d5 JS |
150 | break ; |
151 | } | |
c5c9378c SC |
152 | |
153 | return result ; | |
154 | } | |
155 | ||
156 | static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
157 | { | |
158 | OSStatus result = eventNotHandledErr ; | |
159 | ||
160 | wxWindow* focus = wxWindow::FindFocus() ; | |
92a7272f SC |
161 | if ( focus == NULL ) |
162 | return result ; | |
163 | ||
e40298d5 | 164 | char charCode ; |
1542ea39 | 165 | UInt32 keyCode ; |
c5c9378c | 166 | UInt32 modifiers ; |
e40298d5 JS |
167 | Point point ; |
168 | UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; | |
169 | ||
170 | GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode ); | |
171 | GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode ); | |
172 | GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); | |
173 | GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, | |
174 | sizeof( Point ), NULL, &point ); | |
175 | ||
176 | UInt32 message = (keyCode << 8) + charCode; | |
177 | switch( GetEventKind( event ) ) | |
178 | { | |
179 | case kEventRawKeyRepeat : | |
180 | case kEventRawKeyDown : | |
e40298d5 | 181 | { |
404f1d80 SC |
182 | WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ; |
183 | WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ; | |
184 | wxTheApp->MacSetCurrentEvent( event , handler ) ; | |
185 | if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( | |
186 | focus , message , modifiers , when , point.h , point.v ) ) | |
187 | { | |
188 | result = noErr ; | |
189 | } | |
190 | wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ; | |
e40298d5 JS |
191 | } |
192 | break ; | |
193 | case kEventRawKeyUp : | |
1542ea39 | 194 | if ( (focus != NULL) && wxTheApp->MacSendKeyUpEvent( |
e40298d5 JS |
195 | focus , message , modifiers , when , point.h , point.v ) ) |
196 | { | |
197 | result = noErr ; | |
198 | } | |
199 | break ; | |
200 | case kEventRawKeyModifiersChanged : | |
201 | { | |
202 | wxKeyEvent event(wxEVT_KEY_DOWN); | |
203 | ||
204 | event.m_shiftDown = modifiers & shiftKey; | |
205 | event.m_controlDown = modifiers & controlKey; | |
206 | event.m_altDown = modifiers & optionKey; | |
207 | event.m_metaDown = modifiers & cmdKey; | |
208 | ||
209 | event.m_x = point.h; | |
210 | event.m_y = point.v; | |
211 | event.m_timeStamp = when; | |
212 | wxWindow* focus = wxWindow::FindFocus() ; | |
213 | event.SetEventObject(focus); | |
214 | ||
8d60dc8a | 215 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & controlKey ) |
e40298d5 JS |
216 | { |
217 | event.m_keyCode = WXK_CONTROL ; | |
218 | event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
219 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
220 | } | |
8d60dc8a | 221 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & shiftKey ) |
e40298d5 JS |
222 | { |
223 | event.m_keyCode = WXK_SHIFT ; | |
224 | event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
225 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
226 | } | |
8d60dc8a | 227 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & optionKey ) |
e40298d5 JS |
228 | { |
229 | event.m_keyCode = WXK_ALT ; | |
230 | event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
231 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
232 | } | |
b7aec135 SC |
233 | if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & cmdKey ) |
234 | { | |
235 | event.m_keyCode = WXK_COMMAND ; | |
236 | event.SetEventType( ( modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
237 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
238 | } | |
e40298d5 JS |
239 | wxTheApp->s_lastModifiers = modifiers ; |
240 | } | |
241 | break ; | |
242 | } | |
851b3a88 SC |
243 | |
244 | return result ; | |
245 | } | |
246 | ||
facd6764 SC |
247 | // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr |
248 | // for windows that we didn't create (like eg Scrollbars in a databrowser) , or for controls where we did not handle the | |
249 | // mouse down at all | |
851b3a88 | 250 | |
facd6764 | 251 | // This handler can also be called from app level where data (ie target window) may be null or a non wx window |
1542ea39 | 252 | |
facd6764 | 253 | wxWindow* g_MacLastWindow = NULL ; |
a3195b73 | 254 | |
facd6764 SC |
255 | static void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent ) |
256 | { | |
257 | UInt32 modifiers = cEvent.GetParameter<UInt32>(kEventParamKeyModifiers, typeUInt32) ; | |
258 | Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ; | |
67245665 | 259 | |
facd6764 SC |
260 | // this parameter are not given for all events |
261 | EventMouseButton button = 0 ; | |
262 | UInt32 clickCount = 0 ; | |
263 | cEvent.GetParameter<EventMouseButton>(kEventParamMouseButton, typeMouseButton , &button) ; | |
264 | cEvent.GetParameter<UInt32>(kEventParamClickCount, typeUInt32 , &clickCount ) ; | |
265 | ||
266 | wxevent.m_x = screenMouseLocation.h; | |
267 | wxevent.m_y = screenMouseLocation.v; | |
268 | wxevent.m_shiftDown = modifiers & shiftKey; | |
269 | wxevent.m_controlDown = modifiers & controlKey; | |
270 | wxevent.m_altDown = modifiers & optionKey; | |
271 | wxevent.m_metaDown = modifiers & cmdKey; | |
272 | wxevent.SetTimestamp( cEvent.GetTicks() ) ; | |
273 | // a control click is interpreted as a right click | |
274 | if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) ) | |
851b3a88 | 275 | { |
facd6764 SC |
276 | button = kEventMouseButtonSecondary ; |
277 | } | |
278 | ||
279 | // determinate the correct down state, wx does not want a 'down' for a mouseUp event, while mac delivers | |
280 | // this button | |
281 | if ( button != 0 && cEvent.GetKind() != kEventMouseUp ) | |
282 | { | |
283 | switch( button ) | |
e40298d5 | 284 | { |
facd6764 SC |
285 | case kEventMouseButtonPrimary : |
286 | wxevent.m_leftDown = true ; | |
e40298d5 | 287 | break ; |
facd6764 SC |
288 | case kEventMouseButtonSecondary : |
289 | wxevent.m_rightDown = true ; | |
e40298d5 | 290 | break ; |
facd6764 SC |
291 | case kEventMouseButtonTertiary : |
292 | wxevent.m_middleDown = true ; | |
e40298d5 | 293 | break ; |
facd6764 SC |
294 | } |
295 | } | |
296 | // determinate the correct click button | |
297 | if ( button == kEventMouseButtonSecondary ) | |
298 | { | |
299 | if (cEvent.GetKind() == kEventMouseDown ) | |
92a7272f | 300 | wxevent.SetEventType( clickCount > 1 ? wxEVT_RIGHT_DCLICK : wxEVT_RIGHT_DOWN ) ; |
facd6764 SC |
301 | else if ( cEvent.GetKind() == kEventMouseUp ) |
302 | wxevent.SetEventType(wxEVT_RIGHT_UP ) ; | |
303 | } | |
304 | else if ( button == kEventMouseButtonTertiary ) | |
305 | { | |
306 | if (cEvent.GetKind() == kEventMouseDown ) | |
307 | wxevent.SetEventType(clickCount > 1 ? wxEVT_MIDDLE_DCLICK : wxEVT_MIDDLE_DOWN ) ; | |
308 | else if ( cEvent.GetKind() == kEventMouseUp ) | |
309 | wxevent.SetEventType(wxEVT_MIDDLE_UP ) ; | |
310 | } | |
311 | else | |
312 | { | |
313 | if (cEvent.GetKind() == kEventMouseDown ) | |
314 | wxevent.SetEventType(clickCount > 1 ? wxEVT_LEFT_DCLICK : wxEVT_LEFT_DOWN ) ; | |
315 | else if ( cEvent.GetKind() == kEventMouseUp ) | |
316 | wxevent.SetEventType(wxEVT_LEFT_UP ) ; | |
317 | else if ( cEvent.GetKind() == kEventMouseWheelMoved ) | |
318 | { | |
319 | wxevent.SetEventType(wxEVT_MOUSEWHEEL ) ; | |
320 | ||
321 | // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ; | |
322 | SInt32 delta = cEvent.GetParameter<SInt32>(kEventParamMouseWheelDelta, typeLongInteger) ; | |
323 | ||
324 | wxevent.m_wheelRotation = delta; | |
325 | wxevent.m_wheelDelta = 1; | |
326 | wxevent.m_linesPerAction = 1; | |
327 | } | |
328 | else | |
329 | wxevent.SetEventType(wxEVT_MOTION ) ; | |
330 | } | |
331 | } | |
332 | ||
333 | ControlRef wxMacFindSubControl( Point location , ControlRef superControl , ControlPartCode *outPart ) | |
334 | { | |
335 | if ( superControl ) | |
336 | { | |
337 | UInt16 childrenCount = 0 ; | |
338 | OSStatus err = CountSubControls( superControl , &childrenCount ) ; | |
339 | if ( err == errControlIsNotEmbedder ) | |
340 | return NULL ; | |
341 | wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ; | |
342 | ||
343 | for ( UInt16 i = childrenCount ; i >=1 ; --i ) | |
344 | { | |
345 | ControlHandle sibling ; | |
346 | err = GetIndexedSubControl( superControl , i , & sibling ) ; | |
347 | if ( err == errControlIsNotEmbedder ) | |
348 | return NULL ; | |
349 | ||
350 | wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ; | |
351 | if ( IsControlVisible( sibling ) ) | |
352 | { | |
353 | Rect r ; | |
d6fd667b | 354 | UMAGetControlBoundsInWindowCoords( sibling , &r ) ; |
facd6764 | 355 | if ( MacPtInRect( location , &r ) ) |
de127c69 | 356 | { |
facd6764 SC |
357 | ControlHandle child = wxMacFindSubControl( location , sibling , outPart ) ; |
358 | if ( child ) | |
359 | return child ; | |
360 | else | |
de127c69 | 361 | { |
d6fd667b SC |
362 | Point testLocation = location ; |
363 | #if TARGET_API_MAC_OSX | |
364 | testLocation.h -= r.left ; | |
365 | testLocation.v -= r.top ; | |
366 | #endif | |
367 | *outPart = TestControl( sibling , testLocation ) ; | |
facd6764 | 368 | return sibling ; |
de127c69 GD |
369 | } |
370 | } | |
facd6764 | 371 | } |
e40298d5 JS |
372 | } |
373 | } | |
facd6764 SC |
374 | return NULL ; |
375 | } | |
1542ea39 | 376 | |
facd6764 SC |
377 | ControlRef wxMacFindControlUnderMouse( Point location , WindowRef window , ControlPartCode *outPart ) |
378 | { | |
379 | #if TARGET_API_MAC_OSX | |
7741dfb1 | 380 | if ( UMAGetSystemVersion() >= 0x1030 ) |
30e0b1c9 SC |
381 | return FindControlUnderMouse( location , window , outPart ) ; |
382 | #endif | |
facd6764 SC |
383 | ControlRef rootControl = NULL ; |
384 | verify_noerr( GetRootControl( window , &rootControl ) ) ; | |
385 | return wxMacFindSubControl( location , rootControl , outPart ) ; | |
30e0b1c9 | 386 | |
facd6764 SC |
387 | } |
388 | pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
389 | { | |
390 | ||
391 | OSStatus result = eventNotHandledErr ; | |
392 | ||
393 | wxMacCarbonEvent cEvent( event ) ; | |
394 | ||
395 | Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ; | |
396 | Point windowMouseLocation = screenMouseLocation ; | |
397 | ||
398 | WindowRef window ; | |
399 | short windowPart = ::FindWindow(screenMouseLocation, &window); | |
400 | ||
401 | wxWindow* currentMouseWindow = NULL ; | |
7741dfb1 | 402 | |
facd6764 SC |
403 | if ( window ) |
404 | { | |
d6fd667b | 405 | QDGlobalToLocalPoint( UMAGetWindowPort(window ) , &windowMouseLocation ) ; |
facd6764 SC |
406 | |
407 | if ( wxTheApp->s_captureWindow && wxTheApp->s_captureWindow->MacGetTopLevelWindowRef() == (WXWindow) window && windowPart == inContent ) | |
408 | { | |
409 | currentMouseWindow = wxTheApp->s_captureWindow ; | |
410 | } | |
411 | else if ( (IsWindowActive(window) && windowPart == inContent) ) | |
412 | { | |
413 | ControlPartCode part ; | |
414 | ControlRef control = wxMacFindControlUnderMouse( windowMouseLocation , window , &part ) ; | |
b19bf058 SC |
415 | if ( control == 0 ) |
416 | currentMouseWindow = (wxWindow*) data ; | |
417 | else | |
418 | currentMouseWindow = wxFindControlFromMacControl( control ) ; | |
facd6764 SC |
419 | } |
420 | } | |
421 | ||
422 | wxMouseEvent wxevent(wxEVT_LEFT_DOWN); | |
423 | SetupMouseEvent( wxevent , cEvent ) ; | |
424 | ||
425 | // handle all enter / leave events | |
426 | ||
427 | if ( currentMouseWindow != g_MacLastWindow ) | |
428 | { | |
429 | if ( g_MacLastWindow ) | |
430 | { | |
431 | wxMouseEvent eventleave(wxevent); | |
432 | eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); | |
433 | g_MacLastWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); | |
434 | eventleave.SetEventObject( g_MacLastWindow ) ; | |
435 | ||
436 | #if wxUSE_TOOLTIPS | |
437 | wxToolTip::RelayEvent( g_MacLastWindow , eventleave); | |
438 | #endif // wxUSE_TOOLTIPS | |
439 | g_MacLastWindow->GetEventHandler()->ProcessEvent(eventleave); | |
440 | } | |
441 | if ( currentMouseWindow ) | |
442 | { | |
443 | wxMouseEvent evententer(wxevent); | |
444 | evententer.SetEventType( wxEVT_ENTER_WINDOW ); | |
445 | currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); | |
446 | evententer.SetEventObject( currentMouseWindow ) ; | |
447 | #if wxUSE_TOOLTIPS | |
448 | wxToolTip::RelayEvent( currentMouseWindow , evententer); | |
449 | #endif // wxUSE_TOOLTIPS | |
450 | currentMouseWindow->GetEventHandler()->ProcessEvent(evententer); | |
451 | } | |
452 | g_MacLastWindow = currentMouseWindow ; | |
453 | } | |
454 | ||
455 | if ( windowPart == inMenuBar ) | |
456 | { | |
457 | // special case menu bar, as we are having a low-level runloop we must do it ourselves | |
458 | if ( cEvent.GetKind() == kEventMouseDown ) | |
459 | { | |
460 | ::MenuSelect( screenMouseLocation ) ; | |
461 | result = noErr ; | |
462 | } | |
463 | } // if ( windowPart == inMenuBar ) | |
464 | else if ( currentMouseWindow ) | |
465 | { | |
466 | currentMouseWindow->ScreenToClient( &wxevent.m_x , &wxevent.m_y ) ; | |
467 | ||
468 | wxevent.SetEventObject( currentMouseWindow ) ; | |
469 | ||
470 | // update cursor | |
471 | ||
472 | wxWindow* cursorTarget = currentMouseWindow ; | |
473 | wxPoint cursorPoint( wxevent.m_x , wxevent.m_y ) ; | |
474 | ||
475 | while( cursorTarget && !cursorTarget->MacSetupCursor( cursorPoint ) ) | |
476 | { | |
477 | cursorTarget = cursorTarget->GetParent() ; | |
478 | if ( cursorTarget ) | |
479 | cursorPoint += cursorTarget->GetPosition() ; | |
480 | } | |
1542ea39 | 481 | |
facd6764 | 482 | // update focus |
851b3a88 | 483 | |
facd6764 SC |
484 | if ( wxevent.GetEventType() == wxEVT_LEFT_DOWN ) |
485 | { | |
486 | // set focus to this window | |
487 | if (currentMouseWindow->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow) | |
488 | currentMouseWindow->SetFocus(); | |
489 | } | |
490 | ||
491 | // make tooltips current | |
492 | ||
493 | #if wxUSE_TOOLTIPS | |
494 | if ( wxevent.GetEventType() == wxEVT_MOTION | |
495 | || wxevent.GetEventType() == wxEVT_ENTER_WINDOW | |
496 | || wxevent.GetEventType() == wxEVT_LEAVE_WINDOW ) | |
497 | wxToolTip::RelayEvent( currentMouseWindow , wxevent); | |
498 | #endif // wxUSE_TOOLTIPS | |
499 | if ( currentMouseWindow->GetEventHandler()->ProcessEvent(wxevent) ) | |
500 | result = noErr; | |
30e0b1c9 SC |
501 | else |
502 | { | |
503 | ControlPartCode dummyPart ; | |
504 | // if built-in find control is finding the wrong control (ie static box instead of overlaid | |
505 | // button, we cannot let the standard handler do its job, but must handle manually | |
506 | ||
507 | if ( ( cEvent.GetKind() == kEventMouseDown ) && | |
508 | (FindControlUnderMouse(windowMouseLocation , window , &dummyPart) != | |
509 | wxMacFindControlUnderMouse( windowMouseLocation , window , &dummyPart ) ) ) | |
510 | { | |
511 | EventModifiers modifiers = cEvent.GetParameter<EventModifiers>(kEventParamKeyModifiers, typeUInt32) ; | |
3a9dc061 SC |
512 | Point clickLocation = windowMouseLocation ; |
513 | #if TARGET_API_MAC_OSX | |
514 | currentMouseWindow->MacRootWindowToWindow( &clickLocation.h , &clickLocation.v ) ; | |
515 | #endif | |
516 | HandleControlClick( (ControlRef) currentMouseWindow->GetHandle() , clickLocation , | |
30e0b1c9 SC |
517 | modifiers , (ControlActionUPP ) -1 ) ; |
518 | result = noErr ; | |
519 | } | |
520 | } | |
facd6764 SC |
521 | if ( cEvent.GetKind() == kEventMouseUp && wxTheApp->s_captureWindow ) |
522 | { | |
523 | wxTheApp->s_captureWindow = NULL ; | |
524 | // update cursor ? | |
525 | } | |
526 | } // else if ( currentMouseWindow ) | |
527 | return result ; | |
851b3a88 | 528 | } |
facd6764 SC |
529 | |
530 | static pascal OSStatus wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
851b3a88 SC |
531 | { |
532 | OSStatus result = eventNotHandledErr ; | |
851b3a88 | 533 | |
facd6764 SC |
534 | wxMacCarbonEvent cEvent( event ) ; |
535 | ||
536 | // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ; | |
e40298d5 | 537 | wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; |
1542ea39 | 538 | |
e40298d5 JS |
539 | switch( GetEventKind( event ) ) |
540 | { | |
e40298d5 | 541 | case kEventWindowActivated : |
facd6764 SC |
542 | { |
543 | toplevelWindow->MacActivate( cEvent.GetTicks() , true) ; | |
facd6764 SC |
544 | wxActivateEvent wxevent(wxEVT_ACTIVATE, true , toplevelWindow->GetId()); |
545 | wxevent.SetTimestamp( cEvent.GetTicks() ) ; | |
546 | wxevent.SetEventObject(toplevelWindow); | |
547 | toplevelWindow->GetEventHandler()->ProcessEvent(wxevent); | |
73fe67bd | 548 | // we still sending an eventNotHandledErr in order to allow for default processing |
e40298d5 | 549 | break ; |
facd6764 | 550 | } |
e40298d5 | 551 | case kEventWindowDeactivated : |
facd6764 SC |
552 | { |
553 | toplevelWindow->MacActivate(cEvent.GetTicks() , false) ; | |
554 | wxActivateEvent wxevent(wxEVT_ACTIVATE, false , toplevelWindow->GetId()); | |
555 | wxevent.SetTimestamp( cEvent.GetTicks() ) ; | |
556 | wxevent.SetEventObject(toplevelWindow); | |
557 | toplevelWindow->GetEventHandler()->ProcessEvent(wxevent); | |
73fe67bd | 558 | // we still sending an eventNotHandledErr in order to allow for default processing |
e40298d5 | 559 | break ; |
facd6764 | 560 | } |
16a76184 SC |
561 | case kEventWindowShown : |
562 | toplevelWindow->Refresh() ; | |
563 | result = noErr ; | |
564 | break ; | |
e40298d5 JS |
565 | case kEventWindowClose : |
566 | toplevelWindow->Close() ; | |
567 | result = noErr ; | |
568 | break ; | |
569 | case kEventWindowBoundsChanged : | |
facd6764 SC |
570 | { |
571 | UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ; | |
572 | Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ; | |
573 | wxRect r( newRect.left , newRect.top , newRect.right - newRect.left , newRect.bottom - newRect.top ) ; | |
574 | if ( attributes & kWindowBoundsChangeSizeChanged ) | |
e40298d5 | 575 | { |
facd6764 SC |
576 | // according to the other ports we handle this within the OS level |
577 | // resize event, not within a wxSizeEvent | |
578 | wxFrame *frame = wxDynamicCast( toplevelWindow , wxFrame ) ; | |
579 | if ( frame ) | |
580 | { | |
581 | #if wxUSE_STATUSBAR | |
582 | frame->PositionStatusBar(); | |
583 | #endif | |
584 | #if wxUSE_TOOLBAR | |
585 | frame->PositionToolBar(); | |
586 | #endif | |
587 | } | |
1542ea39 | 588 | |
facd6764 SC |
589 | wxSizeEvent event( r.GetSize() , toplevelWindow->GetId() ) ; |
590 | event.SetEventObject( toplevelWindow ) ; | |
851b3a88 | 591 | |
facd6764 | 592 | toplevelWindow->GetEventHandler()->ProcessEvent(event) ; |
e40298d5 | 593 | } |
facd6764 SC |
594 | if ( attributes & kWindowBoundsChangeOriginChanged ) |
595 | { | |
596 | wxMoveEvent event( r.GetLeftTop() , toplevelWindow->GetId() ) ; | |
597 | event.SetEventObject( toplevelWindow ) ; | |
598 | toplevelWindow->GetEventHandler()->ProcessEvent(event) ; | |
599 | } | |
600 | result = noErr ; | |
e40298d5 | 601 | break ; |
facd6764 | 602 | } |
f81bfef9 | 603 | case kEventWindowBoundsChanging : |
facd6764 SC |
604 | { |
605 | UInt32 attributes = cEvent.GetParameter<UInt32>(kEventParamAttributes,typeUInt32) ; | |
606 | Rect newRect = cEvent.GetParameter<Rect>(kEventParamCurrentBounds) ; | |
83901ec2 | 607 | |
facd6764 SC |
608 | if ( (attributes & kWindowBoundsChangeSizeChanged) || (attributes & kWindowBoundsChangeOriginChanged) ) |
609 | { | |
29281095 SC |
610 | // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates |
611 | int left , top , right , bottom ; | |
612 | toplevelWindow->MacGetContentAreaInset( left , top , right , bottom ) ; | |
613 | wxRect r( newRect.left - left , newRect.top - top , | |
614 | newRect.right - newRect.left + left + right , newRect.bottom - newRect.top + top + bottom ) ; | |
facd6764 SC |
615 | // this is a EVT_SIZING not a EVT_SIZE type ! |
616 | wxSizeEvent wxevent( r , toplevelWindow->GetId() ) ; | |
617 | wxevent.SetEventObject( toplevelWindow ) ; | |
618 | wxRect adjustR = r ; | |
619 | if ( toplevelWindow->GetEventHandler()->ProcessEvent(wxevent) ) | |
facd6764 | 620 | adjustR = wxevent.GetRect() ; |
29281095 | 621 | |
facd6764 SC |
622 | if ( toplevelWindow->GetMaxWidth() != -1 && adjustR.GetWidth() > toplevelWindow->GetMaxWidth() ) |
623 | adjustR.SetWidth( toplevelWindow->GetMaxWidth() ) ; | |
2c25bd55 | 624 | if ( toplevelWindow->GetMaxHeight() != -1 && adjustR.GetHeight() > toplevelWindow->GetMaxHeight() ) |
facd6764 SC |
625 | adjustR.SetHeight( toplevelWindow->GetMaxHeight() ) ; |
626 | if ( toplevelWindow->GetMinWidth() != -1 && adjustR.GetWidth() < toplevelWindow->GetMinWidth() ) | |
627 | adjustR.SetWidth( toplevelWindow->GetMinWidth() ) ; | |
2c25bd55 | 628 | if ( toplevelWindow->GetMinHeight() != -1 && adjustR.GetHeight() < toplevelWindow->GetMinHeight() ) |
facd6764 | 629 | adjustR.SetHeight( toplevelWindow->GetMinHeight() ) ; |
34952e03 | 630 | Rect adjustedRect = { adjustR.y + top , adjustR.x + left , adjustR.y + adjustR.height - bottom , adjustR.x + adjustR.width - right } ; |
facd6764 SC |
631 | if ( !EqualRect( &newRect , &adjustedRect ) ) |
632 | cEvent.SetParameter( kEventParamCurrentBounds , &adjustedRect ) ; | |
f81bfef9 | 633 | } |
facd6764 SC |
634 | |
635 | result = noErr ; | |
f81bfef9 | 636 | break ; |
facd6764 | 637 | } |
e40298d5 JS |
638 | default : |
639 | break ; | |
640 | } | |
641 | return result ; | |
851b3a88 SC |
642 | } |
643 | ||
facd6764 | 644 | pascal OSStatus wxMacTopLevelEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) |
851b3a88 SC |
645 | { |
646 | OSStatus result = eventNotHandledErr ; | |
647 | ||
648 | switch ( GetEventClass( event ) ) | |
649 | { | |
c5c9378c | 650 | case kEventClassKeyboard : |
e40298d5 | 651 | result = KeyboardEventHandler( handler, event , data ) ; |
c5c9378c | 652 | break ; |
851b3a88 | 653 | case kEventClassTextInput : |
e40298d5 | 654 | result = TextInputEventHandler( handler, event , data ) ; |
851b3a88 SC |
655 | break ; |
656 | case kEventClassWindow : | |
facd6764 | 657 | result = wxMacTopLevelWindowEventHandler( handler, event , data ) ; |
e40298d5 | 658 | break ; |
851b3a88 | 659 | case kEventClassMouse : |
facd6764 | 660 | result = wxMacTopLevelMouseEventHandler( handler, event , data ) ; |
e40298d5 | 661 | break ; |
851b3a88 SC |
662 | default : |
663 | break ; | |
664 | } | |
665 | return result ; | |
666 | } | |
667 | ||
facd6764 | 668 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler ) |
851b3a88 | 669 | |
5f0b2f22 SC |
670 | // --------------------------------------------------------------------------- |
671 | // wxWindowMac utility functions | |
672 | // --------------------------------------------------------------------------- | |
673 | ||
674 | // Find an item given the Macintosh Window Reference | |
675 | ||
facd6764 SC |
676 | wxList wxWinMacWindowList(wxKEY_INTEGER); |
677 | wxTopLevelWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef) | |
5f0b2f22 | 678 | { |
facd6764 | 679 | wxNode *node = wxWinMacWindowList.Find((long)inWindowRef); |
5f0b2f22 SC |
680 | if (!node) |
681 | return NULL; | |
eb22f2a6 | 682 | return (wxTopLevelWindowMac *)node->GetData(); |
5f0b2f22 SC |
683 | } |
684 | ||
facd6764 SC |
685 | void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) ; |
686 | void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxTopLevelWindowMac *win) | |
5f0b2f22 SC |
687 | { |
688 | // adding NULL WindowRef is (first) surely a result of an error and | |
689 | // (secondly) breaks menu command processing | |
427ff662 | 690 | wxCHECK_RET( inWindowRef != (WindowRef) NULL, wxT("attempt to add a NULL WindowRef to window list") ); |
5f0b2f22 | 691 | |
facd6764 SC |
692 | if ( !wxWinMacWindowList.Find((long)inWindowRef) ) |
693 | wxWinMacWindowList.Append((long)inWindowRef, win); | |
5f0b2f22 SC |
694 | } |
695 | ||
facd6764 | 696 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) ; |
5f0b2f22 SC |
697 | void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win) |
698 | { | |
facd6764 | 699 | wxWinMacWindowList.DeleteObject(win); |
5f0b2f22 SC |
700 | } |
701 | ||
702 | ||
a15eb0a5 SC |
703 | // ---------------------------------------------------------------------------- |
704 | // wxTopLevelWindowMac creation | |
705 | // ---------------------------------------------------------------------------- | |
706 | ||
245f3581 | 707 | wxTopLevelWindowMac *wxTopLevelWindowMac::s_macDeactivateWindow = NULL; |
5f0b2f22 | 708 | |
a15eb0a5 SC |
709 | void wxTopLevelWindowMac::Init() |
710 | { | |
711 | m_iconized = | |
712 | m_maximizeOnShow = FALSE; | |
6a17ca35 | 713 | m_macWindow = NULL ; |
facd6764 SC |
714 | #if TARGET_API_MAC_OSX |
715 | m_macUsesCompositing = TRUE; | |
716 | #else | |
717 | m_macUsesCompositing = FALSE; | |
718 | #endif | |
7c091673 | 719 | m_macEventHandler = NULL ; |
a15eb0a5 SC |
720 | } |
721 | ||
118f012e SC |
722 | class wxMacDeferredWindowDeleter : public wxObject |
723 | { | |
724 | public : | |
1542ea39 RD |
725 | wxMacDeferredWindowDeleter( WindowRef windowRef ) |
726 | { | |
727 | m_macWindow = windowRef ; | |
118f012e | 728 | } |
1542ea39 RD |
729 | virtual ~wxMacDeferredWindowDeleter() |
730 | { | |
731 | UMADisposeWindow( (WindowRef) m_macWindow ) ; | |
118f012e SC |
732 | } |
733 | protected : | |
734 | WindowRef m_macWindow ; | |
735 | } ; | |
736 | ||
a15eb0a5 SC |
737 | bool wxTopLevelWindowMac::Create(wxWindow *parent, |
738 | wxWindowID id, | |
739 | const wxString& title, | |
740 | const wxPoint& pos, | |
741 | const wxSize& size, | |
742 | long style, | |
743 | const wxString& name) | |
744 | { | |
745 | // init our fields | |
746 | Init(); | |
747 | ||
748 | m_windowStyle = style; | |
749 | ||
750 | SetName(name); | |
751 | ||
752 | m_windowId = id == -1 ? NewControlId() : id; | |
753 | ||
facd6764 SC |
754 | MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; |
755 | ||
94d1d0f4 SC |
756 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); |
757 | ||
a15eb0a5 SC |
758 | wxTopLevelWindows.Append(this); |
759 | ||
760 | if ( parent ) | |
761 | parent->AddChild(this); | |
762 | ||
763 | return TRUE; | |
764 | } | |
765 | ||
766 | wxTopLevelWindowMac::~wxTopLevelWindowMac() | |
767 | { | |
6a17ca35 SC |
768 | if ( m_macWindow ) |
769 | { | |
770 | wxToolTip::NotifyWindowDelete(m_macWindow) ; | |
118f012e | 771 | wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ; |
6a17ca35 | 772 | } |
1542ea39 | 773 | |
7c091673 SC |
774 | if ( m_macEventHandler ) |
775 | { | |
776 | ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); | |
777 | m_macEventHandler = NULL ; | |
778 | } | |
851b3a88 | 779 | |
5f0b2f22 SC |
780 | wxRemoveMacWindowAssociation( this ) ; |
781 | ||
a15eb0a5 SC |
782 | if ( wxModelessWindows.Find(this) ) |
783 | wxModelessWindows.DeleteObject(this); | |
a15eb0a5 SC |
784 | } |
785 | ||
786 | ||
787 | // ---------------------------------------------------------------------------- | |
788 | // wxTopLevelWindowMac maximize/minimize | |
789 | // ---------------------------------------------------------------------------- | |
790 | ||
791 | void wxTopLevelWindowMac::Maximize(bool maximize) | |
792 | { | |
1f90939c SC |
793 | wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ; |
794 | wxMacWindowClipper clip (this); | |
b7aec135 | 795 | ZoomWindow( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , false ) ; |
a15eb0a5 SC |
796 | } |
797 | ||
798 | bool wxTopLevelWindowMac::IsMaximized() const | |
799 | { | |
b7aec135 | 800 | return IsWindowInStandardState( (WindowRef)m_macWindow , NULL , NULL ) ; |
a15eb0a5 SC |
801 | } |
802 | ||
803 | void wxTopLevelWindowMac::Iconize(bool iconize) | |
804 | { | |
b7aec135 SC |
805 | if ( IsWindowCollapsable((WindowRef)m_macWindow) ) |
806 | CollapseWindow((WindowRef)m_macWindow , iconize ) ; | |
a15eb0a5 SC |
807 | } |
808 | ||
809 | bool wxTopLevelWindowMac::IsIconized() const | |
810 | { | |
b7aec135 | 811 | return IsWindowCollapsed((WindowRef)m_macWindow ) ; |
a15eb0a5 SC |
812 | } |
813 | ||
814 | void wxTopLevelWindowMac::Restore() | |
815 | { | |
816 | // not available on mac | |
817 | } | |
818 | ||
819 | // ---------------------------------------------------------------------------- | |
820 | // wxTopLevelWindowMac misc | |
821 | // ---------------------------------------------------------------------------- | |
822 | ||
facd6764 SC |
823 | wxPoint wxTopLevelWindowMac::GetClientAreaOrigin() const |
824 | { | |
825 | return wxPoint(0,0) ; | |
826 | } | |
827 | ||
a15eb0a5 SC |
828 | void wxTopLevelWindowMac::SetIcon(const wxIcon& icon) |
829 | { | |
830 | // this sets m_icon | |
831 | wxTopLevelWindowBase::SetIcon(icon); | |
832 | } | |
5f0b2f22 | 833 | |
facd6764 SC |
834 | void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush &brush ) |
835 | { | |
836 | wxTopLevelWindowBase::MacSetBackgroundBrush( brush ) ; | |
837 | ||
838 | if ( m_macBackgroundBrush.Ok() && m_macBackgroundBrush.GetStyle() != wxTRANSPARENT && m_macBackgroundBrush.MacGetBrushKind() == kwxMacBrushTheme ) | |
839 | { | |
840 | SetThemeWindowBackground( (WindowRef) m_macWindow , m_macBackgroundBrush.MacGetTheme() , false ) ; | |
841 | } | |
842 | } | |
843 | ||
949cb163 SC |
844 | void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler() |
845 | { | |
846 | if ( m_macEventHandler != NULL ) | |
847 | { | |
848 | verify_noerr( ::RemoveEventHandler( (EventHandlerRef) m_macEventHandler ) ) ; | |
849 | } | |
850 | InstallWindowEventHandler(MAC_WXHWND(m_macWindow), GetwxMacTopLevelEventHandlerUPP(), | |
851 | GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macEventHandler); | |
852 | } | |
853 | ||
5f0b2f22 SC |
854 | void wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title, |
855 | const wxPoint& pos, | |
856 | const wxSize& size, | |
857 | long style, | |
1542ea39 | 858 | const wxString& name ) |
5f0b2f22 | 859 | { |
47ac4f9b | 860 | OSStatus err = noErr ; |
e40298d5 JS |
861 | SetName(name); |
862 | m_windowStyle = style; | |
863 | m_isShown = FALSE; | |
1542ea39 | 864 | |
e40298d5 | 865 | // create frame. |
1542ea39 | 866 | |
5f0b2f22 | 867 | Rect theBoundsRect; |
1542ea39 | 868 | |
facd6764 SC |
869 | int x = (int)pos.x; |
870 | int y = (int)pos.y; | |
871 | if ( y < 50 ) | |
872 | y = 50 ; | |
873 | if ( x < 20 ) | |
874 | x = 20 ; | |
1542ea39 | 875 | |
facd6764 SC |
876 | int w = WidthDefault(size.x); |
877 | int h = HeightDefault(size.y); | |
1542ea39 | 878 | |
facd6764 | 879 | ::SetRect(&theBoundsRect, x, y , x + w, y + h); |
1542ea39 | 880 | |
5f0b2f22 | 881 | // translate the window attributes in the appropriate window class and attributes |
1542ea39 | 882 | |
5f0b2f22 SC |
883 | WindowClass wclass = 0; |
884 | WindowAttributes attr = kWindowNoAttributes ; | |
1542ea39 | 885 | |
f5744893 | 886 | if ( HasFlag( wxFRAME_TOOL_WINDOW) ) |
5f0b2f22 | 887 | { |
1542ea39 | 888 | if ( |
f5744893 SC |
889 | HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
890 | HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) || | |
891 | HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) | |
e40298d5 | 892 | ) |
5f0b2f22 | 893 | { |
f5744893 SC |
894 | wclass = kFloatingWindowClass ; |
895 | if ( HasFlag(wxTINY_CAPTION_VERT) ) | |
896 | { | |
897 | attr |= kWindowSideTitlebarAttribute ; | |
898 | } | |
899 | } | |
900 | else | |
901 | { | |
902 | wclass = kPlainWindowClass ; | |
5f0b2f22 SC |
903 | } |
904 | } | |
905 | else if ( HasFlag( wxCAPTION ) ) | |
906 | { | |
1542ea39 | 907 | wclass = kDocumentWindowClass ; |
5f0b2f22 SC |
908 | } |
909 | else | |
910 | { | |
f5744893 | 911 | if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) || |
47ac4f9b | 912 | HasFlag( wxCLOSE_BOX ) || HasFlag( wxSYSTEM_MENU ) ) |
f5744893 SC |
913 | { |
914 | wclass = kDocumentWindowClass ; | |
915 | } | |
916 | else | |
917 | { | |
918 | wclass = kPlainWindowClass ; | |
919 | } | |
5f0b2f22 | 920 | } |
1542ea39 | 921 | |
47ac4f9b | 922 | if ( HasFlag( wxMINIMIZE_BOX ) ) |
5f0b2f22 | 923 | { |
5f0b2f22 SC |
924 | attr |= kWindowCollapseBoxAttribute ; |
925 | } | |
47ac4f9b SC |
926 | if ( HasFlag( wxMAXIMIZE_BOX ) ) |
927 | { | |
928 | attr |= kWindowFullZoomAttribute ; | |
929 | } | |
5f0b2f22 SC |
930 | if ( HasFlag( wxRESIZE_BORDER ) ) |
931 | { | |
932 | attr |= kWindowResizableAttribute ; | |
933 | } | |
47ac4f9b | 934 | if ( HasFlag( wxCLOSE_BOX) ) |
5f0b2f22 SC |
935 | { |
936 | attr |= kWindowCloseBoxAttribute ; | |
937 | } | |
1542ea39 | 938 | |
eb630bf1 DS |
939 | if (UMAGetSystemVersion() >= 0x1000) |
940 | { | |
facd6764 | 941 | // turn on live resizing (OS X only) |
eb630bf1 DS |
942 | attr |= kWindowLiveResizeAttribute; |
943 | } | |
944 | ||
6a7e6411 | 945 | if (HasFlag(wxSTAY_ON_TOP)) |
eb630bf1 | 946 | wclass = kUtilityWindowClass; |
6a7e6411 | 947 | |
facd6764 SC |
948 | #if TARGET_API_MAC_OSX |
949 | attr |= kWindowCompositingAttribute; | |
d66c3960 | 950 | #endif |
1f90939c | 951 | |
6a7e6411 RD |
952 | if ( HasFlag(wxFRAME_SHAPED) ) |
953 | { | |
954 | WindowDefSpec customWindowDefSpec; | |
955 | customWindowDefSpec.defType = kWindowDefProcPtr; | |
956 | customWindowDefSpec.u.defProc = NewWindowDefUPP(wxShapedMacWindowDef); | |
957 | ||
47ac4f9b | 958 | err = ::CreateCustomWindow( &customWindowDefSpec, wclass, |
6a7e6411 RD |
959 | attr, &theBoundsRect, |
960 | (WindowRef*) &m_macWindow); | |
961 | } | |
962 | else | |
963 | { | |
47ac4f9b | 964 | err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ; |
6a7e6411 RD |
965 | } |
966 | ||
47ac4f9b | 967 | wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") ); |
f83b6761 SC |
968 | |
969 | // the create commands are only for content rect, so we have to set the size again as | |
970 | // structure bounds | |
971 | SetWindowBounds( (WindowRef) m_macWindow , kWindowStructureRgn , &theBoundsRect ) ; | |
972 | ||
facd6764 SC |
973 | wxAssociateWinWithMacWindow( (WindowRef) m_macWindow , this ) ; |
974 | UMASetWTitle( (WindowRef) m_macWindow , title , m_font.GetEncoding() ) ; | |
3a9dc061 SC |
975 | #if TARGET_API_MAC_OSX |
976 | // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of | |
977 | // the content view, so we have to retrieve it explicitely | |
978 | HIViewFindByID( HIViewGetRoot( (WindowRef) m_macWindow ) , kHIViewWindowContentID , | |
979 | (ControlRef*)&m_macControl ) ; | |
980 | #else | |
981 | ::CreateRootControl( (WindowRef)m_macWindow , (ControlRef*)&m_macControl ) ; | |
982 | #endif | |
73fe67bd | 983 | // the root control level handleer |
949cb163 | 984 | MacInstallEventHandler() ; |
facd6764 | 985 | |
73fe67bd | 986 | // the frame window event handler |
e40298d5 | 987 | InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ; |
949cb163 | 988 | MacInstallTopLevelWindowEventHandler() ; |
b19bf058 | 989 | |
facd6764 | 990 | m_macFocus = NULL ; |
6a7e6411 RD |
991 | |
992 | if ( HasFlag(wxFRAME_SHAPED) ) | |
993 | { | |
994 | // default shape matches the window size | |
facd6764 | 995 | wxRegion rgn(0, 0, w, h); |
6a7e6411 RD |
996 | SetShape(rgn); |
997 | } | |
3dfafdb9 RD |
998 | |
999 | wxWindowCreateEvent event(this); | |
1000 | GetEventHandler()->ProcessEvent(event); | |
5f0b2f22 SC |
1001 | } |
1002 | ||
5d2e69e8 | 1003 | void wxTopLevelWindowMac::ClearBackground() |
5f0b2f22 | 1004 | { |
5d2e69e8 | 1005 | wxWindow::ClearBackground() ; |
5f0b2f22 SC |
1006 | } |
1007 | ||
5f0b2f22 SC |
1008 | // Raise the window to the top of the Z order |
1009 | void wxTopLevelWindowMac::Raise() | |
1010 | { | |
7f3c339c | 1011 | ::SelectWindow( (WindowRef)m_macWindow ) ; |
5f0b2f22 SC |
1012 | } |
1013 | ||
1014 | // Lower the window to the bottom of the Z order | |
1015 | void wxTopLevelWindowMac::Lower() | |
1016 | { | |
76a5e5d2 | 1017 | ::SendBehind( (WindowRef)m_macWindow , NULL ) ; |
5f0b2f22 SC |
1018 | } |
1019 | ||
851b3a88 | 1020 | |
245f3581 DE |
1021 | void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp) |
1022 | { | |
1023 | if(s_macDeactivateWindow) | |
1024 | { | |
365796b1 | 1025 | wxLogDebug(wxT("Doing delayed deactivation of %p"),s_macDeactivateWindow); |
245f3581 DE |
1026 | s_macDeactivateWindow->MacActivate(timestamp, false); |
1027 | } | |
1028 | } | |
1029 | ||
851b3a88 | 1030 | void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating ) |
5f0b2f22 | 1031 | { |
17f8d2a7 VZ |
1032 | // wxLogDebug(wxT("TopLevel=%p::MacActivate"),this); |
1033 | ||
245f3581 DE |
1034 | if(s_macDeactivateWindow==this) |
1035 | s_macDeactivateWindow=NULL; | |
1036 | MacDelayedDeactivation(timestamp); | |
8ab50549 | 1037 | MacPropagateHiliteChanged() ; |
5f0b2f22 SC |
1038 | } |
1039 | ||
1040 | void wxTopLevelWindowMac::SetTitle(const wxString& title) | |
1041 | { | |
1042 | wxWindow::SetTitle( title ) ; | |
16a76184 | 1043 | UMASetWTitle( (WindowRef)m_macWindow , title , m_font.GetEncoding() ) ; |
5f0b2f22 SC |
1044 | } |
1045 | ||
1046 | bool wxTopLevelWindowMac::Show(bool show) | |
1047 | { | |
facd6764 | 1048 | if ( !wxTopLevelWindowBase::Show(show) ) |
5f0b2f22 SC |
1049 | return FALSE; |
1050 | ||
1051 | if (show) | |
1542ea39 | 1052 | { |
1f90939c SC |
1053 | #if wxUSE_SYSTEM_OPTIONS //code contributed by Ryan Wilcox December 18, 2003 |
1054 | if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1) ) | |
1055 | { | |
1056 | ::ShowWindow( (WindowRef)m_macWindow ); | |
1057 | } | |
1058 | else | |
1059 | #endif | |
1060 | { | |
1061 | ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowShowTransitionAction,nil); | |
1062 | } | |
1063 | ::SelectWindow( (WindowRef)m_macWindow ) ; | |
facd6764 SC |
1064 | // as apps expect a size event to occur at this moment |
1065 | wxSizeEvent event( GetSize() , m_windowId); | |
1f90939c SC |
1066 | event.SetEventObject(this); |
1067 | GetEventHandler()->ProcessEvent(event); | |
5f0b2f22 SC |
1068 | } |
1069 | else | |
1070 | { | |
1f90939c SC |
1071 | #if wxUSE_SYSTEM_OPTIONS |
1072 | if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1) ) | |
1073 | { | |
1074 | ::HideWindow((WindowRef) m_macWindow ); | |
1075 | } | |
1076 | else | |
1077 | #endif | |
1078 | { | |
1079 | ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowHideTransitionAction,nil); | |
1080 | } | |
5f0b2f22 SC |
1081 | } |
1082 | ||
facd6764 | 1083 | MacPropagateVisibilityChanged() ; |
5f0b2f22 | 1084 | |
facd6764 | 1085 | return TRUE ; |
5f0b2f22 SC |
1086 | } |
1087 | ||
facd6764 SC |
1088 | // we are still using coordinates of the content view, todo switch to structure bounds |
1089 | ||
29281095 SC |
1090 | void wxTopLevelWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) |
1091 | { | |
1092 | Rect content ; | |
1093 | Rect structure ; | |
1094 | GetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &structure ) ; | |
1095 | GetWindowBounds( (WindowRef) m_macWindow, kWindowContentRgn , &content ) ; | |
1096 | ||
1097 | left = content.left - structure.left ; | |
1098 | top = content.top - structure.top ; | |
1099 | right = structure.right - content.right ; | |
1100 | bottom = structure.bottom - content.bottom ; | |
1101 | } | |
1102 | ||
5f0b2f22 SC |
1103 | void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height) |
1104 | { | |
facd6764 SC |
1105 | Rect bounds = { y , x , y + height , x + width } ; |
1106 | verify_noerr(SetWindowBounds( (WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
5f0b2f22 SC |
1107 | } |
1108 | ||
facd6764 | 1109 | void wxTopLevelWindowMac::DoGetPosition( int *x, int *y ) const |
5f0b2f22 | 1110 | { |
facd6764 SC |
1111 | Rect bounds ; |
1112 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
1113 | if(x) *x = bounds.left ; | |
1114 | if(y) *y = bounds.top ; | |
1115 | } | |
1116 | void wxTopLevelWindowMac::DoGetSize( int *width, int *height ) const | |
1117 | { | |
1118 | Rect bounds ; | |
1119 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowStructureRgn , &bounds )) ; | |
1120 | if(width) *width = bounds.right - bounds.left ; | |
1121 | if(height) *height = bounds.bottom - bounds.top ; | |
1122 | } | |
1542ea39 | 1123 | |
facd6764 SC |
1124 | void wxTopLevelWindowMac::DoGetClientSize( int *width, int *height ) const |
1125 | { | |
1126 | Rect bounds ; | |
1127 | verify_noerr(GetWindowBounds((WindowRef) m_macWindow, kWindowContentRgn , &bounds )) ; | |
1128 | if(width) *width = bounds.right - bounds.left ; | |
1129 | if(height) *height = bounds.bottom - bounds.top ; | |
1130 | } | |
1542ea39 | 1131 | |
facd6764 SC |
1132 | void wxTopLevelWindowMac::MacSetMetalAppearance( bool set ) |
1133 | { | |
1134 | #if TARGET_API_MAC_OSX | |
1135 | UInt32 attr = 0 ; | |
1136 | GetWindowAttributes((WindowRef) m_macWindow , &attr ) ; | |
1137 | wxASSERT_MSG( attr & kWindowCompositingAttribute , | |
1138 | wxT("Cannot set metal appearance on a non-compositing window") ) ; | |
1139 | ||
1140 | MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes , | |
1141 | set ? kWindowNoAttributes : kWindowMetalAttribute ) ; | |
1142 | #endif | |
1143 | } | |
1542ea39 | 1144 | |
6aab345b SC |
1145 | bool wxTopLevelWindowMac::MacGetMetalAppearance() const |
1146 | { | |
1147 | #if TARGET_API_MAC_OSX | |
1148 | return MacGetWindowAttributes() & kWindowMetalAttribute ; | |
1149 | #else | |
1150 | return false ; | |
1151 | #endif | |
1152 | } | |
1153 | ||
facd6764 SC |
1154 | void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet , wxUint32 attributesToClear ) |
1155 | { | |
1156 | ChangeWindowAttributes ( (WindowRef) m_macWindow , attributesToSet, attributesToClear ) ; | |
1157 | } | |
1542ea39 | 1158 | |
facd6764 SC |
1159 | wxUint32 wxTopLevelWindowMac::MacGetWindowAttributes() const |
1160 | { | |
1161 | UInt32 attr = 0 ; | |
1162 | GetWindowAttributes((WindowRef) m_macWindow , &attr ) ; | |
1163 | return attr ; | |
5f0b2f22 | 1164 | } |
a07c1212 | 1165 | |
facd6764 SC |
1166 | // --------------------------------------------------------------------------- |
1167 | // Shape implementation | |
1168 | // --------------------------------------------------------------------------- | |
1169 | ||
6a7e6411 | 1170 | |
1542ea39 RD |
1171 | bool wxTopLevelWindowMac::SetShape(const wxRegion& region) |
1172 | { | |
6a7e6411 RD |
1173 | wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE, |
1174 | _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); | |
1175 | ||
1176 | // The empty region signifies that the shape should be removed from the | |
1177 | // window. | |
1178 | if ( region.IsEmpty() ) | |
1179 | { | |
1180 | wxSize sz = GetClientSize(); | |
1181 | wxRegion rgn(0, 0, sz.x, sz.y); | |
1182 | return SetShape(rgn); | |
1183 | } | |
1184 | ||
1185 | // Make a copy of the region | |
1186 | RgnHandle shapeRegion = NewRgn(); | |
1187 | CopyRgn( (RgnHandle)region.GetWXHRGN(), shapeRegion ); | |
1188 | ||
1189 | // Dispose of any shape region we may already have | |
1190 | RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() ); | |
1191 | if ( oldRgn ) | |
1192 | DisposeRgn(oldRgn); | |
1193 | ||
1194 | // Save the region so we can use it later | |
1195 | SetWRefCon((WindowRef)MacGetWindowRef(), (SInt32)shapeRegion); | |
1196 | ||
1197 | // Tell the window manager that the window has changed shape | |
1198 | ReshapeCustomWindow((WindowRef)MacGetWindowRef()); | |
1199 | return TRUE; | |
1200 | } | |
1201 | ||
6a7e6411 RD |
1202 | // --------------------------------------------------------------------------- |
1203 | // Support functions for shaped windows, based on Apple's CustomWindow sample at | |
1204 | // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm | |
1205 | // --------------------------------------------------------------------------- | |
1206 | ||
6a7e6411 RD |
1207 | static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect) |
1208 | { | |
1209 | GetWindowPortBounds(window, inRect); | |
1210 | Point pt = {inRect->left, inRect->top}; | |
d6fd667b | 1211 | QDLocalToGlobalPoint( GetWindowPort(window) , &pt ) ; |
6a7e6411 RD |
1212 | inRect->top = pt.v; |
1213 | inRect->left = pt.h; | |
1214 | inRect->bottom += pt.v; | |
1215 | inRect->right += pt.h; | |
1216 | } | |
1217 | ||
1218 | ||
1219 | static SInt32 wxShapedMacWindowGetFeatures(WindowRef window, SInt32 param) | |
1220 | { | |
1221 | /*------------------------------------------------------ | |
1222 | Define which options your custom window supports. | |
1223 | --------------------------------------------------------*/ | |
1224 | //just enable everything for our demo | |
1225 | *(OptionBits*)param=//kWindowCanGrow| | |
1226 | //kWindowCanZoom| | |
1227 | //kWindowCanCollapse| | |
1228 | //kWindowCanGetWindowRegion| | |
1229 | //kWindowHasTitleBar| | |
1230 | //kWindowSupportsDragHilite| | |
1231 | kWindowCanDrawInCurrentPort| | |
1232 | //kWindowCanMeasureTitle| | |
1233 | kWindowWantsDisposeAtProcessDeath| | |
1234 | kWindowSupportsSetGrowImageRegion| | |
1235 | kWindowDefSupportsColorGrafPort; | |
1236 | return 1; | |
1542ea39 | 1237 | } |
6a7e6411 RD |
1238 | |
1239 | // The content region is left as a rectangle matching the window size, this is | |
1240 | // so the origin in the paint event, and etc. still matches what the | |
1241 | // programmer expects. | |
1242 | static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn) | |
1243 | { | |
1244 | SetEmptyRgn(rgn); | |
1245 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow(window); | |
1246 | if (win) | |
1247 | { | |
b19bf058 SC |
1248 | Rect r ; |
1249 | wxShapedMacWindowGetPos(window, &r ) ; | |
1250 | RectRgn( rgn , &r ) ; | |
6a7e6411 RD |
1251 | } |
1252 | } | |
1253 | ||
1254 | // The structure region is set to the shape given to the SetShape method. | |
1255 | static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn) | |
1256 | { | |
1257 | RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window); | |
1258 | ||
1259 | SetEmptyRgn(rgn); | |
1260 | if (cachedRegion) | |
1261 | { | |
1262 | Rect windowRect; | |
1263 | wxShapedMacWindowGetPos(window, &windowRect); //how big is the window | |
1264 | CopyRgn(cachedRegion, rgn); //make a copy of our cached region | |
1265 | OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window | |
1266 | //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size | |
1267 | } | |
1268 | } | |
1269 | ||
1270 | ||
1271 | ||
1272 | static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param) | |
1273 | { | |
1274 | GetWindowRegionPtr rgnRec=(GetWindowRegionPtr)param; | |
1275 | ||
1276 | switch(rgnRec->regionCode) | |
1277 | { | |
1278 | case kWindowStructureRgn: | |
1279 | wxShapedMacWindowStructureRegion(window, rgnRec->winRgn); | |
1280 | break; | |
1281 | case kWindowContentRgn: | |
1282 | wxShapedMacWindowContentRegion(window, rgnRec->winRgn); | |
1283 | break; | |
1284 | default: | |
1285 | SetEmptyRgn(rgnRec->winRgn); | |
1286 | } //switch | |
1287 | ||
1288 | return noErr; | |
1289 | } | |
1290 | ||
1291 | ||
1292 | static SInt32 wxShapedMacWindowHitTest(WindowRef window,SInt32 param) | |
1293 | { | |
1294 | /*------------------------------------------------------ | |
1295 | Determine the region of the window which was hit | |
1296 | --------------------------------------------------------*/ | |
1297 | Point hitPoint; | |
1298 | static RgnHandle tempRgn=nil; | |
1299 | ||
1300 | if(!tempRgn) | |
1301 | tempRgn=NewRgn(); | |
1302 | ||
1303 | SetPt(&hitPoint,LoWord(param),HiWord(param));//get the point clicked | |
1304 | ||
1305 | //Mac OS 8.5 or later | |
1306 | wxShapedMacWindowStructureRegion(window, tempRgn); | |
1307 | if (PtInRgn(hitPoint, tempRgn)) //in window content region? | |
1308 | return wInContent; | |
1309 | ||
1310 | return wNoHit;//no significant area was hit. | |
1311 | } | |
1312 | ||
1313 | ||
1314 | static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param) | |
1315 | { | |
1316 | switch(message) | |
1317 | { | |
1318 | case kWindowMsgHitTest: | |
1319 | return wxShapedMacWindowHitTest(window,param); | |
1320 | ||
1321 | case kWindowMsgGetFeatures: | |
1322 | return wxShapedMacWindowGetFeatures(window,param); | |
1323 | ||
1324 | // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow | |
1325 | case kWindowMsgGetRegion: | |
1326 | return wxShapedMacWindowGetRegion(window,param); | |
1327 | } | |
1328 | ||
1329 | return 0; | |
1330 | } | |
1925be65 | 1331 | |
6a7e6411 | 1332 | // --------------------------------------------------------------------------- |
1925be65 | 1333 |