1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: mac/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 // ----------------------------------------------------------------------------
21 #pragma implementation "toplevel.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/toplevel.h"
35 #include "wx/string.h"
38 #include "wx/settings.h"
41 #include "wx/mac/uma.h"
42 #include "wx/mac/aga.h"
44 #include "wx/tooltip.h"
46 #if wxUSE_SYSTEM_OPTIONS
47 #include "wx/sysopt.h"
50 #include <ToolUtils.h>
53 #include "wx/mac/private.h"
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 // list of all frames and modeless dialogs
60 wxWindowList wxModelessWindows
;
62 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
64 // ============================================================================
65 // wxTopLevelWindowMac implementation
66 // ============================================================================
68 BEGIN_EVENT_TABLE(wxTopLevelWindowMac
, wxTopLevelWindowBase
)
72 // ---------------------------------------------------------------------------
74 // ---------------------------------------------------------------------------
76 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
78 static const EventTypeSpec eventList
[] =
80 // TODO remove control related event like key and mouse (except for WindowLeave events)
82 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
84 { kEventClassKeyboard
, kEventRawKeyDown
} ,
85 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
86 { kEventClassKeyboard
, kEventRawKeyUp
} ,
87 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
90 { kEventClassWindow
, kEventWindowShown
} ,
91 { kEventClassWindow
, kEventWindowActivated
} ,
92 { kEventClassWindow
, kEventWindowDeactivated
} ,
93 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
94 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
95 { kEventClassWindow
, kEventWindowClose
} ,
97 // we have to catch these events on the toplevel window level, as controls don't get the
98 // raw mouse events anymore
100 { kEventClassMouse
, kEventMouseDown
} ,
101 { kEventClassMouse
, kEventMouseUp
} ,
102 { kEventClassMouse
, kEventMouseWheelMoved
} ,
103 { kEventClassMouse
, kEventMouseMoved
} ,
104 { kEventClassMouse
, kEventMouseDragged
} ,
107 static pascal OSStatus
TextInputEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
109 OSStatus result
= eventNotHandledErr
;
111 wxWindow
* focus
= wxWindow::FindFocus() ;
119 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent
) ;
121 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
,sizeof(char), NULL
,&charCode
);
122 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
123 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
124 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
125 sizeof( Point
), NULL
, &point
);
127 switch ( GetEventKind( event
) )
129 case kEventTextInputUnicodeForKeyEvent
:
130 // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not
131 // get its own kEventTextInputUnicodeForKeyEvent, so we route back the
132 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
135 ControlRef macControl
= (ControlRef
) control
->GetHandle() ;
138 ::HandleControlKey( macControl
, keyCode
, charCode
, modifiers
) ;
143 // this may lead to double events sent to a window in case all handlers have skipped the key down event
144 UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
145 UInt32 message = (keyCode << 8) + charCode;
147 if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent(
148 focus , message , modifiers , when , point.h , point.v ) )
159 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
161 OSStatus result
= eventNotHandledErr
;
163 wxWindow
* focus
= wxWindow::FindFocus() ;
171 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
173 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
,sizeof(char), NULL
,&charCode
);
174 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
175 GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
176 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
177 sizeof( Point
), NULL
, &point
);
179 UInt32 message
= (keyCode
<< 8) + charCode
;
180 switch( GetEventKind( event
) )
182 case kEventRawKeyRepeat
:
183 case kEventRawKeyDown
:
185 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
186 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
187 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
188 if ( (focus
!= NULL
) && wxTheApp
->MacSendKeyDownEvent(
189 focus
, message
, modifiers
, when
, point
.h
, point
.v
) )
193 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
196 case kEventRawKeyUp
:
197 if ( (focus
!= NULL
) && wxTheApp
->MacSendKeyUpEvent(
198 focus
, message
, modifiers
, when
, point
.h
, point
.v
) )
203 case kEventRawKeyModifiersChanged
:
205 wxKeyEvent
event(wxEVT_KEY_DOWN
);
207 event
.m_shiftDown
= modifiers
& shiftKey
;
208 event
.m_controlDown
= modifiers
& controlKey
;
209 event
.m_altDown
= modifiers
& optionKey
;
210 event
.m_metaDown
= modifiers
& cmdKey
;
214 event
.m_timeStamp
= when
;
215 wxWindow
* focus
= wxWindow::FindFocus() ;
216 event
.SetEventObject(focus
);
218 if ( focus
&& (modifiers
^ wxTheApp
->s_lastModifiers
) & controlKey
)
220 event
.m_keyCode
= WXK_CONTROL
;
221 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
222 focus
->GetEventHandler()->ProcessEvent( event
) ;
224 if ( focus
&& (modifiers
^ wxTheApp
->s_lastModifiers
) & shiftKey
)
226 event
.m_keyCode
= WXK_SHIFT
;
227 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
228 focus
->GetEventHandler()->ProcessEvent( event
) ;
230 if ( focus
&& (modifiers
^ wxTheApp
->s_lastModifiers
) & optionKey
)
232 event
.m_keyCode
= WXK_ALT
;
233 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
234 focus
->GetEventHandler()->ProcessEvent( event
) ;
236 if ( focus
&& (modifiers
^ wxTheApp
->s_lastModifiers
) & cmdKey
)
238 event
.m_keyCode
= WXK_COMMAND
;
239 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
240 focus
->GetEventHandler()->ProcessEvent( event
) ;
242 wxTheApp
->s_lastModifiers
= modifiers
;
250 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
251 // for windows that we didn't create (like eg Scrollbars in a databrowser) , or for controls where we did not handle the
254 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
256 wxWindow
* g_MacLastWindow
= NULL
;
258 static EventMouseButton lastButton
= 0 ;
260 static void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
262 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
263 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
265 // this parameter are not given for all events
266 EventMouseButton button
= 0 ;
267 UInt32 clickCount
= 0 ;
268 cEvent
.GetParameter
<EventMouseButton
>(kEventParamMouseButton
, typeMouseButton
, &button
) ;
269 cEvent
.GetParameter
<UInt32
>(kEventParamClickCount
, typeUInt32
, &clickCount
) ;
271 wxevent
.m_x
= screenMouseLocation
.h
;
272 wxevent
.m_y
= screenMouseLocation
.v
;
273 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
274 wxevent
.m_controlDown
= modifiers
& controlKey
;
275 wxevent
.m_altDown
= modifiers
& optionKey
;
276 wxevent
.m_metaDown
= modifiers
& cmdKey
;
277 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
278 // a control click is interpreted as a right click
279 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
281 button
= kEventMouseButtonSecondary
;
284 // we must make sure that our synthetic 'right' button corresponds in
285 // mouse down, moved and mouse up, and does not deliver a right down and left up
287 if ( cEvent
.GetKind() == kEventMouseDown
)
288 lastButton
= button
;
292 else if ( lastButton
)
293 button
= lastButton
;
295 // determinate the correct down state, wx does not want a 'down' for a mouseUp event, while mac delivers
297 if ( button
!= 0 && cEvent
.GetKind() != kEventMouseUp
)
301 case kEventMouseButtonPrimary
:
302 wxevent
.m_leftDown
= true ;
304 case kEventMouseButtonSecondary
:
305 wxevent
.m_rightDown
= true ;
307 case kEventMouseButtonTertiary
:
308 wxevent
.m_middleDown
= true ;
312 // translate into wx types
313 switch ( cEvent
.GetKind() )
315 case kEventMouseDown
:
318 case kEventMouseButtonPrimary
:
319 wxevent
.SetEventType(clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
321 case kEventMouseButtonSecondary
:
322 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
324 case kEventMouseButtonTertiary
:
325 wxevent
.SetEventType(clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
332 case kEventMouseButtonPrimary
:
333 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
335 case kEventMouseButtonSecondary
:
336 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
338 case kEventMouseButtonTertiary
:
339 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
343 case kEventMouseWheelMoved
:
345 wxevent
.SetEventType(wxEVT_MOUSEWHEEL
) ;
347 // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
348 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeLongInteger
) ;
350 wxevent
.m_wheelRotation
= delta
;
351 wxevent
.m_wheelDelta
= 1;
352 wxevent
.m_linesPerAction
= 1;
356 wxevent
.SetEventType(wxEVT_MOTION
) ;
361 ControlRef
wxMacFindSubControl( Point location
, ControlRef superControl
, ControlPartCode
*outPart
)
365 UInt16 childrenCount
= 0 ;
366 OSStatus err
= CountSubControls( superControl
, &childrenCount
) ;
367 if ( err
== errControlIsNotEmbedder
)
369 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
371 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
373 ControlHandle sibling
;
374 err
= GetIndexedSubControl( superControl
, i
, & sibling
) ;
375 if ( err
== errControlIsNotEmbedder
)
378 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
379 if ( IsControlVisible( sibling
) )
382 UMAGetControlBoundsInWindowCoords( sibling
, &r
) ;
383 if ( MacPtInRect( location
, &r
) )
385 ControlHandle child
= wxMacFindSubControl( location
, sibling
, outPart
) ;
390 Point testLocation
= location
;
391 #if TARGET_API_MAC_OSX
392 testLocation
.h
-= r
.left
;
393 testLocation
.v
-= r
.top
;
395 *outPart
= TestControl( sibling
, testLocation
) ;
405 ControlRef
wxMacFindControlUnderMouse( Point location
, WindowRef window
, ControlPartCode
*outPart
)
407 #if TARGET_API_MAC_OSX
408 if ( UMAGetSystemVersion() >= 0x1030 )
409 return FindControlUnderMouse( location
, window
, outPart
) ;
411 ControlRef rootControl
= NULL
;
412 verify_noerr( GetRootControl( window
, &rootControl
) ) ;
413 return wxMacFindSubControl( location
, rootControl
, outPart
) ;
416 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
419 OSStatus result
= eventNotHandledErr
;
421 wxMacCarbonEvent
cEvent( event
) ;
423 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
424 Point windowMouseLocation
= screenMouseLocation
;
427 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
429 wxWindow
* currentMouseWindow
= NULL
;
430 ControlRef control
= NULL
;
434 QDGlobalToLocalPoint( UMAGetWindowPort(window
) , &windowMouseLocation
) ;
436 if ( wxTheApp
->s_captureWindow
&& wxTheApp
->s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
)
438 currentMouseWindow
= wxTheApp
->s_captureWindow
;
440 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
442 ControlPartCode part
;
443 control
= wxMacFindControlUnderMouse( windowMouseLocation
, window
, &part
) ;
444 // if there is no control below the mouse position, send the event to the toplevel window itself
446 currentMouseWindow
= (wxWindow
*) data
;
449 currentMouseWindow
= wxFindControlFromMacControl( control
) ;
450 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
452 // for wxToolBar to function we have to send certaint events to it
453 // instead of its children (wxToolBarTools)
455 GetSuperControl(control
, &parent
);
456 wxWindow
*wxParent
= wxFindControlFromMacControl( parent
) ;
457 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
458 currentMouseWindow
= wxParent
;
464 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
465 SetupMouseEvent( wxevent
, cEvent
) ;
467 // handle all enter / leave events
469 if ( currentMouseWindow
!= g_MacLastWindow
)
471 if ( g_MacLastWindow
)
473 wxMouseEvent
eventleave(wxevent
);
474 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
475 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
476 eventleave
.SetEventObject( g_MacLastWindow
) ;
479 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
480 #endif // wxUSE_TOOLTIPS
481 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
483 if ( currentMouseWindow
)
485 wxMouseEvent
evententer(wxevent
);
486 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
487 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
488 evententer
.SetEventObject( currentMouseWindow
) ;
490 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
491 #endif // wxUSE_TOOLTIPS
492 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
494 g_MacLastWindow
= currentMouseWindow
;
497 if ( windowPart
== inMenuBar
)
499 // special case menu bar, as we are having a low-level runloop we must do it ourselves
500 if ( cEvent
.GetKind() == kEventMouseDown
)
502 ::MenuSelect( screenMouseLocation
) ;
505 } // if ( windowPart == inMenuBar )
506 else if ( currentMouseWindow
)
508 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
510 wxevent
.SetEventObject( currentMouseWindow
) ;
514 wxWindow
* cursorTarget
= currentMouseWindow
;
515 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
517 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
519 cursorTarget
= cursorTarget
->GetParent() ;
521 cursorPoint
+= cursorTarget
->GetPosition() ;
524 // make tooltips current
527 if ( wxevent
.GetEventType() == wxEVT_MOTION
528 || wxevent
.GetEventType() == wxEVT_ENTER_WINDOW
529 || wxevent
.GetEventType() == wxEVT_LEAVE_WINDOW
)
530 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
531 #endif // wxUSE_TOOLTIPS
532 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
536 // if the user code did _not_ handle the event, then perform the
537 // default processing
538 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
540 // ... that is set focus to this window
541 if (currentMouseWindow
->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
542 currentMouseWindow
->SetFocus();
545 ControlPartCode dummyPart
;
546 // if built-in find control is finding the wrong control (ie static box instead of overlaid
547 // button, we cannot let the standard handler do its job, but must handle manually
549 if ( ( cEvent
.GetKind() == kEventMouseDown
) &&
550 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
551 wxMacFindControlUnderMouse( windowMouseLocation
, window
, &dummyPart
) ) )
553 if ( currentMouseWindow
->MacIsReallyEnabled() )
555 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
556 Point clickLocation
= windowMouseLocation
;
557 #if TARGET_API_MAC_OSX
558 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
560 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
561 modifiers
, (ControlActionUPP
) -1 ) ;
566 if ( cEvent
.GetKind() == kEventMouseUp
&& wxTheApp
->s_captureWindow
)
568 wxTheApp
->s_captureWindow
= NULL
;
571 } // else if ( currentMouseWindow )
574 // don't mess with controls we don't know about
575 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
576 // so we try sending them the correct control directly
577 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
578 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
580 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
581 Point clickLocation
= windowMouseLocation
;
582 #if TARGET_API_MAC_OSX
584 hiPoint
.x
= clickLocation
.h
;
585 hiPoint
.y
= clickLocation
.v
;
586 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
587 clickLocation
.h
= (int)hiPoint
.x
;
588 clickLocation
.v
= (int)hiPoint
.y
;
590 HandleControlClick( control
, clickLocation
,
591 modifiers
, (ControlActionUPP
) -1 ) ;
598 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
600 OSStatus result
= eventNotHandledErr
;
602 wxMacCarbonEvent
cEvent( event
) ;
604 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
605 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
607 switch( GetEventKind( event
) )
609 case kEventWindowActivated
:
611 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
612 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
613 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
614 wxevent
.SetEventObject(toplevelWindow
);
615 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
616 // we still sending an eventNotHandledErr in order to allow for default processing
619 case kEventWindowDeactivated
:
621 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
622 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
623 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
624 wxevent
.SetEventObject(toplevelWindow
);
625 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
626 // we still sending an eventNotHandledErr in order to allow for default processing
629 case kEventWindowShown
:
630 toplevelWindow
->Refresh() ;
633 case kEventWindowClose
:
634 toplevelWindow
->Close() ;
637 case kEventWindowBoundsChanged
:
639 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
640 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
641 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
642 if ( attributes
& kWindowBoundsChangeSizeChanged
)
644 // according to the other ports we handle this within the OS level
645 // resize event, not within a wxSizeEvent
646 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
650 frame
->PositionStatusBar();
653 frame
->PositionToolBar();
657 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
658 event
.SetEventObject( toplevelWindow
) ;
660 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
662 if ( attributes
& kWindowBoundsChangeOriginChanged
)
664 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
665 event
.SetEventObject( toplevelWindow
) ;
666 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
671 case kEventWindowBoundsChanging
:
673 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
674 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
676 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
678 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
679 int left
, top
, right
, bottom
;
680 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
681 wxRect
r( newRect
.left
- left
, newRect
.top
- top
,
682 newRect
.right
- newRect
.left
+ left
+ right
, newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
683 // this is a EVT_SIZING not a EVT_SIZE type !
684 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
685 wxevent
.SetEventObject( toplevelWindow
) ;
687 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
688 adjustR
= wxevent
.GetRect() ;
690 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
691 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
692 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
693 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
694 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
695 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
696 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
697 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
698 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
699 if ( !EqualRect( &newRect
, &adjustedRect
) )
700 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
712 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
714 OSStatus result
= eventNotHandledErr
;
716 switch ( GetEventClass( event
) )
718 case kEventClassKeyboard
:
719 result
= KeyboardEventHandler( handler
, event
, data
) ;
721 case kEventClassTextInput
:
722 result
= TextInputEventHandler( handler
, event
, data
) ;
724 case kEventClassWindow
:
725 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
727 case kEventClassMouse
:
728 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
736 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
738 // ---------------------------------------------------------------------------
739 // wxWindowMac utility functions
740 // ---------------------------------------------------------------------------
742 // Find an item given the Macintosh Window Reference
744 #if KEY_wxList_DEPRECATED
745 wxList
wxWinMacWindowList(wxKEY_INTEGER
);
746 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
748 wxNode
*node
= wxWinMacWindowList
.Find((long)inWindowRef
);
751 return (wxTopLevelWindowMac
*)node
->GetData();
754 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
755 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
757 // adding NULL WindowRef is (first) surely a result of an error and
758 // (secondly) breaks menu command processing
759 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
761 if ( !wxWinMacWindowList
.Find((long)inWindowRef
) )
762 wxWinMacWindowList
.Append((long)inWindowRef
, win
);
765 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
766 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
768 wxWinMacWindowList
.DeleteObject(win
);
772 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
774 static MacWindowMap wxWinMacWindowList
;
776 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
778 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
780 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
783 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
784 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
786 // adding NULL WindowRef is (first) surely a result of an error and
788 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
790 wxWinMacWindowList
[inWindowRef
] = win
;
793 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
794 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
796 MacWindowMap::iterator it
;
797 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
799 if ( it
->second
== win
)
801 wxWinMacWindowList
.erase(it
);
806 #endif // deprecated wxList
808 // ----------------------------------------------------------------------------
809 // wxTopLevelWindowMac creation
810 // ----------------------------------------------------------------------------
812 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
820 void wxTopLevelWindowMac::Init()
823 m_maximizeOnShow
= FALSE
;
825 #if TARGET_API_MAC_OSX
826 m_macUsesCompositing
= TRUE
;
828 m_macUsesCompositing
= FALSE
;
830 m_macEventHandler
= NULL
;
831 m_macFullScreenData
= NULL
;
834 class wxMacDeferredWindowDeleter
: public wxObject
837 wxMacDeferredWindowDeleter( WindowRef windowRef
)
839 m_macWindow
= windowRef
;
841 virtual ~wxMacDeferredWindowDeleter()
843 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
846 WindowRef m_macWindow
;
849 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
851 const wxString
& title
,
855 const wxString
& name
)
860 m_windowStyle
= style
;
864 m_windowId
= id
== -1 ? NewControlId() : id
;
865 wxWindow::SetTitle( title
) ;
867 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
869 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
871 wxTopLevelWindows
.Append(this);
874 parent
->AddChild(this);
879 wxTopLevelWindowMac::~wxTopLevelWindowMac()
883 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
884 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
887 if ( m_macEventHandler
)
889 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
890 m_macEventHandler
= NULL
;
893 wxRemoveMacWindowAssociation( this ) ;
895 if ( wxModelessWindows
.Find(this) )
896 wxModelessWindows
.DeleteObject(this);
898 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
900 m_macFullScreenData
= NULL
;
904 // ----------------------------------------------------------------------------
905 // wxTopLevelWindowMac maximize/minimize
906 // ----------------------------------------------------------------------------
908 void wxTopLevelWindowMac::Maximize(bool maximize
)
910 wxMacPortStateHelper
help( (GrafPtr
) GetWindowPort( (WindowRef
) m_macWindow
) ) ;
911 wxMacWindowClipper
clip (this);
912 ZoomWindow( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, false ) ;
915 bool wxTopLevelWindowMac::IsMaximized() const
917 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
920 void wxTopLevelWindowMac::Iconize(bool iconize
)
922 if ( IsWindowCollapsable((WindowRef
)m_macWindow
) )
923 CollapseWindow((WindowRef
)m_macWindow
, iconize
) ;
926 bool wxTopLevelWindowMac::IsIconized() const
928 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
931 void wxTopLevelWindowMac::Restore()
933 // not available on mac
936 // ----------------------------------------------------------------------------
937 // wxTopLevelWindowMac misc
938 // ----------------------------------------------------------------------------
940 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
942 return wxPoint(0,0) ;
945 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
948 wxTopLevelWindowBase::SetIcon(icon
);
951 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
953 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
955 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
957 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
961 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
963 if ( m_macEventHandler
!= NULL
)
965 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
967 InstallWindowEventHandler(MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
968 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
971 void wxTopLevelWindowMac::MacCreateRealWindow( const wxString
& title
,
975 const wxString
& name
)
977 OSStatus err
= noErr
;
979 m_windowStyle
= style
;
989 wxRect display
= wxGetClientDisplayRect() ;
991 if ( x
== wxDefaultPosition
.x
)
994 if ( y
== wxDefaultPosition
.y
)
997 int w
= WidthDefault(size
.x
);
998 int h
= HeightDefault(size
.y
);
1000 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1002 // translate the window attributes in the appropriate window class and attributes
1004 WindowClass wclass
= 0;
1005 WindowAttributes attr
= kWindowNoAttributes
;
1007 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1010 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1011 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1012 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1015 wclass
= kFloatingWindowClass
;
1016 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1018 attr
|= kWindowSideTitlebarAttribute
;
1023 wclass
= kPlainWindowClass
;
1026 else if ( HasFlag( wxCAPTION
) )
1028 wclass
= kDocumentWindowClass
;
1030 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1031 else if ( HasFlag( wxFRAME_DRAWER
) )
1033 wclass
= kDrawerWindowClass
;
1034 // Should this be left for compositing check below?
1035 // CreateNewWindow will fail without it, should wxDrawerWindow turn
1036 // on compositing before calling MacCreateRealWindow?
1037 attr
|= kWindowCompositingAttribute
;// | kWindowStandardHandlerAttribute;
1039 #endif //10.2 and up
1042 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1043 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1045 wclass
= kDocumentWindowClass
;
1049 wclass
= kPlainWindowClass
;
1053 if ( HasFlag( wxMINIMIZE_BOX
) )
1055 attr
|= kWindowCollapseBoxAttribute
;
1057 if ( HasFlag( wxMAXIMIZE_BOX
) )
1059 attr
|= kWindowFullZoomAttribute
;
1061 if ( HasFlag( wxRESIZE_BORDER
) )
1063 attr
|= kWindowResizableAttribute
;
1065 if ( HasFlag( wxCLOSE_BOX
) )
1067 attr
|= kWindowCloseBoxAttribute
;
1070 if (UMAGetSystemVersion() >= 0x1000)
1072 // turn on live resizing (OS X only)
1073 attr
|= kWindowLiveResizeAttribute
;
1076 if (HasFlag(wxSTAY_ON_TOP
))
1077 wclass
= kUtilityWindowClass
;
1079 #if TARGET_API_MAC_OSX
1080 attr
|= kWindowCompositingAttribute
;
1083 if ( HasFlag(wxFRAME_SHAPED
) )
1085 WindowDefSpec customWindowDefSpec
;
1086 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1087 customWindowDefSpec
.u
.defProc
= NewWindowDefUPP(wxShapedMacWindowDef
);
1089 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1090 attr
, &theBoundsRect
,
1091 (WindowRef
*) &m_macWindow
);
1095 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1098 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1100 // the create commands are only for content rect, so we have to set the size again as
1102 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1104 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1105 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1106 m_peer
= new wxMacControl() ;
1107 #if TARGET_API_MAC_OSX
1108 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1109 // the content view, so we have to retrieve it explicitely
1110 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1111 m_peer
->GetControlRefAddr() ) ;
1112 if ( !m_peer
->Ok() )
1114 // compatibility mode fallback
1115 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1118 ::CreateRootControl( (WindowRef
)m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1120 // the root control level handleer
1121 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1123 // the frame window event handler
1124 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1125 MacInstallTopLevelWindowEventHandler() ;
1129 if ( HasFlag(wxFRAME_SHAPED
) )
1131 // default shape matches the window size
1132 wxRegion
rgn(0, 0, w
, h
);
1136 wxWindowCreateEvent
event(this);
1137 GetEventHandler()->ProcessEvent(event
);
1140 void wxTopLevelWindowMac::ClearBackground()
1142 wxWindow::ClearBackground() ;
1145 // Raise the window to the top of the Z order
1146 void wxTopLevelWindowMac::Raise()
1148 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1151 // Lower the window to the bottom of the Z order
1152 void wxTopLevelWindowMac::Lower()
1154 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1158 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1160 if(s_macDeactivateWindow
)
1162 wxLogDebug(wxT("Doing delayed deactivation of %p"),s_macDeactivateWindow
);
1163 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1167 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1169 // wxLogDebug(wxT("TopLevel=%p::MacActivate"),this);
1171 if(s_macDeactivateWindow
==this)
1172 s_macDeactivateWindow
=NULL
;
1173 MacDelayedDeactivation(timestamp
);
1174 MacPropagateHiliteChanged() ;
1177 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1179 wxWindow::SetTitle( title
) ;
1180 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1183 bool wxTopLevelWindowMac::Show(bool show
)
1185 if ( !wxTopLevelWindowBase::Show(show
) )
1190 #if wxUSE_SYSTEM_OPTIONS //code contributed by Ryan Wilcox December 18, 2003
1191 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1193 ::ShowWindow( (WindowRef
)m_macWindow
);
1198 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowShowTransitionAction
,nil
);
1200 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1201 // as apps expect a size event to occur at this moment
1202 wxSizeEvent
event( GetSize() , m_windowId
);
1203 event
.SetEventObject(this);
1204 GetEventHandler()->ProcessEvent(event
);
1208 #if wxUSE_SYSTEM_OPTIONS
1209 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1211 ::HideWindow((WindowRef
) m_macWindow
);
1216 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowHideTransitionAction
,nil
);
1220 MacPropagateVisibilityChanged() ;
1225 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1229 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1231 data
= new FullScreenData() ;
1233 m_macFullScreenData
= data
;
1234 data
->m_position
= GetPosition() ;
1235 data
->m_size
= GetSize() ;
1237 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1241 int left
, top
, right
, bottom
;
1242 wxRect client
= wxGetClientDisplayRect() ;
1251 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1253 if ( style
& wxFULLSCREEN_NOCAPTION
)
1258 if ( style
& wxFULLSCREEN_NOBORDER
)
1264 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1268 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1272 SetSize( x
, y
, w
, h
) ;
1277 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1278 SetPosition( data
->m_position
) ;
1279 SetSize( data
->m_size
) ;
1281 m_macFullScreenData
= NULL
;
1286 bool wxTopLevelWindowMac::IsFullScreen() const
1288 return m_macFullScreenData
!= NULL
;
1291 // we are still using coordinates of the content view, todo switch to structure bounds
1293 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1297 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1298 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1300 left
= content
.left
- structure
.left
;
1301 top
= content
.top
- structure
.top
;
1302 right
= structure
.right
- content
.right
;
1303 bottom
= structure
.bottom
- content
.bottom
;
1306 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1308 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1309 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1312 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1315 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1316 if(x
) *x
= bounds
.left
;
1317 if(y
) *y
= bounds
.top
;
1319 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1322 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1323 if(width
) *width
= bounds
.right
- bounds
.left
;
1324 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1327 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1330 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1331 if(width
) *width
= bounds
.right
- bounds
.left
;
1332 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1335 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1337 #if TARGET_API_MAC_OSX
1339 GetWindowAttributes((WindowRef
) m_macWindow
, &attr
) ;
1340 wxASSERT_MSG( attr
& kWindowCompositingAttribute
,
1341 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1343 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1344 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1348 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1350 #if TARGET_API_MAC_OSX
1351 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1357 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1359 ChangeWindowAttributes ( (WindowRef
) m_macWindow
, attributesToSet
, attributesToClear
) ;
1362 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1365 GetWindowAttributes((WindowRef
) m_macWindow
, &attr
) ;
1369 // ---------------------------------------------------------------------------
1370 // Shape implementation
1371 // ---------------------------------------------------------------------------
1374 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1376 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
1377 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1379 // The empty region signifies that the shape should be removed from the
1381 if ( region
.IsEmpty() )
1383 wxSize sz
= GetClientSize();
1384 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1385 return SetShape(rgn
);
1388 // Make a copy of the region
1389 RgnHandle shapeRegion
= NewRgn();
1390 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1392 // Dispose of any shape region we may already have
1393 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1397 // Save the region so we can use it later
1398 SetWRefCon((WindowRef
)MacGetWindowRef(), (SInt32
)shapeRegion
);
1400 // Tell the window manager that the window has changed shape
1401 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1405 // ---------------------------------------------------------------------------
1406 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1407 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1408 // ---------------------------------------------------------------------------
1410 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1412 GetWindowPortBounds(window
, inRect
);
1413 Point pt
= {inRect
->left
, inRect
->top
};
1414 QDLocalToGlobalPoint( GetWindowPort(window
) , &pt
) ;
1416 inRect
->left
= pt
.h
;
1417 inRect
->bottom
+= pt
.v
;
1418 inRect
->right
+= pt
.h
;
1422 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1424 /*------------------------------------------------------
1425 Define which options your custom window supports.
1426 --------------------------------------------------------*/
1427 //just enable everything for our demo
1428 *(OptionBits
*)param
=//kWindowCanGrow|
1430 //kWindowCanCollapse|
1431 //kWindowCanGetWindowRegion|
1432 //kWindowHasTitleBar|
1433 //kWindowSupportsDragHilite|
1434 kWindowCanDrawInCurrentPort
|
1435 //kWindowCanMeasureTitle|
1436 kWindowWantsDisposeAtProcessDeath
|
1437 kWindowSupportsGetGrowImageRegion
|
1438 kWindowDefSupportsColorGrafPort
;
1442 // The content region is left as a rectangle matching the window size, this is
1443 // so the origin in the paint event, and etc. still matches what the
1444 // programmer expects.
1445 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1448 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1452 wxShapedMacWindowGetPos(window
, &r
) ;
1453 RectRgn( rgn
, &r
) ;
1457 // The structure region is set to the shape given to the SetShape method.
1458 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1460 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1466 wxShapedMacWindowGetPos(window
, &windowRect
); //how big is the window
1467 CopyRgn(cachedRegion
, rgn
); //make a copy of our cached region
1468 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1469 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1475 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1477 GetWindowRegionPtr rgnRec
=(GetWindowRegionPtr
)param
;
1479 switch(rgnRec
->regionCode
)
1481 case kWindowStructureRgn
:
1482 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1484 case kWindowContentRgn
:
1485 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1488 SetEmptyRgn(rgnRec
->winRgn
);
1495 static SInt32
wxShapedMacWindowHitTest(WindowRef window
,SInt32 param
)
1497 /*------------------------------------------------------
1498 Determine the region of the window which was hit
1499 --------------------------------------------------------*/
1501 static RgnHandle tempRgn
=nil
;
1506 SetPt(&hitPoint
,LoWord(param
),HiWord(param
));//get the point clicked
1508 //Mac OS 8.5 or later
1509 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1510 if (PtInRgn(hitPoint
, tempRgn
)) //in window content region?
1513 return wNoHit
;//no significant area was hit.
1517 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1521 case kWindowMsgHitTest
:
1522 return wxShapedMacWindowHitTest(window
,param
);
1524 case kWindowMsgGetFeatures
:
1525 return wxShapedMacWindowGetFeatures(window
,param
);
1527 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1528 case kWindowMsgGetRegion
:
1529 return wxShapedMacWindowGetRegion(window
,param
);
1535 // ---------------------------------------------------------------------------