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
} ,
95 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
96 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
98 { kEventClassWindow
, kEventWindowShown
} ,
99 { kEventClassWindow
, kEventWindowActivated
} ,
100 { kEventClassWindow
, kEventWindowDeactivated
} ,
101 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
102 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
103 { kEventClassWindow
, kEventWindowClose
} ,
105 // we have to catch these events on the toplevel window level,
106 // as controls don't get the raw mouse events anymore
108 { kEventClassMouse
, kEventMouseDown
} ,
109 { kEventClassMouse
, kEventMouseUp
} ,
110 { kEventClassMouse
, kEventMouseWheelMoved
} ,
111 { kEventClassMouse
, kEventMouseMoved
} ,
112 { kEventClassMouse
, kEventMouseDragged
} ,
115 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
117 OSStatus result
= eventNotHandledErr
;
118 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
119 // FindFocus does not return the actual focus window, but the enclosing window
120 wxWindow
* focus
= wxWindow::DoFindFocus();
122 focus
= (wxTopLevelWindowMac
*) data
;
124 unsigned char charCode
;
132 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
135 UInt32 dataSize
= 0 ;
136 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
139 int numChars
= dataSize
/ sizeof( UniChar
) + 1;
141 UniChar
* charBuf
= buf
;
143 if ( numChars
* 2 > 4 )
144 charBuf
= new UniChar
[ numChars
] ;
145 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
146 charBuf
[ numChars
- 1 ] = 0;
148 #if SIZEOF_WCHAR_T == 2
149 uniChar
= charBuf
[0] ;
151 wxMBConvUTF16 converter
;
152 converter
.MB2WC( uniChar
, (const char*)charBuf
, 2 ) ;
155 if ( numChars
* 2 > 4 )
160 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
161 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
162 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
163 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
165 UInt32 message
= (keyCode
<< 8) + charCode
;
166 switch ( GetEventKind( event
) )
168 case kEventRawKeyRepeat
:
169 case kEventRawKeyDown
:
171 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
172 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
173 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
174 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
175 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
179 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
183 case kEventRawKeyUp
:
184 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
185 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
191 case kEventRawKeyModifiersChanged
:
193 wxKeyEvent
event(wxEVT_KEY_DOWN
);
195 event
.m_shiftDown
= modifiers
& shiftKey
;
196 event
.m_controlDown
= modifiers
& controlKey
;
197 event
.m_altDown
= modifiers
& optionKey
;
198 event
.m_metaDown
= modifiers
& cmdKey
;
203 event
.m_uniChar
= uniChar
[0] ;
206 event
.SetTimestamp(when
);
207 event
.SetEventObject(focus
);
209 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
211 event
.m_keyCode
= WXK_CONTROL
;
212 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
213 focus
->GetEventHandler()->ProcessEvent( event
) ;
215 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
217 event
.m_keyCode
= WXK_SHIFT
;
218 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
219 focus
->GetEventHandler()->ProcessEvent( event
) ;
221 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
223 event
.m_keyCode
= WXK_ALT
;
224 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
225 focus
->GetEventHandler()->ProcessEvent( event
) ;
227 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
229 event
.m_keyCode
= WXK_COMMAND
;
230 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
231 focus
->GetEventHandler()->ProcessEvent( event
) ;
234 wxApp::s_lastModifiers
= modifiers
;
245 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
246 // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
249 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
251 wxWindow
* g_MacLastWindow
= NULL
;
253 static EventMouseButton lastButton
= 0 ;
255 static void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
257 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
258 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
260 // this parameter are not given for all events
261 EventMouseButton button
= 0 ;
262 UInt32 clickCount
= 0 ;
263 cEvent
.GetParameter
<EventMouseButton
>( kEventParamMouseButton
, typeMouseButton
, &button
) ;
264 cEvent
.GetParameter
<UInt32
>( kEventParamClickCount
, typeUInt32
, &clickCount
) ;
266 wxevent
.m_x
= screenMouseLocation
.h
;
267 wxevent
.m_y
= screenMouseLocation
.v
;
268 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
269 wxevent
.m_controlDown
= modifiers
& controlKey
;
270 wxevent
.m_altDown
= modifiers
& optionKey
;
271 wxevent
.m_metaDown
= modifiers
& cmdKey
;
272 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
274 // a control click is interpreted as a right click
275 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
276 button
= kEventMouseButtonSecondary
;
278 // otherwise we report double clicks by connecting a left click with a ctrl-left click
279 if ( clickCount
> 1 && button
!= lastButton
)
282 // we must make sure that our synthetic 'right' button corresponds in
283 // mouse down, moved and mouse up, and does not deliver a right down and left up
285 if ( cEvent
.GetKind() == kEventMouseDown
)
286 lastButton
= button
;
290 else if ( lastButton
)
291 button
= lastButton
;
293 // determine the correct down state, wx does not want a 'down' for a mouseUp event,
294 // while mac delivers this button
295 if ( button
!= 0 && cEvent
.GetKind() != kEventMouseUp
)
299 case kEventMouseButtonPrimary
:
300 wxevent
.m_leftDown
= true ;
303 case kEventMouseButtonSecondary
:
304 wxevent
.m_rightDown
= true ;
307 case kEventMouseButtonTertiary
:
308 wxevent
.m_middleDown
= true ;
316 // translate into wx types
317 switch ( cEvent
.GetKind() )
319 case kEventMouseDown
:
322 case kEventMouseButtonPrimary
:
323 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
326 case kEventMouseButtonSecondary
:
327 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
330 case kEventMouseButtonTertiary
:
331 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
342 case kEventMouseButtonPrimary
:
343 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
346 case kEventMouseButtonSecondary
:
347 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
350 case kEventMouseButtonTertiary
:
351 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
359 case kEventMouseWheelMoved
:
361 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
363 // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
364 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeLongInteger
) ;
366 wxevent
.m_wheelRotation
= delta
;
367 wxevent
.m_wheelDelta
= 1;
368 wxevent
.m_linesPerAction
= 1;
373 wxevent
.SetEventType( wxEVT_MOTION
) ;
378 ControlRef
wxMacFindSubControl( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, ControlRef superControl
, ControlPartCode
*outPart
)
382 UInt16 childrenCount
= 0 ;
383 ControlHandle sibling
;
385 OSStatus err
= CountSubControls( superControl
, &childrenCount
) ;
386 if ( err
== errControlIsNotEmbedder
)
389 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
391 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
393 err
= GetIndexedSubControl( superControl
, i
, & sibling
) ;
394 if ( err
== errControlIsNotEmbedder
)
397 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
398 if ( IsControlVisible( sibling
) )
400 UMAGetControlBoundsInWindowCoords( sibling
, &r
) ;
401 if ( MacPtInRect( location
, &r
) )
403 ControlHandle child
= wxMacFindSubControl( toplevelWindow
, location
, sibling
, outPart
) ;
410 Point testLocation
= location
;
412 if ( toplevelWindow
&& toplevelWindow
->MacUsesCompositing() )
414 testLocation
.h
-= r
.left
;
415 testLocation
.v
-= r
.top
;
418 *outPart
= TestControl( sibling
, testLocation
) ;
430 ControlRef
wxMacFindControlUnderMouse( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, WindowRef window
, ControlPartCode
*outPart
)
432 #if TARGET_API_MAC_OSX
433 if ( UMAGetSystemVersion() >= 0x1030 && ( toplevelWindow
== 0 || toplevelWindow
->MacUsesCompositing() ) )
434 return FindControlUnderMouse( location
, window
, outPart
) ;
437 ControlRef rootControl
= NULL
;
438 verify_noerr( GetRootControl( window
, &rootControl
) ) ;
440 return wxMacFindSubControl( toplevelWindow
, location
, rootControl
, outPart
) ;
443 #define NEW_CAPTURE_HANDLING 1
445 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
447 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
449 OSStatus result
= eventNotHandledErr
;
451 wxMacCarbonEvent
cEvent( event
) ;
453 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
454 Point windowMouseLocation
= screenMouseLocation
;
456 WindowRef window
= NULL
;
457 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
459 wxWindow
* currentMouseWindow
= NULL
;
460 ControlRef control
= NULL
;
462 #if NEW_CAPTURE_HANDLING
463 if ( wxApp::s_captureWindow
)
465 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
466 windowPart
= inContent
;
472 QDGlobalToLocalPoint( UMAGetWindowPort(window
) , &windowMouseLocation
) ;
474 if ( wxApp::s_captureWindow
475 #if !NEW_CAPTURE_HANDLING
476 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
480 currentMouseWindow
= wxApp::s_captureWindow
;
482 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
484 ControlPartCode part
;
485 control
= wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &part
) ;
486 // if there is no control below the mouse position, send the event to the toplevel window itself
489 currentMouseWindow
= (wxWindow
*) data
;
493 currentMouseWindow
= wxFindControlFromMacControl( control
) ;
494 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
497 // for wxToolBar to function we have to send certaint events to it
498 // instead of its children (wxToolBarTools)
500 GetSuperControl(control
, &parent
);
501 wxWindow
*wxParent
= wxFindControlFromMacControl( parent
) ;
502 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
503 currentMouseWindow
= wxParent
;
508 // disabled windows must not get any input messages
509 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
510 currentMouseWindow
= NULL
;
514 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
515 SetupMouseEvent( wxevent
, cEvent
) ;
517 // handle all enter / leave events
519 if ( currentMouseWindow
!= g_MacLastWindow
)
521 if ( g_MacLastWindow
)
523 wxMouseEvent
eventleave(wxevent
);
524 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
525 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
526 eventleave
.SetEventObject( g_MacLastWindow
) ;
527 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
530 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
533 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
536 if ( currentMouseWindow
)
538 wxMouseEvent
evententer(wxevent
);
539 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
540 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
541 evententer
.SetEventObject( currentMouseWindow
) ;
542 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
545 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
548 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
551 g_MacLastWindow
= currentMouseWindow
;
554 if ( windowPart
== inMenuBar
)
556 // special case menu bar, as we are having a low-level runloop we must do it ourselves
557 if ( cEvent
.GetKind() == kEventMouseDown
)
559 ::MenuSelect( screenMouseLocation
) ;
563 else if ( currentMouseWindow
)
565 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
567 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
569 wxevent
.SetEventObject( currentMouseWindow
) ;
570 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
572 // make tooltips current
575 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
576 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
579 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
581 if ((currentMouseWindowParent
!= NULL
) &&
582 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
583 currentMouseWindow
= NULL
;
589 // if the user code did _not_ handle the event, then perform the
590 // default processing
591 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
593 // ... that is set focus to this window
594 if (currentMouseWindow
->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
595 currentMouseWindow
->SetFocus();
598 ControlPartCode dummyPart
;
599 // if built-in find control is finding the wrong control (ie static box instead of overlaid
600 // button, we cannot let the standard handler do its job, but must handle manually
602 if ( ( cEvent
.GetKind() == kEventMouseDown
)
605 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
606 wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &dummyPart
) )
610 if ( currentMouseWindow
->MacIsReallyEnabled() )
612 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
613 Point clickLocation
= windowMouseLocation
;
615 if ( toplevelWindow
->MacUsesCompositing() )
616 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
618 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
619 modifiers
, (ControlActionUPP
) -1 ) ;
621 if ((currentMouseWindowParent
!= NULL
) &&
622 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
624 currentMouseWindow
= NULL
;
632 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
634 wxApp::s_captureWindow
= NULL
;
640 wxWindow
* cursorTarget
= currentMouseWindow
;
641 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
643 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
645 cursorTarget
= cursorTarget
->GetParent() ;
647 cursorPoint
+= cursorTarget
->GetPosition();
651 else // currentMouseWindow == NULL
653 // don't mess with controls we don't know about
654 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
655 // so we try sending them the correct control directly
656 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
658 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
659 Point clickLocation
= windowMouseLocation
;
660 #if TARGET_API_MAC_OSX
661 if ( toplevelWindow
->MacUsesCompositing() )
664 hiPoint
.x
= clickLocation
.h
;
665 hiPoint
.y
= clickLocation
.v
;
666 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
667 clickLocation
.h
= (int)hiPoint
.x
;
668 clickLocation
.v
= (int)hiPoint
.y
;
670 #endif // TARGET_API_MAC_OSX
672 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
680 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
682 OSStatus result
= eventNotHandledErr
;
684 wxMacCarbonEvent
cEvent( event
) ;
686 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
687 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
689 switch ( GetEventKind( event
) )
691 case kEventWindowActivated
:
693 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
694 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
695 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
696 wxevent
.SetEventObject(toplevelWindow
);
697 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
698 // we still sending an eventNotHandledErr in order to allow for default processing
702 case kEventWindowDeactivated
:
704 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
705 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
706 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
707 wxevent
.SetEventObject(toplevelWindow
);
708 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
709 // we still sending an eventNotHandledErr in order to allow for default processing
713 case kEventWindowShown
:
714 toplevelWindow
->Refresh() ;
718 case kEventWindowClose
:
719 toplevelWindow
->Close() ;
723 case kEventWindowBoundsChanged
:
725 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
726 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
727 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
728 if ( attributes
& kWindowBoundsChangeSizeChanged
)
730 // according to the other ports we handle this within the OS level
731 // resize event, not within a wxSizeEvent
732 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
735 frame
->PositionBars();
738 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
739 event
.SetEventObject( toplevelWindow
) ;
741 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
742 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
745 if ( attributes
& kWindowBoundsChangeOriginChanged
)
747 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
748 event
.SetEventObject( toplevelWindow
) ;
749 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
756 case kEventWindowBoundsChanging
:
758 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
759 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
761 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
763 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
764 int left
, top
, right
, bottom
;
765 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
770 newRect
.right
- newRect
.left
+ left
+ right
,
771 newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
773 // this is a EVT_SIZING not a EVT_SIZE type !
774 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
775 wxevent
.SetEventObject( toplevelWindow
) ;
777 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
778 adjustR
= wxevent
.GetRect() ;
780 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
781 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
782 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
783 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
784 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
785 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
786 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
787 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
788 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
789 if ( !EqualRect( &newRect
, &adjustedRect
) )
790 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
791 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
805 // mix this in from window.cpp
806 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
808 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
810 OSStatus result
= eventNotHandledErr
;
812 switch ( GetEventClass( event
) )
814 case kEventClassTextInput
:
815 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
818 case kEventClassKeyboard
:
819 result
= KeyboardEventHandler( handler
, event
, data
) ;
822 case kEventClassWindow
:
823 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
826 case kEventClassMouse
:
827 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
837 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
839 // ---------------------------------------------------------------------------
840 // wxWindowMac utility functions
841 // ---------------------------------------------------------------------------
843 // Find an item given the Macintosh Window Reference
845 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
847 static MacWindowMap wxWinMacWindowList
;
849 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
851 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
853 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
856 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
857 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
859 // adding NULL WindowRef is (first) surely a result of an error and
861 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
863 wxWinMacWindowList
[inWindowRef
] = win
;
866 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
867 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
869 MacWindowMap::iterator it
;
870 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
872 if ( it
->second
== win
)
874 wxWinMacWindowList
.erase(it
);
880 // ----------------------------------------------------------------------------
881 // wxTopLevelWindowMac creation
882 // ----------------------------------------------------------------------------
884 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
890 bool m_wasResizable
;
894 void wxTopLevelWindowMac::Init()
897 m_maximizeOnShow
= false;
900 #if TARGET_API_MAC_OSX
901 m_macUsesCompositing
= ( UMAGetSystemVersion() >= 0x1030 );
903 m_macUsesCompositing
= false;
906 m_macEventHandler
= NULL
;
907 m_macFullScreenData
= NULL
;
910 class wxMacDeferredWindowDeleter
: public wxObject
913 wxMacDeferredWindowDeleter( WindowRef windowRef
)
915 m_macWindow
= windowRef
;
918 virtual ~wxMacDeferredWindowDeleter()
920 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
924 WindowRef m_macWindow
;
927 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
929 const wxString
& title
,
933 const wxString
& name
)
938 m_windowStyle
= style
;
942 m_windowId
= id
== -1 ? NewControlId() : id
;
943 wxWindow::SetLabel( title
) ;
945 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
947 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
949 if (GetExtraStyle() & wxFRAME_EX_METAL
)
950 MacSetMetalAppearance(true);
952 wxTopLevelWindows
.Append(this);
955 parent
->AddChild(this);
960 wxTopLevelWindowMac::~wxTopLevelWindowMac()
965 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
967 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
970 if ( m_macEventHandler
)
972 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
973 m_macEventHandler
= NULL
;
976 wxRemoveMacWindowAssociation( this ) ;
978 if ( wxModelessWindows
.Find(this) )
979 wxModelessWindows
.DeleteObject(this);
981 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
983 m_macFullScreenData
= NULL
;
987 // ----------------------------------------------------------------------------
988 // wxTopLevelWindowMac maximize/minimize
989 // ----------------------------------------------------------------------------
991 void wxTopLevelWindowMac::Maximize(bool maximize
)
993 // TODO: check if this is still necessary
995 wxMacPortStateHelper
help( (GrafPtr
)GetWindowPort( (WindowRef
)m_macWindow
) ) ;
996 wxMacWindowClipper
clip( this );
999 if ( !IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) )
1003 GetWindowBounds((WindowRef
)m_macWindow
, kWindowGlobalPortRgn
, &rect
);
1004 SetWindowIdealUserState((WindowRef
)m_macWindow
, &rect
);
1005 SetWindowUserState((WindowRef
)m_macWindow
, &rect
);
1008 ZoomWindow( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, false ) ;
1011 bool wxTopLevelWindowMac::IsMaximized() const
1013 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
1016 void wxTopLevelWindowMac::Iconize(bool iconize
)
1018 if ( IsWindowCollapsable( (WindowRef
)m_macWindow
) )
1019 CollapseWindow( (WindowRef
)m_macWindow
, iconize
) ;
1022 bool wxTopLevelWindowMac::IsIconized() const
1024 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1027 void wxTopLevelWindowMac::Restore()
1029 if ( IsMaximized() )
1031 else if ( IsIconized() )
1035 // ----------------------------------------------------------------------------
1036 // wxTopLevelWindowMac misc
1037 // ----------------------------------------------------------------------------
1039 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1041 return wxPoint(0, 0) ;
1044 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
1047 wxTopLevelWindowBase::SetIcon(icon
);
1050 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1052 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1054 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1056 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1060 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1062 if ( m_macEventHandler
!= NULL
)
1064 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1067 InstallWindowEventHandler(
1068 MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1069 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1072 void wxTopLevelWindowMac::MacCreateRealWindow(
1073 const wxString
& title
,
1077 const wxString
& name
)
1079 OSStatus err
= noErr
;
1081 m_windowStyle
= style
;
1089 wxRect display
= wxGetClientDisplayRect() ;
1091 if ( x
== wxDefaultPosition
.x
)
1094 if ( y
== wxDefaultPosition
.y
)
1097 int w
= WidthDefault(size
.x
);
1098 int h
= HeightDefault(size
.y
);
1100 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1102 // translate the window attributes in the appropriate window class and attributes
1103 WindowClass wclass
= 0;
1104 WindowAttributes attr
= kWindowNoAttributes
;
1105 WindowGroupRef group
= NULL
;
1107 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1110 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1111 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1112 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1115 wclass
= kFloatingWindowClass
;
1117 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1118 attr
|= kWindowSideTitlebarAttribute
;
1122 wclass
= kPlainWindowClass
;
1125 else if ( HasFlag( wxCAPTION
) )
1127 wclass
= kDocumentWindowClass
;
1128 attr
|= kWindowInWindowMenuAttribute
;
1130 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1131 else if ( HasFlag( wxFRAME_DRAWER
) )
1133 wclass
= kDrawerWindowClass
;
1134 // we must force compositing on a drawer
1135 m_macUsesCompositing
= true ;
1137 #endif //10.2 and up
1140 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1141 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1143 wclass
= kDocumentWindowClass
;
1147 wclass
= kPlainWindowClass
;
1151 if ( wclass
!= kPlainWindowClass
)
1153 if ( HasFlag( wxMINIMIZE_BOX
) )
1154 attr
|= kWindowCollapseBoxAttribute
;
1156 if ( HasFlag( wxMAXIMIZE_BOX
) )
1157 attr
|= kWindowFullZoomAttribute
;
1159 if ( HasFlag( wxRESIZE_BORDER
) )
1160 attr
|= kWindowResizableAttribute
;
1162 if ( HasFlag( wxCLOSE_BOX
) )
1163 attr
|= kWindowCloseBoxAttribute
;
1166 // turn on live resizing (OS X only)
1167 if (UMAGetSystemVersion() >= 0x1000)
1168 attr
|= kWindowLiveResizeAttribute
;
1170 if ( HasFlag(wxSTAY_ON_TOP
) )
1171 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1173 #if TARGET_API_MAC_OSX
1174 if ( m_macUsesCompositing
)
1175 attr
|= kWindowCompositingAttribute
;
1178 if ( HasFlag(wxFRAME_SHAPED
) )
1180 WindowDefSpec customWindowDefSpec
;
1181 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1182 customWindowDefSpec
.u
.defProc
= NewWindowDefUPP(wxShapedMacWindowDef
);
1184 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1185 attr
, &theBoundsRect
,
1186 (WindowRef
*) &m_macWindow
);
1190 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1193 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1194 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1196 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1198 // the create commands are only for content rect,
1199 // so we have to set the size again as structure bounds
1200 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1202 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1203 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1204 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1206 #if TARGET_API_MAC_OSX
1207 if ( m_macUsesCompositing
)
1209 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1210 // the content view, so we have to retrieve it explicitly
1211 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1212 m_peer
->GetControlRefAddr() ) ;
1213 if ( !m_peer
->Ok() )
1215 // compatibility mode fallback
1216 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1221 ::CreateRootControl( (WindowRef
)m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1224 // the root control level handler
1225 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1227 // Causes the inner part of the window not to be metal
1228 // if the style is used before window creation.
1229 #if 0 // TARGET_API_MAC_OSX
1230 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1232 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1233 MacSetMetalAppearance( true ) ;
1237 // the frame window event handler
1238 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1239 MacInstallTopLevelWindowEventHandler() ;
1241 DoSetWindowVariant( m_windowVariant
) ;
1245 if ( HasFlag(wxFRAME_SHAPED
) )
1247 // default shape matches the window size
1248 wxRegion
rgn( 0, 0, w
, h
);
1252 wxWindowCreateEvent
event(this);
1253 GetEventHandler()->ProcessEvent(event
);
1256 void wxTopLevelWindowMac::ClearBackground()
1258 wxWindow::ClearBackground() ;
1261 // Raise the window to the top of the Z order
1262 void wxTopLevelWindowMac::Raise()
1264 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1267 // Lower the window to the bottom of the Z order
1268 void wxTopLevelWindowMac::Lower()
1270 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1273 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1275 if (s_macDeactivateWindow
)
1277 wxLogTrace(TRACE_ACTIVATE
,
1278 wxT("Doing delayed deactivation of %p"),
1279 s_macDeactivateWindow
);
1281 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1285 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1287 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1289 if (s_macDeactivateWindow
== this)
1290 s_macDeactivateWindow
= NULL
;
1292 MacDelayedDeactivation(timestamp
);
1293 MacPropagateHiliteChanged() ;
1296 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1298 wxWindow::SetLabel( title
) ;
1299 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1302 wxString
wxTopLevelWindowMac::GetTitle() const
1304 return wxWindow::GetLabel();
1307 bool wxTopLevelWindowMac::Show(bool show
)
1309 if ( !wxTopLevelWindowBase::Show(show
) )
1312 bool plainTransition
= false;
1314 #if wxUSE_SYSTEM_OPTIONS
1315 // code contributed by Ryan Wilcox December 18, 2003
1316 plainTransition
= UMAGetSystemVersion() >= 0x1000 ;
1317 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1318 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1323 if ( plainTransition
)
1324 ::ShowWindow( (WindowRef
)m_macWindow
);
1326 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1328 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1330 // because apps expect a size event to occur at this moment
1331 wxSizeEvent
event(GetSize() , m_windowId
);
1332 event
.SetEventObject(this);
1333 GetEventHandler()->ProcessEvent(event
);
1337 if ( plainTransition
)
1338 ::HideWindow( (WindowRef
)m_macWindow
);
1340 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1343 MacPropagateVisibilityChanged() ;
1348 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1352 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1354 data
= new FullScreenData() ;
1356 m_macFullScreenData
= data
;
1357 data
->m_position
= GetPosition() ;
1358 data
->m_size
= GetSize() ;
1359 data
->m_wasResizable
= MacGetWindowAttributes() & kWindowResizableAttribute
;
1361 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1364 wxRect client
= wxGetClientDisplayRect() ;
1366 int left
, top
, right
, bottom
;
1374 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1376 if ( style
& wxFULLSCREEN_NOCAPTION
)
1382 if ( style
& wxFULLSCREEN_NOBORDER
)
1389 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1394 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1399 SetSize( x
, y
, w
, h
) ;
1400 if ( data
->m_wasResizable
)
1401 MacChangeWindowAttributes( kWindowNoAttributes
, kWindowResizableAttribute
) ;
1406 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1407 if ( data
->m_wasResizable
)
1408 MacChangeWindowAttributes( kWindowResizableAttribute
, kWindowNoAttributes
) ;
1409 SetPosition( data
->m_position
) ;
1410 SetSize( data
->m_size
) ;
1413 m_macFullScreenData
= NULL
;
1419 bool wxTopLevelWindowMac::IsFullScreen() const
1421 return m_macFullScreenData
!= NULL
;
1424 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1426 if ( GetExtraStyle() == exStyle
)
1429 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1431 #if TARGET_API_MAC_OSX
1432 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1434 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1435 if ( MacGetMetalAppearance() != metal
)
1436 MacSetMetalAppearance( metal
) ;
1441 // TODO: switch to structure bounds -
1442 // we are still using coordinates of the content view
1444 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1446 Rect content
, structure
;
1448 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1449 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1451 left
= content
.left
- structure
.left
;
1452 top
= content
.top
- structure
.top
;
1453 right
= structure
.right
- content
.right
;
1454 bottom
= structure
.bottom
- content
.bottom
;
1457 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1459 m_cachedClippedRectValid
= false ;
1460 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1461 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1462 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1465 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1469 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1477 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1481 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1484 *width
= bounds
.right
- bounds
.left
;
1486 *height
= bounds
.bottom
- bounds
.top
;
1489 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1493 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1496 *width
= bounds
.right
- bounds
.left
;
1498 *height
= bounds
.bottom
- bounds
.top
;
1501 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1503 #if TARGET_API_MAC_OSX
1504 wxASSERT_MSG( m_macUsesCompositing
,
1505 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1507 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1508 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1512 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1514 #if TARGET_API_MAC_OSX
1515 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1521 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1523 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1526 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1529 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1534 void wxTopLevelWindowMac::MacPerformUpdates()
1536 #if TARGET_API_MAC_OSX
1537 if ( m_macUsesCompositing
)
1539 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1540 // for composited windows this also triggers a redraw of all
1541 // invalid views in the window
1542 if ( UMAGetSystemVersion() >= 0x1030 )
1543 HIWindowFlush((WindowRef
) m_macWindow
) ;
1547 // the only way to trigger the redrawing on earlier systems is to call
1550 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1551 UInt32 currentEventClass
= 0 ;
1552 UInt32 currentEventKind
= 0 ;
1553 if ( currentEvent
!= NULL
)
1555 currentEventClass
= ::GetEventClass( currentEvent
) ;
1556 currentEventKind
= ::GetEventKind( currentEvent
) ;
1559 if ( currentEventClass
!= kEventClassMenu
)
1561 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1563 OSStatus status
= noErr
;
1564 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1571 BeginUpdate( (WindowRef
) m_macWindow
) ;
1573 RgnHandle updateRgn
= NewRgn();
1576 GetPortVisibleRegion( GetWindowPort( (WindowRef
)m_macWindow
), updateRgn
);
1577 UpdateControls( (WindowRef
)m_macWindow
, updateRgn
) ;
1579 // if ( !EmptyRgn( updateRgn ) )
1580 // MacDoRedraw( updateRgn , 0 , true) ;
1582 DisposeRgn( updateRgn
);
1585 EndUpdate( (WindowRef
)m_macWindow
) ;
1586 QDFlushPortBuffer( GetWindowPort( (WindowRef
)m_macWindow
) , NULL
) ;
1590 // Attracts the users attention to this window if the application is
1591 // inactive (should be called when a background event occurs)
1593 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1596 DisposePtr( (Ptr
)ptr
) ;
1599 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1601 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1602 static wxMacNMUPP
nmupp( wxMacNMResponse
);
1604 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1605 notificationRequest
->qType
= nmType
;
1606 notificationRequest
->nmMark
= 1 ;
1607 notificationRequest
->nmIcon
= 0 ;
1608 notificationRequest
->nmSound
= 0 ;
1609 notificationRequest
->nmStr
= NULL
;
1610 notificationRequest
->nmResp
= nmupp
;
1612 verify_noerr( NMInstall( notificationRequest
) ) ;
1615 // ---------------------------------------------------------------------------
1616 // Shape implementation
1617 // ---------------------------------------------------------------------------
1620 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1622 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1623 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1625 // The empty region signifies that the shape
1626 // should be removed from the window.
1627 if ( region
.IsEmpty() )
1629 wxSize sz
= GetClientSize();
1630 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1631 if ( rgn
.IsEmpty() )
1634 return SetShape(rgn
);
1637 // Make a copy of the region
1638 RgnHandle shapeRegion
= NewRgn();
1639 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1641 // Dispose of any shape region we may already have
1642 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1646 // Save the region so we can use it later
1647 SetWRefCon((WindowRef
)MacGetWindowRef(), (SInt32
)shapeRegion
);
1649 // inform the window manager that the window has changed shape
1650 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1655 // ---------------------------------------------------------------------------
1656 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1657 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1658 // ---------------------------------------------------------------------------
1660 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1662 GetWindowPortBounds(window
, inRect
);
1663 Point pt
= { inRect
->left
, inRect
->top
};
1665 QDLocalToGlobalPoint( GetWindowPort(window
), &pt
) ;
1667 inRect
->left
= pt
.h
;
1668 inRect
->bottom
+= pt
.v
;
1669 inRect
->right
+= pt
.h
;
1672 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1674 /*------------------------------------------------------
1675 Define which options your custom window supports.
1676 --------------------------------------------------------*/
1677 //just enable everything for our demo
1678 *(OptionBits
*)param
=
1681 //kWindowCanCollapse |
1682 //kWindowCanGetWindowRegion |
1683 //kWindowHasTitleBar |
1684 //kWindowSupportsDragHilite |
1685 kWindowCanDrawInCurrentPort
|
1686 //kWindowCanMeasureTitle |
1687 kWindowWantsDisposeAtProcessDeath
|
1688 kWindowSupportsGetGrowImageRegion
|
1689 kWindowDefSupportsColorGrafPort
;
1694 // The content region is left as a rectangle matching the window size, this is
1695 // so the origin in the paint event, and etc. still matches what the
1696 // programmer expects.
1697 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1700 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1704 wxShapedMacWindowGetPos( window
, &r
) ;
1705 RectRgn( rgn
, &r
) ;
1709 // The structure region is set to the shape given to the SetShape method.
1710 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1712 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1718 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1719 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1720 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1721 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1725 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1727 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1732 switch (rgnRec
->regionCode
)
1734 case kWindowStructureRgn
:
1735 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1738 case kWindowContentRgn
:
1739 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1743 SetEmptyRgn(rgnRec
->winRgn
);
1750 // Determine the region of the window which was hit
1752 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1755 static RgnHandle tempRgn
= NULL
;
1757 if (tempRgn
== NULL
)
1760 // get the point clicked
1761 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1763 // Mac OS 8.5 or later
1764 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1765 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1768 // no significant area was hit
1772 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1776 case kWindowMsgHitTest
:
1777 return wxShapedMacWindowHitTest(window
, param
);
1779 case kWindowMsgGetFeatures
:
1780 return wxShapedMacWindowGetFeatures(window
, param
);
1782 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1783 case kWindowMsgGetRegion
:
1784 return wxShapedMacWindowGetRegion(window
, param
);