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"
45 #if wxUSE_SYSTEM_OPTIONS
46 #include "wx/sysopt.h"
50 #include <ToolUtils.h>
54 #include "wx/mac/private.h"
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 // trace mask for activation tracing messages
61 static const wxChar
*TRACE_ACTIVATE
= _T("activation");
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 // list of all frames and modeless dialogs
68 wxWindowList wxModelessWindows
;
70 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
72 // ============================================================================
73 // wxTopLevelWindowMac implementation
74 // ============================================================================
76 BEGIN_EVENT_TABLE(wxTopLevelWindowMac
, wxTopLevelWindowBase
)
80 // ---------------------------------------------------------------------------
82 // ---------------------------------------------------------------------------
84 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
86 static const EventTypeSpec eventList
[] =
88 // TODO: remove control related event like key and mouse (except for WindowLeave events)
90 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
92 { kEventClassKeyboard
, kEventRawKeyDown
} ,
93 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
94 { kEventClassKeyboard
, kEventRawKeyUp
} ,
95 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
98 { kEventClassWindow
, kEventWindowShown
} ,
99 { kEventClassWindow
, kEventWindowActivated
} ,
100 { kEventClassWindow
, kEventWindowDeactivated
} ,
101 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
102 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
103 { kEventClassWindow
, kEventWindowClose
} ,
105 // we have to catch these events on the toplevel window level,
106 // as controls don't get the raw mouse events anymore
108 { kEventClassMouse
, kEventMouseDown
} ,
109 { kEventClassMouse
, kEventMouseUp
} ,
110 { kEventClassMouse
, kEventMouseWheelMoved
} ,
111 { kEventClassMouse
, kEventMouseMoved
} ,
112 { kEventClassMouse
, kEventMouseDragged
} ,
115 static pascal OSStatus
TextInputEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
117 OSStatus result
= eventNotHandledErr
;
119 UInt32 keyCode
, modifiers
;
122 unsigned char charCode
;
124 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
, typeEventRef
, NULL
, sizeof(rawEvent
), NULL
, &rawEvent
) ;
126 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
127 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
128 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
129 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
131 focus
= wxWindow::FindFocus() ;
133 switch ( GetEventKind( event
) )
135 case kEventTextInputUnicodeForKeyEvent
:
137 // this is only called when no default handler has jumped in, e.g. a wxControl on a floater window does not
138 // get its own kEventTextInputUnicodeForKeyEvent, so we reroute the event back to the control
139 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
142 ControlRef macControl
= (ControlRef
) control
->GetHandle() ;
145 ::HandleControlKey( macControl
, keyCode
, charCode
, modifiers
) ;
151 // this may lead to double events sent to a window in case all handlers have skipped the key down event
152 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
153 UInt32 message
= (keyCode
<< 8) + charCode
;
155 if ( (focus
!= NULL
) &&
156 wxTheApp
->MacSendKeyDownEvent( focus
, message
, modifiers
, when
, point
.h
, point
.v
) )
171 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
173 OSStatus result
= eventNotHandledErr
;
174 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
175 // FindFocus does not return the actual focus window, but the enclosing window
176 wxWindow
* focus
= wxWindow::DoFindFocus();
178 focus
= (wxTopLevelWindowMac
*) data
;
180 unsigned char charCode
;
185 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
188 UInt32 dataSize
= 0 ;
189 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
193 UniChar
* charBuf
= buf
;
196 charBuf
= new UniChar
[ dataSize
/ sizeof( UniChar
) ] ;
197 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
199 #if SIZEOF_WCHAR_T == 2
200 uniChar
= charBuf
[0] ;
202 wxMBConvUTF16 converter
;
203 converter
.MB2WC( &uniChar
, (const char*)charBuf
, 1 ) ;
211 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
212 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
213 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
214 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
216 UInt32 message
= (keyCode
<< 8) + charCode
;
217 switch ( GetEventKind( event
) )
219 case kEventRawKeyRepeat
:
220 case kEventRawKeyDown
:
222 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
223 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
224 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
225 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
226 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
) )
230 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
234 case kEventRawKeyUp
:
235 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
236 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
) )
242 case kEventRawKeyModifiersChanged
:
244 wxKeyEvent
event(wxEVT_KEY_DOWN
);
246 event
.m_shiftDown
= modifiers
& shiftKey
;
247 event
.m_controlDown
= modifiers
& controlKey
;
248 event
.m_altDown
= modifiers
& optionKey
;
249 event
.m_metaDown
= modifiers
& cmdKey
;
254 event
.m_uniChar
= uniChar
;
257 event
.SetTimestamp(when
);
258 event
.SetEventObject(focus
);
260 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
262 event
.m_keyCode
= WXK_CONTROL
;
263 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
264 focus
->GetEventHandler()->ProcessEvent( event
) ;
266 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
268 event
.m_keyCode
= WXK_SHIFT
;
269 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
270 focus
->GetEventHandler()->ProcessEvent( event
) ;
272 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
274 event
.m_keyCode
= WXK_ALT
;
275 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
276 focus
->GetEventHandler()->ProcessEvent( event
) ;
278 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
280 event
.m_keyCode
= WXK_COMMAND
;
281 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
282 focus
->GetEventHandler()->ProcessEvent( event
) ;
285 wxApp::s_lastModifiers
= modifiers
;
296 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
297 // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
300 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
302 wxWindow
* g_MacLastWindow
= NULL
;
304 static EventMouseButton lastButton
= 0 ;
306 static void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
308 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
309 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
311 // this parameter are not given for all events
312 EventMouseButton button
= 0 ;
313 UInt32 clickCount
= 0 ;
314 cEvent
.GetParameter
<EventMouseButton
>( kEventParamMouseButton
, typeMouseButton
, &button
) ;
315 cEvent
.GetParameter
<UInt32
>( kEventParamClickCount
, typeUInt32
, &clickCount
) ;
317 wxevent
.m_x
= screenMouseLocation
.h
;
318 wxevent
.m_y
= screenMouseLocation
.v
;
319 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
320 wxevent
.m_controlDown
= modifiers
& controlKey
;
321 wxevent
.m_altDown
= modifiers
& optionKey
;
322 wxevent
.m_metaDown
= modifiers
& cmdKey
;
323 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
325 // a control click is interpreted as a right click
326 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
327 button
= kEventMouseButtonSecondary
;
329 // otherwise we report double clicks by connecting a left click with a ctrl-left click
330 if ( clickCount
> 1 && button
!= lastButton
)
333 // we must make sure that our synthetic 'right' button corresponds in
334 // mouse down, moved and mouse up, and does not deliver a right down and left up
336 if ( cEvent
.GetKind() == kEventMouseDown
)
337 lastButton
= button
;
341 else if ( lastButton
)
342 button
= lastButton
;
344 // determine the correct down state, wx does not want a 'down' for a mouseUp event,
345 // while mac delivers this button
346 if ( button
!= 0 && cEvent
.GetKind() != kEventMouseUp
)
350 case kEventMouseButtonPrimary
:
351 wxevent
.m_leftDown
= true ;
354 case kEventMouseButtonSecondary
:
355 wxevent
.m_rightDown
= true ;
358 case kEventMouseButtonTertiary
:
359 wxevent
.m_middleDown
= true ;
367 // translate into wx types
368 switch ( cEvent
.GetKind() )
370 case kEventMouseDown
:
373 case kEventMouseButtonPrimary
:
374 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
377 case kEventMouseButtonSecondary
:
378 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
381 case kEventMouseButtonTertiary
:
382 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
393 case kEventMouseButtonPrimary
:
394 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
397 case kEventMouseButtonSecondary
:
398 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
401 case kEventMouseButtonTertiary
:
402 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
410 case kEventMouseWheelMoved
:
412 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
414 // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
415 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeLongInteger
) ;
417 wxevent
.m_wheelRotation
= delta
;
418 wxevent
.m_wheelDelta
= 1;
419 wxevent
.m_linesPerAction
= 1;
424 wxevent
.SetEventType( wxEVT_MOTION
) ;
429 ControlRef
wxMacFindSubControl( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, ControlRef superControl
, ControlPartCode
*outPart
)
433 UInt16 childrenCount
= 0 ;
434 ControlHandle sibling
;
436 OSStatus err
= CountSubControls( superControl
, &childrenCount
) ;
437 if ( err
== errControlIsNotEmbedder
)
440 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
442 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
444 err
= GetIndexedSubControl( superControl
, i
, & sibling
) ;
445 if ( err
== errControlIsNotEmbedder
)
448 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
449 if ( IsControlVisible( sibling
) )
451 UMAGetControlBoundsInWindowCoords( sibling
, &r
) ;
452 if ( MacPtInRect( location
, &r
) )
454 ControlHandle child
= wxMacFindSubControl( toplevelWindow
, location
, sibling
, outPart
) ;
461 Point testLocation
= location
;
463 if ( toplevelWindow
&& toplevelWindow
->MacUsesCompositing() )
465 testLocation
.h
-= r
.left
;
466 testLocation
.v
-= r
.top
;
469 *outPart
= TestControl( sibling
, testLocation
) ;
481 ControlRef
wxMacFindControlUnderMouse( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, WindowRef window
, ControlPartCode
*outPart
)
483 #if TARGET_API_MAC_OSX
484 if ( UMAGetSystemVersion() >= 0x1030 && ( toplevelWindow
== 0 || toplevelWindow
->MacUsesCompositing() ) )
485 return FindControlUnderMouse( location
, window
, outPart
) ;
488 ControlRef rootControl
= NULL
;
489 verify_noerr( GetRootControl( window
, &rootControl
) ) ;
491 return wxMacFindSubControl( toplevelWindow
, location
, rootControl
, outPart
) ;
494 #define NEW_CAPTURE_HANDLING 1
496 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
498 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
500 OSStatus result
= eventNotHandledErr
;
502 wxMacCarbonEvent
cEvent( event
) ;
504 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
505 Point windowMouseLocation
= screenMouseLocation
;
508 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
510 wxWindow
* currentMouseWindow
= NULL
;
511 ControlRef control
= NULL
;
513 #if NEW_CAPTURE_HANDLING
514 if ( wxApp::s_captureWindow
)
516 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
517 windowPart
= inContent
;
523 QDGlobalToLocalPoint( UMAGetWindowPort(window
) , &windowMouseLocation
) ;
525 if ( wxApp::s_captureWindow
526 #if !NEW_CAPTURE_HANDLING
527 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
531 currentMouseWindow
= wxApp::s_captureWindow
;
533 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
535 ControlPartCode part
;
536 control
= wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &part
) ;
537 // if there is no control below the mouse position, send the event to the toplevel window itself
540 currentMouseWindow
= (wxWindow
*) data
;
544 currentMouseWindow
= wxFindControlFromMacControl( control
) ;
545 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
548 // for wxToolBar to function we have to send certaint events to it
549 // instead of its children (wxToolBarTools)
551 GetSuperControl(control
, &parent
);
552 wxWindow
*wxParent
= wxFindControlFromMacControl( parent
) ;
553 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
554 currentMouseWindow
= wxParent
;
561 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
562 SetupMouseEvent( wxevent
, cEvent
) ;
564 // handle all enter / leave events
566 if ( currentMouseWindow
!= g_MacLastWindow
)
568 if ( g_MacLastWindow
)
570 wxMouseEvent
eventleave(wxevent
);
571 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
572 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
573 eventleave
.SetEventObject( g_MacLastWindow
) ;
574 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
577 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
580 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
583 if ( currentMouseWindow
)
585 wxMouseEvent
evententer(wxevent
);
586 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
587 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
588 evententer
.SetEventObject( currentMouseWindow
) ;
589 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
592 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
595 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
598 g_MacLastWindow
= currentMouseWindow
;
601 if ( windowPart
== inMenuBar
)
603 // special case menu bar, as we are having a low-level runloop we must do it ourselves
604 if ( cEvent
.GetKind() == kEventMouseDown
)
606 ::MenuSelect( screenMouseLocation
) ;
610 else if ( currentMouseWindow
)
612 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
614 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
616 wxevent
.SetEventObject( currentMouseWindow
) ;
617 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
619 // make tooltips current
622 if ( wxevent
.GetEventType() == wxEVT_MOTION
623 || wxevent
.GetEventType() == wxEVT_ENTER_WINDOW
624 || wxevent
.GetEventType() == wxEVT_LEAVE_WINDOW
)
625 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
628 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
630 if ((currentMouseWindowParent
!= NULL
) &&
631 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
632 currentMouseWindow
= NULL
;
638 // if the user code did _not_ handle the event, then perform the
639 // default processing
640 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
642 // ... that is set focus to this window
643 if (currentMouseWindow
->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
644 currentMouseWindow
->SetFocus();
647 ControlPartCode dummyPart
;
648 // if built-in find control is finding the wrong control (ie static box instead of overlaid
649 // button, we cannot let the standard handler do its job, but must handle manually
651 if ( ( cEvent
.GetKind() == kEventMouseDown
)
654 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
655 wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &dummyPart
) )
659 if ( currentMouseWindow
->MacIsReallyEnabled() )
661 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
662 Point clickLocation
= windowMouseLocation
;
664 if ( toplevelWindow
->MacUsesCompositing() )
665 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
667 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
668 modifiers
, (ControlActionUPP
) -1 ) ;
670 if ((currentMouseWindowParent
!= NULL
) &&
671 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
673 currentMouseWindow
= NULL
;
681 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
683 wxApp::s_captureWindow
= NULL
;
689 wxWindow
* cursorTarget
= currentMouseWindow
;
690 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
692 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
694 cursorTarget
= cursorTarget
->GetParent() ;
696 cursorPoint
+= cursorTarget
->GetPosition();
699 } // else if ( currentMouseWindow )
702 // don't mess with controls we don't know about
703 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
704 // so we try sending them the correct control directly
705 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
707 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
708 Point clickLocation
= windowMouseLocation
;
709 if ( toplevelWindow
->MacUsesCompositing() )
713 hiPoint
.x
= clickLocation
.h
;
714 hiPoint
.y
= clickLocation
.v
;
715 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
716 clickLocation
.h
= (int)hiPoint
.x
;
717 clickLocation
.v
= (int)hiPoint
.y
;
721 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
729 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
731 OSStatus result
= eventNotHandledErr
;
733 wxMacCarbonEvent
cEvent( event
) ;
735 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
736 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
738 switch ( GetEventKind( event
) )
740 case kEventWindowActivated
:
742 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
743 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
744 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
745 wxevent
.SetEventObject(toplevelWindow
);
746 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
747 // we still sending an eventNotHandledErr in order to allow for default processing
751 case kEventWindowDeactivated
:
753 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
754 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
755 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
756 wxevent
.SetEventObject(toplevelWindow
);
757 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
758 // we still sending an eventNotHandledErr in order to allow for default processing
762 case kEventWindowShown
:
763 toplevelWindow
->Refresh() ;
767 case kEventWindowClose
:
768 toplevelWindow
->Close() ;
772 case kEventWindowBoundsChanged
:
774 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
775 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
776 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
777 if ( attributes
& kWindowBoundsChangeSizeChanged
)
779 // according to the other ports we handle this within the OS level
780 // resize event, not within a wxSizeEvent
781 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
785 frame
->PositionStatusBar();
788 frame
->PositionToolBar();
792 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
793 event
.SetEventObject( toplevelWindow
) ;
795 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
796 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
799 if ( attributes
& kWindowBoundsChangeOriginChanged
)
801 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
802 event
.SetEventObject( toplevelWindow
) ;
803 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
810 case kEventWindowBoundsChanging
:
812 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
813 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
815 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
817 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
818 int left
, top
, right
, bottom
;
819 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
824 newRect
.right
- newRect
.left
+ left
+ right
,
825 newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
827 // this is a EVT_SIZING not a EVT_SIZE type !
828 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
829 wxevent
.SetEventObject( toplevelWindow
) ;
831 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
832 adjustR
= wxevent
.GetRect() ;
834 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
835 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
836 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
837 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
838 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
839 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
840 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
841 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
842 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
843 if ( !EqualRect( &newRect
, &adjustedRect
) )
844 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
845 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
859 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
861 OSStatus result
= eventNotHandledErr
;
863 switch ( GetEventClass( event
) )
865 case kEventClassKeyboard
:
866 result
= KeyboardEventHandler( handler
, event
, data
) ;
869 case kEventClassTextInput
:
870 result
= TextInputEventHandler( handler
, event
, data
) ;
873 case kEventClassWindow
:
874 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
877 case kEventClassMouse
:
878 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
888 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
890 // ---------------------------------------------------------------------------
891 // wxWindowMac utility functions
892 // ---------------------------------------------------------------------------
894 // Find an item given the Macintosh Window Reference
896 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
898 static MacWindowMap wxWinMacWindowList
;
900 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
902 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
904 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
907 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
908 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
910 // adding NULL WindowRef is (first) surely a result of an error and
912 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
914 wxWinMacWindowList
[inWindowRef
] = win
;
917 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
918 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
920 MacWindowMap::iterator it
;
921 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
923 if ( it
->second
== win
)
925 wxWinMacWindowList
.erase(it
);
931 // ----------------------------------------------------------------------------
932 // wxTopLevelWindowMac creation
933 // ----------------------------------------------------------------------------
935 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
941 bool m_wasResizable
;
945 void wxTopLevelWindowMac::Init()
948 m_maximizeOnShow
= false;
951 #if TARGET_API_MAC_OSX
952 m_macUsesCompositing
= ( UMAGetSystemVersion() >= 0x1030 );
954 m_macUsesCompositing
= false;
957 m_macEventHandler
= NULL
;
958 m_macFullScreenData
= NULL
;
961 class wxMacDeferredWindowDeleter
: public wxObject
964 wxMacDeferredWindowDeleter( WindowRef windowRef
)
966 m_macWindow
= windowRef
;
969 virtual ~wxMacDeferredWindowDeleter()
971 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
975 WindowRef m_macWindow
;
978 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
980 const wxString
& title
,
984 const wxString
& name
)
989 m_windowStyle
= style
;
993 m_windowId
= id
== -1 ? NewControlId() : id
;
994 wxWindow::SetLabel( title
) ;
996 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
998 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
1000 if (GetExtraStyle() & wxFRAME_EX_METAL
)
1001 MacSetMetalAppearance(true);
1003 wxTopLevelWindows
.Append(this);
1006 parent
->AddChild(this);
1011 wxTopLevelWindowMac::~wxTopLevelWindowMac()
1016 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
1018 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
1021 if ( m_macEventHandler
)
1023 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1024 m_macEventHandler
= NULL
;
1027 wxRemoveMacWindowAssociation( this ) ;
1029 if ( wxModelessWindows
.Find(this) )
1030 wxModelessWindows
.DeleteObject(this);
1032 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1034 m_macFullScreenData
= NULL
;
1038 // ----------------------------------------------------------------------------
1039 // wxTopLevelWindowMac maximize/minimize
1040 // ----------------------------------------------------------------------------
1042 void wxTopLevelWindowMac::Maximize(bool maximize
)
1044 // TODO: check if this is still necessary
1046 wxMacPortStateHelper
help( (GrafPtr
)GetWindowPort( (WindowRef
)m_macWindow
) ) ;
1047 wxMacWindowClipper
clip( this );
1050 if ( !IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) )
1054 GetWindowBounds((WindowRef
)m_macWindow
, kWindowGlobalPortRgn
, &rect
);
1055 SetWindowIdealUserState((WindowRef
)m_macWindow
, &rect
);
1056 SetWindowUserState((WindowRef
)m_macWindow
, &rect
);
1059 ZoomWindow( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, false ) ;
1062 bool wxTopLevelWindowMac::IsMaximized() const
1064 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
1067 void wxTopLevelWindowMac::Iconize(bool iconize
)
1069 if ( IsWindowCollapsable( (WindowRef
)m_macWindow
) )
1070 CollapseWindow( (WindowRef
)m_macWindow
, iconize
) ;
1073 bool wxTopLevelWindowMac::IsIconized() const
1075 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1078 void wxTopLevelWindowMac::Restore()
1080 if ( IsMaximized() )
1082 else if ( IsIconized() )
1086 // ----------------------------------------------------------------------------
1087 // wxTopLevelWindowMac misc
1088 // ----------------------------------------------------------------------------
1090 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1092 return wxPoint(0, 0) ;
1095 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
1098 wxTopLevelWindowBase::SetIcon(icon
);
1101 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1103 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1105 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1107 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1111 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1113 if ( m_macEventHandler
!= NULL
)
1115 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1118 InstallWindowEventHandler(
1119 MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1120 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1123 void wxTopLevelWindowMac::MacCreateRealWindow(
1124 const wxString
& title
,
1128 const wxString
& name
)
1130 OSStatus err
= noErr
;
1132 m_windowStyle
= style
;
1140 wxRect display
= wxGetClientDisplayRect() ;
1142 if ( x
== wxDefaultPosition
.x
)
1145 if ( y
== wxDefaultPosition
.y
)
1148 int w
= WidthDefault(size
.x
);
1149 int h
= HeightDefault(size
.y
);
1151 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1153 // translate the window attributes in the appropriate window class and attributes
1154 WindowClass wclass
= 0;
1155 WindowAttributes attr
= kWindowNoAttributes
;
1156 WindowGroupRef group
= NULL
;
1158 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1161 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1162 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1163 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1166 wclass
= kFloatingWindowClass
;
1168 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1169 attr
|= kWindowSideTitlebarAttribute
;
1173 wclass
= kPlainWindowClass
;
1176 else if ( HasFlag( wxCAPTION
) )
1178 wclass
= kDocumentWindowClass
;
1179 attr
|= kWindowInWindowMenuAttribute
;
1181 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1182 else if ( HasFlag( wxFRAME_DRAWER
) )
1184 wclass
= kDrawerWindowClass
;
1185 // we must force compositing on a drawer
1186 m_macUsesCompositing
= true ;
1188 #endif //10.2 and up
1191 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1192 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1194 wclass
= kDocumentWindowClass
;
1198 wclass
= kPlainWindowClass
;
1202 if ( wclass
!= kPlainWindowClass
)
1204 if ( HasFlag( wxMINIMIZE_BOX
) )
1205 attr
|= kWindowCollapseBoxAttribute
;
1207 if ( HasFlag( wxMAXIMIZE_BOX
) )
1208 attr
|= kWindowFullZoomAttribute
;
1210 if ( HasFlag( wxRESIZE_BORDER
) )
1211 attr
|= kWindowResizableAttribute
;
1213 if ( HasFlag( wxCLOSE_BOX
) )
1214 attr
|= kWindowCloseBoxAttribute
;
1217 // turn on live resizing (OS X only)
1218 if (UMAGetSystemVersion() >= 0x1000)
1219 attr
|= kWindowLiveResizeAttribute
;
1221 if ( HasFlag(wxSTAY_ON_TOP
) )
1222 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1224 #if TARGET_API_MAC_OSX
1225 if ( m_macUsesCompositing
)
1226 attr
|= kWindowCompositingAttribute
;
1229 if ( HasFlag(wxFRAME_SHAPED
) )
1231 WindowDefSpec customWindowDefSpec
;
1232 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1233 customWindowDefSpec
.u
.defProc
= NewWindowDefUPP(wxShapedMacWindowDef
);
1235 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1236 attr
, &theBoundsRect
,
1237 (WindowRef
*) &m_macWindow
);
1241 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1244 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1245 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1247 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1249 // the create commands are only for content rect,
1250 // so we have to set the size again as structure bounds
1251 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1253 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1254 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1255 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1257 #if TARGET_API_MAC_OSX
1258 if ( m_macUsesCompositing
)
1260 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1261 // the content view, so we have to retrieve it explicitly
1262 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1263 m_peer
->GetControlRefAddr() ) ;
1264 if ( !m_peer
->Ok() )
1266 // compatibility mode fallback
1267 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1272 ::CreateRootControl( (WindowRef
)m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1275 // the root control level handler
1276 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1278 #if TARGET_API_MAC_OSX
1279 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1281 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1282 MacSetMetalAppearance( true ) ;
1286 // the frame window event handler
1287 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1288 MacInstallTopLevelWindowEventHandler() ;
1290 DoSetWindowVariant( m_windowVariant
) ;
1294 if ( HasFlag(wxFRAME_SHAPED
) )
1296 // default shape matches the window size
1297 wxRegion
rgn( 0, 0, w
, h
);
1301 wxWindowCreateEvent
event(this);
1302 GetEventHandler()->ProcessEvent(event
);
1305 void wxTopLevelWindowMac::ClearBackground()
1307 wxWindow::ClearBackground() ;
1310 // Raise the window to the top of the Z order
1311 void wxTopLevelWindowMac::Raise()
1313 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1316 // Lower the window to the bottom of the Z order
1317 void wxTopLevelWindowMac::Lower()
1319 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1322 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1324 if (s_macDeactivateWindow
)
1326 wxLogTrace(TRACE_ACTIVATE
,
1327 wxT("Doing delayed deactivation of %p"),
1328 s_macDeactivateWindow
);
1330 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1334 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1336 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1338 if (s_macDeactivateWindow
== this)
1339 s_macDeactivateWindow
= NULL
;
1341 MacDelayedDeactivation(timestamp
);
1342 MacPropagateHiliteChanged() ;
1345 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1347 wxWindow::SetLabel( title
) ;
1348 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1351 wxString
wxTopLevelWindowMac::GetTitle() const
1353 return wxWindow::GetLabel();
1356 bool wxTopLevelWindowMac::Show(bool show
)
1358 if ( !wxTopLevelWindowBase::Show(show
) )
1361 bool plainTransition
= false;
1363 #if wxUSE_SYSTEM_OPTIONS
1364 // code contributed by Ryan Wilcox December 18, 2003
1365 plainTransition
= UMAGetSystemVersion() >= 0x1000 ;
1366 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1367 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1372 if ( plainTransition
)
1373 ::ShowWindow( (WindowRef
)m_macWindow
);
1375 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1377 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1379 // because apps expect a size event to occur at this moment
1380 wxSizeEvent
event(GetSize() , m_windowId
);
1381 event
.SetEventObject(this);
1382 GetEventHandler()->ProcessEvent(event
);
1386 if ( plainTransition
)
1387 ::HideWindow( (WindowRef
)m_macWindow
);
1389 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1392 MacPropagateVisibilityChanged() ;
1397 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1401 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1403 data
= new FullScreenData() ;
1405 m_macFullScreenData
= data
;
1406 data
->m_position
= GetPosition() ;
1407 data
->m_size
= GetSize() ;
1408 data
->m_wasResizable
= MacGetWindowAttributes() & kWindowResizableAttribute
;
1410 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1413 wxRect client
= wxGetClientDisplayRect() ;
1415 int left
, top
, right
, bottom
;
1423 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1425 if ( style
& wxFULLSCREEN_NOCAPTION
)
1431 if ( style
& wxFULLSCREEN_NOBORDER
)
1438 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1443 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1448 SetSize( x
, y
, w
, h
) ;
1449 if ( data
->m_wasResizable
)
1450 MacChangeWindowAttributes( kWindowNoAttributes
, kWindowResizableAttribute
) ;
1455 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1456 if ( data
->m_wasResizable
)
1457 MacChangeWindowAttributes( kWindowResizableAttribute
, kWindowNoAttributes
) ;
1458 SetPosition( data
->m_position
) ;
1459 SetSize( data
->m_size
) ;
1462 m_macFullScreenData
= NULL
;
1468 bool wxTopLevelWindowMac::IsFullScreen() const
1470 return m_macFullScreenData
!= NULL
;
1473 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1475 if ( GetExtraStyle() == exStyle
)
1478 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1480 #if TARGET_API_MAC_OSX
1481 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1483 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1484 if ( MacGetMetalAppearance() != metal
)
1485 MacSetMetalAppearance( metal
) ;
1490 // we are still using coordinates of the content view
1491 // TODO: switch to structure bounds
1493 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1495 Rect content
, structure
;
1497 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1498 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1500 left
= content
.left
- structure
.left
;
1501 top
= content
.top
- structure
.top
;
1502 right
= structure
.right
- content
.right
;
1503 bottom
= structure
.bottom
- content
.bottom
;
1506 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1508 m_cachedClippedRectValid
= false ;
1509 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1510 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1511 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1514 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1518 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1526 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1530 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1533 *width
= bounds
.right
- bounds
.left
;
1535 *height
= bounds
.bottom
- bounds
.top
;
1538 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1542 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1545 *width
= bounds
.right
- bounds
.left
;
1547 *height
= bounds
.bottom
- bounds
.top
;
1550 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1552 #if TARGET_API_MAC_OSX
1553 wxASSERT_MSG( m_macUsesCompositing
,
1554 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1556 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1557 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1561 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1563 #if TARGET_API_MAC_OSX
1564 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1570 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1572 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1575 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1578 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1583 void wxTopLevelWindowMac::MacPerformUpdates()
1585 #if TARGET_API_MAC_OSX
1586 if ( m_macUsesCompositing
)
1588 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1589 // for composited windows this also triggers a redraw of all
1590 // invalid views in the window
1591 if ( UMAGetSystemVersion() >= 0x1030 )
1592 HIWindowFlush((WindowRef
) m_macWindow
) ;
1596 // the only way to trigger the redrawing on earlier systems is to call
1599 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1600 UInt32 currentEventClass
= 0 ;
1601 UInt32 currentEventKind
= 0 ;
1602 if ( currentEvent
!= NULL
)
1604 currentEventClass
= ::GetEventClass( currentEvent
) ;
1605 currentEventKind
= ::GetEventKind( currentEvent
) ;
1608 if ( currentEventClass
!= kEventClassMenu
)
1610 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1612 OSStatus status
= noErr
;
1613 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1620 BeginUpdate( (WindowRef
) m_macWindow
) ;
1622 RgnHandle updateRgn
= NewRgn();
1625 GetPortVisibleRegion( GetWindowPort( (WindowRef
)m_macWindow
), updateRgn
);
1626 UpdateControls( (WindowRef
)m_macWindow
, updateRgn
) ;
1628 // if ( !EmptyRgn( updateRgn ) )
1629 // MacDoRedraw( updateRgn , 0 , true) ;
1631 DisposeRgn( updateRgn
);
1634 EndUpdate( (WindowRef
)m_macWindow
) ;
1635 QDFlushPortBuffer( GetWindowPort( (WindowRef
)m_macWindow
) , NULL
) ;
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(), (SInt32
)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
->left
, inRect
->top
};
1714 QDLocalToGlobalPoint( GetWindowPort(window
), &pt
) ;
1716 inRect
->left
= pt
.h
;
1717 inRect
->bottom
+= pt
.v
;
1718 inRect
->right
+= pt
.h
;
1721 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1723 /*------------------------------------------------------
1724 Define which options your custom window supports.
1725 --------------------------------------------------------*/
1726 //just enable everything for our demo
1727 *(OptionBits
*)param
=
1730 //kWindowCanCollapse |
1731 //kWindowCanGetWindowRegion |
1732 //kWindowHasTitleBar |
1733 //kWindowSupportsDragHilite |
1734 kWindowCanDrawInCurrentPort
|
1735 //kWindowCanMeasureTitle |
1736 kWindowWantsDisposeAtProcessDeath
|
1737 kWindowSupportsGetGrowImageRegion
|
1738 kWindowDefSupportsColorGrafPort
;
1743 // The content region is left as a rectangle matching the window size, this is
1744 // so the origin in the paint event, and etc. still matches what the
1745 // programmer expects.
1746 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1749 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1753 wxShapedMacWindowGetPos( window
, &r
) ;
1754 RectRgn( rgn
, &r
) ;
1758 // The structure region is set to the shape given to the SetShape method.
1759 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1761 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1767 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1768 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1769 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1770 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1774 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1776 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1781 switch (rgnRec
->regionCode
)
1783 case kWindowStructureRgn
:
1784 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1787 case kWindowContentRgn
:
1788 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1792 SetEmptyRgn(rgnRec
->winRgn
);
1799 // Determine the region of the window which was hit
1801 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1804 static RgnHandle tempRgn
= NULL
;
1806 if (tempRgn
== NULL
)
1809 // get the point clicked
1810 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1812 // Mac OS 8.5 or later
1813 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1814 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1817 // no significant area was hit
1821 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1825 case kWindowMsgHitTest
:
1826 return wxShapedMacWindowHitTest(window
, param
);
1828 case kWindowMsgGetFeatures
:
1829 return wxShapedMacWindowGetFeatures(window
, param
);
1831 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1832 case kWindowMsgGetRegion
:
1833 return wxShapedMacWindowGetRegion(window
, param
);