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"
27 #include "wx/toplevel.h"
32 #include "wx/string.h"
35 #include "wx/settings.h"
36 #include "wx/strconv.h"
37 #include "wx/control.h"
40 #include "wx/mac/uma.h"
41 #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 // unified title and toolbar constant - not in Tiger headers, so we duplicate it here
61 #define kWindowUnifiedTitleAndToolbarAttribute (1 << 7)
63 // trace mask for activation tracing messages
64 static const wxChar
*TRACE_ACTIVATE
= _T("activation");
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 // list of all frames and modeless dialogs
71 wxWindowList wxModelessWindows
;
73 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
75 // ============================================================================
76 // wxTopLevelWindowMac implementation
77 // ============================================================================
79 BEGIN_EVENT_TABLE(wxTopLevelWindowMac
, wxTopLevelWindowBase
)
83 // ---------------------------------------------------------------------------
85 // ---------------------------------------------------------------------------
87 static const EventTypeSpec eventList
[] =
89 // TODO: remove control related event like key and mouse (except for WindowLeave events)
91 { kEventClassKeyboard
, kEventRawKeyDown
} ,
92 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
93 { kEventClassKeyboard
, kEventRawKeyUp
} ,
94 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
96 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
97 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
99 { kEventClassWindow
, kEventWindowShown
} ,
100 { kEventClassWindow
, kEventWindowActivated
} ,
101 { kEventClassWindow
, kEventWindowDeactivated
} ,
102 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
103 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
104 { kEventClassWindow
, kEventWindowClose
} ,
105 { kEventClassWindow
, kEventWindowGetRegion
} ,
107 // we have to catch these events on the toplevel window level,
108 // as controls don't get the raw mouse events anymore
110 { kEventClassMouse
, kEventMouseDown
} ,
111 { kEventClassMouse
, kEventMouseUp
} ,
112 { kEventClassMouse
, kEventMouseWheelMoved
} ,
113 { kEventClassMouse
, kEventMouseMoved
} ,
114 { kEventClassMouse
, kEventMouseDragged
} ,
117 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
119 OSStatus result
= eventNotHandledErr
;
120 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
121 // FindFocus does not return the actual focus window, but the enclosing window
122 wxWindow
* focus
= wxWindow::DoFindFocus();
124 focus
= (wxTopLevelWindowMac
*) data
;
126 unsigned char charCode
;
134 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
137 ByteCount dataSize
= 0 ;
138 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
141 int numChars
= dataSize
/ sizeof( UniChar
) + 1;
143 UniChar
* charBuf
= buf
;
145 if ( numChars
* 2 > 4 )
146 charBuf
= new UniChar
[ numChars
] ;
147 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
148 charBuf
[ numChars
- 1 ] = 0;
150 #if SIZEOF_WCHAR_T == 2
151 uniChar
= charBuf
[0] ;
153 wxMBConvUTF16 converter
;
154 converter
.MB2WC( uniChar
, (const char*)charBuf
, 2 ) ;
157 if ( numChars
* 2 > 4 )
162 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
163 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
164 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
165 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
167 UInt32 message
= (keyCode
<< 8) + charCode
;
168 switch ( GetEventKind( event
) )
170 case kEventRawKeyRepeat
:
171 case kEventRawKeyDown
:
173 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
174 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
175 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
176 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
177 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
181 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
185 case kEventRawKeyUp
:
186 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
187 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
193 case kEventRawKeyModifiersChanged
:
195 wxKeyEvent
event(wxEVT_KEY_DOWN
);
197 event
.m_shiftDown
= modifiers
& shiftKey
;
198 event
.m_controlDown
= modifiers
& controlKey
;
199 event
.m_altDown
= modifiers
& optionKey
;
200 event
.m_metaDown
= modifiers
& cmdKey
;
205 event
.m_uniChar
= uniChar
[0] ;
208 event
.SetTimestamp(when
);
209 event
.SetEventObject(focus
);
211 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
213 event
.m_keyCode
= WXK_CONTROL
;
214 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
215 focus
->GetEventHandler()->ProcessEvent( event
) ;
217 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
219 event
.m_keyCode
= WXK_SHIFT
;
220 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
221 focus
->GetEventHandler()->ProcessEvent( event
) ;
223 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
225 event
.m_keyCode
= WXK_ALT
;
226 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
227 focus
->GetEventHandler()->ProcessEvent( event
) ;
229 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
231 event
.m_keyCode
= WXK_COMMAND
;
232 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
233 focus
->GetEventHandler()->ProcessEvent( event
) ;
236 wxApp::s_lastModifiers
= modifiers
;
247 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
248 // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
251 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
253 wxWindow
* g_MacLastWindow
= NULL
;
255 EventMouseButton g_lastButton
= 0 ;
256 bool g_lastButtonWasFakeRight
= false ;
258 void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
260 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
261 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
263 // this parameter are not given for all events
264 EventMouseButton button
= 0 ;
265 UInt32 clickCount
= 0 ;
266 cEvent
.GetParameter
<EventMouseButton
>( kEventParamMouseButton
, typeMouseButton
, &button
) ;
267 cEvent
.GetParameter
<UInt32
>( kEventParamClickCount
, typeUInt32
, &clickCount
) ;
269 wxevent
.m_x
= screenMouseLocation
.h
;
270 wxevent
.m_y
= screenMouseLocation
.v
;
271 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
272 wxevent
.m_controlDown
= modifiers
& controlKey
;
273 wxevent
.m_altDown
= modifiers
& optionKey
;
274 wxevent
.m_metaDown
= modifiers
& cmdKey
;
275 wxevent
.m_clickCount
= clickCount
;
276 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
278 // a control click is interpreted as a right click
279 bool thisButtonIsFakeRight
= false ;
280 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
282 button
= kEventMouseButtonSecondary
;
283 thisButtonIsFakeRight
= true ;
285 // otherwise we report double clicks by connecting a left click with a ctrl-left click
286 if ( clickCount
> 1 && button
!= g_lastButton
)
289 // we must make sure that our synthetic 'right' button corresponds in
290 // mouse down, moved and mouse up, and does not deliver a right down and left up
292 if ( cEvent
.GetKind() == kEventMouseDown
)
294 g_lastButton
= button
;
295 g_lastButtonWasFakeRight
= thisButtonIsFakeRight
;
301 g_lastButtonWasFakeRight
= false ;
303 else if ( g_lastButton
== kEventMouseButtonSecondary
&& g_lastButtonWasFakeRight
)
304 button
= g_lastButton
;
306 // determine the correct down state, wx does not want a 'down' for a mouseUp event,
307 // while mac delivers this button
308 if ( button
!= 0 && cEvent
.GetKind() != kEventMouseUp
)
312 case kEventMouseButtonPrimary
:
313 wxevent
.m_leftDown
= true ;
316 case kEventMouseButtonSecondary
:
317 wxevent
.m_rightDown
= true ;
320 case kEventMouseButtonTertiary
:
321 wxevent
.m_middleDown
= true ;
329 // translate into wx types
330 switch ( cEvent
.GetKind() )
332 case kEventMouseDown
:
335 case kEventMouseButtonPrimary
:
336 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
339 case kEventMouseButtonSecondary
:
340 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
343 case kEventMouseButtonTertiary
:
344 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
355 case kEventMouseButtonPrimary
:
356 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
359 case kEventMouseButtonSecondary
:
360 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
363 case kEventMouseButtonTertiary
:
364 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
372 case kEventMouseWheelMoved
:
374 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
376 EventMouseWheelAxis axis
= cEvent
.GetParameter
<EventMouseWheelAxis
>(kEventParamMouseWheelAxis
, typeMouseWheelAxis
) ;
377 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeSInt32
) ;
379 wxevent
.m_wheelRotation
= delta
;
380 wxevent
.m_wheelDelta
= 1;
381 wxevent
.m_linesPerAction
= 1;
382 if ( axis
== kEventMouseWheelAxisX
)
383 wxevent
.m_wheelAxis
= 1;
388 wxevent
.SetEventType( wxEVT_MOTION
) ;
393 ControlRef
wxMacFindSubControl( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, ControlRef superControl
, ControlPartCode
*outPart
)
397 UInt16 childrenCount
= 0 ;
398 ControlHandle sibling
;
400 OSStatus err
= CountSubControls( superControl
, &childrenCount
) ;
401 if ( err
== errControlIsNotEmbedder
)
404 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
406 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
408 err
= GetIndexedSubControl( superControl
, i
, & sibling
) ;
409 if ( err
== errControlIsNotEmbedder
)
412 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
413 if ( IsControlVisible( sibling
) )
415 UMAGetControlBoundsInWindowCoords( sibling
, &r
) ;
416 if ( MacPtInRect( location
, &r
) )
418 ControlHandle child
= wxMacFindSubControl( toplevelWindow
, location
, sibling
, outPart
) ;
425 Point testLocation
= location
;
427 if ( toplevelWindow
)
429 testLocation
.h
-= r
.left
;
430 testLocation
.v
-= r
.top
;
433 *outPart
= TestControl( sibling
, testLocation
) ;
445 ControlRef
wxMacFindControlUnderMouse( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, WindowRef window
, ControlPartCode
*outPart
)
447 #if TARGET_API_MAC_OSX
448 if ( UMAGetSystemVersion() >= 0x1030 )
449 return FindControlUnderMouse( location
, window
, outPart
) ;
452 ControlRef rootControl
= NULL
;
453 verify_noerr( GetRootControl( window
, &rootControl
) ) ;
455 return wxMacFindSubControl( toplevelWindow
, location
, rootControl
, outPart
) ;
458 #define NEW_CAPTURE_HANDLING 1
461 wxMacTopLevelMouseEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
465 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
467 OSStatus result
= eventNotHandledErr
;
469 wxMacCarbonEvent
cEvent( event
) ;
471 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
472 Point windowMouseLocation
= screenMouseLocation
;
474 WindowRef window
= NULL
;
475 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
477 wxWindow
* currentMouseWindow
= NULL
;
478 ControlRef control
= NULL
;
480 #if NEW_CAPTURE_HANDLING
481 if ( wxApp::s_captureWindow
)
483 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
484 windowPart
= inContent
;
490 wxMacGlobalToLocal( window
, &windowMouseLocation
) ;
492 if ( wxApp::s_captureWindow
493 #if !NEW_CAPTURE_HANDLING
494 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
498 currentMouseWindow
= wxApp::s_captureWindow
;
500 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
502 ControlPartCode part
;
503 control
= wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &part
) ;
504 // if there is no control below the mouse position, send the event to the toplevel window itself
507 currentMouseWindow
= (wxWindow
*) data
;
511 currentMouseWindow
= wxFindControlFromMacControl( control
) ;
512 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
515 // for wxToolBar to function we have to send certaint events to it
516 // instead of its children (wxToolBarTools)
518 GetSuperControl(control
, &parent
);
519 wxWindow
*wxParent
= wxFindControlFromMacControl( parent
) ;
520 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
521 currentMouseWindow
= wxParent
;
526 // disabled windows must not get any input messages
527 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
528 currentMouseWindow
= NULL
;
532 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
533 SetupMouseEvent( wxevent
, cEvent
) ;
535 // handle all enter / leave events
537 if ( currentMouseWindow
!= g_MacLastWindow
)
539 if ( g_MacLastWindow
)
541 wxMouseEvent
eventleave(wxevent
);
542 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
543 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
544 eventleave
.SetEventObject( g_MacLastWindow
) ;
545 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
548 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
551 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
554 if ( currentMouseWindow
)
556 wxMouseEvent
evententer(wxevent
);
557 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
558 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
559 evententer
.SetEventObject( currentMouseWindow
) ;
560 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
563 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
566 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
569 g_MacLastWindow
= currentMouseWindow
;
572 if ( windowPart
== inMenuBar
)
574 // special case menu bar, as we are having a low-level runloop we must do it ourselves
575 if ( cEvent
.GetKind() == kEventMouseDown
)
577 ::MenuSelect( screenMouseLocation
) ;
581 else if ( currentMouseWindow
)
583 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
585 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
587 wxevent
.SetEventObject( currentMouseWindow
) ;
588 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
590 // make tooltips current
593 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
594 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
597 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
599 if ((currentMouseWindowParent
!= NULL
) &&
600 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
601 currentMouseWindow
= NULL
;
607 // if the user code did _not_ handle the event, then perform the
608 // default processing
609 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
611 // ... that is set focus to this window
612 if (currentMouseWindow
->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
613 currentMouseWindow
->SetFocus();
616 ControlPartCode dummyPart
;
617 // if built-in find control is finding the wrong control (ie static box instead of overlaid
618 // button, we cannot let the standard handler do its job, but must handle manually
620 if ( ( cEvent
.GetKind() == kEventMouseDown
)
623 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
624 wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &dummyPart
) )
628 if ( currentMouseWindow
->MacIsReallyEnabled() )
630 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
631 Point clickLocation
= windowMouseLocation
;
633 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
635 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
636 modifiers
, (ControlActionUPP
) -1 ) ;
638 if ((currentMouseWindowParent
!= NULL
) &&
639 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
641 currentMouseWindow
= NULL
;
649 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
651 wxApp::s_captureWindow
= NULL
;
657 wxWindow
* cursorTarget
= currentMouseWindow
;
658 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
660 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
662 cursorTarget
= cursorTarget
->GetParent() ;
664 cursorPoint
+= cursorTarget
->GetPosition();
668 else // currentMouseWindow == NULL
670 // don't mess with controls we don't know about
671 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
672 // so we try sending them the correct control directly
673 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
675 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
676 Point clickLocation
= windowMouseLocation
;
677 #if TARGET_API_MAC_OSX
679 hiPoint
.x
= clickLocation
.h
;
680 hiPoint
.y
= clickLocation
.v
;
681 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
682 clickLocation
.h
= (int)hiPoint
.x
;
683 clickLocation
.v
= (int)hiPoint
.y
;
684 #endif // TARGET_API_MAC_OSX
686 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
694 static pascal OSStatus
695 wxMacTopLevelWindowEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
699 OSStatus result
= eventNotHandledErr
;
701 wxMacCarbonEvent
cEvent( event
) ;
703 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
704 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
706 switch ( GetEventKind( event
) )
708 case kEventWindowActivated
:
710 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
711 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
712 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
713 wxevent
.SetEventObject(toplevelWindow
);
714 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
715 // we still sending an eventNotHandledErr in order to allow for default processing
719 case kEventWindowDeactivated
:
721 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
722 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
723 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
724 wxevent
.SetEventObject(toplevelWindow
);
725 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
726 // we still sending an eventNotHandledErr in order to allow for default processing
730 case kEventWindowShown
:
731 toplevelWindow
->Refresh() ;
735 case kEventWindowClose
:
736 toplevelWindow
->Close() ;
740 case kEventWindowBoundsChanged
:
742 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
743 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
744 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
745 if ( attributes
& kWindowBoundsChangeSizeChanged
)
747 // according to the other ports we handle this within the OS level
748 // resize event, not within a wxSizeEvent
749 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
752 frame
->PositionBars();
755 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
756 event
.SetEventObject( toplevelWindow
) ;
758 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
759 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
762 if ( attributes
& kWindowBoundsChangeOriginChanged
)
764 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
765 event
.SetEventObject( toplevelWindow
) ;
766 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
773 case kEventWindowBoundsChanging
:
775 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
776 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
778 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
780 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
781 int left
, top
, right
, bottom
;
782 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
787 newRect
.right
- newRect
.left
+ left
+ right
,
788 newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
790 // this is a EVT_SIZING not a EVT_SIZE type !
791 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
792 wxevent
.SetEventObject( toplevelWindow
) ;
794 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
795 adjustR
= wxevent
.GetRect() ;
797 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
798 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
799 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
800 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
801 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
802 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
803 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
804 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
805 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
806 if ( !EqualRect( &newRect
, &adjustedRect
) )
807 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
808 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
815 case kEventWindowGetRegion
:
817 if ( toplevelWindow
->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
819 WindowRegionCode windowRegionCode
;
821 // Fetch the region code that is being queried
822 GetEventParameter( event
,
823 kEventParamWindowRegionCode
,
824 typeWindowRegionCode
, NULL
,
825 sizeof windowRegionCode
, NULL
,
826 &windowRegionCode
) ;
828 // If it is the opaque region code then set the
829 // region to empty and return noErr to stop event
831 if ( windowRegionCode
== kWindowOpaqueRgn
) {
833 GetEventParameter( event
,
834 kEventParamRgnHandle
,
835 typeQDRgnHandle
, NULL
,
838 SetEmptyRgn(region
) ;
852 // mix this in from window.cpp
853 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
855 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
857 OSStatus result
= eventNotHandledErr
;
859 switch ( GetEventClass( event
) )
861 case kEventClassTextInput
:
862 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
865 case kEventClassKeyboard
:
866 result
= KeyboardEventHandler( handler
, event
, data
) ;
869 case kEventClassWindow
:
870 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
873 case kEventClassMouse
:
874 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
884 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
886 // ---------------------------------------------------------------------------
887 // wxWindowMac utility functions
888 // ---------------------------------------------------------------------------
890 // Find an item given the Macintosh Window Reference
892 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
894 static MacWindowMap wxWinMacWindowList
;
896 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
898 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
900 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
903 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
904 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
906 // adding NULL WindowRef is (first) surely a result of an error and
908 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
910 wxWinMacWindowList
[inWindowRef
] = win
;
913 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
914 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
916 MacWindowMap::iterator it
;
917 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
919 if ( it
->second
== win
)
921 wxWinMacWindowList
.erase(it
);
927 // ----------------------------------------------------------------------------
928 // wxTopLevelWindowMac creation
929 // ----------------------------------------------------------------------------
931 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
937 bool m_wasResizable
;
940 void wxTopLevelWindowMac::Init()
943 m_maximizeOnShow
= false;
946 m_macEventHandler
= NULL
;
947 m_macFullScreenData
= NULL
;
950 class wxMacDeferredWindowDeleter
: public wxObject
953 wxMacDeferredWindowDeleter( WindowRef windowRef
)
955 m_macWindow
= windowRef
;
958 virtual ~wxMacDeferredWindowDeleter()
960 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
964 WindowRef m_macWindow
;
967 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
969 const wxString
& title
,
973 const wxString
& name
)
978 m_windowStyle
= style
;
982 m_windowId
= id
== -1 ? NewControlId() : id
;
983 wxWindow::SetLabel( title
) ;
985 MacCreateRealWindow( title
, pos
, size
, style
, name
) ;
987 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
989 if (GetExtraStyle() & wxFRAME_EX_METAL
)
990 MacSetMetalAppearance(true);
992 wxTopLevelWindows
.Append(this);
995 parent
->AddChild(this);
1000 wxTopLevelWindowMac::~wxTopLevelWindowMac()
1005 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
1007 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
1010 if ( m_macEventHandler
)
1012 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1013 m_macEventHandler
= NULL
;
1016 wxRemoveMacWindowAssociation( this ) ;
1018 if ( wxModelessWindows
.Find(this) )
1019 wxModelessWindows
.DeleteObject(this);
1021 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1023 m_macFullScreenData
= NULL
;
1025 // avoid dangling refs
1026 if ( s_macDeactivateWindow
== this )
1027 s_macDeactivateWindow
= NULL
;
1031 // ----------------------------------------------------------------------------
1032 // wxTopLevelWindowMac maximize/minimize
1033 // ----------------------------------------------------------------------------
1035 void wxTopLevelWindowMac::Maximize(bool maximize
)
1037 Point idealSize
= { 0 , 0 } ;
1040 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1042 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
1044 idealSize
.h
= bounds
.size
.width
;
1045 idealSize
.v
= bounds
.size
.height
;
1048 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
1049 idealSize
.h
= rect
.right
- rect
.left
;
1050 idealSize
.v
= rect
.bottom
- rect
.top
;
1053 ZoomWindowIdeal( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
1056 bool wxTopLevelWindowMac::IsMaximized() const
1058 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
1061 void wxTopLevelWindowMac::Iconize(bool iconize
)
1063 if ( IsWindowCollapsable( (WindowRef
)m_macWindow
) )
1064 CollapseWindow( (WindowRef
)m_macWindow
, iconize
) ;
1067 bool wxTopLevelWindowMac::IsIconized() const
1069 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1072 void wxTopLevelWindowMac::Restore()
1074 if ( IsMaximized() )
1076 else if ( IsIconized() )
1080 // ----------------------------------------------------------------------------
1081 // wxTopLevelWindowMac misc
1082 // ----------------------------------------------------------------------------
1084 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1086 return wxPoint(0, 0) ;
1089 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1091 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1093 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1095 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1099 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1101 if ( m_macEventHandler
!= NULL
)
1103 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1106 InstallWindowEventHandler(
1107 MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1108 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1111 void wxTopLevelWindowMac::MacCreateRealWindow(
1112 const wxString
& title
,
1116 const wxString
& name
)
1118 OSStatus err
= noErr
;
1120 m_windowStyle
= style
;
1128 wxRect display
= wxGetClientDisplayRect() ;
1130 if ( x
== wxDefaultPosition
.x
)
1133 if ( y
== wxDefaultPosition
.y
)
1136 int w
= WidthDefault(size
.x
);
1137 int h
= HeightDefault(size
.y
);
1139 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1141 // translate the window attributes in the appropriate window class and attributes
1142 WindowClass wclass
= 0;
1143 WindowAttributes attr
= kWindowNoAttributes
;
1144 WindowGroupRef group
= NULL
;
1146 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1149 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1150 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1151 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1154 wclass
= kFloatingWindowClass
;
1156 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1157 attr
|= kWindowSideTitlebarAttribute
;
1161 wclass
= kPlainWindowClass
;
1164 else if ( HasFlag( wxPOPUP_WINDOW
) )
1167 // Until we've got a real wxPopupWindow class on wxMac make it a
1168 // little easier for wxFrame to be used to emulate it and workaround
1169 // the lack of wxPopupWindow.
1170 if ( HasFlag( wxBORDER_NONE
) )
1171 wclass
= kHelpWindowClass
; // has no border
1173 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1174 //attr |= kWindowNoShadowAttribute; // turn off the shadow Should we??
1175 group
= GetWindowGroupOfClass( // float above other windows
1176 kFloatingWindowClass
) ;
1178 else if ( HasFlag( wxCAPTION
) )
1180 wclass
= kDocumentWindowClass
;
1181 attr
|= kWindowInWindowMenuAttribute
;
1183 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1184 else if ( HasFlag( wxFRAME_DRAWER
) )
1186 wclass
= kDrawerWindowClass
;
1188 #endif //10.2 and up
1191 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1192 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1194 wclass
= kDocumentWindowClass
;
1198 wclass
= kPlainWindowClass
;
1202 if ( wclass
!= kPlainWindowClass
)
1204 if ( HasFlag( wxMINIMIZE_BOX
) )
1205 attr
|= kWindowCollapseBoxAttribute
;
1207 if ( HasFlag( wxMAXIMIZE_BOX
) )
1208 attr
|= kWindowFullZoomAttribute
;
1210 if ( HasFlag( wxRESIZE_BORDER
) )
1211 attr
|= kWindowResizableAttribute
;
1213 if ( HasFlag( wxCLOSE_BOX
) )
1214 attr
|= kWindowCloseBoxAttribute
;
1217 // turn on live resizing (OS X only)
1218 if (UMAGetSystemVersion() >= 0x1000)
1219 attr
|= kWindowLiveResizeAttribute
;
1221 if ( HasFlag(wxSTAY_ON_TOP
) )
1222 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1224 if ( HasFlag( wxFRAME_FLOAT_ON_PARENT
) )
1225 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1227 attr
|= kWindowCompositingAttribute
;
1228 #if 0 // wxMAC_USE_CORE_GRAPHICS ; TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1229 attr
|= kWindowFrameworkScaledAttribute
;
1232 if ( HasFlag(wxFRAME_SHAPED
) )
1234 WindowDefSpec customWindowDefSpec
;
1235 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1236 customWindowDefSpec
.u
.defProc
=
1238 (WindowDefUPP
) wxShapedMacWindowDef
;
1240 NewWindowDefUPP(wxShapedMacWindowDef
);
1242 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1243 attr
, &theBoundsRect
,
1244 (WindowRef
*) &m_macWindow
);
1248 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1251 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1252 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1254 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1256 // setup a separate group for each window, so that overlays can be handled easily
1257 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &group
));
1258 verify_noerr( SetWindowGroupParent( group
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1259 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, group
));
1261 // the create commands are only for content rect,
1262 // so we have to set the size again as structure bounds
1263 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1265 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1266 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1267 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1269 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1270 // the content view, so we have to retrieve it explicitly
1271 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1272 m_peer
->GetControlRefAddr() ) ;
1273 if ( !m_peer
->Ok() )
1275 // compatibility mode fallback
1276 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1279 // the root control level handler
1280 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1282 // Causes the inner part of the window not to be metal
1283 // if the style is used before window creation.
1284 #if 0 // TARGET_API_MAC_OSX
1285 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1287 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1288 MacSetMetalAppearance( true ) ;
1292 #if TARGET_API_MAC_OSX
1293 if ( m_macWindow
!= NULL
)
1295 MacSetUnifiedAppearance( true ) ;
1299 // the frame window event handler
1300 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1301 MacInstallTopLevelWindowEventHandler() ;
1303 DoSetWindowVariant( m_windowVariant
) ;
1307 if ( HasFlag(wxFRAME_SHAPED
) )
1309 // default shape matches the window size
1310 wxRegion
rgn( 0, 0, w
, h
);
1314 wxWindowCreateEvent
event(this);
1315 GetEventHandler()->ProcessEvent(event
);
1318 void wxTopLevelWindowMac::ClearBackground()
1320 wxWindow::ClearBackground() ;
1323 // Raise the window to the top of the Z order
1324 void wxTopLevelWindowMac::Raise()
1326 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1329 // Lower the window to the bottom of the Z order
1330 void wxTopLevelWindowMac::Lower()
1332 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1335 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1337 if (s_macDeactivateWindow
)
1339 wxLogTrace(TRACE_ACTIVATE
,
1340 wxT("Doing delayed deactivation of %p"),
1341 s_macDeactivateWindow
);
1343 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1347 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool WXUNUSED(inIsActivating
) )
1349 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1351 if (s_macDeactivateWindow
== this)
1352 s_macDeactivateWindow
= NULL
;
1354 MacDelayedDeactivation(timestamp
);
1355 MacPropagateHiliteChanged() ;
1358 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1360 wxWindow::SetLabel( title
) ;
1361 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1364 wxString
wxTopLevelWindowMac::GetTitle() const
1366 return wxWindow::GetLabel();
1369 bool wxTopLevelWindowMac::Show(bool show
)
1371 if ( !wxTopLevelWindowBase::Show(show
) )
1374 bool plainTransition
= false;
1376 #if wxUSE_SYSTEM_OPTIONS
1377 // code contributed by Ryan Wilcox December 18, 2003
1378 plainTransition
= UMAGetSystemVersion() >= 0x1000 ;
1379 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1380 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1385 if ( plainTransition
)
1386 ::ShowWindow( (WindowRef
)m_macWindow
);
1388 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1390 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1392 // because apps expect a size event to occur at this moment
1393 wxSizeEvent
event(GetSize() , m_windowId
);
1394 event
.SetEventObject(this);
1395 GetEventHandler()->ProcessEvent(event
);
1399 if ( plainTransition
)
1400 ::HideWindow( (WindowRef
)m_macWindow
);
1402 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1405 MacPropagateVisibilityChanged() ;
1410 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1414 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1416 data
= new FullScreenData() ;
1418 m_macFullScreenData
= data
;
1419 data
->m_position
= GetPosition() ;
1420 data
->m_size
= GetSize() ;
1421 data
->m_wasResizable
= MacGetWindowAttributes() & kWindowResizableAttribute
;
1423 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1426 wxRect client
= wxGetClientDisplayRect() ;
1428 int left
, top
, right
, bottom
;
1436 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1438 if ( style
& wxFULLSCREEN_NOCAPTION
)
1444 if ( style
& wxFULLSCREEN_NOBORDER
)
1451 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1456 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1461 SetSize( x
, y
, w
, h
) ;
1462 if ( data
->m_wasResizable
)
1463 MacChangeWindowAttributes( kWindowNoAttributes
, kWindowResizableAttribute
) ;
1468 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1469 if ( data
->m_wasResizable
)
1470 MacChangeWindowAttributes( kWindowResizableAttribute
, kWindowNoAttributes
) ;
1471 SetPosition( data
->m_position
) ;
1472 SetSize( data
->m_size
) ;
1475 m_macFullScreenData
= NULL
;
1481 bool wxTopLevelWindowMac::IsFullScreen() const
1483 return m_macFullScreenData
!= NULL
;
1487 bool wxTopLevelWindowMac::SetTransparent(wxByte alpha
)
1489 OSStatus result
= SetWindowAlpha((WindowRef
)m_macWindow
, float(alpha
)/255.0);
1490 return result
== noErr
;
1494 bool wxTopLevelWindowMac::CanSetTransparent()
1500 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1502 if ( GetExtraStyle() == exStyle
)
1505 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1507 #if TARGET_API_MAC_OSX
1508 if ( m_macWindow
!= NULL
)
1510 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1512 if ( MacGetMetalAppearance() != metal
)
1514 if ( MacGetUnifiedAppearance() )
1515 MacSetUnifiedAppearance( !metal
) ;
1517 MacSetMetalAppearance( metal
) ;
1523 bool wxTopLevelWindowMac::SetBackgroundStyle(wxBackgroundStyle style
)
1525 if ( !wxTopLevelWindowBase::SetBackgroundStyle(style
) )
1528 WindowRef windowRef
= HIViewGetWindow( (HIViewRef
)GetHandle() );
1530 if ( GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
1532 OSStatus err
= HIWindowChangeFeatures( windowRef
, 0, kWindowIsOpaque
);
1533 verify_noerr( err
);
1534 err
= ReshapeCustomWindow( windowRef
);
1535 verify_noerr( err
);
1541 // TODO: switch to structure bounds -
1542 // we are still using coordinates of the content view
1544 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1546 Rect content
, structure
;
1548 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1549 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1551 left
= content
.left
- structure
.left
;
1552 top
= content
.top
- structure
.top
;
1553 right
= structure
.right
- content
.right
;
1554 bottom
= structure
.bottom
- content
.bottom
;
1557 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1559 m_cachedClippedRectValid
= false ;
1560 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1561 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1562 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1565 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1569 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1577 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1581 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1584 *width
= bounds
.right
- bounds
.left
;
1586 *height
= bounds
.bottom
- bounds
.top
;
1589 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1593 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1596 *width
= bounds
.right
- bounds
.left
;
1598 *height
= bounds
.bottom
- bounds
.top
;
1601 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1603 #if TARGET_API_MAC_OSX
1604 if ( MacGetUnifiedAppearance() )
1605 MacSetUnifiedAppearance( false ) ;
1607 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1608 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1612 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1614 #if TARGET_API_MAC_OSX
1615 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1621 void wxTopLevelWindowMac::MacSetUnifiedAppearance( bool set
)
1623 #if TARGET_API_MAC_OSX
1624 if ( UMAGetSystemVersion() >= 0x1040 )
1626 if ( MacGetMetalAppearance() )
1627 MacSetMetalAppearance( false ) ;
1629 MacChangeWindowAttributes( set
? kWindowUnifiedTitleAndToolbarAttribute
: kWindowNoAttributes
,
1630 set
? kWindowNoAttributes
: kWindowUnifiedTitleAndToolbarAttribute
) ;
1632 // For some reason, Tiger uses white as the background color for this appearance,
1633 // while most apps using it use the typical striped background. Restore that behavior
1635 // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
1637 SetBackgroundColour( wxSYS_COLOUR_WINDOW
) ;
1642 bool wxTopLevelWindowMac::MacGetUnifiedAppearance() const
1644 #if TARGET_API_MAC_OSX
1645 if ( UMAGetSystemVersion() >= 0x1040 )
1646 return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute
;
1652 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1654 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1657 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1660 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1665 void wxTopLevelWindowMac::MacPerformUpdates()
1667 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1668 // for composited windows this also triggers a redraw of all
1669 // invalid views in the window
1670 if ( UMAGetSystemVersion() >= 0x1030 )
1671 HIWindowFlush((WindowRef
) m_macWindow
) ;
1675 // the only way to trigger the redrawing on earlier systems is to call
1678 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1679 UInt32 currentEventClass
= 0 ;
1680 if ( currentEvent
!= NULL
)
1682 currentEventClass
= ::GetEventClass( currentEvent
) ;
1683 ::GetEventKind( currentEvent
) ;
1686 if ( currentEventClass
!= kEventClassMenu
)
1688 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1690 ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1695 // Attracts the users attention to this window if the application is
1696 // inactive (should be called when a background event occurs)
1698 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1701 DisposePtr( (Ptr
)ptr
) ;
1704 void wxTopLevelWindowMac::RequestUserAttention(int WXUNUSED(flags
))
1706 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1707 static wxMacNMUPP
nmupp( wxMacNMResponse
);
1709 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1710 notificationRequest
->qType
= nmType
;
1711 notificationRequest
->nmMark
= 1 ;
1712 notificationRequest
->nmIcon
= 0 ;
1713 notificationRequest
->nmSound
= 0 ;
1714 notificationRequest
->nmStr
= NULL
;
1715 notificationRequest
->nmResp
= nmupp
;
1717 verify_noerr( NMInstall( notificationRequest
) ) ;
1720 // ---------------------------------------------------------------------------
1721 // Shape implementation
1722 // ---------------------------------------------------------------------------
1725 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1727 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1728 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1730 // The empty region signifies that the shape
1731 // should be removed from the window.
1732 if ( region
.IsEmpty() )
1734 wxSize sz
= GetClientSize();
1735 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1736 if ( rgn
.IsEmpty() )
1739 return SetShape(rgn
);
1742 // Make a copy of the region
1743 RgnHandle shapeRegion
= NewRgn();
1744 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1746 // Dispose of any shape region we may already have
1747 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1751 // Save the region so we can use it later
1752 SetWRefCon((WindowRef
)MacGetWindowRef(), (URefCon
)shapeRegion
);
1754 // inform the window manager that the window has changed shape
1755 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1760 // ---------------------------------------------------------------------------
1761 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1762 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1763 // ---------------------------------------------------------------------------
1765 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1767 GetWindowPortBounds(window
, inRect
);
1768 Point pt
= { inRect
->top
,inRect
->left
};
1769 wxMacLocalToGlobal( window
, &pt
) ;
1770 inRect
->bottom
+= pt
.v
- inRect
->top
;
1771 inRect
->right
+= pt
.h
- inRect
->left
;
1773 inRect
->left
= pt
.h
;
1776 static SInt32
wxShapedMacWindowGetFeatures(WindowRef
WXUNUSED(window
), SInt32 param
)
1778 /*------------------------------------------------------
1779 Define which options your custom window supports.
1780 --------------------------------------------------------*/
1781 //just enable everything for our demo
1782 *(OptionBits
*)param
=
1785 //kWindowCanCollapse |
1786 //kWindowCanGetWindowRegion |
1787 //kWindowHasTitleBar |
1788 //kWindowSupportsDragHilite |
1789 kWindowCanDrawInCurrentPort
|
1790 //kWindowCanMeasureTitle |
1791 kWindowWantsDisposeAtProcessDeath
|
1792 kWindowSupportsGetGrowImageRegion
|
1793 kWindowDefSupportsColorGrafPort
;
1798 // The content region is left as a rectangle matching the window size, this is
1799 // so the origin in the paint event, and etc. still matches what the
1800 // programmer expects.
1801 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1804 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1808 wxShapedMacWindowGetPos( window
, &r
) ;
1809 RectRgn( rgn
, &r
) ;
1813 // The structure region is set to the shape given to the SetShape method.
1814 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1816 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1822 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1823 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1824 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1825 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1829 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1831 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1836 switch (rgnRec
->regionCode
)
1838 case kWindowStructureRgn
:
1839 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1842 case kWindowContentRgn
:
1843 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1847 SetEmptyRgn(rgnRec
->winRgn
);
1854 // Determine the region of the window which was hit
1856 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1859 static RgnHandle tempRgn
= NULL
;
1861 if (tempRgn
== NULL
)
1864 // get the point clicked
1865 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1867 // Mac OS 8.5 or later
1868 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1869 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1872 // no significant area was hit
1876 static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode
), WindowRef window
, SInt16 message
, SInt32 param
)
1880 case kWindowMsgHitTest
:
1881 return wxShapedMacWindowHitTest(window
, param
);
1883 case kWindowMsgGetFeatures
:
1884 return wxShapedMacWindowGetFeatures(window
, param
);
1886 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1887 case kWindowMsgGetRegion
:
1888 return wxShapedMacWindowGetRegion(window
, param
);