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
->CanAcceptFocus() && 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::MacSetBackgroundBrush( const wxBrush
&brush
)
1036 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1038 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1040 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1044 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1046 if ( m_macEventHandler
!= NULL
)
1048 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1051 InstallWindowEventHandler(
1052 MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1053 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1056 void wxTopLevelWindowMac::MacCreateRealWindow(
1057 const wxString
& title
,
1061 const wxString
& name
)
1063 OSStatus err
= noErr
;
1065 m_windowStyle
= style
;
1073 wxRect display
= wxGetClientDisplayRect() ;
1075 if ( x
== wxDefaultPosition
.x
)
1078 if ( y
== wxDefaultPosition
.y
)
1081 int w
= WidthDefault(size
.x
);
1082 int h
= HeightDefault(size
.y
);
1084 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1086 // translate the window attributes in the appropriate window class and attributes
1087 WindowClass wclass
= 0;
1088 WindowAttributes attr
= kWindowNoAttributes
;
1089 WindowGroupRef group
= NULL
;
1091 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1094 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1095 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1096 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1099 wclass
= kFloatingWindowClass
;
1101 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1102 attr
|= kWindowSideTitlebarAttribute
;
1106 wclass
= kPlainWindowClass
;
1109 else if ( HasFlag( wxPOPUP_WINDOW
) )
1112 // Until we've got a real wxPopupWindow class on wxMac make it a
1113 // little easier for wxFrame to be used to emulate it and workaround
1114 // the lack of wxPopupWindow.
1115 if ( HasFlag( wxBORDER_NONE
) )
1116 wclass
= kHelpWindowClass
; // has no border
1118 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1119 //attr |= kWindowNoShadowAttribute; // turn off the shadow Should we??
1120 group
= GetWindowGroupOfClass( // float above other windows
1121 kFloatingWindowClass
) ;
1123 else if ( HasFlag( wxCAPTION
) )
1125 wclass
= kDocumentWindowClass
;
1126 attr
|= kWindowInWindowMenuAttribute
;
1128 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1129 else if ( HasFlag( wxFRAME_DRAWER
) )
1131 wclass
= kDrawerWindowClass
;
1133 #endif //10.2 and up
1136 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1137 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1139 wclass
= kDocumentWindowClass
;
1143 wclass
= kPlainWindowClass
;
1147 if ( wclass
!= kPlainWindowClass
)
1149 if ( HasFlag( wxMINIMIZE_BOX
) )
1150 attr
|= kWindowCollapseBoxAttribute
;
1152 if ( HasFlag( wxMAXIMIZE_BOX
) )
1153 attr
|= kWindowFullZoomAttribute
;
1155 if ( HasFlag( wxRESIZE_BORDER
) )
1156 attr
|= kWindowResizableAttribute
;
1158 if ( HasFlag( wxCLOSE_BOX
) )
1159 attr
|= kWindowCloseBoxAttribute
;
1162 // turn on live resizing (OS X only)
1163 if (UMAGetSystemVersion() >= 0x1000)
1164 attr
|= kWindowLiveResizeAttribute
;
1166 if ( HasFlag(wxSTAY_ON_TOP
) )
1167 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1169 if ( HasFlag( wxFRAME_FLOAT_ON_PARENT
) )
1170 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1172 attr
|= kWindowCompositingAttribute
;
1173 #if 0 // wxMAC_USE_CORE_GRAPHICS ; TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1174 attr
|= kWindowFrameworkScaledAttribute
;
1177 if ( HasFlag(wxFRAME_SHAPED
) )
1179 WindowDefSpec customWindowDefSpec
;
1180 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1181 customWindowDefSpec
.u
.defProc
=
1183 (WindowDefUPP
) wxShapedMacWindowDef
;
1185 NewWindowDefUPP(wxShapedMacWindowDef
);
1187 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1188 attr
, &theBoundsRect
,
1189 (WindowRef
*) &m_macWindow
);
1193 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1196 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1197 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1199 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1201 // setup a separate group for each window, so that overlays can be handled easily
1202 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &group
));
1203 verify_noerr( SetWindowGroupParent( group
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1204 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, group
));
1206 // the create commands are only for content rect,
1207 // so we have to set the size again as structure bounds
1208 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1210 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1211 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1212 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1214 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1215 // the content view, so we have to retrieve it explicitly
1216 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1217 m_peer
->GetControlRefAddr() ) ;
1218 if ( !m_peer
->Ok() )
1220 // compatibility mode fallback
1221 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1224 // the root control level handler
1225 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1227 // Causes the inner part of the window not to be metal
1228 // if the style is used before window creation.
1229 #if 0 // TARGET_API_MAC_OSX
1230 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1232 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1233 MacSetMetalAppearance( true ) ;
1237 // the frame window event handler
1238 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1239 MacInstallTopLevelWindowEventHandler() ;
1241 DoSetWindowVariant( m_windowVariant
) ;
1245 if ( HasFlag(wxFRAME_SHAPED
) )
1247 // default shape matches the window size
1248 wxRegion
rgn( 0, 0, w
, h
);
1252 wxWindowCreateEvent
event(this);
1253 GetEventHandler()->ProcessEvent(event
);
1256 void wxTopLevelWindowMac::ClearBackground()
1258 wxWindow::ClearBackground() ;
1261 // Raise the window to the top of the Z order
1262 void wxTopLevelWindowMac::Raise()
1264 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1267 // Lower the window to the bottom of the Z order
1268 void wxTopLevelWindowMac::Lower()
1270 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1273 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1275 if (s_macDeactivateWindow
)
1277 wxLogTrace(TRACE_ACTIVATE
,
1278 wxT("Doing delayed deactivation of %p"),
1279 s_macDeactivateWindow
);
1281 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1285 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1287 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1289 if (s_macDeactivateWindow
== this)
1290 s_macDeactivateWindow
= NULL
;
1292 MacDelayedDeactivation(timestamp
);
1293 MacPropagateHiliteChanged() ;
1296 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1298 wxWindow::SetLabel( title
) ;
1299 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1302 wxString
wxTopLevelWindowMac::GetTitle() const
1304 return wxWindow::GetLabel();
1307 bool wxTopLevelWindowMac::Show(bool show
)
1309 if ( !wxTopLevelWindowBase::Show(show
) )
1312 bool plainTransition
= false;
1314 #if wxUSE_SYSTEM_OPTIONS
1315 // code contributed by Ryan Wilcox December 18, 2003
1316 plainTransition
= UMAGetSystemVersion() >= 0x1000 ;
1317 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1318 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1323 if ( plainTransition
)
1324 ::ShowWindow( (WindowRef
)m_macWindow
);
1326 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1328 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1330 // because apps expect a size event to occur at this moment
1331 wxSizeEvent
event(GetSize() , m_windowId
);
1332 event
.SetEventObject(this);
1333 GetEventHandler()->ProcessEvent(event
);
1337 if ( plainTransition
)
1338 ::HideWindow( (WindowRef
)m_macWindow
);
1340 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1343 MacPropagateVisibilityChanged() ;
1348 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1352 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1354 data
= new FullScreenData() ;
1356 m_macFullScreenData
= data
;
1357 data
->m_position
= GetPosition() ;
1358 data
->m_size
= GetSize() ;
1359 data
->m_wasResizable
= MacGetWindowAttributes() & kWindowResizableAttribute
;
1361 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1364 wxRect client
= wxGetClientDisplayRect() ;
1366 int left
, top
, right
, bottom
;
1374 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1376 if ( style
& wxFULLSCREEN_NOCAPTION
)
1382 if ( style
& wxFULLSCREEN_NOBORDER
)
1389 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1394 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1399 SetSize( x
, y
, w
, h
) ;
1400 if ( data
->m_wasResizable
)
1401 MacChangeWindowAttributes( kWindowNoAttributes
, kWindowResizableAttribute
) ;
1406 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1407 if ( data
->m_wasResizable
)
1408 MacChangeWindowAttributes( kWindowResizableAttribute
, kWindowNoAttributes
) ;
1409 SetPosition( data
->m_position
) ;
1410 SetSize( data
->m_size
) ;
1413 m_macFullScreenData
= NULL
;
1419 bool wxTopLevelWindowMac::IsFullScreen() const
1421 return m_macFullScreenData
!= NULL
;
1425 bool wxTopLevelWindowMac::SetTransparent(wxByte alpha
)
1427 OSStatus result
= SetWindowAlpha((WindowRef
)m_macWindow
, float(alpha
)/255.0);
1428 return result
== noErr
;
1432 bool wxTopLevelWindowMac::CanSetTransparent()
1438 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1440 if ( GetExtraStyle() == exStyle
)
1443 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1445 #if TARGET_API_MAC_OSX
1446 if ( m_macWindow
!= NULL
)
1448 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1449 if ( MacGetMetalAppearance() != metal
)
1450 MacSetMetalAppearance( metal
) ;
1455 // TODO: switch to structure bounds -
1456 // we are still using coordinates of the content view
1458 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1460 Rect content
, structure
;
1462 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1463 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1465 left
= content
.left
- structure
.left
;
1466 top
= content
.top
- structure
.top
;
1467 right
= structure
.right
- content
.right
;
1468 bottom
= structure
.bottom
- content
.bottom
;
1471 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1473 m_cachedClippedRectValid
= false ;
1474 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1475 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1476 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1479 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1483 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1491 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1495 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1498 *width
= bounds
.right
- bounds
.left
;
1500 *height
= bounds
.bottom
- bounds
.top
;
1503 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1507 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1510 *width
= bounds
.right
- bounds
.left
;
1512 *height
= bounds
.bottom
- bounds
.top
;
1515 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1517 #if TARGET_API_MAC_OSX
1518 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1519 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1523 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1525 #if TARGET_API_MAC_OSX
1526 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1532 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1534 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1537 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1540 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1545 void wxTopLevelWindowMac::MacPerformUpdates()
1547 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1548 // for composited windows this also triggers a redraw of all
1549 // invalid views in the window
1550 if ( UMAGetSystemVersion() >= 0x1030 )
1551 HIWindowFlush((WindowRef
) m_macWindow
) ;
1555 // the only way to trigger the redrawing on earlier systems is to call
1558 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1559 UInt32 currentEventClass
= 0 ;
1560 if ( currentEvent
!= NULL
)
1562 currentEventClass
= ::GetEventClass( currentEvent
) ;
1563 ::GetEventKind( currentEvent
) ;
1566 if ( currentEventClass
!= kEventClassMenu
)
1568 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1570 ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1575 // Attracts the users attention to this window if the application is
1576 // inactive (should be called when a background event occurs)
1578 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1581 DisposePtr( (Ptr
)ptr
) ;
1584 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1586 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1587 static wxMacNMUPP
nmupp( wxMacNMResponse
);
1589 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1590 notificationRequest
->qType
= nmType
;
1591 notificationRequest
->nmMark
= 1 ;
1592 notificationRequest
->nmIcon
= 0 ;
1593 notificationRequest
->nmSound
= 0 ;
1594 notificationRequest
->nmStr
= NULL
;
1595 notificationRequest
->nmResp
= nmupp
;
1597 verify_noerr( NMInstall( notificationRequest
) ) ;
1600 // ---------------------------------------------------------------------------
1601 // Shape implementation
1602 // ---------------------------------------------------------------------------
1605 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1607 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1608 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1610 // The empty region signifies that the shape
1611 // should be removed from the window.
1612 if ( region
.IsEmpty() )
1614 wxSize sz
= GetClientSize();
1615 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1616 if ( rgn
.IsEmpty() )
1619 return SetShape(rgn
);
1622 // Make a copy of the region
1623 RgnHandle shapeRegion
= NewRgn();
1624 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1626 // Dispose of any shape region we may already have
1627 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1631 // Save the region so we can use it later
1632 SetWRefCon((WindowRef
)MacGetWindowRef(), (URefCon
)shapeRegion
);
1634 // inform the window manager that the window has changed shape
1635 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1640 // ---------------------------------------------------------------------------
1641 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1642 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1643 // ---------------------------------------------------------------------------
1645 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1647 GetWindowPortBounds(window
, inRect
);
1648 Point pt
= { inRect
->top
,inRect
->left
};
1649 wxMacLocalToGlobal( window
, &pt
) ;
1650 inRect
->bottom
+= pt
.v
- inRect
->top
;
1651 inRect
->right
+= pt
.h
- inRect
->left
;
1653 inRect
->left
= pt
.h
;
1656 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1658 /*------------------------------------------------------
1659 Define which options your custom window supports.
1660 --------------------------------------------------------*/
1661 //just enable everything for our demo
1662 *(OptionBits
*)param
=
1665 //kWindowCanCollapse |
1666 //kWindowCanGetWindowRegion |
1667 //kWindowHasTitleBar |
1668 //kWindowSupportsDragHilite |
1669 kWindowCanDrawInCurrentPort
|
1670 //kWindowCanMeasureTitle |
1671 kWindowWantsDisposeAtProcessDeath
|
1672 kWindowSupportsGetGrowImageRegion
|
1673 kWindowDefSupportsColorGrafPort
;
1678 // The content region is left as a rectangle matching the window size, this is
1679 // so the origin in the paint event, and etc. still matches what the
1680 // programmer expects.
1681 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1684 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1688 wxShapedMacWindowGetPos( window
, &r
) ;
1689 RectRgn( rgn
, &r
) ;
1693 // The structure region is set to the shape given to the SetShape method.
1694 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1696 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1702 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1703 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1704 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1705 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1709 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1711 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1716 switch (rgnRec
->regionCode
)
1718 case kWindowStructureRgn
:
1719 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1722 case kWindowContentRgn
:
1723 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1727 SetEmptyRgn(rgnRec
->winRgn
);
1734 // Determine the region of the window which was hit
1736 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1739 static RgnHandle tempRgn
= NULL
;
1741 if (tempRgn
== NULL
)
1744 // get the point clicked
1745 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1747 // Mac OS 8.5 or later
1748 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1749 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1752 // no significant area was hit
1756 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1760 case kWindowMsgHitTest
:
1761 return wxShapedMacWindowHitTest(window
, param
);
1763 case kWindowMsgGetFeatures
:
1764 return wxShapedMacWindowGetFeatures(window
, param
);
1766 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1767 case kWindowMsgGetRegion
:
1768 return wxShapedMacWindowGetRegion(window
, param
);