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
;
451 WindowRef window
= NULL
;
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 // Causes the inner part of the window not to be metal
1223 // if the style is used before window creation.
1224 #if 0 // TARGET_API_MAC_OSX
1225 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1227 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1228 MacSetMetalAppearance( true ) ;
1232 // the frame window event handler
1233 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1234 MacInstallTopLevelWindowEventHandler() ;
1236 DoSetWindowVariant( m_windowVariant
) ;
1240 if ( HasFlag(wxFRAME_SHAPED
) )
1242 // default shape matches the window size
1243 wxRegion
rgn( 0, 0, w
, h
);
1247 wxWindowCreateEvent
event(this);
1248 GetEventHandler()->ProcessEvent(event
);
1251 void wxTopLevelWindowMac::ClearBackground()
1253 wxWindow::ClearBackground() ;
1256 // Raise the window to the top of the Z order
1257 void wxTopLevelWindowMac::Raise()
1259 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1262 // Lower the window to the bottom of the Z order
1263 void wxTopLevelWindowMac::Lower()
1265 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1268 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1270 if (s_macDeactivateWindow
)
1272 wxLogTrace(TRACE_ACTIVATE
,
1273 wxT("Doing delayed deactivation of %p"),
1274 s_macDeactivateWindow
);
1276 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1280 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1282 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1284 if (s_macDeactivateWindow
== this)
1285 s_macDeactivateWindow
= NULL
;
1287 MacDelayedDeactivation(timestamp
);
1288 MacPropagateHiliteChanged() ;
1291 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1293 wxWindow::SetLabel( title
) ;
1294 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1297 wxString
wxTopLevelWindowMac::GetTitle() const
1299 return wxWindow::GetLabel();
1302 bool wxTopLevelWindowMac::Show(bool show
)
1304 if ( !wxTopLevelWindowBase::Show(show
) )
1307 bool plainTransition
= false;
1309 #if wxUSE_SYSTEM_OPTIONS
1310 // code contributed by Ryan Wilcox December 18, 2003
1311 plainTransition
= UMAGetSystemVersion() >= 0x1000 ;
1312 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1313 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1318 if ( plainTransition
)
1319 ::ShowWindow( (WindowRef
)m_macWindow
);
1321 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1323 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1325 // because apps expect a size event to occur at this moment
1326 wxSizeEvent
event(GetSize() , m_windowId
);
1327 event
.SetEventObject(this);
1328 GetEventHandler()->ProcessEvent(event
);
1332 if ( plainTransition
)
1333 ::HideWindow( (WindowRef
)m_macWindow
);
1335 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1338 MacPropagateVisibilityChanged() ;
1343 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1347 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1349 data
= new FullScreenData() ;
1351 m_macFullScreenData
= data
;
1352 data
->m_position
= GetPosition() ;
1353 data
->m_size
= GetSize() ;
1354 data
->m_wasResizable
= MacGetWindowAttributes() & kWindowResizableAttribute
;
1356 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1359 wxRect client
= wxGetClientDisplayRect() ;
1361 int left
, top
, right
, bottom
;
1369 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1371 if ( style
& wxFULLSCREEN_NOCAPTION
)
1377 if ( style
& wxFULLSCREEN_NOBORDER
)
1384 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1389 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1394 SetSize( x
, y
, w
, h
) ;
1395 if ( data
->m_wasResizable
)
1396 MacChangeWindowAttributes( kWindowNoAttributes
, kWindowResizableAttribute
) ;
1401 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1402 if ( data
->m_wasResizable
)
1403 MacChangeWindowAttributes( kWindowResizableAttribute
, kWindowNoAttributes
) ;
1404 SetPosition( data
->m_position
) ;
1405 SetSize( data
->m_size
) ;
1408 m_macFullScreenData
= NULL
;
1414 bool wxTopLevelWindowMac::IsFullScreen() const
1416 return m_macFullScreenData
!= NULL
;
1419 void wxTopLevelWindowMac::SetExtraStyle(long exStyle
)
1421 if ( GetExtraStyle() == exStyle
)
1424 wxTopLevelWindowBase::SetExtraStyle( exStyle
) ;
1426 #if TARGET_API_MAC_OSX
1427 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1429 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1430 if ( MacGetMetalAppearance() != metal
)
1431 MacSetMetalAppearance( metal
) ;
1436 // TODO: switch to structure bounds -
1437 // we are still using coordinates of the content view
1439 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1441 Rect content
, structure
;
1443 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1444 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1446 left
= content
.left
- structure
.left
;
1447 top
= content
.top
- structure
.top
;
1448 right
= structure
.right
- content
.right
;
1449 bottom
= structure
.bottom
- content
.bottom
;
1452 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1454 m_cachedClippedRectValid
= false ;
1455 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1456 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1457 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1460 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1464 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1472 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1476 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1479 *width
= bounds
.right
- bounds
.left
;
1481 *height
= bounds
.bottom
- bounds
.top
;
1484 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1488 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1491 *width
= bounds
.right
- bounds
.left
;
1493 *height
= bounds
.bottom
- bounds
.top
;
1496 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1498 #if TARGET_API_MAC_OSX
1499 wxASSERT_MSG( m_macUsesCompositing
,
1500 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1502 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1503 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1507 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1509 #if TARGET_API_MAC_OSX
1510 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1516 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1518 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1521 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1524 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1529 void wxTopLevelWindowMac::MacPerformUpdates()
1531 #if TARGET_API_MAC_OSX
1532 if ( m_macUsesCompositing
)
1534 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1535 // for composited windows this also triggers a redraw of all
1536 // invalid views in the window
1537 if ( UMAGetSystemVersion() >= 0x1030 )
1538 HIWindowFlush((WindowRef
) m_macWindow
) ;
1542 // the only way to trigger the redrawing on earlier systems is to call
1545 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1546 UInt32 currentEventClass
= 0 ;
1547 UInt32 currentEventKind
= 0 ;
1548 if ( currentEvent
!= NULL
)
1550 currentEventClass
= ::GetEventClass( currentEvent
) ;
1551 currentEventKind
= ::GetEventKind( currentEvent
) ;
1554 if ( currentEventClass
!= kEventClassMenu
)
1556 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1558 OSStatus status
= noErr
;
1559 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1566 BeginUpdate( (WindowRef
) m_macWindow
) ;
1568 RgnHandle updateRgn
= NewRgn();
1571 GetPortVisibleRegion( GetWindowPort( (WindowRef
)m_macWindow
), updateRgn
);
1572 UpdateControls( (WindowRef
)m_macWindow
, updateRgn
) ;
1574 // if ( !EmptyRgn( updateRgn ) )
1575 // MacDoRedraw( updateRgn , 0 , true) ;
1577 DisposeRgn( updateRgn
);
1580 EndUpdate( (WindowRef
)m_macWindow
) ;
1581 QDFlushPortBuffer( GetWindowPort( (WindowRef
)m_macWindow
) , NULL
) ;
1585 // Attracts the users attention to this window if the application is
1586 // inactive (should be called when a background event occurs)
1588 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1591 DisposePtr( (Ptr
)ptr
) ;
1594 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1596 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1597 static wxMacNMUPP
nmupp( wxMacNMResponse
);
1599 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1600 notificationRequest
->qType
= nmType
;
1601 notificationRequest
->nmMark
= 1 ;
1602 notificationRequest
->nmIcon
= 0 ;
1603 notificationRequest
->nmSound
= 0 ;
1604 notificationRequest
->nmStr
= NULL
;
1605 notificationRequest
->nmResp
= nmupp
;
1607 verify_noerr( NMInstall( notificationRequest
) ) ;
1610 // ---------------------------------------------------------------------------
1611 // Shape implementation
1612 // ---------------------------------------------------------------------------
1615 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1617 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1618 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1620 // The empty region signifies that the shape
1621 // should be removed from the window.
1622 if ( region
.IsEmpty() )
1624 wxSize sz
= GetClientSize();
1625 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1626 if ( rgn
.IsEmpty() )
1629 return SetShape(rgn
);
1632 // Make a copy of the region
1633 RgnHandle shapeRegion
= NewRgn();
1634 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1636 // Dispose of any shape region we may already have
1637 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1641 // Save the region so we can use it later
1642 SetWRefCon((WindowRef
)MacGetWindowRef(), (SInt32
)shapeRegion
);
1644 // inform the window manager that the window has changed shape
1645 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1650 // ---------------------------------------------------------------------------
1651 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1652 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1653 // ---------------------------------------------------------------------------
1655 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1657 GetWindowPortBounds(window
, inRect
);
1658 Point pt
= { inRect
->left
, inRect
->top
};
1660 QDLocalToGlobalPoint( GetWindowPort(window
), &pt
) ;
1662 inRect
->left
= pt
.h
;
1663 inRect
->bottom
+= pt
.v
;
1664 inRect
->right
+= pt
.h
;
1667 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1669 /*------------------------------------------------------
1670 Define which options your custom window supports.
1671 --------------------------------------------------------*/
1672 //just enable everything for our demo
1673 *(OptionBits
*)param
=
1676 //kWindowCanCollapse |
1677 //kWindowCanGetWindowRegion |
1678 //kWindowHasTitleBar |
1679 //kWindowSupportsDragHilite |
1680 kWindowCanDrawInCurrentPort
|
1681 //kWindowCanMeasureTitle |
1682 kWindowWantsDisposeAtProcessDeath
|
1683 kWindowSupportsGetGrowImageRegion
|
1684 kWindowDefSupportsColorGrafPort
;
1689 // The content region is left as a rectangle matching the window size, this is
1690 // so the origin in the paint event, and etc. still matches what the
1691 // programmer expects.
1692 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1695 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1699 wxShapedMacWindowGetPos( window
, &r
) ;
1700 RectRgn( rgn
, &r
) ;
1704 // The structure region is set to the shape given to the SetShape method.
1705 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1707 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1713 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1714 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1715 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1716 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1720 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1722 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1727 switch (rgnRec
->regionCode
)
1729 case kWindowStructureRgn
:
1730 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1733 case kWindowContentRgn
:
1734 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1738 SetEmptyRgn(rgnRec
->winRgn
);
1745 // Determine the region of the window which was hit
1747 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1750 static RgnHandle tempRgn
= NULL
;
1752 if (tempRgn
== NULL
)
1755 // get the point clicked
1756 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1758 // Mac OS 8.5 or later
1759 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1760 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1763 // no significant area was hit
1767 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1771 case kWindowMsgHitTest
:
1772 return wxShapedMacWindowHitTest(window
, param
);
1774 case kWindowMsgGetFeatures
:
1775 return wxShapedMacWindowGetFeatures(window
, param
);
1777 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1778 case kWindowMsgGetRegion
:
1779 return wxShapedMacWindowGetRegion(window
, param
);