1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for Mac
4 // Author: Stefan Csomor
8 // Copyright: (c) 2001-2004 Stefan Csomor
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/toplevel.h"
31 #include "wx/string.h"
34 #include "wx/settings.h"
35 #include "wx/strconv.h"
36 #include "wx/control.h"
39 #include "wx/mac/uma.h"
40 #include "wx/mac/aga.h"
42 #include "wx/tooltip.h"
45 #if wxUSE_SYSTEM_OPTIONS
46 #include "wx/sysopt.h"
50 #include <ToolUtils.h>
54 #include "wx/mac/private.h"
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 // trace mask for activation tracing messages
61 static const wxChar
*TRACE_ACTIVATE
= _T("activation");
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 // list of all frames and modeless dialogs
68 wxWindowList wxModelessWindows
;
70 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
72 // ============================================================================
73 // wxTopLevelWindowMac implementation
74 // ============================================================================
76 BEGIN_EVENT_TABLE(wxTopLevelWindowMac
, wxTopLevelWindowBase
)
80 // ---------------------------------------------------------------------------
82 // ---------------------------------------------------------------------------
84 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
86 static const EventTypeSpec eventList
[] =
88 // TODO: remove control related event like key and mouse (except for WindowLeave events)
90 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
92 { kEventClassKeyboard
, kEventRawKeyDown
} ,
93 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
94 { kEventClassKeyboard
, kEventRawKeyUp
} ,
95 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
98 { kEventClassWindow
, kEventWindowShown
} ,
99 { kEventClassWindow
, kEventWindowActivated
} ,
100 { kEventClassWindow
, kEventWindowDeactivated
} ,
101 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
102 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
103 { kEventClassWindow
, kEventWindowClose
} ,
105 // we have to catch these events on the toplevel window level,
106 // as controls don't get the raw mouse events anymore
108 { kEventClassMouse
, kEventMouseDown
} ,
109 { kEventClassMouse
, kEventMouseUp
} ,
110 { kEventClassMouse
, kEventMouseWheelMoved
} ,
111 { kEventClassMouse
, kEventMouseMoved
} ,
112 { kEventClassMouse
, kEventMouseDragged
} ,
115 static pascal OSStatus
TextInputEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
117 OSStatus result
= eventNotHandledErr
;
119 UInt32 keyCode
, modifiers
;
122 unsigned char charCode
;
124 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
, typeEventRef
, NULL
, sizeof(rawEvent
), NULL
, &rawEvent
) ;
126 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
127 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
128 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
129 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
131 focus
= wxWindow::FindFocus() ;
133 switch ( GetEventKind( event
) )
135 case kEventTextInputUnicodeForKeyEvent
:
136 // this is only called when no default handler has jumped in, e.g. a wxControl on a floater window does not
137 // get its own kEventTextInputUnicodeForKeyEvent, so we reroute the event back to the control
138 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
141 ControlRef macControl
= (ControlRef
) control
->GetHandle() ;
144 ::HandleControlKey( macControl
, keyCode
, charCode
, modifiers
) ;
150 // this may lead to double events sent to a window in case all handlers have skipped the key down event
151 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
152 UInt32 message
= (keyCode
<< 8) + charCode
;
154 if ( (focus
!= NULL
) &&
155 wxTheApp
->MacSendKeyDownEvent( focus
, message
, modifiers
, when
, point
.h
, point
.v
) )
169 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
171 OSStatus result
= eventNotHandledErr
;
172 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
173 // FindFocus does not return the actual focus window, but the enclosing window
174 wxWindow
* focus
= wxWindow::DoFindFocus();
176 focus
= (wxTopLevelWindowMac
*) data
;
178 unsigned char charCode
;
183 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
186 UInt32 dataSize
= 0 ;
187 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
191 UniChar
* charBuf
= buf
;
194 charBuf
= new UniChar
[ dataSize
/ sizeof( UniChar
) ] ;
195 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
197 #if SIZEOF_WCHAR_T == 2
198 uniChar
= charBuf
[0] ;
200 wxMBConvUTF16 converter
;
201 converter
.MB2WC( &uniChar
, (const char*)charBuf
, 1 ) ;
209 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
210 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
211 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
212 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
214 UInt32 message
= (keyCode
<< 8) + charCode
;
215 switch ( GetEventKind( event
) )
217 case kEventRawKeyRepeat
:
218 case kEventRawKeyDown
:
220 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
221 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
222 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
223 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
224 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
) )
228 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
232 case kEventRawKeyUp
:
233 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
234 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
) )
240 case kEventRawKeyModifiersChanged
:
242 wxKeyEvent
event(wxEVT_KEY_DOWN
);
244 event
.m_shiftDown
= modifiers
& shiftKey
;
245 event
.m_controlDown
= modifiers
& controlKey
;
246 event
.m_altDown
= modifiers
& optionKey
;
247 event
.m_metaDown
= modifiers
& cmdKey
;
252 event
.m_uniChar
= uniChar
;
255 event
.SetTimestamp(when
);
256 event
.SetEventObject(focus
);
258 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
260 event
.m_keyCode
= WXK_CONTROL
;
261 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
262 focus
->GetEventHandler()->ProcessEvent( event
) ;
264 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
266 event
.m_keyCode
= WXK_SHIFT
;
267 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
268 focus
->GetEventHandler()->ProcessEvent( event
) ;
270 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
272 event
.m_keyCode
= WXK_ALT
;
273 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
274 focus
->GetEventHandler()->ProcessEvent( event
) ;
276 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
278 event
.m_keyCode
= WXK_COMMAND
;
279 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
280 focus
->GetEventHandler()->ProcessEvent( event
) ;
283 wxApp::s_lastModifiers
= modifiers
;
294 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
295 // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
298 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
300 wxWindow
* g_MacLastWindow
= NULL
;
302 static EventMouseButton lastButton
= 0 ;
304 static void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
306 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
307 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
309 // this parameter are not given for all events
310 EventMouseButton button
= 0 ;
311 UInt32 clickCount
= 0 ;
312 cEvent
.GetParameter
<EventMouseButton
>( kEventParamMouseButton
, typeMouseButton
, &button
) ;
313 cEvent
.GetParameter
<UInt32
>( kEventParamClickCount
, typeUInt32
, &clickCount
) ;
315 wxevent
.m_x
= screenMouseLocation
.h
;
316 wxevent
.m_y
= screenMouseLocation
.v
;
317 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
318 wxevent
.m_controlDown
= modifiers
& controlKey
;
319 wxevent
.m_altDown
= modifiers
& optionKey
;
320 wxevent
.m_metaDown
= modifiers
& cmdKey
;
321 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
323 // a control click is interpreted as a right click
324 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
325 button
= kEventMouseButtonSecondary
;
327 // otherwise we report double clicks by connecting a left click with a ctrl-left click
328 if ( clickCount
> 1 && button
!= lastButton
)
331 // we must make sure that our synthetic 'right' button corresponds in
332 // mouse down, moved and mouse up, and does not deliver a right down and left up
334 if ( cEvent
.GetKind() == kEventMouseDown
)
335 lastButton
= button
;
339 else if ( lastButton
)
340 button
= lastButton
;
342 // determine the correct down state, wx does not want a 'down' for a mouseUp event,
343 // while mac delivers this button
344 if ( button
!= 0 && cEvent
.GetKind() != kEventMouseUp
)
348 case kEventMouseButtonPrimary
:
349 wxevent
.m_leftDown
= true ;
352 case kEventMouseButtonSecondary
:
353 wxevent
.m_rightDown
= true ;
356 case kEventMouseButtonTertiary
:
357 wxevent
.m_middleDown
= true ;
365 // translate into wx types
366 switch ( cEvent
.GetKind() )
368 case kEventMouseDown
:
371 case kEventMouseButtonPrimary
:
372 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
375 case kEventMouseButtonSecondary
:
376 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
379 case kEventMouseButtonTertiary
:
380 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
391 case kEventMouseButtonPrimary
:
392 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
395 case kEventMouseButtonSecondary
:
396 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
399 case kEventMouseButtonTertiary
:
400 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
408 case kEventMouseWheelMoved
:
410 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
412 // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
413 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeLongInteger
) ;
415 wxevent
.m_wheelRotation
= delta
;
416 wxevent
.m_wheelDelta
= 1;
417 wxevent
.m_linesPerAction
= 1;
422 wxevent
.SetEventType( wxEVT_MOTION
) ;
427 ControlRef
wxMacFindSubControl( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, ControlRef superControl
, ControlPartCode
*outPart
)
431 UInt16 childrenCount
= 0 ;
432 ControlHandle sibling
;
434 OSStatus err
= CountSubControls( superControl
, &childrenCount
) ;
435 if ( err
== errControlIsNotEmbedder
)
438 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
440 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
442 err
= GetIndexedSubControl( superControl
, i
, & sibling
) ;
443 if ( err
== errControlIsNotEmbedder
)
446 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
447 if ( IsControlVisible( sibling
) )
449 UMAGetControlBoundsInWindowCoords( sibling
, &r
) ;
450 if ( MacPtInRect( location
, &r
) )
452 ControlHandle child
= wxMacFindSubControl( toplevelWindow
, location
, sibling
, outPart
) ;
459 Point testLocation
= location
;
461 if ( toplevelWindow
&& toplevelWindow
->MacUsesCompositing() )
463 testLocation
.h
-= r
.left
;
464 testLocation
.v
-= r
.top
;
467 *outPart
= TestControl( sibling
, testLocation
) ;
479 ControlRef
wxMacFindControlUnderMouse( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, WindowRef window
, ControlPartCode
*outPart
)
481 #if TARGET_API_MAC_OSX
482 if ( UMAGetSystemVersion() >= 0x1030 && ( toplevelWindow
== 0 || toplevelWindow
->MacUsesCompositing() ) )
483 return FindControlUnderMouse( location
, window
, outPart
) ;
486 ControlRef rootControl
= NULL
;
487 verify_noerr( GetRootControl( window
, &rootControl
) ) ;
489 return wxMacFindSubControl( toplevelWindow
, location
, rootControl
, outPart
) ;
492 #define NEW_CAPTURE_HANDLING 1
494 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
496 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
498 OSStatus result
= eventNotHandledErr
;
500 wxMacCarbonEvent
cEvent( event
) ;
502 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
503 Point windowMouseLocation
= screenMouseLocation
;
506 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
508 wxWindow
* currentMouseWindow
= NULL
;
509 ControlRef control
= NULL
;
511 #if NEW_CAPTURE_HANDLING
512 if ( wxApp::s_captureWindow
)
514 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
515 windowPart
= inContent
;
521 QDGlobalToLocalPoint( UMAGetWindowPort(window
) , &windowMouseLocation
) ;
523 if ( wxApp::s_captureWindow
524 #if !NEW_CAPTURE_HANDLING
525 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
529 currentMouseWindow
= wxApp::s_captureWindow
;
531 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
533 ControlPartCode part
;
534 control
= wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &part
) ;
535 // if there is no control below the mouse position, send the event to the toplevel window itself
538 currentMouseWindow
= (wxWindow
*) data
;
542 currentMouseWindow
= wxFindControlFromMacControl( control
) ;
543 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
546 // for wxToolBar to function we have to send certaint events to it
547 // instead of its children (wxToolBarTools)
549 GetSuperControl(control
, &parent
);
550 wxWindow
*wxParent
= wxFindControlFromMacControl( parent
) ;
551 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
552 currentMouseWindow
= wxParent
;
559 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
560 SetupMouseEvent( wxevent
, cEvent
) ;
562 // handle all enter / leave events
564 if ( currentMouseWindow
!= g_MacLastWindow
)
566 if ( g_MacLastWindow
)
568 wxMouseEvent
eventleave(wxevent
);
569 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
570 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
571 eventleave
.SetEventObject( g_MacLastWindow
) ;
572 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
575 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
578 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
581 if ( currentMouseWindow
)
583 wxMouseEvent
evententer(wxevent
);
584 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
585 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
586 evententer
.SetEventObject( currentMouseWindow
) ;
587 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
590 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
593 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
596 g_MacLastWindow
= currentMouseWindow
;
599 if ( windowPart
== inMenuBar
)
601 // special case menu bar, as we are having a low-level runloop we must do it ourselves
602 if ( cEvent
.GetKind() == kEventMouseDown
)
604 ::MenuSelect( screenMouseLocation
) ;
608 else if ( currentMouseWindow
)
610 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
612 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
614 wxevent
.SetEventObject( currentMouseWindow
) ;
615 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
617 // make tooltips current
620 if ( wxevent
.GetEventType() == wxEVT_MOTION
621 || wxevent
.GetEventType() == wxEVT_ENTER_WINDOW
622 || wxevent
.GetEventType() == wxEVT_LEAVE_WINDOW
)
623 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
626 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
628 if ((currentMouseWindowParent
!= NULL
) &&
629 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
630 currentMouseWindow
= NULL
;
636 // if the user code did _not_ handle the event, then perform the
637 // default processing
638 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
640 // ... that is set focus to this window
641 if (currentMouseWindow
->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
642 currentMouseWindow
->SetFocus();
645 ControlPartCode dummyPart
;
646 // if built-in find control is finding the wrong control (ie static box instead of overlaid
647 // button, we cannot let the standard handler do its job, but must handle manually
649 if ( ( cEvent
.GetKind() == kEventMouseDown
)
652 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
653 wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &dummyPart
) )
657 if ( currentMouseWindow
->MacIsReallyEnabled() )
659 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
660 Point clickLocation
= windowMouseLocation
;
662 if ( toplevelWindow
->MacUsesCompositing() )
663 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
665 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
666 modifiers
, (ControlActionUPP
) -1 ) ;
668 if ((currentMouseWindowParent
!= NULL
) &&
669 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
671 currentMouseWindow
= NULL
;
679 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
681 wxApp::s_captureWindow
= NULL
;
687 wxWindow
* cursorTarget
= currentMouseWindow
;
688 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
690 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
692 cursorTarget
= cursorTarget
->GetParent() ;
694 cursorPoint
+= cursorTarget
->GetPosition();
697 } // else if ( currentMouseWindow )
700 // don't mess with controls we don't know about
701 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
702 // so we try sending them the correct control directly
703 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
705 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
706 Point clickLocation
= windowMouseLocation
;
707 if ( toplevelWindow
->MacUsesCompositing() )
711 hiPoint
.x
= clickLocation
.h
;
712 hiPoint
.y
= clickLocation
.v
;
713 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
714 clickLocation
.h
= (int)hiPoint
.x
;
715 clickLocation
.v
= (int)hiPoint
.y
;
719 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
727 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
729 OSStatus result
= eventNotHandledErr
;
731 wxMacCarbonEvent
cEvent( event
) ;
733 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
734 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
736 switch ( GetEventKind( event
) )
738 case kEventWindowActivated
:
740 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
741 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
742 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
743 wxevent
.SetEventObject(toplevelWindow
);
744 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
745 // we still sending an eventNotHandledErr in order to allow for default processing
749 case kEventWindowDeactivated
:
751 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
752 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
753 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
754 wxevent
.SetEventObject(toplevelWindow
);
755 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
756 // we still sending an eventNotHandledErr in order to allow for default processing
760 case kEventWindowShown
:
761 toplevelWindow
->Refresh() ;
765 case kEventWindowClose
:
766 toplevelWindow
->Close() ;
770 case kEventWindowBoundsChanged
:
772 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
773 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
774 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
775 if ( attributes
& kWindowBoundsChangeSizeChanged
)
777 // according to the other ports we handle this within the OS level
778 // resize event, not within a wxSizeEvent
779 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
783 frame
->PositionStatusBar();
786 frame
->PositionToolBar();
790 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
791 event
.SetEventObject( toplevelWindow
) ;
793 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
794 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
797 if ( attributes
& kWindowBoundsChangeOriginChanged
)
799 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
800 event
.SetEventObject( toplevelWindow
) ;
801 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
808 case kEventWindowBoundsChanging
:
810 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
811 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
813 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
815 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
816 int left
, top
, right
, bottom
;
817 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
822 newRect
.right
- newRect
.left
+ left
+ right
,
823 newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
825 // this is a EVT_SIZING not a EVT_SIZE type !
826 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
827 wxevent
.SetEventObject( toplevelWindow
) ;
829 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
830 adjustR
= wxevent
.GetRect() ;
832 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
833 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
834 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
835 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
836 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
837 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
838 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
839 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
840 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
841 if ( !EqualRect( &newRect
, &adjustedRect
) )
842 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
843 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
857 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
859 OSStatus result
= eventNotHandledErr
;
861 switch ( GetEventClass( event
) )
863 case kEventClassKeyboard
:
864 result
= KeyboardEventHandler( handler
, event
, data
) ;
867 case kEventClassTextInput
:
868 result
= TextInputEventHandler( handler
, event
, data
) ;
871 case kEventClassWindow
:
872 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
875 case kEventClassMouse
:
876 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
886 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
888 // ---------------------------------------------------------------------------
889 // wxWindowMac utility functions
890 // ---------------------------------------------------------------------------
892 // Find an item given the Macintosh Window Reference
894 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
896 static MacWindowMap wxWinMacWindowList
;
898 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
900 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
902 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
905 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
906 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
908 // adding NULL WindowRef is (first) surely a result of an error and
910 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
912 wxWinMacWindowList
[inWindowRef
] = win
;
915 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
916 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
918 MacWindowMap::iterator it
;
919 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
921 if ( it
->second
== win
)
923 wxWinMacWindowList
.erase(it
);
929 // ----------------------------------------------------------------------------
930 // wxTopLevelWindowMac creation
931 // ----------------------------------------------------------------------------
933 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
942 void wxTopLevelWindowMac::Init()
945 m_maximizeOnShow
= false;
948 #if TARGET_API_MAC_OSX
949 m_macUsesCompositing
= ( UMAGetSystemVersion() >= 0x1030 );
951 m_macUsesCompositing
= false;
954 m_macEventHandler
= NULL
;
955 m_macFullScreenData
= NULL
;
958 class wxMacDeferredWindowDeleter
: public wxObject
961 wxMacDeferredWindowDeleter( WindowRef windowRef
)
963 m_macWindow
= windowRef
;
966 virtual ~wxMacDeferredWindowDeleter()
968 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
972 WindowRef m_macWindow
;
975 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
977 const wxString
& title
,
981 const wxString
& name
)
986 m_windowStyle
= style
;
990 m_windowId
= id
== -1 ? NewControlId() : id
;
991 wxWindow::SetLabel( title
) ;
993 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
995 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
997 if (GetExtraStyle() & wxFRAME_EX_METAL
)
998 MacSetMetalAppearance(true);
1000 wxTopLevelWindows
.Append(this);
1003 parent
->AddChild(this);
1008 wxTopLevelWindowMac::~wxTopLevelWindowMac()
1013 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
1015 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
1018 if ( m_macEventHandler
)
1020 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1021 m_macEventHandler
= NULL
;
1024 wxRemoveMacWindowAssociation( this ) ;
1026 if ( wxModelessWindows
.Find(this) )
1027 wxModelessWindows
.DeleteObject(this);
1029 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1031 m_macFullScreenData
= NULL
;
1035 // ----------------------------------------------------------------------------
1036 // wxTopLevelWindowMac maximize/minimize
1037 // ----------------------------------------------------------------------------
1039 void wxTopLevelWindowMac::Maximize(bool maximize
)
1041 // TODO: check if this is still necessary
1043 wxMacPortStateHelper
help( (GrafPtr
)GetWindowPort( (WindowRef
)m_macWindow
) ) ;
1044 wxMacWindowClipper
clip( this );
1047 if ( !IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) )
1051 GetWindowBounds((WindowRef
)m_macWindow
, kWindowGlobalPortRgn
, &rect
);
1052 SetWindowIdealUserState((WindowRef
)m_macWindow
, &rect
);
1053 SetWindowUserState((WindowRef
)m_macWindow
, &rect
);
1056 ZoomWindow( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, false ) ;
1059 bool wxTopLevelWindowMac::IsMaximized() const
1061 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
1064 void wxTopLevelWindowMac::Iconize(bool iconize
)
1066 if ( IsWindowCollapsable( (WindowRef
)m_macWindow
) )
1067 CollapseWindow( (WindowRef
)m_macWindow
, iconize
) ;
1070 bool wxTopLevelWindowMac::IsIconized() const
1072 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1075 void wxTopLevelWindowMac::Restore()
1077 if ( IsMaximized() )
1079 else if ( IsIconized() )
1083 // ----------------------------------------------------------------------------
1084 // wxTopLevelWindowMac misc
1085 // ----------------------------------------------------------------------------
1087 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1089 return wxPoint(0, 0) ;
1092 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
1095 wxTopLevelWindowBase::SetIcon(icon
);
1098 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1100 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1102 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1104 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1108 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1110 if ( m_macEventHandler
!= NULL
)
1112 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1115 InstallWindowEventHandler(
1116 MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1117 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1120 void wxTopLevelWindowMac::MacCreateRealWindow(
1121 const wxString
& title
,
1125 const wxString
& name
)
1127 OSStatus err
= noErr
;
1129 m_windowStyle
= style
;
1137 wxRect display
= wxGetClientDisplayRect() ;
1139 if ( x
== wxDefaultPosition
.x
)
1142 if ( y
== wxDefaultPosition
.y
)
1145 int w
= WidthDefault(size
.x
);
1146 int h
= HeightDefault(size
.y
);
1148 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1150 // translate the window attributes in the appropriate window class and attributes
1151 WindowClass wclass
= 0;
1152 WindowAttributes attr
= kWindowNoAttributes
;
1153 WindowGroupRef group
= NULL
;
1155 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1158 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1159 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1160 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1163 wclass
= kFloatingWindowClass
;
1165 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1166 attr
|= kWindowSideTitlebarAttribute
;
1170 wclass
= kPlainWindowClass
;
1173 else if ( HasFlag( wxCAPTION
) )
1175 wclass
= kDocumentWindowClass
;
1176 attr
|= kWindowInWindowMenuAttribute
;
1178 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1179 else if ( HasFlag( wxFRAME_DRAWER
) )
1181 wclass
= kDrawerWindowClass
;
1182 // we must force compositing on a drawer
1183 m_macUsesCompositing
= true ;
1185 #endif //10.2 and up
1188 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1189 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1191 wclass
= kDocumentWindowClass
;
1195 wclass
= kPlainWindowClass
;
1199 if ( wclass
!= kPlainWindowClass
)
1201 if ( HasFlag( wxMINIMIZE_BOX
) )
1202 attr
|= kWindowCollapseBoxAttribute
;
1204 if ( HasFlag( wxMAXIMIZE_BOX
) )
1205 attr
|= kWindowFullZoomAttribute
;
1207 if ( HasFlag( wxRESIZE_BORDER
) )
1208 attr
|= kWindowResizableAttribute
;
1210 if ( HasFlag( wxCLOSE_BOX
) )
1211 attr
|= kWindowCloseBoxAttribute
;
1214 // turn on live resizing (OS X only)
1215 if (UMAGetSystemVersion() >= 0x1000)
1216 attr
|= kWindowLiveResizeAttribute
;
1218 if ( HasFlag(wxSTAY_ON_TOP
) )
1219 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1221 #if TARGET_API_MAC_OSX
1222 if ( m_macUsesCompositing
)
1223 attr
|= kWindowCompositingAttribute
;
1226 if ( HasFlag(wxFRAME_SHAPED
) )
1228 WindowDefSpec customWindowDefSpec
;
1229 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1230 customWindowDefSpec
.u
.defProc
= NewWindowDefUPP(wxShapedMacWindowDef
);
1232 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1233 attr
, &theBoundsRect
,
1234 (WindowRef
*) &m_macWindow
);
1238 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1241 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1242 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1244 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1246 // the create commands are only for content rect,
1247 // so we have to set the size again as structure bounds
1248 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1250 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1251 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1252 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1254 #if TARGET_API_MAC_OSX
1255 if ( m_macUsesCompositing
)
1257 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1258 // the content view, so we have to retrieve it explicitly
1259 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1260 m_peer
->GetControlRefAddr() ) ;
1261 if ( !m_peer
->Ok() )
1263 // compatibility mode fallback
1264 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1269 ::CreateRootControl( (WindowRef
)m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1272 // the root control level handler
1273 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1275 #if TARGET_API_MAC_OSX
1276 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1278 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1279 MacSetMetalAppearance( true ) ;
1283 // the frame window event handler
1284 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1285 MacInstallTopLevelWindowEventHandler() ;
1287 DoSetWindowVariant( m_windowVariant
) ;
1291 if ( HasFlag(wxFRAME_SHAPED
) )
1293 // default shape matches the window size
1294 wxRegion
rgn( 0, 0, w
, h
);
1298 wxWindowCreateEvent
event(this);
1299 GetEventHandler()->ProcessEvent(event
);
1302 void wxTopLevelWindowMac::ClearBackground()
1304 wxWindow::ClearBackground() ;
1307 // Raise the window to the top of the Z order
1308 void wxTopLevelWindowMac::Raise()
1310 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1313 // Lower the window to the bottom of the Z order
1314 void wxTopLevelWindowMac::Lower()
1316 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1319 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1321 if (s_macDeactivateWindow
)
1323 wxLogTrace(TRACE_ACTIVATE
,
1324 wxT("Doing delayed deactivation of %p"),
1325 s_macDeactivateWindow
);
1327 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1331 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1333 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1335 if (s_macDeactivateWindow
== this)
1336 s_macDeactivateWindow
= NULL
;
1338 MacDelayedDeactivation(timestamp
);
1339 MacPropagateHiliteChanged() ;
1342 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1344 wxWindow::SetLabel( title
) ;
1345 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1348 wxString
wxTopLevelWindowMac::GetTitle() const
1350 return wxWindow::GetLabel();
1353 bool wxTopLevelWindowMac::Show(bool show
)
1355 if ( !wxTopLevelWindowBase::Show(show
) )
1360 #if wxUSE_SYSTEM_OPTIONS
1361 // code contributed by Ryan Wilcox December 18, 2003
1362 bool plainTransition
= UMAGetSystemVersion() >= 0x1000 ;
1363 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1364 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1366 if ( plainTransition
)
1367 ::ShowWindow( (WindowRef
)m_macWindow
);
1369 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1372 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1375 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1377 // because apps expect a size event to occur at this moment
1378 wxSizeEvent
event(GetSize() , m_windowId
);
1379 event
.SetEventObject(this);
1380 GetEventHandler()->ProcessEvent(event
);
1384 #if wxUSE_SYSTEM_OPTIONS
1385 bool plainTransition
= UMAGetSystemVersion() >= 0x1000 ;
1386 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1387 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1388 if ( plainTransition
)
1390 ::HideWindow((WindowRef
) m_macWindow
);
1395 ::TransitionWindow((WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1399 MacPropagateVisibilityChanged() ;
1404 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1408 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1410 data
= new FullScreenData() ;
1412 m_macFullScreenData
= data
;
1413 data
->m_position
= GetPosition() ;
1414 data
->m_size
= GetSize() ;
1416 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1419 wxRect client
= wxGetClientDisplayRect() ;
1421 int left
, top
, right
, bottom
;
1429 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1431 if ( style
& wxFULLSCREEN_NOCAPTION
)
1437 if ( style
& wxFULLSCREEN_NOBORDER
)
1444 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1449 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1454 SetSize( x
, y
, w
, h
) ;
1459 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1460 SetPosition( data
->m_position
) ;
1461 SetSize( data
->m_size
) ;
1464 m_macFullScreenData
= NULL
;
1470 bool wxTopLevelWindowMac::IsFullScreen() const
1472 return m_macFullScreenData
!= NULL
;
1475 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1477 if ( GetExtraStyle() == exStyle
)
1480 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1482 #if TARGET_API_MAC_OSX
1483 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1485 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1486 if ( MacGetMetalAppearance() != metal
)
1487 MacSetMetalAppearance( metal
) ;
1492 // we are still using coordinates of the content view; TODO: switch to structure bounds
1494 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1498 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1499 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1501 left
= content
.left
- structure
.left
;
1502 top
= content
.top
- structure
.top
;
1503 right
= structure
.right
- content
.right
;
1504 bottom
= structure
.bottom
- content
.bottom
;
1507 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1509 m_cachedClippedRectValid
= false ;
1510 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1511 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1512 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1515 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1519 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1527 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1531 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1534 *width
= bounds
.right
- bounds
.left
;
1536 *height
= bounds
.bottom
- bounds
.top
;
1539 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1543 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1546 *width
= bounds
.right
- bounds
.left
;
1548 *height
= bounds
.bottom
- bounds
.top
;
1551 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1553 #if TARGET_API_MAC_OSX
1554 wxASSERT_MSG( m_macUsesCompositing
,
1555 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1557 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1558 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1562 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1564 #if TARGET_API_MAC_OSX
1565 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1571 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1573 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1576 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1579 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1584 void wxTopLevelWindowMac::MacPerformUpdates()
1586 #if TARGET_API_MAC_OSX
1587 if ( m_macUsesCompositing
)
1589 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1590 // for composited windows this also triggers a redraw of all
1591 // invalid views in the window
1592 if ( UMAGetSystemVersion() >= 0x1030 )
1593 HIWindowFlush((WindowRef
) m_macWindow
) ;
1597 // the only way to trigger the redrawing on earlier systems is to call
1600 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1601 UInt32 currentEventClass
= 0 ;
1602 UInt32 currentEventKind
= 0 ;
1603 if ( currentEvent
!= NULL
)
1605 currentEventClass
= ::GetEventClass( currentEvent
) ;
1606 currentEventKind
= ::GetEventKind( currentEvent
) ;
1609 if ( currentEventClass
!= kEventClassMenu
)
1611 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1613 OSStatus status
= noErr
;
1614 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1621 BeginUpdate( (WindowRef
) m_macWindow
) ;
1623 RgnHandle updateRgn
= NewRgn();
1626 GetPortVisibleRegion( GetWindowPort( (WindowRef
)m_macWindow
), updateRgn
);
1627 UpdateControls( (WindowRef
)m_macWindow
, updateRgn
) ;
1629 // if ( !EmptyRgn( updateRgn ) )
1630 // MacDoRedraw( updateRgn , 0 , true) ;
1632 DisposeRgn( updateRgn
);
1635 EndUpdate( (WindowRef
)m_macWindow
) ;
1636 QDFlushPortBuffer( GetWindowPort( (WindowRef
)m_macWindow
) , NULL
) ;
1640 // Attracts the users attention to this window if the application is
1641 // inactive (should be called when a background event occurs)
1643 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1646 DisposePtr( (Ptr
)ptr
) ;
1649 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1651 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1652 static wxMacNMUPP
nmupp( wxMacNMResponse
);
1654 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1655 notificationRequest
->qType
= nmType
;
1656 notificationRequest
->nmMark
= 1 ;
1657 notificationRequest
->nmIcon
= 0 ;
1658 notificationRequest
->nmSound
= 0 ;
1659 notificationRequest
->nmStr
= NULL
;
1660 notificationRequest
->nmResp
= nmupp
;
1662 verify_noerr( NMInstall( notificationRequest
) ) ;
1665 // ---------------------------------------------------------------------------
1666 // Shape implementation
1667 // ---------------------------------------------------------------------------
1670 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1672 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1673 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1675 // The empty region signifies that the shape
1676 // should be removed from the window.
1677 if ( region
.IsEmpty() )
1679 wxSize sz
= GetClientSize();
1680 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1681 if ( rgn
.IsEmpty() )
1684 return SetShape(rgn
);
1687 // Make a copy of the region
1688 RgnHandle shapeRegion
= NewRgn();
1689 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1691 // Dispose of any shape region we may already have
1692 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1696 // Save the region so we can use it later
1697 SetWRefCon((WindowRef
)MacGetWindowRef(), (SInt32
)shapeRegion
);
1699 // inform the window manager that the window has changed shape
1700 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1705 // ---------------------------------------------------------------------------
1706 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1707 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1708 // ---------------------------------------------------------------------------
1710 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1712 GetWindowPortBounds(window
, inRect
);
1713 Point pt
= { inRect
->left
, inRect
->top
};
1715 QDLocalToGlobalPoint( GetWindowPort(window
), &pt
) ;
1717 inRect
->left
= pt
.h
;
1718 inRect
->bottom
+= pt
.v
;
1719 inRect
->right
+= pt
.h
;
1722 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1724 /*------------------------------------------------------
1725 Define which options your custom window supports.
1726 --------------------------------------------------------*/
1727 //just enable everything for our demo
1728 *(OptionBits
*)param
=
1731 //kWindowCanCollapse |
1732 //kWindowCanGetWindowRegion |
1733 //kWindowHasTitleBar |
1734 //kWindowSupportsDragHilite |
1735 kWindowCanDrawInCurrentPort
|
1736 //kWindowCanMeasureTitle |
1737 kWindowWantsDisposeAtProcessDeath
|
1738 kWindowSupportsGetGrowImageRegion
|
1739 kWindowDefSupportsColorGrafPort
;
1744 // The content region is left as a rectangle matching the window size, this is
1745 // so the origin in the paint event, and etc. still matches what the
1746 // programmer expects.
1747 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1750 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1754 wxShapedMacWindowGetPos( window
, &r
) ;
1755 RectRgn( rgn
, &r
) ;
1759 // The structure region is set to the shape given to the SetShape method.
1760 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1762 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1768 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1769 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1770 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1771 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1775 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1777 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1782 switch (rgnRec
->regionCode
)
1784 case kWindowStructureRgn
:
1785 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1788 case kWindowContentRgn
:
1789 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1793 SetEmptyRgn(rgnRec
->winRgn
);
1800 // Determine the region of the window which was hit
1802 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1805 static RgnHandle tempRgn
= NULL
;
1807 if (tempRgn
== NULL
)
1810 // get the point clicked
1811 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1813 // Mac OS 8.5 or later
1814 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1815 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1818 // no significant area was hit
1822 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1826 case kWindowMsgHitTest
:
1827 return wxShapedMacWindowHitTest(window
, param
);
1829 case kWindowMsgGetFeatures
:
1830 return wxShapedMacWindowGetFeatures(window
, param
);
1832 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1833 case kWindowMsgGetRegion
:
1834 return wxShapedMacWindowGetRegion(window
, param
);