1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for Mac
4 // Author: Stefan Csomor
8 // Copyright: (c) 2001-2004 Stefan Csomor
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/toplevel.h"
32 #include "wx/string.h"
35 #include "wx/settings.h"
36 #include "wx/strconv.h"
37 #include "wx/control.h"
40 #include "wx/mac/uma.h"
41 #include "wx/mac/aga.h"
42 #include "wx/tooltip.h"
45 #if wxUSE_SYSTEM_OPTIONS
46 #include "wx/sysopt.h"
50 #include <ToolUtils.h>
54 #include "wx/mac/private.h"
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 // 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 static const EventTypeSpec eventList
[] =
86 // TODO: remove control related event like key and mouse (except for WindowLeave events)
88 { kEventClassKeyboard
, kEventRawKeyDown
} ,
89 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
90 { kEventClassKeyboard
, kEventRawKeyUp
} ,
91 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
93 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
94 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
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
;
130 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
133 ByteCount dataSize
= 0 ;
134 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
137 int numChars
= dataSize
/ sizeof( UniChar
) + 1;
139 UniChar
* charBuf
= buf
;
141 if ( numChars
* 2 > 4 )
142 charBuf
= new UniChar
[ numChars
] ;
143 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
144 charBuf
[ numChars
- 1 ] = 0;
146 #if SIZEOF_WCHAR_T == 2
147 uniChar
= charBuf
[0] ;
149 wxMBConvUTF16 converter
;
150 converter
.MB2WC( uniChar
, (const char*)charBuf
, 2 ) ;
153 if ( numChars
* 2 > 4 )
158 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
159 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
160 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
161 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
163 UInt32 message
= (keyCode
<< 8) + charCode
;
164 switch ( GetEventKind( event
) )
166 case kEventRawKeyRepeat
:
167 case kEventRawKeyDown
:
169 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
170 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
171 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
172 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
173 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
177 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
181 case kEventRawKeyUp
:
182 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
183 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
189 case kEventRawKeyModifiersChanged
:
191 wxKeyEvent
event(wxEVT_KEY_DOWN
);
193 event
.m_shiftDown
= modifiers
& shiftKey
;
194 event
.m_controlDown
= modifiers
& controlKey
;
195 event
.m_altDown
= modifiers
& optionKey
;
196 event
.m_metaDown
= modifiers
& cmdKey
;
201 event
.m_uniChar
= uniChar
[0] ;
204 event
.SetTimestamp(when
);
205 event
.SetEventObject(focus
);
207 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
209 event
.m_keyCode
= WXK_CONTROL
;
210 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
211 focus
->GetEventHandler()->ProcessEvent( event
) ;
213 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
215 event
.m_keyCode
= WXK_SHIFT
;
216 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
217 focus
->GetEventHandler()->ProcessEvent( event
) ;
219 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
221 event
.m_keyCode
= WXK_ALT
;
222 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
223 focus
->GetEventHandler()->ProcessEvent( event
) ;
225 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
227 event
.m_keyCode
= WXK_COMMAND
;
228 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
229 focus
->GetEventHandler()->ProcessEvent( event
) ;
232 wxApp::s_lastModifiers
= modifiers
;
243 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
244 // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
247 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
249 wxWindow
* g_MacLastWindow
= NULL
;
251 EventMouseButton g_lastButton
= 0 ;
253 void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
255 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
256 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
258 // this parameter are not given for all events
259 EventMouseButton button
= 0 ;
260 UInt32 clickCount
= 0 ;
261 cEvent
.GetParameter
<EventMouseButton
>( kEventParamMouseButton
, typeMouseButton
, &button
) ;
262 cEvent
.GetParameter
<UInt32
>( kEventParamClickCount
, typeUInt32
, &clickCount
) ;
264 wxevent
.m_x
= screenMouseLocation
.h
;
265 wxevent
.m_y
= screenMouseLocation
.v
;
266 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
267 wxevent
.m_controlDown
= modifiers
& controlKey
;
268 wxevent
.m_altDown
= modifiers
& optionKey
;
269 wxevent
.m_metaDown
= modifiers
& cmdKey
;
270 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
272 // a control click is interpreted as a right click
273 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
274 button
= kEventMouseButtonSecondary
;
276 // otherwise we report double clicks by connecting a left click with a ctrl-left click
277 if ( clickCount
> 1 && button
!= g_lastButton
)
280 // we must make sure that our synthetic 'right' button corresponds in
281 // mouse down, moved and mouse up, and does not deliver a right down and left up
283 if ( cEvent
.GetKind() == kEventMouseDown
)
284 g_lastButton
= button
;
288 else if ( g_lastButton
)
289 button
= g_lastButton
;
291 // determine the correct down state, wx does not want a 'down' for a mouseUp event,
292 // while mac delivers this button
293 if ( button
!= 0 && cEvent
.GetKind() != kEventMouseUp
)
297 case kEventMouseButtonPrimary
:
298 wxevent
.m_leftDown
= true ;
301 case kEventMouseButtonSecondary
:
302 wxevent
.m_rightDown
= true ;
305 case kEventMouseButtonTertiary
:
306 wxevent
.m_middleDown
= true ;
314 // translate into wx types
315 switch ( cEvent
.GetKind() )
317 case kEventMouseDown
:
320 case kEventMouseButtonPrimary
:
321 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
324 case kEventMouseButtonSecondary
:
325 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
328 case kEventMouseButtonTertiary
:
329 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
340 case kEventMouseButtonPrimary
:
341 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
344 case kEventMouseButtonSecondary
:
345 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
348 case kEventMouseButtonTertiary
:
349 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
357 case kEventMouseWheelMoved
:
359 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
361 // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
362 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeSInt32
) ;
364 wxevent
.m_wheelRotation
= delta
;
365 wxevent
.m_wheelDelta
= 1;
366 wxevent
.m_linesPerAction
= 1;
371 wxevent
.SetEventType( wxEVT_MOTION
) ;
376 ControlRef
wxMacFindSubControl( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, ControlRef superControl
, ControlPartCode
*outPart
)
380 UInt16 childrenCount
= 0 ;
381 ControlHandle sibling
;
383 OSStatus err
= CountSubControls( superControl
, &childrenCount
) ;
384 if ( err
== errControlIsNotEmbedder
)
387 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
389 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
391 err
= GetIndexedSubControl( superControl
, i
, & sibling
) ;
392 if ( err
== errControlIsNotEmbedder
)
395 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
396 if ( IsControlVisible( sibling
) )
398 UMAGetControlBoundsInWindowCoords( sibling
, &r
) ;
399 if ( MacPtInRect( location
, &r
) )
401 ControlHandle child
= wxMacFindSubControl( toplevelWindow
, location
, sibling
, outPart
) ;
408 Point testLocation
= location
;
410 if ( toplevelWindow
)
412 testLocation
.h
-= r
.left
;
413 testLocation
.v
-= r
.top
;
416 *outPart
= TestControl( sibling
, testLocation
) ;
428 ControlRef
wxMacFindControlUnderMouse( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, WindowRef window
, ControlPartCode
*outPart
)
430 #if TARGET_API_MAC_OSX
431 if ( UMAGetSystemVersion() >= 0x1030 )
432 return FindControlUnderMouse( location
, window
, outPart
) ;
435 ControlRef rootControl
= NULL
;
436 verify_noerr( GetRootControl( window
, &rootControl
) ) ;
438 return wxMacFindSubControl( toplevelWindow
, location
, rootControl
, outPart
) ;
441 #define NEW_CAPTURE_HANDLING 1
443 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
445 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
447 OSStatus result
= eventNotHandledErr
;
449 wxMacCarbonEvent
cEvent( event
) ;
451 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
452 Point windowMouseLocation
= screenMouseLocation
;
454 WindowRef window
= NULL
;
455 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
457 wxWindow
* currentMouseWindow
= NULL
;
458 ControlRef control
= NULL
;
460 #if NEW_CAPTURE_HANDLING
461 if ( wxApp::s_captureWindow
)
463 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
464 windowPart
= inContent
;
470 wxMacGlobalToLocal( window
, &windowMouseLocation
) ;
472 if ( wxApp::s_captureWindow
473 #if !NEW_CAPTURE_HANDLING
474 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
478 currentMouseWindow
= wxApp::s_captureWindow
;
480 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
482 ControlPartCode part
;
483 control
= wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &part
) ;
484 // if there is no control below the mouse position, send the event to the toplevel window itself
487 currentMouseWindow
= (wxWindow
*) data
;
491 currentMouseWindow
= wxFindControlFromMacControl( control
) ;
492 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
495 // for wxToolBar to function we have to send certaint events to it
496 // instead of its children (wxToolBarTools)
498 GetSuperControl(control
, &parent
);
499 wxWindow
*wxParent
= wxFindControlFromMacControl( parent
) ;
500 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
501 currentMouseWindow
= wxParent
;
506 // disabled windows must not get any input messages
507 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
508 currentMouseWindow
= NULL
;
512 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
513 SetupMouseEvent( wxevent
, cEvent
) ;
515 // handle all enter / leave events
517 if ( currentMouseWindow
!= g_MacLastWindow
)
519 if ( g_MacLastWindow
)
521 wxMouseEvent
eventleave(wxevent
);
522 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
523 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
524 eventleave
.SetEventObject( g_MacLastWindow
) ;
525 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
528 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
531 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
534 if ( currentMouseWindow
)
536 wxMouseEvent
evententer(wxevent
);
537 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
538 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
539 evententer
.SetEventObject( currentMouseWindow
) ;
540 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
543 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
546 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
549 g_MacLastWindow
= currentMouseWindow
;
552 if ( windowPart
== inMenuBar
)
554 // special case menu bar, as we are having a low-level runloop we must do it ourselves
555 if ( cEvent
.GetKind() == kEventMouseDown
)
557 ::MenuSelect( screenMouseLocation
) ;
561 else if ( currentMouseWindow
)
563 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
565 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
567 wxevent
.SetEventObject( currentMouseWindow
) ;
568 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
570 // make tooltips current
573 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
574 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
577 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
579 if ((currentMouseWindowParent
!= NULL
) &&
580 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
581 currentMouseWindow
= NULL
;
587 // if the user code did _not_ handle the event, then perform the
588 // default processing
589 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
591 // ... that is set focus to this window
592 if (currentMouseWindow
->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
593 currentMouseWindow
->SetFocus();
596 ControlPartCode dummyPart
;
597 // if built-in find control is finding the wrong control (ie static box instead of overlaid
598 // button, we cannot let the standard handler do its job, but must handle manually
600 if ( ( cEvent
.GetKind() == kEventMouseDown
)
603 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
604 wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &dummyPart
) )
608 if ( currentMouseWindow
->MacIsReallyEnabled() )
610 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
611 Point clickLocation
= windowMouseLocation
;
613 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
615 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
616 modifiers
, (ControlActionUPP
) -1 ) ;
618 if ((currentMouseWindowParent
!= NULL
) &&
619 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
621 currentMouseWindow
= NULL
;
629 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
631 wxApp::s_captureWindow
= NULL
;
637 wxWindow
* cursorTarget
= currentMouseWindow
;
638 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
640 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
642 cursorTarget
= cursorTarget
->GetParent() ;
644 cursorPoint
+= cursorTarget
->GetPosition();
648 else // currentMouseWindow == NULL
650 // don't mess with controls we don't know about
651 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
652 // so we try sending them the correct control directly
653 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
655 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
656 Point clickLocation
= windowMouseLocation
;
657 #if TARGET_API_MAC_OSX
659 hiPoint
.x
= clickLocation
.h
;
660 hiPoint
.y
= clickLocation
.v
;
661 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
662 clickLocation
.h
= (int)hiPoint
.x
;
663 clickLocation
.v
= (int)hiPoint
.y
;
664 #endif // TARGET_API_MAC_OSX
666 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
674 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
676 OSStatus result
= eventNotHandledErr
;
678 wxMacCarbonEvent
cEvent( event
) ;
680 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
681 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
683 switch ( GetEventKind( event
) )
685 case kEventWindowActivated
:
687 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
688 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
689 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
690 wxevent
.SetEventObject(toplevelWindow
);
691 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
692 // we still sending an eventNotHandledErr in order to allow for default processing
696 case kEventWindowDeactivated
:
698 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
699 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
700 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
701 wxevent
.SetEventObject(toplevelWindow
);
702 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
703 // we still sending an eventNotHandledErr in order to allow for default processing
707 case kEventWindowShown
:
708 toplevelWindow
->Refresh() ;
712 case kEventWindowClose
:
713 toplevelWindow
->Close() ;
717 case kEventWindowBoundsChanged
:
719 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
720 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
721 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
722 if ( attributes
& kWindowBoundsChangeSizeChanged
)
724 // according to the other ports we handle this within the OS level
725 // resize event, not within a wxSizeEvent
726 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
729 frame
->PositionBars();
732 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
733 event
.SetEventObject( toplevelWindow
) ;
735 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
736 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
739 if ( attributes
& kWindowBoundsChangeOriginChanged
)
741 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
742 event
.SetEventObject( toplevelWindow
) ;
743 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
750 case kEventWindowBoundsChanging
:
752 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
753 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
755 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
757 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
758 int left
, top
, right
, bottom
;
759 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
764 newRect
.right
- newRect
.left
+ left
+ right
,
765 newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
767 // this is a EVT_SIZING not a EVT_SIZE type !
768 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
769 wxevent
.SetEventObject( toplevelWindow
) ;
771 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
772 adjustR
= wxevent
.GetRect() ;
774 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
775 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
776 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
777 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
778 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
779 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
780 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
781 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
782 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
783 if ( !EqualRect( &newRect
, &adjustedRect
) )
784 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
785 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
799 // mix this in from window.cpp
800 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
802 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
804 OSStatus result
= eventNotHandledErr
;
806 switch ( GetEventClass( event
) )
808 case kEventClassTextInput
:
809 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
812 case kEventClassKeyboard
:
813 result
= KeyboardEventHandler( handler
, event
, data
) ;
816 case kEventClassWindow
:
817 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
820 case kEventClassMouse
:
821 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
831 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
833 // ---------------------------------------------------------------------------
834 // wxWindowMac utility functions
835 // ---------------------------------------------------------------------------
837 // Find an item given the Macintosh Window Reference
839 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
841 static MacWindowMap wxWinMacWindowList
;
843 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
845 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
847 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
850 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
851 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
853 // adding NULL WindowRef is (first) surely a result of an error and
855 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
857 wxWinMacWindowList
[inWindowRef
] = win
;
860 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
861 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
863 MacWindowMap::iterator it
;
864 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
866 if ( it
->second
== win
)
868 wxWinMacWindowList
.erase(it
);
874 // ----------------------------------------------------------------------------
875 // wxTopLevelWindowMac creation
876 // ----------------------------------------------------------------------------
878 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
884 bool m_wasResizable
;
887 void wxTopLevelWindowMac::Init()
890 m_maximizeOnShow
= false;
893 m_macEventHandler
= NULL
;
894 m_macFullScreenData
= NULL
;
897 class wxMacDeferredWindowDeleter
: public wxObject
900 wxMacDeferredWindowDeleter( WindowRef windowRef
)
902 m_macWindow
= windowRef
;
905 virtual ~wxMacDeferredWindowDeleter()
907 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
911 WindowRef m_macWindow
;
914 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
916 const wxString
& title
,
920 const wxString
& name
)
925 m_windowStyle
= style
;
929 m_windowId
= id
== -1 ? NewControlId() : id
;
930 wxWindow::SetLabel( title
) ;
932 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
934 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
936 if (GetExtraStyle() & wxFRAME_EX_METAL
)
937 MacSetMetalAppearance(true);
939 wxTopLevelWindows
.Append(this);
942 parent
->AddChild(this);
947 wxTopLevelWindowMac::~wxTopLevelWindowMac()
952 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
954 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
957 if ( m_macEventHandler
)
959 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
960 m_macEventHandler
= NULL
;
963 wxRemoveMacWindowAssociation( this ) ;
965 if ( wxModelessWindows
.Find(this) )
966 wxModelessWindows
.DeleteObject(this);
968 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
970 m_macFullScreenData
= NULL
;
974 // ----------------------------------------------------------------------------
975 // wxTopLevelWindowMac maximize/minimize
976 // ----------------------------------------------------------------------------
978 void wxTopLevelWindowMac::Maximize(bool maximize
)
980 Point idealSize
= { 0 , 0 } ;
983 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
985 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
987 idealSize
.h
= bounds
.size
.width
;
988 idealSize
.v
= bounds
.size
.height
;
991 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
992 idealSize
.h
= rect
.right
- rect
.left
;
993 idealSize
.v
= rect
.bottom
- rect
.top
;
996 ZoomWindowIdeal( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
999 bool wxTopLevelWindowMac::IsMaximized() const
1001 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
1004 void wxTopLevelWindowMac::Iconize(bool iconize
)
1006 if ( IsWindowCollapsable( (WindowRef
)m_macWindow
) )
1007 CollapseWindow( (WindowRef
)m_macWindow
, iconize
) ;
1010 bool wxTopLevelWindowMac::IsIconized() const
1012 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1015 void wxTopLevelWindowMac::Restore()
1017 if ( IsMaximized() )
1019 else if ( IsIconized() )
1023 // ----------------------------------------------------------------------------
1024 // wxTopLevelWindowMac misc
1025 // ----------------------------------------------------------------------------
1027 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1029 return wxPoint(0, 0) ;
1032 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
1035 wxTopLevelWindowBase::SetIcon(icon
);
1038 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1040 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1042 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1044 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1048 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1050 if ( m_macEventHandler
!= NULL
)
1052 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1055 InstallWindowEventHandler(
1056 MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1057 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1060 void wxTopLevelWindowMac::MacCreateRealWindow(
1061 const wxString
& title
,
1065 const wxString
& name
)
1067 OSStatus err
= noErr
;
1069 m_windowStyle
= style
;
1077 wxRect display
= wxGetClientDisplayRect() ;
1079 if ( x
== wxDefaultPosition
.x
)
1082 if ( y
== wxDefaultPosition
.y
)
1085 int w
= WidthDefault(size
.x
);
1086 int h
= HeightDefault(size
.y
);
1088 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1090 // translate the window attributes in the appropriate window class and attributes
1091 WindowClass wclass
= 0;
1092 WindowAttributes attr
= kWindowNoAttributes
;
1093 WindowGroupRef group
= NULL
;
1095 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1098 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1099 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1100 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1103 wclass
= kFloatingWindowClass
;
1105 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1106 attr
|= kWindowSideTitlebarAttribute
;
1110 wclass
= kPlainWindowClass
;
1113 else if ( HasFlag( wxCAPTION
) )
1115 wclass
= kDocumentWindowClass
;
1116 attr
|= kWindowInWindowMenuAttribute
;
1118 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1119 else if ( HasFlag( wxFRAME_DRAWER
) )
1121 wclass
= kDrawerWindowClass
;
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 attr
|= kWindowCompositingAttribute
;
1160 #if 0 // wxMAC_USE_CORE_GRAPHICS ; TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1161 attr
|= kWindowFrameworkScaledAttribute
;
1164 if ( HasFlag(wxFRAME_SHAPED
) )
1166 WindowDefSpec customWindowDefSpec
;
1167 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1168 customWindowDefSpec
.u
.defProc
=
1170 (WindowDefUPP
) wxShapedMacWindowDef
;
1172 NewWindowDefUPP(wxShapedMacWindowDef
);
1174 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1175 attr
, &theBoundsRect
,
1176 (WindowRef
*) &m_macWindow
);
1180 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1183 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1184 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1186 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1188 // setup a separate group for each window, so that overlays can be handled easily
1189 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &group
));
1190 verify_noerr( SetWindowGroupParent( group
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1191 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, group
));
1193 // the create commands are only for content rect,
1194 // so we have to set the size again as structure bounds
1195 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1197 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1198 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1199 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1201 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1202 // the content view, so we have to retrieve it explicitly
1203 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1204 m_peer
->GetControlRefAddr() ) ;
1205 if ( !m_peer
->Ok() )
1207 // compatibility mode fallback
1208 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1211 // the root control level handler
1212 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1214 // Causes the inner part of the window not to be metal
1215 // if the style is used before window creation.
1216 #if 0 // TARGET_API_MAC_OSX
1217 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1219 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1220 MacSetMetalAppearance( true ) ;
1224 // the frame window event handler
1225 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1226 MacInstallTopLevelWindowEventHandler() ;
1228 DoSetWindowVariant( m_windowVariant
) ;
1232 if ( HasFlag(wxFRAME_SHAPED
) )
1234 // default shape matches the window size
1235 wxRegion
rgn( 0, 0, w
, h
);
1239 wxWindowCreateEvent
event(this);
1240 GetEventHandler()->ProcessEvent(event
);
1243 void wxTopLevelWindowMac::ClearBackground()
1245 wxWindow::ClearBackground() ;
1248 // Raise the window to the top of the Z order
1249 void wxTopLevelWindowMac::Raise()
1251 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1254 // Lower the window to the bottom of the Z order
1255 void wxTopLevelWindowMac::Lower()
1257 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1260 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1262 if (s_macDeactivateWindow
)
1264 wxLogTrace(TRACE_ACTIVATE
,
1265 wxT("Doing delayed deactivation of %p"),
1266 s_macDeactivateWindow
);
1268 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1272 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1274 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1276 if (s_macDeactivateWindow
== this)
1277 s_macDeactivateWindow
= NULL
;
1279 MacDelayedDeactivation(timestamp
);
1280 MacPropagateHiliteChanged() ;
1283 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1285 wxWindow::SetLabel( title
) ;
1286 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1289 wxString
wxTopLevelWindowMac::GetTitle() const
1291 return wxWindow::GetLabel();
1294 bool wxTopLevelWindowMac::Show(bool show
)
1296 if ( !wxTopLevelWindowBase::Show(show
) )
1299 bool plainTransition
= false;
1301 #if wxUSE_SYSTEM_OPTIONS
1302 // code contributed by Ryan Wilcox December 18, 2003
1303 plainTransition
= UMAGetSystemVersion() >= 0x1000 ;
1304 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1305 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1310 if ( plainTransition
)
1311 ::ShowWindow( (WindowRef
)m_macWindow
);
1313 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1315 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1317 // because apps expect a size event to occur at this moment
1318 wxSizeEvent
event(GetSize() , m_windowId
);
1319 event
.SetEventObject(this);
1320 GetEventHandler()->ProcessEvent(event
);
1324 if ( plainTransition
)
1325 ::HideWindow( (WindowRef
)m_macWindow
);
1327 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1330 MacPropagateVisibilityChanged() ;
1335 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1339 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1341 data
= new FullScreenData() ;
1343 m_macFullScreenData
= data
;
1344 data
->m_position
= GetPosition() ;
1345 data
->m_size
= GetSize() ;
1346 data
->m_wasResizable
= MacGetWindowAttributes() & kWindowResizableAttribute
;
1348 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1351 wxRect client
= wxGetClientDisplayRect() ;
1353 int left
, top
, right
, bottom
;
1361 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1363 if ( style
& wxFULLSCREEN_NOCAPTION
)
1369 if ( style
& wxFULLSCREEN_NOBORDER
)
1376 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1381 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1386 SetSize( x
, y
, w
, h
) ;
1387 if ( data
->m_wasResizable
)
1388 MacChangeWindowAttributes( kWindowNoAttributes
, kWindowResizableAttribute
) ;
1393 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1394 if ( data
->m_wasResizable
)
1395 MacChangeWindowAttributes( kWindowResizableAttribute
, kWindowNoAttributes
) ;
1396 SetPosition( data
->m_position
) ;
1397 SetSize( data
->m_size
) ;
1400 m_macFullScreenData
= NULL
;
1406 bool wxTopLevelWindowMac::IsFullScreen() const
1408 return m_macFullScreenData
!= NULL
;
1412 bool wxTopLevelWindowMac::SetTransparent(wxByte alpha
)
1414 OSStatus result
= SetWindowAlpha((WindowRef
)m_macWindow
, float(alpha
)/255.0);
1415 return result
== noErr
;
1419 bool wxTopLevelWindowMac::CanSetTransparent()
1425 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1427 if ( GetExtraStyle() == exStyle
)
1430 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1432 #if TARGET_API_MAC_OSX
1433 if ( m_macWindow
!= NULL
)
1435 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1436 if ( MacGetMetalAppearance() != metal
)
1437 MacSetMetalAppearance( metal
) ;
1442 // TODO: switch to structure bounds -
1443 // we are still using coordinates of the content view
1445 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1447 Rect content
, structure
;
1449 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1450 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1452 left
= content
.left
- structure
.left
;
1453 top
= content
.top
- structure
.top
;
1454 right
= structure
.right
- content
.right
;
1455 bottom
= structure
.bottom
- content
.bottom
;
1458 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1460 m_cachedClippedRectValid
= false ;
1461 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1462 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1463 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1466 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1470 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1478 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1482 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1485 *width
= bounds
.right
- bounds
.left
;
1487 *height
= bounds
.bottom
- bounds
.top
;
1490 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1494 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1497 *width
= bounds
.right
- bounds
.left
;
1499 *height
= bounds
.bottom
- bounds
.top
;
1502 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1504 #if TARGET_API_MAC_OSX
1505 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1506 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1510 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1512 #if TARGET_API_MAC_OSX
1513 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1519 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1521 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1524 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1527 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1532 void wxTopLevelWindowMac::MacPerformUpdates()
1534 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1535 // for composited windows this also triggers a redraw of all
1536 // invalid views in the window
1537 if ( UMAGetSystemVersion() >= 0x1030 )
1538 HIWindowFlush((WindowRef
) m_macWindow
) ;
1542 // the only way to trigger the redrawing on earlier systems is to call
1545 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1546 UInt32 currentEventClass
= 0 ;
1547 if ( currentEvent
!= NULL
)
1549 currentEventClass
= ::GetEventClass( currentEvent
) ;
1550 ::GetEventKind( currentEvent
) ;
1553 if ( currentEventClass
!= kEventClassMenu
)
1555 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1557 ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1562 // Attracts the users attention to this window if the application is
1563 // inactive (should be called when a background event occurs)
1565 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1568 DisposePtr( (Ptr
)ptr
) ;
1571 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1573 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1574 static wxMacNMUPP
nmupp( wxMacNMResponse
);
1576 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1577 notificationRequest
->qType
= nmType
;
1578 notificationRequest
->nmMark
= 1 ;
1579 notificationRequest
->nmIcon
= 0 ;
1580 notificationRequest
->nmSound
= 0 ;
1581 notificationRequest
->nmStr
= NULL
;
1582 notificationRequest
->nmResp
= nmupp
;
1584 verify_noerr( NMInstall( notificationRequest
) ) ;
1587 // ---------------------------------------------------------------------------
1588 // Shape implementation
1589 // ---------------------------------------------------------------------------
1592 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1594 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1595 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1597 // The empty region signifies that the shape
1598 // should be removed from the window.
1599 if ( region
.IsEmpty() )
1601 wxSize sz
= GetClientSize();
1602 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1603 if ( rgn
.IsEmpty() )
1606 return SetShape(rgn
);
1609 // Make a copy of the region
1610 RgnHandle shapeRegion
= NewRgn();
1611 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1613 // Dispose of any shape region we may already have
1614 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1618 // Save the region so we can use it later
1619 SetWRefCon((WindowRef
)MacGetWindowRef(), (URefCon
)shapeRegion
);
1621 // inform the window manager that the window has changed shape
1622 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1627 // ---------------------------------------------------------------------------
1628 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1629 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1630 // ---------------------------------------------------------------------------
1632 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1634 GetWindowPortBounds(window
, inRect
);
1635 Point pt
= { inRect
->top
,inRect
->left
};
1636 wxMacLocalToGlobal( window
, &pt
) ;
1637 inRect
->bottom
+= pt
.v
- inRect
->top
;
1638 inRect
->right
+= pt
.h
- inRect
->left
;
1640 inRect
->left
= pt
.h
;
1643 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1645 /*------------------------------------------------------
1646 Define which options your custom window supports.
1647 --------------------------------------------------------*/
1648 //just enable everything for our demo
1649 *(OptionBits
*)param
=
1652 //kWindowCanCollapse |
1653 //kWindowCanGetWindowRegion |
1654 //kWindowHasTitleBar |
1655 //kWindowSupportsDragHilite |
1656 kWindowCanDrawInCurrentPort
|
1657 //kWindowCanMeasureTitle |
1658 kWindowWantsDisposeAtProcessDeath
|
1659 kWindowSupportsGetGrowImageRegion
|
1660 kWindowDefSupportsColorGrafPort
;
1665 // The content region is left as a rectangle matching the window size, this is
1666 // so the origin in the paint event, and etc. still matches what the
1667 // programmer expects.
1668 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1671 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1675 wxShapedMacWindowGetPos( window
, &r
) ;
1676 RectRgn( rgn
, &r
) ;
1680 // The structure region is set to the shape given to the SetShape method.
1681 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1683 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1689 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1690 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1691 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1692 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1696 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1698 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1703 switch (rgnRec
->regionCode
)
1705 case kWindowStructureRgn
:
1706 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1709 case kWindowContentRgn
:
1710 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1714 SetEmptyRgn(rgnRec
->winRgn
);
1721 // Determine the region of the window which was hit
1723 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1726 static RgnHandle tempRgn
= NULL
;
1728 if (tempRgn
== NULL
)
1731 // get the point clicked
1732 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1734 // Mac OS 8.5 or later
1735 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1736 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1739 // no significant area was hit
1743 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1747 case kWindowMsgHitTest
:
1748 return wxShapedMacWindowHitTest(window
, param
);
1750 case kWindowMsgGetFeatures
:
1751 return wxShapedMacWindowGetFeatures(window
, param
);
1753 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1754 case kWindowMsgGetRegion
:
1755 return wxShapedMacWindowGetRegion(window
, param
);