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 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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"
39 #include "wx/control.h"
42 #include "wx/mac/uma.h"
43 #include "wx/mac/aga.h"
45 #include "wx/tooltip.h"
47 #if wxUSE_SYSTEM_OPTIONS
48 #include "wx/sysopt.h"
51 #include <ToolUtils.h>
54 #include "wx/mac/private.h"
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 // list of all frames and modeless dialogs
61 wxWindowList wxModelessWindows
;
63 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
65 // ============================================================================
66 // wxTopLevelWindowMac implementation
67 // ============================================================================
69 BEGIN_EVENT_TABLE(wxTopLevelWindowMac
, wxTopLevelWindowBase
)
73 // ---------------------------------------------------------------------------
75 // ---------------------------------------------------------------------------
77 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
79 static const EventTypeSpec eventList
[] =
81 // TODO remove control related event like key and mouse (except for WindowLeave events)
83 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
85 { kEventClassKeyboard
, kEventRawKeyDown
} ,
86 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
87 { kEventClassKeyboard
, kEventRawKeyUp
} ,
88 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
91 { kEventClassWindow
, kEventWindowShown
} ,
92 { kEventClassWindow
, kEventWindowActivated
} ,
93 { kEventClassWindow
, kEventWindowDeactivated
} ,
94 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
95 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
96 { kEventClassWindow
, kEventWindowClose
} ,
98 // we have to catch these events on the toplevel window level, as controls don't get the
99 // raw mouse events anymore
101 { kEventClassMouse
, kEventMouseDown
} ,
102 { kEventClassMouse
, kEventMouseUp
} ,
103 { kEventClassMouse
, kEventMouseWheelMoved
} ,
104 { kEventClassMouse
, kEventMouseMoved
} ,
105 { kEventClassMouse
, kEventMouseDragged
} ,
108 static pascal OSStatus
TextInputEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
110 OSStatus result
= eventNotHandledErr
;
112 wxWindow
* focus
= wxWindow::FindFocus() ;
120 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent
) ;
122 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
,sizeof(char), NULL
,&charCode
);
123 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
124 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
125 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
126 sizeof( Point
), NULL
, &point
);
128 switch ( GetEventKind( event
) )
130 case kEventTextInputUnicodeForKeyEvent
:
131 // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not
132 // get its own kEventTextInputUnicodeForKeyEvent, so we route back the
133 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
136 ControlRef macControl
= (ControlRef
) control
->GetHandle() ;
139 ::HandleControlKey( macControl
, keyCode
, charCode
, modifiers
) ;
144 // this may lead to double events sent to a window in case all handlers have skipped the key down event
145 UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
146 UInt32 message = (keyCode << 8) + charCode;
148 if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent(
149 focus , message , modifiers , when , point.h , point.v ) )
160 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
162 OSStatus result
= eventNotHandledErr
;
163 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
164 // FindFocus does not return the actual focus window,but the enclosing window
165 wxWindow
* focus
= wxWindow::DoFindFocus();
173 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
175 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
,sizeof(char), NULL
,&charCode
);
176 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
177 GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
178 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
179 sizeof( Point
), NULL
, &point
);
181 UInt32 message
= (keyCode
<< 8) + charCode
;
182 switch( GetEventKind( event
) )
184 case kEventRawKeyRepeat
:
185 case kEventRawKeyDown
:
187 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
188 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
189 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
190 if ( (focus
!= NULL
) && wxTheApp
->MacSendKeyDownEvent(
191 focus
, message
, modifiers
, when
, point
.h
, point
.v
) )
195 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
198 case kEventRawKeyUp
:
199 if ( (focus
!= NULL
) && wxTheApp
->MacSendKeyUpEvent(
200 focus
, message
, modifiers
, when
, point
.h
, point
.v
) )
205 case kEventRawKeyModifiersChanged
:
207 wxKeyEvent
event(wxEVT_KEY_DOWN
);
209 event
.m_shiftDown
= modifiers
& shiftKey
;
210 event
.m_controlDown
= modifiers
& controlKey
;
211 event
.m_altDown
= modifiers
& optionKey
;
212 event
.m_metaDown
= modifiers
& cmdKey
;
216 event
.SetTimestamp(when
);
217 event
.SetEventObject(focus
);
219 if ( focus
&& (modifiers
^ wxTheApp
->s_lastModifiers
) & controlKey
)
221 event
.m_keyCode
= WXK_CONTROL
;
222 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
223 focus
->GetEventHandler()->ProcessEvent( event
) ;
225 if ( focus
&& (modifiers
^ wxTheApp
->s_lastModifiers
) & shiftKey
)
227 event
.m_keyCode
= WXK_SHIFT
;
228 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
229 focus
->GetEventHandler()->ProcessEvent( event
) ;
231 if ( focus
&& (modifiers
^ wxTheApp
->s_lastModifiers
) & optionKey
)
233 event
.m_keyCode
= WXK_ALT
;
234 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
235 focus
->GetEventHandler()->ProcessEvent( event
) ;
237 if ( focus
&& (modifiers
^ wxTheApp
->s_lastModifiers
) & cmdKey
)
239 event
.m_keyCode
= WXK_COMMAND
;
240 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
241 focus
->GetEventHandler()->ProcessEvent( event
) ;
243 wxTheApp
->s_lastModifiers
= modifiers
;
251 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
252 // for windows that we didn't create (like eg Scrollbars in a databrowser) , or for controls where we did not handle the
255 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
257 wxWindow
* g_MacLastWindow
= NULL
;
259 static EventMouseButton lastButton
= 0 ;
261 static void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
263 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
264 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
266 // this parameter are not given for all events
267 EventMouseButton button
= 0 ;
268 UInt32 clickCount
= 0 ;
269 cEvent
.GetParameter
<EventMouseButton
>(kEventParamMouseButton
, typeMouseButton
, &button
) ;
270 cEvent
.GetParameter
<UInt32
>(kEventParamClickCount
, typeUInt32
, &clickCount
) ;
272 wxevent
.m_x
= screenMouseLocation
.h
;
273 wxevent
.m_y
= screenMouseLocation
.v
;
274 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
275 wxevent
.m_controlDown
= modifiers
& controlKey
;
276 wxevent
.m_altDown
= modifiers
& optionKey
;
277 wxevent
.m_metaDown
= modifiers
& cmdKey
;
278 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
279 // a control click is interpreted as a right click
280 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
282 button
= kEventMouseButtonSecondary
;
285 // we must make sure that our synthetic 'right' button corresponds in
286 // mouse down, moved and mouse up, and does not deliver a right down and left up
288 if ( cEvent
.GetKind() == kEventMouseDown
)
289 lastButton
= button
;
293 else if ( lastButton
)
294 button
= lastButton
;
296 // determinate the correct down state, wx does not want a 'down' for a mouseUp event, while mac delivers
298 if ( button
!= 0 && cEvent
.GetKind() != kEventMouseUp
)
302 case kEventMouseButtonPrimary
:
303 wxevent
.m_leftDown
= true ;
305 case kEventMouseButtonSecondary
:
306 wxevent
.m_rightDown
= true ;
308 case kEventMouseButtonTertiary
:
309 wxevent
.m_middleDown
= true ;
313 // translate into wx types
314 switch ( cEvent
.GetKind() )
316 case kEventMouseDown
:
319 case kEventMouseButtonPrimary
:
320 wxevent
.SetEventType(clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
322 case kEventMouseButtonSecondary
:
323 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
325 case kEventMouseButtonTertiary
:
326 wxevent
.SetEventType(clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
333 case kEventMouseButtonPrimary
:
334 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
336 case kEventMouseButtonSecondary
:
337 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
339 case kEventMouseButtonTertiary
:
340 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
344 case kEventMouseWheelMoved
:
346 wxevent
.SetEventType(wxEVT_MOUSEWHEEL
) ;
348 // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
349 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeLongInteger
) ;
351 wxevent
.m_wheelRotation
= delta
;
352 wxevent
.m_wheelDelta
= 1;
353 wxevent
.m_linesPerAction
= 1;
357 wxevent
.SetEventType(wxEVT_MOTION
) ;
362 ControlRef
wxMacFindSubControl( wxTopLevelWindowMac
* toplevelWindow
, Point location
, ControlRef superControl
, ControlPartCode
*outPart
)
366 UInt16 childrenCount
= 0 ;
367 OSStatus err
= CountSubControls( superControl
, &childrenCount
) ;
368 if ( err
== errControlIsNotEmbedder
)
370 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
372 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
374 ControlHandle sibling
;
375 err
= GetIndexedSubControl( superControl
, i
, & sibling
) ;
376 if ( err
== errControlIsNotEmbedder
)
379 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
380 if ( IsControlVisible( sibling
) )
383 UMAGetControlBoundsInWindowCoords( sibling
, &r
) ;
384 if ( MacPtInRect( location
, &r
) )
386 ControlHandle child
= wxMacFindSubControl( toplevelWindow
, location
, sibling
, outPart
) ;
391 Point testLocation
= location
;
393 if ( toplevelWindow
&& toplevelWindow
->MacUsesCompositing() )
395 testLocation
.h
-= r
.left
;
396 testLocation
.v
-= r
.top
;
399 *outPart
= TestControl( sibling
, testLocation
) ;
409 ControlRef
wxMacFindControlUnderMouse( wxTopLevelWindowMac
* toplevelWindow
, Point location
, WindowRef window
, ControlPartCode
*outPart
)
411 #if TARGET_API_MAC_OSX
412 if ( UMAGetSystemVersion() >= 0x1030 && ( toplevelWindow
== 0 || toplevelWindow
->MacUsesCompositing() ) )
413 return FindControlUnderMouse( location
, window
, outPart
) ;
415 ControlRef rootControl
= NULL
;
416 verify_noerr( GetRootControl( window
, &rootControl
) ) ;
417 return wxMacFindSubControl( toplevelWindow
, location
, rootControl
, outPart
) ;
420 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
422 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
424 OSStatus result
= eventNotHandledErr
;
426 wxMacCarbonEvent
cEvent( event
) ;
428 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
429 Point windowMouseLocation
= screenMouseLocation
;
432 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
434 wxWindow
* currentMouseWindow
= NULL
;
435 ControlRef control
= NULL
;
439 QDGlobalToLocalPoint( UMAGetWindowPort(window
) , &windowMouseLocation
) ;
441 if ( wxTheApp
->s_captureWindow
&& wxTheApp
->s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
)
443 currentMouseWindow
= wxTheApp
->s_captureWindow
;
445 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
447 ControlPartCode part
;
448 control
= wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &part
) ;
449 // if there is no control below the mouse position, send the event to the toplevel window itself
451 currentMouseWindow
= (wxWindow
*) data
;
454 currentMouseWindow
= wxFindControlFromMacControl( control
) ;
455 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
458 // for wxToolBar to function we have to send certaint events to it
459 // instead of its children (wxToolBarTools)
461 GetSuperControl(control
, &parent
);
462 wxWindow
*wxParent
= wxFindControlFromMacControl( parent
) ;
463 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
464 currentMouseWindow
= wxParent
;
471 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
472 SetupMouseEvent( wxevent
, cEvent
) ;
474 // handle all enter / leave events
476 if ( currentMouseWindow
!= g_MacLastWindow
)
478 if ( g_MacLastWindow
)
480 wxMouseEvent
eventleave(wxevent
);
481 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
482 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
483 eventleave
.SetEventObject( g_MacLastWindow
) ;
486 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
487 #endif // wxUSE_TOOLTIPS
488 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
490 if ( currentMouseWindow
)
492 wxMouseEvent
evententer(wxevent
);
493 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
494 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
495 evententer
.SetEventObject( currentMouseWindow
) ;
497 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
498 #endif // wxUSE_TOOLTIPS
499 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
501 g_MacLastWindow
= currentMouseWindow
;
504 if ( windowPart
== inMenuBar
)
506 // special case menu bar, as we are having a low-level runloop we must do it ourselves
507 if ( cEvent
.GetKind() == kEventMouseDown
)
509 ::MenuSelect( screenMouseLocation
) ;
512 } // if ( windowPart == inMenuBar )
513 else if ( currentMouseWindow
)
515 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
517 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
519 wxevent
.SetEventObject( currentMouseWindow
) ;
521 // make tooltips current
524 if ( wxevent
.GetEventType() == wxEVT_MOTION
525 || wxevent
.GetEventType() == wxEVT_ENTER_WINDOW
526 || wxevent
.GetEventType() == wxEVT_LEAVE_WINDOW
)
527 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
528 #endif // wxUSE_TOOLTIPS
529 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
531 if ((currentMouseWindowParent
!= NULL
) &&
532 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
533 currentMouseWindow
= NULL
;
539 // if the user code did _not_ handle the event, then perform the
540 // default processing
541 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
543 // ... that is set focus to this window
544 if (currentMouseWindow
->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
545 currentMouseWindow
->SetFocus();
548 ControlPartCode dummyPart
;
549 // if built-in find control is finding the wrong control (ie static box instead of overlaid
550 // button, we cannot let the standard handler do its job, but must handle manually
552 if ( ( cEvent
.GetKind() == kEventMouseDown
)
555 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
556 wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &dummyPart
) )
560 if ( currentMouseWindow
->MacIsReallyEnabled() )
562 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
563 Point clickLocation
= windowMouseLocation
;
565 if ( toplevelWindow
->MacUsesCompositing() )
566 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
568 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
569 modifiers
, (ControlActionUPP
) -1 ) ;
571 if ((currentMouseWindowParent
!= NULL
) &&
572 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
573 currentMouseWindow
= NULL
;
578 if ( cEvent
.GetKind() == kEventMouseUp
&& wxTheApp
->s_captureWindow
)
580 wxTheApp
->s_captureWindow
= NULL
;
586 wxWindow
* cursorTarget
= currentMouseWindow
;
587 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
589 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
591 cursorTarget
= cursorTarget
->GetParent() ;
593 cursorPoint
+= cursorTarget
->GetPosition();
596 } // else if ( currentMouseWindow )
599 // don't mess with controls we don't know about
600 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
601 // so we try sending them the correct control directly
602 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
604 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
605 Point clickLocation
= windowMouseLocation
;
606 if ( toplevelWindow
->MacUsesCompositing() )
610 hiPoint
.x
= clickLocation
.h
;
611 hiPoint
.y
= clickLocation
.v
;
612 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
613 clickLocation
.h
= (int)hiPoint
.x
;
614 clickLocation
.v
= (int)hiPoint
.y
;
617 HandleControlClick( control
, clickLocation
,
618 modifiers
, (ControlActionUPP
) -1 ) ;
625 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
627 OSStatus result
= eventNotHandledErr
;
629 wxMacCarbonEvent
cEvent( event
) ;
631 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
632 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
634 switch( GetEventKind( event
) )
636 case kEventWindowActivated
:
638 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
639 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
640 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
641 wxevent
.SetEventObject(toplevelWindow
);
642 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
643 // we still sending an eventNotHandledErr in order to allow for default processing
646 case kEventWindowDeactivated
:
648 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
649 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
650 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
651 wxevent
.SetEventObject(toplevelWindow
);
652 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
653 // we still sending an eventNotHandledErr in order to allow for default processing
656 case kEventWindowShown
:
657 toplevelWindow
->Refresh() ;
660 case kEventWindowClose
:
661 toplevelWindow
->Close() ;
664 case kEventWindowBoundsChanged
:
666 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
667 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
668 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
669 if ( attributes
& kWindowBoundsChangeSizeChanged
)
671 // according to the other ports we handle this within the OS level
672 // resize event, not within a wxSizeEvent
673 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
677 frame
->PositionStatusBar();
680 frame
->PositionToolBar();
684 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
685 event
.SetEventObject( toplevelWindow
) ;
687 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
689 if ( attributes
& kWindowBoundsChangeOriginChanged
)
691 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
692 event
.SetEventObject( toplevelWindow
) ;
693 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
698 case kEventWindowBoundsChanging
:
700 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
701 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
703 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
705 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
706 int left
, top
, right
, bottom
;
707 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
708 wxRect
r( newRect
.left
- left
, newRect
.top
- top
,
709 newRect
.right
- newRect
.left
+ left
+ right
, newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
710 // this is a EVT_SIZING not a EVT_SIZE type !
711 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
712 wxevent
.SetEventObject( toplevelWindow
) ;
714 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
715 adjustR
= wxevent
.GetRect() ;
717 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
718 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
719 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
720 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
721 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
722 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
723 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
724 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
725 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
726 if ( !EqualRect( &newRect
, &adjustedRect
) )
727 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
739 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
741 OSStatus result
= eventNotHandledErr
;
743 switch ( GetEventClass( event
) )
745 case kEventClassKeyboard
:
746 result
= KeyboardEventHandler( handler
, event
, data
) ;
748 case kEventClassTextInput
:
749 result
= TextInputEventHandler( handler
, event
, data
) ;
751 case kEventClassWindow
:
752 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
754 case kEventClassMouse
:
755 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
763 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
765 // ---------------------------------------------------------------------------
766 // wxWindowMac utility functions
767 // ---------------------------------------------------------------------------
769 // Find an item given the Macintosh Window Reference
771 #if KEY_wxList_DEPRECATED
772 wxList
wxWinMacWindowList(wxKEY_INTEGER
);
773 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
775 wxNode
*node
= wxWinMacWindowList
.Find((long)inWindowRef
);
778 return (wxTopLevelWindowMac
*)node
->GetData();
781 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
782 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
784 // adding NULL WindowRef is (first) surely a result of an error and
785 // (secondly) breaks menu command processing
786 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
788 if ( !wxWinMacWindowList
.Find((long)inWindowRef
) )
789 wxWinMacWindowList
.Append((long)inWindowRef
, win
);
792 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
793 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
795 wxWinMacWindowList
.DeleteObject(win
);
799 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
801 static MacWindowMap wxWinMacWindowList
;
803 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
805 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
807 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
810 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
811 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
813 // adding NULL WindowRef is (first) surely a result of an error and
815 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
817 wxWinMacWindowList
[inWindowRef
] = win
;
820 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
821 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
823 MacWindowMap::iterator it
;
824 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
826 if ( it
->second
== win
)
828 wxWinMacWindowList
.erase(it
);
833 #endif // deprecated wxList
835 // ----------------------------------------------------------------------------
836 // wxTopLevelWindowMac creation
837 // ----------------------------------------------------------------------------
839 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
847 void wxTopLevelWindowMac::Init()
850 m_maximizeOnShow
= FALSE
;
852 #if TARGET_API_MAC_OSX
853 if ( UMAGetSystemVersion() >= 0x1030 )
855 m_macUsesCompositing
= TRUE
;
860 m_macUsesCompositing
= FALSE
;
862 m_macEventHandler
= NULL
;
863 m_macFullScreenData
= NULL
;
866 class wxMacDeferredWindowDeleter
: public wxObject
869 wxMacDeferredWindowDeleter( WindowRef windowRef
)
871 m_macWindow
= windowRef
;
873 virtual ~wxMacDeferredWindowDeleter()
875 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
878 WindowRef m_macWindow
;
881 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
883 const wxString
& title
,
887 const wxString
& name
)
892 m_windowStyle
= style
;
896 m_windowId
= id
== -1 ? NewControlId() : id
;
897 wxWindow::SetTitle( title
) ;
899 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
901 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
903 wxTopLevelWindows
.Append(this);
906 parent
->AddChild(this);
911 wxTopLevelWindowMac::~wxTopLevelWindowMac()
915 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
916 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
919 if ( m_macEventHandler
)
921 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
922 m_macEventHandler
= NULL
;
925 wxRemoveMacWindowAssociation( this ) ;
927 if ( wxModelessWindows
.Find(this) )
928 wxModelessWindows
.DeleteObject(this);
930 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
932 m_macFullScreenData
= NULL
;
936 // ----------------------------------------------------------------------------
937 // wxTopLevelWindowMac maximize/minimize
938 // ----------------------------------------------------------------------------
940 void wxTopLevelWindowMac::Maximize(bool maximize
)
942 wxMacPortStateHelper
help( (GrafPtr
) GetWindowPort( (WindowRef
) m_macWindow
) ) ;
943 wxMacWindowClipper
clip (this);
944 ZoomWindow( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, false ) ;
947 bool wxTopLevelWindowMac::IsMaximized() const
949 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
952 void wxTopLevelWindowMac::Iconize(bool iconize
)
954 if ( IsWindowCollapsable((WindowRef
)m_macWindow
) )
955 CollapseWindow((WindowRef
)m_macWindow
, iconize
) ;
958 bool wxTopLevelWindowMac::IsIconized() const
960 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
963 void wxTopLevelWindowMac::Restore()
965 // not available on mac
968 // ----------------------------------------------------------------------------
969 // wxTopLevelWindowMac misc
970 // ----------------------------------------------------------------------------
972 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
974 return wxPoint(0,0) ;
977 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
980 wxTopLevelWindowBase::SetIcon(icon
);
983 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
985 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
987 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
989 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
993 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
995 if ( m_macEventHandler
!= NULL
)
997 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
999 InstallWindowEventHandler(MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1000 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1003 void wxTopLevelWindowMac::MacCreateRealWindow( const wxString
& title
,
1007 const wxString
& name
)
1009 OSStatus err
= noErr
;
1011 m_windowStyle
= style
;
1021 wxRect display
= wxGetClientDisplayRect() ;
1023 if ( x
== wxDefaultPosition
.x
)
1026 if ( y
== wxDefaultPosition
.y
)
1029 int w
= WidthDefault(size
.x
);
1030 int h
= HeightDefault(size
.y
);
1032 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1034 // translate the window attributes in the appropriate window class and attributes
1036 WindowClass wclass
= 0;
1037 WindowAttributes attr
= kWindowNoAttributes
;
1038 WindowGroupRef group
= NULL
;
1040 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1043 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1044 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1045 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1048 wclass
= kFloatingWindowClass
;
1049 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1051 attr
|= kWindowSideTitlebarAttribute
;
1056 wclass
= kPlainWindowClass
;
1059 else if ( HasFlag( wxCAPTION
) )
1061 wclass
= kDocumentWindowClass
;
1063 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1064 else if ( HasFlag( wxFRAME_DRAWER
) )
1066 wclass
= kDrawerWindowClass
;
1067 // we must force compositing on a drawer
1068 m_macUsesCompositing
= TRUE
;
1070 #endif //10.2 and up
1073 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1074 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1076 wclass
= kDocumentWindowClass
;
1080 wclass
= kPlainWindowClass
;
1084 if ( HasFlag( wxMINIMIZE_BOX
) )
1086 attr
|= kWindowCollapseBoxAttribute
;
1088 if ( HasFlag( wxMAXIMIZE_BOX
) )
1090 attr
|= kWindowFullZoomAttribute
;
1092 if ( HasFlag( wxRESIZE_BORDER
) )
1094 attr
|= kWindowResizableAttribute
;
1096 if ( HasFlag( wxCLOSE_BOX
) )
1098 attr
|= kWindowCloseBoxAttribute
;
1101 if (UMAGetSystemVersion() >= 0x1000)
1103 // turn on live resizing (OS X only)
1104 attr
|= kWindowLiveResizeAttribute
;
1107 if ( HasFlag(wxSTAY_ON_TOP
) )
1109 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1112 #if TARGET_API_MAC_OSX
1113 if ( m_macUsesCompositing
)
1114 attr
|= kWindowCompositingAttribute
;
1117 if ( HasFlag(wxFRAME_SHAPED
) )
1119 WindowDefSpec customWindowDefSpec
;
1120 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1121 customWindowDefSpec
.u
.defProc
= NewWindowDefUPP(wxShapedMacWindowDef
);
1123 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1124 attr
, &theBoundsRect
,
1125 (WindowRef
*) &m_macWindow
);
1129 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1132 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1133 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1135 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1137 // the create commands are only for content rect, so we have to set the size again as
1139 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1141 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1142 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1143 m_peer
= new wxMacControl(this) ;
1144 #if TARGET_API_MAC_OSX
1146 if ( m_macUsesCompositing
)
1148 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1149 // the content view, so we have to retrieve it explicitely
1150 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1151 m_peer
->GetControlRefAddr() ) ;
1152 if ( !m_peer
->Ok() )
1154 // compatibility mode fallback
1155 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1160 ::CreateRootControl( (WindowRef
)m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1162 // the root control level handleer
1163 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1165 // the frame window event handler
1166 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1167 MacInstallTopLevelWindowEventHandler() ;
1171 if ( HasFlag(wxFRAME_SHAPED
) )
1173 // default shape matches the window size
1174 wxRegion
rgn(0, 0, w
, h
);
1178 wxWindowCreateEvent
event(this);
1179 GetEventHandler()->ProcessEvent(event
);
1182 void wxTopLevelWindowMac::ClearBackground()
1184 wxWindow::ClearBackground() ;
1187 // Raise the window to the top of the Z order
1188 void wxTopLevelWindowMac::Raise()
1190 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1193 // Lower the window to the bottom of the Z order
1194 void wxTopLevelWindowMac::Lower()
1196 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1200 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1202 if(s_macDeactivateWindow
)
1204 wxLogDebug(wxT("Doing delayed deactivation of %p"),s_macDeactivateWindow
);
1205 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1209 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1211 // wxLogDebug(wxT("TopLevel=%p::MacActivate"),this);
1213 if(s_macDeactivateWindow
==this)
1214 s_macDeactivateWindow
=NULL
;
1215 MacDelayedDeactivation(timestamp
);
1216 MacPropagateHiliteChanged() ;
1219 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1221 wxWindow::SetTitle( title
) ;
1222 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1225 bool wxTopLevelWindowMac::Show(bool show
)
1227 if ( !wxTopLevelWindowBase::Show(show
) )
1232 #if wxUSE_SYSTEM_OPTIONS //code contributed by Ryan Wilcox December 18, 2003
1233 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1235 ::ShowWindow( (WindowRef
)m_macWindow
);
1240 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowShowTransitionAction
,nil
);
1242 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1243 // as apps expect a size event to occur at this moment
1244 wxSizeEvent
event( GetSize() , m_windowId
);
1245 event
.SetEventObject(this);
1246 GetEventHandler()->ProcessEvent(event
);
1250 #if wxUSE_SYSTEM_OPTIONS
1251 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1253 ::HideWindow((WindowRef
) m_macWindow
);
1258 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowHideTransitionAction
,nil
);
1262 MacPropagateVisibilityChanged() ;
1267 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1271 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1273 data
= new FullScreenData() ;
1275 m_macFullScreenData
= data
;
1276 data
->m_position
= GetPosition() ;
1277 data
->m_size
= GetSize() ;
1279 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1283 int left
, top
, right
, bottom
;
1284 wxRect client
= wxGetClientDisplayRect() ;
1293 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1295 if ( style
& wxFULLSCREEN_NOCAPTION
)
1300 if ( style
& wxFULLSCREEN_NOBORDER
)
1306 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1310 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1314 SetSize( x
, y
, w
, h
) ;
1319 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1320 SetPosition( data
->m_position
) ;
1321 SetSize( data
->m_size
) ;
1323 m_macFullScreenData
= NULL
;
1328 bool wxTopLevelWindowMac::IsFullScreen() const
1330 return m_macFullScreenData
!= NULL
;
1333 // we are still using coordinates of the content view, todo switch to structure bounds
1335 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1339 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1340 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1342 left
= content
.left
- structure
.left
;
1343 top
= content
.top
- structure
.top
;
1344 right
= structure
.right
- content
.right
;
1345 bottom
= structure
.bottom
- content
.bottom
;
1348 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1350 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1351 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1354 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1357 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1358 if(x
) *x
= bounds
.left
;
1359 if(y
) *y
= bounds
.top
;
1361 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1364 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1365 if(width
) *width
= bounds
.right
- bounds
.left
;
1366 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1369 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1372 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1373 if(width
) *width
= bounds
.right
- bounds
.left
;
1374 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1377 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1379 #if TARGET_API_MAC_OSX
1380 wxASSERT_MSG( m_macUsesCompositing
,
1381 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1383 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1384 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1388 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1390 #if TARGET_API_MAC_OSX
1391 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1397 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1399 ChangeWindowAttributes ( (WindowRef
) m_macWindow
, attributesToSet
, attributesToClear
) ;
1402 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1405 GetWindowAttributes((WindowRef
) m_macWindow
, &attr
) ;
1409 // Attracts the users attention to this window if the application is
1410 // inactive (should be called when a background event occurs)
1412 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1415 DisposePtr( (Ptr
) ptr
) ;
1419 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1421 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1422 static wxMacNMUPP
nmupp( wxMacNMResponse
)
1424 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1425 notificationRequest
->qType
= nmType
;
1426 notificationRequest
->nmMark
= 1 ;
1427 notificationRequest
->nmIcon
= 0 ;
1428 notificationRequest
->nmSound
= 0 ;
1429 notificationRequest
->nmStr
= NULL
;
1430 notificationRequest
->nmResp
= nmupp
;
1431 verify_noerr( NMInstall( notificationRequest
) ) ;
1434 // ---------------------------------------------------------------------------
1435 // Shape implementation
1436 // ---------------------------------------------------------------------------
1439 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1441 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
1442 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1444 // The empty region signifies that the shape should be removed from the
1446 if ( region
.IsEmpty() )
1448 wxSize sz
= GetClientSize();
1449 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1450 return SetShape(rgn
);
1453 // Make a copy of the region
1454 RgnHandle shapeRegion
= NewRgn();
1455 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1457 // Dispose of any shape region we may already have
1458 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1462 // Save the region so we can use it later
1463 SetWRefCon((WindowRef
)MacGetWindowRef(), (SInt32
)shapeRegion
);
1465 // Tell the window manager that the window has changed shape
1466 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1470 // ---------------------------------------------------------------------------
1471 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1472 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1473 // ---------------------------------------------------------------------------
1475 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1477 GetWindowPortBounds(window
, inRect
);
1478 Point pt
= {inRect
->left
, inRect
->top
};
1479 QDLocalToGlobalPoint( GetWindowPort(window
) , &pt
) ;
1481 inRect
->left
= pt
.h
;
1482 inRect
->bottom
+= pt
.v
;
1483 inRect
->right
+= pt
.h
;
1487 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1489 /*------------------------------------------------------
1490 Define which options your custom window supports.
1491 --------------------------------------------------------*/
1492 //just enable everything for our demo
1493 *(OptionBits
*)param
=//kWindowCanGrow|
1495 //kWindowCanCollapse|
1496 //kWindowCanGetWindowRegion|
1497 //kWindowHasTitleBar|
1498 //kWindowSupportsDragHilite|
1499 kWindowCanDrawInCurrentPort
|
1500 //kWindowCanMeasureTitle|
1501 kWindowWantsDisposeAtProcessDeath
|
1502 kWindowSupportsGetGrowImageRegion
|
1503 kWindowDefSupportsColorGrafPort
;
1507 // The content region is left as a rectangle matching the window size, this is
1508 // so the origin in the paint event, and etc. still matches what the
1509 // programmer expects.
1510 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1513 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1517 wxShapedMacWindowGetPos(window
, &r
) ;
1518 RectRgn( rgn
, &r
) ;
1522 // The structure region is set to the shape given to the SetShape method.
1523 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1525 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1531 wxShapedMacWindowGetPos(window
, &windowRect
); //how big is the window
1532 CopyRgn(cachedRegion
, rgn
); //make a copy of our cached region
1533 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1534 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1540 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1542 GetWindowRegionPtr rgnRec
=(GetWindowRegionPtr
)param
;
1544 switch(rgnRec
->regionCode
)
1546 case kWindowStructureRgn
:
1547 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1549 case kWindowContentRgn
:
1550 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1553 SetEmptyRgn(rgnRec
->winRgn
);
1560 static SInt32
wxShapedMacWindowHitTest(WindowRef window
,SInt32 param
)
1562 /*------------------------------------------------------
1563 Determine the region of the window which was hit
1564 --------------------------------------------------------*/
1566 static RgnHandle tempRgn
=nil
;
1571 SetPt(&hitPoint
,LoWord(param
),HiWord(param
));//get the point clicked
1573 //Mac OS 8.5 or later
1574 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1575 if (PtInRgn(hitPoint
, tempRgn
)) //in window content region?
1578 return wNoHit
;//no significant area was hit.
1582 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1586 case kWindowMsgHitTest
:
1587 return wxShapedMacWindowHitTest(window
,param
);
1589 case kWindowMsgGetFeatures
:
1590 return wxShapedMacWindowGetFeatures(window
,param
);
1592 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1593 case kWindowMsgGetRegion
:
1594 return wxShapedMacWindowGetRegion(window
,param
);
1600 // ---------------------------------------------------------------------------