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
460 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
462 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
464 OSStatus result
= eventNotHandledErr
;
466 wxMacCarbonEvent
cEvent( event
) ;
468 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
469 Point windowMouseLocation
= screenMouseLocation
;
471 WindowRef window
= NULL
;
472 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
474 wxWindow
* currentMouseWindow
= NULL
;
475 ControlRef control
= NULL
;
477 #if NEW_CAPTURE_HANDLING
478 if ( wxApp::s_captureWindow
)
480 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
481 windowPart
= inContent
;
487 wxMacGlobalToLocal( window
, &windowMouseLocation
) ;
489 if ( wxApp::s_captureWindow
490 #if !NEW_CAPTURE_HANDLING
491 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
495 currentMouseWindow
= wxApp::s_captureWindow
;
497 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
499 ControlPartCode part
;
500 control
= wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &part
) ;
501 // if there is no control below the mouse position, send the event to the toplevel window itself
504 currentMouseWindow
= (wxWindow
*) data
;
508 currentMouseWindow
= wxFindControlFromMacControl( control
) ;
509 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
512 // for wxToolBar to function we have to send certaint events to it
513 // instead of its children (wxToolBarTools)
515 GetSuperControl(control
, &parent
);
516 wxWindow
*wxParent
= wxFindControlFromMacControl( parent
) ;
517 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
518 currentMouseWindow
= wxParent
;
523 // disabled windows must not get any input messages
524 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
525 currentMouseWindow
= NULL
;
529 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
530 SetupMouseEvent( wxevent
, cEvent
) ;
532 // handle all enter / leave events
534 if ( currentMouseWindow
!= g_MacLastWindow
)
536 if ( g_MacLastWindow
)
538 wxMouseEvent
eventleave(wxevent
);
539 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
540 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
541 eventleave
.SetEventObject( g_MacLastWindow
) ;
542 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
545 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
548 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
551 if ( currentMouseWindow
)
553 wxMouseEvent
evententer(wxevent
);
554 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
555 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
556 evententer
.SetEventObject( currentMouseWindow
) ;
557 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
560 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
563 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
566 g_MacLastWindow
= currentMouseWindow
;
569 if ( windowPart
== inMenuBar
)
571 // special case menu bar, as we are having a low-level runloop we must do it ourselves
572 if ( cEvent
.GetKind() == kEventMouseDown
)
574 ::MenuSelect( screenMouseLocation
) ;
578 else if ( currentMouseWindow
)
580 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
582 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
584 wxevent
.SetEventObject( currentMouseWindow
) ;
585 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
587 // make tooltips current
590 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
591 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
594 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
596 if ((currentMouseWindowParent
!= NULL
) &&
597 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
598 currentMouseWindow
= NULL
;
604 // if the user code did _not_ handle the event, then perform the
605 // default processing
606 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
608 // ... that is set focus to this window
609 if (currentMouseWindow
->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
610 currentMouseWindow
->SetFocus();
613 ControlPartCode dummyPart
;
614 // if built-in find control is finding the wrong control (ie static box instead of overlaid
615 // button, we cannot let the standard handler do its job, but must handle manually
617 if ( ( cEvent
.GetKind() == kEventMouseDown
)
620 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
621 wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &dummyPart
) )
625 if ( currentMouseWindow
->MacIsReallyEnabled() )
627 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
628 Point clickLocation
= windowMouseLocation
;
630 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
632 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
633 modifiers
, (ControlActionUPP
) -1 ) ;
635 if ((currentMouseWindowParent
!= NULL
) &&
636 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
638 currentMouseWindow
= NULL
;
646 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
648 wxApp::s_captureWindow
= NULL
;
654 wxWindow
* cursorTarget
= currentMouseWindow
;
655 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
657 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
659 cursorTarget
= cursorTarget
->GetParent() ;
661 cursorPoint
+= cursorTarget
->GetPosition();
665 else // currentMouseWindow == NULL
667 // don't mess with controls we don't know about
668 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
669 // so we try sending them the correct control directly
670 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
672 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
673 Point clickLocation
= windowMouseLocation
;
674 #if TARGET_API_MAC_OSX
676 hiPoint
.x
= clickLocation
.h
;
677 hiPoint
.y
= clickLocation
.v
;
678 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
679 clickLocation
.h
= (int)hiPoint
.x
;
680 clickLocation
.v
= (int)hiPoint
.y
;
681 #endif // TARGET_API_MAC_OSX
683 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
691 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
693 OSStatus result
= eventNotHandledErr
;
695 wxMacCarbonEvent
cEvent( event
) ;
697 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
698 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
700 switch ( GetEventKind( event
) )
702 case kEventWindowActivated
:
704 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
705 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
706 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
707 wxevent
.SetEventObject(toplevelWindow
);
708 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
709 // we still sending an eventNotHandledErr in order to allow for default processing
713 case kEventWindowDeactivated
:
715 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
716 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
717 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
718 wxevent
.SetEventObject(toplevelWindow
);
719 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
720 // we still sending an eventNotHandledErr in order to allow for default processing
724 case kEventWindowShown
:
725 toplevelWindow
->Refresh() ;
729 case kEventWindowClose
:
730 toplevelWindow
->Close() ;
734 case kEventWindowBoundsChanged
:
736 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
737 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
738 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
739 if ( attributes
& kWindowBoundsChangeSizeChanged
)
741 // according to the other ports we handle this within the OS level
742 // resize event, not within a wxSizeEvent
743 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
746 frame
->PositionBars();
749 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
750 event
.SetEventObject( toplevelWindow
) ;
752 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
753 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
756 if ( attributes
& kWindowBoundsChangeOriginChanged
)
758 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
759 event
.SetEventObject( toplevelWindow
) ;
760 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
767 case kEventWindowBoundsChanging
:
769 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
770 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
772 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
774 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
775 int left
, top
, right
, bottom
;
776 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
781 newRect
.right
- newRect
.left
+ left
+ right
,
782 newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
784 // this is a EVT_SIZING not a EVT_SIZE type !
785 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
786 wxevent
.SetEventObject( toplevelWindow
) ;
788 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
789 adjustR
= wxevent
.GetRect() ;
791 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
792 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
793 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
794 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
795 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
796 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
797 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
798 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
799 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
800 if ( !EqualRect( &newRect
, &adjustedRect
) )
801 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
802 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
809 case kEventWindowGetRegion
:
811 if ( toplevelWindow
->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
813 WindowRegionCode windowRegionCode
;
815 // Fetch the region code that is being queried
816 GetEventParameter( event
,
817 kEventParamWindowRegionCode
,
818 typeWindowRegionCode
, NULL
,
819 sizeof windowRegionCode
, NULL
,
820 &windowRegionCode
) ;
822 // If it is the opaque region code then set the
823 // region to empty and return noErr to stop event
825 if ( windowRegionCode
== kWindowOpaqueRgn
) {
827 GetEventParameter( event
,
828 kEventParamRgnHandle
,
829 typeQDRgnHandle
, NULL
,
832 SetEmptyRgn(region
) ;
846 // mix this in from window.cpp
847 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
849 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
851 OSStatus result
= eventNotHandledErr
;
853 switch ( GetEventClass( event
) )
855 case kEventClassTextInput
:
856 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
859 case kEventClassKeyboard
:
860 result
= KeyboardEventHandler( handler
, event
, data
) ;
863 case kEventClassWindow
:
864 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
867 case kEventClassMouse
:
868 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
878 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
880 // ---------------------------------------------------------------------------
881 // wxWindowMac utility functions
882 // ---------------------------------------------------------------------------
884 // Find an item given the Macintosh Window Reference
886 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
888 static MacWindowMap wxWinMacWindowList
;
890 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
892 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
894 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
897 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
898 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
900 // adding NULL WindowRef is (first) surely a result of an error and
902 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
904 wxWinMacWindowList
[inWindowRef
] = win
;
907 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
908 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
910 MacWindowMap::iterator it
;
911 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
913 if ( it
->second
== win
)
915 wxWinMacWindowList
.erase(it
);
921 // ----------------------------------------------------------------------------
922 // wxTopLevelWindowMac creation
923 // ----------------------------------------------------------------------------
925 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
931 bool m_wasResizable
;
934 void wxTopLevelWindowMac::Init()
937 m_maximizeOnShow
= false;
940 m_macEventHandler
= NULL
;
941 m_macFullScreenData
= NULL
;
944 class wxMacDeferredWindowDeleter
: public wxObject
947 wxMacDeferredWindowDeleter( WindowRef windowRef
)
949 m_macWindow
= windowRef
;
952 virtual ~wxMacDeferredWindowDeleter()
954 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
958 WindowRef m_macWindow
;
961 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
963 const wxString
& title
,
967 const wxString
& name
)
972 m_windowStyle
= style
;
976 m_windowId
= id
== -1 ? NewControlId() : id
;
977 wxWindow::SetLabel( title
) ;
979 MacCreateRealWindow( title
, pos
, size
, style
, name
) ;
981 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
983 if (GetExtraStyle() & wxFRAME_EX_METAL
)
984 MacSetMetalAppearance(true);
986 wxTopLevelWindows
.Append(this);
989 parent
->AddChild(this);
994 wxTopLevelWindowMac::~wxTopLevelWindowMac()
999 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
1001 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
1004 if ( m_macEventHandler
)
1006 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1007 m_macEventHandler
= NULL
;
1010 wxRemoveMacWindowAssociation( this ) ;
1012 if ( wxModelessWindows
.Find(this) )
1013 wxModelessWindows
.DeleteObject(this);
1015 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1017 m_macFullScreenData
= NULL
;
1019 // avoid dangling refs
1020 if ( s_macDeactivateWindow
== this )
1021 s_macDeactivateWindow
= NULL
;
1025 // ----------------------------------------------------------------------------
1026 // wxTopLevelWindowMac maximize/minimize
1027 // ----------------------------------------------------------------------------
1029 void wxTopLevelWindowMac::Maximize(bool maximize
)
1031 Point idealSize
= { 0 , 0 } ;
1034 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1036 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
1038 idealSize
.h
= bounds
.size
.width
;
1039 idealSize
.v
= bounds
.size
.height
;
1042 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
1043 idealSize
.h
= rect
.right
- rect
.left
;
1044 idealSize
.v
= rect
.bottom
- rect
.top
;
1047 ZoomWindowIdeal( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
1050 bool wxTopLevelWindowMac::IsMaximized() const
1052 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
1055 void wxTopLevelWindowMac::Iconize(bool iconize
)
1057 if ( IsWindowCollapsable( (WindowRef
)m_macWindow
) )
1058 CollapseWindow( (WindowRef
)m_macWindow
, iconize
) ;
1061 bool wxTopLevelWindowMac::IsIconized() const
1063 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1066 void wxTopLevelWindowMac::Restore()
1068 if ( IsMaximized() )
1070 else if ( IsIconized() )
1074 // ----------------------------------------------------------------------------
1075 // wxTopLevelWindowMac misc
1076 // ----------------------------------------------------------------------------
1078 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1080 return wxPoint(0, 0) ;
1083 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1085 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1087 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1089 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1093 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1095 if ( m_macEventHandler
!= NULL
)
1097 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1100 InstallWindowEventHandler(
1101 MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1102 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1105 void wxTopLevelWindowMac::MacCreateRealWindow(
1106 const wxString
& title
,
1110 const wxString
& name
)
1112 OSStatus err
= noErr
;
1114 m_windowStyle
= style
;
1122 wxRect display
= wxGetClientDisplayRect() ;
1124 if ( x
== wxDefaultPosition
.x
)
1127 if ( y
== wxDefaultPosition
.y
)
1130 int w
= WidthDefault(size
.x
);
1131 int h
= HeightDefault(size
.y
);
1133 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1135 // translate the window attributes in the appropriate window class and attributes
1136 WindowClass wclass
= 0;
1137 WindowAttributes attr
= kWindowNoAttributes
;
1138 WindowGroupRef group
= NULL
;
1140 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1143 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1144 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1145 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1148 wclass
= kFloatingWindowClass
;
1150 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1151 attr
|= kWindowSideTitlebarAttribute
;
1155 wclass
= kPlainWindowClass
;
1158 else if ( HasFlag( wxPOPUP_WINDOW
) )
1161 // Until we've got a real wxPopupWindow class on wxMac make it a
1162 // little easier for wxFrame to be used to emulate it and workaround
1163 // the lack of wxPopupWindow.
1164 if ( HasFlag( wxBORDER_NONE
) )
1165 wclass
= kHelpWindowClass
; // has no border
1167 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1168 //attr |= kWindowNoShadowAttribute; // turn off the shadow Should we??
1169 group
= GetWindowGroupOfClass( // float above other windows
1170 kFloatingWindowClass
) ;
1172 else if ( HasFlag( wxCAPTION
) )
1174 wclass
= kDocumentWindowClass
;
1175 attr
|= kWindowInWindowMenuAttribute
;
1177 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1178 else if ( HasFlag( wxFRAME_DRAWER
) )
1180 wclass
= kDrawerWindowClass
;
1182 #endif //10.2 and up
1185 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1186 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1188 wclass
= kDocumentWindowClass
;
1192 wclass
= kPlainWindowClass
;
1196 if ( wclass
!= kPlainWindowClass
)
1198 if ( HasFlag( wxMINIMIZE_BOX
) )
1199 attr
|= kWindowCollapseBoxAttribute
;
1201 if ( HasFlag( wxMAXIMIZE_BOX
) )
1202 attr
|= kWindowFullZoomAttribute
;
1204 if ( HasFlag( wxRESIZE_BORDER
) )
1205 attr
|= kWindowResizableAttribute
;
1207 if ( HasFlag( wxCLOSE_BOX
) )
1208 attr
|= kWindowCloseBoxAttribute
;
1211 // turn on live resizing (OS X only)
1212 if (UMAGetSystemVersion() >= 0x1000)
1213 attr
|= kWindowLiveResizeAttribute
;
1215 if ( HasFlag(wxSTAY_ON_TOP
) )
1216 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1218 if ( HasFlag( wxFRAME_FLOAT_ON_PARENT
) )
1219 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1221 attr
|= kWindowCompositingAttribute
;
1222 #if 0 // wxMAC_USE_CORE_GRAPHICS ; TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1223 attr
|= kWindowFrameworkScaledAttribute
;
1226 if ( HasFlag(wxFRAME_SHAPED
) )
1228 WindowDefSpec customWindowDefSpec
;
1229 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1230 customWindowDefSpec
.u
.defProc
=
1232 (WindowDefUPP
) wxShapedMacWindowDef
;
1234 NewWindowDefUPP(wxShapedMacWindowDef
);
1236 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1237 attr
, &theBoundsRect
,
1238 (WindowRef
*) &m_macWindow
);
1242 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1245 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1246 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1248 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1250 // setup a separate group for each window, so that overlays can be handled easily
1251 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &group
));
1252 verify_noerr( SetWindowGroupParent( group
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1253 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, group
));
1255 // the create commands are only for content rect,
1256 // so we have to set the size again as structure bounds
1257 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1259 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1260 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1261 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1263 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1264 // the content view, so we have to retrieve it explicitly
1265 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1266 m_peer
->GetControlRefAddr() ) ;
1267 if ( !m_peer
->Ok() )
1269 // compatibility mode fallback
1270 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1273 // the root control level handler
1274 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1276 // Causes the inner part of the window not to be metal
1277 // if the style is used before window creation.
1278 #if 0 // TARGET_API_MAC_OSX
1279 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1281 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1282 MacSetMetalAppearance( true ) ;
1286 #if TARGET_API_MAC_OSX
1287 if ( m_macWindow
!= NULL
)
1289 MacSetUnifiedAppearance( true ) ;
1293 // the frame window event handler
1294 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1295 MacInstallTopLevelWindowEventHandler() ;
1297 DoSetWindowVariant( m_windowVariant
) ;
1301 if ( HasFlag(wxFRAME_SHAPED
) )
1303 // default shape matches the window size
1304 wxRegion
rgn( 0, 0, w
, h
);
1308 wxWindowCreateEvent
event(this);
1309 GetEventHandler()->ProcessEvent(event
);
1312 void wxTopLevelWindowMac::ClearBackground()
1314 wxWindow::ClearBackground() ;
1317 // Raise the window to the top of the Z order
1318 void wxTopLevelWindowMac::Raise()
1320 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1323 // Lower the window to the bottom of the Z order
1324 void wxTopLevelWindowMac::Lower()
1326 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1329 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1331 if (s_macDeactivateWindow
)
1333 wxLogTrace(TRACE_ACTIVATE
,
1334 wxT("Doing delayed deactivation of %p"),
1335 s_macDeactivateWindow
);
1337 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1341 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1343 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1345 if (s_macDeactivateWindow
== this)
1346 s_macDeactivateWindow
= NULL
;
1348 MacDelayedDeactivation(timestamp
);
1349 MacPropagateHiliteChanged() ;
1352 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1354 wxWindow::SetLabel( title
) ;
1355 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1358 wxString
wxTopLevelWindowMac::GetTitle() const
1360 return wxWindow::GetLabel();
1363 bool wxTopLevelWindowMac::Show(bool show
)
1365 if ( !wxTopLevelWindowBase::Show(show
) )
1368 bool plainTransition
= false;
1370 #if wxUSE_SYSTEM_OPTIONS
1371 // code contributed by Ryan Wilcox December 18, 2003
1372 plainTransition
= UMAGetSystemVersion() >= 0x1000 ;
1373 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1374 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1379 if ( plainTransition
)
1380 ::ShowWindow( (WindowRef
)m_macWindow
);
1382 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1384 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1386 // because apps expect a size event to occur at this moment
1387 wxSizeEvent
event(GetSize() , m_windowId
);
1388 event
.SetEventObject(this);
1389 GetEventHandler()->ProcessEvent(event
);
1393 if ( plainTransition
)
1394 ::HideWindow( (WindowRef
)m_macWindow
);
1396 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1399 MacPropagateVisibilityChanged() ;
1404 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1408 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1410 data
= new FullScreenData() ;
1412 m_macFullScreenData
= data
;
1413 data
->m_position
= GetPosition() ;
1414 data
->m_size
= GetSize() ;
1415 data
->m_wasResizable
= MacGetWindowAttributes() & kWindowResizableAttribute
;
1417 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1420 wxRect client
= wxGetClientDisplayRect() ;
1422 int left
, top
, right
, bottom
;
1430 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1432 if ( style
& wxFULLSCREEN_NOCAPTION
)
1438 if ( style
& wxFULLSCREEN_NOBORDER
)
1445 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1450 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1455 SetSize( x
, y
, w
, h
) ;
1456 if ( data
->m_wasResizable
)
1457 MacChangeWindowAttributes( kWindowNoAttributes
, kWindowResizableAttribute
) ;
1462 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1463 if ( data
->m_wasResizable
)
1464 MacChangeWindowAttributes( kWindowResizableAttribute
, kWindowNoAttributes
) ;
1465 SetPosition( data
->m_position
) ;
1466 SetSize( data
->m_size
) ;
1469 m_macFullScreenData
= NULL
;
1475 bool wxTopLevelWindowMac::IsFullScreen() const
1477 return m_macFullScreenData
!= NULL
;
1481 bool wxTopLevelWindowMac::SetTransparent(wxByte alpha
)
1483 OSStatus result
= SetWindowAlpha((WindowRef
)m_macWindow
, float(alpha
)/255.0);
1484 return result
== noErr
;
1488 bool wxTopLevelWindowMac::CanSetTransparent()
1494 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1496 if ( GetExtraStyle() == exStyle
)
1499 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1501 #if TARGET_API_MAC_OSX
1502 if ( m_macWindow
!= NULL
)
1504 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1506 if ( MacGetMetalAppearance() != metal
)
1508 if ( MacGetUnifiedAppearance() )
1509 MacSetUnifiedAppearance( !metal
) ;
1511 MacSetMetalAppearance( metal
) ;
1517 bool wxTopLevelWindowMac::SetBackgroundStyle(wxBackgroundStyle style
)
1519 if ( !wxTopLevelWindowBase::SetBackgroundStyle(style
) )
1522 WindowRef windowRef
= HIViewGetWindow( (HIViewRef
)GetHandle() );
1524 if ( GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
1526 OSStatus err
= HIWindowChangeFeatures( windowRef
, 0, kWindowIsOpaque
);
1527 verify_noerr( err
);
1528 err
= ReshapeCustomWindow( windowRef
);
1529 verify_noerr( err
);
1535 // TODO: switch to structure bounds -
1536 // we are still using coordinates of the content view
1538 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1540 Rect content
, structure
;
1542 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1543 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1545 left
= content
.left
- structure
.left
;
1546 top
= content
.top
- structure
.top
;
1547 right
= structure
.right
- content
.right
;
1548 bottom
= structure
.bottom
- content
.bottom
;
1551 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1553 m_cachedClippedRectValid
= false ;
1554 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1555 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1556 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1559 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1563 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1571 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1575 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1578 *width
= bounds
.right
- bounds
.left
;
1580 *height
= bounds
.bottom
- bounds
.top
;
1583 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1587 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1590 *width
= bounds
.right
- bounds
.left
;
1592 *height
= bounds
.bottom
- bounds
.top
;
1595 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1597 #if TARGET_API_MAC_OSX
1598 if ( MacGetUnifiedAppearance() )
1599 MacSetUnifiedAppearance( false ) ;
1601 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1602 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1606 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1608 #if TARGET_API_MAC_OSX
1609 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1615 void wxTopLevelWindowMac::MacSetUnifiedAppearance( bool set
)
1617 #if TARGET_API_MAC_OSX
1618 if ( UMAGetSystemVersion() >= 0x1040 )
1620 if ( MacGetMetalAppearance() )
1621 MacSetMetalAppearance( false ) ;
1623 MacChangeWindowAttributes( set
? kWindowUnifiedTitleAndToolbarAttribute
: kWindowNoAttributes
,
1624 set
? kWindowNoAttributes
: kWindowUnifiedTitleAndToolbarAttribute
) ;
1626 // For some reason, Tiger uses white as the background color for this appearance,
1627 // while most apps using it use the typical striped background. Restore that behavior
1629 // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
1631 SetBackgroundColour( wxSYS_COLOUR_WINDOW
) ;
1636 bool wxTopLevelWindowMac::MacGetUnifiedAppearance() const
1638 #if TARGET_API_MAC_OSX
1639 if ( UMAGetSystemVersion() >= 0x1040 )
1640 return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute
;
1646 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1648 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1651 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1654 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1659 void wxTopLevelWindowMac::MacPerformUpdates()
1661 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1662 // for composited windows this also triggers a redraw of all
1663 // invalid views in the window
1664 if ( UMAGetSystemVersion() >= 0x1030 )
1665 HIWindowFlush((WindowRef
) m_macWindow
) ;
1669 // the only way to trigger the redrawing on earlier systems is to call
1672 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1673 UInt32 currentEventClass
= 0 ;
1674 if ( currentEvent
!= NULL
)
1676 currentEventClass
= ::GetEventClass( currentEvent
) ;
1677 ::GetEventKind( currentEvent
) ;
1680 if ( currentEventClass
!= kEventClassMenu
)
1682 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1684 ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1689 // Attracts the users attention to this window if the application is
1690 // inactive (should be called when a background event occurs)
1692 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1695 DisposePtr( (Ptr
)ptr
) ;
1698 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1700 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1701 static wxMacNMUPP
nmupp( wxMacNMResponse
);
1703 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1704 notificationRequest
->qType
= nmType
;
1705 notificationRequest
->nmMark
= 1 ;
1706 notificationRequest
->nmIcon
= 0 ;
1707 notificationRequest
->nmSound
= 0 ;
1708 notificationRequest
->nmStr
= NULL
;
1709 notificationRequest
->nmResp
= nmupp
;
1711 verify_noerr( NMInstall( notificationRequest
) ) ;
1714 // ---------------------------------------------------------------------------
1715 // Shape implementation
1716 // ---------------------------------------------------------------------------
1719 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1721 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1722 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1724 // The empty region signifies that the shape
1725 // should be removed from the window.
1726 if ( region
.IsEmpty() )
1728 wxSize sz
= GetClientSize();
1729 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1730 if ( rgn
.IsEmpty() )
1733 return SetShape(rgn
);
1736 // Make a copy of the region
1737 RgnHandle shapeRegion
= NewRgn();
1738 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1740 // Dispose of any shape region we may already have
1741 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1745 // Save the region so we can use it later
1746 SetWRefCon((WindowRef
)MacGetWindowRef(), (URefCon
)shapeRegion
);
1748 // inform the window manager that the window has changed shape
1749 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1754 // ---------------------------------------------------------------------------
1755 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1756 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1757 // ---------------------------------------------------------------------------
1759 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1761 GetWindowPortBounds(window
, inRect
);
1762 Point pt
= { inRect
->top
,inRect
->left
};
1763 wxMacLocalToGlobal( window
, &pt
) ;
1764 inRect
->bottom
+= pt
.v
- inRect
->top
;
1765 inRect
->right
+= pt
.h
- inRect
->left
;
1767 inRect
->left
= pt
.h
;
1770 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1772 /*------------------------------------------------------
1773 Define which options your custom window supports.
1774 --------------------------------------------------------*/
1775 //just enable everything for our demo
1776 *(OptionBits
*)param
=
1779 //kWindowCanCollapse |
1780 //kWindowCanGetWindowRegion |
1781 //kWindowHasTitleBar |
1782 //kWindowSupportsDragHilite |
1783 kWindowCanDrawInCurrentPort
|
1784 //kWindowCanMeasureTitle |
1785 kWindowWantsDisposeAtProcessDeath
|
1786 kWindowSupportsGetGrowImageRegion
|
1787 kWindowDefSupportsColorGrafPort
;
1792 // The content region is left as a rectangle matching the window size, this is
1793 // so the origin in the paint event, and etc. still matches what the
1794 // programmer expects.
1795 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1798 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1802 wxShapedMacWindowGetPos( window
, &r
) ;
1803 RectRgn( rgn
, &r
) ;
1807 // The structure region is set to the shape given to the SetShape method.
1808 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1810 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1816 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1817 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1818 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1819 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1823 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1825 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1830 switch (rgnRec
->regionCode
)
1832 case kWindowStructureRgn
:
1833 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1836 case kWindowContentRgn
:
1837 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1841 SetEmptyRgn(rgnRec
->winRgn
);
1848 // Determine the region of the window which was hit
1850 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1853 static RgnHandle tempRgn
= NULL
;
1855 if (tempRgn
== NULL
)
1858 // get the point clicked
1859 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1861 // Mac OS 8.5 or later
1862 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1863 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1866 // no significant area was hit
1870 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1874 case kWindowMsgHitTest
:
1875 return wxShapedMacWindowHitTest(window
, param
);
1877 case kWindowMsgGetFeatures
:
1878 return wxShapedMacWindowGetFeatures(window
, param
);
1880 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1881 case kWindowMsgGetRegion
:
1882 return wxShapedMacWindowGetRegion(window
, param
);