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
) ;
445 ControlRef
wxMacFindControlUnderMouse( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, WindowRef window
, ControlPartCode
*outPart
)
447 #if TARGET_API_MAC_OSX
448 if ( UMAGetSystemVersion() >= 0x1030 )
449 return FindControlUnderMouse( location
, window
, outPart
) ;
452 ControlRef rootControl
= NULL
;
453 verify_noerr( GetRootControl( window
, &rootControl
) ) ;
455 return wxMacFindSubControl( toplevelWindow
, location
, rootControl
, outPart
) ;
458 #define NEW_CAPTURE_HANDLING 1
461 wxMacTopLevelMouseEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
465 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
467 OSStatus result
= eventNotHandledErr
;
469 wxMacCarbonEvent
cEvent( event
) ;
471 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
472 Point windowMouseLocation
= screenMouseLocation
;
474 WindowRef window
= NULL
;
475 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
477 wxWindow
* currentMouseWindow
= NULL
;
478 ControlRef control
= NULL
;
480 #if NEW_CAPTURE_HANDLING
481 if ( wxApp::s_captureWindow
)
483 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
484 windowPart
= inContent
;
490 wxMacGlobalToLocal( window
, &windowMouseLocation
) ;
492 if ( wxApp::s_captureWindow
493 #if !NEW_CAPTURE_HANDLING
494 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
498 currentMouseWindow
= wxApp::s_captureWindow
;
500 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
502 ControlPartCode part
;
503 control
= FindControlUnderMouse( windowMouseLocation
, window
, &part
) ;
504 // if there is no control below the mouse position, send the event to the toplevel window itself
507 currentMouseWindow
= (wxWindow
*) data
;
511 currentMouseWindow
= (wxWindow
*) wxFindControlFromMacControl( control
) ;
512 #ifndef __WXUNIVERSAL__
513 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
516 // for wxToolBar to function we have to send certaint events to it
517 // instead of its children (wxToolBarTools)
519 GetSuperControl(control
, &parent
);
520 wxWindow
*wxParent
= (wxWindow
*) wxFindControlFromMacControl( parent
) ;
521 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
522 currentMouseWindow
= wxParent
;
528 // disabled windows must not get any input messages
529 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
530 currentMouseWindow
= NULL
;
534 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
535 SetupMouseEvent( wxevent
, cEvent
) ;
537 // handle all enter / leave events
539 if ( currentMouseWindow
!= g_MacLastWindow
)
541 if ( g_MacLastWindow
)
543 wxMouseEvent
eventleave(wxevent
);
544 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
545 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
546 eventleave
.SetEventObject( g_MacLastWindow
) ;
547 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
550 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
553 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
556 if ( currentMouseWindow
)
558 wxMouseEvent
evententer(wxevent
);
559 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
560 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
561 evententer
.SetEventObject( currentMouseWindow
) ;
562 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
565 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
568 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
571 g_MacLastWindow
= currentMouseWindow
;
574 if ( windowPart
== inMenuBar
)
576 // special case menu bar, as we are having a low-level runloop we must do it ourselves
577 if ( cEvent
.GetKind() == kEventMouseDown
)
579 ::MenuSelect( screenMouseLocation
) ;
584 else if ( currentMouseWindow
)
586 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
588 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
590 wxevent
.SetEventObject( currentMouseWindow
) ;
591 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
593 // make tooltips current
596 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
597 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
600 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
602 if ((currentMouseWindowParent
!= NULL
) &&
603 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
604 currentMouseWindow
= NULL
;
610 // if the user code did _not_ handle the event, then perform the
611 // default processing
612 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
614 // ... that is set focus to this window
615 if (currentMouseWindow
->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
616 currentMouseWindow
->SetFocus();
619 ControlPartCode dummyPart
;
620 // if built-in find control is finding the wrong control (ie static box instead of overlaid
621 // button, we cannot let the standard handler do its job, but must handle manually
623 if ( ( cEvent
.GetKind() == kEventMouseDown
)
626 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
627 wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &dummyPart
) )
631 if ( currentMouseWindow
->MacIsReallyEnabled() )
633 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
634 Point clickLocation
= windowMouseLocation
;
636 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
638 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
639 modifiers
, (ControlActionUPP
) -1 ) ;
641 if ((currentMouseWindowParent
!= NULL
) &&
642 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
644 currentMouseWindow
= NULL
;
652 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
654 wxApp::s_captureWindow
= NULL
;
660 wxWindow
* cursorTarget
= currentMouseWindow
;
661 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
663 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
665 cursorTarget
= cursorTarget
->GetParent() ;
667 cursorPoint
+= cursorTarget
->GetPosition();
671 else // currentMouseWindow == NULL
673 // don't mess with controls we don't know about
674 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
675 // so we try sending them the correct control directly
676 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
678 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
679 Point clickLocation
= windowMouseLocation
;
680 #if TARGET_API_MAC_OSX
682 hiPoint
.x
= clickLocation
.h
;
683 hiPoint
.y
= clickLocation
.v
;
684 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
685 clickLocation
.h
= (int)hiPoint
.x
;
686 clickLocation
.v
= (int)hiPoint
.y
;
687 #endif // TARGET_API_MAC_OSX
689 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
697 static pascal OSStatus
698 wxMacTopLevelWindowEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
702 OSStatus result
= eventNotHandledErr
;
704 wxMacCarbonEvent
cEvent( event
) ;
706 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
707 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
709 switch ( GetEventKind( event
) )
711 case kEventWindowActivated
:
713 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
714 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
715 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
716 wxevent
.SetEventObject(toplevelWindow
);
717 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
718 // we still sending an eventNotHandledErr in order to allow for default processing
722 case kEventWindowDeactivated
:
724 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
725 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
726 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
727 wxevent
.SetEventObject(toplevelWindow
);
728 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
729 // we still sending an eventNotHandledErr in order to allow for default processing
733 case kEventWindowShown
:
734 toplevelWindow
->Refresh() ;
738 case kEventWindowClose
:
739 toplevelWindow
->Close() ;
743 case kEventWindowBoundsChanged
:
745 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
746 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
747 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
748 if ( attributes
& kWindowBoundsChangeSizeChanged
)
750 #ifndef __WXUNIVERSAL__
751 // according to the other ports we handle this within the OS level
752 // resize event, not within a wxSizeEvent
753 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
756 frame
->PositionBars();
759 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
760 event
.SetEventObject( toplevelWindow
) ;
762 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
763 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
766 if ( attributes
& kWindowBoundsChangeOriginChanged
)
768 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
769 event
.SetEventObject( toplevelWindow
) ;
770 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
777 case kEventWindowBoundsChanging
:
779 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
780 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
782 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
784 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
785 int left
, top
, right
, bottom
;
786 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
791 newRect
.right
- newRect
.left
+ left
+ right
,
792 newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
794 // this is a EVT_SIZING not a EVT_SIZE type !
795 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
796 wxevent
.SetEventObject( toplevelWindow
) ;
798 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
799 adjustR
= wxevent
.GetRect() ;
801 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
802 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
803 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
804 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
805 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
806 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
807 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
808 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
809 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
810 if ( !EqualRect( &newRect
, &adjustedRect
) )
811 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
812 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
819 case kEventWindowGetRegion
:
821 if ( toplevelWindow
->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
823 WindowRegionCode windowRegionCode
;
825 // Fetch the region code that is being queried
826 GetEventParameter( event
,
827 kEventParamWindowRegionCode
,
828 typeWindowRegionCode
, NULL
,
829 sizeof windowRegionCode
, NULL
,
830 &windowRegionCode
) ;
832 // If it is the opaque region code then set the
833 // region to empty and return noErr to stop event
835 if ( windowRegionCode
== kWindowOpaqueRgn
) {
837 GetEventParameter( event
,
838 kEventParamRgnHandle
,
839 typeQDRgnHandle
, NULL
,
842 SetEmptyRgn(region
) ;
856 // mix this in from window.cpp
857 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
859 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
861 OSStatus result
= eventNotHandledErr
;
863 switch ( GetEventClass( event
) )
865 case kEventClassTextInput
:
866 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
869 case kEventClassKeyboard
:
870 result
= KeyboardEventHandler( handler
, event
, data
) ;
873 case kEventClassWindow
:
874 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
877 case kEventClassMouse
:
878 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
888 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
890 // ---------------------------------------------------------------------------
891 // wxWindowMac utility functions
892 // ---------------------------------------------------------------------------
894 // Find an item given the Macintosh Window Reference
896 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
898 static MacWindowMap wxWinMacWindowList
;
900 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
902 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
904 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
907 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
908 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
910 // adding NULL WindowRef is (first) surely a result of an error and
912 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
914 wxWinMacWindowList
[inWindowRef
] = win
;
917 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
918 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
920 MacWindowMap::iterator it
;
921 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
923 if ( it
->second
== win
)
925 wxWinMacWindowList
.erase(it
);
931 // ----------------------------------------------------------------------------
932 // wxTopLevelWindowMac creation
933 // ----------------------------------------------------------------------------
935 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
941 bool m_wasResizable
;
944 void wxTopLevelWindowMac::Init()
947 m_maximizeOnShow
= false;
950 m_macEventHandler
= NULL
;
951 m_macFullScreenData
= NULL
;
954 wxMacDeferredWindowDeleter::wxMacDeferredWindowDeleter( WindowRef windowRef
)
956 m_macWindow
= windowRef
;
959 wxMacDeferredWindowDeleter::~wxMacDeferredWindowDeleter()
961 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
964 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
966 const wxString
& title
,
970 const wxString
& name
)
975 m_windowStyle
= style
;
979 m_windowId
= id
== -1 ? NewControlId() : id
;
980 wxWindow::SetLabel( title
) ;
982 DoMacCreateRealWindow( parent
, title
, pos
, size
, style
, name
) ;
984 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
986 if (GetExtraStyle() & wxFRAME_EX_METAL
)
987 MacSetMetalAppearance(true);
989 wxTopLevelWindows
.Append(this);
992 parent
->AddChild(this);
997 wxTopLevelWindowMac::~wxTopLevelWindowMac()
1002 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
1004 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
1007 if ( m_macEventHandler
)
1009 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1010 m_macEventHandler
= NULL
;
1013 wxRemoveMacWindowAssociation( this ) ;
1015 if ( wxModelessWindows
.Find(this) )
1016 wxModelessWindows
.DeleteObject(this);
1018 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1020 m_macFullScreenData
= NULL
;
1022 // avoid dangling refs
1023 if ( s_macDeactivateWindow
== this )
1024 s_macDeactivateWindow
= NULL
;
1028 // ----------------------------------------------------------------------------
1029 // wxTopLevelWindowMac maximize/minimize
1030 // ----------------------------------------------------------------------------
1032 void wxTopLevelWindowMac::Maximize(bool maximize
)
1034 Point idealSize
= { 0 , 0 } ;
1037 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1039 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
1041 idealSize
.h
= bounds
.size
.width
;
1042 idealSize
.v
= bounds
.size
.height
;
1045 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
1046 idealSize
.h
= rect
.right
- rect
.left
;
1047 idealSize
.v
= rect
.bottom
- rect
.top
;
1050 ZoomWindowIdeal( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
1053 bool wxTopLevelWindowMac::IsMaximized() const
1055 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
1058 void wxTopLevelWindowMac::Iconize(bool iconize
)
1060 if ( IsWindowCollapsable( (WindowRef
)m_macWindow
) )
1061 CollapseWindow( (WindowRef
)m_macWindow
, iconize
) ;
1064 bool wxTopLevelWindowMac::IsIconized() const
1066 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1069 void wxTopLevelWindowMac::Restore()
1071 if ( IsMaximized() )
1073 else if ( IsIconized() )
1077 // ----------------------------------------------------------------------------
1078 // wxTopLevelWindowMac misc
1079 // ----------------------------------------------------------------------------
1081 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1083 return wxPoint(0, 0) ;
1086 #ifndef __WXUNIVERSAL__
1087 void wxTopLevelWindowMac::SetIcons( const wxIconBundle
& icons
)
1089 // { SetIcon( icons.GetIcon( -1 ) ); }
1093 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1095 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1097 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1099 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1103 void wxTopLevelWindowMacInstallTopLevelWindowEventHandler(WindowRef window
, EventHandlerRef
* handler
, void *ref
)
1105 InstallWindowEventHandler(window
, GetwxMacTopLevelEventHandlerUPP(),
1106 GetEventTypeCount(eventList
), eventList
, ref
, handler
);
1109 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1111 if ( m_macEventHandler
!= NULL
)
1113 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1115 wxTopLevelWindowMacInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow
),(EventHandlerRef
*)&m_macEventHandler
,this);
1118 void wxTopLevelWindowMac::MacCreateRealWindow(
1119 const wxString
& title
,
1123 const wxString
& name
)
1125 DoMacCreateRealWindow( NULL
, title
, pos
, size
, style
, name
);
1128 void wxTopLevelWindowMac::DoMacCreateRealWindow(
1130 const wxString
& title
,
1134 const wxString
& name
)
1136 OSStatus err
= noErr
;
1138 m_windowStyle
= style
;
1146 wxRect display
= wxGetClientDisplayRect() ;
1148 if ( x
== wxDefaultPosition
.x
)
1151 if ( y
== wxDefaultPosition
.y
)
1154 int w
= WidthDefault(size
.x
);
1155 int h
= HeightDefault(size
.y
);
1157 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1159 // translate the window attributes in the appropriate window class and attributes
1160 WindowClass wclass
= 0;
1161 WindowAttributes attr
= kWindowNoAttributes
;
1162 WindowGroupRef group
= NULL
;
1163 bool activationScopeSet
= false;
1164 WindowActivationScope activationScope
= kWindowActivationScopeNone
;
1166 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1169 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1170 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1171 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1174 if ( HasFlag( wxSTAY_ON_TOP
) )
1175 wclass
= kUtilityWindowClass
;
1177 wclass
= kFloatingWindowClass
;
1179 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1180 attr
|= kWindowSideTitlebarAttribute
;
1184 wclass
= kPlainWindowClass
;
1185 activationScopeSet
= true;
1186 activationScope
= kWindowActivationScopeNone
;
1189 else if ( HasFlag( wxPOPUP_WINDOW
) )
1192 // Until we've got a real wxPopupWindow class on wxMac make it a
1193 // little easier for wxFrame to be used to emulate it and workaround
1194 // the lack of wxPopupWindow.
1195 if ( HasFlag( wxBORDER_NONE
) )
1196 wclass
= kHelpWindowClass
; // has no border
1198 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1199 //attr |= kWindowNoShadowAttribute; // turn off the shadow Should we??
1200 group
= GetWindowGroupOfClass( // float above other windows
1201 kFloatingWindowClass
) ;
1203 else if ( HasFlag( wxCAPTION
) )
1205 wclass
= kDocumentWindowClass
;
1206 attr
|= kWindowInWindowMenuAttribute
;
1208 else if ( HasFlag( wxFRAME_DRAWER
) )
1210 wclass
= kDrawerWindowClass
;
1214 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1215 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1217 wclass
= kDocumentWindowClass
;
1219 else if ( HasFlag( wxNO_BORDER
) )
1221 wclass
= kSimpleWindowClass
;
1225 wclass
= kPlainWindowClass
;
1229 if ( wclass
!= kPlainWindowClass
)
1231 if ( HasFlag( wxMINIMIZE_BOX
) )
1232 attr
|= kWindowCollapseBoxAttribute
;
1234 if ( HasFlag( wxMAXIMIZE_BOX
) )
1235 attr
|= kWindowFullZoomAttribute
;
1237 if ( HasFlag( wxRESIZE_BORDER
) )
1238 attr
|= kWindowResizableAttribute
;
1240 if ( HasFlag( wxCLOSE_BOX
) )
1241 attr
|= kWindowCloseBoxAttribute
;
1244 // turn on live resizing (OS X only)
1245 if (UMAGetSystemVersion() >= 0x1000)
1246 attr
|= kWindowLiveResizeAttribute
;
1248 if ( HasFlag(wxSTAY_ON_TOP
) )
1249 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1251 if ( HasFlag( wxFRAME_FLOAT_ON_PARENT
) )
1252 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1254 if ( group
== NULL
&& parent
!= NULL
)
1256 WindowRef parenttlw
= (WindowRef
) parent
->MacGetTopLevelWindowRef();
1258 group
= GetWindowGroupParent( GetWindowGroup( parenttlw
) );
1261 attr
|= kWindowCompositingAttribute
;
1262 #if 0 // wxMAC_USE_CORE_GRAPHICS ; TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1263 attr
|= kWindowFrameworkScaledAttribute
;
1266 if ( HasFlag(wxFRAME_SHAPED
) )
1268 WindowDefSpec customWindowDefSpec
;
1269 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1270 customWindowDefSpec
.u
.defProc
=
1272 (WindowDefUPP
) wxShapedMacWindowDef
;
1274 NewWindowDefUPP(wxShapedMacWindowDef
);
1276 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1277 attr
, &theBoundsRect
,
1278 (WindowRef
*) &m_macWindow
);
1282 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1285 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1286 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1288 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1290 // setup a separate group for each window, so that overlays can be handled easily
1292 WindowGroupRef overlaygroup
= NULL
;
1293 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &overlaygroup
));
1294 verify_noerr( SetWindowGroupParent( overlaygroup
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1295 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, overlaygroup
));
1297 if ( activationScopeSet
)
1299 verify_noerr( SetWindowActivationScope( (WindowRef
) m_macWindow
, activationScope
));
1302 // the create commands are only for content rect,
1303 // so we have to set the size again as structure bounds
1304 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1306 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1307 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1308 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1310 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1311 // the content view, so we have to retrieve it explicitly
1312 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1313 m_peer
->GetControlRefAddr() ) ;
1314 if ( !m_peer
->Ok() )
1316 // compatibility mode fallback
1317 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1320 // the root control level handler
1321 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1323 // Causes the inner part of the window not to be metal
1324 // if the style is used before window creation.
1325 #if 0 // TARGET_API_MAC_OSX
1326 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1328 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1329 MacSetMetalAppearance( true ) ;
1333 #if TARGET_API_MAC_OSX
1334 if ( m_macWindow
!= NULL
)
1336 MacSetUnifiedAppearance( true ) ;
1340 HIViewRef growBoxRef
= 0 ;
1341 err
= HIViewFindByID( HIViewGetRoot( (WindowRef
)m_macWindow
), kHIViewWindowGrowBoxID
, &growBoxRef
);
1342 if ( err
== noErr
&& growBoxRef
!= 0 )
1343 HIGrowBoxViewSetTransparent( growBoxRef
, true ) ;
1345 // the frame window event handler
1346 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1347 MacInstallTopLevelWindowEventHandler() ;
1349 DoSetWindowVariant( m_windowVariant
) ;
1353 if ( HasFlag(wxFRAME_SHAPED
) )
1355 // default shape matches the window size
1356 wxRegion
rgn( 0, 0, w
, h
);
1360 wxWindowCreateEvent
event(this);
1361 GetEventHandler()->ProcessEvent(event
);
1364 void wxTopLevelWindowMac::ClearBackground()
1366 wxWindow::ClearBackground() ;
1369 // Raise the window to the top of the Z order
1370 void wxTopLevelWindowMac::Raise()
1372 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1375 // Lower the window to the bottom of the Z order
1376 void wxTopLevelWindowMac::Lower()
1378 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1381 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1383 if (s_macDeactivateWindow
)
1385 wxLogTrace(TRACE_ACTIVATE
,
1386 wxT("Doing delayed deactivation of %p"),
1387 s_macDeactivateWindow
);
1389 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1393 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool WXUNUSED(inIsActivating
) )
1395 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1397 if (s_macDeactivateWindow
== this)
1398 s_macDeactivateWindow
= NULL
;
1400 MacDelayedDeactivation(timestamp
);
1401 MacPropagateHiliteChanged() ;
1404 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1406 wxWindow::SetLabel( title
) ;
1407 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1410 wxString
wxTopLevelWindowMac::GetTitle() const
1412 return wxWindow::GetLabel();
1415 bool wxTopLevelWindowMac::Show(bool show
)
1417 if ( !wxTopLevelWindowBase::Show(show
) )
1420 bool plainTransition
= false;
1422 #if wxUSE_SYSTEM_OPTIONS
1423 // code contributed by Ryan Wilcox December 18, 2003
1424 plainTransition
= UMAGetSystemVersion() >= 0x1000 ;
1425 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1426 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1431 if ( plainTransition
)
1432 ::ShowWindow( (WindowRef
)m_macWindow
);
1434 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1436 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1438 // because apps expect a size event to occur at this moment
1439 wxSizeEvent
event(GetSize() , m_windowId
);
1440 event
.SetEventObject(this);
1441 GetEventHandler()->ProcessEvent(event
);
1445 if ( plainTransition
)
1446 ::HideWindow( (WindowRef
)m_macWindow
);
1448 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1451 MacPropagateVisibilityChanged() ;
1456 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1460 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1462 data
= new FullScreenData() ;
1464 m_macFullScreenData
= data
;
1465 data
->m_position
= GetPosition() ;
1466 data
->m_size
= GetSize() ;
1467 data
->m_wasResizable
= MacGetWindowAttributes() & kWindowResizableAttribute
;
1469 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1472 wxRect client
= wxGetClientDisplayRect() ;
1474 int left
, top
, right
, bottom
;
1482 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1484 if ( style
& wxFULLSCREEN_NOCAPTION
)
1490 if ( style
& wxFULLSCREEN_NOBORDER
)
1497 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1502 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1507 SetSize( x
, y
, w
, h
) ;
1508 if ( data
->m_wasResizable
)
1509 MacChangeWindowAttributes( kWindowNoAttributes
, kWindowResizableAttribute
) ;
1514 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1515 if ( data
->m_wasResizable
)
1516 MacChangeWindowAttributes( kWindowResizableAttribute
, kWindowNoAttributes
) ;
1517 SetPosition( data
->m_position
) ;
1518 SetSize( data
->m_size
) ;
1521 m_macFullScreenData
= NULL
;
1527 bool wxTopLevelWindowMac::IsFullScreen() const
1529 return m_macFullScreenData
!= NULL
;
1533 bool wxTopLevelWindowMac::SetTransparent(wxByte alpha
)
1535 OSStatus result
= SetWindowAlpha((WindowRef
)m_macWindow
, float(alpha
)/255.0);
1536 return result
== noErr
;
1540 bool wxTopLevelWindowMac::CanSetTransparent()
1546 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1548 if ( GetExtraStyle() == exStyle
)
1551 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1553 #if TARGET_API_MAC_OSX
1554 if ( m_macWindow
!= NULL
)
1556 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1558 if ( MacGetMetalAppearance() != metal
)
1560 if ( MacGetUnifiedAppearance() )
1561 MacSetUnifiedAppearance( !metal
) ;
1563 MacSetMetalAppearance( metal
) ;
1569 bool wxTopLevelWindowMac::SetBackgroundStyle(wxBackgroundStyle style
)
1571 if ( !wxTopLevelWindowBase::SetBackgroundStyle(style
) )
1574 WindowRef windowRef
= HIViewGetWindow( (HIViewRef
)GetHandle() );
1576 if ( GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
1578 OSStatus err
= HIWindowChangeFeatures( windowRef
, 0, kWindowIsOpaque
);
1579 verify_noerr( err
);
1580 err
= ReshapeCustomWindow( windowRef
);
1581 verify_noerr( err
);
1587 // TODO: switch to structure bounds -
1588 // we are still using coordinates of the content view
1590 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1592 Rect content
, structure
;
1594 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1595 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1597 left
= content
.left
- structure
.left
;
1598 top
= content
.top
- structure
.top
;
1599 right
= structure
.right
- content
.right
;
1600 bottom
= structure
.bottom
- content
.bottom
;
1603 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1605 m_cachedClippedRectValid
= false ;
1606 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1607 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1608 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1611 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1615 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1623 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1627 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1630 *width
= bounds
.right
- bounds
.left
;
1632 *height
= bounds
.bottom
- bounds
.top
;
1635 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1639 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1642 *width
= bounds
.right
- bounds
.left
;
1644 *height
= bounds
.bottom
- bounds
.top
;
1647 void wxTopLevelWindowMac::DoCentre(int dir
)
1649 if ( m_macWindow
!= 0 )
1650 wxTopLevelWindowBase::DoCentre(dir
);
1653 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1655 #if TARGET_API_MAC_OSX
1656 if ( MacGetUnifiedAppearance() )
1657 MacSetUnifiedAppearance( false ) ;
1659 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1660 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1664 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1666 #if TARGET_API_MAC_OSX
1667 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1673 void wxTopLevelWindowMac::MacSetUnifiedAppearance( bool set
)
1675 #if TARGET_API_MAC_OSX
1676 if ( UMAGetSystemVersion() >= 0x1040 )
1678 if ( MacGetMetalAppearance() )
1679 MacSetMetalAppearance( false ) ;
1681 MacChangeWindowAttributes( set
? kWindowUnifiedTitleAndToolbarAttribute
: kWindowNoAttributes
,
1682 set
? kWindowNoAttributes
: kWindowUnifiedTitleAndToolbarAttribute
) ;
1684 // For some reason, Tiger uses white as the background color for this appearance,
1685 // while most apps using it use the typical striped background. Restore that behavior
1687 // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
1689 SetBackgroundColour( wxSYS_COLOUR_WINDOW
) ;
1694 bool wxTopLevelWindowMac::MacGetUnifiedAppearance() const
1696 #if TARGET_API_MAC_OSX
1697 if ( UMAGetSystemVersion() >= 0x1040 )
1698 return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute
;
1704 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1706 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1709 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1712 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1717 void wxTopLevelWindowMac::MacPerformUpdates()
1719 // for composited windows this also triggers a redraw of all
1720 // invalid views in the window
1721 HIWindowFlush((WindowRef
) m_macWindow
) ;
1724 // Attracts the users attention to this window if the application is
1725 // inactive (should be called when a background event occurs)
1727 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1730 DisposePtr( (Ptr
)ptr
) ;
1733 void wxTopLevelWindowMac::RequestUserAttention(int WXUNUSED(flags
))
1735 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1736 static wxMacNMUPP
nmupp( wxMacNMResponse
);
1738 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1739 notificationRequest
->qType
= nmType
;
1740 notificationRequest
->nmMark
= 1 ;
1741 notificationRequest
->nmIcon
= 0 ;
1742 notificationRequest
->nmSound
= 0 ;
1743 notificationRequest
->nmStr
= NULL
;
1744 notificationRequest
->nmResp
= nmupp
;
1746 verify_noerr( NMInstall( notificationRequest
) ) ;
1749 // ---------------------------------------------------------------------------
1750 // Shape implementation
1751 // ---------------------------------------------------------------------------
1754 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1756 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1757 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1759 // The empty region signifies that the shape
1760 // should be removed from the window.
1761 if ( region
.IsEmpty() )
1763 wxSize sz
= GetClientSize();
1764 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1765 if ( rgn
.IsEmpty() )
1768 return SetShape(rgn
);
1771 // Make a copy of the region
1772 RgnHandle shapeRegion
= NewRgn();
1773 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1775 // Dispose of any shape region we may already have
1776 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1780 // Save the region so we can use it later
1781 SetWRefCon((WindowRef
)MacGetWindowRef(), (URefCon
)shapeRegion
);
1783 // inform the window manager that the window has changed shape
1784 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1789 // ---------------------------------------------------------------------------
1790 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1791 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1792 // ---------------------------------------------------------------------------
1794 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1796 GetWindowPortBounds(window
, inRect
);
1797 Point pt
= { inRect
->top
,inRect
->left
};
1798 wxMacLocalToGlobal( window
, &pt
) ;
1799 inRect
->bottom
+= pt
.v
- inRect
->top
;
1800 inRect
->right
+= pt
.h
- inRect
->left
;
1802 inRect
->left
= pt
.h
;
1805 static SInt32
wxShapedMacWindowGetFeatures(WindowRef
WXUNUSED(window
), SInt32 param
)
1807 /*------------------------------------------------------
1808 Define which options your custom window supports.
1809 --------------------------------------------------------*/
1810 //just enable everything for our demo
1811 *(OptionBits
*)param
=
1814 //kWindowCanCollapse |
1815 //kWindowCanGetWindowRegion |
1816 //kWindowHasTitleBar |
1817 //kWindowSupportsDragHilite |
1818 kWindowCanDrawInCurrentPort
|
1819 //kWindowCanMeasureTitle |
1820 kWindowWantsDisposeAtProcessDeath
|
1821 kWindowSupportsGetGrowImageRegion
|
1822 kWindowDefSupportsColorGrafPort
;
1827 // The content region is left as a rectangle matching the window size, this is
1828 // so the origin in the paint event, and etc. still matches what the
1829 // programmer expects.
1830 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1833 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1837 wxShapedMacWindowGetPos( window
, &r
) ;
1838 RectRgn( rgn
, &r
) ;
1842 // The structure region is set to the shape given to the SetShape method.
1843 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1845 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1851 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1852 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1853 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1854 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1858 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1860 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1865 switch (rgnRec
->regionCode
)
1867 case kWindowStructureRgn
:
1868 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1871 case kWindowContentRgn
:
1872 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1876 SetEmptyRgn(rgnRec
->winRgn
);
1883 // Determine the region of the window which was hit
1885 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1888 static RgnHandle tempRgn
= NULL
;
1890 if (tempRgn
== NULL
)
1893 // get the point clicked
1894 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1896 // Mac OS 8.5 or later
1897 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1898 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1901 // no significant area was hit
1905 static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode
), WindowRef window
, SInt16 message
, SInt32 param
)
1909 case kWindowMsgHitTest
:
1910 return wxShapedMacWindowHitTest(window
, param
);
1912 case kWindowMsgGetFeatures
:
1913 return wxShapedMacWindowGetFeatures(window
, param
);
1915 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1916 case kWindowMsgGetRegion
:
1917 return wxShapedMacWindowGetRegion(window
, param
);