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
& col
)
995 if ( !wxTopLevelWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
998 if ( col
== wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
) || col
== wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDocumentWindowBackground
)) )
1000 SetThemeWindowBackground( (WindowRef
) m_macWindow
, kThemeBrushDocumentWindowBackground
, false ) ;
1001 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
1003 else if ( col
== wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE
) || col
== wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive
)) )
1005 SetThemeWindowBackground( (WindowRef
) m_macWindow
, kThemeBrushDialogBackgroundActive
, false ) ;
1006 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
1011 void wxTopLevelWindowMacInstallTopLevelWindowEventHandler(WindowRef window
, EventHandlerRef
* handler
, void *ref
)
1013 InstallWindowEventHandler(window
, GetwxMacTopLevelEventHandlerUPP(),
1014 GetEventTypeCount(eventList
), eventList
, ref
, handler
);
1017 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1019 if ( m_macEventHandler
!= NULL
)
1021 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1023 wxTopLevelWindowMacInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow
),(EventHandlerRef
*)&m_macEventHandler
,this);
1026 void wxTopLevelWindowMac::MacCreateRealWindow(
1027 const wxString
& title
,
1031 const wxString
& name
)
1033 DoMacCreateRealWindow( NULL
, title
, pos
, size
, style
, name
);
1036 void wxTopLevelWindowMac::DoMacCreateRealWindow(
1038 const wxString
& title
,
1042 const wxString
& name
)
1044 OSStatus err
= noErr
;
1046 m_windowStyle
= style
;
1054 wxRect display
= wxGetClientDisplayRect() ;
1056 if ( x
== wxDefaultPosition
.x
)
1059 if ( y
== wxDefaultPosition
.y
)
1062 int w
= WidthDefault(size
.x
);
1063 int h
= HeightDefault(size
.y
);
1065 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1067 // translate the window attributes in the appropriate window class and attributes
1068 WindowClass wclass
= 0;
1069 WindowAttributes attr
= kWindowNoAttributes
;
1070 WindowGroupRef group
= NULL
;
1071 bool activationScopeSet
= false;
1072 WindowActivationScope activationScope
= kWindowActivationScopeNone
;
1074 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1077 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1078 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1079 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1082 if ( HasFlag( wxSTAY_ON_TOP
) )
1083 wclass
= kUtilityWindowClass
;
1085 wclass
= kFloatingWindowClass
;
1087 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1088 attr
|= kWindowSideTitlebarAttribute
;
1092 wclass
= kPlainWindowClass
;
1093 activationScopeSet
= true;
1094 activationScope
= kWindowActivationScopeNone
;
1097 else if ( HasFlag( wxPOPUP_WINDOW
) )
1100 // Until we've got a real wxPopupWindow class on wxMac make it a
1101 // little easier for wxFrame to be used to emulate it and workaround
1102 // the lack of wxPopupWindow.
1103 if ( HasFlag( wxBORDER_NONE
) )
1104 wclass
= kHelpWindowClass
; // has no border
1106 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1107 //attr |= kWindowNoShadowAttribute; // turn off the shadow Should we??
1108 group
= GetWindowGroupOfClass( // float above other windows
1109 kFloatingWindowClass
) ;
1111 else if ( HasFlag( wxCAPTION
) )
1113 wclass
= kDocumentWindowClass
;
1114 attr
|= kWindowInWindowMenuAttribute
;
1116 else if ( HasFlag( wxFRAME_DRAWER
) )
1118 wclass
= kDrawerWindowClass
;
1122 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1123 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1125 wclass
= kDocumentWindowClass
;
1127 else if ( HasFlag( wxNO_BORDER
) )
1129 wclass
= kSimpleWindowClass
;
1133 wclass
= kPlainWindowClass
;
1137 if ( wclass
!= kPlainWindowClass
)
1139 if ( HasFlag( wxMINIMIZE_BOX
) )
1140 attr
|= kWindowCollapseBoxAttribute
;
1142 if ( HasFlag( wxMAXIMIZE_BOX
) )
1143 attr
|= kWindowFullZoomAttribute
;
1145 if ( HasFlag( wxRESIZE_BORDER
) )
1146 attr
|= kWindowResizableAttribute
;
1148 if ( HasFlag( wxCLOSE_BOX
) )
1149 attr
|= kWindowCloseBoxAttribute
;
1151 attr
|= kWindowLiveResizeAttribute
;
1153 if ( HasFlag(wxSTAY_ON_TOP
) )
1154 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1156 if ( HasFlag( wxFRAME_FLOAT_ON_PARENT
) )
1157 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1159 if ( group
== NULL
&& parent
!= NULL
)
1161 WindowRef parenttlw
= (WindowRef
) parent
->MacGetTopLevelWindowRef();
1163 group
= GetWindowGroupParent( GetWindowGroup( parenttlw
) );
1166 attr
|= kWindowCompositingAttribute
;
1167 #if 0 // wxMAC_USE_CORE_GRAPHICS ; TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1168 attr
|= kWindowFrameworkScaledAttribute
;
1171 if ( HasFlag(wxFRAME_SHAPED
) )
1173 WindowDefSpec customWindowDefSpec
;
1174 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1175 customWindowDefSpec
.u
.defProc
=
1177 (WindowDefUPP
) wxShapedMacWindowDef
;
1179 NewWindowDefUPP(wxShapedMacWindowDef
);
1181 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1182 attr
, &theBoundsRect
,
1183 (WindowRef
*) &m_macWindow
);
1187 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1190 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1191 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1193 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1195 // setup a separate group for each window, so that overlays can be handled easily
1197 WindowGroupRef overlaygroup
= NULL
;
1198 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &overlaygroup
));
1199 verify_noerr( SetWindowGroupParent( overlaygroup
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1200 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, overlaygroup
));
1202 if ( activationScopeSet
)
1204 verify_noerr( SetWindowActivationScope( (WindowRef
) m_macWindow
, activationScope
));
1207 // the create commands are only for content rect,
1208 // so we have to set the size again as structure bounds
1209 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1211 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1212 SetWindowTitleWithCFString( (WindowRef
) m_macWindow
, wxCFStringRef( title
, m_font
.GetEncoding() ) );
1213 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1215 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1216 // the content view, so we have to retrieve it explicitly
1217 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1218 m_peer
->GetControlRefAddr() ) ;
1219 if ( !m_peer
->Ok() )
1221 // compatibility mode fallback
1222 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1225 // the root control level handler
1226 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1228 // Causes the inner part of the window not to be metal
1229 // if the style is used before window creation.
1230 #if 0 // TARGET_API_MAC_OSX
1231 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1233 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1234 MacSetMetalAppearance( true ) ;
1238 if ( m_macWindow
!= NULL
)
1240 MacSetUnifiedAppearance( true ) ;
1243 HIViewRef growBoxRef
= 0 ;
1244 err
= HIViewFindByID( HIViewGetRoot( (WindowRef
)m_macWindow
), kHIViewWindowGrowBoxID
, &growBoxRef
);
1245 if ( err
== noErr
&& growBoxRef
!= 0 )
1246 HIGrowBoxViewSetTransparent( growBoxRef
, true ) ;
1248 // the frame window event handler
1249 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1250 MacInstallTopLevelWindowEventHandler() ;
1252 DoSetWindowVariant( m_windowVariant
) ;
1256 if ( HasFlag(wxFRAME_SHAPED
) )
1258 // default shape matches the window size
1259 wxRegion
rgn( 0, 0, w
, h
);
1263 wxWindowCreateEvent
event(this);
1264 HandleWindowEvent(event
);
1267 void wxTopLevelWindowMac::ClearBackground()
1269 wxWindow::ClearBackground() ;
1272 // Raise the window to the top of the Z order
1273 void wxTopLevelWindowMac::Raise()
1275 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1278 // Lower the window to the bottom of the Z order
1279 void wxTopLevelWindowMac::Lower()
1281 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1284 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1286 if (s_macDeactivateWindow
)
1288 wxLogTrace(TRACE_ACTIVATE
,
1289 wxT("Doing delayed deactivation of %p"),
1290 s_macDeactivateWindow
);
1292 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1296 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool WXUNUSED(inIsActivating
) )
1298 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1300 if (s_macDeactivateWindow
== this)
1301 s_macDeactivateWindow
= NULL
;
1303 MacDelayedDeactivation(timestamp
);
1306 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1308 wxWindow::SetLabel( title
) ;
1309 SetWindowTitleWithCFString( (WindowRef
) m_macWindow
, wxCFStringRef( title
, m_font
.GetEncoding() ) ) ;
1312 wxString
wxTopLevelWindowMac::GetTitle() const
1314 return wxWindow::GetLabel();
1317 bool wxTopLevelWindowMac::Show(bool show
)
1319 if ( !wxTopLevelWindowBase::Show(show
) )
1322 bool plainTransition
= true;
1324 #if wxUSE_SYSTEM_OPTIONS
1325 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1326 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1331 if ( plainTransition
)
1332 ::ShowWindow( (WindowRef
)m_macWindow
);
1334 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1336 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1338 // because apps expect a size event to occur at this moment
1339 wxSizeEvent
event(GetSize() , m_windowId
);
1340 event
.SetEventObject(this);
1341 HandleWindowEvent(event
);
1345 if ( plainTransition
)
1346 ::HideWindow( (WindowRef
)m_macWindow
);
1348 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1354 bool wxTopLevelWindowMac::ShowWithEffect(wxShowEffect effect
,
1358 // TODO factor common code
1359 if ( !wxTopLevelWindowBase::Show(true) )
1362 WindowTransitionEffect transition
= 0 ;
1365 case wxSHOW_EFFECT_ROLL
:
1366 case wxSHOW_EFFECT_SLIDE
:
1367 transition
= kWindowGenieTransitionEffect
;
1369 case wxSHOW_EFFECT_BLEND
:
1370 transition
= kWindowFadeTransitionEffect
;
1372 case wxSHOW_EFFECT_EXPAND
:
1374 // having sheets would be fine, but this might lead to a repositioning
1377 transition
= kWindowSheetTransitionEffect
;
1380 transition
= kWindowZoomTransitionEffect
;
1384 TransitionWindowOptions options
;
1385 options
.version
= 0;
1386 options
.duration
= timeout
/ 1000.0;
1387 options
.window
= transition
== kWindowSheetTransitionEffect
? (WindowRef
) GetParent()->MacGetTopLevelWindowRef() :0;
1388 options
.userData
= 0;
1390 wxSize size
= wxGetDisplaySize();
1392 GetWindowBounds( (WindowRef
)m_macWindow
, kWindowStructureRgn
, &bounds
);
1393 CGRect hiBounds
= CGRectMake( bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
);
1395 if ( dir
& wxRIGHT
)
1397 hiBounds
.origin
.x
= size
.x
;
1398 hiBounds
.size
.width
= 0;
1402 hiBounds
.origin
.y
= 0;
1403 hiBounds
.size
.height
= 0;
1407 hiBounds
.origin
.y
= size
.y
;
1408 hiBounds
.size
.height
= 0;
1412 hiBounds
.origin
.x
= 0;
1413 hiBounds
.size
.width
= 0;
1416 ::TransitionWindowWithOptions( (WindowRef
)m_macWindow
, transition
, kWindowShowTransitionAction
, transition
== kWindowGenieTransitionEffect
? &hiBounds
: NULL
,
1419 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1421 // because apps expect a size event to occur at this moment
1422 wxSizeEvent
event(GetSize() , m_windowId
);
1423 event
.SetEventObject(this);
1424 HandleWindowEvent(event
);
1429 bool wxTopLevelWindowMac::HideWithEffect(wxShowEffect effect
,
1433 if ( !wxTopLevelWindowBase::Show(false) )
1436 WindowTransitionEffect transition
= 0 ;
1439 case wxSHOW_EFFECT_ROLL
:
1440 case wxSHOW_EFFECT_SLIDE
:
1441 transition
= kWindowGenieTransitionEffect
;
1443 case wxSHOW_EFFECT_BLEND
:
1444 transition
= kWindowFadeTransitionEffect
;
1446 case wxSHOW_EFFECT_EXPAND
:
1450 transition
= kWindowSheetTransitionEffect
;
1453 transition
= kWindowZoomTransitionEffect
;
1456 TransitionWindowOptions options
;
1457 options
.version
= 0;
1458 options
.duration
= timeout
/ 1000.0;
1459 options
.window
= transition
== kWindowSheetTransitionEffect
? (WindowRef
) GetParent()->MacGetTopLevelWindowRef() :0;
1460 options
.userData
= 0;
1462 wxSize size
= wxGetDisplaySize();
1464 GetWindowBounds( (WindowRef
)m_macWindow
, kWindowStructureRgn
, &bounds
);
1465 CGRect hiBounds
= CGRectMake( bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
);
1467 if ( dir
& wxRIGHT
)
1469 hiBounds
.origin
.x
= size
.x
;
1470 hiBounds
.size
.width
= 0;
1474 hiBounds
.origin
.y
= 0;
1475 hiBounds
.size
.height
= 0;
1479 hiBounds
.origin
.y
= size
.y
;
1480 hiBounds
.size
.height
= 0;
1484 hiBounds
.origin
.x
= 0;
1485 hiBounds
.size
.width
= 0;
1487 ::TransitionWindowWithOptions( (WindowRef
)m_macWindow
, transition
, kWindowHideTransitionAction
, transition
== kWindowGenieTransitionEffect
? &hiBounds
: NULL
,
1493 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1497 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1499 data
= new FullScreenData() ;
1501 m_macFullScreenData
= data
;
1502 data
->m_position
= GetPosition() ;
1503 data
->m_size
= GetSize() ;
1504 data
->m_wasResizable
= MacGetWindowAttributes() & kWindowResizableAttribute
;
1506 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1509 wxRect client
= wxGetClientDisplayRect() ;
1511 int left
, top
, right
, bottom
;
1519 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1521 if ( style
& wxFULLSCREEN_NOCAPTION
)
1527 if ( style
& wxFULLSCREEN_NOBORDER
)
1534 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1539 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1544 SetSize( x
, y
, w
, h
) ;
1545 if ( data
->m_wasResizable
)
1546 MacChangeWindowAttributes( kWindowNoAttributes
, kWindowResizableAttribute
) ;
1551 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1552 if ( data
->m_wasResizable
)
1553 MacChangeWindowAttributes( kWindowResizableAttribute
, kWindowNoAttributes
) ;
1554 SetPosition( data
->m_position
) ;
1555 SetSize( data
->m_size
) ;
1558 m_macFullScreenData
= NULL
;
1564 bool wxTopLevelWindowMac::IsFullScreen() const
1566 return m_macFullScreenData
!= NULL
;
1570 bool wxTopLevelWindowMac::SetTransparent(wxByte alpha
)
1572 OSStatus result
= SetWindowAlpha((WindowRef
)m_macWindow
, float(alpha
)/255.0);
1573 return result
== noErr
;
1577 bool wxTopLevelWindowMac::CanSetTransparent()
1583 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1585 if ( GetExtraStyle() == exStyle
)
1588 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1590 if ( m_macWindow
!= NULL
)
1592 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1594 if ( MacGetMetalAppearance() != metal
)
1596 if ( MacGetUnifiedAppearance() )
1597 MacSetUnifiedAppearance( !metal
) ;
1599 MacSetMetalAppearance( metal
) ;
1604 bool wxTopLevelWindowMac::SetBackgroundStyle(wxBackgroundStyle style
)
1606 if ( !wxTopLevelWindowBase::SetBackgroundStyle(style
) )
1609 WindowRef windowRef
= HIViewGetWindow( (HIViewRef
)GetHandle() );
1611 if ( GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
1613 OSStatus err
= HIWindowChangeFeatures( windowRef
, 0, kWindowIsOpaque
);
1614 verify_noerr( err
);
1615 err
= ReshapeCustomWindow( windowRef
);
1616 verify_noerr( err
);
1622 // TODO: switch to structure bounds -
1623 // we are still using coordinates of the content view
1625 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1627 Rect content
, structure
;
1629 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1630 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1632 left
= content
.left
- structure
.left
;
1633 top
= content
.top
- structure
.top
;
1634 right
= structure
.right
- content
.right
;
1635 bottom
= structure
.bottom
- content
.bottom
;
1638 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1640 m_cachedClippedRectValid
= false ;
1641 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1642 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1643 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1646 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1650 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1658 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1662 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1665 *width
= bounds
.right
- bounds
.left
;
1667 *height
= bounds
.bottom
- bounds
.top
;
1670 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1674 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1677 *width
= bounds
.right
- bounds
.left
;
1679 *height
= bounds
.bottom
- bounds
.top
;
1682 void wxTopLevelWindowMac::DoCentre(int dir
)
1684 if ( m_macWindow
!= 0 )
1685 wxTopLevelWindowBase::DoCentre(dir
);
1688 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1690 if ( MacGetUnifiedAppearance() )
1691 MacSetUnifiedAppearance( false ) ;
1693 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1694 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1697 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1699 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1702 void wxTopLevelWindowMac::MacSetUnifiedAppearance( bool set
)
1704 if ( MacGetMetalAppearance() )
1705 MacSetMetalAppearance( false ) ;
1707 MacChangeWindowAttributes( set
? kWindowUnifiedTitleAndToolbarAttribute
: kWindowNoAttributes
,
1708 set
? kWindowNoAttributes
: kWindowUnifiedTitleAndToolbarAttribute
) ;
1710 // For some reason, Tiger uses white as the background color for this appearance,
1711 // while most apps using it use the typical striped background. Restore that behavior
1713 // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
1715 SetBackgroundColour( wxSYS_COLOUR_WINDOW
) ;
1718 bool wxTopLevelWindowMac::MacGetUnifiedAppearance() const
1720 return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute
;
1723 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1725 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1728 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1731 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1736 void wxTopLevelWindowMac::MacPerformUpdates()
1738 // for composited windows this also triggers a redraw of all
1739 // invalid views in the window
1740 HIWindowFlush((WindowRef
) m_macWindow
) ;
1743 // Attracts the users attention to this window if the application is
1744 // inactive (should be called when a background event occurs)
1746 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1749 DisposePtr( (Ptr
)ptr
) ;
1752 void wxTopLevelWindowMac::RequestUserAttention(int WXUNUSED(flags
))
1754 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1755 static wxMacNMUPP
nmupp( wxMacNMResponse
);
1757 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1758 notificationRequest
->qType
= nmType
;
1759 notificationRequest
->nmMark
= 1 ;
1760 notificationRequest
->nmIcon
= 0 ;
1761 notificationRequest
->nmSound
= 0 ;
1762 notificationRequest
->nmStr
= NULL
;
1763 notificationRequest
->nmResp
= nmupp
;
1765 verify_noerr( NMInstall( notificationRequest
) ) ;
1768 // ---------------------------------------------------------------------------
1769 // Shape implementation
1770 // ---------------------------------------------------------------------------
1773 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1775 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1776 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1778 // The empty region signifies that the shape
1779 // should be removed from the window.
1780 if ( region
.IsEmpty() )
1782 wxSize sz
= GetClientSize();
1783 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1784 if ( rgn
.IsEmpty() )
1787 return SetShape(rgn
);
1790 // Make a copy of the region
1791 RgnHandle shapeRegion
= NewRgn();
1792 HIShapeGetAsQDRgn( region
.GetWXHRGN(), shapeRegion
);
1794 // Dispose of any shape region we may already have
1795 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1799 // Save the region so we can use it later
1800 SetWRefCon((WindowRef
)MacGetWindowRef(), (URefCon
)shapeRegion
);
1802 // inform the window manager that the window has changed shape
1803 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1808 // ---------------------------------------------------------------------------
1809 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1810 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1811 // ---------------------------------------------------------------------------
1813 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1815 GetWindowPortBounds(window
, inRect
);
1816 Point pt
= { inRect
->top
,inRect
->left
};
1817 wxMacLocalToGlobal( window
, &pt
) ;
1818 inRect
->bottom
+= pt
.v
- inRect
->top
;
1819 inRect
->right
+= pt
.h
- inRect
->left
;
1821 inRect
->left
= pt
.h
;
1824 static SInt32
wxShapedMacWindowGetFeatures(WindowRef
WXUNUSED(window
), SInt32 param
)
1826 /*------------------------------------------------------
1827 Define which options your custom window supports.
1828 --------------------------------------------------------*/
1829 //just enable everything for our demo
1830 *(OptionBits
*)param
=
1833 //kWindowCanCollapse |
1834 //kWindowCanGetWindowRegion |
1835 //kWindowHasTitleBar |
1836 //kWindowSupportsDragHilite |
1837 kWindowCanDrawInCurrentPort
|
1838 //kWindowCanMeasureTitle |
1839 kWindowWantsDisposeAtProcessDeath
|
1840 kWindowSupportsGetGrowImageRegion
|
1841 kWindowDefSupportsColorGrafPort
;
1846 // The content region is left as a rectangle matching the window size, this is
1847 // so the origin in the paint event, and etc. still matches what the
1848 // programmer expects.
1849 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1852 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1856 wxShapedMacWindowGetPos( window
, &r
) ;
1857 RectRgn( rgn
, &r
) ;
1861 // The structure region is set to the shape given to the SetShape method.
1862 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1864 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1870 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1871 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1872 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1873 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1877 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1879 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1884 switch (rgnRec
->regionCode
)
1886 case kWindowStructureRgn
:
1887 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1890 case kWindowContentRgn
:
1891 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1895 SetEmptyRgn(rgnRec
->winRgn
);
1902 // Determine the region of the window which was hit
1904 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1907 static RgnHandle tempRgn
= NULL
;
1909 if (tempRgn
== NULL
)
1912 // get the point clicked
1913 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1915 // Mac OS 8.5 or later
1916 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1917 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1920 // no significant area was hit
1924 static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode
), WindowRef window
, SInt16 message
, SInt32 param
)
1928 case kWindowMsgHitTest
:
1929 return wxShapedMacWindowHitTest(window
, param
);
1931 case kWindowMsgGetFeatures
:
1932 return wxShapedMacWindowGetFeatures(window
, param
);
1934 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1935 case kWindowMsgGetRegion
:
1936 return wxShapedMacWindowGetRegion(window
, param
);