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"
29 #include "wx/toplevel.h"
31 #include "wx/string.h"
34 #include "wx/settings.h"
35 #include "wx/strconv.h"
36 #include "wx/control.h"
39 #include "wx/mac/uma.h"
40 #include "wx/mac/aga.h"
42 #include "wx/tooltip.h"
44 #if wxUSE_SYSTEM_OPTIONS
45 #include "wx/sysopt.h"
49 #include <ToolUtils.h>
53 #include "wx/mac/private.h"
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 // trace mask for activation tracing messages
60 static const wxChar
*TRACE_ACTIVATE
= _T("activation");
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 // list of all frames and modeless dialogs
67 wxWindowList wxModelessWindows
;
69 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
71 // ============================================================================
72 // wxTopLevelWindowMac implementation
73 // ============================================================================
75 BEGIN_EVENT_TABLE(wxTopLevelWindowMac
, wxTopLevelWindowBase
)
79 // ---------------------------------------------------------------------------
81 // ---------------------------------------------------------------------------
83 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
85 static const EventTypeSpec eventList
[] =
87 // TODO remove control related event like key and mouse (except for WindowLeave events)
89 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
91 { kEventClassKeyboard
, kEventRawKeyDown
} ,
92 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
93 { kEventClassKeyboard
, kEventRawKeyUp
} ,
94 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
97 { kEventClassWindow
, kEventWindowShown
} ,
98 { kEventClassWindow
, kEventWindowActivated
} ,
99 { kEventClassWindow
, kEventWindowDeactivated
} ,
100 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
101 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
102 { kEventClassWindow
, kEventWindowClose
} ,
104 // we have to catch these events on the toplevel window level, as controls don't get the
105 // raw mouse events anymore
107 { kEventClassMouse
, kEventMouseDown
} ,
108 { kEventClassMouse
, kEventMouseUp
} ,
109 { kEventClassMouse
, kEventMouseWheelMoved
} ,
110 { kEventClassMouse
, kEventMouseMoved
} ,
111 { kEventClassMouse
, kEventMouseDragged
} ,
114 static pascal OSStatus
TextInputEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
116 OSStatus result
= eventNotHandledErr
;
118 wxWindow
* focus
= wxWindow::FindFocus() ;
119 unsigned char charCode
;
126 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
, typeEventRef
, NULL
, sizeof(rawEvent
), NULL
, &rawEvent
) ;
128 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
,sizeof(char), NULL
,&charCode
);
129 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
130 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
131 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
133 switch ( GetEventKind( event
) )
135 case kEventTextInputUnicodeForKeyEvent
:
136 // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not
137 // get its own kEventTextInputUnicodeForKeyEvent, so we route back the
138 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
141 ControlRef macControl
= (ControlRef
) control
->GetHandle() ;
144 ::HandleControlKey( macControl
, keyCode
, charCode
, modifiers
) ;
150 // this may lead to double events sent to a window in case all handlers have skipped the key down event
151 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
152 UInt32 message
= (keyCode
<< 8) + charCode
;
154 if ( (focus
!= NULL
) && wxTheApp
->MacSendKeyDownEvent(
155 focus
, message
, modifiers
, when
, point
.h
, point
.v
) )
169 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
171 OSStatus result
= eventNotHandledErr
;
172 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
173 // FindFocus does not return the actual focus window,but the enclosing window
174 wxWindow
* focus
= wxWindow::DoFindFocus();
176 focus
= (wxTopLevelWindowMac
*) data
;
178 unsigned char charCode
;
183 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
186 UInt32 dataSize
= 0 ;
187 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
191 UniChar
* charBuf
= buf
;
194 charBuf
= new UniChar
[ dataSize
/ sizeof( UniChar
) ] ;
195 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
196 #if SIZEOF_WCHAR_T == 2
197 uniChar
= charBuf
[0] ;
199 wxMBConvUTF16 converter
;
200 converter
.MB2WC( &uniChar
, (const char*)charBuf
, 1 ) ;
207 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
,sizeof(char), NULL
,&charCode
);
208 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
209 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
210 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
212 UInt32 message
= (keyCode
<< 8) + charCode
;
213 switch( GetEventKind( event
) )
215 case kEventRawKeyRepeat
:
216 case kEventRawKeyDown
:
218 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
219 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
220 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
221 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
222 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
) )
226 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
230 case kEventRawKeyUp
:
231 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
232 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
) )
238 case kEventRawKeyModifiersChanged
:
240 wxKeyEvent
event(wxEVT_KEY_DOWN
);
242 event
.m_shiftDown
= modifiers
& shiftKey
;
243 event
.m_controlDown
= modifiers
& controlKey
;
244 event
.m_altDown
= modifiers
& optionKey
;
245 event
.m_metaDown
= modifiers
& cmdKey
;
247 event
.m_uniChar
= uniChar
;
251 event
.SetTimestamp(when
);
252 event
.SetEventObject(focus
);
254 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
256 event
.m_keyCode
= WXK_CONTROL
;
257 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
258 focus
->GetEventHandler()->ProcessEvent( event
) ;
260 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
262 event
.m_keyCode
= WXK_SHIFT
;
263 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
264 focus
->GetEventHandler()->ProcessEvent( event
) ;
266 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
268 event
.m_keyCode
= WXK_ALT
;
269 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
270 focus
->GetEventHandler()->ProcessEvent( event
) ;
272 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
274 event
.m_keyCode
= WXK_COMMAND
;
275 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
276 focus
->GetEventHandler()->ProcessEvent( event
) ;
278 wxApp::s_lastModifiers
= modifiers
;
289 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
290 // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
293 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
295 wxWindow
* g_MacLastWindow
= NULL
;
297 static EventMouseButton lastButton
= 0 ;
299 static void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
301 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
302 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
304 // this parameter are not given for all events
305 EventMouseButton button
= 0 ;
306 UInt32 clickCount
= 0 ;
307 cEvent
.GetParameter
<EventMouseButton
>(kEventParamMouseButton
, typeMouseButton
, &button
) ;
308 cEvent
.GetParameter
<UInt32
>(kEventParamClickCount
, typeUInt32
, &clickCount
) ;
310 wxevent
.m_x
= screenMouseLocation
.h
;
311 wxevent
.m_y
= screenMouseLocation
.v
;
312 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
313 wxevent
.m_controlDown
= modifiers
& controlKey
;
314 wxevent
.m_altDown
= modifiers
& optionKey
;
315 wxevent
.m_metaDown
= modifiers
& cmdKey
;
316 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
318 // a control click is interpreted as a right click
319 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
320 button
= kEventMouseButtonSecondary
;
322 // otherwise we report double clicks by connecting a left click with a ctrl-left click
323 if ( clickCount
> 1 && button
!= lastButton
)
326 // we must make sure that our synthetic 'right' button corresponds in
327 // mouse down, moved and mouse up, and does not deliver a right down and left up
329 if ( cEvent
.GetKind() == kEventMouseDown
)
330 lastButton
= button
;
334 else if ( lastButton
)
335 button
= lastButton
;
337 // determinate the correct down state, wx does not want a 'down' for a mouseUp event, while mac delivers
339 if ( button
!= 0 && cEvent
.GetKind() != kEventMouseUp
)
343 case kEventMouseButtonPrimary
:
344 wxevent
.m_leftDown
= true ;
347 case kEventMouseButtonSecondary
:
348 wxevent
.m_rightDown
= true ;
351 case kEventMouseButtonTertiary
:
352 wxevent
.m_middleDown
= true ;
360 // translate into wx types
361 switch ( cEvent
.GetKind() )
363 case kEventMouseDown
:
366 case kEventMouseButtonPrimary
:
367 wxevent
.SetEventType(clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
370 case kEventMouseButtonSecondary
:
371 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
374 case kEventMouseButtonTertiary
:
375 wxevent
.SetEventType(clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
386 case kEventMouseButtonPrimary
:
387 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
390 case kEventMouseButtonSecondary
:
391 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
394 case kEventMouseButtonTertiary
:
395 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
403 case kEventMouseWheelMoved
:
405 wxevent
.SetEventType(wxEVT_MOUSEWHEEL
) ;
407 // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
408 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeLongInteger
) ;
410 wxevent
.m_wheelRotation
= delta
;
411 wxevent
.m_wheelDelta
= 1;
412 wxevent
.m_linesPerAction
= 1;
417 wxevent
.SetEventType(wxEVT_MOTION
) ;
422 ControlRef
wxMacFindSubControl( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, ControlRef superControl
, ControlPartCode
*outPart
)
426 UInt16 childrenCount
= 0 ;
427 OSStatus err
= CountSubControls( superControl
, &childrenCount
) ;
428 if ( err
== errControlIsNotEmbedder
)
430 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
432 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
434 ControlHandle sibling
;
435 err
= GetIndexedSubControl( superControl
, i
, & sibling
) ;
436 if ( err
== errControlIsNotEmbedder
)
439 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
440 if ( IsControlVisible( sibling
) )
443 UMAGetControlBoundsInWindowCoords( sibling
, &r
) ;
444 if ( MacPtInRect( location
, &r
) )
446 ControlHandle child
= wxMacFindSubControl( toplevelWindow
, location
, sibling
, outPart
) ;
451 Point testLocation
= location
;
453 if ( toplevelWindow
&& toplevelWindow
->MacUsesCompositing() )
455 testLocation
.h
-= r
.left
;
456 testLocation
.v
-= r
.top
;
459 *outPart
= TestControl( sibling
, testLocation
) ;
470 ControlRef
wxMacFindControlUnderMouse( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, WindowRef window
, ControlPartCode
*outPart
)
472 #if TARGET_API_MAC_OSX
473 if ( UMAGetSystemVersion() >= 0x1030 && ( toplevelWindow
== 0 || toplevelWindow
->MacUsesCompositing() ) )
474 return FindControlUnderMouse( location
, window
, outPart
) ;
476 ControlRef rootControl
= NULL
;
477 verify_noerr( GetRootControl( window
, &rootControl
) ) ;
478 return wxMacFindSubControl( toplevelWindow
, location
, rootControl
, outPart
) ;
482 #define NEW_CAPTURE_HANDLING 1
484 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
486 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
488 OSStatus result
= eventNotHandledErr
;
490 wxMacCarbonEvent
cEvent( event
) ;
492 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
493 Point windowMouseLocation
= screenMouseLocation
;
496 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
498 wxWindow
* currentMouseWindow
= NULL
;
499 ControlRef control
= NULL
;
501 #if NEW_CAPTURE_HANDLING
502 if ( wxApp::s_captureWindow
)
504 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
505 windowPart
= inContent
;
511 QDGlobalToLocalPoint( UMAGetWindowPort(window
) , &windowMouseLocation
) ;
513 if ( wxApp::s_captureWindow
514 #if !NEW_CAPTURE_HANDLING
515 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
519 currentMouseWindow
= wxApp::s_captureWindow
;
521 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
523 ControlPartCode part
;
524 control
= wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &part
) ;
525 // if there is no control below the mouse position, send the event to the toplevel window itself
527 currentMouseWindow
= (wxWindow
*) data
;
530 currentMouseWindow
= wxFindControlFromMacControl( control
) ;
531 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
534 // for wxToolBar to function we have to send certaint events to it
535 // instead of its children (wxToolBarTools)
537 GetSuperControl(control
, &parent
);
538 wxWindow
*wxParent
= wxFindControlFromMacControl( parent
) ;
539 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
540 currentMouseWindow
= wxParent
;
547 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
548 SetupMouseEvent( wxevent
, cEvent
) ;
550 // handle all enter / leave events
552 if ( currentMouseWindow
!= g_MacLastWindow
)
554 if ( g_MacLastWindow
)
556 wxMouseEvent
eventleave(wxevent
);
557 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
558 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
559 eventleave
.SetEventObject( g_MacLastWindow
) ;
560 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
562 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
563 #endif // wxUSE_TOOLTIPS
564 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
567 if ( currentMouseWindow
)
569 wxMouseEvent
evententer(wxevent
);
570 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
571 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
572 evententer
.SetEventObject( currentMouseWindow
) ;
573 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
575 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
576 #endif // wxUSE_TOOLTIPS
577 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
580 g_MacLastWindow
= currentMouseWindow
;
583 if ( windowPart
== inMenuBar
)
585 // special case menu bar, as we are having a low-level runloop we must do it ourselves
586 if ( cEvent
.GetKind() == kEventMouseDown
)
588 ::MenuSelect( screenMouseLocation
) ;
592 else if ( currentMouseWindow
)
594 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
596 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
598 wxevent
.SetEventObject( currentMouseWindow
) ;
599 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
601 // make tooltips current
604 if ( wxevent
.GetEventType() == wxEVT_MOTION
605 || wxevent
.GetEventType() == wxEVT_ENTER_WINDOW
606 || wxevent
.GetEventType() == wxEVT_LEAVE_WINDOW
)
607 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
608 #endif // wxUSE_TOOLTIPS
609 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
611 if ((currentMouseWindowParent
!= NULL
) &&
612 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
613 currentMouseWindow
= NULL
;
619 // if the user code did _not_ handle the event, then perform the
620 // default processing
621 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
623 // ... that is set focus to this window
624 if (currentMouseWindow
->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
625 currentMouseWindow
->SetFocus();
628 ControlPartCode dummyPart
;
629 // if built-in find control is finding the wrong control (ie static box instead of overlaid
630 // button, we cannot let the standard handler do its job, but must handle manually
632 if ( ( cEvent
.GetKind() == kEventMouseDown
)
635 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
636 wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &dummyPart
) )
640 if ( currentMouseWindow
->MacIsReallyEnabled() )
642 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
643 Point clickLocation
= windowMouseLocation
;
645 if ( toplevelWindow
->MacUsesCompositing() )
646 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
648 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
649 modifiers
, (ControlActionUPP
) -1 ) ;
651 if ((currentMouseWindowParent
!= NULL
) &&
652 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
653 currentMouseWindow
= NULL
;
659 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
661 wxApp::s_captureWindow
= NULL
;
667 wxWindow
* cursorTarget
= currentMouseWindow
;
668 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
670 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
672 cursorTarget
= cursorTarget
->GetParent() ;
674 cursorPoint
+= cursorTarget
->GetPosition();
677 } // else if ( currentMouseWindow )
680 // don't mess with controls we don't know about
681 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
682 // so we try sending them the correct control directly
683 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
685 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
686 Point clickLocation
= windowMouseLocation
;
687 if ( toplevelWindow
->MacUsesCompositing() )
691 hiPoint
.x
= clickLocation
.h
;
692 hiPoint
.y
= clickLocation
.v
;
693 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
694 clickLocation
.h
= (int)hiPoint
.x
;
695 clickLocation
.v
= (int)hiPoint
.y
;
699 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
706 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
708 OSStatus result
= eventNotHandledErr
;
710 wxMacCarbonEvent
cEvent( event
) ;
712 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
713 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
715 switch ( GetEventKind( event
) )
717 case kEventWindowActivated
:
719 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
720 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
721 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
722 wxevent
.SetEventObject(toplevelWindow
);
723 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
724 // we still sending an eventNotHandledErr in order to allow for default processing
728 case kEventWindowDeactivated
:
730 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
731 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
732 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
733 wxevent
.SetEventObject(toplevelWindow
);
734 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
735 // we still sending an eventNotHandledErr in order to allow for default processing
739 case kEventWindowShown
:
740 toplevelWindow
->Refresh() ;
744 case kEventWindowClose
:
745 toplevelWindow
->Close() ;
749 case kEventWindowBoundsChanged
:
751 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
752 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
753 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
754 if ( attributes
& kWindowBoundsChangeSizeChanged
)
756 // according to the other ports we handle this within the OS level
757 // resize event, not within a wxSizeEvent
758 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
762 frame
->PositionStatusBar();
765 frame
->PositionToolBar();
769 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
770 event
.SetEventObject( toplevelWindow
) ;
772 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
773 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
776 if ( attributes
& kWindowBoundsChangeOriginChanged
)
778 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
779 event
.SetEventObject( toplevelWindow
) ;
780 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
787 case kEventWindowBoundsChanging
:
789 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
790 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
792 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
794 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
795 int left
, top
, right
, bottom
;
796 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
801 newRect
.right
- newRect
.left
+ left
+ right
,
802 newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
804 // this is a EVT_SIZING not a EVT_SIZE type !
805 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
806 wxevent
.SetEventObject( toplevelWindow
) ;
808 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
809 adjustR
= wxevent
.GetRect() ;
811 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
812 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
813 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
814 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
815 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
816 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
817 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
818 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
819 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
820 if ( !EqualRect( &newRect
, &adjustedRect
) )
821 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
822 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
836 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
838 OSStatus result
= eventNotHandledErr
;
840 switch ( GetEventClass( event
) )
842 case kEventClassKeyboard
:
843 result
= KeyboardEventHandler( handler
, event
, data
) ;
846 case kEventClassTextInput
:
847 result
= TextInputEventHandler( handler
, event
, data
) ;
850 case kEventClassWindow
:
851 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
854 case kEventClassMouse
:
855 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
865 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
867 // ---------------------------------------------------------------------------
868 // wxWindowMac utility functions
869 // ---------------------------------------------------------------------------
871 // Find an item given the Macintosh Window Reference
873 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
875 static MacWindowMap wxWinMacWindowList
;
877 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
879 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
881 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
884 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
885 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
887 // adding NULL WindowRef is (first) surely a result of an error and
889 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
891 wxWinMacWindowList
[inWindowRef
] = win
;
894 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
895 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
897 MacWindowMap::iterator it
;
898 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
900 if ( it
->second
== win
)
902 wxWinMacWindowList
.erase(it
);
908 // ----------------------------------------------------------------------------
909 // wxTopLevelWindowMac creation
910 // ----------------------------------------------------------------------------
912 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
921 void wxTopLevelWindowMac::Init()
924 m_maximizeOnShow
= false;
927 #if TARGET_API_MAC_OSX
928 m_macUsesCompositing
= ( UMAGetSystemVersion() >= 0x1030 );
930 m_macUsesCompositing
= false;
933 m_macEventHandler
= NULL
;
934 m_macFullScreenData
= NULL
;
937 class wxMacDeferredWindowDeleter
: public wxObject
940 wxMacDeferredWindowDeleter( WindowRef windowRef
)
942 m_macWindow
= windowRef
;
945 virtual ~wxMacDeferredWindowDeleter()
947 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
951 WindowRef m_macWindow
;
954 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
956 const wxString
& title
,
960 const wxString
& name
)
965 m_windowStyle
= style
;
969 m_windowId
= id
== -1 ? NewControlId() : id
;
970 wxWindow::SetLabel( title
) ;
972 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
974 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
976 if (GetExtraStyle() & wxFRAME_EX_METAL
)
977 MacSetMetalAppearance(true);
979 wxTopLevelWindows
.Append(this);
982 parent
->AddChild(this);
987 wxTopLevelWindowMac::~wxTopLevelWindowMac()
992 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
994 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
997 if ( m_macEventHandler
)
999 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1000 m_macEventHandler
= NULL
;
1003 wxRemoveMacWindowAssociation( this ) ;
1005 if ( wxModelessWindows
.Find(this) )
1006 wxModelessWindows
.DeleteObject(this);
1008 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1010 m_macFullScreenData
= NULL
;
1014 // ----------------------------------------------------------------------------
1015 // wxTopLevelWindowMac maximize/minimize
1016 // ----------------------------------------------------------------------------
1018 void wxTopLevelWindowMac::Maximize(bool maximize
)
1020 // TODO Check, is this still necessary
1022 wxMacPortStateHelper
help( (GrafPtr
) GetWindowPort( (WindowRef
) m_macWindow
) ) ;
1023 wxMacWindowClipper
clip (this);
1026 if ( !IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) )
1029 GetWindowBounds((WindowRef
)m_macWindow
, kWindowGlobalPortRgn
, &rect
);
1030 SetWindowIdealUserState((WindowRef
)m_macWindow
, &rect
);
1031 SetWindowUserState((WindowRef
)m_macWindow
, &rect
);
1034 ZoomWindow( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, false ) ;
1037 bool wxTopLevelWindowMac::IsMaximized() const
1039 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
1042 void wxTopLevelWindowMac::Iconize(bool iconize
)
1044 if ( IsWindowCollapsable( (WindowRef
)m_macWindow
) )
1045 CollapseWindow( (WindowRef
)m_macWindow
, iconize
) ;
1048 bool wxTopLevelWindowMac::IsIconized() const
1050 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1053 void wxTopLevelWindowMac::Restore()
1055 if ( IsMaximized() )
1057 else if ( IsIconized() )
1061 // ----------------------------------------------------------------------------
1062 // wxTopLevelWindowMac misc
1063 // ----------------------------------------------------------------------------
1065 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1067 return wxPoint(0, 0) ;
1070 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
1073 wxTopLevelWindowBase::SetIcon(icon
);
1076 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1078 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1080 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1082 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1086 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1088 if ( m_macEventHandler
!= NULL
)
1090 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1093 InstallWindowEventHandler(
1094 MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1095 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1098 void wxTopLevelWindowMac::MacCreateRealWindow( const wxString
& title
,
1102 const wxString
& name
)
1104 OSStatus err
= noErr
;
1106 m_windowStyle
= style
;
1114 wxRect display
= wxGetClientDisplayRect() ;
1116 if ( x
== wxDefaultPosition
.x
)
1119 if ( y
== wxDefaultPosition
.y
)
1122 int w
= WidthDefault(size
.x
);
1123 int h
= HeightDefault(size
.y
);
1125 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1127 // translate the window attributes in the appropriate window class and attributes
1128 WindowClass wclass
= 0;
1129 WindowAttributes attr
= kWindowNoAttributes
;
1130 WindowGroupRef group
= NULL
;
1132 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1135 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1136 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1137 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1140 wclass
= kFloatingWindowClass
;
1142 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1143 attr
|= kWindowSideTitlebarAttribute
;
1147 wclass
= kPlainWindowClass
;
1150 else if ( HasFlag( wxCAPTION
) )
1152 wclass
= kDocumentWindowClass
;
1153 attr
|= kWindowInWindowMenuAttribute
;
1155 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1156 else if ( HasFlag( wxFRAME_DRAWER
) )
1158 wclass
= kDrawerWindowClass
;
1159 // we must force compositing on a drawer
1160 m_macUsesCompositing
= true ;
1162 #endif //10.2 and up
1165 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1166 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1168 wclass
= kDocumentWindowClass
;
1172 wclass
= kPlainWindowClass
;
1176 if ( wclass
!= kPlainWindowClass
)
1178 if ( HasFlag( wxMINIMIZE_BOX
) )
1179 attr
|= kWindowCollapseBoxAttribute
;
1181 if ( HasFlag( wxMAXIMIZE_BOX
) )
1182 attr
|= kWindowFullZoomAttribute
;
1184 if ( HasFlag( wxRESIZE_BORDER
) )
1185 attr
|= kWindowResizableAttribute
;
1187 if ( HasFlag( wxCLOSE_BOX
) )
1188 attr
|= kWindowCloseBoxAttribute
;
1191 // turn on live resizing (OS X only)
1192 if (UMAGetSystemVersion() >= 0x1000)
1193 attr
|= kWindowLiveResizeAttribute
;
1195 if ( HasFlag(wxSTAY_ON_TOP
) )
1196 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1198 #if TARGET_API_MAC_OSX
1199 if ( m_macUsesCompositing
)
1200 attr
|= kWindowCompositingAttribute
;
1203 if ( HasFlag(wxFRAME_SHAPED
) )
1205 WindowDefSpec customWindowDefSpec
;
1206 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1207 customWindowDefSpec
.u
.defProc
= NewWindowDefUPP(wxShapedMacWindowDef
);
1209 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1210 attr
, &theBoundsRect
,
1211 (WindowRef
*) &m_macWindow
);
1215 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1218 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1219 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1221 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1223 // the create commands are only for content rect, so we have to set the size again as
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*/) ;
1230 #if TARGET_API_MAC_OSX
1232 if ( m_macUsesCompositing
)
1234 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1235 // the content view, so we have to retrieve it explicitly
1236 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1237 m_peer
->GetControlRefAddr() ) ;
1238 if ( !m_peer
->Ok() )
1240 // compatibility mode fallback
1241 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1246 ::CreateRootControl( (WindowRef
)m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1249 // the root control level handler
1250 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1252 #if TARGET_API_MAC_OSX
1253 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1255 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1256 MacSetMetalAppearance( true ) ;
1260 // the frame window event handler
1261 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1262 MacInstallTopLevelWindowEventHandler() ;
1264 DoSetWindowVariant( m_windowVariant
) ;
1268 if ( HasFlag(wxFRAME_SHAPED
) )
1270 // default shape matches the window size
1271 wxRegion
rgn( 0, 0, w
, h
);
1275 wxWindowCreateEvent
event(this);
1276 GetEventHandler()->ProcessEvent(event
);
1279 void wxTopLevelWindowMac::ClearBackground()
1281 wxWindow::ClearBackground() ;
1284 // Raise the window to the top of the Z order
1285 void wxTopLevelWindowMac::Raise()
1287 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1290 // Lower the window to the bottom of the Z order
1291 void wxTopLevelWindowMac::Lower()
1293 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1296 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1298 if (s_macDeactivateWindow
)
1300 wxLogTrace(TRACE_ACTIVATE
,
1301 wxT("Doing delayed deactivation of %p"),
1302 s_macDeactivateWindow
);
1304 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1308 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1310 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1312 if (s_macDeactivateWindow
== this)
1313 s_macDeactivateWindow
= NULL
;
1315 MacDelayedDeactivation(timestamp
);
1316 MacPropagateHiliteChanged() ;
1319 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1321 wxWindow::SetLabel( title
) ;
1322 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1325 wxString
wxTopLevelWindowMac::GetTitle() const
1327 return wxWindow::GetLabel();
1330 bool wxTopLevelWindowMac::Show(bool show
)
1332 if ( !wxTopLevelWindowBase::Show(show
) )
1337 #if wxUSE_SYSTEM_OPTIONS // code contributed by Ryan Wilcox December 18, 2003
1338 bool plainTransition
= UMAGetSystemVersion() >= 0x1000 ;
1339 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1340 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1342 if ( plainTransition
)
1344 ::ShowWindow( (WindowRef
)m_macWindow
);
1349 ::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 wxUSE_SYSTEM_OPTIONS
1362 bool plainTransition
= UMAGetSystemVersion() >= 0x1000 ;
1363 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1364 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1365 if ( plainTransition
)
1367 ::HideWindow((WindowRef
) m_macWindow
);
1372 ::TransitionWindow((WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1376 MacPropagateVisibilityChanged() ;
1381 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1385 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1387 data
= new FullScreenData() ;
1389 m_macFullScreenData
= data
;
1390 data
->m_position
= GetPosition() ;
1391 data
->m_size
= GetSize() ;
1393 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1396 wxRect client
= wxGetClientDisplayRect() ;
1398 int left
, top
, right
, bottom
;
1406 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1408 if ( style
& wxFULLSCREEN_NOCAPTION
)
1414 if ( style
& wxFULLSCREEN_NOBORDER
)
1421 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1426 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1431 SetSize( x
, y
, w
, h
) ;
1436 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1437 SetPosition( data
->m_position
) ;
1438 SetSize( data
->m_size
) ;
1441 m_macFullScreenData
= NULL
;
1447 bool wxTopLevelWindowMac::IsFullScreen() const
1449 return m_macFullScreenData
!= NULL
;
1452 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1454 if ( GetExtraStyle() == exStyle
)
1457 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1459 #if TARGET_API_MAC_OSX
1460 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1462 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1463 if ( MacGetMetalAppearance() != metal
)
1464 MacSetMetalAppearance( metal
) ;
1469 // we are still using coordinates of the content view; TODO: switch to structure bounds
1471 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1475 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1476 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1478 left
= content
.left
- structure
.left
;
1479 top
= content
.top
- structure
.top
;
1480 right
= structure
.right
- content
.right
;
1481 bottom
= structure
.bottom
- content
.bottom
;
1484 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1486 m_cachedClippedRectValid
= false ;
1487 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1488 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1489 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1492 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1496 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1504 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1508 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1511 *width
= bounds
.right
- bounds
.left
;
1513 *height
= bounds
.bottom
- bounds
.top
;
1516 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1520 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1523 *width
= bounds
.right
- bounds
.left
;
1525 *height
= bounds
.bottom
- bounds
.top
;
1528 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1530 #if TARGET_API_MAC_OSX
1531 wxASSERT_MSG( m_macUsesCompositing
,
1532 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1534 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1535 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1539 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1541 #if TARGET_API_MAC_OSX
1542 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1548 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1550 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1553 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1556 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1561 void wxTopLevelWindowMac::MacPerformUpdates()
1563 #if TARGET_API_MAC_OSX
1564 if ( m_macUsesCompositing
)
1566 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1567 // for composited windows this also triggers a redraw of all
1568 // invalid views in the window
1569 if ( UMAGetSystemVersion() >= 0x1030 )
1570 HIWindowFlush((WindowRef
) m_macWindow
) ;
1574 // the only way to trigger the redrawing on earlier systems is to call
1577 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1578 UInt32 currentEventClass
= 0 ;
1579 UInt32 currentEventKind
= 0 ;
1580 if ( currentEvent
!= NULL
)
1582 currentEventClass
= ::GetEventClass( currentEvent
) ;
1583 currentEventKind
= ::GetEventKind( currentEvent
) ;
1586 if ( currentEventClass
!= kEventClassMenu
)
1588 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1590 OSStatus status
= noErr
;
1591 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1598 BeginUpdate( (WindowRef
) m_macWindow
) ;
1600 RgnHandle updateRgn
= NewRgn();
1603 GetPortVisibleRegion( GetWindowPort( (WindowRef
)m_macWindow
), updateRgn
);
1604 UpdateControls( (WindowRef
)m_macWindow
, updateRgn
) ;
1606 // if ( !EmptyRgn( updateRgn ) )
1607 // MacDoRedraw( updateRgn , 0 , true) ;
1609 DisposeRgn( updateRgn
);
1612 EndUpdate( (WindowRef
)m_macWindow
) ;
1613 QDFlushPortBuffer( GetWindowPort( (WindowRef
)m_macWindow
) , NULL
) ;
1617 // Attracts the users attention to this window if the application is
1618 // inactive (should be called when a background event occurs)
1620 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1623 DisposePtr( (Ptr
) ptr
) ;
1627 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1629 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1630 static wxMacNMUPP
nmupp( wxMacNMResponse
);
1632 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1633 notificationRequest
->qType
= nmType
;
1634 notificationRequest
->nmMark
= 1 ;
1635 notificationRequest
->nmIcon
= 0 ;
1636 notificationRequest
->nmSound
= 0 ;
1637 notificationRequest
->nmStr
= NULL
;
1638 notificationRequest
->nmResp
= nmupp
;
1640 verify_noerr( NMInstall( notificationRequest
) ) ;
1643 // ---------------------------------------------------------------------------
1644 // Shape implementation
1645 // ---------------------------------------------------------------------------
1648 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1650 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1651 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1653 // The empty region signifies that the shape should be removed from the
1655 if ( region
.IsEmpty() )
1657 wxSize sz
= GetClientSize();
1658 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1659 if ( rgn
.IsEmpty() )
1662 return SetShape(rgn
);
1665 // Make a copy of the region
1666 RgnHandle shapeRegion
= NewRgn();
1667 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1669 // Dispose of any shape region we may already have
1670 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1674 // Save the region so we can use it later
1675 SetWRefCon((WindowRef
)MacGetWindowRef(), (SInt32
)shapeRegion
);
1677 // inform the window manager that the window has changed shape
1678 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1683 // ---------------------------------------------------------------------------
1684 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1685 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1686 // ---------------------------------------------------------------------------
1688 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1690 GetWindowPortBounds(window
, inRect
);
1691 Point pt
= {inRect
->left
, inRect
->top
};
1692 QDLocalToGlobalPoint( GetWindowPort(window
) , &pt
) ;
1694 inRect
->left
= pt
.h
;
1695 inRect
->bottom
+= pt
.v
;
1696 inRect
->right
+= pt
.h
;
1699 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1701 /*------------------------------------------------------
1702 Define which options your custom window supports.
1703 --------------------------------------------------------*/
1704 //just enable everything for our demo
1705 *(OptionBits
*)param
=
1708 //kWindowCanCollapse |
1709 //kWindowCanGetWindowRegion |
1710 //kWindowHasTitleBar |
1711 //kWindowSupportsDragHilite |
1712 kWindowCanDrawInCurrentPort
|
1713 //kWindowCanMeasureTitle |
1714 kWindowWantsDisposeAtProcessDeath
|
1715 kWindowSupportsGetGrowImageRegion
|
1716 kWindowDefSupportsColorGrafPort
;
1721 // The content region is left as a rectangle matching the window size, this is
1722 // so the origin in the paint event, and etc. still matches what the
1723 // programmer expects.
1724 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1727 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1731 wxShapedMacWindowGetPos( window
, &r
) ;
1732 RectRgn( rgn
, &r
) ;
1736 // The structure region is set to the shape given to the SetShape method.
1737 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1739 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1745 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1746 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1747 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1748 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1752 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1754 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1759 switch (rgnRec
->regionCode
)
1761 case kWindowStructureRgn
:
1762 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1765 case kWindowContentRgn
:
1766 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1770 SetEmptyRgn(rgnRec
->winRgn
);
1777 // Determine the region of the window which was hit
1779 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1782 static RgnHandle tempRgn
= NULL
;
1784 if (tempRgn
== NULL
)
1787 // get the point clicked
1788 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1790 // Mac OS 8.5 or later
1791 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1792 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1795 // no significant area was hit
1799 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1803 case kWindowMsgHitTest
:
1804 return wxShapedMacWindowHitTest(window
, param
);
1806 case kWindowMsgGetFeatures
:
1807 return wxShapedMacWindowGetFeatures(window
, param
);
1809 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1810 case kWindowMsgGetRegion
:
1811 return wxShapedMacWindowGetRegion(window
, param
);