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
) ;
512 // make tooltips current
515 if ( wxevent
.GetEventType() == wxEVT_MOTION
516 || wxevent
.GetEventType() == wxEVT_ENTER_WINDOW
517 || wxevent
.GetEventType() == wxEVT_LEAVE_WINDOW
)
518 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
519 #endif // wxUSE_TOOLTIPS
520 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
524 // if the user code did _not_ handle the event, then perform the
525 // default processing
526 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
528 // ... that is set focus to this window
529 if (currentMouseWindow
->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
530 currentMouseWindow
->SetFocus();
533 ControlPartCode dummyPart
;
534 // if built-in find control is finding the wrong control (ie static box instead of overlaid
535 // button, we cannot let the standard handler do its job, but must handle manually
537 if ( ( cEvent
.GetKind() == kEventMouseDown
) &&
538 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
539 wxMacFindControlUnderMouse( windowMouseLocation
, window
, &dummyPart
) ) )
541 if ( currentMouseWindow
->MacIsReallyEnabled() )
543 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
544 Point clickLocation
= windowMouseLocation
;
545 #if TARGET_API_MAC_OSX
546 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
548 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
549 modifiers
, (ControlActionUPP
) -1 ) ;
554 if ( cEvent
.GetKind() == kEventMouseUp
&& wxTheApp
->s_captureWindow
)
556 wxTheApp
->s_captureWindow
= NULL
;
562 wxWindow
* cursorTarget
= currentMouseWindow
;
563 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
565 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
567 cursorTarget
= cursorTarget
->GetParent() ;
569 cursorPoint
+= cursorTarget
->GetPosition() ;
572 } // else if ( currentMouseWindow )
575 // don't mess with controls we don't know about
576 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
577 // so we try sending them the correct control directly
578 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
579 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
581 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
582 Point clickLocation
= windowMouseLocation
;
583 #if TARGET_API_MAC_OSX
585 hiPoint
.x
= clickLocation
.h
;
586 hiPoint
.y
= clickLocation
.v
;
587 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
588 clickLocation
.h
= (int)hiPoint
.x
;
589 clickLocation
.v
= (int)hiPoint
.y
;
591 HandleControlClick( control
, clickLocation
,
592 modifiers
, (ControlActionUPP
) -1 ) ;
599 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
601 OSStatus result
= eventNotHandledErr
;
603 wxMacCarbonEvent
cEvent( event
) ;
605 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
606 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
608 switch( GetEventKind( event
) )
610 case kEventWindowActivated
:
612 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
613 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
614 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
615 wxevent
.SetEventObject(toplevelWindow
);
616 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
617 // we still sending an eventNotHandledErr in order to allow for default processing
620 case kEventWindowDeactivated
:
622 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
623 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
624 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
625 wxevent
.SetEventObject(toplevelWindow
);
626 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
627 // we still sending an eventNotHandledErr in order to allow for default processing
630 case kEventWindowShown
:
631 toplevelWindow
->Refresh() ;
634 case kEventWindowClose
:
635 toplevelWindow
->Close() ;
638 case kEventWindowBoundsChanged
:
640 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
641 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
642 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
643 if ( attributes
& kWindowBoundsChangeSizeChanged
)
645 // according to the other ports we handle this within the OS level
646 // resize event, not within a wxSizeEvent
647 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
651 frame
->PositionStatusBar();
654 frame
->PositionToolBar();
658 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
659 event
.SetEventObject( toplevelWindow
) ;
661 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
663 if ( attributes
& kWindowBoundsChangeOriginChanged
)
665 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
666 event
.SetEventObject( toplevelWindow
) ;
667 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
672 case kEventWindowBoundsChanging
:
674 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
675 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
677 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
679 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
680 int left
, top
, right
, bottom
;
681 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
682 wxRect
r( newRect
.left
- left
, newRect
.top
- top
,
683 newRect
.right
- newRect
.left
+ left
+ right
, newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
684 // this is a EVT_SIZING not a EVT_SIZE type !
685 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
686 wxevent
.SetEventObject( toplevelWindow
) ;
688 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
689 adjustR
= wxevent
.GetRect() ;
691 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
692 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
693 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
694 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
695 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
696 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
697 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
698 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
699 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
700 if ( !EqualRect( &newRect
, &adjustedRect
) )
701 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
713 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
715 OSStatus result
= eventNotHandledErr
;
717 switch ( GetEventClass( event
) )
719 case kEventClassKeyboard
:
720 result
= KeyboardEventHandler( handler
, event
, data
) ;
722 case kEventClassTextInput
:
723 result
= TextInputEventHandler( handler
, event
, data
) ;
725 case kEventClassWindow
:
726 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
728 case kEventClassMouse
:
729 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
737 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
739 // ---------------------------------------------------------------------------
740 // wxWindowMac utility functions
741 // ---------------------------------------------------------------------------
743 // Find an item given the Macintosh Window Reference
745 #if KEY_wxList_DEPRECATED
746 wxList
wxWinMacWindowList(wxKEY_INTEGER
);
747 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
749 wxNode
*node
= wxWinMacWindowList
.Find((long)inWindowRef
);
752 return (wxTopLevelWindowMac
*)node
->GetData();
755 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
756 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
758 // adding NULL WindowRef is (first) surely a result of an error and
759 // (secondly) breaks menu command processing
760 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
762 if ( !wxWinMacWindowList
.Find((long)inWindowRef
) )
763 wxWinMacWindowList
.Append((long)inWindowRef
, win
);
766 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
767 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
769 wxWinMacWindowList
.DeleteObject(win
);
773 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
775 static MacWindowMap wxWinMacWindowList
;
777 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
779 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
781 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
784 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
785 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
787 // adding NULL WindowRef is (first) surely a result of an error and
789 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
791 wxWinMacWindowList
[inWindowRef
] = win
;
794 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
795 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
797 MacWindowMap::iterator it
;
798 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
800 if ( it
->second
== win
)
802 wxWinMacWindowList
.erase(it
);
807 #endif // deprecated wxList
809 // ----------------------------------------------------------------------------
810 // wxTopLevelWindowMac creation
811 // ----------------------------------------------------------------------------
813 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
821 void wxTopLevelWindowMac::Init()
824 m_maximizeOnShow
= FALSE
;
826 #if TARGET_API_MAC_OSX
827 m_macUsesCompositing
= TRUE
;
829 m_macUsesCompositing
= FALSE
;
831 m_macEventHandler
= NULL
;
832 m_macFullScreenData
= NULL
;
835 class wxMacDeferredWindowDeleter
: public wxObject
838 wxMacDeferredWindowDeleter( WindowRef windowRef
)
840 m_macWindow
= windowRef
;
842 virtual ~wxMacDeferredWindowDeleter()
844 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
847 WindowRef m_macWindow
;
850 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
852 const wxString
& title
,
856 const wxString
& name
)
861 m_windowStyle
= style
;
865 m_windowId
= id
== -1 ? NewControlId() : id
;
866 wxWindow::SetTitle( title
) ;
868 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
870 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
872 wxTopLevelWindows
.Append(this);
875 parent
->AddChild(this);
880 wxTopLevelWindowMac::~wxTopLevelWindowMac()
884 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
885 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
888 if ( m_macEventHandler
)
890 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
891 m_macEventHandler
= NULL
;
894 wxRemoveMacWindowAssociation( this ) ;
896 if ( wxModelessWindows
.Find(this) )
897 wxModelessWindows
.DeleteObject(this);
899 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
901 m_macFullScreenData
= NULL
;
905 // ----------------------------------------------------------------------------
906 // wxTopLevelWindowMac maximize/minimize
907 // ----------------------------------------------------------------------------
909 void wxTopLevelWindowMac::Maximize(bool maximize
)
911 wxMacPortStateHelper
help( (GrafPtr
) GetWindowPort( (WindowRef
) m_macWindow
) ) ;
912 wxMacWindowClipper
clip (this);
913 ZoomWindow( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, false ) ;
916 bool wxTopLevelWindowMac::IsMaximized() const
918 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
921 void wxTopLevelWindowMac::Iconize(bool iconize
)
923 if ( IsWindowCollapsable((WindowRef
)m_macWindow
) )
924 CollapseWindow((WindowRef
)m_macWindow
, iconize
) ;
927 bool wxTopLevelWindowMac::IsIconized() const
929 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
932 void wxTopLevelWindowMac::Restore()
934 // not available on mac
937 // ----------------------------------------------------------------------------
938 // wxTopLevelWindowMac misc
939 // ----------------------------------------------------------------------------
941 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
943 return wxPoint(0,0) ;
946 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
949 wxTopLevelWindowBase::SetIcon(icon
);
952 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
954 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
956 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
958 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
962 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
964 if ( m_macEventHandler
!= NULL
)
966 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
968 InstallWindowEventHandler(MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
969 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
972 void wxTopLevelWindowMac::MacCreateRealWindow( const wxString
& title
,
976 const wxString
& name
)
978 OSStatus err
= noErr
;
980 m_windowStyle
= style
;
990 wxRect display
= wxGetClientDisplayRect() ;
992 if ( x
== wxDefaultPosition
.x
)
995 if ( y
== wxDefaultPosition
.y
)
998 int w
= WidthDefault(size
.x
);
999 int h
= HeightDefault(size
.y
);
1001 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1003 // translate the window attributes in the appropriate window class and attributes
1005 WindowClass wclass
= 0;
1006 WindowAttributes attr
= kWindowNoAttributes
;
1007 WindowGroupRef group
= NULL
;
1009 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1012 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1013 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1014 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1017 wclass
= kFloatingWindowClass
;
1018 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1020 attr
|= kWindowSideTitlebarAttribute
;
1025 wclass
= kPlainWindowClass
;
1028 else if ( HasFlag( wxCAPTION
) )
1030 wclass
= kDocumentWindowClass
;
1032 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1033 else if ( HasFlag( wxFRAME_DRAWER
) )
1035 wclass
= kDrawerWindowClass
;
1036 // Should this be left for compositing check below?
1037 // CreateNewWindow will fail without it, should wxDrawerWindow turn
1038 // on compositing before calling MacCreateRealWindow?
1039 attr
|= kWindowCompositingAttribute
;// | kWindowStandardHandlerAttribute;
1041 #endif //10.2 and up
1044 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1045 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1047 wclass
= kDocumentWindowClass
;
1051 wclass
= kPlainWindowClass
;
1055 if ( HasFlag( wxMINIMIZE_BOX
) )
1057 attr
|= kWindowCollapseBoxAttribute
;
1059 if ( HasFlag( wxMAXIMIZE_BOX
) )
1061 attr
|= kWindowFullZoomAttribute
;
1063 if ( HasFlag( wxRESIZE_BORDER
) )
1065 attr
|= kWindowResizableAttribute
;
1067 if ( HasFlag( wxCLOSE_BOX
) )
1069 attr
|= kWindowCloseBoxAttribute
;
1072 if (UMAGetSystemVersion() >= 0x1000)
1074 // turn on live resizing (OS X only)
1075 attr
|= kWindowLiveResizeAttribute
;
1078 if ( HasFlag(wxSTAY_ON_TOP
) )
1080 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1083 #if TARGET_API_MAC_OSX
1084 attr
|= kWindowCompositingAttribute
;
1087 if ( HasFlag(wxFRAME_SHAPED
) )
1089 WindowDefSpec customWindowDefSpec
;
1090 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1091 customWindowDefSpec
.u
.defProc
= NewWindowDefUPP(wxShapedMacWindowDef
);
1093 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1094 attr
, &theBoundsRect
,
1095 (WindowRef
*) &m_macWindow
);
1099 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1102 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1103 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1105 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1107 // the create commands are only for content rect, so we have to set the size again as
1109 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1111 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1112 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1113 m_peer
= new wxMacControl() ;
1114 #if TARGET_API_MAC_OSX
1115 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1116 // the content view, so we have to retrieve it explicitely
1117 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1118 m_peer
->GetControlRefAddr() ) ;
1119 if ( !m_peer
->Ok() )
1121 // compatibility mode fallback
1122 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1125 ::CreateRootControl( (WindowRef
)m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1127 // the root control level handleer
1128 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1130 // the frame window event handler
1131 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1132 MacInstallTopLevelWindowEventHandler() ;
1136 if ( HasFlag(wxFRAME_SHAPED
) )
1138 // default shape matches the window size
1139 wxRegion
rgn(0, 0, w
, h
);
1143 wxWindowCreateEvent
event(this);
1144 GetEventHandler()->ProcessEvent(event
);
1147 void wxTopLevelWindowMac::ClearBackground()
1149 wxWindow::ClearBackground() ;
1152 // Raise the window to the top of the Z order
1153 void wxTopLevelWindowMac::Raise()
1155 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1158 // Lower the window to the bottom of the Z order
1159 void wxTopLevelWindowMac::Lower()
1161 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1165 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1167 if(s_macDeactivateWindow
)
1169 wxLogDebug(wxT("Doing delayed deactivation of %p"),s_macDeactivateWindow
);
1170 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1174 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1176 // wxLogDebug(wxT("TopLevel=%p::MacActivate"),this);
1178 if(s_macDeactivateWindow
==this)
1179 s_macDeactivateWindow
=NULL
;
1180 MacDelayedDeactivation(timestamp
);
1181 MacPropagateHiliteChanged() ;
1184 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1186 wxWindow::SetTitle( title
) ;
1187 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1190 bool wxTopLevelWindowMac::Show(bool show
)
1192 if ( !wxTopLevelWindowBase::Show(show
) )
1197 #if wxUSE_SYSTEM_OPTIONS //code contributed by Ryan Wilcox December 18, 2003
1198 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1200 ::ShowWindow( (WindowRef
)m_macWindow
);
1205 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowShowTransitionAction
,nil
);
1207 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1208 // as apps expect a size event to occur at this moment
1209 wxSizeEvent
event( GetSize() , m_windowId
);
1210 event
.SetEventObject(this);
1211 GetEventHandler()->ProcessEvent(event
);
1215 #if wxUSE_SYSTEM_OPTIONS
1216 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1218 ::HideWindow((WindowRef
) m_macWindow
);
1223 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowHideTransitionAction
,nil
);
1227 MacPropagateVisibilityChanged() ;
1232 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1236 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1238 data
= new FullScreenData() ;
1240 m_macFullScreenData
= data
;
1241 data
->m_position
= GetPosition() ;
1242 data
->m_size
= GetSize() ;
1244 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1248 int left
, top
, right
, bottom
;
1249 wxRect client
= wxGetClientDisplayRect() ;
1258 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1260 if ( style
& wxFULLSCREEN_NOCAPTION
)
1265 if ( style
& wxFULLSCREEN_NOBORDER
)
1271 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1275 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1279 SetSize( x
, y
, w
, h
) ;
1284 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1285 SetPosition( data
->m_position
) ;
1286 SetSize( data
->m_size
) ;
1288 m_macFullScreenData
= NULL
;
1293 bool wxTopLevelWindowMac::IsFullScreen() const
1295 return m_macFullScreenData
!= NULL
;
1298 // we are still using coordinates of the content view, todo switch to structure bounds
1300 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1304 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1305 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1307 left
= content
.left
- structure
.left
;
1308 top
= content
.top
- structure
.top
;
1309 right
= structure
.right
- content
.right
;
1310 bottom
= structure
.bottom
- content
.bottom
;
1313 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1315 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1316 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1319 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1322 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1323 if(x
) *x
= bounds
.left
;
1324 if(y
) *y
= bounds
.top
;
1326 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1329 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1330 if(width
) *width
= bounds
.right
- bounds
.left
;
1331 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1334 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1337 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1338 if(width
) *width
= bounds
.right
- bounds
.left
;
1339 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1342 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1344 #if TARGET_API_MAC_OSX
1346 GetWindowAttributes((WindowRef
) m_macWindow
, &attr
) ;
1347 wxASSERT_MSG( attr
& kWindowCompositingAttribute
,
1348 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1350 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1351 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1355 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1357 #if TARGET_API_MAC_OSX
1358 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1364 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1366 ChangeWindowAttributes ( (WindowRef
) m_macWindow
, attributesToSet
, attributesToClear
) ;
1369 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1372 GetWindowAttributes((WindowRef
) m_macWindow
, &attr
) ;
1376 // Attracts the users attention to this window if the application is
1377 // inactive (should be called when a background event occurs)
1379 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1382 DisposePtr( (Ptr
) ptr
) ;
1386 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1388 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1389 static wxMacNMUPP
nmupp( wxMacNMResponse
)
1391 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1392 notificationRequest
->qType
= nmType
;
1393 notificationRequest
->nmMark
= 1 ;
1394 notificationRequest
->nmIcon
= 0 ;
1395 notificationRequest
->nmSound
= 0 ;
1396 notificationRequest
->nmStr
= NULL
;
1397 notificationRequest
->nmResp
= nmupp
;
1398 verify_noerr( NMInstall( notificationRequest
) ) ;
1401 // ---------------------------------------------------------------------------
1402 // Shape implementation
1403 // ---------------------------------------------------------------------------
1406 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1408 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
1409 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1411 // The empty region signifies that the shape should be removed from the
1413 if ( region
.IsEmpty() )
1415 wxSize sz
= GetClientSize();
1416 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1417 return SetShape(rgn
);
1420 // Make a copy of the region
1421 RgnHandle shapeRegion
= NewRgn();
1422 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1424 // Dispose of any shape region we may already have
1425 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1429 // Save the region so we can use it later
1430 SetWRefCon((WindowRef
)MacGetWindowRef(), (SInt32
)shapeRegion
);
1432 // Tell the window manager that the window has changed shape
1433 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1437 // ---------------------------------------------------------------------------
1438 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1439 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1440 // ---------------------------------------------------------------------------
1442 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1444 GetWindowPortBounds(window
, inRect
);
1445 Point pt
= {inRect
->left
, inRect
->top
};
1446 QDLocalToGlobalPoint( GetWindowPort(window
) , &pt
) ;
1448 inRect
->left
= pt
.h
;
1449 inRect
->bottom
+= pt
.v
;
1450 inRect
->right
+= pt
.h
;
1454 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1456 /*------------------------------------------------------
1457 Define which options your custom window supports.
1458 --------------------------------------------------------*/
1459 //just enable everything for our demo
1460 *(OptionBits
*)param
=//kWindowCanGrow|
1462 //kWindowCanCollapse|
1463 //kWindowCanGetWindowRegion|
1464 //kWindowHasTitleBar|
1465 //kWindowSupportsDragHilite|
1466 kWindowCanDrawInCurrentPort
|
1467 //kWindowCanMeasureTitle|
1468 kWindowWantsDisposeAtProcessDeath
|
1469 kWindowSupportsGetGrowImageRegion
|
1470 kWindowDefSupportsColorGrafPort
;
1474 // The content region is left as a rectangle matching the window size, this is
1475 // so the origin in the paint event, and etc. still matches what the
1476 // programmer expects.
1477 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1480 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1484 wxShapedMacWindowGetPos(window
, &r
) ;
1485 RectRgn( rgn
, &r
) ;
1489 // The structure region is set to the shape given to the SetShape method.
1490 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1492 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1498 wxShapedMacWindowGetPos(window
, &windowRect
); //how big is the window
1499 CopyRgn(cachedRegion
, rgn
); //make a copy of our cached region
1500 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1501 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1507 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1509 GetWindowRegionPtr rgnRec
=(GetWindowRegionPtr
)param
;
1511 switch(rgnRec
->regionCode
)
1513 case kWindowStructureRgn
:
1514 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1516 case kWindowContentRgn
:
1517 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1520 SetEmptyRgn(rgnRec
->winRgn
);
1527 static SInt32
wxShapedMacWindowHitTest(WindowRef window
,SInt32 param
)
1529 /*------------------------------------------------------
1530 Determine the region of the window which was hit
1531 --------------------------------------------------------*/
1533 static RgnHandle tempRgn
=nil
;
1538 SetPt(&hitPoint
,LoWord(param
),HiWord(param
));//get the point clicked
1540 //Mac OS 8.5 or later
1541 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1542 if (PtInRgn(hitPoint
, tempRgn
)) //in window content region?
1545 return wNoHit
;//no significant area was hit.
1549 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1553 case kWindowMsgHitTest
:
1554 return wxShapedMacWindowHitTest(window
,param
);
1556 case kWindowMsgGetFeatures
:
1557 return wxShapedMacWindowGetFeatures(window
,param
);
1559 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1560 case kWindowMsgGetRegion
:
1561 return wxShapedMacWindowGetRegion(window
,param
);
1567 // ---------------------------------------------------------------------------