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