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
)
82 // ---------------------------------------------------------------------------
84 // ---------------------------------------------------------------------------
86 static const EventTypeSpec eventList
[] =
88 // TODO: remove control related event like key and mouse (except for WindowLeave events)
90 { kEventClassKeyboard
, kEventRawKeyDown
} ,
91 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
92 { kEventClassKeyboard
, kEventRawKeyUp
} ,
93 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
95 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
96 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
98 { kEventClassWindow
, kEventWindowShown
} ,
99 { kEventClassWindow
, kEventWindowActivated
} ,
100 { kEventClassWindow
, kEventWindowDeactivated
} ,
101 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
102 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
103 { kEventClassWindow
, kEventWindowClose
} ,
104 { kEventClassWindow
, kEventWindowGetRegion
} ,
106 // we have to catch these events on the toplevel window level,
107 // as controls don't get the raw mouse events anymore
109 { kEventClassMouse
, kEventMouseDown
} ,
110 { kEventClassMouse
, kEventMouseUp
} ,
111 { kEventClassMouse
, kEventMouseWheelMoved
} ,
112 { kEventClassMouse
, kEventMouseMoved
} ,
113 { kEventClassMouse
, kEventMouseDragged
} ,
116 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
118 OSStatus result
= eventNotHandledErr
;
119 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
120 // FindFocus does not return the actual focus window, but the enclosing window
121 wxWindow
* focus
= wxWindow::DoFindFocus();
123 focus
= (wxTopLevelWindowMac
*) data
;
125 unsigned char charCode
;
133 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
136 ByteCount dataSize
= 0 ;
137 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
140 int numChars
= dataSize
/ sizeof( UniChar
) + 1;
142 UniChar
* charBuf
= buf
;
144 if ( numChars
* 2 > 4 )
145 charBuf
= new UniChar
[ numChars
] ;
146 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
147 charBuf
[ numChars
- 1 ] = 0;
149 #if SIZEOF_WCHAR_T == 2
150 uniChar
= charBuf
[0] ;
152 wxMBConvUTF16 converter
;
153 converter
.MB2WC( uniChar
, (const char*)charBuf
, 2 ) ;
156 if ( numChars
* 2 > 4 )
161 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
162 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
163 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
164 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
166 UInt32 message
= (keyCode
<< 8) + charCode
;
167 switch ( GetEventKind( event
) )
169 case kEventRawKeyRepeat
:
170 case kEventRawKeyDown
:
172 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
173 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
174 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
175 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
176 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
180 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
184 case kEventRawKeyUp
:
185 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
186 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
192 case kEventRawKeyModifiersChanged
:
194 wxKeyEvent
event(wxEVT_KEY_DOWN
);
196 event
.m_shiftDown
= modifiers
& shiftKey
;
197 event
.m_controlDown
= modifiers
& controlKey
;
198 event
.m_altDown
= modifiers
& optionKey
;
199 event
.m_metaDown
= modifiers
& cmdKey
;
204 event
.m_uniChar
= uniChar
[0] ;
207 event
.SetTimestamp(when
);
208 event
.SetEventObject(focus
);
210 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
212 event
.m_keyCode
= WXK_CONTROL
;
213 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
214 focus
->HandleWindowEvent( event
) ;
216 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
218 event
.m_keyCode
= WXK_SHIFT
;
219 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
220 focus
->HandleWindowEvent( event
) ;
222 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
224 event
.m_keyCode
= WXK_ALT
;
225 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
226 focus
->HandleWindowEvent( event
) ;
228 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
230 event
.m_keyCode
= WXK_COMMAND
;
231 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
232 focus
->HandleWindowEvent( event
) ;
235 wxApp::s_lastModifiers
= modifiers
;
246 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
247 // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
250 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
252 wxWindow
* g_MacLastWindow
= NULL
;
254 EventMouseButton g_lastButton
= 0 ;
255 bool g_lastButtonWasFakeRight
= false ;
257 void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
259 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
260 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
262 // these parameters are not given for all events
263 EventMouseButton button
= 0 ;
264 UInt32 clickCount
= 0 ;
265 UInt32 mouseChord
= 0;
267 cEvent
.GetParameter
<EventMouseButton
>( kEventParamMouseButton
, typeMouseButton
, &button
) ;
268 cEvent
.GetParameter
<UInt32
>( kEventParamClickCount
, typeUInt32
, &clickCount
) ;
269 // the chord is the state of the buttons pressed currently
270 cEvent
.GetParameter
<UInt32
>( kEventParamMouseChord
, typeUInt32
, &mouseChord
) ;
272 wxevent
.m_x
= screenMouseLocation
.h
;
273 wxevent
.m_y
= screenMouseLocation
.v
;
274 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
275 wxevent
.m_controlDown
= modifiers
& controlKey
;
276 wxevent
.m_altDown
= modifiers
& optionKey
;
277 wxevent
.m_metaDown
= modifiers
& cmdKey
;
278 wxevent
.m_clickCount
= clickCount
;
279 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
281 // a control click is interpreted as a right click
282 bool thisButtonIsFakeRight
= false ;
283 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
285 button
= kEventMouseButtonSecondary
;
286 thisButtonIsFakeRight
= true ;
289 // otherwise we report double clicks by connecting a left click with a ctrl-left click
290 if ( clickCount
> 1 && button
!= g_lastButton
)
293 // we must make sure that our synthetic 'right' button corresponds in
294 // mouse down, moved and mouse up, and does not deliver a right down and left up
296 if ( cEvent
.GetKind() == kEventMouseDown
)
298 g_lastButton
= button
;
299 g_lastButtonWasFakeRight
= thisButtonIsFakeRight
;
305 g_lastButtonWasFakeRight
= false ;
307 else if ( g_lastButton
== kEventMouseButtonSecondary
&& g_lastButtonWasFakeRight
)
308 button
= g_lastButton
;
310 // Adjust the chord mask to remove the primary button and add the
311 // secondary button. It is possible that the secondary button is
312 // already pressed, e.g. on a mouse connected to a laptop, but this
313 // possibility is ignored here:
314 if( thisButtonIsFakeRight
&& ( mouseChord
& 1U ) )
315 mouseChord
= ((mouseChord
& ~1U) | 2U);
318 wxevent
.m_leftDown
= true ;
320 wxevent
.m_rightDown
= true ;
322 wxevent
.m_middleDown
= true ;
324 // translate into wx types
325 switch ( cEvent
.GetKind() )
327 case kEventMouseDown
:
330 case kEventMouseButtonPrimary
:
331 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
334 case kEventMouseButtonSecondary
:
335 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
338 case kEventMouseButtonTertiary
:
339 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
350 case kEventMouseButtonPrimary
:
351 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
354 case kEventMouseButtonSecondary
:
355 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
358 case kEventMouseButtonTertiary
:
359 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
367 case kEventMouseWheelMoved
:
369 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
371 EventMouseWheelAxis axis
= cEvent
.GetParameter
<EventMouseWheelAxis
>(kEventParamMouseWheelAxis
, typeMouseWheelAxis
) ;
372 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeSInt32
) ;
374 wxevent
.m_wheelRotation
= delta
;
375 wxevent
.m_wheelDelta
= 1;
376 wxevent
.m_linesPerAction
= 1;
377 if ( axis
== kEventMouseWheelAxisX
)
378 wxevent
.m_wheelAxis
= 1;
382 case kEventMouseEntered
:
383 case kEventMouseExited
:
384 case kEventMouseDragged
:
385 case kEventMouseMoved
:
386 wxevent
.SetEventType( wxEVT_MOTION
) ;
393 #define NEW_CAPTURE_HANDLING 1
396 wxMacTopLevelMouseEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
400 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
402 OSStatus result
= eventNotHandledErr
;
404 wxMacCarbonEvent
cEvent( event
) ;
406 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
407 Point windowMouseLocation
= screenMouseLocation
;
409 WindowRef window
= NULL
;
410 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
412 wxWindow
* currentMouseWindow
= NULL
;
413 ControlRef control
= NULL
;
415 #if NEW_CAPTURE_HANDLING
416 if ( wxApp::s_captureWindow
)
418 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
419 windowPart
= inContent
;
425 wxMacGlobalToLocal( window
, &windowMouseLocation
) ;
427 if ( wxApp::s_captureWindow
428 #if !NEW_CAPTURE_HANDLING
429 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
433 currentMouseWindow
= wxApp::s_captureWindow
;
435 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
437 ControlPartCode part
;
438 control
= FindControlUnderMouse( windowMouseLocation
, window
, &part
) ;
439 // if there is no control below the mouse position, send the event to the toplevel window itself
442 currentMouseWindow
= (wxWindow
*) data
;
446 currentMouseWindow
= (wxWindow
*) wxFindControlFromMacControl( control
) ;
447 #ifndef __WXUNIVERSAL__
448 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
451 // for wxToolBar to function we have to send certaint events to it
452 // instead of its children (wxToolBarTools)
454 GetSuperControl(control
, &parent
);
455 wxWindow
*wxParent
= (wxWindow
*) wxFindControlFromMacControl( parent
) ;
456 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
457 currentMouseWindow
= wxParent
;
463 // disabled windows must not get any input messages
464 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
465 currentMouseWindow
= NULL
;
469 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
470 SetupMouseEvent( wxevent
, cEvent
) ;
472 // handle all enter / leave events
474 if ( currentMouseWindow
!= g_MacLastWindow
)
476 if ( g_MacLastWindow
)
478 wxMouseEvent
eventleave(wxevent
);
479 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
480 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
481 eventleave
.SetEventObject( g_MacLastWindow
) ;
482 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
485 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
488 g_MacLastWindow
->HandleWindowEvent(eventleave
);
491 if ( currentMouseWindow
)
493 wxMouseEvent
evententer(wxevent
);
494 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
495 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
496 evententer
.SetEventObject( currentMouseWindow
) ;
497 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
500 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
503 currentMouseWindow
->HandleWindowEvent(evententer
);
506 g_MacLastWindow
= currentMouseWindow
;
509 if ( windowPart
== inMenuBar
)
511 // special case menu bar, as we are having a low-level runloop we must do it ourselves
512 if ( cEvent
.GetKind() == kEventMouseDown
)
514 ::MenuSelect( screenMouseLocation
) ;
519 else if ( currentMouseWindow
)
521 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
523 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
525 wxevent
.SetEventObject( currentMouseWindow
) ;
526 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
528 // make tooltips current
531 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
532 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
535 if ( currentMouseWindow
->HandleWindowEvent(wxevent
) )
537 if ((currentMouseWindowParent
!= NULL
) &&
538 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
539 currentMouseWindow
= NULL
;
545 // if the user code did _not_ handle the event, then perform the
546 // default processing
547 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
549 // ... that is set focus to this window
550 if (currentMouseWindow
->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
551 currentMouseWindow
->SetFocus();
555 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
557 wxApp::s_captureWindow
= NULL
;
563 wxWindow
* cursorTarget
= currentMouseWindow
;
564 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
566 extern wxCursor gGlobalCursor
;
568 if (!gGlobalCursor
.IsOk())
570 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
572 cursorTarget
= cursorTarget
->GetParent() ;
574 cursorPoint
+= cursorTarget
->GetPosition();
579 else // currentMouseWindow == NULL
581 // don't mess with controls we don't know about
582 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
583 // so we try sending them the correct control directly
584 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
586 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
587 Point clickLocation
= windowMouseLocation
;
590 hiPoint
.x
= clickLocation
.h
;
591 hiPoint
.y
= clickLocation
.v
;
592 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
593 clickLocation
.h
= (int)hiPoint
.x
;
594 clickLocation
.v
= (int)hiPoint
.y
;
596 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
604 static pascal OSStatus
605 wxMacTopLevelWindowEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
609 OSStatus result
= eventNotHandledErr
;
611 wxMacCarbonEvent
cEvent( event
) ;
613 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
614 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
616 switch ( GetEventKind( event
) )
618 case kEventWindowActivated
:
620 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
621 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
622 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
623 wxevent
.SetEventObject(toplevelWindow
);
624 toplevelWindow
->HandleWindowEvent(wxevent
);
625 // we still sending an eventNotHandledErr in order to allow for default processing
629 case kEventWindowDeactivated
:
631 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
632 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
633 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
634 wxevent
.SetEventObject(toplevelWindow
);
635 toplevelWindow
->HandleWindowEvent(wxevent
);
636 // we still sending an eventNotHandledErr in order to allow for default processing
640 case kEventWindowShown
:
641 toplevelWindow
->Refresh() ;
645 case kEventWindowClose
:
646 toplevelWindow
->Close() ;
650 case kEventWindowBoundsChanged
:
652 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
653 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
654 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
655 if ( attributes
& kWindowBoundsChangeSizeChanged
)
657 #ifndef __WXUNIVERSAL__
658 // according to the other ports we handle this within the OS level
659 // resize event, not within a wxSizeEvent
660 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
663 frame
->PositionBars();
666 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
667 event
.SetEventObject( toplevelWindow
) ;
669 toplevelWindow
->HandleWindowEvent(event
) ;
670 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
673 if ( attributes
& kWindowBoundsChangeOriginChanged
)
675 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
676 event
.SetEventObject( toplevelWindow
) ;
677 toplevelWindow
->HandleWindowEvent(event
) ;
684 case kEventWindowBoundsChanging
:
686 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
687 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
689 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
691 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
692 int left
, top
, right
, bottom
;
693 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
698 newRect
.right
- newRect
.left
+ left
+ right
,
699 newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
701 // this is a EVT_SIZING not a EVT_SIZE type !
702 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
703 wxevent
.SetEventObject( toplevelWindow
) ;
705 if ( toplevelWindow
->HandleWindowEvent(wxevent
) )
706 adjustR
= wxevent
.GetRect() ;
708 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
709 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
710 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
711 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
712 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
713 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
714 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
715 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
716 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
717 if ( !EqualRect( &newRect
, &adjustedRect
) )
718 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
719 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
726 case kEventWindowGetRegion
:
728 if ( toplevelWindow
->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
730 WindowRegionCode windowRegionCode
;
732 // Fetch the region code that is being queried
733 GetEventParameter( event
,
734 kEventParamWindowRegionCode
,
735 typeWindowRegionCode
, NULL
,
736 sizeof windowRegionCode
, NULL
,
737 &windowRegionCode
) ;
739 // If it is the opaque region code then set the
740 // region to empty and return noErr to stop event
742 if ( windowRegionCode
== kWindowOpaqueRgn
) {
744 GetEventParameter( event
,
745 kEventParamRgnHandle
,
746 typeQDRgnHandle
, NULL
,
749 SetEmptyRgn(region
) ;
763 // mix this in from window.cpp
764 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
766 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
768 OSStatus result
= eventNotHandledErr
;
770 switch ( GetEventClass( event
) )
772 case kEventClassTextInput
:
773 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
776 case kEventClassKeyboard
:
777 result
= KeyboardEventHandler( handler
, event
, data
) ;
780 case kEventClassWindow
:
781 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
784 case kEventClassMouse
:
785 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
795 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
797 // ---------------------------------------------------------------------------
798 // wxWindowMac utility functions
799 // ---------------------------------------------------------------------------
801 // Find an item given the Macintosh Window Reference
803 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
805 static MacWindowMap wxWinMacWindowList
;
807 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
809 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
811 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
814 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
815 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
817 // adding NULL WindowRef is (first) surely a result of an error and
819 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
821 wxWinMacWindowList
[inWindowRef
] = win
;
824 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
825 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
827 MacWindowMap::iterator it
;
828 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
830 if ( it
->second
== win
)
832 wxWinMacWindowList
.erase(it
);
838 // ----------------------------------------------------------------------------
839 // wxTopLevelWindowMac creation
840 // ----------------------------------------------------------------------------
842 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
848 bool m_wasResizable
;
851 void wxTopLevelWindowMac::Init()
854 m_maximizeOnShow
= false;
857 m_macEventHandler
= NULL
;
858 m_macFullScreenData
= NULL
;
861 wxMacDeferredWindowDeleter::wxMacDeferredWindowDeleter( WindowRef windowRef
)
863 m_macWindow
= windowRef
;
866 wxMacDeferredWindowDeleter::~wxMacDeferredWindowDeleter()
868 DisposeWindow( (WindowRef
) m_macWindow
) ;
871 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
873 const wxString
& title
,
877 const wxString
& name
)
882 m_windowStyle
= style
;
886 m_windowId
= id
== -1 ? NewControlId() : id
;
887 wxWindow::SetLabel( title
) ;
889 DoMacCreateRealWindow( parent
, title
, pos
, size
, style
, name
) ;
891 SetBackgroundColour(wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE
));
893 if (GetExtraStyle() & wxFRAME_EX_METAL
)
894 MacSetMetalAppearance(true);
896 wxTopLevelWindows
.Append(this);
899 parent
->AddChild(this);
904 wxTopLevelWindowMac::~wxTopLevelWindowMac()
909 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
911 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
914 if ( m_macEventHandler
)
916 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
917 m_macEventHandler
= NULL
;
920 wxRemoveMacWindowAssociation( this ) ;
922 if ( wxModelessWindows
.Find(this) )
923 wxModelessWindows
.DeleteObject(this);
925 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
927 m_macFullScreenData
= NULL
;
929 // avoid dangling refs
930 if ( s_macDeactivateWindow
== this )
931 s_macDeactivateWindow
= NULL
;
935 // ----------------------------------------------------------------------------
936 // wxTopLevelWindowMac maximize/minimize
937 // ----------------------------------------------------------------------------
939 void wxTopLevelWindowMac::Maximize(bool maximize
)
941 Point idealSize
= { 0 , 0 } ;
944 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
946 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
948 idealSize
.h
= bounds
.size
.width
;
949 idealSize
.v
= bounds
.size
.height
;
952 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
953 idealSize
.h
= rect
.right
- rect
.left
;
954 idealSize
.v
= rect
.bottom
- rect
.top
;
957 ZoomWindowIdeal( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
960 bool wxTopLevelWindowMac::IsMaximized() const
962 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
965 void wxTopLevelWindowMac::Iconize(bool iconize
)
967 if ( IsWindowCollapsable( (WindowRef
)m_macWindow
) )
968 CollapseWindow( (WindowRef
)m_macWindow
, iconize
) ;
971 bool wxTopLevelWindowMac::IsIconized() const
973 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
976 void wxTopLevelWindowMac::Restore()
980 else if ( IsIconized() )
984 // ----------------------------------------------------------------------------
985 // wxTopLevelWindowMac misc
986 // ----------------------------------------------------------------------------
988 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
990 return wxPoint(0, 0) ;
993 bool wxTopLevelWindowMac::SetBackgroundColour(const wxColour
& c
)
996 if ( col
== wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
) )
997 col
= wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDocumentWindowBackground
));
998 else if ( col
== wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE
) )
999 col
= wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive
));
1001 if ( !wxTopLevelWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1004 if ( col
== wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDocumentWindowBackground
)) )
1006 SetThemeWindowBackground( (WindowRef
) m_macWindow
, kThemeBrushDocumentWindowBackground
, false ) ;
1007 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
1009 else if ( col
== wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive
)) )
1011 SetThemeWindowBackground( (WindowRef
) m_macWindow
, kThemeBrushDialogBackgroundActive
, false ) ;
1012 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
1017 void wxTopLevelWindowMacInstallTopLevelWindowEventHandler(WindowRef window
, EventHandlerRef
* handler
, void *ref
)
1019 InstallWindowEventHandler(window
, GetwxMacTopLevelEventHandlerUPP(),
1020 GetEventTypeCount(eventList
), eventList
, ref
, handler
);
1023 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1025 if ( m_macEventHandler
!= NULL
)
1027 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1029 wxTopLevelWindowMacInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow
),(EventHandlerRef
*)&m_macEventHandler
,this);
1032 void wxTopLevelWindowMac::MacCreateRealWindow(
1033 const wxString
& title
,
1037 const wxString
& name
)
1039 DoMacCreateRealWindow( NULL
, title
, pos
, size
, style
, name
);
1042 void wxTopLevelWindowMac::DoMacCreateRealWindow(
1044 const wxString
& title
,
1048 const wxString
& name
)
1050 OSStatus err
= noErr
;
1052 m_windowStyle
= style
;
1060 wxRect display
= wxGetClientDisplayRect() ;
1062 if ( x
== wxDefaultPosition
.x
)
1065 if ( y
== wxDefaultPosition
.y
)
1068 int w
= WidthDefault(size
.x
);
1069 int h
= HeightDefault(size
.y
);
1071 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1073 // translate the window attributes in the appropriate window class and attributes
1074 WindowClass wclass
= 0;
1075 WindowAttributes attr
= kWindowNoAttributes
;
1076 WindowGroupRef group
= NULL
;
1077 bool activationScopeSet
= false;
1078 WindowActivationScope activationScope
= kWindowActivationScopeNone
;
1080 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1083 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1084 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1085 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1088 if ( HasFlag( wxSTAY_ON_TOP
) )
1089 wclass
= kUtilityWindowClass
;
1091 wclass
= kFloatingWindowClass
;
1093 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1094 attr
|= kWindowSideTitlebarAttribute
;
1098 wclass
= kPlainWindowClass
;
1099 activationScopeSet
= true;
1100 activationScope
= kWindowActivationScopeNone
;
1103 else if ( HasFlag( wxPOPUP_WINDOW
) )
1106 // Until we've got a real wxPopupWindow class on wxMac make it a
1107 // little easier for wxFrame to be used to emulate it and workaround
1108 // the lack of wxPopupWindow.
1109 if ( HasFlag( wxBORDER_NONE
) )
1110 wclass
= kHelpWindowClass
; // has no border
1112 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1113 //attr |= kWindowNoShadowAttribute; // turn off the shadow Should we??
1114 group
= GetWindowGroupOfClass( // float above other windows
1115 kFloatingWindowClass
) ;
1117 else if ( HasFlag( wxCAPTION
) )
1119 wclass
= kDocumentWindowClass
;
1120 attr
|= kWindowInWindowMenuAttribute
;
1122 else if ( HasFlag( wxFRAME_DRAWER
) )
1124 wclass
= kDrawerWindowClass
;
1128 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1129 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1131 wclass
= kDocumentWindowClass
;
1133 else if ( HasFlag( wxNO_BORDER
) )
1135 wclass
= kSimpleWindowClass
;
1139 wclass
= kPlainWindowClass
;
1143 if ( wclass
!= kPlainWindowClass
)
1145 if ( HasFlag( wxMINIMIZE_BOX
) )
1146 attr
|= kWindowCollapseBoxAttribute
;
1148 if ( HasFlag( wxMAXIMIZE_BOX
) )
1149 attr
|= kWindowFullZoomAttribute
;
1151 if ( HasFlag( wxRESIZE_BORDER
) )
1152 attr
|= kWindowResizableAttribute
;
1154 if ( HasFlag( wxCLOSE_BOX
) )
1155 attr
|= kWindowCloseBoxAttribute
;
1157 attr
|= kWindowLiveResizeAttribute
;
1159 if ( HasFlag(wxSTAY_ON_TOP
) )
1160 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1162 if ( HasFlag( wxFRAME_FLOAT_ON_PARENT
) )
1163 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1165 if ( group
== NULL
&& parent
!= NULL
)
1167 WindowRef parenttlw
= (WindowRef
) parent
->MacGetTopLevelWindowRef();
1169 group
= GetWindowGroupParent( GetWindowGroup( parenttlw
) );
1172 attr
|= kWindowCompositingAttribute
;
1173 #if 0 // wxMAC_USE_CORE_GRAPHICS ; TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1174 attr
|= kWindowFrameworkScaledAttribute
;
1177 if ( HasFlag(wxFRAME_SHAPED
) )
1179 WindowDefSpec customWindowDefSpec
;
1180 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1181 customWindowDefSpec
.u
.defProc
=
1183 (WindowDefUPP
) wxShapedMacWindowDef
;
1185 NewWindowDefUPP(wxShapedMacWindowDef
);
1187 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1188 attr
, &theBoundsRect
,
1189 (WindowRef
*) &m_macWindow
);
1193 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1196 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1197 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1199 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1201 // setup a separate group for each window, so that overlays can be handled easily
1203 WindowGroupRef overlaygroup
= NULL
;
1204 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &overlaygroup
));
1205 verify_noerr( SetWindowGroupParent( overlaygroup
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1206 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, overlaygroup
));
1208 if ( activationScopeSet
)
1210 verify_noerr( SetWindowActivationScope( (WindowRef
) m_macWindow
, activationScope
));
1213 // the create commands are only for content rect,
1214 // so we have to set the size again as structure bounds
1215 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1217 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1218 SetWindowTitleWithCFString( (WindowRef
) m_macWindow
, wxCFStringRef( title
, GetFont().GetEncoding() ) );
1219 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1221 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1222 // the content view, so we have to retrieve it explicitly
1223 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1224 m_peer
->GetControlRefAddr() ) ;
1225 if ( !m_peer
->Ok() )
1227 // compatibility mode fallback
1228 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1231 // the root control level handler
1232 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1234 // Causes the inner part of the window not to be metal
1235 // if the style is used before window creation.
1236 #if 0 // TARGET_API_MAC_OSX
1237 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1239 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1240 MacSetMetalAppearance( true ) ;
1244 if ( m_macWindow
!= NULL
)
1246 MacSetUnifiedAppearance( true ) ;
1249 HIViewRef growBoxRef
= 0 ;
1250 err
= HIViewFindByID( HIViewGetRoot( (WindowRef
)m_macWindow
), kHIViewWindowGrowBoxID
, &growBoxRef
);
1251 if ( err
== noErr
&& growBoxRef
!= 0 )
1252 HIGrowBoxViewSetTransparent( growBoxRef
, true ) ;
1254 // the frame window event handler
1255 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1256 MacInstallTopLevelWindowEventHandler() ;
1258 DoSetWindowVariant( m_windowVariant
) ;
1262 if ( HasFlag(wxFRAME_SHAPED
) )
1264 // default shape matches the window size
1265 wxRegion
rgn( 0, 0, w
, h
);
1269 wxWindowCreateEvent
event(this);
1270 HandleWindowEvent(event
);
1273 void wxTopLevelWindowMac::ClearBackground()
1275 wxWindow::ClearBackground() ;
1278 // Raise the window to the top of the Z order
1279 void wxTopLevelWindowMac::Raise()
1281 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1284 // Lower the window to the bottom of the Z order
1285 void wxTopLevelWindowMac::Lower()
1287 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1290 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1292 if (s_macDeactivateWindow
)
1294 wxLogTrace(TRACE_ACTIVATE
,
1295 wxT("Doing delayed deactivation of %p"),
1296 s_macDeactivateWindow
);
1298 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1302 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool WXUNUSED(inIsActivating
) )
1304 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1306 if (s_macDeactivateWindow
== this)
1307 s_macDeactivateWindow
= NULL
;
1309 MacDelayedDeactivation(timestamp
);
1312 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1314 wxWindow::SetLabel( title
) ;
1315 SetWindowTitleWithCFString( (WindowRef
) m_macWindow
, wxCFStringRef( title
, GetFont().GetEncoding() ) ) ;
1318 wxString
wxTopLevelWindowMac::GetTitle() const
1320 return wxWindow::GetLabel();
1323 bool wxTopLevelWindowMac::Show(bool show
)
1325 if ( !wxTopLevelWindowBase::Show(show
) )
1328 bool plainTransition
= true;
1330 #if wxUSE_SYSTEM_OPTIONS
1331 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1332 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1337 if ( plainTransition
)
1338 ::ShowWindow( (WindowRef
)m_macWindow
);
1340 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1342 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1344 // because apps expect a size event to occur at this moment
1345 wxSizeEvent
event(GetSize() , m_windowId
);
1346 event
.SetEventObject(this);
1347 HandleWindowEvent(event
);
1351 if ( plainTransition
)
1352 ::HideWindow( (WindowRef
)m_macWindow
);
1354 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1360 bool wxTopLevelWindowMac::ShowWithEffect(wxShowEffect effect
,
1364 // TODO factor common code
1365 if ( !wxTopLevelWindowBase::Show(true) )
1368 WindowTransitionEffect transition
= 0 ;
1371 case wxSHOW_EFFECT_ROLL
:
1372 case wxSHOW_EFFECT_SLIDE
:
1373 transition
= kWindowGenieTransitionEffect
;
1375 case wxSHOW_EFFECT_BLEND
:
1376 transition
= kWindowFadeTransitionEffect
;
1378 case wxSHOW_EFFECT_EXPAND
:
1380 // having sheets would be fine, but this might lead to a repositioning
1383 transition
= kWindowSheetTransitionEffect
;
1386 transition
= kWindowZoomTransitionEffect
;
1390 TransitionWindowOptions options
;
1391 options
.version
= 0;
1392 options
.duration
= timeout
/ 1000.0;
1393 options
.window
= transition
== kWindowSheetTransitionEffect
? (WindowRef
) GetParent()->MacGetTopLevelWindowRef() :0;
1394 options
.userData
= 0;
1396 wxSize size
= wxGetDisplaySize();
1398 GetWindowBounds( (WindowRef
)m_macWindow
, kWindowStructureRgn
, &bounds
);
1399 CGRect hiBounds
= CGRectMake( bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
);
1401 if ( dir
& wxRIGHT
)
1403 hiBounds
.origin
.x
= size
.x
;
1404 hiBounds
.size
.width
= 0;
1408 hiBounds
.origin
.y
= 0;
1409 hiBounds
.size
.height
= 0;
1413 hiBounds
.origin
.y
= size
.y
;
1414 hiBounds
.size
.height
= 0;
1418 hiBounds
.origin
.x
= 0;
1419 hiBounds
.size
.width
= 0;
1422 ::TransitionWindowWithOptions( (WindowRef
)m_macWindow
, transition
, kWindowShowTransitionAction
, transition
== kWindowGenieTransitionEffect
? &hiBounds
: NULL
,
1425 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1427 // because apps expect a size event to occur at this moment
1428 wxSizeEvent
event(GetSize() , m_windowId
);
1429 event
.SetEventObject(this);
1430 HandleWindowEvent(event
);
1435 bool wxTopLevelWindowMac::HideWithEffect(wxShowEffect effect
,
1439 if ( !wxTopLevelWindowBase::Show(false) )
1442 WindowTransitionEffect transition
= 0 ;
1445 case wxSHOW_EFFECT_ROLL
:
1446 case wxSHOW_EFFECT_SLIDE
:
1447 transition
= kWindowGenieTransitionEffect
;
1449 case wxSHOW_EFFECT_BLEND
:
1450 transition
= kWindowFadeTransitionEffect
;
1452 case wxSHOW_EFFECT_EXPAND
:
1456 transition
= kWindowSheetTransitionEffect
;
1459 transition
= kWindowZoomTransitionEffect
;
1462 TransitionWindowOptions options
;
1463 options
.version
= 0;
1464 options
.duration
= timeout
/ 1000.0;
1465 options
.window
= transition
== kWindowSheetTransitionEffect
? (WindowRef
) GetParent()->MacGetTopLevelWindowRef() :0;
1466 options
.userData
= 0;
1468 wxSize size
= wxGetDisplaySize();
1470 GetWindowBounds( (WindowRef
)m_macWindow
, kWindowStructureRgn
, &bounds
);
1471 CGRect hiBounds
= CGRectMake( bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
);
1473 if ( dir
& wxRIGHT
)
1475 hiBounds
.origin
.x
= size
.x
;
1476 hiBounds
.size
.width
= 0;
1480 hiBounds
.origin
.y
= 0;
1481 hiBounds
.size
.height
= 0;
1485 hiBounds
.origin
.y
= size
.y
;
1486 hiBounds
.size
.height
= 0;
1490 hiBounds
.origin
.x
= 0;
1491 hiBounds
.size
.width
= 0;
1493 ::TransitionWindowWithOptions( (WindowRef
)m_macWindow
, transition
, kWindowHideTransitionAction
, transition
== kWindowGenieTransitionEffect
? &hiBounds
: NULL
,
1499 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1503 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1505 data
= new FullScreenData() ;
1507 m_macFullScreenData
= data
;
1508 data
->m_position
= GetPosition() ;
1509 data
->m_size
= GetSize() ;
1510 data
->m_wasResizable
= MacGetWindowAttributes() & kWindowResizableAttribute
;
1512 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1515 wxRect client
= wxGetClientDisplayRect() ;
1517 int left
, top
, right
, bottom
;
1525 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1527 if ( style
& wxFULLSCREEN_NOCAPTION
)
1533 if ( style
& wxFULLSCREEN_NOBORDER
)
1540 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1545 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1550 SetSize( x
, y
, w
, h
) ;
1551 if ( data
->m_wasResizable
)
1552 MacChangeWindowAttributes( kWindowNoAttributes
, kWindowResizableAttribute
) ;
1557 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1558 if ( data
->m_wasResizable
)
1559 MacChangeWindowAttributes( kWindowResizableAttribute
, kWindowNoAttributes
) ;
1560 SetPosition( data
->m_position
) ;
1561 SetSize( data
->m_size
) ;
1564 m_macFullScreenData
= NULL
;
1570 bool wxTopLevelWindowMac::IsFullScreen() const
1572 return m_macFullScreenData
!= NULL
;
1576 bool wxTopLevelWindowMac::SetTransparent(wxByte alpha
)
1578 OSStatus result
= SetWindowAlpha((WindowRef
)m_macWindow
, float(alpha
)/255.0);
1579 return result
== noErr
;
1583 bool wxTopLevelWindowMac::CanSetTransparent()
1589 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1591 if ( GetExtraStyle() == exStyle
)
1594 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1596 if ( m_macWindow
!= NULL
)
1598 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1600 if ( MacGetMetalAppearance() != metal
)
1602 if ( MacGetUnifiedAppearance() )
1603 MacSetUnifiedAppearance( !metal
) ;
1605 MacSetMetalAppearance( metal
) ;
1610 bool wxTopLevelWindowMac::SetBackgroundStyle(wxBackgroundStyle style
)
1612 if ( !wxTopLevelWindowBase::SetBackgroundStyle(style
) )
1615 WindowRef windowRef
= HIViewGetWindow( (HIViewRef
)GetHandle() );
1617 if ( GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
1619 OSStatus err
= HIWindowChangeFeatures( windowRef
, 0, kWindowIsOpaque
);
1620 verify_noerr( err
);
1621 err
= ReshapeCustomWindow( windowRef
);
1622 verify_noerr( err
);
1628 // TODO: switch to structure bounds -
1629 // we are still using coordinates of the content view
1631 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1633 Rect content
, structure
;
1635 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1636 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1638 left
= content
.left
- structure
.left
;
1639 top
= content
.top
- structure
.top
;
1640 right
= structure
.right
- content
.right
;
1641 bottom
= structure
.bottom
- content
.bottom
;
1644 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1646 m_cachedClippedRectValid
= false ;
1647 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1648 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1649 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1652 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1656 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1664 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1668 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1671 *width
= bounds
.right
- bounds
.left
;
1673 *height
= bounds
.bottom
- bounds
.top
;
1676 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1680 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1683 *width
= bounds
.right
- bounds
.left
;
1685 *height
= bounds
.bottom
- bounds
.top
;
1688 void wxTopLevelWindowMac::DoCentre(int dir
)
1690 if ( m_macWindow
!= 0 )
1691 wxTopLevelWindowBase::DoCentre(dir
);
1694 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1696 if ( MacGetUnifiedAppearance() )
1697 MacSetUnifiedAppearance( false ) ;
1699 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1700 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1703 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1705 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1708 void wxTopLevelWindowMac::MacSetUnifiedAppearance( bool set
)
1710 if ( MacGetMetalAppearance() )
1711 MacSetMetalAppearance( false ) ;
1713 MacChangeWindowAttributes( set
? kWindowUnifiedTitleAndToolbarAttribute
: kWindowNoAttributes
,
1714 set
? kWindowNoAttributes
: kWindowUnifiedTitleAndToolbarAttribute
) ;
1716 // For some reason, Tiger uses white as the background color for this appearance,
1717 // while most apps using it use the typical striped background. Restore that behavior
1719 // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
1721 SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
) ) ;
1724 bool wxTopLevelWindowMac::MacGetUnifiedAppearance() const
1726 return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute
;
1729 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1731 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1734 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1737 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1742 void wxTopLevelWindowMac::MacPerformUpdates()
1744 // for composited windows this also triggers a redraw of all
1745 // invalid views in the window
1746 HIWindowFlush((WindowRef
) m_macWindow
) ;
1749 // Attracts the users attention to this window if the application is
1750 // inactive (should be called when a background event occurs)
1752 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1755 DisposePtr( (Ptr
)ptr
) ;
1758 void wxTopLevelWindowMac::RequestUserAttention(int WXUNUSED(flags
))
1760 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1761 static wxMacNMUPP
nmupp( wxMacNMResponse
);
1763 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1764 notificationRequest
->qType
= nmType
;
1765 notificationRequest
->nmMark
= 1 ;
1766 notificationRequest
->nmIcon
= 0 ;
1767 notificationRequest
->nmSound
= 0 ;
1768 notificationRequest
->nmStr
= NULL
;
1769 notificationRequest
->nmResp
= nmupp
;
1771 verify_noerr( NMInstall( notificationRequest
) ) ;
1774 // ---------------------------------------------------------------------------
1775 // Shape implementation
1776 // ---------------------------------------------------------------------------
1779 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1781 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1782 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1784 // The empty region signifies that the shape
1785 // should be removed from the window.
1786 if ( region
.IsEmpty() )
1788 wxSize sz
= GetClientSize();
1789 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1790 if ( rgn
.IsEmpty() )
1793 return SetShape(rgn
);
1796 // Make a copy of the region
1797 RgnHandle shapeRegion
= NewRgn();
1798 HIShapeGetAsQDRgn( region
.GetWXHRGN(), shapeRegion
);
1800 // Dispose of any shape region we may already have
1801 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1805 // Save the region so we can use it later
1806 SetWRefCon((WindowRef
)MacGetWindowRef(), (URefCon
)shapeRegion
);
1808 // inform the window manager that the window has changed shape
1809 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1814 // ---------------------------------------------------------------------------
1815 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1816 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1817 // ---------------------------------------------------------------------------
1819 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1821 GetWindowPortBounds(window
, inRect
);
1822 Point pt
= { inRect
->top
,inRect
->left
};
1823 wxMacLocalToGlobal( window
, &pt
) ;
1824 inRect
->bottom
+= pt
.v
- inRect
->top
;
1825 inRect
->right
+= pt
.h
- inRect
->left
;
1827 inRect
->left
= pt
.h
;
1830 static SInt32
wxShapedMacWindowGetFeatures(WindowRef
WXUNUSED(window
), SInt32 param
)
1832 /*------------------------------------------------------
1833 Define which options your custom window supports.
1834 --------------------------------------------------------*/
1835 //just enable everything for our demo
1836 *(OptionBits
*)param
=
1839 kWindowCanCollapse
|
1840 //kWindowCanGetWindowRegion |
1841 //kWindowHasTitleBar |
1842 //kWindowSupportsDragHilite |
1843 kWindowCanDrawInCurrentPort
|
1844 //kWindowCanMeasureTitle |
1845 kWindowWantsDisposeAtProcessDeath
|
1846 kWindowSupportsGetGrowImageRegion
|
1847 kWindowDefSupportsColorGrafPort
;
1852 // The content region is left as a rectangle matching the window size, this is
1853 // so the origin in the paint event, and etc. still matches what the
1854 // programmer expects.
1855 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1858 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1862 wxShapedMacWindowGetPos( window
, &r
) ;
1863 RectRgn( rgn
, &r
) ;
1867 // The structure region is set to the shape given to the SetShape method.
1868 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1870 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1876 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1877 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1878 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1879 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1883 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1885 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1890 switch (rgnRec
->regionCode
)
1892 case kWindowStructureRgn
:
1893 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1896 case kWindowContentRgn
:
1897 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1901 SetEmptyRgn(rgnRec
->winRgn
);
1908 // Determine the region of the window which was hit
1910 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1913 static RgnHandle tempRgn
= NULL
;
1915 if (tempRgn
== NULL
)
1918 // get the point clicked
1919 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1921 // Mac OS 8.5 or later
1922 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1923 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1926 // no significant area was hit
1930 static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode
), WindowRef window
, SInt16 message
, SInt32 param
)
1934 case kWindowMsgHitTest
:
1935 return wxShapedMacWindowHitTest(window
, param
);
1937 case kWindowMsgGetFeatures
:
1938 return wxShapedMacWindowGetFeatures(window
, param
);
1940 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1941 case kWindowMsgGetRegion
:
1942 return wxShapedMacWindowGetRegion(window
, param
);