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
->GetEventHandler()->ProcessEvent( 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
->GetEventHandler()->ProcessEvent( 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
->GetEventHandler()->ProcessEvent( 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
->GetEventHandler()->ProcessEvent( 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 ControlRef
wxMacFindSubControl( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, ControlRef superControl
, ControlPartCode
*outPart
)
397 UInt16 childrenCount
= 0 ;
398 ControlHandle sibling
;
400 OSStatus err
= CountSubControls( superControl
, &childrenCount
) ;
401 if ( err
== errControlIsNotEmbedder
)
404 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
406 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
408 err
= GetIndexedSubControl( superControl
, i
, & sibling
) ;
409 if ( err
== errControlIsNotEmbedder
)
412 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
413 if ( IsControlVisible( sibling
) )
415 UMAGetControlBoundsInWindowCoords( sibling
, &r
) ;
416 if ( MacPtInRect( location
, &r
) )
418 ControlHandle child
= wxMacFindSubControl( toplevelWindow
, location
, sibling
, outPart
) ;
425 Point testLocation
= location
;
427 if ( toplevelWindow
)
429 testLocation
.h
-= r
.left
;
430 testLocation
.v
-= r
.top
;
433 *outPart
= TestControl( sibling
, testLocation
) ;
446 #define NEW_CAPTURE_HANDLING 1
449 wxMacTopLevelMouseEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
453 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
455 OSStatus result
= eventNotHandledErr
;
457 wxMacCarbonEvent
cEvent( event
) ;
459 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
460 Point windowMouseLocation
= screenMouseLocation
;
462 WindowRef window
= NULL
;
463 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
465 wxWindow
* currentMouseWindow
= NULL
;
466 ControlRef control
= NULL
;
468 #if NEW_CAPTURE_HANDLING
469 if ( wxApp::s_captureWindow
)
471 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
472 windowPart
= inContent
;
478 wxMacGlobalToLocal( window
, &windowMouseLocation
) ;
480 if ( wxApp::s_captureWindow
481 #if !NEW_CAPTURE_HANDLING
482 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
486 currentMouseWindow
= wxApp::s_captureWindow
;
488 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
490 ControlPartCode part
;
491 control
= FindControlUnderMouse( windowMouseLocation
, window
, &part
) ;
492 // if there is no control below the mouse position, send the event to the toplevel window itself
495 currentMouseWindow
= (wxWindow
*) data
;
499 currentMouseWindow
= (wxWindow
*) wxFindControlFromMacControl( control
) ;
500 #ifndef __WXUNIVERSAL__
501 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
504 // for wxToolBar to function we have to send certaint events to it
505 // instead of its children (wxToolBarTools)
507 GetSuperControl(control
, &parent
);
508 wxWindow
*wxParent
= (wxWindow
*) wxFindControlFromMacControl( parent
) ;
509 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
510 currentMouseWindow
= wxParent
;
516 // disabled windows must not get any input messages
517 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
518 currentMouseWindow
= NULL
;
522 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
523 SetupMouseEvent( wxevent
, cEvent
) ;
525 // handle all enter / leave events
527 if ( currentMouseWindow
!= g_MacLastWindow
)
529 if ( g_MacLastWindow
)
531 wxMouseEvent
eventleave(wxevent
);
532 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
533 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
534 eventleave
.SetEventObject( g_MacLastWindow
) ;
535 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
538 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
541 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
544 if ( currentMouseWindow
)
546 wxMouseEvent
evententer(wxevent
);
547 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
548 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
549 evententer
.SetEventObject( currentMouseWindow
) ;
550 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
553 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
556 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
559 g_MacLastWindow
= currentMouseWindow
;
562 if ( windowPart
== inMenuBar
)
564 // special case menu bar, as we are having a low-level runloop we must do it ourselves
565 if ( cEvent
.GetKind() == kEventMouseDown
)
567 ::MenuSelect( screenMouseLocation
) ;
572 else if ( currentMouseWindow
)
574 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
576 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
578 wxevent
.SetEventObject( currentMouseWindow
) ;
579 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
581 // make tooltips current
584 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
585 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
588 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
590 if ((currentMouseWindowParent
!= NULL
) &&
591 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
592 currentMouseWindow
= NULL
;
598 // if the user code did _not_ handle the event, then perform the
599 // default processing
600 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
602 // ... that is set focus to this window
603 if (currentMouseWindow
->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
604 currentMouseWindow
->SetFocus();
607 // if built-in find control is finding the wrong control (ie static box instead of overlaid
608 // button, we cannot let the standard handler do its job, but must handle manually
610 if ( cEvent
.GetKind() == kEventMouseDown
)
612 if ( currentMouseWindow
->MacIsReallyEnabled() )
614 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
615 Point clickLocation
= windowMouseLocation
;
617 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
619 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
620 modifiers
, (ControlActionUPP
) -1 ) ;
622 if ((currentMouseWindowParent
!= NULL
) &&
623 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
625 currentMouseWindow
= NULL
;
633 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
635 wxApp::s_captureWindow
= NULL
;
641 wxWindow
* cursorTarget
= currentMouseWindow
;
642 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
644 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
646 cursorTarget
= cursorTarget
->GetParent() ;
648 cursorPoint
+= cursorTarget
->GetPosition();
652 else // currentMouseWindow == NULL
654 // don't mess with controls we don't know about
655 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
656 // so we try sending them the correct control directly
657 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
659 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
660 Point clickLocation
= windowMouseLocation
;
663 hiPoint
.x
= clickLocation
.h
;
664 hiPoint
.y
= clickLocation
.v
;
665 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
666 clickLocation
.h
= (int)hiPoint
.x
;
667 clickLocation
.v
= (int)hiPoint
.y
;
669 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
677 static pascal OSStatus
678 wxMacTopLevelWindowEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
682 OSStatus result
= eventNotHandledErr
;
684 wxMacCarbonEvent
cEvent( event
) ;
686 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
687 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
689 switch ( GetEventKind( event
) )
691 case kEventWindowActivated
:
693 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
694 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
695 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
696 wxevent
.SetEventObject(toplevelWindow
);
697 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
698 // we still sending an eventNotHandledErr in order to allow for default processing
702 case kEventWindowDeactivated
:
704 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
705 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
706 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
707 wxevent
.SetEventObject(toplevelWindow
);
708 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
709 // we still sending an eventNotHandledErr in order to allow for default processing
713 case kEventWindowShown
:
714 toplevelWindow
->Refresh() ;
718 case kEventWindowClose
:
719 toplevelWindow
->Close() ;
723 case kEventWindowBoundsChanged
:
725 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
726 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
727 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
728 if ( attributes
& kWindowBoundsChangeSizeChanged
)
730 #ifndef __WXUNIVERSAL__
731 // according to the other ports we handle this within the OS level
732 // resize event, not within a wxSizeEvent
733 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
736 frame
->PositionBars();
739 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
740 event
.SetEventObject( toplevelWindow
) ;
742 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
743 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
746 if ( attributes
& kWindowBoundsChangeOriginChanged
)
748 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
749 event
.SetEventObject( toplevelWindow
) ;
750 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
757 case kEventWindowBoundsChanging
:
759 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
760 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
762 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
764 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
765 int left
, top
, right
, bottom
;
766 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
771 newRect
.right
- newRect
.left
+ left
+ right
,
772 newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
774 // this is a EVT_SIZING not a EVT_SIZE type !
775 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
776 wxevent
.SetEventObject( toplevelWindow
) ;
778 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
779 adjustR
= wxevent
.GetRect() ;
781 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
782 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
783 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
784 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
785 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
786 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
787 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
788 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
789 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
790 if ( !EqualRect( &newRect
, &adjustedRect
) )
791 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
792 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
799 case kEventWindowGetRegion
:
801 if ( toplevelWindow
->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
803 WindowRegionCode windowRegionCode
;
805 // Fetch the region code that is being queried
806 GetEventParameter( event
,
807 kEventParamWindowRegionCode
,
808 typeWindowRegionCode
, NULL
,
809 sizeof windowRegionCode
, NULL
,
810 &windowRegionCode
) ;
812 // If it is the opaque region code then set the
813 // region to empty and return noErr to stop event
815 if ( windowRegionCode
== kWindowOpaqueRgn
) {
817 GetEventParameter( event
,
818 kEventParamRgnHandle
,
819 typeQDRgnHandle
, NULL
,
822 SetEmptyRgn(region
) ;
836 // mix this in from window.cpp
837 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
839 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
841 OSStatus result
= eventNotHandledErr
;
843 switch ( GetEventClass( event
) )
845 case kEventClassTextInput
:
846 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
849 case kEventClassKeyboard
:
850 result
= KeyboardEventHandler( handler
, event
, data
) ;
853 case kEventClassWindow
:
854 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
857 case kEventClassMouse
:
858 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
868 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
870 // ---------------------------------------------------------------------------
871 // wxWindowMac utility functions
872 // ---------------------------------------------------------------------------
874 // Find an item given the Macintosh Window Reference
876 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
878 static MacWindowMap wxWinMacWindowList
;
880 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
882 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
884 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
887 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
888 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
890 // adding NULL WindowRef is (first) surely a result of an error and
892 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
894 wxWinMacWindowList
[inWindowRef
] = win
;
897 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
898 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
900 MacWindowMap::iterator it
;
901 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
903 if ( it
->second
== win
)
905 wxWinMacWindowList
.erase(it
);
911 // ----------------------------------------------------------------------------
912 // wxTopLevelWindowMac creation
913 // ----------------------------------------------------------------------------
915 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
921 bool m_wasResizable
;
924 void wxTopLevelWindowMac::Init()
927 m_maximizeOnShow
= false;
930 m_macEventHandler
= NULL
;
931 m_macFullScreenData
= NULL
;
934 wxMacDeferredWindowDeleter::wxMacDeferredWindowDeleter( WindowRef windowRef
)
936 m_macWindow
= windowRef
;
939 wxMacDeferredWindowDeleter::~wxMacDeferredWindowDeleter()
941 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
944 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
946 const wxString
& title
,
950 const wxString
& name
)
955 m_windowStyle
= style
;
959 m_windowId
= id
== -1 ? NewControlId() : id
;
960 wxWindow::SetLabel( title
) ;
962 DoMacCreateRealWindow( parent
, title
, pos
, size
, style
, name
) ;
964 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
966 if (GetExtraStyle() & wxFRAME_EX_METAL
)
967 MacSetMetalAppearance(true);
969 wxTopLevelWindows
.Append(this);
972 parent
->AddChild(this);
977 wxTopLevelWindowMac::~wxTopLevelWindowMac()
982 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
984 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
987 if ( m_macEventHandler
)
989 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
990 m_macEventHandler
= NULL
;
993 wxRemoveMacWindowAssociation( this ) ;
995 if ( wxModelessWindows
.Find(this) )
996 wxModelessWindows
.DeleteObject(this);
998 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1000 m_macFullScreenData
= NULL
;
1002 // avoid dangling refs
1003 if ( s_macDeactivateWindow
== this )
1004 s_macDeactivateWindow
= NULL
;
1008 // ----------------------------------------------------------------------------
1009 // wxTopLevelWindowMac maximize/minimize
1010 // ----------------------------------------------------------------------------
1012 void wxTopLevelWindowMac::Maximize(bool maximize
)
1014 Point idealSize
= { 0 , 0 } ;
1017 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1019 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
1021 idealSize
.h
= bounds
.size
.width
;
1022 idealSize
.v
= bounds
.size
.height
;
1025 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
1026 idealSize
.h
= rect
.right
- rect
.left
;
1027 idealSize
.v
= rect
.bottom
- rect
.top
;
1030 ZoomWindowIdeal( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
1033 bool wxTopLevelWindowMac::IsMaximized() const
1035 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
1038 void wxTopLevelWindowMac::Iconize(bool iconize
)
1040 if ( IsWindowCollapsable( (WindowRef
)m_macWindow
) )
1041 CollapseWindow( (WindowRef
)m_macWindow
, iconize
) ;
1044 bool wxTopLevelWindowMac::IsIconized() const
1046 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1049 void wxTopLevelWindowMac::Restore()
1051 if ( IsMaximized() )
1053 else if ( IsIconized() )
1057 // ----------------------------------------------------------------------------
1058 // wxTopLevelWindowMac misc
1059 // ----------------------------------------------------------------------------
1061 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1063 return wxPoint(0, 0) ;
1066 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1068 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1070 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1072 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1076 void wxTopLevelWindowMacInstallTopLevelWindowEventHandler(WindowRef window
, EventHandlerRef
* handler
, void *ref
)
1078 InstallWindowEventHandler(window
, GetwxMacTopLevelEventHandlerUPP(),
1079 GetEventTypeCount(eventList
), eventList
, ref
, handler
);
1082 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1084 if ( m_macEventHandler
!= NULL
)
1086 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1088 wxTopLevelWindowMacInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow
),(EventHandlerRef
*)&m_macEventHandler
,this);
1091 void wxTopLevelWindowMac::MacCreateRealWindow(
1092 const wxString
& title
,
1096 const wxString
& name
)
1098 DoMacCreateRealWindow( NULL
, title
, pos
, size
, style
, name
);
1101 void wxTopLevelWindowMac::DoMacCreateRealWindow(
1103 const wxString
& title
,
1107 const wxString
& name
)
1109 OSStatus err
= noErr
;
1111 m_windowStyle
= style
;
1119 wxRect display
= wxGetClientDisplayRect() ;
1121 if ( x
== wxDefaultPosition
.x
)
1124 if ( y
== wxDefaultPosition
.y
)
1127 int w
= WidthDefault(size
.x
);
1128 int h
= HeightDefault(size
.y
);
1130 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1132 // translate the window attributes in the appropriate window class and attributes
1133 WindowClass wclass
= 0;
1134 WindowAttributes attr
= kWindowNoAttributes
;
1135 WindowGroupRef group
= NULL
;
1136 bool activationScopeSet
= false;
1137 WindowActivationScope activationScope
= kWindowActivationScopeNone
;
1139 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1142 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1143 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1144 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1147 if ( HasFlag( wxSTAY_ON_TOP
) )
1148 wclass
= kUtilityWindowClass
;
1150 wclass
= kFloatingWindowClass
;
1152 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1153 attr
|= kWindowSideTitlebarAttribute
;
1157 wclass
= kPlainWindowClass
;
1158 activationScopeSet
= true;
1159 activationScope
= kWindowActivationScopeNone
;
1162 else if ( HasFlag( wxPOPUP_WINDOW
) )
1165 // Until we've got a real wxPopupWindow class on wxMac make it a
1166 // little easier for wxFrame to be used to emulate it and workaround
1167 // the lack of wxPopupWindow.
1168 if ( HasFlag( wxBORDER_NONE
) )
1169 wclass
= kHelpWindowClass
; // has no border
1171 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1172 //attr |= kWindowNoShadowAttribute; // turn off the shadow Should we??
1173 group
= GetWindowGroupOfClass( // float above other windows
1174 kFloatingWindowClass
) ;
1176 else if ( HasFlag( wxCAPTION
) )
1178 wclass
= kDocumentWindowClass
;
1179 attr
|= kWindowInWindowMenuAttribute
;
1181 else if ( HasFlag( wxFRAME_DRAWER
) )
1183 wclass
= kDrawerWindowClass
;
1187 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1188 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1190 wclass
= kDocumentWindowClass
;
1192 else if ( HasFlag( wxNO_BORDER
) )
1194 wclass
= kSimpleWindowClass
;
1198 wclass
= kPlainWindowClass
;
1202 if ( wclass
!= kPlainWindowClass
)
1204 if ( HasFlag( wxMINIMIZE_BOX
) )
1205 attr
|= kWindowCollapseBoxAttribute
;
1207 if ( HasFlag( wxMAXIMIZE_BOX
) )
1208 attr
|= kWindowFullZoomAttribute
;
1210 if ( HasFlag( wxRESIZE_BORDER
) )
1211 attr
|= kWindowResizableAttribute
;
1213 if ( HasFlag( wxCLOSE_BOX
) )
1214 attr
|= kWindowCloseBoxAttribute
;
1216 attr
|= kWindowLiveResizeAttribute
;
1218 if ( HasFlag(wxSTAY_ON_TOP
) )
1219 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1221 if ( HasFlag( wxFRAME_FLOAT_ON_PARENT
) )
1222 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1224 if ( group
== NULL
&& parent
!= NULL
)
1226 WindowRef parenttlw
= (WindowRef
) parent
->MacGetTopLevelWindowRef();
1228 group
= GetWindowGroupParent( GetWindowGroup( parenttlw
) );
1231 attr
|= kWindowCompositingAttribute
;
1232 #if 0 // wxMAC_USE_CORE_GRAPHICS ; TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1233 attr
|= kWindowFrameworkScaledAttribute
;
1236 if ( HasFlag(wxFRAME_SHAPED
) )
1238 WindowDefSpec customWindowDefSpec
;
1239 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1240 customWindowDefSpec
.u
.defProc
=
1242 (WindowDefUPP
) wxShapedMacWindowDef
;
1244 NewWindowDefUPP(wxShapedMacWindowDef
);
1246 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1247 attr
, &theBoundsRect
,
1248 (WindowRef
*) &m_macWindow
);
1252 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1255 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1256 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1258 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1260 // setup a separate group for each window, so that overlays can be handled easily
1262 WindowGroupRef overlaygroup
= NULL
;
1263 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &overlaygroup
));
1264 verify_noerr( SetWindowGroupParent( overlaygroup
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1265 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, overlaygroup
));
1267 if ( activationScopeSet
)
1269 verify_noerr( SetWindowActivationScope( (WindowRef
) m_macWindow
, activationScope
));
1272 // the create commands are only for content rect,
1273 // so we have to set the size again as structure bounds
1274 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1276 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1277 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1278 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1280 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1281 // the content view, so we have to retrieve it explicitly
1282 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1283 m_peer
->GetControlRefAddr() ) ;
1284 if ( !m_peer
->Ok() )
1286 // compatibility mode fallback
1287 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1290 // the root control level handler
1291 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1293 // Causes the inner part of the window not to be metal
1294 // if the style is used before window creation.
1295 #if 0 // TARGET_API_MAC_OSX
1296 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1298 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1299 MacSetMetalAppearance( true ) ;
1303 if ( m_macWindow
!= NULL
)
1305 MacSetUnifiedAppearance( true ) ;
1308 HIViewRef growBoxRef
= 0 ;
1309 err
= HIViewFindByID( HIViewGetRoot( (WindowRef
)m_macWindow
), kHIViewWindowGrowBoxID
, &growBoxRef
);
1310 if ( err
== noErr
&& growBoxRef
!= 0 )
1311 HIGrowBoxViewSetTransparent( growBoxRef
, true ) ;
1313 // the frame window event handler
1314 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1315 MacInstallTopLevelWindowEventHandler() ;
1317 DoSetWindowVariant( m_windowVariant
) ;
1321 if ( HasFlag(wxFRAME_SHAPED
) )
1323 // default shape matches the window size
1324 wxRegion
rgn( 0, 0, w
, h
);
1328 wxWindowCreateEvent
event(this);
1329 GetEventHandler()->ProcessEvent(event
);
1332 void wxTopLevelWindowMac::ClearBackground()
1334 wxWindow::ClearBackground() ;
1337 // Raise the window to the top of the Z order
1338 void wxTopLevelWindowMac::Raise()
1340 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1343 // Lower the window to the bottom of the Z order
1344 void wxTopLevelWindowMac::Lower()
1346 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1349 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1351 if (s_macDeactivateWindow
)
1353 wxLogTrace(TRACE_ACTIVATE
,
1354 wxT("Doing delayed deactivation of %p"),
1355 s_macDeactivateWindow
);
1357 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1361 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool WXUNUSED(inIsActivating
) )
1363 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1365 if (s_macDeactivateWindow
== this)
1366 s_macDeactivateWindow
= NULL
;
1368 MacDelayedDeactivation(timestamp
);
1369 MacPropagateHiliteChanged() ;
1372 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1374 wxWindow::SetLabel( title
) ;
1375 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1378 wxString
wxTopLevelWindowMac::GetTitle() const
1380 return wxWindow::GetLabel();
1383 bool wxTopLevelWindowMac::Show(bool show
)
1385 if ( !wxTopLevelWindowBase::Show(show
) )
1388 bool plainTransition
= true;
1390 #if wxUSE_SYSTEM_OPTIONS
1391 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1392 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1397 if ( plainTransition
)
1398 ::ShowWindow( (WindowRef
)m_macWindow
);
1400 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1402 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1404 // because apps expect a size event to occur at this moment
1405 wxSizeEvent
event(GetSize() , m_windowId
);
1406 event
.SetEventObject(this);
1407 GetEventHandler()->ProcessEvent(event
);
1411 if ( plainTransition
)
1412 ::HideWindow( (WindowRef
)m_macWindow
);
1414 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1417 MacPropagateVisibilityChanged() ;
1422 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1426 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1428 data
= new FullScreenData() ;
1430 m_macFullScreenData
= data
;
1431 data
->m_position
= GetPosition() ;
1432 data
->m_size
= GetSize() ;
1433 data
->m_wasResizable
= MacGetWindowAttributes() & kWindowResizableAttribute
;
1435 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1438 wxRect client
= wxGetClientDisplayRect() ;
1440 int left
, top
, right
, bottom
;
1448 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1450 if ( style
& wxFULLSCREEN_NOCAPTION
)
1456 if ( style
& wxFULLSCREEN_NOBORDER
)
1463 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1468 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1473 SetSize( x
, y
, w
, h
) ;
1474 if ( data
->m_wasResizable
)
1475 MacChangeWindowAttributes( kWindowNoAttributes
, kWindowResizableAttribute
) ;
1480 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1481 if ( data
->m_wasResizable
)
1482 MacChangeWindowAttributes( kWindowResizableAttribute
, kWindowNoAttributes
) ;
1483 SetPosition( data
->m_position
) ;
1484 SetSize( data
->m_size
) ;
1487 m_macFullScreenData
= NULL
;
1493 bool wxTopLevelWindowMac::IsFullScreen() const
1495 return m_macFullScreenData
!= NULL
;
1499 bool wxTopLevelWindowMac::SetTransparent(wxByte alpha
)
1501 OSStatus result
= SetWindowAlpha((WindowRef
)m_macWindow
, float(alpha
)/255.0);
1502 return result
== noErr
;
1506 bool wxTopLevelWindowMac::CanSetTransparent()
1512 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1514 if ( GetExtraStyle() == exStyle
)
1517 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1519 if ( m_macWindow
!= NULL
)
1521 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1523 if ( MacGetMetalAppearance() != metal
)
1525 if ( MacGetUnifiedAppearance() )
1526 MacSetUnifiedAppearance( !metal
) ;
1528 MacSetMetalAppearance( metal
) ;
1533 bool wxTopLevelWindowMac::SetBackgroundStyle(wxBackgroundStyle style
)
1535 if ( !wxTopLevelWindowBase::SetBackgroundStyle(style
) )
1538 WindowRef windowRef
= HIViewGetWindow( (HIViewRef
)GetHandle() );
1540 if ( GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
1542 OSStatus err
= HIWindowChangeFeatures( windowRef
, 0, kWindowIsOpaque
);
1543 verify_noerr( err
);
1544 err
= ReshapeCustomWindow( windowRef
);
1545 verify_noerr( err
);
1551 // TODO: switch to structure bounds -
1552 // we are still using coordinates of the content view
1554 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1556 Rect content
, structure
;
1558 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1559 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1561 left
= content
.left
- structure
.left
;
1562 top
= content
.top
- structure
.top
;
1563 right
= structure
.right
- content
.right
;
1564 bottom
= structure
.bottom
- content
.bottom
;
1567 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1569 m_cachedClippedRectValid
= false ;
1570 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1571 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1572 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1575 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1579 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1587 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1591 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1594 *width
= bounds
.right
- bounds
.left
;
1596 *height
= bounds
.bottom
- bounds
.top
;
1599 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1603 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1606 *width
= bounds
.right
- bounds
.left
;
1608 *height
= bounds
.bottom
- bounds
.top
;
1611 void wxTopLevelWindowMac::DoCentre(int dir
)
1613 if ( m_macWindow
!= 0 )
1614 wxTopLevelWindowBase::DoCentre(dir
);
1617 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1619 if ( MacGetUnifiedAppearance() )
1620 MacSetUnifiedAppearance( false ) ;
1622 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1623 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1626 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1628 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1631 void wxTopLevelWindowMac::MacSetUnifiedAppearance( bool set
)
1633 if ( MacGetMetalAppearance() )
1634 MacSetMetalAppearance( false ) ;
1636 MacChangeWindowAttributes( set
? kWindowUnifiedTitleAndToolbarAttribute
: kWindowNoAttributes
,
1637 set
? kWindowNoAttributes
: kWindowUnifiedTitleAndToolbarAttribute
) ;
1639 // For some reason, Tiger uses white as the background color for this appearance,
1640 // while most apps using it use the typical striped background. Restore that behavior
1642 // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
1644 SetBackgroundColour( wxSYS_COLOUR_WINDOW
) ;
1647 bool wxTopLevelWindowMac::MacGetUnifiedAppearance() const
1649 return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute
;
1652 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1654 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1657 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1660 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1665 void wxTopLevelWindowMac::MacPerformUpdates()
1667 // for composited windows this also triggers a redraw of all
1668 // invalid views in the window
1669 HIWindowFlush((WindowRef
) m_macWindow
) ;
1672 // Attracts the users attention to this window if the application is
1673 // inactive (should be called when a background event occurs)
1675 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1678 DisposePtr( (Ptr
)ptr
) ;
1681 void wxTopLevelWindowMac::RequestUserAttention(int WXUNUSED(flags
))
1683 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1684 static wxMacNMUPP
nmupp( wxMacNMResponse
);
1686 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1687 notificationRequest
->qType
= nmType
;
1688 notificationRequest
->nmMark
= 1 ;
1689 notificationRequest
->nmIcon
= 0 ;
1690 notificationRequest
->nmSound
= 0 ;
1691 notificationRequest
->nmStr
= NULL
;
1692 notificationRequest
->nmResp
= nmupp
;
1694 verify_noerr( NMInstall( notificationRequest
) ) ;
1697 // ---------------------------------------------------------------------------
1698 // Shape implementation
1699 // ---------------------------------------------------------------------------
1702 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1704 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1705 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1707 // The empty region signifies that the shape
1708 // should be removed from the window.
1709 if ( region
.IsEmpty() )
1711 wxSize sz
= GetClientSize();
1712 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1713 if ( rgn
.IsEmpty() )
1716 return SetShape(rgn
);
1719 // Make a copy of the region
1720 RgnHandle shapeRegion
= NewRgn();
1721 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1723 // Dispose of any shape region we may already have
1724 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1728 // Save the region so we can use it later
1729 SetWRefCon((WindowRef
)MacGetWindowRef(), (URefCon
)shapeRegion
);
1731 // inform the window manager that the window has changed shape
1732 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1737 // ---------------------------------------------------------------------------
1738 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1739 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1740 // ---------------------------------------------------------------------------
1742 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1744 GetWindowPortBounds(window
, inRect
);
1745 Point pt
= { inRect
->top
,inRect
->left
};
1746 wxMacLocalToGlobal( window
, &pt
) ;
1747 inRect
->bottom
+= pt
.v
- inRect
->top
;
1748 inRect
->right
+= pt
.h
- inRect
->left
;
1750 inRect
->left
= pt
.h
;
1753 static SInt32
wxShapedMacWindowGetFeatures(WindowRef
WXUNUSED(window
), SInt32 param
)
1755 /*------------------------------------------------------
1756 Define which options your custom window supports.
1757 --------------------------------------------------------*/
1758 //just enable everything for our demo
1759 *(OptionBits
*)param
=
1762 //kWindowCanCollapse |
1763 //kWindowCanGetWindowRegion |
1764 //kWindowHasTitleBar |
1765 //kWindowSupportsDragHilite |
1766 kWindowCanDrawInCurrentPort
|
1767 //kWindowCanMeasureTitle |
1768 kWindowWantsDisposeAtProcessDeath
|
1769 kWindowSupportsGetGrowImageRegion
|
1770 kWindowDefSupportsColorGrafPort
;
1775 // The content region is left as a rectangle matching the window size, this is
1776 // so the origin in the paint event, and etc. still matches what the
1777 // programmer expects.
1778 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1781 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1785 wxShapedMacWindowGetPos( window
, &r
) ;
1786 RectRgn( rgn
, &r
) ;
1790 // The structure region is set to the shape given to the SetShape method.
1791 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1793 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1799 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1800 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1801 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1802 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1806 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1808 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1813 switch (rgnRec
->regionCode
)
1815 case kWindowStructureRgn
:
1816 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1819 case kWindowContentRgn
:
1820 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1824 SetEmptyRgn(rgnRec
->winRgn
);
1831 // Determine the region of the window which was hit
1833 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1836 static RgnHandle tempRgn
= NULL
;
1838 if (tempRgn
== NULL
)
1841 // get the point clicked
1842 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1844 // Mac OS 8.5 or later
1845 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1846 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1849 // no significant area was hit
1853 static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode
), WindowRef window
, SInt16 message
, SInt32 param
)
1857 case kWindowMsgHitTest
:
1858 return wxShapedMacWindowHitTest(window
, param
);
1860 case kWindowMsgGetFeatures
:
1861 return wxShapedMacWindowGetFeatures(window
, param
);
1863 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1864 case kWindowMsgGetRegion
:
1865 return wxShapedMacWindowGetRegion(window
, param
);