1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for Mac
4 // Author: Stefan Csomor
8 // Copyright: (c) 2001-2004 Stefan Csomor
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/toplevel.h"
32 #include "wx/string.h"
35 #include "wx/settings.h"
36 #include "wx/strconv.h"
37 #include "wx/control.h"
40 #include "wx/mac/uma.h"
41 #include "wx/mac/aga.h"
42 #include "wx/tooltip.h"
45 #if wxUSE_SYSTEM_OPTIONS
46 #include "wx/sysopt.h"
50 #include <ToolUtils.h>
54 #include "wx/mac/private.h"
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 // trace mask for activation tracing messages
61 static const wxChar
*TRACE_ACTIVATE
= _T("activation");
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 // list of all frames and modeless dialogs
68 wxWindowList wxModelessWindows
;
70 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
72 // ============================================================================
73 // wxTopLevelWindowMac implementation
74 // ============================================================================
76 BEGIN_EVENT_TABLE(wxTopLevelWindowMac
, wxTopLevelWindowBase
)
80 // ---------------------------------------------------------------------------
82 // ---------------------------------------------------------------------------
84 static const EventTypeSpec eventList
[] =
86 // TODO: remove control related event like key and mouse (except for WindowLeave events)
88 { kEventClassKeyboard
, kEventRawKeyDown
} ,
89 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
90 { kEventClassKeyboard
, kEventRawKeyUp
} ,
91 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
93 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
94 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
96 { kEventClassWindow
, kEventWindowShown
} ,
97 { kEventClassWindow
, kEventWindowActivated
} ,
98 { kEventClassWindow
, kEventWindowDeactivated
} ,
99 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
100 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
101 { kEventClassWindow
, kEventWindowClose
} ,
103 // we have to catch these events on the toplevel window level,
104 // as controls don't get the raw mouse events anymore
106 { kEventClassMouse
, kEventMouseDown
} ,
107 { kEventClassMouse
, kEventMouseUp
} ,
108 { kEventClassMouse
, kEventMouseWheelMoved
} ,
109 { kEventClassMouse
, kEventMouseMoved
} ,
110 { kEventClassMouse
, kEventMouseDragged
} ,
113 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
115 OSStatus result
= eventNotHandledErr
;
116 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
117 // FindFocus does not return the actual focus window, but the enclosing window
118 wxWindow
* focus
= wxWindow::DoFindFocus();
120 focus
= (wxTopLevelWindowMac
*) data
;
122 unsigned char charCode
;
130 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
133 ByteCount dataSize
= 0 ;
134 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
137 int numChars
= dataSize
/ sizeof( UniChar
) + 1;
139 UniChar
* charBuf
= buf
;
141 if ( numChars
* 2 > 4 )
142 charBuf
= new UniChar
[ numChars
] ;
143 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
144 charBuf
[ numChars
- 1 ] = 0;
146 #if SIZEOF_WCHAR_T == 2
147 uniChar
= charBuf
[0] ;
149 wxMBConvUTF16 converter
;
150 converter
.MB2WC( uniChar
, (const char*)charBuf
, 2 ) ;
153 if ( numChars
* 2 > 4 )
158 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
159 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
160 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
161 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
163 UInt32 message
= (keyCode
<< 8) + charCode
;
164 switch ( GetEventKind( event
) )
166 case kEventRawKeyRepeat
:
167 case kEventRawKeyDown
:
169 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
170 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
171 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
172 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
173 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
177 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
181 case kEventRawKeyUp
:
182 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
183 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
189 case kEventRawKeyModifiersChanged
:
191 wxKeyEvent
event(wxEVT_KEY_DOWN
);
193 event
.m_shiftDown
= modifiers
& shiftKey
;
194 event
.m_controlDown
= modifiers
& controlKey
;
195 event
.m_altDown
= modifiers
& optionKey
;
196 event
.m_metaDown
= modifiers
& cmdKey
;
201 event
.m_uniChar
= uniChar
[0] ;
204 event
.SetTimestamp(when
);
205 event
.SetEventObject(focus
);
207 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
209 event
.m_keyCode
= WXK_CONTROL
;
210 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
211 focus
->GetEventHandler()->ProcessEvent( event
) ;
213 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
215 event
.m_keyCode
= WXK_SHIFT
;
216 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
217 focus
->GetEventHandler()->ProcessEvent( event
) ;
219 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
221 event
.m_keyCode
= WXK_ALT
;
222 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
223 focus
->GetEventHandler()->ProcessEvent( event
) ;
225 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
227 event
.m_keyCode
= WXK_COMMAND
;
228 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
229 focus
->GetEventHandler()->ProcessEvent( event
) ;
232 wxApp::s_lastModifiers
= modifiers
;
243 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
244 // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
247 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
249 wxWindow
* g_MacLastWindow
= NULL
;
251 EventMouseButton g_lastButton
= 0 ;
253 void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
255 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
256 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
258 // this parameter are not given for all events
259 EventMouseButton button
= 0 ;
260 UInt32 clickCount
= 0 ;
261 cEvent
.GetParameter
<EventMouseButton
>( kEventParamMouseButton
, typeMouseButton
, &button
) ;
262 cEvent
.GetParameter
<UInt32
>( kEventParamClickCount
, typeUInt32
, &clickCount
) ;
264 wxevent
.m_x
= screenMouseLocation
.h
;
265 wxevent
.m_y
= screenMouseLocation
.v
;
266 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
267 wxevent
.m_controlDown
= modifiers
& controlKey
;
268 wxevent
.m_altDown
= modifiers
& optionKey
;
269 wxevent
.m_metaDown
= modifiers
& cmdKey
;
270 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
272 // a control click is interpreted as a right click
273 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
274 button
= kEventMouseButtonSecondary
;
276 // otherwise we report double clicks by connecting a left click with a ctrl-left click
277 if ( clickCount
> 1 && button
!= g_lastButton
)
280 // we must make sure that our synthetic 'right' button corresponds in
281 // mouse down, moved and mouse up, and does not deliver a right down and left up
283 if ( cEvent
.GetKind() == kEventMouseDown
)
284 g_lastButton
= button
;
288 else if ( g_lastButton
)
289 button
= g_lastButton
;
291 // determine the correct down state, wx does not want a 'down' for a mouseUp event,
292 // while mac delivers this button
293 if ( button
!= 0 && cEvent
.GetKind() != kEventMouseUp
)
297 case kEventMouseButtonPrimary
:
298 wxevent
.m_leftDown
= true ;
301 case kEventMouseButtonSecondary
:
302 wxevent
.m_rightDown
= true ;
305 case kEventMouseButtonTertiary
:
306 wxevent
.m_middleDown
= true ;
314 // translate into wx types
315 switch ( cEvent
.GetKind() )
317 case kEventMouseDown
:
320 case kEventMouseButtonPrimary
:
321 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
324 case kEventMouseButtonSecondary
:
325 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
328 case kEventMouseButtonTertiary
:
329 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
340 case kEventMouseButtonPrimary
:
341 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
344 case kEventMouseButtonSecondary
:
345 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
348 case kEventMouseButtonTertiary
:
349 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
357 case kEventMouseWheelMoved
:
359 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
361 EventMouseWheelAxis axis
= cEvent
.GetParameter
<EventMouseWheelAxis
>(kEventParamMouseWheelAxis
, typeMouseWheelAxis
) ;
362 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeSInt32
) ;
364 wxevent
.m_wheelRotation
= delta
;
365 wxevent
.m_wheelDelta
= 1;
366 wxevent
.m_linesPerAction
= 1;
367 if ( axis
== kEventMouseWheelAxisX
)
368 wxevent
.m_wheelAxis
= 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 wxMacGlobalToLocal( 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
;
889 void wxTopLevelWindowMac::Init()
892 m_maximizeOnShow
= false;
895 m_macEventHandler
= NULL
;
896 m_macFullScreenData
= NULL
;
899 class wxMacDeferredWindowDeleter
: public wxObject
902 wxMacDeferredWindowDeleter( WindowRef windowRef
)
904 m_macWindow
= windowRef
;
907 virtual ~wxMacDeferredWindowDeleter()
909 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
913 WindowRef m_macWindow
;
916 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
918 const wxString
& title
,
922 const wxString
& name
)
927 m_windowStyle
= style
;
931 m_windowId
= id
== -1 ? NewControlId() : id
;
932 wxWindow::SetLabel( title
) ;
934 MacCreateRealWindow( title
, pos
, size
, style
, name
) ;
936 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
938 if (GetExtraStyle() & wxFRAME_EX_METAL
)
939 MacSetMetalAppearance(true);
941 wxTopLevelWindows
.Append(this);
944 parent
->AddChild(this);
949 wxTopLevelWindowMac::~wxTopLevelWindowMac()
954 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
956 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
959 if ( m_macEventHandler
)
961 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
962 m_macEventHandler
= NULL
;
965 wxRemoveMacWindowAssociation( this ) ;
967 if ( wxModelessWindows
.Find(this) )
968 wxModelessWindows
.DeleteObject(this);
970 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
972 m_macFullScreenData
= NULL
;
976 // ----------------------------------------------------------------------------
977 // wxTopLevelWindowMac maximize/minimize
978 // ----------------------------------------------------------------------------
980 void wxTopLevelWindowMac::Maximize(bool maximize
)
982 Point idealSize
= { 0 , 0 } ;
985 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
987 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
989 idealSize
.h
= bounds
.size
.width
;
990 idealSize
.v
= bounds
.size
.height
;
993 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
994 idealSize
.h
= rect
.right
- rect
.left
;
995 idealSize
.v
= rect
.bottom
- rect
.top
;
998 ZoomWindowIdeal( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
1001 bool wxTopLevelWindowMac::IsMaximized() const
1003 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
1006 void wxTopLevelWindowMac::Iconize(bool iconize
)
1008 if ( IsWindowCollapsable( (WindowRef
)m_macWindow
) )
1009 CollapseWindow( (WindowRef
)m_macWindow
, iconize
) ;
1012 bool wxTopLevelWindowMac::IsIconized() const
1014 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1017 void wxTopLevelWindowMac::Restore()
1019 if ( IsMaximized() )
1021 else if ( IsIconized() )
1025 // ----------------------------------------------------------------------------
1026 // wxTopLevelWindowMac misc
1027 // ----------------------------------------------------------------------------
1029 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1031 return wxPoint(0, 0) ;
1034 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
1037 wxTopLevelWindowBase::SetIcon(icon
);
1040 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1042 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1044 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1046 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1050 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1052 if ( m_macEventHandler
!= NULL
)
1054 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1057 InstallWindowEventHandler(
1058 MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1059 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1062 void wxTopLevelWindowMac::MacCreateRealWindow(
1063 const wxString
& title
,
1067 const wxString
& name
)
1069 OSStatus err
= noErr
;
1071 m_windowStyle
= style
;
1079 wxRect display
= wxGetClientDisplayRect() ;
1081 if ( x
== wxDefaultPosition
.x
)
1084 if ( y
== wxDefaultPosition
.y
)
1087 int w
= WidthDefault(size
.x
);
1088 int h
= HeightDefault(size
.y
);
1090 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1092 // translate the window attributes in the appropriate window class and attributes
1093 WindowClass wclass
= 0;
1094 WindowAttributes attr
= kWindowNoAttributes
;
1095 WindowGroupRef group
= NULL
;
1097 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1100 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1101 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1102 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1105 wclass
= kFloatingWindowClass
;
1107 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1108 attr
|= kWindowSideTitlebarAttribute
;
1112 wclass
= kPlainWindowClass
;
1115 else if ( HasFlag( wxPOPUP_WINDOW
) )
1118 // Until we've got a real wxPopupWindow class on wxMac make it a
1119 // little easier for wxFrame to be used to emulate it and workaround
1120 // the lack of wxPopupWindow.
1121 if ( HasFlag( wxBORDER_NONE
) )
1122 wclass
= kHelpWindowClass
; // has no border
1124 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1125 //attr |= kWindowNoShadowAttribute; // turn off the shadow Should we??
1126 group
= GetWindowGroupOfClass( // float above other windows
1127 kFloatingWindowClass
) ;
1129 else if ( HasFlag( wxCAPTION
) )
1131 wclass
= kDocumentWindowClass
;
1132 attr
|= kWindowInWindowMenuAttribute
;
1134 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1135 else if ( HasFlag( wxFRAME_DRAWER
) )
1137 wclass
= kDrawerWindowClass
;
1139 #endif //10.2 and up
1142 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1143 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1145 wclass
= kDocumentWindowClass
;
1149 wclass
= kPlainWindowClass
;
1153 if ( wclass
!= kPlainWindowClass
)
1155 if ( HasFlag( wxMINIMIZE_BOX
) )
1156 attr
|= kWindowCollapseBoxAttribute
;
1158 if ( HasFlag( wxMAXIMIZE_BOX
) )
1159 attr
|= kWindowFullZoomAttribute
;
1161 if ( HasFlag( wxRESIZE_BORDER
) )
1162 attr
|= kWindowResizableAttribute
;
1164 if ( HasFlag( wxCLOSE_BOX
) )
1165 attr
|= kWindowCloseBoxAttribute
;
1168 // turn on live resizing (OS X only)
1169 if (UMAGetSystemVersion() >= 0x1000)
1170 attr
|= kWindowLiveResizeAttribute
;
1172 if ( HasFlag(wxSTAY_ON_TOP
) )
1173 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1175 if ( HasFlag( wxFRAME_FLOAT_ON_PARENT
) )
1176 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1178 attr
|= kWindowCompositingAttribute
;
1179 #if 0 // wxMAC_USE_CORE_GRAPHICS ; TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1180 attr
|= kWindowFrameworkScaledAttribute
;
1183 if ( HasFlag(wxFRAME_SHAPED
) )
1185 WindowDefSpec customWindowDefSpec
;
1186 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1187 customWindowDefSpec
.u
.defProc
=
1189 (WindowDefUPP
) wxShapedMacWindowDef
;
1191 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 // setup a separate group for each window, so that overlays can be handled easily
1208 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &group
));
1209 verify_noerr( SetWindowGroupParent( group
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1210 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, group
));
1212 // the create commands are only for content rect,
1213 // so we have to set the size again as structure bounds
1214 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1216 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1217 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1218 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1220 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1221 // the content view, so we have to retrieve it explicitly
1222 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1223 m_peer
->GetControlRefAddr() ) ;
1224 if ( !m_peer
->Ok() )
1226 // compatibility mode fallback
1227 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1230 // the root control level handler
1231 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1233 // Causes the inner part of the window not to be metal
1234 // if the style is used before window creation.
1235 #if 0 // TARGET_API_MAC_OSX
1236 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1238 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1239 MacSetMetalAppearance( true ) ;
1243 // the frame window event handler
1244 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1245 MacInstallTopLevelWindowEventHandler() ;
1247 DoSetWindowVariant( m_windowVariant
) ;
1251 if ( HasFlag(wxFRAME_SHAPED
) )
1253 // default shape matches the window size
1254 wxRegion
rgn( 0, 0, w
, h
);
1258 wxWindowCreateEvent
event(this);
1259 GetEventHandler()->ProcessEvent(event
);
1262 void wxTopLevelWindowMac::ClearBackground()
1264 wxWindow::ClearBackground() ;
1267 // Raise the window to the top of the Z order
1268 void wxTopLevelWindowMac::Raise()
1270 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1273 // Lower the window to the bottom of the Z order
1274 void wxTopLevelWindowMac::Lower()
1276 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1279 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1281 if (s_macDeactivateWindow
)
1283 wxLogTrace(TRACE_ACTIVATE
,
1284 wxT("Doing delayed deactivation of %p"),
1285 s_macDeactivateWindow
);
1287 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1291 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1293 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1295 if (s_macDeactivateWindow
== this)
1296 s_macDeactivateWindow
= NULL
;
1298 MacDelayedDeactivation(timestamp
);
1299 MacPropagateHiliteChanged() ;
1302 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1304 wxWindow::SetLabel( title
) ;
1305 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1308 wxString
wxTopLevelWindowMac::GetTitle() const
1310 return wxWindow::GetLabel();
1313 bool wxTopLevelWindowMac::Show(bool show
)
1315 if ( !wxTopLevelWindowBase::Show(show
) )
1318 bool plainTransition
= false;
1320 #if wxUSE_SYSTEM_OPTIONS
1321 // code contributed by Ryan Wilcox December 18, 2003
1322 plainTransition
= UMAGetSystemVersion() >= 0x1000 ;
1323 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1324 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1329 if ( plainTransition
)
1330 ::ShowWindow( (WindowRef
)m_macWindow
);
1332 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1334 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1336 // because apps expect a size event to occur at this moment
1337 wxSizeEvent
event(GetSize() , m_windowId
);
1338 event
.SetEventObject(this);
1339 GetEventHandler()->ProcessEvent(event
);
1343 if ( plainTransition
)
1344 ::HideWindow( (WindowRef
)m_macWindow
);
1346 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1349 MacPropagateVisibilityChanged() ;
1354 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1358 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1360 data
= new FullScreenData() ;
1362 m_macFullScreenData
= data
;
1363 data
->m_position
= GetPosition() ;
1364 data
->m_size
= GetSize() ;
1365 data
->m_wasResizable
= MacGetWindowAttributes() & kWindowResizableAttribute
;
1367 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1370 wxRect client
= wxGetClientDisplayRect() ;
1372 int left
, top
, right
, bottom
;
1380 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1382 if ( style
& wxFULLSCREEN_NOCAPTION
)
1388 if ( style
& wxFULLSCREEN_NOBORDER
)
1395 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1400 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1405 SetSize( x
, y
, w
, h
) ;
1406 if ( data
->m_wasResizable
)
1407 MacChangeWindowAttributes( kWindowNoAttributes
, kWindowResizableAttribute
) ;
1412 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1413 if ( data
->m_wasResizable
)
1414 MacChangeWindowAttributes( kWindowResizableAttribute
, kWindowNoAttributes
) ;
1415 SetPosition( data
->m_position
) ;
1416 SetSize( data
->m_size
) ;
1419 m_macFullScreenData
= NULL
;
1425 bool wxTopLevelWindowMac::IsFullScreen() const
1427 return m_macFullScreenData
!= NULL
;
1431 bool wxTopLevelWindowMac::SetTransparent(wxByte alpha
)
1433 OSStatus result
= SetWindowAlpha((WindowRef
)m_macWindow
, float(alpha
)/255.0);
1434 return result
== noErr
;
1438 bool wxTopLevelWindowMac::CanSetTransparent()
1444 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1446 if ( GetExtraStyle() == exStyle
)
1449 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1451 #if TARGET_API_MAC_OSX
1452 if ( m_macWindow
!= NULL
)
1454 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1455 if ( MacGetMetalAppearance() != metal
)
1456 MacSetMetalAppearance( metal
) ;
1461 // TODO: switch to structure bounds -
1462 // we are still using coordinates of the content view
1464 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1466 Rect content
, structure
;
1468 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1469 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1471 left
= content
.left
- structure
.left
;
1472 top
= content
.top
- structure
.top
;
1473 right
= structure
.right
- content
.right
;
1474 bottom
= structure
.bottom
- content
.bottom
;
1477 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1479 m_cachedClippedRectValid
= false ;
1480 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1481 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1482 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1485 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1489 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1497 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1501 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1504 *width
= bounds
.right
- bounds
.left
;
1506 *height
= bounds
.bottom
- bounds
.top
;
1509 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1513 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1516 *width
= bounds
.right
- bounds
.left
;
1518 *height
= bounds
.bottom
- bounds
.top
;
1521 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1523 #if TARGET_API_MAC_OSX
1524 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1525 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1529 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1531 #if TARGET_API_MAC_OSX
1532 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1538 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1540 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1543 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1546 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1551 void wxTopLevelWindowMac::MacPerformUpdates()
1553 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1554 // for composited windows this also triggers a redraw of all
1555 // invalid views in the window
1556 if ( UMAGetSystemVersion() >= 0x1030 )
1557 HIWindowFlush((WindowRef
) m_macWindow
) ;
1561 // the only way to trigger the redrawing on earlier systems is to call
1564 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1565 UInt32 currentEventClass
= 0 ;
1566 if ( currentEvent
!= NULL
)
1568 currentEventClass
= ::GetEventClass( currentEvent
) ;
1569 ::GetEventKind( currentEvent
) ;
1572 if ( currentEventClass
!= kEventClassMenu
)
1574 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1576 ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1581 // Attracts the users attention to this window if the application is
1582 // inactive (should be called when a background event occurs)
1584 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1587 DisposePtr( (Ptr
)ptr
) ;
1590 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1592 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1593 static wxMacNMUPP
nmupp( wxMacNMResponse
);
1595 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1596 notificationRequest
->qType
= nmType
;
1597 notificationRequest
->nmMark
= 1 ;
1598 notificationRequest
->nmIcon
= 0 ;
1599 notificationRequest
->nmSound
= 0 ;
1600 notificationRequest
->nmStr
= NULL
;
1601 notificationRequest
->nmResp
= nmupp
;
1603 verify_noerr( NMInstall( notificationRequest
) ) ;
1606 // ---------------------------------------------------------------------------
1607 // Shape implementation
1608 // ---------------------------------------------------------------------------
1611 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1613 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1614 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1616 // The empty region signifies that the shape
1617 // should be removed from the window.
1618 if ( region
.IsEmpty() )
1620 wxSize sz
= GetClientSize();
1621 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1622 if ( rgn
.IsEmpty() )
1625 return SetShape(rgn
);
1628 // Make a copy of the region
1629 RgnHandle shapeRegion
= NewRgn();
1630 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1632 // Dispose of any shape region we may already have
1633 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1637 // Save the region so we can use it later
1638 SetWRefCon((WindowRef
)MacGetWindowRef(), (URefCon
)shapeRegion
);
1640 // inform the window manager that the window has changed shape
1641 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1646 // ---------------------------------------------------------------------------
1647 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1648 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1649 // ---------------------------------------------------------------------------
1651 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1653 GetWindowPortBounds(window
, inRect
);
1654 Point pt
= { inRect
->top
,inRect
->left
};
1655 wxMacLocalToGlobal( window
, &pt
) ;
1656 inRect
->bottom
+= pt
.v
- inRect
->top
;
1657 inRect
->right
+= pt
.h
- inRect
->left
;
1659 inRect
->left
= pt
.h
;
1662 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1664 /*------------------------------------------------------
1665 Define which options your custom window supports.
1666 --------------------------------------------------------*/
1667 //just enable everything for our demo
1668 *(OptionBits
*)param
=
1671 //kWindowCanCollapse |
1672 //kWindowCanGetWindowRegion |
1673 //kWindowHasTitleBar |
1674 //kWindowSupportsDragHilite |
1675 kWindowCanDrawInCurrentPort
|
1676 //kWindowCanMeasureTitle |
1677 kWindowWantsDisposeAtProcessDeath
|
1678 kWindowSupportsGetGrowImageRegion
|
1679 kWindowDefSupportsColorGrafPort
;
1684 // The content region is left as a rectangle matching the window size, this is
1685 // so the origin in the paint event, and etc. still matches what the
1686 // programmer expects.
1687 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1690 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1694 wxShapedMacWindowGetPos( window
, &r
) ;
1695 RectRgn( rgn
, &r
) ;
1699 // The structure region is set to the shape given to the SetShape method.
1700 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1702 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1708 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1709 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1710 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1711 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1715 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1717 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1722 switch (rgnRec
->regionCode
)
1724 case kWindowStructureRgn
:
1725 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1728 case kWindowContentRgn
:
1729 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1733 SetEmptyRgn(rgnRec
->winRgn
);
1740 // Determine the region of the window which was hit
1742 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1745 static RgnHandle tempRgn
= NULL
;
1747 if (tempRgn
== NULL
)
1750 // get the point clicked
1751 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1753 // Mac OS 8.5 or later
1754 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1755 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1758 // no significant area was hit
1762 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1766 case kWindowMsgHitTest
:
1767 return wxShapedMacWindowHitTest(window
, param
);
1769 case kWindowMsgGetFeatures
:
1770 return wxShapedMacWindowGetFeatures(window
, param
);
1772 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1773 case kWindowMsgGetRegion
:
1774 return wxShapedMacWindowGetRegion(window
, param
);