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
.SetTimestamp( cEvent
.GetTicks() ) ;
277 // a control click is interpreted as a right click
278 bool thisButtonIsFakeRight
= false ;
279 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
281 button
= kEventMouseButtonSecondary
;
282 thisButtonIsFakeRight
= true ;
284 // otherwise we report double clicks by connecting a left click with a ctrl-left click
285 if ( clickCount
> 1 && button
!= g_lastButton
)
288 // we must make sure that our synthetic 'right' button corresponds in
289 // mouse down, moved and mouse up, and does not deliver a right down and left up
291 if ( cEvent
.GetKind() == kEventMouseDown
)
293 g_lastButton
= button
;
294 g_lastButtonWasFakeRight
= thisButtonIsFakeRight
;
300 g_lastButtonWasFakeRight
= false ;
302 else if ( g_lastButton
== kEventMouseButtonSecondary
&& g_lastButtonWasFakeRight
)
303 button
= g_lastButton
;
305 // determine the correct down state, wx does not want a 'down' for a mouseUp event,
306 // while mac delivers this button
307 if ( button
!= 0 && cEvent
.GetKind() != kEventMouseUp
)
311 case kEventMouseButtonPrimary
:
312 wxevent
.m_leftDown
= true ;
315 case kEventMouseButtonSecondary
:
316 wxevent
.m_rightDown
= true ;
319 case kEventMouseButtonTertiary
:
320 wxevent
.m_middleDown
= true ;
328 // translate into wx types
329 switch ( cEvent
.GetKind() )
331 case kEventMouseDown
:
334 case kEventMouseButtonPrimary
:
335 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
338 case kEventMouseButtonSecondary
:
339 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
342 case kEventMouseButtonTertiary
:
343 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
354 case kEventMouseButtonPrimary
:
355 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
358 case kEventMouseButtonSecondary
:
359 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
362 case kEventMouseButtonTertiary
:
363 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
371 case kEventMouseWheelMoved
:
373 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
375 EventMouseWheelAxis axis
= cEvent
.GetParameter
<EventMouseWheelAxis
>(kEventParamMouseWheelAxis
, typeMouseWheelAxis
) ;
376 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeSInt32
) ;
378 wxevent
.m_wheelRotation
= delta
;
379 wxevent
.m_wheelDelta
= 1;
380 wxevent
.m_linesPerAction
= 1;
381 if ( axis
== kEventMouseWheelAxisX
)
382 wxevent
.m_wheelAxis
= 1;
387 wxevent
.SetEventType( wxEVT_MOTION
) ;
392 ControlRef
wxMacFindSubControl( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, ControlRef superControl
, ControlPartCode
*outPart
)
396 UInt16 childrenCount
= 0 ;
397 ControlHandle sibling
;
399 OSStatus err
= CountSubControls( superControl
, &childrenCount
) ;
400 if ( err
== errControlIsNotEmbedder
)
403 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
405 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
407 err
= GetIndexedSubControl( superControl
, i
, & sibling
) ;
408 if ( err
== errControlIsNotEmbedder
)
411 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
412 if ( IsControlVisible( sibling
) )
414 UMAGetControlBoundsInWindowCoords( sibling
, &r
) ;
415 if ( MacPtInRect( location
, &r
) )
417 ControlHandle child
= wxMacFindSubControl( toplevelWindow
, location
, sibling
, outPart
) ;
424 Point testLocation
= location
;
426 if ( toplevelWindow
)
428 testLocation
.h
-= r
.left
;
429 testLocation
.v
-= r
.top
;
432 *outPart
= TestControl( sibling
, testLocation
) ;
444 ControlRef
wxMacFindControlUnderMouse( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, WindowRef window
, ControlPartCode
*outPart
)
446 #if TARGET_API_MAC_OSX
447 if ( UMAGetSystemVersion() >= 0x1030 )
448 return FindControlUnderMouse( location
, window
, outPart
) ;
451 ControlRef rootControl
= NULL
;
452 verify_noerr( GetRootControl( window
, &rootControl
) ) ;
454 return wxMacFindSubControl( toplevelWindow
, location
, rootControl
, outPart
) ;
457 #define NEW_CAPTURE_HANDLING 1
459 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
461 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
463 OSStatus result
= eventNotHandledErr
;
465 wxMacCarbonEvent
cEvent( event
) ;
467 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
468 Point windowMouseLocation
= screenMouseLocation
;
470 WindowRef window
= NULL
;
471 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
473 wxWindow
* currentMouseWindow
= NULL
;
474 ControlRef control
= NULL
;
476 #if NEW_CAPTURE_HANDLING
477 if ( wxApp::s_captureWindow
)
479 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
480 windowPart
= inContent
;
486 wxMacGlobalToLocal( window
, &windowMouseLocation
) ;
488 if ( wxApp::s_captureWindow
489 #if !NEW_CAPTURE_HANDLING
490 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
494 currentMouseWindow
= wxApp::s_captureWindow
;
496 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
498 ControlPartCode part
;
499 control
= wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &part
) ;
500 // if there is no control below the mouse position, send the event to the toplevel window itself
503 currentMouseWindow
= (wxWindow
*) data
;
507 currentMouseWindow
= wxFindControlFromMacControl( control
) ;
508 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
511 // for wxToolBar to function we have to send certaint events to it
512 // instead of its children (wxToolBarTools)
514 GetSuperControl(control
, &parent
);
515 wxWindow
*wxParent
= wxFindControlFromMacControl( parent
) ;
516 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
517 currentMouseWindow
= wxParent
;
522 // disabled windows must not get any input messages
523 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
524 currentMouseWindow
= NULL
;
528 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
529 SetupMouseEvent( wxevent
, cEvent
) ;
531 // handle all enter / leave events
533 if ( currentMouseWindow
!= g_MacLastWindow
)
535 if ( g_MacLastWindow
)
537 wxMouseEvent
eventleave(wxevent
);
538 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
539 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
540 eventleave
.SetEventObject( g_MacLastWindow
) ;
541 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
544 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
547 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
550 if ( currentMouseWindow
)
552 wxMouseEvent
evententer(wxevent
);
553 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
554 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
555 evententer
.SetEventObject( currentMouseWindow
) ;
556 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
559 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
562 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
565 g_MacLastWindow
= currentMouseWindow
;
568 if ( windowPart
== inMenuBar
)
570 // special case menu bar, as we are having a low-level runloop we must do it ourselves
571 if ( cEvent
.GetKind() == kEventMouseDown
)
573 ::MenuSelect( screenMouseLocation
) ;
577 else if ( currentMouseWindow
)
579 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
581 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
583 wxevent
.SetEventObject( currentMouseWindow
) ;
584 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
586 // make tooltips current
589 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
590 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
593 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
595 if ((currentMouseWindowParent
!= NULL
) &&
596 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
597 currentMouseWindow
= NULL
;
603 // if the user code did _not_ handle the event, then perform the
604 // default processing
605 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
607 // ... that is set focus to this window
608 if (currentMouseWindow
->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
609 currentMouseWindow
->SetFocus();
612 ControlPartCode dummyPart
;
613 // if built-in find control is finding the wrong control (ie static box instead of overlaid
614 // button, we cannot let the standard handler do its job, but must handle manually
616 if ( ( cEvent
.GetKind() == kEventMouseDown
)
619 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
620 wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &dummyPart
) )
624 if ( currentMouseWindow
->MacIsReallyEnabled() )
626 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
627 Point clickLocation
= windowMouseLocation
;
629 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
631 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
632 modifiers
, (ControlActionUPP
) -1 ) ;
634 if ((currentMouseWindowParent
!= NULL
) &&
635 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
637 currentMouseWindow
= NULL
;
645 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
647 wxApp::s_captureWindow
= NULL
;
653 wxWindow
* cursorTarget
= currentMouseWindow
;
654 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
656 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
658 cursorTarget
= cursorTarget
->GetParent() ;
660 cursorPoint
+= cursorTarget
->GetPosition();
664 else // currentMouseWindow == NULL
666 // don't mess with controls we don't know about
667 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
668 // so we try sending them the correct control directly
669 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
671 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
672 Point clickLocation
= windowMouseLocation
;
673 #if TARGET_API_MAC_OSX
675 hiPoint
.x
= clickLocation
.h
;
676 hiPoint
.y
= clickLocation
.v
;
677 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
678 clickLocation
.h
= (int)hiPoint
.x
;
679 clickLocation
.v
= (int)hiPoint
.y
;
680 #endif // TARGET_API_MAC_OSX
682 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
690 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
692 OSStatus result
= eventNotHandledErr
;
694 wxMacCarbonEvent
cEvent( event
) ;
696 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
697 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
699 switch ( GetEventKind( event
) )
701 case kEventWindowActivated
:
703 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
704 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
705 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
706 wxevent
.SetEventObject(toplevelWindow
);
707 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
708 // we still sending an eventNotHandledErr in order to allow for default processing
712 case kEventWindowDeactivated
:
714 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
715 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
716 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
717 wxevent
.SetEventObject(toplevelWindow
);
718 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
719 // we still sending an eventNotHandledErr in order to allow for default processing
723 case kEventWindowShown
:
724 toplevelWindow
->Refresh() ;
728 case kEventWindowClose
:
729 toplevelWindow
->Close() ;
733 case kEventWindowBoundsChanged
:
735 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
736 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
737 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
738 if ( attributes
& kWindowBoundsChangeSizeChanged
)
740 // according to the other ports we handle this within the OS level
741 // resize event, not within a wxSizeEvent
742 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
745 frame
->PositionBars();
748 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
749 event
.SetEventObject( toplevelWindow
) ;
751 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
752 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
755 if ( attributes
& kWindowBoundsChangeOriginChanged
)
757 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
758 event
.SetEventObject( toplevelWindow
) ;
759 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
766 case kEventWindowBoundsChanging
:
768 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
769 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
771 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
773 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
774 int left
, top
, right
, bottom
;
775 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
780 newRect
.right
- newRect
.left
+ left
+ right
,
781 newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
783 // this is a EVT_SIZING not a EVT_SIZE type !
784 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
785 wxevent
.SetEventObject( toplevelWindow
) ;
787 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
788 adjustR
= wxevent
.GetRect() ;
790 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
791 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
792 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
793 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
794 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
795 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
796 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
797 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
798 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
799 if ( !EqualRect( &newRect
, &adjustedRect
) )
800 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
801 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
808 case kEventWindowGetRegion
:
810 if ( toplevelWindow
->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
812 WindowRegionCode windowRegionCode
;
814 // Fetch the region code that is being queried
815 GetEventParameter( event
,
816 kEventParamWindowRegionCode
,
817 typeWindowRegionCode
, NULL
,
818 sizeof windowRegionCode
, NULL
,
819 &windowRegionCode
) ;
821 // If it is the opaque region code then set the
822 // region to empty and return noErr to stop event
824 if ( windowRegionCode
== kWindowOpaqueRgn
) {
826 GetEventParameter( event
,
827 kEventParamRgnHandle
,
828 typeQDRgnHandle
, NULL
,
831 SetEmptyRgn(region
) ;
845 // mix this in from window.cpp
846 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
848 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
850 OSStatus result
= eventNotHandledErr
;
852 switch ( GetEventClass( event
) )
854 case kEventClassTextInput
:
855 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
858 case kEventClassKeyboard
:
859 result
= KeyboardEventHandler( handler
, event
, data
) ;
862 case kEventClassWindow
:
863 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
866 case kEventClassMouse
:
867 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
877 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
879 // ---------------------------------------------------------------------------
880 // wxWindowMac utility functions
881 // ---------------------------------------------------------------------------
883 // Find an item given the Macintosh Window Reference
885 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
887 static MacWindowMap wxWinMacWindowList
;
889 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
891 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
893 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
896 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
897 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
899 // adding NULL WindowRef is (first) surely a result of an error and
901 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
903 wxWinMacWindowList
[inWindowRef
] = win
;
906 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
907 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
909 MacWindowMap::iterator it
;
910 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
912 if ( it
->second
== win
)
914 wxWinMacWindowList
.erase(it
);
920 // ----------------------------------------------------------------------------
921 // wxTopLevelWindowMac creation
922 // ----------------------------------------------------------------------------
924 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
930 bool m_wasResizable
;
933 void wxTopLevelWindowMac::Init()
936 m_maximizeOnShow
= false;
939 m_macEventHandler
= NULL
;
940 m_macFullScreenData
= NULL
;
943 class wxMacDeferredWindowDeleter
: public wxObject
946 wxMacDeferredWindowDeleter( WindowRef windowRef
)
948 m_macWindow
= windowRef
;
951 virtual ~wxMacDeferredWindowDeleter()
953 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
957 WindowRef m_macWindow
;
960 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
962 const wxString
& title
,
966 const wxString
& name
)
971 m_windowStyle
= style
;
975 m_windowId
= id
== -1 ? NewControlId() : id
;
976 wxWindow::SetLabel( title
) ;
978 MacCreateRealWindow( title
, pos
, size
, style
, name
) ;
980 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
982 if (GetExtraStyle() & wxFRAME_EX_METAL
)
983 MacSetMetalAppearance(true);
985 wxTopLevelWindows
.Append(this);
988 parent
->AddChild(this);
993 wxTopLevelWindowMac::~wxTopLevelWindowMac()
998 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
1000 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
1003 if ( m_macEventHandler
)
1005 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1006 m_macEventHandler
= NULL
;
1009 wxRemoveMacWindowAssociation( this ) ;
1011 if ( wxModelessWindows
.Find(this) )
1012 wxModelessWindows
.DeleteObject(this);
1014 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1016 m_macFullScreenData
= NULL
;
1018 // avoid dangling refs
1019 if ( s_macDeactivateWindow
== this )
1020 s_macDeactivateWindow
= NULL
;
1024 // ----------------------------------------------------------------------------
1025 // wxTopLevelWindowMac maximize/minimize
1026 // ----------------------------------------------------------------------------
1028 void wxTopLevelWindowMac::Maximize(bool maximize
)
1030 Point idealSize
= { 0 , 0 } ;
1033 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1035 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
1037 idealSize
.h
= bounds
.size
.width
;
1038 idealSize
.v
= bounds
.size
.height
;
1041 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
1042 idealSize
.h
= rect
.right
- rect
.left
;
1043 idealSize
.v
= rect
.bottom
- rect
.top
;
1046 ZoomWindowIdeal( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
1049 bool wxTopLevelWindowMac::IsMaximized() const
1051 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
1054 void wxTopLevelWindowMac::Iconize(bool iconize
)
1056 if ( IsWindowCollapsable( (WindowRef
)m_macWindow
) )
1057 CollapseWindow( (WindowRef
)m_macWindow
, iconize
) ;
1060 bool wxTopLevelWindowMac::IsIconized() const
1062 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1065 void wxTopLevelWindowMac::Restore()
1067 if ( IsMaximized() )
1069 else if ( IsIconized() )
1073 // ----------------------------------------------------------------------------
1074 // wxTopLevelWindowMac misc
1075 // ----------------------------------------------------------------------------
1077 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1079 return wxPoint(0, 0) ;
1082 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1084 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1086 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1088 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1092 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1094 if ( m_macEventHandler
!= NULL
)
1096 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1099 InstallWindowEventHandler(
1100 MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1101 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1104 void wxTopLevelWindowMac::MacCreateRealWindow(
1105 const wxString
& title
,
1109 const wxString
& name
)
1111 OSStatus err
= noErr
;
1113 m_windowStyle
= style
;
1121 wxRect display
= wxGetClientDisplayRect() ;
1123 if ( x
== wxDefaultPosition
.x
)
1126 if ( y
== wxDefaultPosition
.y
)
1129 int w
= WidthDefault(size
.x
);
1130 int h
= HeightDefault(size
.y
);
1132 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1134 // translate the window attributes in the appropriate window class and attributes
1135 WindowClass wclass
= 0;
1136 WindowAttributes attr
= kWindowNoAttributes
;
1137 WindowGroupRef group
= NULL
;
1139 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1142 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1143 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1144 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1147 wclass
= kFloatingWindowClass
;
1149 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1150 attr
|= kWindowSideTitlebarAttribute
;
1154 wclass
= kPlainWindowClass
;
1157 else if ( HasFlag( wxPOPUP_WINDOW
) )
1160 // Until we've got a real wxPopupWindow class on wxMac make it a
1161 // little easier for wxFrame to be used to emulate it and workaround
1162 // the lack of wxPopupWindow.
1163 if ( HasFlag( wxBORDER_NONE
) )
1164 wclass
= kHelpWindowClass
; // has no border
1166 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1167 //attr |= kWindowNoShadowAttribute; // turn off the shadow Should we??
1168 group
= GetWindowGroupOfClass( // float above other windows
1169 kFloatingWindowClass
) ;
1171 else if ( HasFlag( wxCAPTION
) )
1173 wclass
= kDocumentWindowClass
;
1174 attr
|= kWindowInWindowMenuAttribute
;
1176 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1177 else if ( HasFlag( wxFRAME_DRAWER
) )
1179 wclass
= kDrawerWindowClass
;
1181 #endif //10.2 and up
1184 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1185 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1187 wclass
= kDocumentWindowClass
;
1191 wclass
= kPlainWindowClass
;
1195 if ( wclass
!= kPlainWindowClass
)
1197 if ( HasFlag( wxMINIMIZE_BOX
) )
1198 attr
|= kWindowCollapseBoxAttribute
;
1200 if ( HasFlag( wxMAXIMIZE_BOX
) )
1201 attr
|= kWindowFullZoomAttribute
;
1203 if ( HasFlag( wxRESIZE_BORDER
) )
1204 attr
|= kWindowResizableAttribute
;
1206 if ( HasFlag( wxCLOSE_BOX
) )
1207 attr
|= kWindowCloseBoxAttribute
;
1210 // turn on live resizing (OS X only)
1211 if (UMAGetSystemVersion() >= 0x1000)
1212 attr
|= kWindowLiveResizeAttribute
;
1214 if ( HasFlag(wxSTAY_ON_TOP
) )
1215 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1217 if ( HasFlag( wxFRAME_FLOAT_ON_PARENT
) )
1218 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1220 attr
|= kWindowCompositingAttribute
;
1221 #if 0 // wxMAC_USE_CORE_GRAPHICS ; TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1222 attr
|= kWindowFrameworkScaledAttribute
;
1225 if ( HasFlag(wxFRAME_SHAPED
) )
1227 WindowDefSpec customWindowDefSpec
;
1228 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1229 customWindowDefSpec
.u
.defProc
=
1231 (WindowDefUPP
) wxShapedMacWindowDef
;
1233 NewWindowDefUPP(wxShapedMacWindowDef
);
1235 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1236 attr
, &theBoundsRect
,
1237 (WindowRef
*) &m_macWindow
);
1241 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1244 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1245 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1247 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1249 // setup a separate group for each window, so that overlays can be handled easily
1250 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &group
));
1251 verify_noerr( SetWindowGroupParent( group
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1252 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, group
));
1254 // the create commands are only for content rect,
1255 // so we have to set the size again as structure bounds
1256 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1258 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1259 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1260 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1262 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1263 // the content view, so we have to retrieve it explicitly
1264 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1265 m_peer
->GetControlRefAddr() ) ;
1266 if ( !m_peer
->Ok() )
1268 // compatibility mode fallback
1269 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1272 // the root control level handler
1273 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1275 // Causes the inner part of the window not to be metal
1276 // if the style is used before window creation.
1277 #if 0 // TARGET_API_MAC_OSX
1278 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1280 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1281 MacSetMetalAppearance( true ) ;
1285 #if TARGET_API_MAC_OSX
1286 if ( m_macWindow
!= NULL
)
1288 MacSetUnifiedAppearance( true ) ;
1292 // the frame window event handler
1293 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1294 MacInstallTopLevelWindowEventHandler() ;
1296 DoSetWindowVariant( m_windowVariant
) ;
1300 if ( HasFlag(wxFRAME_SHAPED
) )
1302 // default shape matches the window size
1303 wxRegion
rgn( 0, 0, w
, h
);
1307 wxWindowCreateEvent
event(this);
1308 GetEventHandler()->ProcessEvent(event
);
1311 void wxTopLevelWindowMac::ClearBackground()
1313 wxWindow::ClearBackground() ;
1316 // Raise the window to the top of the Z order
1317 void wxTopLevelWindowMac::Raise()
1319 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1322 // Lower the window to the bottom of the Z order
1323 void wxTopLevelWindowMac::Lower()
1325 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1328 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1330 if (s_macDeactivateWindow
)
1332 wxLogTrace(TRACE_ACTIVATE
,
1333 wxT("Doing delayed deactivation of %p"),
1334 s_macDeactivateWindow
);
1336 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1340 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1342 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1344 if (s_macDeactivateWindow
== this)
1345 s_macDeactivateWindow
= NULL
;
1347 MacDelayedDeactivation(timestamp
);
1348 MacPropagateHiliteChanged() ;
1351 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1353 wxWindow::SetLabel( title
) ;
1354 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1357 wxString
wxTopLevelWindowMac::GetTitle() const
1359 return wxWindow::GetLabel();
1362 bool wxTopLevelWindowMac::Show(bool show
)
1364 if ( !wxTopLevelWindowBase::Show(show
) )
1367 bool plainTransition
= false;
1369 #if wxUSE_SYSTEM_OPTIONS
1370 // code contributed by Ryan Wilcox December 18, 2003
1371 plainTransition
= UMAGetSystemVersion() >= 0x1000 ;
1372 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1373 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1378 if ( plainTransition
)
1379 ::ShowWindow( (WindowRef
)m_macWindow
);
1381 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1383 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1385 // because apps expect a size event to occur at this moment
1386 wxSizeEvent
event(GetSize() , m_windowId
);
1387 event
.SetEventObject(this);
1388 GetEventHandler()->ProcessEvent(event
);
1392 if ( plainTransition
)
1393 ::HideWindow( (WindowRef
)m_macWindow
);
1395 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1398 MacPropagateVisibilityChanged() ;
1403 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1407 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1409 data
= new FullScreenData() ;
1411 m_macFullScreenData
= data
;
1412 data
->m_position
= GetPosition() ;
1413 data
->m_size
= GetSize() ;
1414 data
->m_wasResizable
= MacGetWindowAttributes() & kWindowResizableAttribute
;
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
) ;
1455 if ( data
->m_wasResizable
)
1456 MacChangeWindowAttributes( kWindowNoAttributes
, kWindowResizableAttribute
) ;
1461 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1462 if ( data
->m_wasResizable
)
1463 MacChangeWindowAttributes( kWindowResizableAttribute
, kWindowNoAttributes
) ;
1464 SetPosition( data
->m_position
) ;
1465 SetSize( data
->m_size
) ;
1468 m_macFullScreenData
= NULL
;
1474 bool wxTopLevelWindowMac::IsFullScreen() const
1476 return m_macFullScreenData
!= NULL
;
1480 bool wxTopLevelWindowMac::SetTransparent(wxByte alpha
)
1482 OSStatus result
= SetWindowAlpha((WindowRef
)m_macWindow
, float(alpha
)/255.0);
1483 return result
== noErr
;
1487 bool wxTopLevelWindowMac::CanSetTransparent()
1493 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1495 if ( GetExtraStyle() == exStyle
)
1498 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1500 #if TARGET_API_MAC_OSX
1501 if ( m_macWindow
!= NULL
)
1503 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1505 if ( MacGetMetalAppearance() != metal
)
1507 if ( MacGetUnifiedAppearance() )
1508 MacSetUnifiedAppearance( !metal
) ;
1510 MacSetMetalAppearance( metal
) ;
1516 bool wxTopLevelWindowMac::SetBackgroundStyle(wxBackgroundStyle style
)
1518 if ( !wxTopLevelWindowBase::SetBackgroundStyle(style
) )
1521 WindowRef windowRef
= HIViewGetWindow( (HIViewRef
)GetHandle() );
1523 if ( GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
1525 OSStatus err
= HIWindowChangeFeatures( windowRef
, 0, kWindowIsOpaque
);
1526 verify_noerr( err
);
1527 err
= ReshapeCustomWindow( windowRef
);
1528 verify_noerr( err
);
1534 // TODO: switch to structure bounds -
1535 // we are still using coordinates of the content view
1537 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1539 Rect content
, structure
;
1541 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1542 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1544 left
= content
.left
- structure
.left
;
1545 top
= content
.top
- structure
.top
;
1546 right
= structure
.right
- content
.right
;
1547 bottom
= structure
.bottom
- content
.bottom
;
1550 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1552 m_cachedClippedRectValid
= false ;
1553 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1554 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1555 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1558 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1562 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1570 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1574 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1577 *width
= bounds
.right
- bounds
.left
;
1579 *height
= bounds
.bottom
- bounds
.top
;
1582 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1586 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1589 *width
= bounds
.right
- bounds
.left
;
1591 *height
= bounds
.bottom
- bounds
.top
;
1594 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1596 #if TARGET_API_MAC_OSX
1597 if ( MacGetUnifiedAppearance() )
1598 MacSetUnifiedAppearance( false ) ;
1600 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1601 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1605 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1607 #if TARGET_API_MAC_OSX
1608 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1614 void wxTopLevelWindowMac::MacSetUnifiedAppearance( bool set
)
1616 #if TARGET_API_MAC_OSX
1617 if ( UMAGetSystemVersion() >= 0x1040 )
1619 if ( MacGetMetalAppearance() )
1620 MacSetMetalAppearance( false ) ;
1622 MacChangeWindowAttributes( set
? kWindowUnifiedTitleAndToolbarAttribute
: kWindowNoAttributes
,
1623 set
? kWindowNoAttributes
: kWindowUnifiedTitleAndToolbarAttribute
) ;
1625 // For some reason, Tiger uses white as the background color for this appearance,
1626 // while most apps using it use the typical striped background. Restore that behavior
1628 // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
1630 SetBackgroundColour( wxSYS_COLOUR_WINDOW
) ;
1635 bool wxTopLevelWindowMac::MacGetUnifiedAppearance() const
1637 #if TARGET_API_MAC_OSX
1638 if ( UMAGetSystemVersion() >= 0x1040 )
1639 return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute
;
1645 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1647 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1650 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1653 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1658 void wxTopLevelWindowMac::MacPerformUpdates()
1660 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1661 // for composited windows this also triggers a redraw of all
1662 // invalid views in the window
1663 if ( UMAGetSystemVersion() >= 0x1030 )
1664 HIWindowFlush((WindowRef
) m_macWindow
) ;
1668 // the only way to trigger the redrawing on earlier systems is to call
1671 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1672 UInt32 currentEventClass
= 0 ;
1673 if ( currentEvent
!= NULL
)
1675 currentEventClass
= ::GetEventClass( currentEvent
) ;
1676 ::GetEventKind( currentEvent
) ;
1679 if ( currentEventClass
!= kEventClassMenu
)
1681 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1683 ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1688 // Attracts the users attention to this window if the application is
1689 // inactive (should be called when a background event occurs)
1691 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1694 DisposePtr( (Ptr
)ptr
) ;
1697 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1699 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1700 static wxMacNMUPP
nmupp( wxMacNMResponse
);
1702 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1703 notificationRequest
->qType
= nmType
;
1704 notificationRequest
->nmMark
= 1 ;
1705 notificationRequest
->nmIcon
= 0 ;
1706 notificationRequest
->nmSound
= 0 ;
1707 notificationRequest
->nmStr
= NULL
;
1708 notificationRequest
->nmResp
= nmupp
;
1710 verify_noerr( NMInstall( notificationRequest
) ) ;
1713 // ---------------------------------------------------------------------------
1714 // Shape implementation
1715 // ---------------------------------------------------------------------------
1718 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1720 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1721 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1723 // The empty region signifies that the shape
1724 // should be removed from the window.
1725 if ( region
.IsEmpty() )
1727 wxSize sz
= GetClientSize();
1728 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1729 if ( rgn
.IsEmpty() )
1732 return SetShape(rgn
);
1735 // Make a copy of the region
1736 RgnHandle shapeRegion
= NewRgn();
1737 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1739 // Dispose of any shape region we may already have
1740 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1744 // Save the region so we can use it later
1745 SetWRefCon((WindowRef
)MacGetWindowRef(), (URefCon
)shapeRegion
);
1747 // inform the window manager that the window has changed shape
1748 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1753 // ---------------------------------------------------------------------------
1754 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1755 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1756 // ---------------------------------------------------------------------------
1758 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1760 GetWindowPortBounds(window
, inRect
);
1761 Point pt
= { inRect
->top
,inRect
->left
};
1762 wxMacLocalToGlobal( window
, &pt
) ;
1763 inRect
->bottom
+= pt
.v
- inRect
->top
;
1764 inRect
->right
+= pt
.h
- inRect
->left
;
1766 inRect
->left
= pt
.h
;
1769 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1771 /*------------------------------------------------------
1772 Define which options your custom window supports.
1773 --------------------------------------------------------*/
1774 //just enable everything for our demo
1775 *(OptionBits
*)param
=
1778 //kWindowCanCollapse |
1779 //kWindowCanGetWindowRegion |
1780 //kWindowHasTitleBar |
1781 //kWindowSupportsDragHilite |
1782 kWindowCanDrawInCurrentPort
|
1783 //kWindowCanMeasureTitle |
1784 kWindowWantsDisposeAtProcessDeath
|
1785 kWindowSupportsGetGrowImageRegion
|
1786 kWindowDefSupportsColorGrafPort
;
1791 // The content region is left as a rectangle matching the window size, this is
1792 // so the origin in the paint event, and etc. still matches what the
1793 // programmer expects.
1794 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1797 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1801 wxShapedMacWindowGetPos( window
, &r
) ;
1802 RectRgn( rgn
, &r
) ;
1806 // The structure region is set to the shape given to the SetShape method.
1807 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1809 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1815 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1816 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1817 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1818 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1822 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1824 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1829 switch (rgnRec
->regionCode
)
1831 case kWindowStructureRgn
:
1832 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1835 case kWindowContentRgn
:
1836 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1840 SetEmptyRgn(rgnRec
->winRgn
);
1847 // Determine the region of the window which was hit
1849 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1852 static RgnHandle tempRgn
= NULL
;
1854 if (tempRgn
== NULL
)
1857 // get the point clicked
1858 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1860 // Mac OS 8.5 or later
1861 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1862 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1865 // no significant area was hit
1869 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1873 case kWindowMsgHitTest
:
1874 return wxShapedMacWindowHitTest(window
, param
);
1876 case kWindowMsgGetFeatures
:
1877 return wxShapedMacWindowGetFeatures(window
, param
);
1879 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1880 case kWindowMsgGetRegion
:
1881 return wxShapedMacWindowGetRegion(window
, param
);