1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for Mac
4 // Author: Stefan Csomor
8 // Copyright: (c) 2001-2004 Stefan Csomor
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/toplevel.h"
31 #include "wx/string.h"
34 #include "wx/settings.h"
35 #include "wx/strconv.h"
36 #include "wx/control.h"
39 #include "wx/mac/uma.h"
40 #include "wx/mac/aga.h"
42 #include "wx/tooltip.h"
45 #if wxUSE_SYSTEM_OPTIONS
46 #include "wx/sysopt.h"
50 #include <ToolUtils.h>
54 #include "wx/mac/private.h"
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 // trace mask for activation tracing messages
61 static const wxChar
*TRACE_ACTIVATE
= _T("activation");
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 // list of all frames and modeless dialogs
68 wxWindowList wxModelessWindows
;
70 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
72 // ============================================================================
73 // wxTopLevelWindowMac implementation
74 // ============================================================================
76 BEGIN_EVENT_TABLE(wxTopLevelWindowMac
, wxTopLevelWindowBase
)
80 // ---------------------------------------------------------------------------
82 // ---------------------------------------------------------------------------
84 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
86 static const EventTypeSpec eventList
[] =
88 // TODO: remove control related event like key and mouse (except for WindowLeave events)
90 { kEventClassKeyboard
, kEventRawKeyDown
} ,
91 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
92 { kEventClassKeyboard
, kEventRawKeyUp
} ,
93 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
95 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
96 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
98 { kEventClassWindow
, kEventWindowShown
} ,
99 { kEventClassWindow
, kEventWindowActivated
} ,
100 { kEventClassWindow
, kEventWindowDeactivated
} ,
101 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
102 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
103 { kEventClassWindow
, kEventWindowClose
} ,
105 // we have to catch these events on the toplevel window level,
106 // as controls don't get the raw mouse events anymore
108 { kEventClassMouse
, kEventMouseDown
} ,
109 { kEventClassMouse
, kEventMouseUp
} ,
110 { kEventClassMouse
, kEventMouseWheelMoved
} ,
111 { kEventClassMouse
, kEventMouseMoved
} ,
112 { kEventClassMouse
, kEventMouseDragged
} ,
115 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
117 OSStatus result
= eventNotHandledErr
;
118 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
119 // FindFocus does not return the actual focus window, but the enclosing window
120 wxWindow
* focus
= wxWindow::DoFindFocus();
122 focus
= (wxTopLevelWindowMac
*) data
;
124 unsigned char charCode
;
129 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
132 UInt32 dataSize
= 0 ;
133 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
137 UniChar
* charBuf
= buf
;
140 charBuf
= new UniChar
[ dataSize
/ sizeof( UniChar
) ] ;
141 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
143 #if SIZEOF_WCHAR_T == 2
144 uniChar
= charBuf
[0] ;
146 wxMBConvUTF16 converter
;
147 converter
.MB2WC( &uniChar
, (const char*)charBuf
, 1 ) ;
155 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
156 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
157 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
158 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
160 UInt32 message
= (keyCode
<< 8) + charCode
;
161 switch ( GetEventKind( event
) )
163 case kEventRawKeyRepeat
:
164 case kEventRawKeyDown
:
166 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
167 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
168 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
169 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
170 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
) )
174 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
178 case kEventRawKeyUp
:
179 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
180 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
) )
186 case kEventRawKeyModifiersChanged
:
188 wxKeyEvent
event(wxEVT_KEY_DOWN
);
190 event
.m_shiftDown
= modifiers
& shiftKey
;
191 event
.m_controlDown
= modifiers
& controlKey
;
192 event
.m_altDown
= modifiers
& optionKey
;
193 event
.m_metaDown
= modifiers
& cmdKey
;
198 event
.m_uniChar
= uniChar
;
201 event
.SetTimestamp(when
);
202 event
.SetEventObject(focus
);
204 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
206 event
.m_keyCode
= WXK_CONTROL
;
207 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
208 focus
->GetEventHandler()->ProcessEvent( event
) ;
210 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
212 event
.m_keyCode
= WXK_SHIFT
;
213 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
214 focus
->GetEventHandler()->ProcessEvent( event
) ;
216 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
218 event
.m_keyCode
= WXK_ALT
;
219 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
220 focus
->GetEventHandler()->ProcessEvent( event
) ;
222 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
224 event
.m_keyCode
= WXK_COMMAND
;
225 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
226 focus
->GetEventHandler()->ProcessEvent( event
) ;
229 wxApp::s_lastModifiers
= modifiers
;
240 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
241 // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
244 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
246 wxWindow
* g_MacLastWindow
= NULL
;
248 static EventMouseButton lastButton
= 0 ;
250 static void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
252 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
253 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
255 // this parameter are not given for all events
256 EventMouseButton button
= 0 ;
257 UInt32 clickCount
= 0 ;
258 cEvent
.GetParameter
<EventMouseButton
>( kEventParamMouseButton
, typeMouseButton
, &button
) ;
259 cEvent
.GetParameter
<UInt32
>( kEventParamClickCount
, typeUInt32
, &clickCount
) ;
261 wxevent
.m_x
= screenMouseLocation
.h
;
262 wxevent
.m_y
= screenMouseLocation
.v
;
263 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
264 wxevent
.m_controlDown
= modifiers
& controlKey
;
265 wxevent
.m_altDown
= modifiers
& optionKey
;
266 wxevent
.m_metaDown
= modifiers
& cmdKey
;
267 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
269 // a control click is interpreted as a right click
270 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
271 button
= kEventMouseButtonSecondary
;
273 // otherwise we report double clicks by connecting a left click with a ctrl-left click
274 if ( clickCount
> 1 && button
!= lastButton
)
277 // we must make sure that our synthetic 'right' button corresponds in
278 // mouse down, moved and mouse up, and does not deliver a right down and left up
280 if ( cEvent
.GetKind() == kEventMouseDown
)
281 lastButton
= button
;
285 else if ( lastButton
)
286 button
= lastButton
;
288 // determine the correct down state, wx does not want a 'down' for a mouseUp event,
289 // while mac delivers this button
290 if ( button
!= 0 && cEvent
.GetKind() != kEventMouseUp
)
294 case kEventMouseButtonPrimary
:
295 wxevent
.m_leftDown
= true ;
298 case kEventMouseButtonSecondary
:
299 wxevent
.m_rightDown
= true ;
302 case kEventMouseButtonTertiary
:
303 wxevent
.m_middleDown
= true ;
311 // translate into wx types
312 switch ( cEvent
.GetKind() )
314 case kEventMouseDown
:
317 case kEventMouseButtonPrimary
:
318 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
321 case kEventMouseButtonSecondary
:
322 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
325 case kEventMouseButtonTertiary
:
326 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
337 case kEventMouseButtonPrimary
:
338 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
341 case kEventMouseButtonSecondary
:
342 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
345 case kEventMouseButtonTertiary
:
346 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
354 case kEventMouseWheelMoved
:
356 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
358 // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
359 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeLongInteger
) ;
361 wxevent
.m_wheelRotation
= delta
;
362 wxevent
.m_wheelDelta
= 1;
363 wxevent
.m_linesPerAction
= 1;
368 wxevent
.SetEventType( wxEVT_MOTION
) ;
373 ControlRef
wxMacFindSubControl( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, ControlRef superControl
, ControlPartCode
*outPart
)
377 UInt16 childrenCount
= 0 ;
378 ControlHandle sibling
;
380 OSStatus err
= CountSubControls( superControl
, &childrenCount
) ;
381 if ( err
== errControlIsNotEmbedder
)
384 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
386 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
388 err
= GetIndexedSubControl( superControl
, i
, & sibling
) ;
389 if ( err
== errControlIsNotEmbedder
)
392 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
393 if ( IsControlVisible( sibling
) )
395 UMAGetControlBoundsInWindowCoords( sibling
, &r
) ;
396 if ( MacPtInRect( location
, &r
) )
398 ControlHandle child
= wxMacFindSubControl( toplevelWindow
, location
, sibling
, outPart
) ;
405 Point testLocation
= location
;
407 if ( toplevelWindow
&& toplevelWindow
->MacUsesCompositing() )
409 testLocation
.h
-= r
.left
;
410 testLocation
.v
-= r
.top
;
413 *outPart
= TestControl( sibling
, testLocation
) ;
425 ControlRef
wxMacFindControlUnderMouse( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, WindowRef window
, ControlPartCode
*outPart
)
427 #if TARGET_API_MAC_OSX
428 if ( UMAGetSystemVersion() >= 0x1030 && ( toplevelWindow
== 0 || toplevelWindow
->MacUsesCompositing() ) )
429 return FindControlUnderMouse( location
, window
, outPart
) ;
432 ControlRef rootControl
= NULL
;
433 verify_noerr( GetRootControl( window
, &rootControl
) ) ;
435 return wxMacFindSubControl( toplevelWindow
, location
, rootControl
, outPart
) ;
438 #define NEW_CAPTURE_HANDLING 1
440 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
442 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
444 OSStatus result
= eventNotHandledErr
;
446 wxMacCarbonEvent
cEvent( event
) ;
448 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
449 Point windowMouseLocation
= screenMouseLocation
;
452 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
454 wxWindow
* currentMouseWindow
= NULL
;
455 ControlRef control
= NULL
;
457 #if NEW_CAPTURE_HANDLING
458 if ( wxApp::s_captureWindow
)
460 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
461 windowPart
= inContent
;
467 QDGlobalToLocalPoint( UMAGetWindowPort(window
) , &windowMouseLocation
) ;
469 if ( wxApp::s_captureWindow
470 #if !NEW_CAPTURE_HANDLING
471 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
475 currentMouseWindow
= wxApp::s_captureWindow
;
477 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
479 ControlPartCode part
;
480 control
= wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &part
) ;
481 // if there is no control below the mouse position, send the event to the toplevel window itself
484 currentMouseWindow
= (wxWindow
*) data
;
488 currentMouseWindow
= wxFindControlFromMacControl( control
) ;
489 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
492 // for wxToolBar to function we have to send certaint events to it
493 // instead of its children (wxToolBarTools)
495 GetSuperControl(control
, &parent
);
496 wxWindow
*wxParent
= wxFindControlFromMacControl( parent
) ;
497 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
498 currentMouseWindow
= wxParent
;
503 // disabled windows must not get any input messages
504 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
505 currentMouseWindow
= NULL
;
509 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
510 SetupMouseEvent( wxevent
, cEvent
) ;
512 // handle all enter / leave events
514 if ( currentMouseWindow
!= g_MacLastWindow
)
516 if ( g_MacLastWindow
)
518 wxMouseEvent
eventleave(wxevent
);
519 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
520 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
521 eventleave
.SetEventObject( g_MacLastWindow
) ;
522 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
525 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
528 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
531 if ( currentMouseWindow
)
533 wxMouseEvent
evententer(wxevent
);
534 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
535 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
536 evententer
.SetEventObject( currentMouseWindow
) ;
537 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
540 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
543 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
546 g_MacLastWindow
= currentMouseWindow
;
549 if ( windowPart
== inMenuBar
)
551 // special case menu bar, as we are having a low-level runloop we must do it ourselves
552 if ( cEvent
.GetKind() == kEventMouseDown
)
554 ::MenuSelect( screenMouseLocation
) ;
558 else if ( currentMouseWindow
)
560 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
562 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
564 wxevent
.SetEventObject( currentMouseWindow
) ;
565 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
567 // make tooltips current
570 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
571 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
574 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
576 if ((currentMouseWindowParent
!= NULL
) &&
577 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
578 currentMouseWindow
= NULL
;
584 // if the user code did _not_ handle the event, then perform the
585 // default processing
586 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
588 // ... that is set focus to this window
589 if (currentMouseWindow
->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
590 currentMouseWindow
->SetFocus();
593 ControlPartCode dummyPart
;
594 // if built-in find control is finding the wrong control (ie static box instead of overlaid
595 // button, we cannot let the standard handler do its job, but must handle manually
597 if ( ( cEvent
.GetKind() == kEventMouseDown
)
600 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
601 wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &dummyPart
) )
605 if ( currentMouseWindow
->MacIsReallyEnabled() )
607 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
608 Point clickLocation
= windowMouseLocation
;
610 if ( toplevelWindow
->MacUsesCompositing() )
611 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
613 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
614 modifiers
, (ControlActionUPP
) -1 ) ;
616 if ((currentMouseWindowParent
!= NULL
) &&
617 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
619 currentMouseWindow
= NULL
;
627 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
629 wxApp::s_captureWindow
= NULL
;
635 wxWindow
* cursorTarget
= currentMouseWindow
;
636 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
638 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
640 cursorTarget
= cursorTarget
->GetParent() ;
642 cursorPoint
+= cursorTarget
->GetPosition();
646 else // currentMouseWindow == NULL
648 // don't mess with controls we don't know about
649 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
650 // so we try sending them the correct control directly
651 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
653 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
654 Point clickLocation
= windowMouseLocation
;
655 #if TARGET_API_MAC_OSX
656 if ( toplevelWindow
->MacUsesCompositing() )
659 hiPoint
.x
= clickLocation
.h
;
660 hiPoint
.y
= clickLocation
.v
;
661 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
662 clickLocation
.h
= (int)hiPoint
.x
;
663 clickLocation
.v
= (int)hiPoint
.y
;
665 #endif // TARGET_API_MAC_OSX
667 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
675 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
677 OSStatus result
= eventNotHandledErr
;
679 wxMacCarbonEvent
cEvent( event
) ;
681 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
682 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
684 switch ( GetEventKind( event
) )
686 case kEventWindowActivated
:
688 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
689 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
690 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
691 wxevent
.SetEventObject(toplevelWindow
);
692 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
693 // we still sending an eventNotHandledErr in order to allow for default processing
697 case kEventWindowDeactivated
:
699 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
700 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
701 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
702 wxevent
.SetEventObject(toplevelWindow
);
703 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
704 // we still sending an eventNotHandledErr in order to allow for default processing
708 case kEventWindowShown
:
709 toplevelWindow
->Refresh() ;
713 case kEventWindowClose
:
714 toplevelWindow
->Close() ;
718 case kEventWindowBoundsChanged
:
720 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
721 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
722 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
723 if ( attributes
& kWindowBoundsChangeSizeChanged
)
725 // according to the other ports we handle this within the OS level
726 // resize event, not within a wxSizeEvent
727 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
730 frame
->PositionBars();
733 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
734 event
.SetEventObject( toplevelWindow
) ;
736 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
737 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
740 if ( attributes
& kWindowBoundsChangeOriginChanged
)
742 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
743 event
.SetEventObject( toplevelWindow
) ;
744 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
751 case kEventWindowBoundsChanging
:
753 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
754 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
756 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
758 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
759 int left
, top
, right
, bottom
;
760 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
765 newRect
.right
- newRect
.left
+ left
+ right
,
766 newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
768 // this is a EVT_SIZING not a EVT_SIZE type !
769 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
770 wxevent
.SetEventObject( toplevelWindow
) ;
772 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
773 adjustR
= wxevent
.GetRect() ;
775 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
776 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
777 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
778 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
779 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
780 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
781 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
782 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
783 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
784 if ( !EqualRect( &newRect
, &adjustedRect
) )
785 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
786 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
800 // mix this in from window.cpp
801 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
803 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
805 OSStatus result
= eventNotHandledErr
;
807 switch ( GetEventClass( event
) )
809 case kEventClassTextInput
:
810 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
813 case kEventClassKeyboard
:
814 result
= KeyboardEventHandler( handler
, event
, data
) ;
817 case kEventClassWindow
:
818 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
821 case kEventClassMouse
:
822 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
832 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
834 // ---------------------------------------------------------------------------
835 // wxWindowMac utility functions
836 // ---------------------------------------------------------------------------
838 // Find an item given the Macintosh Window Reference
840 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
842 static MacWindowMap wxWinMacWindowList
;
844 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
846 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
848 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
851 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
852 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
854 // adding NULL WindowRef is (first) surely a result of an error and
856 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
858 wxWinMacWindowList
[inWindowRef
] = win
;
861 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
862 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
864 MacWindowMap::iterator it
;
865 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
867 if ( it
->second
== win
)
869 wxWinMacWindowList
.erase(it
);
875 // ----------------------------------------------------------------------------
876 // wxTopLevelWindowMac creation
877 // ----------------------------------------------------------------------------
879 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
885 bool m_wasResizable
;
889 void wxTopLevelWindowMac::Init()
892 m_maximizeOnShow
= false;
895 #if TARGET_API_MAC_OSX
896 m_macUsesCompositing
= ( UMAGetSystemVersion() >= 0x1030 );
898 m_macUsesCompositing
= false;
901 m_macEventHandler
= NULL
;
902 m_macFullScreenData
= NULL
;
905 class wxMacDeferredWindowDeleter
: public wxObject
908 wxMacDeferredWindowDeleter( WindowRef windowRef
)
910 m_macWindow
= windowRef
;
913 virtual ~wxMacDeferredWindowDeleter()
915 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
919 WindowRef m_macWindow
;
922 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
924 const wxString
& title
,
928 const wxString
& name
)
933 m_windowStyle
= style
;
937 m_windowId
= id
== -1 ? NewControlId() : id
;
938 wxWindow::SetLabel( title
) ;
940 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
942 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
944 if (GetExtraStyle() & wxFRAME_EX_METAL
)
945 MacSetMetalAppearance(true);
947 wxTopLevelWindows
.Append(this);
950 parent
->AddChild(this);
955 wxTopLevelWindowMac::~wxTopLevelWindowMac()
960 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
962 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
965 if ( m_macEventHandler
)
967 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
968 m_macEventHandler
= NULL
;
971 wxRemoveMacWindowAssociation( this ) ;
973 if ( wxModelessWindows
.Find(this) )
974 wxModelessWindows
.DeleteObject(this);
976 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
978 m_macFullScreenData
= NULL
;
982 // ----------------------------------------------------------------------------
983 // wxTopLevelWindowMac maximize/minimize
984 // ----------------------------------------------------------------------------
986 void wxTopLevelWindowMac::Maximize(bool maximize
)
988 // TODO: check if this is still necessary
990 wxMacPortStateHelper
help( (GrafPtr
)GetWindowPort( (WindowRef
)m_macWindow
) ) ;
991 wxMacWindowClipper
clip( this );
994 if ( !IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) )
998 GetWindowBounds((WindowRef
)m_macWindow
, kWindowGlobalPortRgn
, &rect
);
999 SetWindowIdealUserState((WindowRef
)m_macWindow
, &rect
);
1000 SetWindowUserState((WindowRef
)m_macWindow
, &rect
);
1003 ZoomWindow( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, false ) ;
1006 bool wxTopLevelWindowMac::IsMaximized() const
1008 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
1011 void wxTopLevelWindowMac::Iconize(bool iconize
)
1013 if ( IsWindowCollapsable( (WindowRef
)m_macWindow
) )
1014 CollapseWindow( (WindowRef
)m_macWindow
, iconize
) ;
1017 bool wxTopLevelWindowMac::IsIconized() const
1019 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1022 void wxTopLevelWindowMac::Restore()
1024 if ( IsMaximized() )
1026 else if ( IsIconized() )
1030 // ----------------------------------------------------------------------------
1031 // wxTopLevelWindowMac misc
1032 // ----------------------------------------------------------------------------
1034 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1036 return wxPoint(0, 0) ;
1039 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
1042 wxTopLevelWindowBase::SetIcon(icon
);
1045 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1047 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1049 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1051 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1055 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1057 if ( m_macEventHandler
!= NULL
)
1059 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1062 InstallWindowEventHandler(
1063 MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1064 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1067 void wxTopLevelWindowMac::MacCreateRealWindow(
1068 const wxString
& title
,
1072 const wxString
& name
)
1074 OSStatus err
= noErr
;
1076 m_windowStyle
= style
;
1084 wxRect display
= wxGetClientDisplayRect() ;
1086 if ( x
== wxDefaultPosition
.x
)
1089 if ( y
== wxDefaultPosition
.y
)
1092 int w
= WidthDefault(size
.x
);
1093 int h
= HeightDefault(size
.y
);
1095 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1097 // translate the window attributes in the appropriate window class and attributes
1098 WindowClass wclass
= 0;
1099 WindowAttributes attr
= kWindowNoAttributes
;
1100 WindowGroupRef group
= NULL
;
1102 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1105 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1106 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1107 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1110 wclass
= kFloatingWindowClass
;
1112 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1113 attr
|= kWindowSideTitlebarAttribute
;
1117 wclass
= kPlainWindowClass
;
1120 else if ( HasFlag( wxCAPTION
) )
1122 wclass
= kDocumentWindowClass
;
1123 attr
|= kWindowInWindowMenuAttribute
;
1125 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1126 else if ( HasFlag( wxFRAME_DRAWER
) )
1128 wclass
= kDrawerWindowClass
;
1129 // we must force compositing on a drawer
1130 m_macUsesCompositing
= true ;
1132 #endif //10.2 and up
1135 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1136 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1138 wclass
= kDocumentWindowClass
;
1142 wclass
= kPlainWindowClass
;
1146 if ( wclass
!= kPlainWindowClass
)
1148 if ( HasFlag( wxMINIMIZE_BOX
) )
1149 attr
|= kWindowCollapseBoxAttribute
;
1151 if ( HasFlag( wxMAXIMIZE_BOX
) )
1152 attr
|= kWindowFullZoomAttribute
;
1154 if ( HasFlag( wxRESIZE_BORDER
) )
1155 attr
|= kWindowResizableAttribute
;
1157 if ( HasFlag( wxCLOSE_BOX
) )
1158 attr
|= kWindowCloseBoxAttribute
;
1161 // turn on live resizing (OS X only)
1162 if (UMAGetSystemVersion() >= 0x1000)
1163 attr
|= kWindowLiveResizeAttribute
;
1165 if ( HasFlag(wxSTAY_ON_TOP
) )
1166 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1168 #if TARGET_API_MAC_OSX
1169 if ( m_macUsesCompositing
)
1170 attr
|= kWindowCompositingAttribute
;
1173 if ( HasFlag(wxFRAME_SHAPED
) )
1175 WindowDefSpec customWindowDefSpec
;
1176 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1177 customWindowDefSpec
.u
.defProc
= NewWindowDefUPP(wxShapedMacWindowDef
);
1179 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1180 attr
, &theBoundsRect
,
1181 (WindowRef
*) &m_macWindow
);
1185 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1188 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1189 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1191 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1193 // the create commands are only for content rect,
1194 // so we have to set the size again as structure bounds
1195 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1197 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1198 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1199 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1201 #if TARGET_API_MAC_OSX
1202 if ( m_macUsesCompositing
)
1204 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1205 // the content view, so we have to retrieve it explicitly
1206 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1207 m_peer
->GetControlRefAddr() ) ;
1208 if ( !m_peer
->Ok() )
1210 // compatibility mode fallback
1211 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1216 ::CreateRootControl( (WindowRef
)m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1219 // the root control level handler
1220 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1222 #if TARGET_API_MAC_OSX
1223 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1225 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1226 MacSetMetalAppearance( true ) ;
1230 // the frame window event handler
1231 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1232 MacInstallTopLevelWindowEventHandler() ;
1234 DoSetWindowVariant( m_windowVariant
) ;
1238 if ( HasFlag(wxFRAME_SHAPED
) )
1240 // default shape matches the window size
1241 wxRegion
rgn( 0, 0, w
, h
);
1245 wxWindowCreateEvent
event(this);
1246 GetEventHandler()->ProcessEvent(event
);
1249 void wxTopLevelWindowMac::ClearBackground()
1251 wxWindow::ClearBackground() ;
1254 // Raise the window to the top of the Z order
1255 void wxTopLevelWindowMac::Raise()
1257 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1260 // Lower the window to the bottom of the Z order
1261 void wxTopLevelWindowMac::Lower()
1263 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1266 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1268 if (s_macDeactivateWindow
)
1270 wxLogTrace(TRACE_ACTIVATE
,
1271 wxT("Doing delayed deactivation of %p"),
1272 s_macDeactivateWindow
);
1274 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1278 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1280 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1282 if (s_macDeactivateWindow
== this)
1283 s_macDeactivateWindow
= NULL
;
1285 MacDelayedDeactivation(timestamp
);
1286 MacPropagateHiliteChanged() ;
1289 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1291 wxWindow::SetLabel( title
) ;
1292 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1295 wxString
wxTopLevelWindowMac::GetTitle() const
1297 return wxWindow::GetLabel();
1300 bool wxTopLevelWindowMac::Show(bool show
)
1302 if ( !wxTopLevelWindowBase::Show(show
) )
1305 bool plainTransition
= false;
1307 #if wxUSE_SYSTEM_OPTIONS
1308 // code contributed by Ryan Wilcox December 18, 2003
1309 plainTransition
= UMAGetSystemVersion() >= 0x1000 ;
1310 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1311 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1316 if ( plainTransition
)
1317 ::ShowWindow( (WindowRef
)m_macWindow
);
1319 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1321 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1323 // because apps expect a size event to occur at this moment
1324 wxSizeEvent
event(GetSize() , m_windowId
);
1325 event
.SetEventObject(this);
1326 GetEventHandler()->ProcessEvent(event
);
1330 if ( plainTransition
)
1331 ::HideWindow( (WindowRef
)m_macWindow
);
1333 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1336 MacPropagateVisibilityChanged() ;
1341 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1345 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1347 data
= new FullScreenData() ;
1349 m_macFullScreenData
= data
;
1350 data
->m_position
= GetPosition() ;
1351 data
->m_size
= GetSize() ;
1352 data
->m_wasResizable
= MacGetWindowAttributes() & kWindowResizableAttribute
;
1354 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1357 wxRect client
= wxGetClientDisplayRect() ;
1359 int left
, top
, right
, bottom
;
1367 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1369 if ( style
& wxFULLSCREEN_NOCAPTION
)
1375 if ( style
& wxFULLSCREEN_NOBORDER
)
1382 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1387 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1392 SetSize( x
, y
, w
, h
) ;
1393 if ( data
->m_wasResizable
)
1394 MacChangeWindowAttributes( kWindowNoAttributes
, kWindowResizableAttribute
) ;
1399 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1400 if ( data
->m_wasResizable
)
1401 MacChangeWindowAttributes( kWindowResizableAttribute
, kWindowNoAttributes
) ;
1402 SetPosition( data
->m_position
) ;
1403 SetSize( data
->m_size
) ;
1406 m_macFullScreenData
= NULL
;
1412 bool wxTopLevelWindowMac::IsFullScreen() const
1414 return m_macFullScreenData
!= NULL
;
1417 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1419 if ( GetExtraStyle() == exStyle
)
1422 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1424 #if TARGET_API_MAC_OSX
1425 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1427 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1428 if ( MacGetMetalAppearance() != metal
)
1429 MacSetMetalAppearance( metal
) ;
1434 // we are still using coordinates of the content view
1435 // TODO: switch to structure bounds
1437 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1439 Rect content
, structure
;
1441 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1442 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1444 left
= content
.left
- structure
.left
;
1445 top
= content
.top
- structure
.top
;
1446 right
= structure
.right
- content
.right
;
1447 bottom
= structure
.bottom
- content
.bottom
;
1450 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1452 m_cachedClippedRectValid
= false ;
1453 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1454 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1455 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1458 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1462 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1470 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1474 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1477 *width
= bounds
.right
- bounds
.left
;
1479 *height
= bounds
.bottom
- bounds
.top
;
1482 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1486 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1489 *width
= bounds
.right
- bounds
.left
;
1491 *height
= bounds
.bottom
- bounds
.top
;
1494 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1496 #if TARGET_API_MAC_OSX
1497 wxASSERT_MSG( m_macUsesCompositing
,
1498 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1500 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1501 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1505 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1507 #if TARGET_API_MAC_OSX
1508 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1514 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1516 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1519 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1522 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1527 void wxTopLevelWindowMac::MacPerformUpdates()
1529 #if TARGET_API_MAC_OSX
1530 if ( m_macUsesCompositing
)
1532 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1533 // for composited windows this also triggers a redraw of all
1534 // invalid views in the window
1535 if ( UMAGetSystemVersion() >= 0x1030 )
1536 HIWindowFlush((WindowRef
) m_macWindow
) ;
1540 // the only way to trigger the redrawing on earlier systems is to call
1543 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1544 UInt32 currentEventClass
= 0 ;
1545 UInt32 currentEventKind
= 0 ;
1546 if ( currentEvent
!= NULL
)
1548 currentEventClass
= ::GetEventClass( currentEvent
) ;
1549 currentEventKind
= ::GetEventKind( currentEvent
) ;
1552 if ( currentEventClass
!= kEventClassMenu
)
1554 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1556 OSStatus status
= noErr
;
1557 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1564 BeginUpdate( (WindowRef
) m_macWindow
) ;
1566 RgnHandle updateRgn
= NewRgn();
1569 GetPortVisibleRegion( GetWindowPort( (WindowRef
)m_macWindow
), updateRgn
);
1570 UpdateControls( (WindowRef
)m_macWindow
, updateRgn
) ;
1572 // if ( !EmptyRgn( updateRgn ) )
1573 // MacDoRedraw( updateRgn , 0 , true) ;
1575 DisposeRgn( updateRgn
);
1578 EndUpdate( (WindowRef
)m_macWindow
) ;
1579 QDFlushPortBuffer( GetWindowPort( (WindowRef
)m_macWindow
) , NULL
) ;
1583 // Attracts the users attention to this window if the application is
1584 // inactive (should be called when a background event occurs)
1586 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1589 DisposePtr( (Ptr
)ptr
) ;
1592 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1594 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1595 static wxMacNMUPP
nmupp( wxMacNMResponse
);
1597 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1598 notificationRequest
->qType
= nmType
;
1599 notificationRequest
->nmMark
= 1 ;
1600 notificationRequest
->nmIcon
= 0 ;
1601 notificationRequest
->nmSound
= 0 ;
1602 notificationRequest
->nmStr
= NULL
;
1603 notificationRequest
->nmResp
= nmupp
;
1605 verify_noerr( NMInstall( notificationRequest
) ) ;
1608 // ---------------------------------------------------------------------------
1609 // Shape implementation
1610 // ---------------------------------------------------------------------------
1613 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1615 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1616 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1618 // The empty region signifies that the shape
1619 // should be removed from the window.
1620 if ( region
.IsEmpty() )
1622 wxSize sz
= GetClientSize();
1623 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1624 if ( rgn
.IsEmpty() )
1627 return SetShape(rgn
);
1630 // Make a copy of the region
1631 RgnHandle shapeRegion
= NewRgn();
1632 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1634 // Dispose of any shape region we may already have
1635 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1639 // Save the region so we can use it later
1640 SetWRefCon((WindowRef
)MacGetWindowRef(), (SInt32
)shapeRegion
);
1642 // inform the window manager that the window has changed shape
1643 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1648 // ---------------------------------------------------------------------------
1649 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1650 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1651 // ---------------------------------------------------------------------------
1653 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1655 GetWindowPortBounds(window
, inRect
);
1656 Point pt
= { inRect
->left
, inRect
->top
};
1658 QDLocalToGlobalPoint( GetWindowPort(window
), &pt
) ;
1660 inRect
->left
= pt
.h
;
1661 inRect
->bottom
+= pt
.v
;
1662 inRect
->right
+= pt
.h
;
1665 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1667 /*------------------------------------------------------
1668 Define which options your custom window supports.
1669 --------------------------------------------------------*/
1670 //just enable everything for our demo
1671 *(OptionBits
*)param
=
1674 //kWindowCanCollapse |
1675 //kWindowCanGetWindowRegion |
1676 //kWindowHasTitleBar |
1677 //kWindowSupportsDragHilite |
1678 kWindowCanDrawInCurrentPort
|
1679 //kWindowCanMeasureTitle |
1680 kWindowWantsDisposeAtProcessDeath
|
1681 kWindowSupportsGetGrowImageRegion
|
1682 kWindowDefSupportsColorGrafPort
;
1687 // The content region is left as a rectangle matching the window size, this is
1688 // so the origin in the paint event, and etc. still matches what the
1689 // programmer expects.
1690 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1693 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1697 wxShapedMacWindowGetPos( window
, &r
) ;
1698 RectRgn( rgn
, &r
) ;
1702 // The structure region is set to the shape given to the SetShape method.
1703 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1705 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1711 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1712 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1713 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1714 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1718 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1720 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1725 switch (rgnRec
->regionCode
)
1727 case kWindowStructureRgn
:
1728 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1731 case kWindowContentRgn
:
1732 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1736 SetEmptyRgn(rgnRec
->winRgn
);
1743 // Determine the region of the window which was hit
1745 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1748 static RgnHandle tempRgn
= NULL
;
1750 if (tempRgn
== NULL
)
1753 // get the point clicked
1754 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1756 // Mac OS 8.5 or later
1757 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1758 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1761 // no significant area was hit
1765 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1769 case kWindowMsgHitTest
:
1770 return wxShapedMacWindowHitTest(window
, param
);
1772 case kWindowMsgGetFeatures
:
1773 return wxShapedMacWindowGetFeatures(window
, param
);
1775 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1776 case kWindowMsgGetRegion
:
1777 return wxShapedMacWindowGetRegion(window
, param
);