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 { kEventClassKeyboard
, kEventRawKeyDown
} ,
91 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
92 { kEventClassKeyboard
, kEventRawKeyUp
} ,
93 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
96 { kEventClassWindow
, kEventWindowShown
} ,
97 { kEventClassWindow
, kEventWindowActivated
} ,
98 { kEventClassWindow
, kEventWindowDeactivated
} ,
99 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
100 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
101 { kEventClassWindow
, kEventWindowClose
} ,
103 // we have to catch these events on the toplevel window level,
104 // as controls don't get the raw mouse events anymore
106 { kEventClassMouse
, kEventMouseDown
} ,
107 { kEventClassMouse
, kEventMouseUp
} ,
108 { kEventClassMouse
, kEventMouseWheelMoved
} ,
109 { kEventClassMouse
, kEventMouseMoved
} ,
110 { kEventClassMouse
, kEventMouseDragged
} ,
113 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
115 OSStatus result
= eventNotHandledErr
;
116 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
117 // FindFocus does not return the actual focus window, but the enclosing window
118 wxWindow
* focus
= wxWindow::DoFindFocus();
120 focus
= (wxTopLevelWindowMac
*) data
;
122 unsigned char charCode
;
127 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
130 UInt32 dataSize
= 0 ;
131 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
135 UniChar
* charBuf
= buf
;
138 charBuf
= new UniChar
[ dataSize
/ sizeof( UniChar
) ] ;
139 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
141 #if SIZEOF_WCHAR_T == 2
142 uniChar
= charBuf
[0] ;
144 wxMBConvUTF16 converter
;
145 converter
.MB2WC( &uniChar
, (const char*)charBuf
, 1 ) ;
153 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
154 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
155 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
156 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
158 UInt32 message
= (keyCode
<< 8) + charCode
;
159 switch ( GetEventKind( event
) )
161 case kEventRawKeyRepeat
:
162 case kEventRawKeyDown
:
164 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
165 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
166 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
167 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
168 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
) )
172 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
176 case kEventRawKeyUp
:
177 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
178 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
) )
184 case kEventRawKeyModifiersChanged
:
186 wxKeyEvent
event(wxEVT_KEY_DOWN
);
188 event
.m_shiftDown
= modifiers
& shiftKey
;
189 event
.m_controlDown
= modifiers
& controlKey
;
190 event
.m_altDown
= modifiers
& optionKey
;
191 event
.m_metaDown
= modifiers
& cmdKey
;
196 event
.m_uniChar
= uniChar
;
199 event
.SetTimestamp(when
);
200 event
.SetEventObject(focus
);
202 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
204 event
.m_keyCode
= WXK_CONTROL
;
205 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
206 focus
->GetEventHandler()->ProcessEvent( event
) ;
208 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
210 event
.m_keyCode
= WXK_SHIFT
;
211 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
212 focus
->GetEventHandler()->ProcessEvent( event
) ;
214 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
216 event
.m_keyCode
= WXK_ALT
;
217 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
218 focus
->GetEventHandler()->ProcessEvent( event
) ;
220 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
222 event
.m_keyCode
= WXK_COMMAND
;
223 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
224 focus
->GetEventHandler()->ProcessEvent( event
) ;
227 wxApp::s_lastModifiers
= modifiers
;
238 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
239 // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
242 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
244 wxWindow
* g_MacLastWindow
= NULL
;
246 static EventMouseButton lastButton
= 0 ;
248 static void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
250 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
251 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
253 // this parameter are not given for all events
254 EventMouseButton button
= 0 ;
255 UInt32 clickCount
= 0 ;
256 cEvent
.GetParameter
<EventMouseButton
>( kEventParamMouseButton
, typeMouseButton
, &button
) ;
257 cEvent
.GetParameter
<UInt32
>( kEventParamClickCount
, typeUInt32
, &clickCount
) ;
259 wxevent
.m_x
= screenMouseLocation
.h
;
260 wxevent
.m_y
= screenMouseLocation
.v
;
261 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
262 wxevent
.m_controlDown
= modifiers
& controlKey
;
263 wxevent
.m_altDown
= modifiers
& optionKey
;
264 wxevent
.m_metaDown
= modifiers
& cmdKey
;
265 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
267 // a control click is interpreted as a right click
268 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
269 button
= kEventMouseButtonSecondary
;
271 // otherwise we report double clicks by connecting a left click with a ctrl-left click
272 if ( clickCount
> 1 && button
!= lastButton
)
275 // we must make sure that our synthetic 'right' button corresponds in
276 // mouse down, moved and mouse up, and does not deliver a right down and left up
278 if ( cEvent
.GetKind() == kEventMouseDown
)
279 lastButton
= button
;
283 else if ( lastButton
)
284 button
= lastButton
;
286 // determine the correct down state, wx does not want a 'down' for a mouseUp event,
287 // while mac delivers this button
288 if ( button
!= 0 && cEvent
.GetKind() != kEventMouseUp
)
292 case kEventMouseButtonPrimary
:
293 wxevent
.m_leftDown
= true ;
296 case kEventMouseButtonSecondary
:
297 wxevent
.m_rightDown
= true ;
300 case kEventMouseButtonTertiary
:
301 wxevent
.m_middleDown
= true ;
309 // translate into wx types
310 switch ( cEvent
.GetKind() )
312 case kEventMouseDown
:
315 case kEventMouseButtonPrimary
:
316 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
319 case kEventMouseButtonSecondary
:
320 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
323 case kEventMouseButtonTertiary
:
324 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
335 case kEventMouseButtonPrimary
:
336 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
339 case kEventMouseButtonSecondary
:
340 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
343 case kEventMouseButtonTertiary
:
344 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
352 case kEventMouseWheelMoved
:
354 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
356 // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
357 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeLongInteger
) ;
359 wxevent
.m_wheelRotation
= delta
;
360 wxevent
.m_wheelDelta
= 1;
361 wxevent
.m_linesPerAction
= 1;
366 wxevent
.SetEventType( wxEVT_MOTION
) ;
371 ControlRef
wxMacFindSubControl( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, ControlRef superControl
, ControlPartCode
*outPart
)
375 UInt16 childrenCount
= 0 ;
376 ControlHandle sibling
;
378 OSStatus err
= CountSubControls( superControl
, &childrenCount
) ;
379 if ( err
== errControlIsNotEmbedder
)
382 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
384 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
386 err
= GetIndexedSubControl( superControl
, i
, & sibling
) ;
387 if ( err
== errControlIsNotEmbedder
)
390 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
391 if ( IsControlVisible( sibling
) )
393 UMAGetControlBoundsInWindowCoords( sibling
, &r
) ;
394 if ( MacPtInRect( location
, &r
) )
396 ControlHandle child
= wxMacFindSubControl( toplevelWindow
, location
, sibling
, outPart
) ;
403 Point testLocation
= location
;
405 if ( toplevelWindow
&& toplevelWindow
->MacUsesCompositing() )
407 testLocation
.h
-= r
.left
;
408 testLocation
.v
-= r
.top
;
411 *outPart
= TestControl( sibling
, testLocation
) ;
423 ControlRef
wxMacFindControlUnderMouse( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, WindowRef window
, ControlPartCode
*outPart
)
425 #if TARGET_API_MAC_OSX
426 if ( UMAGetSystemVersion() >= 0x1030 && ( toplevelWindow
== 0 || toplevelWindow
->MacUsesCompositing() ) )
427 return FindControlUnderMouse( location
, window
, outPart
) ;
430 ControlRef rootControl
= NULL
;
431 verify_noerr( GetRootControl( window
, &rootControl
) ) ;
433 return wxMacFindSubControl( toplevelWindow
, location
, rootControl
, outPart
) ;
436 #define NEW_CAPTURE_HANDLING 1
438 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
440 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
442 OSStatus result
= eventNotHandledErr
;
444 wxMacCarbonEvent
cEvent( event
) ;
446 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
447 Point windowMouseLocation
= screenMouseLocation
;
450 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
452 wxWindow
* currentMouseWindow
= NULL
;
453 ControlRef control
= NULL
;
455 #if NEW_CAPTURE_HANDLING
456 if ( wxApp::s_captureWindow
)
458 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
459 windowPart
= inContent
;
465 QDGlobalToLocalPoint( UMAGetWindowPort(window
) , &windowMouseLocation
) ;
467 if ( wxApp::s_captureWindow
468 #if !NEW_CAPTURE_HANDLING
469 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
473 currentMouseWindow
= wxApp::s_captureWindow
;
475 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
477 ControlPartCode part
;
478 control
= wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &part
) ;
479 // if there is no control below the mouse position, send the event to the toplevel window itself
482 currentMouseWindow
= (wxWindow
*) data
;
486 currentMouseWindow
= wxFindControlFromMacControl( control
) ;
487 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
490 // for wxToolBar to function we have to send certaint events to it
491 // instead of its children (wxToolBarTools)
493 GetSuperControl(control
, &parent
);
494 wxWindow
*wxParent
= wxFindControlFromMacControl( parent
) ;
495 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
496 currentMouseWindow
= wxParent
;
501 // disabled windows must not get any input messages
502 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
503 currentMouseWindow
= NULL
;
507 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
508 SetupMouseEvent( wxevent
, cEvent
) ;
510 // handle all enter / leave events
512 if ( currentMouseWindow
!= g_MacLastWindow
)
514 if ( g_MacLastWindow
)
516 wxMouseEvent
eventleave(wxevent
);
517 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
518 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
519 eventleave
.SetEventObject( g_MacLastWindow
) ;
520 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
523 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
526 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
529 if ( currentMouseWindow
)
531 wxMouseEvent
evententer(wxevent
);
532 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
533 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
534 evententer
.SetEventObject( currentMouseWindow
) ;
535 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
538 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
541 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
544 g_MacLastWindow
= currentMouseWindow
;
547 if ( windowPart
== inMenuBar
)
549 // special case menu bar, as we are having a low-level runloop we must do it ourselves
550 if ( cEvent
.GetKind() == kEventMouseDown
)
552 ::MenuSelect( screenMouseLocation
) ;
556 else if ( currentMouseWindow
)
558 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
560 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
562 wxevent
.SetEventObject( currentMouseWindow
) ;
563 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
565 // make tooltips current
568 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
569 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
572 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
574 if ((currentMouseWindowParent
!= NULL
) &&
575 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
576 currentMouseWindow
= NULL
;
582 // if the user code did _not_ handle the event, then perform the
583 // default processing
584 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
586 // ... that is set focus to this window
587 if (currentMouseWindow
->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
588 currentMouseWindow
->SetFocus();
591 ControlPartCode dummyPart
;
592 // if built-in find control is finding the wrong control (ie static box instead of overlaid
593 // button, we cannot let the standard handler do its job, but must handle manually
595 if ( ( cEvent
.GetKind() == kEventMouseDown
)
598 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
599 wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &dummyPart
) )
603 if ( currentMouseWindow
->MacIsReallyEnabled() )
605 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
606 Point clickLocation
= windowMouseLocation
;
608 if ( toplevelWindow
->MacUsesCompositing() )
609 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
611 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
612 modifiers
, (ControlActionUPP
) -1 ) ;
614 if ((currentMouseWindowParent
!= NULL
) &&
615 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
617 currentMouseWindow
= NULL
;
625 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
627 wxApp::s_captureWindow
= NULL
;
633 wxWindow
* cursorTarget
= currentMouseWindow
;
634 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
636 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
638 cursorTarget
= cursorTarget
->GetParent() ;
640 cursorPoint
+= cursorTarget
->GetPosition();
644 else // currentMouseWindow == NULL
646 // don't mess with controls we don't know about
647 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
648 // so we try sending them the correct control directly
649 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
651 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
652 Point clickLocation
= windowMouseLocation
;
653 #if TARGET_API_MAC_OSX
654 if ( toplevelWindow
->MacUsesCompositing() )
657 hiPoint
.x
= clickLocation
.h
;
658 hiPoint
.y
= clickLocation
.v
;
659 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
660 clickLocation
.h
= (int)hiPoint
.x
;
661 clickLocation
.v
= (int)hiPoint
.y
;
663 #endif // TARGET_API_MAC_OSX
665 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
673 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
675 OSStatus result
= eventNotHandledErr
;
677 wxMacCarbonEvent
cEvent( event
) ;
679 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
680 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
682 switch ( GetEventKind( event
) )
684 case kEventWindowActivated
:
686 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
687 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
688 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
689 wxevent
.SetEventObject(toplevelWindow
);
690 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
691 // we still sending an eventNotHandledErr in order to allow for default processing
695 case kEventWindowDeactivated
:
697 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
698 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
699 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
700 wxevent
.SetEventObject(toplevelWindow
);
701 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
702 // we still sending an eventNotHandledErr in order to allow for default processing
706 case kEventWindowShown
:
707 toplevelWindow
->Refresh() ;
711 case kEventWindowClose
:
712 toplevelWindow
->Close() ;
716 case kEventWindowBoundsChanged
:
718 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
719 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
720 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
721 if ( attributes
& kWindowBoundsChangeSizeChanged
)
723 // according to the other ports we handle this within the OS level
724 // resize event, not within a wxSizeEvent
725 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
728 frame
->PositionBars();
731 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
732 event
.SetEventObject( toplevelWindow
) ;
734 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
735 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
738 if ( attributes
& kWindowBoundsChangeOriginChanged
)
740 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
741 event
.SetEventObject( toplevelWindow
) ;
742 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
749 case kEventWindowBoundsChanging
:
751 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
752 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
754 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
756 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
757 int left
, top
, right
, bottom
;
758 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
763 newRect
.right
- newRect
.left
+ left
+ right
,
764 newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
766 // this is a EVT_SIZING not a EVT_SIZE type !
767 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
768 wxevent
.SetEventObject( toplevelWindow
) ;
770 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
771 adjustR
= wxevent
.GetRect() ;
773 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
774 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
775 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
776 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
777 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
778 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
779 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
780 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
781 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
782 if ( !EqualRect( &newRect
, &adjustedRect
) )
783 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
784 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
798 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
800 OSStatus result
= eventNotHandledErr
;
802 switch ( GetEventClass( event
) )
804 case kEventClassKeyboard
:
805 result
= KeyboardEventHandler( handler
, event
, data
) ;
808 case kEventClassWindow
:
809 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
812 case kEventClassMouse
:
813 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
823 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
825 // ---------------------------------------------------------------------------
826 // wxWindowMac utility functions
827 // ---------------------------------------------------------------------------
829 // Find an item given the Macintosh Window Reference
831 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
833 static MacWindowMap wxWinMacWindowList
;
835 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
837 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
839 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
842 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
843 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
845 // adding NULL WindowRef is (first) surely a result of an error and
847 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
849 wxWinMacWindowList
[inWindowRef
] = win
;
852 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
853 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
855 MacWindowMap::iterator it
;
856 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
858 if ( it
->second
== win
)
860 wxWinMacWindowList
.erase(it
);
866 // ----------------------------------------------------------------------------
867 // wxTopLevelWindowMac creation
868 // ----------------------------------------------------------------------------
870 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
876 bool m_wasResizable
;
880 void wxTopLevelWindowMac::Init()
883 m_maximizeOnShow
= false;
886 #if TARGET_API_MAC_OSX
887 m_macUsesCompositing
= ( UMAGetSystemVersion() >= 0x1030 );
889 m_macUsesCompositing
= false;
892 m_macEventHandler
= NULL
;
893 m_macFullScreenData
= NULL
;
896 class wxMacDeferredWindowDeleter
: public wxObject
899 wxMacDeferredWindowDeleter( WindowRef windowRef
)
901 m_macWindow
= windowRef
;
904 virtual ~wxMacDeferredWindowDeleter()
906 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
910 WindowRef m_macWindow
;
913 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
915 const wxString
& title
,
919 const wxString
& name
)
924 m_windowStyle
= style
;
928 m_windowId
= id
== -1 ? NewControlId() : id
;
929 wxWindow::SetLabel( title
) ;
931 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
933 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
935 if (GetExtraStyle() & wxFRAME_EX_METAL
)
936 MacSetMetalAppearance(true);
938 wxTopLevelWindows
.Append(this);
941 parent
->AddChild(this);
946 wxTopLevelWindowMac::~wxTopLevelWindowMac()
951 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
953 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
956 if ( m_macEventHandler
)
958 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
959 m_macEventHandler
= NULL
;
962 wxRemoveMacWindowAssociation( this ) ;
964 if ( wxModelessWindows
.Find(this) )
965 wxModelessWindows
.DeleteObject(this);
967 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
969 m_macFullScreenData
= NULL
;
973 // ----------------------------------------------------------------------------
974 // wxTopLevelWindowMac maximize/minimize
975 // ----------------------------------------------------------------------------
977 void wxTopLevelWindowMac::Maximize(bool maximize
)
979 // TODO: check if this is still necessary
981 wxMacPortStateHelper
help( (GrafPtr
)GetWindowPort( (WindowRef
)m_macWindow
) ) ;
982 wxMacWindowClipper
clip( this );
985 if ( !IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) )
989 GetWindowBounds((WindowRef
)m_macWindow
, kWindowGlobalPortRgn
, &rect
);
990 SetWindowIdealUserState((WindowRef
)m_macWindow
, &rect
);
991 SetWindowUserState((WindowRef
)m_macWindow
, &rect
);
994 ZoomWindow( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, false ) ;
997 bool wxTopLevelWindowMac::IsMaximized() const
999 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
1002 void wxTopLevelWindowMac::Iconize(bool iconize
)
1004 if ( IsWindowCollapsable( (WindowRef
)m_macWindow
) )
1005 CollapseWindow( (WindowRef
)m_macWindow
, iconize
) ;
1008 bool wxTopLevelWindowMac::IsIconized() const
1010 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1013 void wxTopLevelWindowMac::Restore()
1015 if ( IsMaximized() )
1017 else if ( IsIconized() )
1021 // ----------------------------------------------------------------------------
1022 // wxTopLevelWindowMac misc
1023 // ----------------------------------------------------------------------------
1025 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1027 return wxPoint(0, 0) ;
1030 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
1033 wxTopLevelWindowBase::SetIcon(icon
);
1036 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1038 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1040 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1042 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1046 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1048 if ( m_macEventHandler
!= NULL
)
1050 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1053 InstallWindowEventHandler(
1054 MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1055 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1058 void wxTopLevelWindowMac::MacCreateRealWindow(
1059 const wxString
& title
,
1063 const wxString
& name
)
1065 OSStatus err
= noErr
;
1067 m_windowStyle
= style
;
1075 wxRect display
= wxGetClientDisplayRect() ;
1077 if ( x
== wxDefaultPosition
.x
)
1080 if ( y
== wxDefaultPosition
.y
)
1083 int w
= WidthDefault(size
.x
);
1084 int h
= HeightDefault(size
.y
);
1086 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1088 // translate the window attributes in the appropriate window class and attributes
1089 WindowClass wclass
= 0;
1090 WindowAttributes attr
= kWindowNoAttributes
;
1091 WindowGroupRef group
= NULL
;
1093 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1096 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1097 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1098 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1101 wclass
= kFloatingWindowClass
;
1103 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1104 attr
|= kWindowSideTitlebarAttribute
;
1108 wclass
= kPlainWindowClass
;
1111 else if ( HasFlag( wxCAPTION
) )
1113 wclass
= kDocumentWindowClass
;
1114 attr
|= kWindowInWindowMenuAttribute
;
1116 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1117 else if ( HasFlag( wxFRAME_DRAWER
) )
1119 wclass
= kDrawerWindowClass
;
1120 // we must force compositing on a drawer
1121 m_macUsesCompositing
= true ;
1123 #endif //10.2 and up
1126 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1127 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1129 wclass
= kDocumentWindowClass
;
1133 wclass
= kPlainWindowClass
;
1137 if ( wclass
!= kPlainWindowClass
)
1139 if ( HasFlag( wxMINIMIZE_BOX
) )
1140 attr
|= kWindowCollapseBoxAttribute
;
1142 if ( HasFlag( wxMAXIMIZE_BOX
) )
1143 attr
|= kWindowFullZoomAttribute
;
1145 if ( HasFlag( wxRESIZE_BORDER
) )
1146 attr
|= kWindowResizableAttribute
;
1148 if ( HasFlag( wxCLOSE_BOX
) )
1149 attr
|= kWindowCloseBoxAttribute
;
1152 // turn on live resizing (OS X only)
1153 if (UMAGetSystemVersion() >= 0x1000)
1154 attr
|= kWindowLiveResizeAttribute
;
1156 if ( HasFlag(wxSTAY_ON_TOP
) )
1157 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1159 #if TARGET_API_MAC_OSX
1160 if ( m_macUsesCompositing
)
1161 attr
|= kWindowCompositingAttribute
;
1164 if ( HasFlag(wxFRAME_SHAPED
) )
1166 WindowDefSpec customWindowDefSpec
;
1167 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1168 customWindowDefSpec
.u
.defProc
= NewWindowDefUPP(wxShapedMacWindowDef
);
1170 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1171 attr
, &theBoundsRect
,
1172 (WindowRef
*) &m_macWindow
);
1176 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1179 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1180 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1182 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1184 // the create commands are only for content rect,
1185 // so we have to set the size again as structure bounds
1186 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1188 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1189 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1190 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1192 #if TARGET_API_MAC_OSX
1193 if ( m_macUsesCompositing
)
1195 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1196 // the content view, so we have to retrieve it explicitly
1197 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1198 m_peer
->GetControlRefAddr() ) ;
1199 if ( !m_peer
->Ok() )
1201 // compatibility mode fallback
1202 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1207 ::CreateRootControl( (WindowRef
)m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1210 // the root control level handler
1211 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1213 #if TARGET_API_MAC_OSX
1214 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1216 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1217 MacSetMetalAppearance( true ) ;
1221 // the frame window event handler
1222 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1223 MacInstallTopLevelWindowEventHandler() ;
1225 DoSetWindowVariant( m_windowVariant
) ;
1229 if ( HasFlag(wxFRAME_SHAPED
) )
1231 // default shape matches the window size
1232 wxRegion
rgn( 0, 0, w
, h
);
1236 wxWindowCreateEvent
event(this);
1237 GetEventHandler()->ProcessEvent(event
);
1240 void wxTopLevelWindowMac::ClearBackground()
1242 wxWindow::ClearBackground() ;
1245 // Raise the window to the top of the Z order
1246 void wxTopLevelWindowMac::Raise()
1248 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1251 // Lower the window to the bottom of the Z order
1252 void wxTopLevelWindowMac::Lower()
1254 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1257 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1259 if (s_macDeactivateWindow
)
1261 wxLogTrace(TRACE_ACTIVATE
,
1262 wxT("Doing delayed deactivation of %p"),
1263 s_macDeactivateWindow
);
1265 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1269 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1271 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1273 if (s_macDeactivateWindow
== this)
1274 s_macDeactivateWindow
= NULL
;
1276 MacDelayedDeactivation(timestamp
);
1277 MacPropagateHiliteChanged() ;
1280 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1282 wxWindow::SetLabel( title
) ;
1283 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1286 wxString
wxTopLevelWindowMac::GetTitle() const
1288 return wxWindow::GetLabel();
1291 bool wxTopLevelWindowMac::Show(bool show
)
1293 if ( !wxTopLevelWindowBase::Show(show
) )
1296 bool plainTransition
= false;
1298 #if wxUSE_SYSTEM_OPTIONS
1299 // code contributed by Ryan Wilcox December 18, 2003
1300 plainTransition
= UMAGetSystemVersion() >= 0x1000 ;
1301 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1302 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1307 if ( plainTransition
)
1308 ::ShowWindow( (WindowRef
)m_macWindow
);
1310 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1312 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1314 // because apps expect a size event to occur at this moment
1315 wxSizeEvent
event(GetSize() , m_windowId
);
1316 event
.SetEventObject(this);
1317 GetEventHandler()->ProcessEvent(event
);
1321 if ( plainTransition
)
1322 ::HideWindow( (WindowRef
)m_macWindow
);
1324 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1327 MacPropagateVisibilityChanged() ;
1332 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1336 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1338 data
= new FullScreenData() ;
1340 m_macFullScreenData
= data
;
1341 data
->m_position
= GetPosition() ;
1342 data
->m_size
= GetSize() ;
1343 data
->m_wasResizable
= MacGetWindowAttributes() & kWindowResizableAttribute
;
1345 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1348 wxRect client
= wxGetClientDisplayRect() ;
1350 int left
, top
, right
, bottom
;
1358 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1360 if ( style
& wxFULLSCREEN_NOCAPTION
)
1366 if ( style
& wxFULLSCREEN_NOBORDER
)
1373 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1378 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1383 SetSize( x
, y
, w
, h
) ;
1384 if ( data
->m_wasResizable
)
1385 MacChangeWindowAttributes( kWindowNoAttributes
, kWindowResizableAttribute
) ;
1390 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1391 if ( data
->m_wasResizable
)
1392 MacChangeWindowAttributes( kWindowResizableAttribute
, kWindowNoAttributes
) ;
1393 SetPosition( data
->m_position
) ;
1394 SetSize( data
->m_size
) ;
1397 m_macFullScreenData
= NULL
;
1403 bool wxTopLevelWindowMac::IsFullScreen() const
1405 return m_macFullScreenData
!= NULL
;
1408 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1410 if ( GetExtraStyle() == exStyle
)
1413 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1415 #if TARGET_API_MAC_OSX
1416 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1418 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1419 if ( MacGetMetalAppearance() != metal
)
1420 MacSetMetalAppearance( metal
) ;
1425 // we are still using coordinates of the content view
1426 // TODO: switch to structure bounds
1428 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1430 Rect content
, structure
;
1432 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1433 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1435 left
= content
.left
- structure
.left
;
1436 top
= content
.top
- structure
.top
;
1437 right
= structure
.right
- content
.right
;
1438 bottom
= structure
.bottom
- content
.bottom
;
1441 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1443 m_cachedClippedRectValid
= false ;
1444 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1445 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1446 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1449 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1453 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1461 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1465 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1468 *width
= bounds
.right
- bounds
.left
;
1470 *height
= bounds
.bottom
- bounds
.top
;
1473 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1477 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1480 *width
= bounds
.right
- bounds
.left
;
1482 *height
= bounds
.bottom
- bounds
.top
;
1485 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1487 #if TARGET_API_MAC_OSX
1488 wxASSERT_MSG( m_macUsesCompositing
,
1489 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1491 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1492 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1496 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1498 #if TARGET_API_MAC_OSX
1499 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1505 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1507 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1510 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1513 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1518 void wxTopLevelWindowMac::MacPerformUpdates()
1520 #if TARGET_API_MAC_OSX
1521 if ( m_macUsesCompositing
)
1523 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1524 // for composited windows this also triggers a redraw of all
1525 // invalid views in the window
1526 if ( UMAGetSystemVersion() >= 0x1030 )
1527 HIWindowFlush((WindowRef
) m_macWindow
) ;
1531 // the only way to trigger the redrawing on earlier systems is to call
1534 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1535 UInt32 currentEventClass
= 0 ;
1536 UInt32 currentEventKind
= 0 ;
1537 if ( currentEvent
!= NULL
)
1539 currentEventClass
= ::GetEventClass( currentEvent
) ;
1540 currentEventKind
= ::GetEventKind( currentEvent
) ;
1543 if ( currentEventClass
!= kEventClassMenu
)
1545 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1547 OSStatus status
= noErr
;
1548 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1555 BeginUpdate( (WindowRef
) m_macWindow
) ;
1557 RgnHandle updateRgn
= NewRgn();
1560 GetPortVisibleRegion( GetWindowPort( (WindowRef
)m_macWindow
), updateRgn
);
1561 UpdateControls( (WindowRef
)m_macWindow
, updateRgn
) ;
1563 // if ( !EmptyRgn( updateRgn ) )
1564 // MacDoRedraw( updateRgn , 0 , true) ;
1566 DisposeRgn( updateRgn
);
1569 EndUpdate( (WindowRef
)m_macWindow
) ;
1570 QDFlushPortBuffer( GetWindowPort( (WindowRef
)m_macWindow
) , NULL
) ;
1574 // Attracts the users attention to this window if the application is
1575 // inactive (should be called when a background event occurs)
1577 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1580 DisposePtr( (Ptr
)ptr
) ;
1583 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1585 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1586 static wxMacNMUPP
nmupp( wxMacNMResponse
);
1588 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1589 notificationRequest
->qType
= nmType
;
1590 notificationRequest
->nmMark
= 1 ;
1591 notificationRequest
->nmIcon
= 0 ;
1592 notificationRequest
->nmSound
= 0 ;
1593 notificationRequest
->nmStr
= NULL
;
1594 notificationRequest
->nmResp
= nmupp
;
1596 verify_noerr( NMInstall( notificationRequest
) ) ;
1599 // ---------------------------------------------------------------------------
1600 // Shape implementation
1601 // ---------------------------------------------------------------------------
1604 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1606 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1607 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1609 // The empty region signifies that the shape
1610 // should be removed from the window.
1611 if ( region
.IsEmpty() )
1613 wxSize sz
= GetClientSize();
1614 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1615 if ( rgn
.IsEmpty() )
1618 return SetShape(rgn
);
1621 // Make a copy of the region
1622 RgnHandle shapeRegion
= NewRgn();
1623 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1625 // Dispose of any shape region we may already have
1626 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1630 // Save the region so we can use it later
1631 SetWRefCon((WindowRef
)MacGetWindowRef(), (SInt32
)shapeRegion
);
1633 // inform the window manager that the window has changed shape
1634 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1639 // ---------------------------------------------------------------------------
1640 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1641 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1642 // ---------------------------------------------------------------------------
1644 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1646 GetWindowPortBounds(window
, inRect
);
1647 Point pt
= { inRect
->left
, inRect
->top
};
1649 QDLocalToGlobalPoint( GetWindowPort(window
), &pt
) ;
1651 inRect
->left
= pt
.h
;
1652 inRect
->bottom
+= pt
.v
;
1653 inRect
->right
+= pt
.h
;
1656 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1658 /*------------------------------------------------------
1659 Define which options your custom window supports.
1660 --------------------------------------------------------*/
1661 //just enable everything for our demo
1662 *(OptionBits
*)param
=
1665 //kWindowCanCollapse |
1666 //kWindowCanGetWindowRegion |
1667 //kWindowHasTitleBar |
1668 //kWindowSupportsDragHilite |
1669 kWindowCanDrawInCurrentPort
|
1670 //kWindowCanMeasureTitle |
1671 kWindowWantsDisposeAtProcessDeath
|
1672 kWindowSupportsGetGrowImageRegion
|
1673 kWindowDefSupportsColorGrafPort
;
1678 // The content region is left as a rectangle matching the window size, this is
1679 // so the origin in the paint event, and etc. still matches what the
1680 // programmer expects.
1681 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1684 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1688 wxShapedMacWindowGetPos( window
, &r
) ;
1689 RectRgn( rgn
, &r
) ;
1693 // The structure region is set to the shape given to the SetShape method.
1694 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1696 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1702 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1703 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1704 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1705 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1709 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1711 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1716 switch (rgnRec
->regionCode
)
1718 case kWindowStructureRgn
:
1719 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1722 case kWindowContentRgn
:
1723 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1727 SetEmptyRgn(rgnRec
->winRgn
);
1734 // Determine the region of the window which was hit
1736 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1739 static RgnHandle tempRgn
= NULL
;
1741 if (tempRgn
== NULL
)
1744 // get the point clicked
1745 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1747 // Mac OS 8.5 or later
1748 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1749 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1752 // no significant area was hit
1756 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1760 case kWindowMsgHitTest
:
1761 return wxShapedMacWindowHitTest(window
, param
);
1763 case kWindowMsgGetFeatures
:
1764 return wxShapedMacWindowGetFeatures(window
, param
);
1766 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1767 case kWindowMsgGetRegion
:
1768 return wxShapedMacWindowGetRegion(window
, param
);