1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for Mac
4 // Author: Stefan Csomor
8 // Copyright: (c) 2001-2004 Stefan Csomor
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/toplevel.h"
32 #include "wx/string.h"
35 #include "wx/settings.h"
36 #include "wx/strconv.h"
37 #include "wx/control.h"
40 #include "wx/mac/uma.h"
41 #include "wx/mac/aga.h"
42 #include "wx/tooltip.h"
45 #if wxUSE_SYSTEM_OPTIONS
46 #include "wx/sysopt.h"
50 #include <ToolUtils.h>
54 #include "wx/mac/private.h"
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 // trace mask for activation tracing messages
61 static const wxChar
*TRACE_ACTIVATE
= _T("activation");
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 // list of all frames and modeless dialogs
68 wxWindowList wxModelessWindows
;
70 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
72 // ============================================================================
73 // wxTopLevelWindowMac implementation
74 // ============================================================================
76 BEGIN_EVENT_TABLE(wxTopLevelWindowMac
, wxTopLevelWindowBase
)
80 // ---------------------------------------------------------------------------
82 // ---------------------------------------------------------------------------
84 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
)
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 )
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 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
661 hiPoint
.x
= clickLocation
.h
;
662 hiPoint
.y
= clickLocation
.v
;
663 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
664 clickLocation
.h
= (int)hiPoint
.x
;
665 clickLocation
.v
= (int)hiPoint
.y
;
666 #endif // TARGET_API_MAC_OSX
668 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
676 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
678 OSStatus result
= eventNotHandledErr
;
680 wxMacCarbonEvent
cEvent( event
) ;
682 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
683 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
685 switch ( GetEventKind( event
) )
687 case kEventWindowActivated
:
689 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
690 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
691 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
692 wxevent
.SetEventObject(toplevelWindow
);
693 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
694 // we still sending an eventNotHandledErr in order to allow for default processing
698 case kEventWindowDeactivated
:
700 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
701 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
702 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
703 wxevent
.SetEventObject(toplevelWindow
);
704 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
705 // we still sending an eventNotHandledErr in order to allow for default processing
709 case kEventWindowShown
:
710 toplevelWindow
->Refresh() ;
714 case kEventWindowClose
:
715 toplevelWindow
->Close() ;
719 case kEventWindowBoundsChanged
:
721 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
722 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
723 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
724 if ( attributes
& kWindowBoundsChangeSizeChanged
)
726 // according to the other ports we handle this within the OS level
727 // resize event, not within a wxSizeEvent
728 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
731 frame
->PositionBars();
734 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
735 event
.SetEventObject( toplevelWindow
) ;
737 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
738 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
741 if ( attributes
& kWindowBoundsChangeOriginChanged
)
743 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
744 event
.SetEventObject( toplevelWindow
) ;
745 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
752 case kEventWindowBoundsChanging
:
754 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
755 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
757 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
759 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
760 int left
, top
, right
, bottom
;
761 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
766 newRect
.right
- newRect
.left
+ left
+ right
,
767 newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
769 // this is a EVT_SIZING not a EVT_SIZE type !
770 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
771 wxevent
.SetEventObject( toplevelWindow
) ;
773 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
774 adjustR
= wxevent
.GetRect() ;
776 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
777 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
778 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
779 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
780 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
781 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
782 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
783 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
784 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
785 if ( !EqualRect( &newRect
, &adjustedRect
) )
786 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
787 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
801 // mix this in from window.cpp
802 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
804 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
806 OSStatus result
= eventNotHandledErr
;
808 switch ( GetEventClass( event
) )
810 case kEventClassTextInput
:
811 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
814 case kEventClassKeyboard
:
815 result
= KeyboardEventHandler( handler
, event
, data
) ;
818 case kEventClassWindow
:
819 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
822 case kEventClassMouse
:
823 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
833 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
835 // ---------------------------------------------------------------------------
836 // wxWindowMac utility functions
837 // ---------------------------------------------------------------------------
839 // Find an item given the Macintosh Window Reference
841 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
843 static MacWindowMap wxWinMacWindowList
;
845 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
847 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
849 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
852 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
853 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
855 // adding NULL WindowRef is (first) surely a result of an error and
857 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
859 wxWinMacWindowList
[inWindowRef
] = win
;
862 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
863 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
865 MacWindowMap::iterator it
;
866 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
868 if ( it
->second
== win
)
870 wxWinMacWindowList
.erase(it
);
876 // ----------------------------------------------------------------------------
877 // wxTopLevelWindowMac creation
878 // ----------------------------------------------------------------------------
880 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
886 bool m_wasResizable
;
890 void wxTopLevelWindowMac::Init()
893 m_maximizeOnShow
= false;
896 m_macEventHandler
= NULL
;
897 m_macFullScreenData
= NULL
;
900 class wxMacDeferredWindowDeleter
: public wxObject
903 wxMacDeferredWindowDeleter( WindowRef windowRef
)
905 m_macWindow
= windowRef
;
908 virtual ~wxMacDeferredWindowDeleter()
910 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
914 WindowRef m_macWindow
;
917 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
919 const wxString
& title
,
923 const wxString
& name
)
928 m_windowStyle
= style
;
932 m_windowId
= id
== -1 ? NewControlId() : id
;
933 wxWindow::SetLabel( title
) ;
935 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
937 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
939 if (GetExtraStyle() & wxFRAME_EX_METAL
)
940 MacSetMetalAppearance(true);
942 wxTopLevelWindows
.Append(this);
945 parent
->AddChild(this);
950 wxTopLevelWindowMac::~wxTopLevelWindowMac()
955 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
957 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
960 if ( m_macEventHandler
)
962 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
963 m_macEventHandler
= NULL
;
966 wxRemoveMacWindowAssociation( this ) ;
968 if ( wxModelessWindows
.Find(this) )
969 wxModelessWindows
.DeleteObject(this);
971 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
973 m_macFullScreenData
= NULL
;
977 // ----------------------------------------------------------------------------
978 // wxTopLevelWindowMac maximize/minimize
979 // ----------------------------------------------------------------------------
981 void wxTopLevelWindowMac::Maximize(bool maximize
)
983 Point idealSize
= { 0 , 0 } ;
987 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
988 idealSize
.h
= rect
.right
- rect
.left
;
989 idealSize
.v
= rect
.bottom
- rect
.top
;
991 ZoomWindowIdeal( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
994 bool wxTopLevelWindowMac::IsMaximized() const
996 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
999 void wxTopLevelWindowMac::Iconize(bool iconize
)
1001 if ( IsWindowCollapsable( (WindowRef
)m_macWindow
) )
1002 CollapseWindow( (WindowRef
)m_macWindow
, iconize
) ;
1005 bool wxTopLevelWindowMac::IsIconized() const
1007 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1010 void wxTopLevelWindowMac::Restore()
1012 if ( IsMaximized() )
1014 else if ( IsIconized() )
1018 // ----------------------------------------------------------------------------
1019 // wxTopLevelWindowMac misc
1020 // ----------------------------------------------------------------------------
1022 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1024 return wxPoint(0, 0) ;
1027 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
1030 wxTopLevelWindowBase::SetIcon(icon
);
1033 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1035 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1037 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1039 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1043 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1045 if ( m_macEventHandler
!= NULL
)
1047 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1050 InstallWindowEventHandler(
1051 MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1052 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1055 void wxTopLevelWindowMac::MacCreateRealWindow(
1056 const wxString
& title
,
1060 const wxString
& name
)
1062 OSStatus err
= noErr
;
1064 m_windowStyle
= style
;
1072 wxRect display
= wxGetClientDisplayRect() ;
1074 if ( x
== wxDefaultPosition
.x
)
1077 if ( y
== wxDefaultPosition
.y
)
1080 int w
= WidthDefault(size
.x
);
1081 int h
= HeightDefault(size
.y
);
1083 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1085 // translate the window attributes in the appropriate window class and attributes
1086 WindowClass wclass
= 0;
1087 WindowAttributes attr
= kWindowNoAttributes
;
1088 WindowGroupRef group
= NULL
;
1090 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1093 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1094 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1095 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1098 wclass
= kFloatingWindowClass
;
1100 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1101 attr
|= kWindowSideTitlebarAttribute
;
1105 wclass
= kPlainWindowClass
;
1108 else if ( HasFlag( wxCAPTION
) )
1110 wclass
= kDocumentWindowClass
;
1111 attr
|= kWindowInWindowMenuAttribute
;
1113 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1114 else if ( HasFlag( wxFRAME_DRAWER
) )
1116 wclass
= kDrawerWindowClass
;
1118 #endif //10.2 and up
1121 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1122 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1124 wclass
= kDocumentWindowClass
;
1128 wclass
= kPlainWindowClass
;
1132 if ( wclass
!= kPlainWindowClass
)
1134 if ( HasFlag( wxMINIMIZE_BOX
) )
1135 attr
|= kWindowCollapseBoxAttribute
;
1137 if ( HasFlag( wxMAXIMIZE_BOX
) )
1138 attr
|= kWindowFullZoomAttribute
;
1140 if ( HasFlag( wxRESIZE_BORDER
) )
1141 attr
|= kWindowResizableAttribute
;
1143 if ( HasFlag( wxCLOSE_BOX
) )
1144 attr
|= kWindowCloseBoxAttribute
;
1147 // turn on live resizing (OS X only)
1148 if (UMAGetSystemVersion() >= 0x1000)
1149 attr
|= kWindowLiveResizeAttribute
;
1151 if ( HasFlag(wxSTAY_ON_TOP
) )
1152 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1154 attr
|= kWindowCompositingAttribute
;
1155 #if 0 // wxMAC_USE_CORE_GRAPHICS ; TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1156 attr
|= kWindowFrameworkScaledAttribute
;
1159 if ( HasFlag(wxFRAME_SHAPED
) )
1161 WindowDefSpec customWindowDefSpec
;
1162 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1163 customWindowDefSpec
.u
.defProc
= NewWindowDefUPP(wxShapedMacWindowDef
);
1165 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1166 attr
, &theBoundsRect
,
1167 (WindowRef
*) &m_macWindow
);
1171 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1174 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1175 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1177 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1179 // the create commands are only for content rect,
1180 // so we have to set the size again as structure bounds
1181 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1183 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1184 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1185 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1187 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1188 // the content view, so we have to retrieve it explicitly
1189 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1190 m_peer
->GetControlRefAddr() ) ;
1191 if ( !m_peer
->Ok() )
1193 // compatibility mode fallback
1194 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1197 // the root control level handler
1198 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1200 // Causes the inner part of the window not to be metal
1201 // if the style is used before window creation.
1202 #if 0 // TARGET_API_MAC_OSX
1203 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1205 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1206 MacSetMetalAppearance( true ) ;
1210 // the frame window event handler
1211 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1212 MacInstallTopLevelWindowEventHandler() ;
1214 DoSetWindowVariant( m_windowVariant
) ;
1218 if ( HasFlag(wxFRAME_SHAPED
) )
1220 // default shape matches the window size
1221 wxRegion
rgn( 0, 0, w
, h
);
1225 wxWindowCreateEvent
event(this);
1226 GetEventHandler()->ProcessEvent(event
);
1229 void wxTopLevelWindowMac::ClearBackground()
1231 wxWindow::ClearBackground() ;
1234 // Raise the window to the top of the Z order
1235 void wxTopLevelWindowMac::Raise()
1237 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1240 // Lower the window to the bottom of the Z order
1241 void wxTopLevelWindowMac::Lower()
1243 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1246 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1248 if (s_macDeactivateWindow
)
1250 wxLogTrace(TRACE_ACTIVATE
,
1251 wxT("Doing delayed deactivation of %p"),
1252 s_macDeactivateWindow
);
1254 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1258 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1260 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1262 if (s_macDeactivateWindow
== this)
1263 s_macDeactivateWindow
= NULL
;
1265 MacDelayedDeactivation(timestamp
);
1266 MacPropagateHiliteChanged() ;
1269 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1271 wxWindow::SetLabel( title
) ;
1272 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1275 wxString
wxTopLevelWindowMac::GetTitle() const
1277 return wxWindow::GetLabel();
1280 bool wxTopLevelWindowMac::Show(bool show
)
1282 if ( !wxTopLevelWindowBase::Show(show
) )
1285 bool plainTransition
= false;
1287 #if wxUSE_SYSTEM_OPTIONS
1288 // code contributed by Ryan Wilcox December 18, 2003
1289 plainTransition
= UMAGetSystemVersion() >= 0x1000 ;
1290 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1291 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1296 if ( plainTransition
)
1297 ::ShowWindow( (WindowRef
)m_macWindow
);
1299 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1301 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1303 // because apps expect a size event to occur at this moment
1304 wxSizeEvent
event(GetSize() , m_windowId
);
1305 event
.SetEventObject(this);
1306 GetEventHandler()->ProcessEvent(event
);
1310 if ( plainTransition
)
1311 ::HideWindow( (WindowRef
)m_macWindow
);
1313 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1316 MacPropagateVisibilityChanged() ;
1321 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1325 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1327 data
= new FullScreenData() ;
1329 m_macFullScreenData
= data
;
1330 data
->m_position
= GetPosition() ;
1331 data
->m_size
= GetSize() ;
1332 data
->m_wasResizable
= MacGetWindowAttributes() & kWindowResizableAttribute
;
1334 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1337 wxRect client
= wxGetClientDisplayRect() ;
1339 int left
, top
, right
, bottom
;
1347 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1349 if ( style
& wxFULLSCREEN_NOCAPTION
)
1355 if ( style
& wxFULLSCREEN_NOBORDER
)
1362 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1367 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1372 SetSize( x
, y
, w
, h
) ;
1373 if ( data
->m_wasResizable
)
1374 MacChangeWindowAttributes( kWindowNoAttributes
, kWindowResizableAttribute
) ;
1379 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1380 if ( data
->m_wasResizable
)
1381 MacChangeWindowAttributes( kWindowResizableAttribute
, kWindowNoAttributes
) ;
1382 SetPosition( data
->m_position
) ;
1383 SetSize( data
->m_size
) ;
1386 m_macFullScreenData
= NULL
;
1392 bool wxTopLevelWindowMac::IsFullScreen() const
1394 return m_macFullScreenData
!= NULL
;
1398 bool wxTopLevelWindowMac::SetTransparent(wxByte alpha
)
1400 OSStatus result
= SetWindowAlpha((WindowRef
)m_macWindow
, float(alpha
)/255.0);
1401 return result
== noErr
;
1405 bool wxTopLevelWindowMac::CanSetTransparent()
1411 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1413 if ( GetExtraStyle() == exStyle
)
1416 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1418 #if TARGET_API_MAC_OSX
1419 if ( m_macWindow
!= NULL
)
1421 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1422 if ( MacGetMetalAppearance() != metal
)
1423 MacSetMetalAppearance( metal
) ;
1428 // TODO: switch to structure bounds -
1429 // we are still using coordinates of the content view
1431 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1433 Rect content
, structure
;
1435 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1436 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1438 left
= content
.left
- structure
.left
;
1439 top
= content
.top
- structure
.top
;
1440 right
= structure
.right
- content
.right
;
1441 bottom
= structure
.bottom
- content
.bottom
;
1444 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1446 m_cachedClippedRectValid
= false ;
1447 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1448 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1449 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1452 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1456 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1464 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1468 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1471 *width
= bounds
.right
- bounds
.left
;
1473 *height
= bounds
.bottom
- bounds
.top
;
1476 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1480 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1483 *width
= bounds
.right
- bounds
.left
;
1485 *height
= bounds
.bottom
- bounds
.top
;
1488 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1490 #if TARGET_API_MAC_OSX
1491 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1492 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1496 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1498 #if TARGET_API_MAC_OSX
1499 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1505 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1507 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1510 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1513 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1518 void wxTopLevelWindowMac::MacPerformUpdates()
1520 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1521 // for composited windows this also triggers a redraw of all
1522 // invalid views in the window
1523 if ( UMAGetSystemVersion() >= 0x1030 )
1524 HIWindowFlush((WindowRef
) m_macWindow
) ;
1528 // the only way to trigger the redrawing on earlier systems is to call
1531 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1532 UInt32 currentEventClass
= 0 ;
1533 UInt32 currentEventKind
= 0 ;
1534 if ( currentEvent
!= NULL
)
1536 currentEventClass
= ::GetEventClass( currentEvent
) ;
1537 currentEventKind
= ::GetEventKind( currentEvent
) ;
1540 if ( currentEventClass
!= kEventClassMenu
)
1542 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1544 OSStatus status
= noErr
;
1545 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1550 // Attracts the users attention to this window if the application is
1551 // inactive (should be called when a background event occurs)
1553 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1556 DisposePtr( (Ptr
)ptr
) ;
1559 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1561 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1562 static wxMacNMUPP
nmupp( wxMacNMResponse
);
1564 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1565 notificationRequest
->qType
= nmType
;
1566 notificationRequest
->nmMark
= 1 ;
1567 notificationRequest
->nmIcon
= 0 ;
1568 notificationRequest
->nmSound
= 0 ;
1569 notificationRequest
->nmStr
= NULL
;
1570 notificationRequest
->nmResp
= nmupp
;
1572 verify_noerr( NMInstall( notificationRequest
) ) ;
1575 // ---------------------------------------------------------------------------
1576 // Shape implementation
1577 // ---------------------------------------------------------------------------
1580 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1582 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1583 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1585 // The empty region signifies that the shape
1586 // should be removed from the window.
1587 if ( region
.IsEmpty() )
1589 wxSize sz
= GetClientSize();
1590 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1591 if ( rgn
.IsEmpty() )
1594 return SetShape(rgn
);
1597 // Make a copy of the region
1598 RgnHandle shapeRegion
= NewRgn();
1599 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1601 // Dispose of any shape region we may already have
1602 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1606 // Save the region so we can use it later
1607 SetWRefCon((WindowRef
)MacGetWindowRef(), (SInt32
)shapeRegion
);
1609 // inform the window manager that the window has changed shape
1610 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1615 // ---------------------------------------------------------------------------
1616 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1617 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1618 // ---------------------------------------------------------------------------
1620 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1622 GetWindowPortBounds(window
, inRect
);
1623 Point pt
= { inRect
->left
, inRect
->top
};
1625 QDLocalToGlobalPoint( GetWindowPort(window
), &pt
) ;
1627 inRect
->left
= pt
.h
;
1628 inRect
->bottom
+= pt
.v
;
1629 inRect
->right
+= pt
.h
;
1632 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1634 /*------------------------------------------------------
1635 Define which options your custom window supports.
1636 --------------------------------------------------------*/
1637 //just enable everything for our demo
1638 *(OptionBits
*)param
=
1641 //kWindowCanCollapse |
1642 //kWindowCanGetWindowRegion |
1643 //kWindowHasTitleBar |
1644 //kWindowSupportsDragHilite |
1645 kWindowCanDrawInCurrentPort
|
1646 //kWindowCanMeasureTitle |
1647 kWindowWantsDisposeAtProcessDeath
|
1648 kWindowSupportsGetGrowImageRegion
|
1649 kWindowDefSupportsColorGrafPort
;
1654 // The content region is left as a rectangle matching the window size, this is
1655 // so the origin in the paint event, and etc. still matches what the
1656 // programmer expects.
1657 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1660 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1664 wxShapedMacWindowGetPos( window
, &r
) ;
1665 RectRgn( rgn
, &r
) ;
1669 // The structure region is set to the shape given to the SetShape method.
1670 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1672 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1678 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1679 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1680 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1681 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1685 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1687 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1692 switch (rgnRec
->regionCode
)
1694 case kWindowStructureRgn
:
1695 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1698 case kWindowContentRgn
:
1699 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1703 SetEmptyRgn(rgnRec
->winRgn
);
1710 // Determine the region of the window which was hit
1712 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1715 static RgnHandle tempRgn
= NULL
;
1717 if (tempRgn
== NULL
)
1720 // get the point clicked
1721 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1723 // Mac OS 8.5 or later
1724 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1725 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1728 // no significant area was hit
1732 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1736 case kWindowMsgHitTest
:
1737 return wxShapedMacWindowHitTest(window
, param
);
1739 case kWindowMsgGetFeatures
:
1740 return wxShapedMacWindowGetFeatures(window
, param
);
1742 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1743 case kWindowMsgGetRegion
:
1744 return wxShapedMacWindowGetRegion(window
, param
);