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
;
944 void wxTopLevelWindowMac::Init()
947 m_maximizeOnShow
= false;
950 #if TARGET_API_MAC_OSX
951 m_macUsesCompositing
= ( UMAGetSystemVersion() >= 0x1030 );
953 m_macUsesCompositing
= false;
956 m_macEventHandler
= NULL
;
957 m_macFullScreenData
= NULL
;
960 class wxMacDeferredWindowDeleter
: public wxObject
963 wxMacDeferredWindowDeleter( WindowRef windowRef
)
965 m_macWindow
= windowRef
;
968 virtual ~wxMacDeferredWindowDeleter()
970 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
974 WindowRef m_macWindow
;
977 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
979 const wxString
& title
,
983 const wxString
& name
)
988 m_windowStyle
= style
;
992 m_windowId
= id
== -1 ? NewControlId() : id
;
993 wxWindow::SetLabel( title
) ;
995 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
997 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
999 if (GetExtraStyle() & wxFRAME_EX_METAL
)
1000 MacSetMetalAppearance(true);
1002 wxTopLevelWindows
.Append(this);
1005 parent
->AddChild(this);
1010 wxTopLevelWindowMac::~wxTopLevelWindowMac()
1015 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
1017 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
1020 if ( m_macEventHandler
)
1022 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1023 m_macEventHandler
= NULL
;
1026 wxRemoveMacWindowAssociation( this ) ;
1028 if ( wxModelessWindows
.Find(this) )
1029 wxModelessWindows
.DeleteObject(this);
1031 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1033 m_macFullScreenData
= NULL
;
1037 // ----------------------------------------------------------------------------
1038 // wxTopLevelWindowMac maximize/minimize
1039 // ----------------------------------------------------------------------------
1041 void wxTopLevelWindowMac::Maximize(bool maximize
)
1043 // TODO: check if this is still necessary
1045 wxMacPortStateHelper
help( (GrafPtr
)GetWindowPort( (WindowRef
)m_macWindow
) ) ;
1046 wxMacWindowClipper
clip( this );
1049 if ( !IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) )
1053 GetWindowBounds((WindowRef
)m_macWindow
, kWindowGlobalPortRgn
, &rect
);
1054 SetWindowIdealUserState((WindowRef
)m_macWindow
, &rect
);
1055 SetWindowUserState((WindowRef
)m_macWindow
, &rect
);
1058 ZoomWindow( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, false ) ;
1061 bool wxTopLevelWindowMac::IsMaximized() const
1063 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
1066 void wxTopLevelWindowMac::Iconize(bool iconize
)
1068 if ( IsWindowCollapsable( (WindowRef
)m_macWindow
) )
1069 CollapseWindow( (WindowRef
)m_macWindow
, iconize
) ;
1072 bool wxTopLevelWindowMac::IsIconized() const
1074 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1077 void wxTopLevelWindowMac::Restore()
1079 if ( IsMaximized() )
1081 else if ( IsIconized() )
1085 // ----------------------------------------------------------------------------
1086 // wxTopLevelWindowMac misc
1087 // ----------------------------------------------------------------------------
1089 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1091 return wxPoint(0, 0) ;
1094 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
1097 wxTopLevelWindowBase::SetIcon(icon
);
1100 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1102 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1104 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1106 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1110 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1112 if ( m_macEventHandler
!= NULL
)
1114 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1117 InstallWindowEventHandler(
1118 MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1119 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1122 void wxTopLevelWindowMac::MacCreateRealWindow(
1123 const wxString
& title
,
1127 const wxString
& name
)
1129 OSStatus err
= noErr
;
1131 m_windowStyle
= style
;
1139 wxRect display
= wxGetClientDisplayRect() ;
1141 if ( x
== wxDefaultPosition
.x
)
1144 if ( y
== wxDefaultPosition
.y
)
1147 int w
= WidthDefault(size
.x
);
1148 int h
= HeightDefault(size
.y
);
1150 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1152 // translate the window attributes in the appropriate window class and attributes
1153 WindowClass wclass
= 0;
1154 WindowAttributes attr
= kWindowNoAttributes
;
1155 WindowGroupRef group
= NULL
;
1157 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1160 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1161 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1162 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1165 wclass
= kFloatingWindowClass
;
1167 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1168 attr
|= kWindowSideTitlebarAttribute
;
1172 wclass
= kPlainWindowClass
;
1175 else if ( HasFlag( wxCAPTION
) )
1177 wclass
= kDocumentWindowClass
;
1178 attr
|= kWindowInWindowMenuAttribute
;
1180 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1181 else if ( HasFlag( wxFRAME_DRAWER
) )
1183 wclass
= kDrawerWindowClass
;
1184 // we must force compositing on a drawer
1185 m_macUsesCompositing
= true ;
1187 #endif //10.2 and up
1190 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1191 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1193 wclass
= kDocumentWindowClass
;
1197 wclass
= kPlainWindowClass
;
1201 if ( wclass
!= kPlainWindowClass
)
1203 if ( HasFlag( wxMINIMIZE_BOX
) )
1204 attr
|= kWindowCollapseBoxAttribute
;
1206 if ( HasFlag( wxMAXIMIZE_BOX
) )
1207 attr
|= kWindowFullZoomAttribute
;
1209 if ( HasFlag( wxRESIZE_BORDER
) )
1210 attr
|= kWindowResizableAttribute
;
1212 if ( HasFlag( wxCLOSE_BOX
) )
1213 attr
|= kWindowCloseBoxAttribute
;
1216 // turn on live resizing (OS X only)
1217 if (UMAGetSystemVersion() >= 0x1000)
1218 attr
|= kWindowLiveResizeAttribute
;
1220 if ( HasFlag(wxSTAY_ON_TOP
) )
1221 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1223 #if TARGET_API_MAC_OSX
1224 if ( m_macUsesCompositing
)
1225 attr
|= kWindowCompositingAttribute
;
1228 if ( HasFlag(wxFRAME_SHAPED
) )
1230 WindowDefSpec customWindowDefSpec
;
1231 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1232 customWindowDefSpec
.u
.defProc
= NewWindowDefUPP(wxShapedMacWindowDef
);
1234 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1235 attr
, &theBoundsRect
,
1236 (WindowRef
*) &m_macWindow
);
1240 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1243 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1244 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1246 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1248 // the create commands are only for content rect,
1249 // so we have to set the size again as structure bounds
1250 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1252 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1253 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1254 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1256 #if TARGET_API_MAC_OSX
1257 if ( m_macUsesCompositing
)
1259 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1260 // the content view, so we have to retrieve it explicitly
1261 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1262 m_peer
->GetControlRefAddr() ) ;
1263 if ( !m_peer
->Ok() )
1265 // compatibility mode fallback
1266 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1271 ::CreateRootControl( (WindowRef
)m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1274 // the root control level handler
1275 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1277 #if TARGET_API_MAC_OSX
1278 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1280 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1281 MacSetMetalAppearance( true ) ;
1285 // the frame window event handler
1286 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1287 MacInstallTopLevelWindowEventHandler() ;
1289 DoSetWindowVariant( m_windowVariant
) ;
1293 if ( HasFlag(wxFRAME_SHAPED
) )
1295 // default shape matches the window size
1296 wxRegion
rgn( 0, 0, w
, h
);
1300 wxWindowCreateEvent
event(this);
1301 GetEventHandler()->ProcessEvent(event
);
1304 void wxTopLevelWindowMac::ClearBackground()
1306 wxWindow::ClearBackground() ;
1309 // Raise the window to the top of the Z order
1310 void wxTopLevelWindowMac::Raise()
1312 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1315 // Lower the window to the bottom of the Z order
1316 void wxTopLevelWindowMac::Lower()
1318 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1321 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1323 if (s_macDeactivateWindow
)
1325 wxLogTrace(TRACE_ACTIVATE
,
1326 wxT("Doing delayed deactivation of %p"),
1327 s_macDeactivateWindow
);
1329 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1333 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1335 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1337 if (s_macDeactivateWindow
== this)
1338 s_macDeactivateWindow
= NULL
;
1340 MacDelayedDeactivation(timestamp
);
1341 MacPropagateHiliteChanged() ;
1344 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1346 wxWindow::SetLabel( title
) ;
1347 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1350 wxString
wxTopLevelWindowMac::GetTitle() const
1352 return wxWindow::GetLabel();
1355 bool wxTopLevelWindowMac::Show(bool show
)
1357 if ( !wxTopLevelWindowBase::Show(show
) )
1360 bool plainTransition
= false;
1362 #if wxUSE_SYSTEM_OPTIONS
1363 // code contributed by Ryan Wilcox December 18, 2003
1364 plainTransition
= UMAGetSystemVersion() >= 0x1000 ;
1365 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1366 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1371 if ( plainTransition
)
1372 ::ShowWindow( (WindowRef
)m_macWindow
);
1374 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1376 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1378 // because apps expect a size event to occur at this moment
1379 wxSizeEvent
event(GetSize() , m_windowId
);
1380 event
.SetEventObject(this);
1381 GetEventHandler()->ProcessEvent(event
);
1385 if ( plainTransition
)
1386 ::HideWindow( (WindowRef
)m_macWindow
);
1388 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1391 MacPropagateVisibilityChanged() ;
1396 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1400 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1402 data
= new FullScreenData() ;
1404 m_macFullScreenData
= data
;
1405 data
->m_position
= GetPosition() ;
1406 data
->m_size
= GetSize() ;
1408 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1411 wxRect client
= wxGetClientDisplayRect() ;
1413 int left
, top
, right
, bottom
;
1421 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1423 if ( style
& wxFULLSCREEN_NOCAPTION
)
1429 if ( style
& wxFULLSCREEN_NOBORDER
)
1436 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1441 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1446 SetSize( x
, y
, w
, h
) ;
1451 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1452 SetPosition( data
->m_position
) ;
1453 SetSize( data
->m_size
) ;
1456 m_macFullScreenData
= NULL
;
1462 bool wxTopLevelWindowMac::IsFullScreen() const
1464 return m_macFullScreenData
!= NULL
;
1467 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1469 if ( GetExtraStyle() == exStyle
)
1472 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1474 #if TARGET_API_MAC_OSX
1475 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1477 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1478 if ( MacGetMetalAppearance() != metal
)
1479 MacSetMetalAppearance( metal
) ;
1484 // we are still using coordinates of the content view
1485 // TODO: switch to structure bounds
1487 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1489 Rect content
, structure
;
1491 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1492 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1494 left
= content
.left
- structure
.left
;
1495 top
= content
.top
- structure
.top
;
1496 right
= structure
.right
- content
.right
;
1497 bottom
= structure
.bottom
- content
.bottom
;
1500 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1502 m_cachedClippedRectValid
= false ;
1503 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1504 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1505 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1508 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1512 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1520 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1524 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1527 *width
= bounds
.right
- bounds
.left
;
1529 *height
= bounds
.bottom
- bounds
.top
;
1532 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1536 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1539 *width
= bounds
.right
- bounds
.left
;
1541 *height
= bounds
.bottom
- bounds
.top
;
1544 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1546 #if TARGET_API_MAC_OSX
1547 wxASSERT_MSG( m_macUsesCompositing
,
1548 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1550 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1551 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1555 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1557 #if TARGET_API_MAC_OSX
1558 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1564 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1566 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1569 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1572 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1577 void wxTopLevelWindowMac::MacPerformUpdates()
1579 #if TARGET_API_MAC_OSX
1580 if ( m_macUsesCompositing
)
1582 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1583 // for composited windows this also triggers a redraw of all
1584 // invalid views in the window
1585 if ( UMAGetSystemVersion() >= 0x1030 )
1586 HIWindowFlush((WindowRef
) m_macWindow
) ;
1590 // the only way to trigger the redrawing on earlier systems is to call
1593 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1594 UInt32 currentEventClass
= 0 ;
1595 UInt32 currentEventKind
= 0 ;
1596 if ( currentEvent
!= NULL
)
1598 currentEventClass
= ::GetEventClass( currentEvent
) ;
1599 currentEventKind
= ::GetEventKind( currentEvent
) ;
1602 if ( currentEventClass
!= kEventClassMenu
)
1604 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1606 OSStatus status
= noErr
;
1607 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1614 BeginUpdate( (WindowRef
) m_macWindow
) ;
1616 RgnHandle updateRgn
= NewRgn();
1619 GetPortVisibleRegion( GetWindowPort( (WindowRef
)m_macWindow
), updateRgn
);
1620 UpdateControls( (WindowRef
)m_macWindow
, updateRgn
) ;
1622 // if ( !EmptyRgn( updateRgn ) )
1623 // MacDoRedraw( updateRgn , 0 , true) ;
1625 DisposeRgn( updateRgn
);
1628 EndUpdate( (WindowRef
)m_macWindow
) ;
1629 QDFlushPortBuffer( GetWindowPort( (WindowRef
)m_macWindow
) , NULL
) ;
1633 // Attracts the users attention to this window if the application is
1634 // inactive (should be called when a background event occurs)
1636 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1639 DisposePtr( (Ptr
)ptr
) ;
1642 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1644 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1645 static wxMacNMUPP
nmupp( wxMacNMResponse
);
1647 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1648 notificationRequest
->qType
= nmType
;
1649 notificationRequest
->nmMark
= 1 ;
1650 notificationRequest
->nmIcon
= 0 ;
1651 notificationRequest
->nmSound
= 0 ;
1652 notificationRequest
->nmStr
= NULL
;
1653 notificationRequest
->nmResp
= nmupp
;
1655 verify_noerr( NMInstall( notificationRequest
) ) ;
1658 // ---------------------------------------------------------------------------
1659 // Shape implementation
1660 // ---------------------------------------------------------------------------
1663 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1665 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1666 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1668 // The empty region signifies that the shape
1669 // should be removed from the window.
1670 if ( region
.IsEmpty() )
1672 wxSize sz
= GetClientSize();
1673 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1674 if ( rgn
.IsEmpty() )
1677 return SetShape(rgn
);
1680 // Make a copy of the region
1681 RgnHandle shapeRegion
= NewRgn();
1682 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1684 // Dispose of any shape region we may already have
1685 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1689 // Save the region so we can use it later
1690 SetWRefCon((WindowRef
)MacGetWindowRef(), (SInt32
)shapeRegion
);
1692 // inform the window manager that the window has changed shape
1693 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1698 // ---------------------------------------------------------------------------
1699 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1700 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1701 // ---------------------------------------------------------------------------
1703 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1705 GetWindowPortBounds(window
, inRect
);
1706 Point pt
= { inRect
->left
, inRect
->top
};
1708 QDLocalToGlobalPoint( GetWindowPort(window
), &pt
) ;
1710 inRect
->left
= pt
.h
;
1711 inRect
->bottom
+= pt
.v
;
1712 inRect
->right
+= pt
.h
;
1715 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1717 /*------------------------------------------------------
1718 Define which options your custom window supports.
1719 --------------------------------------------------------*/
1720 //just enable everything for our demo
1721 *(OptionBits
*)param
=
1724 //kWindowCanCollapse |
1725 //kWindowCanGetWindowRegion |
1726 //kWindowHasTitleBar |
1727 //kWindowSupportsDragHilite |
1728 kWindowCanDrawInCurrentPort
|
1729 //kWindowCanMeasureTitle |
1730 kWindowWantsDisposeAtProcessDeath
|
1731 kWindowSupportsGetGrowImageRegion
|
1732 kWindowDefSupportsColorGrafPort
;
1737 // The content region is left as a rectangle matching the window size, this is
1738 // so the origin in the paint event, and etc. still matches what the
1739 // programmer expects.
1740 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1743 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1747 wxShapedMacWindowGetPos( window
, &r
) ;
1748 RectRgn( rgn
, &r
) ;
1752 // The structure region is set to the shape given to the SetShape method.
1753 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1755 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1761 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1762 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1763 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1764 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1768 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1770 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1775 switch (rgnRec
->regionCode
)
1777 case kWindowStructureRgn
:
1778 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1781 case kWindowContentRgn
:
1782 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1786 SetEmptyRgn(rgnRec
->winRgn
);
1793 // Determine the region of the window which was hit
1795 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1798 static RgnHandle tempRgn
= NULL
;
1800 if (tempRgn
== NULL
)
1803 // get the point clicked
1804 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1806 // Mac OS 8.5 or later
1807 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1808 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1811 // no significant area was hit
1815 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1819 case kWindowMsgHitTest
:
1820 return wxShapedMacWindowHitTest(window
, param
);
1822 case kWindowMsgGetFeatures
:
1823 return wxShapedMacWindowGetFeatures(window
, param
);
1825 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1826 case kWindowMsgGetRegion
:
1827 return wxShapedMacWindowGetRegion(window
, param
);