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