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"
41 #include "wx/tooltip.h"
44 #if wxUSE_SYSTEM_OPTIONS
45 #include "wx/sysopt.h"
49 #include <ToolUtils.h>
53 #include "wx/mac/private.h"
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 // trace mask for activation tracing messages
60 static const wxChar
*TRACE_ACTIVATE
= _T("activation");
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 // list of all frames and modeless dialogs
67 wxWindowList wxModelessWindows
;
69 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
71 // ============================================================================
72 // wxTopLevelWindowMac implementation
73 // ============================================================================
75 BEGIN_EVENT_TABLE(wxTopLevelWindowMac
, wxTopLevelWindowBase
)
79 // ---------------------------------------------------------------------------
81 // ---------------------------------------------------------------------------
83 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
85 static const EventTypeSpec eventList
[] =
87 // TODO: remove control related event like key and mouse (except for WindowLeave events)
89 { kEventClassKeyboard
, kEventRawKeyDown
} ,
90 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
91 { kEventClassKeyboard
, kEventRawKeyUp
} ,
92 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
94 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
95 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
97 { kEventClassWindow
, kEventWindowShown
} ,
98 { kEventClassWindow
, kEventWindowActivated
} ,
99 { kEventClassWindow
, kEventWindowDeactivated
} ,
100 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
101 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
102 { kEventClassWindow
, kEventWindowClose
} ,
104 // we have to catch these events on the toplevel window level,
105 // as controls don't get the raw mouse events anymore
107 { kEventClassMouse
, kEventMouseDown
} ,
108 { kEventClassMouse
, kEventMouseUp
} ,
109 { kEventClassMouse
, kEventMouseWheelMoved
} ,
110 { kEventClassMouse
, kEventMouseMoved
} ,
111 { kEventClassMouse
, kEventMouseDragged
} ,
114 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
116 OSStatus result
= eventNotHandledErr
;
117 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
118 // FindFocus does not return the actual focus window, but the enclosing window
119 wxWindow
* focus
= wxWindow::DoFindFocus();
121 focus
= (wxTopLevelWindowMac
*) data
;
123 unsigned char charCode
;
131 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
134 UInt32 dataSize
= 0 ;
135 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
138 int numChars
= dataSize
/ sizeof( UniChar
) + 1;
140 UniChar
* charBuf
= buf
;
142 if ( numChars
* 2 > 4 )
143 charBuf
= new UniChar
[ numChars
] ;
144 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
145 charBuf
[ numChars
- 1 ] = 0;
147 #if SIZEOF_WCHAR_T == 2
148 uniChar
= charBuf
[0] ;
150 wxMBConvUTF16 converter
;
151 converter
.MB2WC( uniChar
, (const char*)charBuf
, 2 ) ;
154 if ( numChars
* 2 > 4 )
159 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
160 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
161 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
162 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
164 UInt32 message
= (keyCode
<< 8) + charCode
;
165 switch ( GetEventKind( event
) )
167 case kEventRawKeyRepeat
:
168 case kEventRawKeyDown
:
170 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
171 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
172 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
173 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
174 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
178 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
182 case kEventRawKeyUp
:
183 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
184 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
190 case kEventRawKeyModifiersChanged
:
192 wxKeyEvent
event(wxEVT_KEY_DOWN
);
194 event
.m_shiftDown
= modifiers
& shiftKey
;
195 event
.m_controlDown
= modifiers
& controlKey
;
196 event
.m_altDown
= modifiers
& optionKey
;
197 event
.m_metaDown
= modifiers
& cmdKey
;
202 event
.m_uniChar
= uniChar
[0] ;
205 event
.SetTimestamp(when
);
206 event
.SetEventObject(focus
);
208 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
210 event
.m_keyCode
= WXK_CONTROL
;
211 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
212 focus
->GetEventHandler()->ProcessEvent( event
) ;
214 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
216 event
.m_keyCode
= WXK_SHIFT
;
217 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
218 focus
->GetEventHandler()->ProcessEvent( event
) ;
220 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
222 event
.m_keyCode
= WXK_ALT
;
223 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
224 focus
->GetEventHandler()->ProcessEvent( event
) ;
226 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
228 event
.m_keyCode
= WXK_COMMAND
;
229 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
230 focus
->GetEventHandler()->ProcessEvent( event
) ;
233 wxApp::s_lastModifiers
= modifiers
;
244 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
245 // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
248 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
250 wxWindow
* g_MacLastWindow
= NULL
;
252 static EventMouseButton lastButton
= 0 ;
254 static void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
256 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
257 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
259 // this parameter are not given for all events
260 EventMouseButton button
= 0 ;
261 UInt32 clickCount
= 0 ;
262 cEvent
.GetParameter
<EventMouseButton
>( kEventParamMouseButton
, typeMouseButton
, &button
) ;
263 cEvent
.GetParameter
<UInt32
>( kEventParamClickCount
, typeUInt32
, &clickCount
) ;
265 wxevent
.m_x
= screenMouseLocation
.h
;
266 wxevent
.m_y
= screenMouseLocation
.v
;
267 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
268 wxevent
.m_controlDown
= modifiers
& controlKey
;
269 wxevent
.m_altDown
= modifiers
& optionKey
;
270 wxevent
.m_metaDown
= modifiers
& cmdKey
;
271 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
273 // a control click is interpreted as a right click
274 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
275 button
= kEventMouseButtonSecondary
;
277 // otherwise we report double clicks by connecting a left click with a ctrl-left click
278 if ( clickCount
> 1 && button
!= lastButton
)
281 // we must make sure that our synthetic 'right' button corresponds in
282 // mouse down, moved and mouse up, and does not deliver a right down and left up
284 if ( cEvent
.GetKind() == kEventMouseDown
)
285 lastButton
= button
;
289 else if ( lastButton
)
290 button
= lastButton
;
292 // determine the correct down state, wx does not want a 'down' for a mouseUp event,
293 // while mac delivers this button
294 if ( button
!= 0 && cEvent
.GetKind() != kEventMouseUp
)
298 case kEventMouseButtonPrimary
:
299 wxevent
.m_leftDown
= true ;
302 case kEventMouseButtonSecondary
:
303 wxevent
.m_rightDown
= true ;
306 case kEventMouseButtonTertiary
:
307 wxevent
.m_middleDown
= true ;
315 // translate into wx types
316 switch ( cEvent
.GetKind() )
318 case kEventMouseDown
:
321 case kEventMouseButtonPrimary
:
322 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
325 case kEventMouseButtonSecondary
:
326 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
329 case kEventMouseButtonTertiary
:
330 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
341 case kEventMouseButtonPrimary
:
342 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
345 case kEventMouseButtonSecondary
:
346 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
349 case kEventMouseButtonTertiary
:
350 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
358 case kEventMouseWheelMoved
:
360 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
362 // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
363 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeLongInteger
) ;
365 wxevent
.m_wheelRotation
= delta
;
366 wxevent
.m_wheelDelta
= 1;
367 wxevent
.m_linesPerAction
= 1;
372 wxevent
.SetEventType( wxEVT_MOTION
) ;
377 ControlRef
wxMacFindSubControl( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, ControlRef superControl
, ControlPartCode
*outPart
)
381 UInt16 childrenCount
= 0 ;
382 ControlHandle sibling
;
384 OSStatus err
= CountSubControls( superControl
, &childrenCount
) ;
385 if ( err
== errControlIsNotEmbedder
)
388 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
390 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
392 err
= GetIndexedSubControl( superControl
, i
, & sibling
) ;
393 if ( err
== errControlIsNotEmbedder
)
396 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
397 if ( IsControlVisible( sibling
) )
399 UMAGetControlBoundsInWindowCoords( sibling
, &r
) ;
400 if ( MacPtInRect( location
, &r
) )
402 ControlHandle child
= wxMacFindSubControl( toplevelWindow
, location
, sibling
, outPart
) ;
409 Point testLocation
= location
;
411 if ( toplevelWindow
&& toplevelWindow
->MacUsesCompositing() )
413 testLocation
.h
-= r
.left
;
414 testLocation
.v
-= r
.top
;
417 *outPart
= TestControl( sibling
, testLocation
) ;
429 ControlRef
wxMacFindControlUnderMouse( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, WindowRef window
, ControlPartCode
*outPart
)
431 #if TARGET_API_MAC_OSX
432 if ( UMAGetSystemVersion() >= 0x1030 && ( toplevelWindow
== 0 || toplevelWindow
->MacUsesCompositing() ) )
433 return FindControlUnderMouse( location
, window
, outPart
) ;
436 ControlRef rootControl
= NULL
;
437 verify_noerr( GetRootControl( window
, &rootControl
) ) ;
439 return wxMacFindSubControl( toplevelWindow
, location
, rootControl
, outPart
) ;
442 #define NEW_CAPTURE_HANDLING 1
444 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
446 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
448 OSStatus result
= eventNotHandledErr
;
450 wxMacCarbonEvent
cEvent( event
) ;
452 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
453 Point windowMouseLocation
= screenMouseLocation
;
455 WindowRef window
= NULL
;
456 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
458 wxWindow
* currentMouseWindow
= NULL
;
459 ControlRef control
= NULL
;
461 #if NEW_CAPTURE_HANDLING
462 if ( wxApp::s_captureWindow
)
464 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
465 windowPart
= inContent
;
471 QDGlobalToLocalPoint( UMAGetWindowPort(window
) , &windowMouseLocation
) ;
473 if ( wxApp::s_captureWindow
474 #if !NEW_CAPTURE_HANDLING
475 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
479 currentMouseWindow
= wxApp::s_captureWindow
;
481 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
483 ControlPartCode part
;
484 control
= wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &part
) ;
485 // if there is no control below the mouse position, send the event to the toplevel window itself
488 currentMouseWindow
= (wxWindow
*) data
;
492 currentMouseWindow
= wxFindControlFromMacControl( control
) ;
493 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
496 // for wxToolBar to function we have to send certaint events to it
497 // instead of its children (wxToolBarTools)
499 GetSuperControl(control
, &parent
);
500 wxWindow
*wxParent
= wxFindControlFromMacControl( parent
) ;
501 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
502 currentMouseWindow
= wxParent
;
507 // disabled windows must not get any input messages
508 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
509 currentMouseWindow
= NULL
;
513 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
514 SetupMouseEvent( wxevent
, cEvent
) ;
516 // handle all enter / leave events
518 if ( currentMouseWindow
!= g_MacLastWindow
)
520 if ( g_MacLastWindow
)
522 wxMouseEvent
eventleave(wxevent
);
523 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
524 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
525 eventleave
.SetEventObject( g_MacLastWindow
) ;
526 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
529 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
532 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
535 if ( currentMouseWindow
)
537 wxMouseEvent
evententer(wxevent
);
538 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
539 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
540 evententer
.SetEventObject( currentMouseWindow
) ;
541 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
544 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
547 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
550 g_MacLastWindow
= currentMouseWindow
;
553 if ( windowPart
== inMenuBar
)
555 // special case menu bar, as we are having a low-level runloop we must do it ourselves
556 if ( cEvent
.GetKind() == kEventMouseDown
)
558 ::MenuSelect( screenMouseLocation
) ;
562 else if ( currentMouseWindow
)
564 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
566 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
568 wxevent
.SetEventObject( currentMouseWindow
) ;
569 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
571 // make tooltips current
574 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
575 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
578 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
580 if ((currentMouseWindowParent
!= NULL
) &&
581 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
582 currentMouseWindow
= NULL
;
588 // if the user code did _not_ handle the event, then perform the
589 // default processing
590 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
592 // ... that is set focus to this window
593 if (currentMouseWindow
->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
594 currentMouseWindow
->SetFocus();
597 ControlPartCode dummyPart
;
598 // if built-in find control is finding the wrong control (ie static box instead of overlaid
599 // button, we cannot let the standard handler do its job, but must handle manually
601 if ( ( cEvent
.GetKind() == kEventMouseDown
)
604 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
605 wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &dummyPart
) )
609 if ( currentMouseWindow
->MacIsReallyEnabled() )
611 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
612 Point clickLocation
= windowMouseLocation
;
614 if ( toplevelWindow
->MacUsesCompositing() )
615 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
617 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
618 modifiers
, (ControlActionUPP
) -1 ) ;
620 if ((currentMouseWindowParent
!= NULL
) &&
621 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
623 currentMouseWindow
= NULL
;
631 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
633 wxApp::s_captureWindow
= NULL
;
639 wxWindow
* cursorTarget
= currentMouseWindow
;
640 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
642 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
644 cursorTarget
= cursorTarget
->GetParent() ;
646 cursorPoint
+= cursorTarget
->GetPosition();
650 else // currentMouseWindow == NULL
652 // don't mess with controls we don't know about
653 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
654 // so we try sending them the correct control directly
655 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
657 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
658 Point clickLocation
= windowMouseLocation
;
659 #if TARGET_API_MAC_OSX
660 if ( toplevelWindow
->MacUsesCompositing() )
663 hiPoint
.x
= clickLocation
.h
;
664 hiPoint
.y
= clickLocation
.v
;
665 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
666 clickLocation
.h
= (int)hiPoint
.x
;
667 clickLocation
.v
= (int)hiPoint
.y
;
669 #endif // TARGET_API_MAC_OSX
671 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
679 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
681 OSStatus result
= eventNotHandledErr
;
683 wxMacCarbonEvent
cEvent( event
) ;
685 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
686 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
688 switch ( GetEventKind( event
) )
690 case kEventWindowActivated
:
692 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
693 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
694 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
695 wxevent
.SetEventObject(toplevelWindow
);
696 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
697 // we still sending an eventNotHandledErr in order to allow for default processing
701 case kEventWindowDeactivated
:
703 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
704 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
705 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
706 wxevent
.SetEventObject(toplevelWindow
);
707 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
708 // we still sending an eventNotHandledErr in order to allow for default processing
712 case kEventWindowShown
:
713 toplevelWindow
->Refresh() ;
717 case kEventWindowClose
:
718 toplevelWindow
->Close() ;
722 case kEventWindowBoundsChanged
:
724 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
725 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
726 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
727 if ( attributes
& kWindowBoundsChangeSizeChanged
)
729 // according to the other ports we handle this within the OS level
730 // resize event, not within a wxSizeEvent
731 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
734 frame
->PositionBars();
737 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
738 event
.SetEventObject( toplevelWindow
) ;
740 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
741 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
744 if ( attributes
& kWindowBoundsChangeOriginChanged
)
746 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
747 event
.SetEventObject( toplevelWindow
) ;
748 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
755 case kEventWindowBoundsChanging
:
757 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
758 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
760 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
762 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
763 int left
, top
, right
, bottom
;
764 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
769 newRect
.right
- newRect
.left
+ left
+ right
,
770 newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
772 // this is a EVT_SIZING not a EVT_SIZE type !
773 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
774 wxevent
.SetEventObject( toplevelWindow
) ;
776 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
777 adjustR
= wxevent
.GetRect() ;
779 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
780 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
781 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
782 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
783 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
784 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
785 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
786 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
787 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
788 if ( !EqualRect( &newRect
, &adjustedRect
) )
789 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
790 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
804 // mix this in from window.cpp
805 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
807 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
809 OSStatus result
= eventNotHandledErr
;
811 switch ( GetEventClass( event
) )
813 case kEventClassTextInput
:
814 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
817 case kEventClassKeyboard
:
818 result
= KeyboardEventHandler( handler
, event
, data
) ;
821 case kEventClassWindow
:
822 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
825 case kEventClassMouse
:
826 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
836 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
838 // ---------------------------------------------------------------------------
839 // wxWindowMac utility functions
840 // ---------------------------------------------------------------------------
842 // Find an item given the Macintosh Window Reference
844 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
846 static MacWindowMap wxWinMacWindowList
;
848 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
850 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
852 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
855 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
856 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
858 // adding NULL WindowRef is (first) surely a result of an error and
860 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
862 wxWinMacWindowList
[inWindowRef
] = win
;
865 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
866 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
868 MacWindowMap::iterator it
;
869 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
871 if ( it
->second
== win
)
873 wxWinMacWindowList
.erase(it
);
879 // ----------------------------------------------------------------------------
880 // wxTopLevelWindowMac creation
881 // ----------------------------------------------------------------------------
883 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
889 bool m_wasResizable
;
893 void wxTopLevelWindowMac::Init()
896 m_maximizeOnShow
= false;
899 #if TARGET_API_MAC_OSX
900 m_macUsesCompositing
= ( UMAGetSystemVersion() >= 0x1030 );
902 m_macUsesCompositing
= false;
905 m_macEventHandler
= NULL
;
906 m_macFullScreenData
= NULL
;
909 class wxMacDeferredWindowDeleter
: public wxObject
912 wxMacDeferredWindowDeleter( WindowRef windowRef
)
914 m_macWindow
= windowRef
;
917 virtual ~wxMacDeferredWindowDeleter()
919 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
923 WindowRef m_macWindow
;
926 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
928 const wxString
& title
,
932 const wxString
& name
)
937 m_windowStyle
= style
;
941 m_windowId
= id
== -1 ? NewControlId() : id
;
942 wxWindow::SetLabel( title
) ;
944 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
946 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
948 if (GetExtraStyle() & wxFRAME_EX_METAL
)
949 MacSetMetalAppearance(true);
951 wxTopLevelWindows
.Append(this);
954 parent
->AddChild(this);
959 wxTopLevelWindowMac::~wxTopLevelWindowMac()
964 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
966 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
969 if ( m_macEventHandler
)
971 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
972 m_macEventHandler
= NULL
;
975 wxRemoveMacWindowAssociation( this ) ;
977 if ( wxModelessWindows
.Find(this) )
978 wxModelessWindows
.DeleteObject(this);
980 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
982 m_macFullScreenData
= NULL
;
986 // ----------------------------------------------------------------------------
987 // wxTopLevelWindowMac maximize/minimize
988 // ----------------------------------------------------------------------------
990 void wxTopLevelWindowMac::Maximize(bool maximize
)
992 // TODO: check if this is still necessary
994 wxMacPortStateHelper
help( (GrafPtr
)GetWindowPort( (WindowRef
)m_macWindow
) ) ;
995 wxMacWindowClipper
clip( this );
998 if ( !IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) )
1002 GetWindowBounds((WindowRef
)m_macWindow
, kWindowGlobalPortRgn
, &rect
);
1003 SetWindowIdealUserState((WindowRef
)m_macWindow
, &rect
);
1004 SetWindowUserState((WindowRef
)m_macWindow
, &rect
);
1006 ZoomWindow( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, false ) ;
1008 Point idealSize
= { 0 , 0 } ;
1012 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
1013 idealSize
.h
= rect
.right
- rect
.left
;
1014 idealSize
.v
= rect
.bottom
- rect
.top
;
1016 ZoomWindowIdeal( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
1020 bool wxTopLevelWindowMac::IsMaximized() const
1022 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
1025 void wxTopLevelWindowMac::Iconize(bool iconize
)
1027 if ( IsWindowCollapsable( (WindowRef
)m_macWindow
) )
1028 CollapseWindow( (WindowRef
)m_macWindow
, iconize
) ;
1031 bool wxTopLevelWindowMac::IsIconized() const
1033 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1036 void wxTopLevelWindowMac::Restore()
1038 if ( IsMaximized() )
1040 else if ( IsIconized() )
1044 // ----------------------------------------------------------------------------
1045 // wxTopLevelWindowMac misc
1046 // ----------------------------------------------------------------------------
1048 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1050 return wxPoint(0, 0) ;
1053 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
1056 wxTopLevelWindowBase::SetIcon(icon
);
1059 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1061 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1063 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1065 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1069 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1071 if ( m_macEventHandler
!= NULL
)
1073 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1076 InstallWindowEventHandler(
1077 MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1078 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1081 void wxTopLevelWindowMac::MacCreateRealWindow(
1082 const wxString
& title
,
1086 const wxString
& name
)
1088 OSStatus err
= noErr
;
1090 m_windowStyle
= style
;
1098 wxRect display
= wxGetClientDisplayRect() ;
1100 if ( x
== wxDefaultPosition
.x
)
1103 if ( y
== wxDefaultPosition
.y
)
1106 int w
= WidthDefault(size
.x
);
1107 int h
= HeightDefault(size
.y
);
1109 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1111 // translate the window attributes in the appropriate window class and attributes
1112 WindowClass wclass
= 0;
1113 WindowAttributes attr
= kWindowNoAttributes
;
1114 WindowGroupRef group
= NULL
;
1116 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1119 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1120 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1121 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1124 wclass
= kFloatingWindowClass
;
1126 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1127 attr
|= kWindowSideTitlebarAttribute
;
1131 wclass
= kPlainWindowClass
;
1134 else if ( HasFlag( wxCAPTION
) )
1136 wclass
= kDocumentWindowClass
;
1137 attr
|= kWindowInWindowMenuAttribute
;
1139 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1140 else if ( HasFlag( wxFRAME_DRAWER
) )
1142 wclass
= kDrawerWindowClass
;
1143 // we must force compositing on a drawer
1144 m_macUsesCompositing
= true ;
1146 #endif //10.2 and up
1149 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1150 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1152 wclass
= kDocumentWindowClass
;
1156 wclass
= kPlainWindowClass
;
1160 if ( wclass
!= kPlainWindowClass
)
1162 if ( HasFlag( wxMINIMIZE_BOX
) )
1163 attr
|= kWindowCollapseBoxAttribute
;
1165 if ( HasFlag( wxMAXIMIZE_BOX
) )
1166 attr
|= kWindowFullZoomAttribute
;
1168 if ( HasFlag( wxRESIZE_BORDER
) )
1169 attr
|= kWindowResizableAttribute
;
1171 if ( HasFlag( wxCLOSE_BOX
) )
1172 attr
|= kWindowCloseBoxAttribute
;
1175 // turn on live resizing (OS X only)
1176 if (UMAGetSystemVersion() >= 0x1000)
1177 attr
|= kWindowLiveResizeAttribute
;
1179 if ( HasFlag(wxSTAY_ON_TOP
) )
1180 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1182 #if TARGET_API_MAC_OSX
1183 if ( m_macUsesCompositing
)
1184 attr
|= kWindowCompositingAttribute
;
1187 if ( HasFlag(wxFRAME_SHAPED
) )
1189 WindowDefSpec customWindowDefSpec
;
1190 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1191 customWindowDefSpec
.u
.defProc
= NewWindowDefUPP(wxShapedMacWindowDef
);
1193 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1194 attr
, &theBoundsRect
,
1195 (WindowRef
*) &m_macWindow
);
1199 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1202 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1203 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1205 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1207 // the create commands are only for content rect,
1208 // so we have to set the size again as structure bounds
1209 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1211 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1212 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1213 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1215 #if TARGET_API_MAC_OSX
1216 if ( m_macUsesCompositing
)
1218 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1219 // the content view, so we have to retrieve it explicitly
1220 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1221 m_peer
->GetControlRefAddr() ) ;
1222 if ( !m_peer
->Ok() )
1224 // compatibility mode fallback
1225 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1230 ::CreateRootControl( (WindowRef
)m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1233 // the root control level handler
1234 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1236 // Causes the inner part of the window not to be metal
1237 // if the style is used before window creation.
1238 #if 0 // TARGET_API_MAC_OSX
1239 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1241 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1242 MacSetMetalAppearance( true ) ;
1246 // the frame window event handler
1247 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1248 MacInstallTopLevelWindowEventHandler() ;
1250 DoSetWindowVariant( m_windowVariant
) ;
1254 if ( HasFlag(wxFRAME_SHAPED
) )
1256 // default shape matches the window size
1257 wxRegion
rgn( 0, 0, w
, h
);
1261 wxWindowCreateEvent
event(this);
1262 GetEventHandler()->ProcessEvent(event
);
1265 void wxTopLevelWindowMac::ClearBackground()
1267 wxWindow::ClearBackground() ;
1270 // Raise the window to the top of the Z order
1271 void wxTopLevelWindowMac::Raise()
1273 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1276 // Lower the window to the bottom of the Z order
1277 void wxTopLevelWindowMac::Lower()
1279 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1282 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1284 if (s_macDeactivateWindow
)
1286 wxLogTrace(TRACE_ACTIVATE
,
1287 wxT("Doing delayed deactivation of %p"),
1288 s_macDeactivateWindow
);
1290 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1294 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1296 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1298 if (s_macDeactivateWindow
== this)
1299 s_macDeactivateWindow
= NULL
;
1301 MacDelayedDeactivation(timestamp
);
1302 MacPropagateHiliteChanged() ;
1305 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1307 wxWindow::SetLabel( title
) ;
1308 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1311 wxString
wxTopLevelWindowMac::GetTitle() const
1313 return wxWindow::GetLabel();
1316 bool wxTopLevelWindowMac::Show(bool show
)
1318 if ( !wxTopLevelWindowBase::Show(show
) )
1321 bool plainTransition
= false;
1323 #if wxUSE_SYSTEM_OPTIONS
1324 // code contributed by Ryan Wilcox December 18, 2003
1325 plainTransition
= UMAGetSystemVersion() >= 0x1000 ;
1326 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1327 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1332 if ( plainTransition
)
1333 ::ShowWindow( (WindowRef
)m_macWindow
);
1335 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1337 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1339 // because apps expect a size event to occur at this moment
1340 wxSizeEvent
event(GetSize() , m_windowId
);
1341 event
.SetEventObject(this);
1342 GetEventHandler()->ProcessEvent(event
);
1346 if ( plainTransition
)
1347 ::HideWindow( (WindowRef
)m_macWindow
);
1349 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1352 MacPropagateVisibilityChanged() ;
1357 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1361 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1363 data
= new FullScreenData() ;
1365 m_macFullScreenData
= data
;
1366 data
->m_position
= GetPosition() ;
1367 data
->m_size
= GetSize() ;
1368 data
->m_wasResizable
= MacGetWindowAttributes() & kWindowResizableAttribute
;
1370 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1373 wxRect client
= wxGetClientDisplayRect() ;
1375 int left
, top
, right
, bottom
;
1383 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1385 if ( style
& wxFULLSCREEN_NOCAPTION
)
1391 if ( style
& wxFULLSCREEN_NOBORDER
)
1398 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1403 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1408 SetSize( x
, y
, w
, h
) ;
1409 if ( data
->m_wasResizable
)
1410 MacChangeWindowAttributes( kWindowNoAttributes
, kWindowResizableAttribute
) ;
1415 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1416 if ( data
->m_wasResizable
)
1417 MacChangeWindowAttributes( kWindowResizableAttribute
, kWindowNoAttributes
) ;
1418 SetPosition( data
->m_position
) ;
1419 SetSize( data
->m_size
) ;
1422 m_macFullScreenData
= NULL
;
1428 bool wxTopLevelWindowMac::IsFullScreen() const
1430 return m_macFullScreenData
!= NULL
;
1433 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1435 if ( GetExtraStyle() == exStyle
)
1438 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1440 #if TARGET_API_MAC_OSX
1441 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1443 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1444 if ( MacGetMetalAppearance() != metal
)
1445 MacSetMetalAppearance( metal
) ;
1450 // TODO: switch to structure bounds -
1451 // we are still using coordinates of the content view
1453 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1455 Rect content
, structure
;
1457 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1458 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1460 left
= content
.left
- structure
.left
;
1461 top
= content
.top
- structure
.top
;
1462 right
= structure
.right
- content
.right
;
1463 bottom
= structure
.bottom
- content
.bottom
;
1466 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1468 m_cachedClippedRectValid
= false ;
1469 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1470 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1471 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1474 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1478 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1486 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1490 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1493 *width
= bounds
.right
- bounds
.left
;
1495 *height
= bounds
.bottom
- bounds
.top
;
1498 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1502 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1505 *width
= bounds
.right
- bounds
.left
;
1507 *height
= bounds
.bottom
- bounds
.top
;
1510 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1512 #if TARGET_API_MAC_OSX
1513 wxASSERT_MSG( m_macUsesCompositing
,
1514 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1516 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1517 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1521 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1523 #if TARGET_API_MAC_OSX
1524 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1530 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1532 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1535 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1538 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1543 void wxTopLevelWindowMac::MacPerformUpdates()
1545 #if TARGET_API_MAC_OSX
1546 if ( m_macUsesCompositing
)
1548 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1549 // for composited windows this also triggers a redraw of all
1550 // invalid views in the window
1551 if ( UMAGetSystemVersion() >= 0x1030 )
1552 HIWindowFlush((WindowRef
) m_macWindow
) ;
1556 // the only way to trigger the redrawing on earlier systems is to call
1559 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1560 UInt32 currentEventClass
= 0 ;
1561 UInt32 currentEventKind
= 0 ;
1562 if ( currentEvent
!= NULL
)
1564 currentEventClass
= ::GetEventClass( currentEvent
) ;
1565 currentEventKind
= ::GetEventKind( currentEvent
) ;
1568 if ( currentEventClass
!= kEventClassMenu
)
1570 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1572 OSStatus status
= noErr
;
1573 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1580 BeginUpdate( (WindowRef
) m_macWindow
) ;
1582 RgnHandle updateRgn
= NewRgn();
1585 GetPortVisibleRegion( GetWindowPort( (WindowRef
)m_macWindow
), updateRgn
);
1586 UpdateControls( (WindowRef
)m_macWindow
, updateRgn
) ;
1588 // if ( !EmptyRgn( updateRgn ) )
1589 // MacDoRedraw( updateRgn , 0 , true) ;
1591 DisposeRgn( updateRgn
);
1594 EndUpdate( (WindowRef
)m_macWindow
) ;
1595 QDFlushPortBuffer( GetWindowPort( (WindowRef
)m_macWindow
) , NULL
) ;
1599 // Attracts the users attention to this window if the application is
1600 // inactive (should be called when a background event occurs)
1602 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1605 DisposePtr( (Ptr
)ptr
) ;
1608 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1610 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1611 static wxMacNMUPP
nmupp( wxMacNMResponse
);
1613 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1614 notificationRequest
->qType
= nmType
;
1615 notificationRequest
->nmMark
= 1 ;
1616 notificationRequest
->nmIcon
= 0 ;
1617 notificationRequest
->nmSound
= 0 ;
1618 notificationRequest
->nmStr
= NULL
;
1619 notificationRequest
->nmResp
= nmupp
;
1621 verify_noerr( NMInstall( notificationRequest
) ) ;
1624 // ---------------------------------------------------------------------------
1625 // Shape implementation
1626 // ---------------------------------------------------------------------------
1629 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1631 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1632 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1634 // The empty region signifies that the shape
1635 // should be removed from the window.
1636 if ( region
.IsEmpty() )
1638 wxSize sz
= GetClientSize();
1639 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1640 if ( rgn
.IsEmpty() )
1643 return SetShape(rgn
);
1646 // Make a copy of the region
1647 RgnHandle shapeRegion
= NewRgn();
1648 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1650 // Dispose of any shape region we may already have
1651 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1655 // Save the region so we can use it later
1656 SetWRefCon((WindowRef
)MacGetWindowRef(), (SInt32
)shapeRegion
);
1658 // inform the window manager that the window has changed shape
1659 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1664 // ---------------------------------------------------------------------------
1665 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1666 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1667 // ---------------------------------------------------------------------------
1669 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1671 GetWindowPortBounds(window
, inRect
);
1672 Point pt
= { inRect
->left
, inRect
->top
};
1674 QDLocalToGlobalPoint( GetWindowPort(window
), &pt
) ;
1676 inRect
->left
= pt
.h
;
1677 inRect
->bottom
+= pt
.v
;
1678 inRect
->right
+= pt
.h
;
1681 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1683 /*------------------------------------------------------
1684 Define which options your custom window supports.
1685 --------------------------------------------------------*/
1686 //just enable everything for our demo
1687 *(OptionBits
*)param
=
1690 //kWindowCanCollapse |
1691 //kWindowCanGetWindowRegion |
1692 //kWindowHasTitleBar |
1693 //kWindowSupportsDragHilite |
1694 kWindowCanDrawInCurrentPort
|
1695 //kWindowCanMeasureTitle |
1696 kWindowWantsDisposeAtProcessDeath
|
1697 kWindowSupportsGetGrowImageRegion
|
1698 kWindowDefSupportsColorGrafPort
;
1703 // The content region is left as a rectangle matching the window size, this is
1704 // so the origin in the paint event, and etc. still matches what the
1705 // programmer expects.
1706 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1709 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1713 wxShapedMacWindowGetPos( window
, &r
) ;
1714 RectRgn( rgn
, &r
) ;
1718 // The structure region is set to the shape given to the SetShape method.
1719 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1721 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1727 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1728 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1729 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1730 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1734 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1736 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1741 switch (rgnRec
->regionCode
)
1743 case kWindowStructureRgn
:
1744 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1747 case kWindowContentRgn
:
1748 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1752 SetEmptyRgn(rgnRec
->winRgn
);
1759 // Determine the region of the window which was hit
1761 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1764 static RgnHandle tempRgn
= NULL
;
1766 if (tempRgn
== NULL
)
1769 // get the point clicked
1770 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1772 // Mac OS 8.5 or later
1773 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1774 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1777 // no significant area was hit
1781 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1785 case kWindowMsgHitTest
:
1786 return wxShapedMacWindowHitTest(window
, param
);
1788 case kWindowMsgGetFeatures
:
1789 return wxShapedMacWindowGetFeatures(window
, param
);
1791 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1792 case kWindowMsgGetRegion
:
1793 return wxShapedMacWindowGetRegion(window
, param
);