1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: mac/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for Mac
4 // Author: Stefan Csomor
8 // Copyright: (c) 2001-2004 Stefan Csomor
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "toplevel.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/toplevel.h"
35 #include "wx/string.h"
38 #include "wx/settings.h"
39 #include "wx/strconv.h"
40 #include "wx/control.h"
43 #include "wx/mac/uma.h"
44 #include "wx/mac/aga.h"
46 #include "wx/tooltip.h"
48 #if wxUSE_SYSTEM_OPTIONS
49 #include "wx/sysopt.h"
53 #include <ToolUtils.h>
57 #include "wx/mac/private.h"
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 // trace mask for activation tracing messages
64 static const wxChar
*TRACE_ACTIVATE
= _T("activation");
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 // list of all frames and modeless dialogs
71 wxWindowList wxModelessWindows
;
73 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
75 // ============================================================================
76 // wxTopLevelWindowMac implementation
77 // ============================================================================
79 BEGIN_EVENT_TABLE(wxTopLevelWindowMac
, wxTopLevelWindowBase
)
83 // ---------------------------------------------------------------------------
85 // ---------------------------------------------------------------------------
87 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
89 static const EventTypeSpec eventList
[] =
91 // TODO remove control related event like key and mouse (except for WindowLeave events)
93 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
95 { kEventClassKeyboard
, kEventRawKeyDown
} ,
96 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
97 { kEventClassKeyboard
, kEventRawKeyUp
} ,
98 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
101 { kEventClassWindow
, kEventWindowShown
} ,
102 { kEventClassWindow
, kEventWindowActivated
} ,
103 { kEventClassWindow
, kEventWindowDeactivated
} ,
104 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
105 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
106 { kEventClassWindow
, kEventWindowClose
} ,
108 // we have to catch these events on the toplevel window level, as controls don't get the
109 // raw mouse events anymore
111 { kEventClassMouse
, kEventMouseDown
} ,
112 { kEventClassMouse
, kEventMouseUp
} ,
113 { kEventClassMouse
, kEventMouseWheelMoved
} ,
114 { kEventClassMouse
, kEventMouseMoved
} ,
115 { kEventClassMouse
, kEventMouseDragged
} ,
118 static pascal OSStatus
TextInputEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
120 OSStatus result
= eventNotHandledErr
;
122 wxWindow
* focus
= wxWindow::FindFocus() ;
123 unsigned char charCode
;
130 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent
) ;
132 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
,sizeof(char), NULL
,&charCode
);
133 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
134 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
135 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
136 sizeof( Point
), NULL
, &point
);
138 switch ( GetEventKind( event
) )
140 case kEventTextInputUnicodeForKeyEvent
:
141 // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not
142 // get its own kEventTextInputUnicodeForKeyEvent, so we route back the
143 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
146 ControlRef macControl
= (ControlRef
) control
->GetHandle() ;
149 ::HandleControlKey( macControl
, keyCode
, charCode
, modifiers
) ;
154 // this may lead to double events sent to a window in case all handlers have skipped the key down event
155 UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
156 UInt32 message = (keyCode << 8) + charCode;
158 if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent(
159 focus , message , modifiers , when , point.h , point.v ) )
170 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
172 OSStatus result
= eventNotHandledErr
;
173 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
174 // FindFocus does not return the actual focus window,but the enclosing window
175 wxWindow
* focus
= wxWindow::DoFindFocus();
179 unsigned char charCode
;
184 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
187 UInt32 dataSize
= 0 ;
188 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
192 UniChar
* charBuf
= buf
;
195 charBuf
= new UniChar
[ dataSize
/ sizeof( UniChar
) ] ;
196 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
197 #if SIZEOF_WCHAR_T == 2
198 uniChar
= charBuf
[0] ;
200 wxMBConvUTF16 converter
;
201 converter
.MB2WC( &uniChar
, (const char*)charBuf
, 1 ) ;
208 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
,sizeof(char), NULL
,&charCode
);
209 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
210 GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
211 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
212 sizeof( Point
), NULL
, &point
);
214 UInt32 message
= (keyCode
<< 8) + charCode
;
215 switch( GetEventKind( event
) )
217 case kEventRawKeyRepeat
:
218 case kEventRawKeyDown
:
220 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
221 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
222 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
223 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
224 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
) )
228 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
231 case kEventRawKeyUp
:
232 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
233 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
) )
238 case kEventRawKeyModifiersChanged
:
240 wxKeyEvent
event(wxEVT_KEY_DOWN
);
242 event
.m_shiftDown
= modifiers
& shiftKey
;
243 event
.m_controlDown
= modifiers
& controlKey
;
244 event
.m_altDown
= modifiers
& optionKey
;
245 event
.m_metaDown
= modifiers
& cmdKey
;
247 event
.m_uniChar
= uniChar
;
251 event
.SetTimestamp(when
);
252 event
.SetEventObject(focus
);
254 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
256 event
.m_keyCode
= WXK_CONTROL
;
257 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
258 focus
->GetEventHandler()->ProcessEvent( event
) ;
260 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
262 event
.m_keyCode
= WXK_SHIFT
;
263 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
264 focus
->GetEventHandler()->ProcessEvent( event
) ;
266 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
268 event
.m_keyCode
= WXK_ALT
;
269 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
270 focus
->GetEventHandler()->ProcessEvent( event
) ;
272 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
274 event
.m_keyCode
= WXK_COMMAND
;
275 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
276 focus
->GetEventHandler()->ProcessEvent( event
) ;
278 wxApp::s_lastModifiers
= modifiers
;
286 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
287 // for windows that we didn't create (like eg Scrollbars in a databrowser) , or for controls where we did not handle the
290 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
292 wxWindow
* g_MacLastWindow
= NULL
;
294 static EventMouseButton lastButton
= 0 ;
296 static void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
298 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
299 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
301 // this parameter are not given for all events
302 EventMouseButton button
= 0 ;
303 UInt32 clickCount
= 0 ;
304 cEvent
.GetParameter
<EventMouseButton
>(kEventParamMouseButton
, typeMouseButton
, &button
) ;
305 cEvent
.GetParameter
<UInt32
>(kEventParamClickCount
, typeUInt32
, &clickCount
) ;
307 wxevent
.m_x
= screenMouseLocation
.h
;
308 wxevent
.m_y
= screenMouseLocation
.v
;
309 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
310 wxevent
.m_controlDown
= modifiers
& controlKey
;
311 wxevent
.m_altDown
= modifiers
& optionKey
;
312 wxevent
.m_metaDown
= modifiers
& cmdKey
;
313 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
314 // a control click is interpreted as a right click
315 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
317 button
= kEventMouseButtonSecondary
;
320 // otherwise we report double clicks by connecting a left click with a ctrl-left click
321 if ( clickCount
> 1 && button
!= lastButton
)
324 // we must make sure that our synthetic 'right' button corresponds in
325 // mouse down, moved and mouse up, and does not deliver a right down and left up
327 if ( cEvent
.GetKind() == kEventMouseDown
)
328 lastButton
= button
;
332 else if ( lastButton
)
333 button
= lastButton
;
335 // determinate the correct down state, wx does not want a 'down' for a mouseUp event, while mac delivers
337 if ( button
!= 0 && cEvent
.GetKind() != kEventMouseUp
)
341 case kEventMouseButtonPrimary
:
342 wxevent
.m_leftDown
= true ;
344 case kEventMouseButtonSecondary
:
345 wxevent
.m_rightDown
= true ;
347 case kEventMouseButtonTertiary
:
348 wxevent
.m_middleDown
= true ;
352 // translate into wx types
353 switch ( cEvent
.GetKind() )
355 case kEventMouseDown
:
358 case kEventMouseButtonPrimary
:
359 wxevent
.SetEventType(clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
361 case kEventMouseButtonSecondary
:
362 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
364 case kEventMouseButtonTertiary
:
365 wxevent
.SetEventType(clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
372 case kEventMouseButtonPrimary
:
373 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
375 case kEventMouseButtonSecondary
:
376 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
378 case kEventMouseButtonTertiary
:
379 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
383 case kEventMouseWheelMoved
:
385 wxevent
.SetEventType(wxEVT_MOUSEWHEEL
) ;
387 // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
388 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeLongInteger
) ;
390 wxevent
.m_wheelRotation
= delta
;
391 wxevent
.m_wheelDelta
= 1;
392 wxevent
.m_linesPerAction
= 1;
396 wxevent
.SetEventType(wxEVT_MOTION
) ;
401 ControlRef
wxMacFindSubControl( wxTopLevelWindowMac
* toplevelWindow
, Point location
, ControlRef superControl
, ControlPartCode
*outPart
)
405 UInt16 childrenCount
= 0 ;
406 OSStatus err
= CountSubControls( superControl
, &childrenCount
) ;
407 if ( err
== errControlIsNotEmbedder
)
409 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
411 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
413 ControlHandle sibling
;
414 err
= GetIndexedSubControl( superControl
, i
, & sibling
) ;
415 if ( err
== errControlIsNotEmbedder
)
418 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
419 if ( IsControlVisible( sibling
) )
422 UMAGetControlBoundsInWindowCoords( sibling
, &r
) ;
423 if ( MacPtInRect( location
, &r
) )
425 ControlHandle child
= wxMacFindSubControl( toplevelWindow
, location
, sibling
, outPart
) ;
430 Point testLocation
= location
;
432 if ( toplevelWindow
&& toplevelWindow
->MacUsesCompositing() )
434 testLocation
.h
-= r
.left
;
435 testLocation
.v
-= r
.top
;
438 *outPart
= TestControl( sibling
, testLocation
) ;
448 ControlRef
wxMacFindControlUnderMouse( wxTopLevelWindowMac
* toplevelWindow
, Point location
, WindowRef window
, ControlPartCode
*outPart
)
450 #if TARGET_API_MAC_OSX
451 if ( UMAGetSystemVersion() >= 0x1030 && ( toplevelWindow
== 0 || toplevelWindow
->MacUsesCompositing() ) )
452 return FindControlUnderMouse( location
, window
, outPart
) ;
454 ControlRef rootControl
= NULL
;
455 verify_noerr( GetRootControl( window
, &rootControl
) ) ;
456 return wxMacFindSubControl( toplevelWindow
, location
, rootControl
, outPart
) ;
460 #define NEW_CAPTURE_HANDLING 1
462 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
464 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
466 OSStatus result
= eventNotHandledErr
;
468 wxMacCarbonEvent
cEvent( event
) ;
470 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
471 Point windowMouseLocation
= screenMouseLocation
;
474 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
476 wxWindow
* currentMouseWindow
= NULL
;
477 ControlRef control
= NULL
;
479 #if NEW_CAPTURE_HANDLING
480 if ( wxApp::s_captureWindow
)
482 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
483 windowPart
= inContent
;
489 QDGlobalToLocalPoint( UMAGetWindowPort(window
) , &windowMouseLocation
) ;
491 if ( wxApp::s_captureWindow
492 #if !NEW_CAPTURE_HANDLING
493 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
497 currentMouseWindow
= wxApp::s_captureWindow
;
499 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
501 ControlPartCode part
;
502 control
= wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &part
) ;
503 // if there is no control below the mouse position, send the event to the toplevel window itself
505 currentMouseWindow
= (wxWindow
*) data
;
508 currentMouseWindow
= wxFindControlFromMacControl( control
) ;
509 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
512 // for wxToolBar to function we have to send certaint events to it
513 // instead of its children (wxToolBarTools)
515 GetSuperControl(control
, &parent
);
516 wxWindow
*wxParent
= wxFindControlFromMacControl( parent
) ;
517 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
518 currentMouseWindow
= wxParent
;
525 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
526 SetupMouseEvent( wxevent
, cEvent
) ;
528 // handle all enter / leave events
530 if ( currentMouseWindow
!= g_MacLastWindow
)
532 if ( g_MacLastWindow
)
534 wxMouseEvent
eventleave(wxevent
);
535 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
536 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
537 eventleave
.SetEventObject( g_MacLastWindow
) ;
540 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
541 #endif // wxUSE_TOOLTIPS
542 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
544 if ( currentMouseWindow
)
546 wxMouseEvent
evententer(wxevent
);
547 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
548 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
549 evententer
.SetEventObject( currentMouseWindow
) ;
551 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
552 #endif // wxUSE_TOOLTIPS
553 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
555 g_MacLastWindow
= currentMouseWindow
;
558 if ( windowPart
== inMenuBar
)
560 // special case menu bar, as we are having a low-level runloop we must do it ourselves
561 if ( cEvent
.GetKind() == kEventMouseDown
)
563 ::MenuSelect( screenMouseLocation
) ;
566 } // if ( windowPart == inMenuBar )
567 else if ( currentMouseWindow
)
569 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
571 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
573 wxevent
.SetEventObject( currentMouseWindow
) ;
575 // make tooltips current
578 if ( wxevent
.GetEventType() == wxEVT_MOTION
579 || wxevent
.GetEventType() == wxEVT_ENTER_WINDOW
580 || wxevent
.GetEventType() == wxEVT_LEAVE_WINDOW
)
581 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
582 #endif // wxUSE_TOOLTIPS
583 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
585 if ((currentMouseWindowParent
!= NULL
) &&
586 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
587 currentMouseWindow
= NULL
;
593 // if the user code did _not_ handle the event, then perform the
594 // default processing
595 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
597 // ... that is set focus to this window
598 if (currentMouseWindow
->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
599 currentMouseWindow
->SetFocus();
602 ControlPartCode dummyPart
;
603 // if built-in find control is finding the wrong control (ie static box instead of overlaid
604 // button, we cannot let the standard handler do its job, but must handle manually
606 if ( ( cEvent
.GetKind() == kEventMouseDown
)
609 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
610 wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &dummyPart
) )
614 if ( currentMouseWindow
->MacIsReallyEnabled() )
616 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
617 Point clickLocation
= windowMouseLocation
;
619 if ( toplevelWindow
->MacUsesCompositing() )
620 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
622 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
623 modifiers
, (ControlActionUPP
) -1 ) ;
625 if ((currentMouseWindowParent
!= NULL
) &&
626 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
627 currentMouseWindow
= NULL
;
632 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
634 wxApp::s_captureWindow
= NULL
;
640 wxWindow
* cursorTarget
= currentMouseWindow
;
641 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
643 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
645 cursorTarget
= cursorTarget
->GetParent() ;
647 cursorPoint
+= cursorTarget
->GetPosition();
650 } // else if ( currentMouseWindow )
653 // don't mess with controls we don't know about
654 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
655 // so we try sending them the correct control directly
656 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
658 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
659 Point clickLocation
= windowMouseLocation
;
660 if ( toplevelWindow
->MacUsesCompositing() )
664 hiPoint
.x
= clickLocation
.h
;
665 hiPoint
.y
= clickLocation
.v
;
666 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
667 clickLocation
.h
= (int)hiPoint
.x
;
668 clickLocation
.v
= (int)hiPoint
.y
;
671 HandleControlClick( control
, clickLocation
,
672 modifiers
, (ControlActionUPP
) -1 ) ;
679 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
681 OSStatus result
= eventNotHandledErr
;
683 wxMacCarbonEvent
cEvent( event
) ;
685 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
686 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
688 switch( GetEventKind( event
) )
690 case kEventWindowActivated
:
692 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
693 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
694 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
695 wxevent
.SetEventObject(toplevelWindow
);
696 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
697 // we still sending an eventNotHandledErr in order to allow for default processing
700 case kEventWindowDeactivated
:
702 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
703 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
704 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
705 wxevent
.SetEventObject(toplevelWindow
);
706 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
707 // we still sending an eventNotHandledErr in order to allow for default processing
710 case kEventWindowShown
:
712 toplevelWindow
->Refresh() ;
716 case kEventWindowClose
:
717 toplevelWindow
->Close() ;
720 case kEventWindowBoundsChanged
:
722 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
723 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
724 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
725 if ( attributes
& kWindowBoundsChangeSizeChanged
)
727 // according to the other ports we handle this within the OS level
728 // resize event, not within a wxSizeEvent
729 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
733 frame
->PositionStatusBar();
736 frame
->PositionToolBar();
740 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
741 event
.SetEventObject( toplevelWindow
) ;
743 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
744 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
746 if ( attributes
& kWindowBoundsChangeOriginChanged
)
748 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
749 event
.SetEventObject( toplevelWindow
) ;
750 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
755 case kEventWindowBoundsChanging
:
757 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
758 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
760 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
762 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
763 int left
, top
, right
, bottom
;
764 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
765 wxRect
r( newRect
.left
- left
, newRect
.top
- top
,
766 newRect
.right
- newRect
.left
+ left
+ right
, newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
767 // this is a EVT_SIZING not a EVT_SIZE type !
768 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
769 wxevent
.SetEventObject( toplevelWindow
) ;
771 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
772 adjustR
= wxevent
.GetRect() ;
774 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
775 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
776 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
777 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
778 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
779 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
780 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
781 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
782 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
783 if ( !EqualRect( &newRect
, &adjustedRect
) )
784 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
785 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
797 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
799 OSStatus result
= eventNotHandledErr
;
801 switch ( GetEventClass( event
) )
803 case kEventClassKeyboard
:
804 result
= KeyboardEventHandler( handler
, event
, data
) ;
806 case kEventClassTextInput
:
807 result
= TextInputEventHandler( handler
, event
, data
) ;
809 case kEventClassWindow
:
810 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
812 case kEventClassMouse
:
813 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
821 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
823 // ---------------------------------------------------------------------------
824 // wxWindowMac utility functions
825 // ---------------------------------------------------------------------------
827 // Find an item given the Macintosh Window Reference
829 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
831 static MacWindowMap wxWinMacWindowList
;
833 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
835 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
837 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
840 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
841 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
843 // adding NULL WindowRef is (first) surely a result of an error and
845 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
847 wxWinMacWindowList
[inWindowRef
] = win
;
850 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
851 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
853 MacWindowMap::iterator it
;
854 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
856 if ( it
->second
== win
)
858 wxWinMacWindowList
.erase(it
);
864 // ----------------------------------------------------------------------------
865 // wxTopLevelWindowMac creation
866 // ----------------------------------------------------------------------------
868 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
876 void wxTopLevelWindowMac::Init()
879 m_maximizeOnShow
= false;
881 #if TARGET_API_MAC_OSX
882 if ( UMAGetSystemVersion() >= 0x1030 )
884 m_macUsesCompositing
= true;
889 m_macUsesCompositing
= false;
891 m_macEventHandler
= NULL
;
892 m_macFullScreenData
= NULL
;
895 class wxMacDeferredWindowDeleter
: public wxObject
898 wxMacDeferredWindowDeleter( WindowRef windowRef
)
900 m_macWindow
= windowRef
;
902 virtual ~wxMacDeferredWindowDeleter()
904 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
907 WindowRef m_macWindow
;
910 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
912 const wxString
& title
,
916 const wxString
& name
)
921 m_windowStyle
= style
;
925 m_windowId
= id
== -1 ? NewControlId() : id
;
926 wxWindow::SetTitle( title
) ;
928 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
930 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
932 if (GetExtraStyle() & wxFRAME_EX_METAL
)
933 MacSetMetalAppearance(true);
935 wxTopLevelWindows
.Append(this);
938 parent
->AddChild(this);
943 wxTopLevelWindowMac::~wxTopLevelWindowMac()
948 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
950 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
953 if ( m_macEventHandler
)
955 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
956 m_macEventHandler
= NULL
;
959 wxRemoveMacWindowAssociation( this ) ;
961 if ( wxModelessWindows
.Find(this) )
962 wxModelessWindows
.DeleteObject(this);
964 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
966 m_macFullScreenData
= NULL
;
970 // ----------------------------------------------------------------------------
971 // wxTopLevelWindowMac maximize/minimize
972 // ----------------------------------------------------------------------------
974 void wxTopLevelWindowMac::Maximize(bool maximize
)
976 // TODO Check, is this still necessary
978 wxMacPortStateHelper
help( (GrafPtr
) GetWindowPort( (WindowRef
) m_macWindow
) ) ;
979 wxMacWindowClipper
clip (this);
981 if ( !IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) )
984 GetWindowBounds((WindowRef
)m_macWindow
, kWindowGlobalPortRgn
, &rect
);
985 SetWindowIdealUserState((WindowRef
)m_macWindow
, &rect
);
986 SetWindowUserState((WindowRef
)m_macWindow
, &rect
);
988 ZoomWindow( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, false ) ;
991 bool wxTopLevelWindowMac::IsMaximized() const
993 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
996 void wxTopLevelWindowMac::Iconize(bool iconize
)
998 if ( IsWindowCollapsable((WindowRef
)m_macWindow
) )
999 CollapseWindow((WindowRef
)m_macWindow
, iconize
) ;
1002 bool wxTopLevelWindowMac::IsIconized() const
1004 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1007 void wxTopLevelWindowMac::Restore()
1009 if ( IsMaximized() )
1011 else if ( IsIconized() )
1015 // ----------------------------------------------------------------------------
1016 // wxTopLevelWindowMac misc
1017 // ----------------------------------------------------------------------------
1019 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1021 return wxPoint(0,0) ;
1024 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
1027 wxTopLevelWindowBase::SetIcon(icon
);
1030 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1032 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1034 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1036 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1040 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1042 if ( m_macEventHandler
!= NULL
)
1044 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1046 InstallWindowEventHandler(MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1047 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1050 void wxTopLevelWindowMac::MacCreateRealWindow( const wxString
& title
,
1054 const wxString
& name
)
1056 OSStatus err
= noErr
;
1058 m_windowStyle
= style
;
1068 wxRect display
= wxGetClientDisplayRect() ;
1070 if ( x
== wxDefaultPosition
.x
)
1073 if ( y
== wxDefaultPosition
.y
)
1076 int w
= WidthDefault(size
.x
);
1077 int h
= HeightDefault(size
.y
);
1079 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1081 // translate the window attributes in the appropriate window class and attributes
1083 WindowClass wclass
= 0;
1084 WindowAttributes attr
= kWindowNoAttributes
;
1085 WindowGroupRef group
= NULL
;
1087 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1090 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1091 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1092 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1095 wclass
= kFloatingWindowClass
;
1096 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1098 attr
|= kWindowSideTitlebarAttribute
;
1103 wclass
= kPlainWindowClass
;
1106 else if ( HasFlag( wxCAPTION
) )
1108 wclass
= kDocumentWindowClass
;
1109 attr
|= kWindowInWindowMenuAttribute
;
1111 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1112 else if ( HasFlag( wxFRAME_DRAWER
) )
1114 wclass
= kDrawerWindowClass
;
1115 // we must force compositing on a drawer
1116 m_macUsesCompositing
= true ;
1118 #endif //10.2 and up
1121 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1122 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1124 wclass
= kDocumentWindowClass
;
1128 wclass
= kPlainWindowClass
;
1132 if ( HasFlag( wxMINIMIZE_BOX
) && wclass
!= kPlainWindowClass
)
1134 attr
|= kWindowCollapseBoxAttribute
;
1136 if ( HasFlag( wxMAXIMIZE_BOX
) && wclass
!= kPlainWindowClass
)
1138 attr
|= kWindowFullZoomAttribute
;
1140 if ( HasFlag( wxRESIZE_BORDER
) && wclass
!= kPlainWindowClass
)
1142 attr
|= kWindowResizableAttribute
;
1144 if ( HasFlag( wxCLOSE_BOX
) && wclass
!= kPlainWindowClass
)
1146 attr
|= kWindowCloseBoxAttribute
;
1149 if (UMAGetSystemVersion() >= 0x1000)
1151 // turn on live resizing (OS X only)
1152 attr
|= kWindowLiveResizeAttribute
;
1155 if ( HasFlag(wxSTAY_ON_TOP
) )
1157 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1160 #if TARGET_API_MAC_OSX
1161 if ( m_macUsesCompositing
)
1162 attr
|= kWindowCompositingAttribute
;
1165 if ( HasFlag(wxFRAME_SHAPED
) )
1167 WindowDefSpec customWindowDefSpec
;
1168 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1169 customWindowDefSpec
.u
.defProc
= NewWindowDefUPP(wxShapedMacWindowDef
);
1171 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1172 attr
, &theBoundsRect
,
1173 (WindowRef
*) &m_macWindow
);
1177 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1180 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1181 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1183 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1185 // the create commands are only for content rect, so we have to set the size again as
1187 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1189 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1190 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1191 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1192 #if TARGET_API_MAC_OSX
1194 if ( m_macUsesCompositing
)
1196 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1197 // the content view, so we have to retrieve it explicitly
1198 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1199 m_peer
->GetControlRefAddr() ) ;
1200 if ( !m_peer
->Ok() )
1202 // compatibility mode fallback
1203 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1208 ::CreateRootControl( (WindowRef
)m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1210 // the root control level handleer
1211 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1213 // the frame window event handler
1214 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1215 MacInstallTopLevelWindowEventHandler() ;
1217 DoSetWindowVariant( m_windowVariant
) ;
1221 if ( HasFlag(wxFRAME_SHAPED
) )
1223 // default shape matches the window size
1224 wxRegion
rgn(0, 0, w
, h
);
1228 wxWindowCreateEvent
event(this);
1229 GetEventHandler()->ProcessEvent(event
);
1232 void wxTopLevelWindowMac::ClearBackground()
1234 wxWindow::ClearBackground() ;
1237 // Raise the window to the top of the Z order
1238 void wxTopLevelWindowMac::Raise()
1240 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1243 // Lower the window to the bottom of the Z order
1244 void wxTopLevelWindowMac::Lower()
1246 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1250 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1252 if(s_macDeactivateWindow
)
1254 wxLogTrace(TRACE_ACTIVATE
,
1255 wxT("Doing delayed deactivation of %p"),
1256 s_macDeactivateWindow
);
1257 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1261 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1263 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1265 if(s_macDeactivateWindow
==this)
1266 s_macDeactivateWindow
=NULL
;
1267 MacDelayedDeactivation(timestamp
);
1268 MacPropagateHiliteChanged() ;
1271 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1273 wxWindow::SetTitle( title
) ;
1274 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1277 bool wxTopLevelWindowMac::Show(bool show
)
1279 if ( !wxTopLevelWindowBase::Show(show
) )
1284 #if wxUSE_SYSTEM_OPTIONS //code contributed by Ryan Wilcox December 18, 2003
1285 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1287 ::ShowWindow( (WindowRef
)m_macWindow
);
1292 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowShowTransitionAction
,nil
);
1294 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1295 // as apps expect a size event to occur at this moment
1296 wxSizeEvent
event( GetSize() , m_windowId
);
1297 event
.SetEventObject(this);
1298 GetEventHandler()->ProcessEvent(event
);
1302 #if wxUSE_SYSTEM_OPTIONS
1303 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1305 ::HideWindow((WindowRef
) m_macWindow
);
1310 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowHideTransitionAction
,nil
);
1314 MacPropagateVisibilityChanged() ;
1319 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1323 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1325 data
= new FullScreenData() ;
1327 m_macFullScreenData
= data
;
1328 data
->m_position
= GetPosition() ;
1329 data
->m_size
= GetSize() ;
1331 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1335 int left
, top
, right
, bottom
;
1336 wxRect client
= wxGetClientDisplayRect() ;
1345 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1347 if ( style
& wxFULLSCREEN_NOCAPTION
)
1352 if ( style
& wxFULLSCREEN_NOBORDER
)
1358 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1362 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1366 SetSize( x
, y
, w
, h
) ;
1371 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1372 SetPosition( data
->m_position
) ;
1373 SetSize( data
->m_size
) ;
1375 m_macFullScreenData
= NULL
;
1380 bool wxTopLevelWindowMac::IsFullScreen() const
1382 return m_macFullScreenData
!= NULL
;
1385 // we are still using coordinates of the content view, todo switch to structure bounds
1387 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1391 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1392 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1394 left
= content
.left
- structure
.left
;
1395 top
= content
.top
- structure
.top
;
1396 right
= structure
.right
- content
.right
;
1397 bottom
= structure
.bottom
- content
.bottom
;
1400 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1402 m_cachedClippedRectValid
= false ;
1403 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1404 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1405 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1408 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1411 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1412 if(x
) *x
= bounds
.left
;
1413 if(y
) *y
= bounds
.top
;
1415 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1418 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1419 if(width
) *width
= bounds
.right
- bounds
.left
;
1420 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1423 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1426 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1427 if(width
) *width
= bounds
.right
- bounds
.left
;
1428 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1431 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1433 #if TARGET_API_MAC_OSX
1434 wxASSERT_MSG( m_macUsesCompositing
,
1435 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1437 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1438 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1442 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1444 #if TARGET_API_MAC_OSX
1445 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1451 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1453 ChangeWindowAttributes ( (WindowRef
) m_macWindow
, attributesToSet
, attributesToClear
) ;
1456 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1459 GetWindowAttributes((WindowRef
) m_macWindow
, &attr
) ;
1463 void wxTopLevelWindowMac::MacPerformUpdates()
1465 #if TARGET_API_MAC_OSX
1466 if ( m_macUsesCompositing
)
1468 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1469 // for composited windows this also triggers a redraw of all
1470 // invalid views in the window
1471 if( UMAGetSystemVersion() >= 0x1030 )
1472 HIWindowFlush((WindowRef
) m_macWindow
) ;
1476 // the only way to trigger the redrawing on earlier systems is to call
1479 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1480 UInt32 currentEventClass
= 0 ;
1481 UInt32 currentEventKind
= 0 ;
1482 if ( currentEvent
!= NULL
)
1484 currentEventClass
= ::GetEventClass( currentEvent
) ;
1485 currentEventKind
= ::GetEventKind( currentEvent
) ;
1487 if ( currentEventClass
!= kEventClassMenu
)
1489 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1491 OSStatus status
= noErr
;
1492 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1499 BeginUpdate( (WindowRef
) m_macWindow
) ;
1501 RgnHandle updateRgn
= NewRgn();
1504 GetPortVisibleRegion( GetWindowPort( (WindowRef
)m_macWindow
), updateRgn
);
1505 UpdateControls( (WindowRef
)m_macWindow
, updateRgn
) ;
1506 // if ( !EmptyRgn( updateRgn ) )
1507 // MacDoRedraw( updateRgn , 0 , true) ;
1508 DisposeRgn( updateRgn
);
1510 EndUpdate( (WindowRef
)m_macWindow
) ;
1511 QDFlushPortBuffer( GetWindowPort( (WindowRef
)m_macWindow
) , NULL
) ;
1515 // Attracts the users attention to this window if the application is
1516 // inactive (should be called when a background event occurs)
1518 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1521 DisposePtr( (Ptr
) ptr
) ;
1525 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1527 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1528 static wxMacNMUPP
nmupp( wxMacNMResponse
)
1530 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1531 notificationRequest
->qType
= nmType
;
1532 notificationRequest
->nmMark
= 1 ;
1533 notificationRequest
->nmIcon
= 0 ;
1534 notificationRequest
->nmSound
= 0 ;
1535 notificationRequest
->nmStr
= NULL
;
1536 notificationRequest
->nmResp
= nmupp
;
1537 verify_noerr( NMInstall( notificationRequest
) ) ;
1540 // ---------------------------------------------------------------------------
1541 // Shape implementation
1542 // ---------------------------------------------------------------------------
1545 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1547 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1548 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1550 // The empty region signifies that the shape should be removed from the
1552 if ( region
.IsEmpty() )
1554 wxSize sz
= GetClientSize();
1555 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1556 if ( rgn
.IsEmpty() )
1559 return SetShape(rgn
);
1562 // Make a copy of the region
1563 RgnHandle shapeRegion
= NewRgn();
1564 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1566 // Dispose of any shape region we may already have
1567 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1571 // Save the region so we can use it later
1572 SetWRefCon((WindowRef
)MacGetWindowRef(), (SInt32
)shapeRegion
);
1574 // Tell the window manager that the window has changed shape
1575 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1579 // ---------------------------------------------------------------------------
1580 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1581 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1582 // ---------------------------------------------------------------------------
1584 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1586 GetWindowPortBounds(window
, inRect
);
1587 Point pt
= {inRect
->left
, inRect
->top
};
1588 QDLocalToGlobalPoint( GetWindowPort(window
) , &pt
) ;
1590 inRect
->left
= pt
.h
;
1591 inRect
->bottom
+= pt
.v
;
1592 inRect
->right
+= pt
.h
;
1596 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1598 /*------------------------------------------------------
1599 Define which options your custom window supports.
1600 --------------------------------------------------------*/
1601 //just enable everything for our demo
1602 *(OptionBits
*)param
=//kWindowCanGrow|
1604 //kWindowCanCollapse|
1605 //kWindowCanGetWindowRegion|
1606 //kWindowHasTitleBar|
1607 //kWindowSupportsDragHilite|
1608 kWindowCanDrawInCurrentPort
|
1609 //kWindowCanMeasureTitle|
1610 kWindowWantsDisposeAtProcessDeath
|
1611 kWindowSupportsGetGrowImageRegion
|
1612 kWindowDefSupportsColorGrafPort
;
1616 // The content region is left as a rectangle matching the window size, this is
1617 // so the origin in the paint event, and etc. still matches what the
1618 // programmer expects.
1619 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1622 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1626 wxShapedMacWindowGetPos(window
, &r
) ;
1627 RectRgn( rgn
, &r
) ;
1631 // The structure region is set to the shape given to the SetShape method.
1632 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1634 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1640 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1641 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1642 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1643 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1649 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1651 GetWindowRegionPtr rgnRec
=(GetWindowRegionPtr
)param
;
1653 switch(rgnRec
->regionCode
)
1655 case kWindowStructureRgn
:
1656 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1658 case kWindowContentRgn
:
1659 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1662 SetEmptyRgn(rgnRec
->winRgn
);
1669 static SInt32
wxShapedMacWindowHitTest(WindowRef window
,SInt32 param
)
1671 /*------------------------------------------------------
1672 Determine the region of the window which was hit
1673 --------------------------------------------------------*/
1675 static RgnHandle tempRgn
=nil
;
1680 SetPt(&hitPoint
,LoWord(param
),HiWord(param
));//get the point clicked
1682 //Mac OS 8.5 or later
1683 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1684 if (PtInRgn(hitPoint
, tempRgn
)) //in window content region?
1687 return wNoHit
;//no significant area was hit.
1691 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1695 case kWindowMsgHitTest
:
1696 return wxShapedMacWindowHitTest(window
,param
);
1698 case kWindowMsgGetFeatures
:
1699 return wxShapedMacWindowGetFeatures(window
,param
);
1701 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1702 case kWindowMsgGetRegion
:
1703 return wxShapedMacWindowGetRegion(window
,param
);
1709 // ---------------------------------------------------------------------------