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
.SetTimestamp(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 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
510 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
512 wxevent
.SetEventObject( currentMouseWindow
) ;
514 // make tooltips current
517 if ( wxevent
.GetEventType() == wxEVT_MOTION
518 || wxevent
.GetEventType() == wxEVT_ENTER_WINDOW
519 || wxevent
.GetEventType() == wxEVT_LEAVE_WINDOW
)
520 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
521 #endif // wxUSE_TOOLTIPS
522 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
524 if ((currentMouseWindowParent
!= NULL
) &&
525 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
526 currentMouseWindow
= NULL
;
532 // if the user code did _not_ handle the event, then perform the
533 // default processing
534 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
536 // ... that is set focus to this window
537 if (currentMouseWindow
->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
538 currentMouseWindow
->SetFocus();
541 ControlPartCode dummyPart
;
542 // if built-in find control is finding the wrong control (ie static box instead of overlaid
543 // button, we cannot let the standard handler do its job, but must handle manually
545 if ( ( cEvent
.GetKind() == kEventMouseDown
) &&
546 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
547 wxMacFindControlUnderMouse( windowMouseLocation
, window
, &dummyPart
) ) )
549 if ( currentMouseWindow
->MacIsReallyEnabled() )
551 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
552 Point clickLocation
= windowMouseLocation
;
553 #if TARGET_API_MAC_OSX
554 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
556 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
557 modifiers
, (ControlActionUPP
) -1 ) ;
559 if ((currentMouseWindowParent
!= NULL
) &&
560 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
561 currentMouseWindow
= NULL
;
566 if ( cEvent
.GetKind() == kEventMouseUp
&& wxTheApp
->s_captureWindow
)
568 wxTheApp
->s_captureWindow
= NULL
;
574 wxWindow
* cursorTarget
= currentMouseWindow
;
575 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
577 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
579 cursorTarget
= cursorTarget
->GetParent() ;
581 cursorPoint
+= cursorTarget
->GetPosition();
584 } // else if ( currentMouseWindow )
587 // don't mess with controls we don't know about
588 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
589 // so we try sending them the correct control directly
590 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
591 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
593 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
594 Point clickLocation
= windowMouseLocation
;
595 #if TARGET_API_MAC_OSX
597 hiPoint
.x
= clickLocation
.h
;
598 hiPoint
.y
= clickLocation
.v
;
599 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
600 clickLocation
.h
= (int)hiPoint
.x
;
601 clickLocation
.v
= (int)hiPoint
.y
;
603 HandleControlClick( control
, clickLocation
,
604 modifiers
, (ControlActionUPP
) -1 ) ;
611 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
613 OSStatus result
= eventNotHandledErr
;
615 wxMacCarbonEvent
cEvent( event
) ;
617 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
618 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
620 switch( GetEventKind( event
) )
622 case kEventWindowActivated
:
624 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
625 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
626 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
627 wxevent
.SetEventObject(toplevelWindow
);
628 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
629 // we still sending an eventNotHandledErr in order to allow for default processing
632 case kEventWindowDeactivated
:
634 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
635 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
636 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
637 wxevent
.SetEventObject(toplevelWindow
);
638 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
639 // we still sending an eventNotHandledErr in order to allow for default processing
642 case kEventWindowShown
:
643 toplevelWindow
->Refresh() ;
646 case kEventWindowClose
:
647 toplevelWindow
->Close() ;
650 case kEventWindowBoundsChanged
:
652 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
653 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
654 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
655 if ( attributes
& kWindowBoundsChangeSizeChanged
)
657 // according to the other ports we handle this within the OS level
658 // resize event, not within a wxSizeEvent
659 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
663 frame
->PositionStatusBar();
666 frame
->PositionToolBar();
670 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
671 event
.SetEventObject( toplevelWindow
) ;
673 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
675 if ( attributes
& kWindowBoundsChangeOriginChanged
)
677 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
678 event
.SetEventObject( toplevelWindow
) ;
679 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
684 case kEventWindowBoundsChanging
:
686 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
687 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
689 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
691 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
692 int left
, top
, right
, bottom
;
693 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
694 wxRect
r( newRect
.left
- left
, newRect
.top
- top
,
695 newRect
.right
- newRect
.left
+ left
+ right
, newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
696 // this is a EVT_SIZING not a EVT_SIZE type !
697 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
698 wxevent
.SetEventObject( toplevelWindow
) ;
700 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
701 adjustR
= wxevent
.GetRect() ;
703 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
704 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
705 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
706 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
707 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
708 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
709 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
710 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
711 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
712 if ( !EqualRect( &newRect
, &adjustedRect
) )
713 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
725 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
727 OSStatus result
= eventNotHandledErr
;
729 switch ( GetEventClass( event
) )
731 case kEventClassKeyboard
:
732 result
= KeyboardEventHandler( handler
, event
, data
) ;
734 case kEventClassTextInput
:
735 result
= TextInputEventHandler( handler
, event
, data
) ;
737 case kEventClassWindow
:
738 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
740 case kEventClassMouse
:
741 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
749 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
751 // ---------------------------------------------------------------------------
752 // wxWindowMac utility functions
753 // ---------------------------------------------------------------------------
755 // Find an item given the Macintosh Window Reference
757 #if KEY_wxList_DEPRECATED
758 wxList
wxWinMacWindowList(wxKEY_INTEGER
);
759 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
761 wxNode
*node
= wxWinMacWindowList
.Find((long)inWindowRef
);
764 return (wxTopLevelWindowMac
*)node
->GetData();
767 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
768 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
770 // adding NULL WindowRef is (first) surely a result of an error and
771 // (secondly) breaks menu command processing
772 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
774 if ( !wxWinMacWindowList
.Find((long)inWindowRef
) )
775 wxWinMacWindowList
.Append((long)inWindowRef
, win
);
778 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
779 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
781 wxWinMacWindowList
.DeleteObject(win
);
785 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
787 static MacWindowMap wxWinMacWindowList
;
789 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
791 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
793 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
796 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
797 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
799 // adding NULL WindowRef is (first) surely a result of an error and
801 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
803 wxWinMacWindowList
[inWindowRef
] = win
;
806 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
807 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
809 MacWindowMap::iterator it
;
810 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
812 if ( it
->second
== win
)
814 wxWinMacWindowList
.erase(it
);
819 #endif // deprecated wxList
821 // ----------------------------------------------------------------------------
822 // wxTopLevelWindowMac creation
823 // ----------------------------------------------------------------------------
825 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
833 void wxTopLevelWindowMac::Init()
836 m_maximizeOnShow
= FALSE
;
838 #if TARGET_API_MAC_OSX
839 m_macUsesCompositing
= TRUE
;
841 m_macUsesCompositing
= FALSE
;
843 m_macEventHandler
= NULL
;
844 m_macFullScreenData
= NULL
;
847 class wxMacDeferredWindowDeleter
: public wxObject
850 wxMacDeferredWindowDeleter( WindowRef windowRef
)
852 m_macWindow
= windowRef
;
854 virtual ~wxMacDeferredWindowDeleter()
856 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
859 WindowRef m_macWindow
;
862 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
864 const wxString
& title
,
868 const wxString
& name
)
873 m_windowStyle
= style
;
877 m_windowId
= id
== -1 ? NewControlId() : id
;
878 wxWindow::SetTitle( title
) ;
880 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
882 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
884 wxTopLevelWindows
.Append(this);
887 parent
->AddChild(this);
892 wxTopLevelWindowMac::~wxTopLevelWindowMac()
896 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
897 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
900 if ( m_macEventHandler
)
902 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
903 m_macEventHandler
= NULL
;
906 wxRemoveMacWindowAssociation( this ) ;
908 if ( wxModelessWindows
.Find(this) )
909 wxModelessWindows
.DeleteObject(this);
911 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
913 m_macFullScreenData
= NULL
;
917 // ----------------------------------------------------------------------------
918 // wxTopLevelWindowMac maximize/minimize
919 // ----------------------------------------------------------------------------
921 void wxTopLevelWindowMac::Maximize(bool maximize
)
923 wxMacPortStateHelper
help( (GrafPtr
) GetWindowPort( (WindowRef
) m_macWindow
) ) ;
924 wxMacWindowClipper
clip (this);
925 ZoomWindow( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, false ) ;
928 bool wxTopLevelWindowMac::IsMaximized() const
930 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
933 void wxTopLevelWindowMac::Iconize(bool iconize
)
935 if ( IsWindowCollapsable((WindowRef
)m_macWindow
) )
936 CollapseWindow((WindowRef
)m_macWindow
, iconize
) ;
939 bool wxTopLevelWindowMac::IsIconized() const
941 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
944 void wxTopLevelWindowMac::Restore()
946 // not available on mac
949 // ----------------------------------------------------------------------------
950 // wxTopLevelWindowMac misc
951 // ----------------------------------------------------------------------------
953 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
955 return wxPoint(0,0) ;
958 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
961 wxTopLevelWindowBase::SetIcon(icon
);
964 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
966 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
968 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
970 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
974 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
976 if ( m_macEventHandler
!= NULL
)
978 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
980 InstallWindowEventHandler(MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
981 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
984 void wxTopLevelWindowMac::MacCreateRealWindow( const wxString
& title
,
988 const wxString
& name
)
990 OSStatus err
= noErr
;
992 m_windowStyle
= style
;
1002 wxRect display
= wxGetClientDisplayRect() ;
1004 if ( x
== wxDefaultPosition
.x
)
1007 if ( y
== wxDefaultPosition
.y
)
1010 int w
= WidthDefault(size
.x
);
1011 int h
= HeightDefault(size
.y
);
1013 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1015 // translate the window attributes in the appropriate window class and attributes
1017 WindowClass wclass
= 0;
1018 WindowAttributes attr
= kWindowNoAttributes
;
1019 WindowGroupRef group
= NULL
;
1021 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1024 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1025 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1026 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1029 wclass
= kFloatingWindowClass
;
1030 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1032 attr
|= kWindowSideTitlebarAttribute
;
1037 wclass
= kPlainWindowClass
;
1040 else if ( HasFlag( wxCAPTION
) )
1042 wclass
= kDocumentWindowClass
;
1044 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1045 else if ( HasFlag( wxFRAME_DRAWER
) )
1047 wclass
= kDrawerWindowClass
;
1048 // Should this be left for compositing check below?
1049 // CreateNewWindow will fail without it, should wxDrawerWindow turn
1050 // on compositing before calling MacCreateRealWindow?
1051 attr
|= kWindowCompositingAttribute
;// | kWindowStandardHandlerAttribute;
1053 #endif //10.2 and up
1056 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1057 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1059 wclass
= kDocumentWindowClass
;
1063 wclass
= kPlainWindowClass
;
1067 if ( HasFlag( wxMINIMIZE_BOX
) )
1069 attr
|= kWindowCollapseBoxAttribute
;
1071 if ( HasFlag( wxMAXIMIZE_BOX
) )
1073 attr
|= kWindowFullZoomAttribute
;
1075 if ( HasFlag( wxRESIZE_BORDER
) )
1077 attr
|= kWindowResizableAttribute
;
1079 if ( HasFlag( wxCLOSE_BOX
) )
1081 attr
|= kWindowCloseBoxAttribute
;
1084 if (UMAGetSystemVersion() >= 0x1000)
1086 // turn on live resizing (OS X only)
1087 attr
|= kWindowLiveResizeAttribute
;
1090 if ( HasFlag(wxSTAY_ON_TOP
) )
1092 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1095 #if TARGET_API_MAC_OSX
1096 attr
|= kWindowCompositingAttribute
;
1099 if ( HasFlag(wxFRAME_SHAPED
) )
1101 WindowDefSpec customWindowDefSpec
;
1102 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1103 customWindowDefSpec
.u
.defProc
= NewWindowDefUPP(wxShapedMacWindowDef
);
1105 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1106 attr
, &theBoundsRect
,
1107 (WindowRef
*) &m_macWindow
);
1111 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1114 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1115 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1117 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1119 // the create commands are only for content rect, so we have to set the size again as
1121 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1123 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1124 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1125 m_peer
= new wxMacControl() ;
1126 #if TARGET_API_MAC_OSX
1127 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1128 // the content view, so we have to retrieve it explicitely
1129 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1130 m_peer
->GetControlRefAddr() ) ;
1131 if ( !m_peer
->Ok() )
1133 // compatibility mode fallback
1134 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1137 ::CreateRootControl( (WindowRef
)m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1139 // the root control level handleer
1140 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1142 // the frame window event handler
1143 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1144 MacInstallTopLevelWindowEventHandler() ;
1148 if ( HasFlag(wxFRAME_SHAPED
) )
1150 // default shape matches the window size
1151 wxRegion
rgn(0, 0, w
, h
);
1155 wxWindowCreateEvent
event(this);
1156 GetEventHandler()->ProcessEvent(event
);
1159 void wxTopLevelWindowMac::ClearBackground()
1161 wxWindow::ClearBackground() ;
1164 // Raise the window to the top of the Z order
1165 void wxTopLevelWindowMac::Raise()
1167 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1170 // Lower the window to the bottom of the Z order
1171 void wxTopLevelWindowMac::Lower()
1173 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1177 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1179 if(s_macDeactivateWindow
)
1181 wxLogDebug(wxT("Doing delayed deactivation of %p"),s_macDeactivateWindow
);
1182 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1186 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1188 // wxLogDebug(wxT("TopLevel=%p::MacActivate"),this);
1190 if(s_macDeactivateWindow
==this)
1191 s_macDeactivateWindow
=NULL
;
1192 MacDelayedDeactivation(timestamp
);
1193 MacPropagateHiliteChanged() ;
1196 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1198 wxWindow::SetTitle( title
) ;
1199 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1202 bool wxTopLevelWindowMac::Show(bool show
)
1204 if ( !wxTopLevelWindowBase::Show(show
) )
1209 #if wxUSE_SYSTEM_OPTIONS //code contributed by Ryan Wilcox December 18, 2003
1210 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1212 ::ShowWindow( (WindowRef
)m_macWindow
);
1217 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowShowTransitionAction
,nil
);
1219 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1220 // as apps expect a size event to occur at this moment
1221 wxSizeEvent
event( GetSize() , m_windowId
);
1222 event
.SetEventObject(this);
1223 GetEventHandler()->ProcessEvent(event
);
1227 #if wxUSE_SYSTEM_OPTIONS
1228 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1230 ::HideWindow((WindowRef
) m_macWindow
);
1235 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowHideTransitionAction
,nil
);
1239 MacPropagateVisibilityChanged() ;
1244 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1248 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1250 data
= new FullScreenData() ;
1252 m_macFullScreenData
= data
;
1253 data
->m_position
= GetPosition() ;
1254 data
->m_size
= GetSize() ;
1256 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1260 int left
, top
, right
, bottom
;
1261 wxRect client
= wxGetClientDisplayRect() ;
1270 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1272 if ( style
& wxFULLSCREEN_NOCAPTION
)
1277 if ( style
& wxFULLSCREEN_NOBORDER
)
1283 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1287 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1291 SetSize( x
, y
, w
, h
) ;
1296 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1297 SetPosition( data
->m_position
) ;
1298 SetSize( data
->m_size
) ;
1300 m_macFullScreenData
= NULL
;
1305 bool wxTopLevelWindowMac::IsFullScreen() const
1307 return m_macFullScreenData
!= NULL
;
1310 // we are still using coordinates of the content view, todo switch to structure bounds
1312 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1316 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1317 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1319 left
= content
.left
- structure
.left
;
1320 top
= content
.top
- structure
.top
;
1321 right
= structure
.right
- content
.right
;
1322 bottom
= structure
.bottom
- content
.bottom
;
1325 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1327 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1328 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1331 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1334 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1335 if(x
) *x
= bounds
.left
;
1336 if(y
) *y
= bounds
.top
;
1338 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1341 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1342 if(width
) *width
= bounds
.right
- bounds
.left
;
1343 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1346 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1349 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1350 if(width
) *width
= bounds
.right
- bounds
.left
;
1351 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1354 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1356 #if TARGET_API_MAC_OSX
1358 GetWindowAttributes((WindowRef
) m_macWindow
, &attr
) ;
1359 wxASSERT_MSG( attr
& kWindowCompositingAttribute
,
1360 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1362 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1363 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1367 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1369 #if TARGET_API_MAC_OSX
1370 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1376 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1378 ChangeWindowAttributes ( (WindowRef
) m_macWindow
, attributesToSet
, attributesToClear
) ;
1381 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1384 GetWindowAttributes((WindowRef
) m_macWindow
, &attr
) ;
1388 // Attracts the users attention to this window if the application is
1389 // inactive (should be called when a background event occurs)
1391 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1394 DisposePtr( (Ptr
) ptr
) ;
1398 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1400 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1401 static wxMacNMUPP
nmupp( wxMacNMResponse
)
1403 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1404 notificationRequest
->qType
= nmType
;
1405 notificationRequest
->nmMark
= 1 ;
1406 notificationRequest
->nmIcon
= 0 ;
1407 notificationRequest
->nmSound
= 0 ;
1408 notificationRequest
->nmStr
= NULL
;
1409 notificationRequest
->nmResp
= nmupp
;
1410 verify_noerr( NMInstall( notificationRequest
) ) ;
1413 // ---------------------------------------------------------------------------
1414 // Shape implementation
1415 // ---------------------------------------------------------------------------
1418 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1420 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
1421 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1423 // The empty region signifies that the shape should be removed from the
1425 if ( region
.IsEmpty() )
1427 wxSize sz
= GetClientSize();
1428 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1429 return SetShape(rgn
);
1432 // Make a copy of the region
1433 RgnHandle shapeRegion
= NewRgn();
1434 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1436 // Dispose of any shape region we may already have
1437 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1441 // Save the region so we can use it later
1442 SetWRefCon((WindowRef
)MacGetWindowRef(), (SInt32
)shapeRegion
);
1444 // Tell the window manager that the window has changed shape
1445 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1449 // ---------------------------------------------------------------------------
1450 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1451 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1452 // ---------------------------------------------------------------------------
1454 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1456 GetWindowPortBounds(window
, inRect
);
1457 Point pt
= {inRect
->left
, inRect
->top
};
1458 QDLocalToGlobalPoint( GetWindowPort(window
) , &pt
) ;
1460 inRect
->left
= pt
.h
;
1461 inRect
->bottom
+= pt
.v
;
1462 inRect
->right
+= pt
.h
;
1466 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1468 /*------------------------------------------------------
1469 Define which options your custom window supports.
1470 --------------------------------------------------------*/
1471 //just enable everything for our demo
1472 *(OptionBits
*)param
=//kWindowCanGrow|
1474 //kWindowCanCollapse|
1475 //kWindowCanGetWindowRegion|
1476 //kWindowHasTitleBar|
1477 //kWindowSupportsDragHilite|
1478 kWindowCanDrawInCurrentPort
|
1479 //kWindowCanMeasureTitle|
1480 kWindowWantsDisposeAtProcessDeath
|
1481 kWindowSupportsGetGrowImageRegion
|
1482 kWindowDefSupportsColorGrafPort
;
1486 // The content region is left as a rectangle matching the window size, this is
1487 // so the origin in the paint event, and etc. still matches what the
1488 // programmer expects.
1489 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1492 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1496 wxShapedMacWindowGetPos(window
, &r
) ;
1497 RectRgn( rgn
, &r
) ;
1501 // The structure region is set to the shape given to the SetShape method.
1502 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1504 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1510 wxShapedMacWindowGetPos(window
, &windowRect
); //how big is the window
1511 CopyRgn(cachedRegion
, rgn
); //make a copy of our cached region
1512 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1513 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1519 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1521 GetWindowRegionPtr rgnRec
=(GetWindowRegionPtr
)param
;
1523 switch(rgnRec
->regionCode
)
1525 case kWindowStructureRgn
:
1526 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1528 case kWindowContentRgn
:
1529 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1532 SetEmptyRgn(rgnRec
->winRgn
);
1539 static SInt32
wxShapedMacWindowHitTest(WindowRef window
,SInt32 param
)
1541 /*------------------------------------------------------
1542 Determine the region of the window which was hit
1543 --------------------------------------------------------*/
1545 static RgnHandle tempRgn
=nil
;
1550 SetPt(&hitPoint
,LoWord(param
),HiWord(param
));//get the point clicked
1552 //Mac OS 8.5 or later
1553 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1554 if (PtInRgn(hitPoint
, tempRgn
)) //in window content region?
1557 return wNoHit
;//no significant area was hit.
1561 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1565 case kWindowMsgHitTest
:
1566 return wxShapedMacWindowHitTest(window
,param
);
1568 case kWindowMsgGetFeatures
:
1569 return wxShapedMacWindowGetFeatures(window
,param
);
1571 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1572 case kWindowMsgGetRegion
:
1573 return wxShapedMacWindowGetRegion(window
,param
);
1579 // ---------------------------------------------------------------------------