1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for Mac
4 // Author: Stefan Csomor
8 // Copyright: (c) 2001-2004 Stefan Csomor
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/toplevel.h"
32 #include "wx/string.h"
35 #include "wx/settings.h"
36 #include "wx/strconv.h"
37 #include "wx/control.h"
40 #include "wx/mac/uma.h"
41 #include "wx/mac/aga.h"
42 #include "wx/tooltip.h"
45 #if wxUSE_SYSTEM_OPTIONS
46 #include "wx/sysopt.h"
50 #include <ToolUtils.h>
54 #include "wx/mac/private.h"
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 // unified title and toolbar constant - not in Tiger headers, so we duplicate it here
61 #define kWindowUnifiedTitleAndToolbarAttribute (1 << 7)
63 // trace mask for activation tracing messages
64 static const wxChar
*TRACE_ACTIVATE
= _T("activation");
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 // list of all frames and modeless dialogs
71 wxWindowList wxModelessWindows
;
73 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
75 // ============================================================================
76 // wxTopLevelWindowMac implementation
77 // ============================================================================
79 BEGIN_EVENT_TABLE(wxTopLevelWindowMac
, wxTopLevelWindowBase
)
83 // ---------------------------------------------------------------------------
85 // ---------------------------------------------------------------------------
87 static const EventTypeSpec eventList
[] =
89 // TODO: remove control related event like key and mouse (except for WindowLeave events)
91 { kEventClassKeyboard
, kEventRawKeyDown
} ,
92 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
93 { kEventClassKeyboard
, kEventRawKeyUp
} ,
94 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
96 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
97 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
99 { kEventClassWindow
, kEventWindowShown
} ,
100 { kEventClassWindow
, kEventWindowActivated
} ,
101 { kEventClassWindow
, kEventWindowDeactivated
} ,
102 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
103 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
104 { kEventClassWindow
, kEventWindowClose
} ,
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 // this parameter are not given for all events
263 EventMouseButton button
= 0 ;
264 UInt32 clickCount
= 0 ;
265 cEvent
.GetParameter
<EventMouseButton
>( kEventParamMouseButton
, typeMouseButton
, &button
) ;
266 cEvent
.GetParameter
<UInt32
>( kEventParamClickCount
, typeUInt32
, &clickCount
) ;
268 wxevent
.m_x
= screenMouseLocation
.h
;
269 wxevent
.m_y
= screenMouseLocation
.v
;
270 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
271 wxevent
.m_controlDown
= modifiers
& controlKey
;
272 wxevent
.m_altDown
= modifiers
& optionKey
;
273 wxevent
.m_metaDown
= modifiers
& cmdKey
;
274 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
276 // a control click is interpreted as a right click
277 bool thisButtonIsFakeRight
= false ;
278 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
280 button
= kEventMouseButtonSecondary
;
281 thisButtonIsFakeRight
= true ;
283 // otherwise we report double clicks by connecting a left click with a ctrl-left click
284 if ( clickCount
> 1 && button
!= g_lastButton
)
287 // we must make sure that our synthetic 'right' button corresponds in
288 // mouse down, moved and mouse up, and does not deliver a right down and left up
290 if ( cEvent
.GetKind() == kEventMouseDown
)
292 g_lastButton
= button
;
293 g_lastButtonWasFakeRight
= thisButtonIsFakeRight
;
299 g_lastButtonWasFakeRight
= false ;
301 else if ( g_lastButton
== kEventMouseButtonSecondary
&& g_lastButtonWasFakeRight
)
302 button
= g_lastButton
;
304 // determine the correct down state, wx does not want a 'down' for a mouseUp event,
305 // while mac delivers this button
306 if ( button
!= 0 && cEvent
.GetKind() != kEventMouseUp
)
310 case kEventMouseButtonPrimary
:
311 wxevent
.m_leftDown
= true ;
314 case kEventMouseButtonSecondary
:
315 wxevent
.m_rightDown
= true ;
318 case kEventMouseButtonTertiary
:
319 wxevent
.m_middleDown
= true ;
327 // translate into wx types
328 switch ( cEvent
.GetKind() )
330 case kEventMouseDown
:
333 case kEventMouseButtonPrimary
:
334 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
337 case kEventMouseButtonSecondary
:
338 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
341 case kEventMouseButtonTertiary
:
342 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
353 case kEventMouseButtonPrimary
:
354 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
357 case kEventMouseButtonSecondary
:
358 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
361 case kEventMouseButtonTertiary
:
362 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
370 case kEventMouseWheelMoved
:
372 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
374 EventMouseWheelAxis axis
= cEvent
.GetParameter
<EventMouseWheelAxis
>(kEventParamMouseWheelAxis
, typeMouseWheelAxis
) ;
375 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeSInt32
) ;
377 wxevent
.m_wheelRotation
= delta
;
378 wxevent
.m_wheelDelta
= 1;
379 wxevent
.m_linesPerAction
= 1;
380 if ( axis
== kEventMouseWheelAxisX
)
381 wxevent
.m_wheelAxis
= 1;
386 wxevent
.SetEventType( wxEVT_MOTION
) ;
391 ControlRef
wxMacFindSubControl( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, ControlRef superControl
, ControlPartCode
*outPart
)
395 UInt16 childrenCount
= 0 ;
396 ControlHandle sibling
;
398 OSStatus err
= CountSubControls( superControl
, &childrenCount
) ;
399 if ( err
== errControlIsNotEmbedder
)
402 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
404 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
406 err
= GetIndexedSubControl( superControl
, i
, & sibling
) ;
407 if ( err
== errControlIsNotEmbedder
)
410 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
411 if ( IsControlVisible( sibling
) )
413 UMAGetControlBoundsInWindowCoords( sibling
, &r
) ;
414 if ( MacPtInRect( location
, &r
) )
416 ControlHandle child
= wxMacFindSubControl( toplevelWindow
, location
, sibling
, outPart
) ;
423 Point testLocation
= location
;
425 if ( toplevelWindow
)
427 testLocation
.h
-= r
.left
;
428 testLocation
.v
-= r
.top
;
431 *outPart
= TestControl( sibling
, testLocation
) ;
443 ControlRef
wxMacFindControlUnderMouse( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, WindowRef window
, ControlPartCode
*outPart
)
445 #if TARGET_API_MAC_OSX
446 if ( UMAGetSystemVersion() >= 0x1030 )
447 return FindControlUnderMouse( location
, window
, outPart
) ;
450 ControlRef rootControl
= NULL
;
451 verify_noerr( GetRootControl( window
, &rootControl
) ) ;
453 return wxMacFindSubControl( toplevelWindow
, location
, rootControl
, outPart
) ;
456 #define NEW_CAPTURE_HANDLING 1
458 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
460 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
462 OSStatus result
= eventNotHandledErr
;
464 wxMacCarbonEvent
cEvent( event
) ;
466 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
467 Point windowMouseLocation
= screenMouseLocation
;
469 WindowRef window
= NULL
;
470 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
472 wxWindow
* currentMouseWindow
= NULL
;
473 ControlRef control
= NULL
;
475 #if NEW_CAPTURE_HANDLING
476 if ( wxApp::s_captureWindow
)
478 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
479 windowPart
= inContent
;
485 wxMacGlobalToLocal( window
, &windowMouseLocation
) ;
487 if ( wxApp::s_captureWindow
488 #if !NEW_CAPTURE_HANDLING
489 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
493 currentMouseWindow
= wxApp::s_captureWindow
;
495 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
497 ControlPartCode part
;
498 control
= wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &part
) ;
499 // if there is no control below the mouse position, send the event to the toplevel window itself
502 currentMouseWindow
= (wxWindow
*) data
;
506 currentMouseWindow
= wxFindControlFromMacControl( control
) ;
507 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
510 // for wxToolBar to function we have to send certaint events to it
511 // instead of its children (wxToolBarTools)
513 GetSuperControl(control
, &parent
);
514 wxWindow
*wxParent
= wxFindControlFromMacControl( parent
) ;
515 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
516 currentMouseWindow
= wxParent
;
521 // disabled windows must not get any input messages
522 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
523 currentMouseWindow
= NULL
;
527 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
528 SetupMouseEvent( wxevent
, cEvent
) ;
530 // handle all enter / leave events
532 if ( currentMouseWindow
!= g_MacLastWindow
)
534 if ( g_MacLastWindow
)
536 wxMouseEvent
eventleave(wxevent
);
537 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
538 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
539 eventleave
.SetEventObject( g_MacLastWindow
) ;
540 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
543 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
546 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
549 if ( currentMouseWindow
)
551 wxMouseEvent
evententer(wxevent
);
552 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
553 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
554 evententer
.SetEventObject( currentMouseWindow
) ;
555 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
558 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
561 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
564 g_MacLastWindow
= currentMouseWindow
;
567 if ( windowPart
== inMenuBar
)
569 // special case menu bar, as we are having a low-level runloop we must do it ourselves
570 if ( cEvent
.GetKind() == kEventMouseDown
)
572 ::MenuSelect( screenMouseLocation
) ;
576 else if ( currentMouseWindow
)
578 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
580 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
582 wxevent
.SetEventObject( currentMouseWindow
) ;
583 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
585 // make tooltips current
588 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
589 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
592 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
594 if ((currentMouseWindowParent
!= NULL
) &&
595 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
596 currentMouseWindow
= NULL
;
602 // if the user code did _not_ handle the event, then perform the
603 // default processing
604 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
606 // ... that is set focus to this window
607 if (currentMouseWindow
->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
608 currentMouseWindow
->SetFocus();
611 ControlPartCode dummyPart
;
612 // if built-in find control is finding the wrong control (ie static box instead of overlaid
613 // button, we cannot let the standard handler do its job, but must handle manually
615 if ( ( cEvent
.GetKind() == kEventMouseDown
)
618 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
619 wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &dummyPart
) )
623 if ( currentMouseWindow
->MacIsReallyEnabled() )
625 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
626 Point clickLocation
= windowMouseLocation
;
628 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
630 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
631 modifiers
, (ControlActionUPP
) -1 ) ;
633 if ((currentMouseWindowParent
!= NULL
) &&
634 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
636 currentMouseWindow
= NULL
;
644 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
646 wxApp::s_captureWindow
= NULL
;
652 wxWindow
* cursorTarget
= currentMouseWindow
;
653 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
655 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
657 cursorTarget
= cursorTarget
->GetParent() ;
659 cursorPoint
+= cursorTarget
->GetPosition();
663 else // currentMouseWindow == NULL
665 // don't mess with controls we don't know about
666 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
667 // so we try sending them the correct control directly
668 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
670 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
671 Point clickLocation
= windowMouseLocation
;
672 #if TARGET_API_MAC_OSX
674 hiPoint
.x
= clickLocation
.h
;
675 hiPoint
.y
= clickLocation
.v
;
676 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
677 clickLocation
.h
= (int)hiPoint
.x
;
678 clickLocation
.v
= (int)hiPoint
.y
;
679 #endif // TARGET_API_MAC_OSX
681 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
689 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
691 OSStatus result
= eventNotHandledErr
;
693 wxMacCarbonEvent
cEvent( event
) ;
695 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
696 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
698 switch ( GetEventKind( event
) )
700 case kEventWindowActivated
:
702 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
703 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
704 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
705 wxevent
.SetEventObject(toplevelWindow
);
706 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
707 // we still sending an eventNotHandledErr in order to allow for default processing
711 case kEventWindowDeactivated
:
713 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
714 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , 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 kEventWindowShown
:
723 toplevelWindow
->Refresh() ;
727 case kEventWindowClose
:
728 toplevelWindow
->Close() ;
732 case kEventWindowBoundsChanged
:
734 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
735 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
736 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
737 if ( attributes
& kWindowBoundsChangeSizeChanged
)
739 // according to the other ports we handle this within the OS level
740 // resize event, not within a wxSizeEvent
741 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
744 frame
->PositionBars();
747 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
748 event
.SetEventObject( toplevelWindow
) ;
750 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
751 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
754 if ( attributes
& kWindowBoundsChangeOriginChanged
)
756 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
757 event
.SetEventObject( toplevelWindow
) ;
758 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
765 case kEventWindowBoundsChanging
:
767 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
768 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
770 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
772 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
773 int left
, top
, right
, bottom
;
774 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
779 newRect
.right
- newRect
.left
+ left
+ right
,
780 newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
782 // this is a EVT_SIZING not a EVT_SIZE type !
783 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
784 wxevent
.SetEventObject( toplevelWindow
) ;
786 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
787 adjustR
= wxevent
.GetRect() ;
789 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
790 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
791 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
792 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
793 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
794 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
795 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
796 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
797 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
798 if ( !EqualRect( &newRect
, &adjustedRect
) )
799 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
800 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
814 // mix this in from window.cpp
815 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
817 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
819 OSStatus result
= eventNotHandledErr
;
821 switch ( GetEventClass( event
) )
823 case kEventClassTextInput
:
824 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
827 case kEventClassKeyboard
:
828 result
= KeyboardEventHandler( handler
, event
, data
) ;
831 case kEventClassWindow
:
832 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
835 case kEventClassMouse
:
836 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
846 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
848 // ---------------------------------------------------------------------------
849 // wxWindowMac utility functions
850 // ---------------------------------------------------------------------------
852 // Find an item given the Macintosh Window Reference
854 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
856 static MacWindowMap wxWinMacWindowList
;
858 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
860 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
862 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
865 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
866 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
868 // adding NULL WindowRef is (first) surely a result of an error and
870 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
872 wxWinMacWindowList
[inWindowRef
] = win
;
875 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
876 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
878 MacWindowMap::iterator it
;
879 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
881 if ( it
->second
== win
)
883 wxWinMacWindowList
.erase(it
);
889 // ----------------------------------------------------------------------------
890 // wxTopLevelWindowMac creation
891 // ----------------------------------------------------------------------------
893 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
899 bool m_wasResizable
;
902 void wxTopLevelWindowMac::Init()
905 m_maximizeOnShow
= false;
908 m_macEventHandler
= NULL
;
909 m_macFullScreenData
= NULL
;
912 class wxMacDeferredWindowDeleter
: public wxObject
915 wxMacDeferredWindowDeleter( WindowRef windowRef
)
917 m_macWindow
= windowRef
;
920 virtual ~wxMacDeferredWindowDeleter()
922 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
926 WindowRef m_macWindow
;
929 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
931 const wxString
& title
,
935 const wxString
& name
)
940 m_windowStyle
= style
;
944 m_windowId
= id
== -1 ? NewControlId() : id
;
945 wxWindow::SetLabel( title
) ;
947 MacCreateRealWindow( title
, pos
, size
, style
, name
) ;
949 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
951 if (GetExtraStyle() & wxFRAME_EX_METAL
)
952 MacSetMetalAppearance(true);
954 wxTopLevelWindows
.Append(this);
957 parent
->AddChild(this);
962 wxTopLevelWindowMac::~wxTopLevelWindowMac()
967 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
969 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
972 if ( m_macEventHandler
)
974 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
975 m_macEventHandler
= NULL
;
978 wxRemoveMacWindowAssociation( this ) ;
980 if ( wxModelessWindows
.Find(this) )
981 wxModelessWindows
.DeleteObject(this);
983 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
985 m_macFullScreenData
= NULL
;
987 // avoid dangling refs
988 if ( s_macDeactivateWindow
== this )
989 s_macDeactivateWindow
= NULL
;
993 // ----------------------------------------------------------------------------
994 // wxTopLevelWindowMac maximize/minimize
995 // ----------------------------------------------------------------------------
997 void wxTopLevelWindowMac::Maximize(bool maximize
)
999 Point idealSize
= { 0 , 0 } ;
1002 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1004 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
1006 idealSize
.h
= bounds
.size
.width
;
1007 idealSize
.v
= bounds
.size
.height
;
1010 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
1011 idealSize
.h
= rect
.right
- rect
.left
;
1012 idealSize
.v
= rect
.bottom
- rect
.top
;
1015 ZoomWindowIdeal( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
1018 bool wxTopLevelWindowMac::IsMaximized() const
1020 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
1023 void wxTopLevelWindowMac::Iconize(bool iconize
)
1025 if ( IsWindowCollapsable( (WindowRef
)m_macWindow
) )
1026 CollapseWindow( (WindowRef
)m_macWindow
, iconize
) ;
1029 bool wxTopLevelWindowMac::IsIconized() const
1031 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1034 void wxTopLevelWindowMac::Restore()
1036 if ( IsMaximized() )
1038 else if ( IsIconized() )
1042 // ----------------------------------------------------------------------------
1043 // wxTopLevelWindowMac misc
1044 // ----------------------------------------------------------------------------
1046 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1048 return wxPoint(0, 0) ;
1051 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1053 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1055 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1057 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1061 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1063 if ( m_macEventHandler
!= NULL
)
1065 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1068 InstallWindowEventHandler(
1069 MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1070 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1073 void wxTopLevelWindowMac::MacCreateRealWindow(
1074 const wxString
& title
,
1078 const wxString
& name
)
1080 OSStatus err
= noErr
;
1082 m_windowStyle
= style
;
1090 wxRect display
= wxGetClientDisplayRect() ;
1092 if ( x
== wxDefaultPosition
.x
)
1095 if ( y
== wxDefaultPosition
.y
)
1098 int w
= WidthDefault(size
.x
);
1099 int h
= HeightDefault(size
.y
);
1101 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1103 // translate the window attributes in the appropriate window class and attributes
1104 WindowClass wclass
= 0;
1105 WindowAttributes attr
= kWindowNoAttributes
;
1106 WindowGroupRef group
= NULL
;
1108 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1111 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1112 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1113 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1116 wclass
= kFloatingWindowClass
;
1118 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1119 attr
|= kWindowSideTitlebarAttribute
;
1123 wclass
= kPlainWindowClass
;
1126 else if ( HasFlag( wxPOPUP_WINDOW
) )
1129 // Until we've got a real wxPopupWindow class on wxMac make it a
1130 // little easier for wxFrame to be used to emulate it and workaround
1131 // the lack of wxPopupWindow.
1132 if ( HasFlag( wxBORDER_NONE
) )
1133 wclass
= kHelpWindowClass
; // has no border
1135 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1136 //attr |= kWindowNoShadowAttribute; // turn off the shadow Should we??
1137 group
= GetWindowGroupOfClass( // float above other windows
1138 kFloatingWindowClass
) ;
1140 else if ( HasFlag( wxCAPTION
) )
1142 wclass
= kDocumentWindowClass
;
1143 attr
|= kWindowInWindowMenuAttribute
;
1145 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1146 else if ( HasFlag( wxFRAME_DRAWER
) )
1148 wclass
= kDrawerWindowClass
;
1150 #endif //10.2 and up
1153 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1154 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1156 wclass
= kDocumentWindowClass
;
1160 wclass
= kPlainWindowClass
;
1164 if ( wclass
!= kPlainWindowClass
)
1166 if ( HasFlag( wxMINIMIZE_BOX
) )
1167 attr
|= kWindowCollapseBoxAttribute
;
1169 if ( HasFlag( wxMAXIMIZE_BOX
) )
1170 attr
|= kWindowFullZoomAttribute
;
1172 if ( HasFlag( wxRESIZE_BORDER
) )
1173 attr
|= kWindowResizableAttribute
;
1175 if ( HasFlag( wxCLOSE_BOX
) )
1176 attr
|= kWindowCloseBoxAttribute
;
1179 // turn on live resizing (OS X only)
1180 if (UMAGetSystemVersion() >= 0x1000)
1181 attr
|= kWindowLiveResizeAttribute
;
1183 if ( HasFlag(wxSTAY_ON_TOP
) )
1184 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1186 if ( HasFlag( wxFRAME_FLOAT_ON_PARENT
) )
1187 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1189 attr
|= kWindowCompositingAttribute
;
1190 #if 0 // wxMAC_USE_CORE_GRAPHICS ; TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1191 attr
|= kWindowFrameworkScaledAttribute
;
1194 if ( HasFlag(wxFRAME_SHAPED
) )
1196 WindowDefSpec customWindowDefSpec
;
1197 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1198 customWindowDefSpec
.u
.defProc
=
1200 (WindowDefUPP
) wxShapedMacWindowDef
;
1202 NewWindowDefUPP(wxShapedMacWindowDef
);
1204 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1205 attr
, &theBoundsRect
,
1206 (WindowRef
*) &m_macWindow
);
1210 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1213 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1214 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1216 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1218 // setup a separate group for each window, so that overlays can be handled easily
1219 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &group
));
1220 verify_noerr( SetWindowGroupParent( group
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1221 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, group
));
1223 // the create commands are only for content rect,
1224 // so we have to set the size again as structure bounds
1225 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1227 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1228 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1229 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1231 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1232 // the content view, so we have to retrieve it explicitly
1233 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1234 m_peer
->GetControlRefAddr() ) ;
1235 if ( !m_peer
->Ok() )
1237 // compatibility mode fallback
1238 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1241 // the root control level handler
1242 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1244 // Causes the inner part of the window not to be metal
1245 // if the style is used before window creation.
1246 #if 0 // TARGET_API_MAC_OSX
1247 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1249 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1250 MacSetMetalAppearance( true ) ;
1254 #if TARGET_API_MAC_OSX
1255 if ( m_macWindow
!= NULL
)
1257 MacSetUnifiedAppearance( true ) ;
1261 // the frame window event handler
1262 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1263 MacInstallTopLevelWindowEventHandler() ;
1265 DoSetWindowVariant( m_windowVariant
) ;
1269 if ( HasFlag(wxFRAME_SHAPED
) )
1271 // default shape matches the window size
1272 wxRegion
rgn( 0, 0, w
, h
);
1276 wxWindowCreateEvent
event(this);
1277 GetEventHandler()->ProcessEvent(event
);
1280 void wxTopLevelWindowMac::ClearBackground()
1282 wxWindow::ClearBackground() ;
1285 // Raise the window to the top of the Z order
1286 void wxTopLevelWindowMac::Raise()
1288 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1291 // Lower the window to the bottom of the Z order
1292 void wxTopLevelWindowMac::Lower()
1294 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1297 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1299 if (s_macDeactivateWindow
)
1301 wxLogTrace(TRACE_ACTIVATE
,
1302 wxT("Doing delayed deactivation of %p"),
1303 s_macDeactivateWindow
);
1305 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1309 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1311 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1313 if (s_macDeactivateWindow
== this)
1314 s_macDeactivateWindow
= NULL
;
1316 MacDelayedDeactivation(timestamp
);
1317 MacPropagateHiliteChanged() ;
1320 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1322 wxWindow::SetLabel( title
) ;
1323 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1326 wxString
wxTopLevelWindowMac::GetTitle() const
1328 return wxWindow::GetLabel();
1331 bool wxTopLevelWindowMac::Show(bool show
)
1333 if ( !wxTopLevelWindowBase::Show(show
) )
1336 bool plainTransition
= false;
1338 #if wxUSE_SYSTEM_OPTIONS
1339 // code contributed by Ryan Wilcox December 18, 2003
1340 plainTransition
= UMAGetSystemVersion() >= 0x1000 ;
1341 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1342 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1347 if ( plainTransition
)
1348 ::ShowWindow( (WindowRef
)m_macWindow
);
1350 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1352 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1354 // because apps expect a size event to occur at this moment
1355 wxSizeEvent
event(GetSize() , m_windowId
);
1356 event
.SetEventObject(this);
1357 GetEventHandler()->ProcessEvent(event
);
1361 if ( plainTransition
)
1362 ::HideWindow( (WindowRef
)m_macWindow
);
1364 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1367 MacPropagateVisibilityChanged() ;
1372 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1376 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1378 data
= new FullScreenData() ;
1380 m_macFullScreenData
= data
;
1381 data
->m_position
= GetPosition() ;
1382 data
->m_size
= GetSize() ;
1383 data
->m_wasResizable
= MacGetWindowAttributes() & kWindowResizableAttribute
;
1385 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1388 wxRect client
= wxGetClientDisplayRect() ;
1390 int left
, top
, right
, bottom
;
1398 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1400 if ( style
& wxFULLSCREEN_NOCAPTION
)
1406 if ( style
& wxFULLSCREEN_NOBORDER
)
1413 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1418 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1423 SetSize( x
, y
, w
, h
) ;
1424 if ( data
->m_wasResizable
)
1425 MacChangeWindowAttributes( kWindowNoAttributes
, kWindowResizableAttribute
) ;
1430 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1431 if ( data
->m_wasResizable
)
1432 MacChangeWindowAttributes( kWindowResizableAttribute
, kWindowNoAttributes
) ;
1433 SetPosition( data
->m_position
) ;
1434 SetSize( data
->m_size
) ;
1437 m_macFullScreenData
= NULL
;
1443 bool wxTopLevelWindowMac::IsFullScreen() const
1445 return m_macFullScreenData
!= NULL
;
1449 bool wxTopLevelWindowMac::SetTransparent(wxByte alpha
)
1451 OSStatus result
= SetWindowAlpha((WindowRef
)m_macWindow
, float(alpha
)/255.0);
1452 return result
== noErr
;
1456 bool wxTopLevelWindowMac::CanSetTransparent()
1462 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1464 if ( GetExtraStyle() == exStyle
)
1467 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1469 #if TARGET_API_MAC_OSX
1470 if ( m_macWindow
!= NULL
)
1472 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1474 if ( MacGetMetalAppearance() != metal
)
1476 if ( MacGetUnifiedAppearance() )
1477 MacSetUnifiedAppearance( !metal
) ;
1479 MacSetMetalAppearance( metal
) ;
1485 // TODO: switch to structure bounds -
1486 // we are still using coordinates of the content view
1488 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1490 Rect content
, structure
;
1492 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1493 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1495 left
= content
.left
- structure
.left
;
1496 top
= content
.top
- structure
.top
;
1497 right
= structure
.right
- content
.right
;
1498 bottom
= structure
.bottom
- content
.bottom
;
1501 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1503 m_cachedClippedRectValid
= false ;
1504 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1505 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1506 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1509 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1513 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1521 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1525 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1528 *width
= bounds
.right
- bounds
.left
;
1530 *height
= bounds
.bottom
- bounds
.top
;
1533 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1537 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1540 *width
= bounds
.right
- bounds
.left
;
1542 *height
= bounds
.bottom
- bounds
.top
;
1545 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1547 #if TARGET_API_MAC_OSX
1548 if ( MacGetUnifiedAppearance() )
1549 MacSetUnifiedAppearance( false ) ;
1551 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1552 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1556 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1558 #if TARGET_API_MAC_OSX
1559 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1565 void wxTopLevelWindowMac::MacSetUnifiedAppearance( bool set
)
1567 #if TARGET_API_MAC_OSX
1568 if ( UMAGetSystemVersion() >= 0x1040 )
1570 if ( MacGetMetalAppearance() )
1571 MacSetMetalAppearance( false ) ;
1573 MacChangeWindowAttributes( set
? kWindowUnifiedTitleAndToolbarAttribute
: kWindowNoAttributes
,
1574 set
? kWindowNoAttributes
: kWindowUnifiedTitleAndToolbarAttribute
) ;
1576 // For some reason, Tiger uses white as the background color for this appearance,
1577 // while most apps using it use the typical striped background. Restore that behavior
1579 // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
1581 SetBackgroundColour( wxSYS_COLOUR_WINDOW
) ;
1586 bool wxTopLevelWindowMac::MacGetUnifiedAppearance() const
1588 #if TARGET_API_MAC_OSX
1589 if ( UMAGetSystemVersion() >= 0x1040 )
1590 return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute
;
1596 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1598 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1601 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1604 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1609 void wxTopLevelWindowMac::MacPerformUpdates()
1611 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1612 // for composited windows this also triggers a redraw of all
1613 // invalid views in the window
1614 if ( UMAGetSystemVersion() >= 0x1030 )
1615 HIWindowFlush((WindowRef
) m_macWindow
) ;
1619 // the only way to trigger the redrawing on earlier systems is to call
1622 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1623 UInt32 currentEventClass
= 0 ;
1624 if ( currentEvent
!= NULL
)
1626 currentEventClass
= ::GetEventClass( currentEvent
) ;
1627 ::GetEventKind( currentEvent
) ;
1630 if ( currentEventClass
!= kEventClassMenu
)
1632 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1634 ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1639 // Attracts the users attention to this window if the application is
1640 // inactive (should be called when a background event occurs)
1642 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1645 DisposePtr( (Ptr
)ptr
) ;
1648 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1650 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1651 static wxMacNMUPP
nmupp( wxMacNMResponse
);
1653 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1654 notificationRequest
->qType
= nmType
;
1655 notificationRequest
->nmMark
= 1 ;
1656 notificationRequest
->nmIcon
= 0 ;
1657 notificationRequest
->nmSound
= 0 ;
1658 notificationRequest
->nmStr
= NULL
;
1659 notificationRequest
->nmResp
= nmupp
;
1661 verify_noerr( NMInstall( notificationRequest
) ) ;
1664 // ---------------------------------------------------------------------------
1665 // Shape implementation
1666 // ---------------------------------------------------------------------------
1669 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1671 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1672 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1674 // The empty region signifies that the shape
1675 // should be removed from the window.
1676 if ( region
.IsEmpty() )
1678 wxSize sz
= GetClientSize();
1679 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1680 if ( rgn
.IsEmpty() )
1683 return SetShape(rgn
);
1686 // Make a copy of the region
1687 RgnHandle shapeRegion
= NewRgn();
1688 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1690 // Dispose of any shape region we may already have
1691 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1695 // Save the region so we can use it later
1696 SetWRefCon((WindowRef
)MacGetWindowRef(), (URefCon
)shapeRegion
);
1698 // inform the window manager that the window has changed shape
1699 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1704 // ---------------------------------------------------------------------------
1705 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1706 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1707 // ---------------------------------------------------------------------------
1709 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1711 GetWindowPortBounds(window
, inRect
);
1712 Point pt
= { inRect
->top
,inRect
->left
};
1713 wxMacLocalToGlobal( window
, &pt
) ;
1714 inRect
->bottom
+= pt
.v
- inRect
->top
;
1715 inRect
->right
+= pt
.h
- inRect
->left
;
1717 inRect
->left
= pt
.h
;
1720 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1722 /*------------------------------------------------------
1723 Define which options your custom window supports.
1724 --------------------------------------------------------*/
1725 //just enable everything for our demo
1726 *(OptionBits
*)param
=
1729 //kWindowCanCollapse |
1730 //kWindowCanGetWindowRegion |
1731 //kWindowHasTitleBar |
1732 //kWindowSupportsDragHilite |
1733 kWindowCanDrawInCurrentPort
|
1734 //kWindowCanMeasureTitle |
1735 kWindowWantsDisposeAtProcessDeath
|
1736 kWindowSupportsGetGrowImageRegion
|
1737 kWindowDefSupportsColorGrafPort
;
1742 // The content region is left as a rectangle matching the window size, this is
1743 // so the origin in the paint event, and etc. still matches what the
1744 // programmer expects.
1745 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1748 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1752 wxShapedMacWindowGetPos( window
, &r
) ;
1753 RectRgn( rgn
, &r
) ;
1757 // The structure region is set to the shape given to the SetShape method.
1758 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1760 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1766 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1767 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1768 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1769 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1773 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1775 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1780 switch (rgnRec
->regionCode
)
1782 case kWindowStructureRgn
:
1783 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1786 case kWindowContentRgn
:
1787 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1791 SetEmptyRgn(rgnRec
->winRgn
);
1798 // Determine the region of the window which was hit
1800 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1803 static RgnHandle tempRgn
= NULL
;
1805 if (tempRgn
== NULL
)
1808 // get the point clicked
1809 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1811 // Mac OS 8.5 or later
1812 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1813 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1816 // no significant area was hit
1820 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1824 case kWindowMsgHitTest
:
1825 return wxShapedMacWindowHitTest(window
, param
);
1827 case kWindowMsgGetFeatures
:
1828 return wxShapedMacWindowGetFeatures(window
, param
);
1830 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1831 case kWindowMsgGetRegion
:
1832 return wxShapedMacWindowGetRegion(window
, param
);