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"
52 #include <ToolUtils.h>
55 #include "wx/mac/private.h"
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 // list of all frames and modeless dialogs
62 wxWindowList wxModelessWindows
;
64 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
66 // ============================================================================
67 // wxTopLevelWindowMac implementation
68 // ============================================================================
70 BEGIN_EVENT_TABLE(wxTopLevelWindowMac
, wxTopLevelWindowBase
)
74 // ---------------------------------------------------------------------------
76 // ---------------------------------------------------------------------------
78 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
80 static const EventTypeSpec eventList
[] =
82 // TODO remove control related event like key and mouse (except for WindowLeave events)
84 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
86 { kEventClassKeyboard
, kEventRawKeyDown
} ,
87 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
88 { kEventClassKeyboard
, kEventRawKeyUp
} ,
89 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
92 { kEventClassWindow
, kEventWindowShown
} ,
93 { kEventClassWindow
, kEventWindowActivated
} ,
94 { kEventClassWindow
, kEventWindowDeactivated
} ,
95 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
96 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
97 { kEventClassWindow
, kEventWindowClose
} ,
99 // we have to catch these events on the toplevel window level, as controls don't get the
100 // raw mouse events anymore
102 { kEventClassMouse
, kEventMouseDown
} ,
103 { kEventClassMouse
, kEventMouseUp
} ,
104 { kEventClassMouse
, kEventMouseWheelMoved
} ,
105 { kEventClassMouse
, kEventMouseMoved
} ,
106 { kEventClassMouse
, kEventMouseDragged
} ,
109 static pascal OSStatus
TextInputEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
111 OSStatus result
= eventNotHandledErr
;
113 wxWindow
* focus
= wxWindow::FindFocus() ;
114 unsigned char charCode
;
121 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent
) ;
123 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
,sizeof(char), NULL
,&charCode
);
124 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
125 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
126 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
127 sizeof( Point
), NULL
, &point
);
129 switch ( GetEventKind( event
) )
131 case kEventTextInputUnicodeForKeyEvent
:
132 // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not
133 // get its own kEventTextInputUnicodeForKeyEvent, so we route back the
134 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
137 ControlRef macControl
= (ControlRef
) control
->GetHandle() ;
140 ::HandleControlKey( macControl
, keyCode
, charCode
, modifiers
) ;
145 // this may lead to double events sent to a window in case all handlers have skipped the key down event
146 UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
147 UInt32 message = (keyCode << 8) + charCode;
149 if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent(
150 focus , message , modifiers , when , point.h , point.v ) )
161 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
163 OSStatus result
= eventNotHandledErr
;
164 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
165 // FindFocus does not return the actual focus window,but the enclosing window
166 wxWindow
* focus
= wxWindow::DoFindFocus();
170 unsigned char charCode
;
175 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
178 UInt32 dataSize
= 0 ;
179 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
183 UniChar
* charBuf
= buf
;
186 charBuf
= new UniChar
[ dataSize
/ sizeof( UniChar
) ] ;
187 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
188 #if SIZEOF_WCHAR_T == 2
189 uniChar
= charBuf
[0] ;
191 wxMBConvUTF16BE converter
;
192 converter
.MB2WC( &uniChar
, (const char*)charBuf
, 1 ) ;
199 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
,sizeof(char), NULL
,&charCode
);
200 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
201 GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
202 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
203 sizeof( Point
), NULL
, &point
);
205 UInt32 message
= (keyCode
<< 8) + charCode
;
206 switch( GetEventKind( event
) )
208 case kEventRawKeyRepeat
:
209 case kEventRawKeyDown
:
211 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
212 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
213 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
214 if ( (focus
!= NULL
) && wxTheApp
->MacSendKeyDownEvent(
215 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
) )
219 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
222 case kEventRawKeyUp
:
223 if ( (focus
!= NULL
) && wxTheApp
->MacSendKeyUpEvent(
224 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
) )
229 case kEventRawKeyModifiersChanged
:
231 wxKeyEvent
event(wxEVT_KEY_DOWN
);
233 event
.m_shiftDown
= modifiers
& shiftKey
;
234 event
.m_controlDown
= modifiers
& controlKey
;
235 event
.m_altDown
= modifiers
& optionKey
;
236 event
.m_metaDown
= modifiers
& cmdKey
;
238 event
.m_uniChar
= uniChar
;
242 event
.SetTimestamp(when
);
243 event
.SetEventObject(focus
);
245 if ( focus
&& (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
247 event
.m_keyCode
= WXK_CONTROL
;
248 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
249 focus
->GetEventHandler()->ProcessEvent( event
) ;
251 if ( focus
&& (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
253 event
.m_keyCode
= WXK_SHIFT
;
254 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
255 focus
->GetEventHandler()->ProcessEvent( event
) ;
257 if ( focus
&& (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
259 event
.m_keyCode
= WXK_ALT
;
260 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
261 focus
->GetEventHandler()->ProcessEvent( event
) ;
263 if ( focus
&& (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
265 event
.m_keyCode
= WXK_COMMAND
;
266 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
267 focus
->GetEventHandler()->ProcessEvent( event
) ;
269 wxApp::s_lastModifiers
= modifiers
;
277 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
278 // for windows that we didn't create (like eg Scrollbars in a databrowser) , or for controls where we did not handle the
281 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
283 wxWindow
* g_MacLastWindow
= NULL
;
285 static EventMouseButton lastButton
= 0 ;
287 static void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
289 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
290 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
292 // this parameter are not given for all events
293 EventMouseButton button
= 0 ;
294 UInt32 clickCount
= 0 ;
295 cEvent
.GetParameter
<EventMouseButton
>(kEventParamMouseButton
, typeMouseButton
, &button
) ;
296 cEvent
.GetParameter
<UInt32
>(kEventParamClickCount
, typeUInt32
, &clickCount
) ;
298 wxevent
.m_x
= screenMouseLocation
.h
;
299 wxevent
.m_y
= screenMouseLocation
.v
;
300 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
301 wxevent
.m_controlDown
= modifiers
& controlKey
;
302 wxevent
.m_altDown
= modifiers
& optionKey
;
303 wxevent
.m_metaDown
= modifiers
& cmdKey
;
304 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
305 // a control click is interpreted as a right click
306 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
308 button
= kEventMouseButtonSecondary
;
311 // otherwise we report double clicks by connecting a left click with a ctrl-left click
312 if ( clickCount
> 1 && button
!= lastButton
)
315 // we must make sure that our synthetic 'right' button corresponds in
316 // mouse down, moved and mouse up, and does not deliver a right down and left up
318 if ( cEvent
.GetKind() == kEventMouseDown
)
319 lastButton
= button
;
323 else if ( lastButton
)
324 button
= lastButton
;
326 // determinate the correct down state, wx does not want a 'down' for a mouseUp event, while mac delivers
328 if ( button
!= 0 && cEvent
.GetKind() != kEventMouseUp
)
332 case kEventMouseButtonPrimary
:
333 wxevent
.m_leftDown
= true ;
335 case kEventMouseButtonSecondary
:
336 wxevent
.m_rightDown
= true ;
338 case kEventMouseButtonTertiary
:
339 wxevent
.m_middleDown
= true ;
343 // translate into wx types
344 switch ( cEvent
.GetKind() )
346 case kEventMouseDown
:
349 case kEventMouseButtonPrimary
:
350 wxevent
.SetEventType(clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
352 case kEventMouseButtonSecondary
:
353 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
355 case kEventMouseButtonTertiary
:
356 wxevent
.SetEventType(clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
363 case kEventMouseButtonPrimary
:
364 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
366 case kEventMouseButtonSecondary
:
367 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
369 case kEventMouseButtonTertiary
:
370 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
374 case kEventMouseWheelMoved
:
376 wxevent
.SetEventType(wxEVT_MOUSEWHEEL
) ;
378 // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
379 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeLongInteger
) ;
381 wxevent
.m_wheelRotation
= delta
;
382 wxevent
.m_wheelDelta
= 1;
383 wxevent
.m_linesPerAction
= 1;
387 wxevent
.SetEventType(wxEVT_MOTION
) ;
392 ControlRef
wxMacFindSubControl( wxTopLevelWindowMac
* toplevelWindow
, Point location
, ControlRef superControl
, ControlPartCode
*outPart
)
396 UInt16 childrenCount
= 0 ;
397 OSStatus err
= CountSubControls( superControl
, &childrenCount
) ;
398 if ( err
== errControlIsNotEmbedder
)
400 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
402 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
404 ControlHandle sibling
;
405 err
= GetIndexedSubControl( superControl
, i
, & sibling
) ;
406 if ( err
== errControlIsNotEmbedder
)
409 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
410 if ( IsControlVisible( sibling
) )
413 UMAGetControlBoundsInWindowCoords( sibling
, &r
) ;
414 if ( MacPtInRect( location
, &r
) )
416 ControlHandle child
= wxMacFindSubControl( toplevelWindow
, location
, sibling
, outPart
) ;
421 Point testLocation
= location
;
423 if ( toplevelWindow
&& toplevelWindow
->MacUsesCompositing() )
425 testLocation
.h
-= r
.left
;
426 testLocation
.v
-= r
.top
;
429 *outPart
= TestControl( sibling
, testLocation
) ;
439 ControlRef
wxMacFindControlUnderMouse( wxTopLevelWindowMac
* toplevelWindow
, Point location
, WindowRef window
, ControlPartCode
*outPart
)
441 #if TARGET_API_MAC_OSX
442 if ( UMAGetSystemVersion() >= 0x1030 && ( toplevelWindow
== 0 || toplevelWindow
->MacUsesCompositing() ) )
443 return FindControlUnderMouse( location
, window
, outPart
) ;
445 ControlRef rootControl
= NULL
;
446 verify_noerr( GetRootControl( window
, &rootControl
) ) ;
447 return wxMacFindSubControl( toplevelWindow
, location
, rootControl
, outPart
) ;
450 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
452 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
454 OSStatus result
= eventNotHandledErr
;
456 wxMacCarbonEvent
cEvent( event
) ;
458 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
459 Point windowMouseLocation
= screenMouseLocation
;
462 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
464 wxWindow
* currentMouseWindow
= NULL
;
465 ControlRef control
= NULL
;
469 QDGlobalToLocalPoint( UMAGetWindowPort(window
) , &windowMouseLocation
) ;
471 if ( wxApp::s_captureWindow
&& wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
)
473 currentMouseWindow
= wxApp::s_captureWindow
;
475 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
477 ControlPartCode part
;
478 control
= wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &part
) ;
479 // if there is no control below the mouse position, send the event to the toplevel window itself
481 currentMouseWindow
= (wxWindow
*) data
;
484 currentMouseWindow
= wxFindControlFromMacControl( control
) ;
485 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
488 // for wxToolBar to function we have to send certaint events to it
489 // instead of its children (wxToolBarTools)
491 GetSuperControl(control
, &parent
);
492 wxWindow
*wxParent
= wxFindControlFromMacControl( parent
) ;
493 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
494 currentMouseWindow
= wxParent
;
501 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
502 SetupMouseEvent( wxevent
, cEvent
) ;
504 // handle all enter / leave events
506 if ( currentMouseWindow
!= g_MacLastWindow
)
508 if ( g_MacLastWindow
)
510 wxMouseEvent
eventleave(wxevent
);
511 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
512 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
513 eventleave
.SetEventObject( g_MacLastWindow
) ;
516 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
517 #endif // wxUSE_TOOLTIPS
518 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
520 if ( currentMouseWindow
)
522 wxMouseEvent
evententer(wxevent
);
523 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
524 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
525 evententer
.SetEventObject( currentMouseWindow
) ;
527 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
528 #endif // wxUSE_TOOLTIPS
529 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
531 g_MacLastWindow
= currentMouseWindow
;
534 if ( windowPart
== inMenuBar
)
536 // special case menu bar, as we are having a low-level runloop we must do it ourselves
537 if ( cEvent
.GetKind() == kEventMouseDown
)
539 ::MenuSelect( screenMouseLocation
) ;
542 } // if ( windowPart == inMenuBar )
543 else if ( currentMouseWindow
)
545 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
547 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
549 wxevent
.SetEventObject( currentMouseWindow
) ;
551 // make tooltips current
554 if ( wxevent
.GetEventType() == wxEVT_MOTION
555 || wxevent
.GetEventType() == wxEVT_ENTER_WINDOW
556 || wxevent
.GetEventType() == wxEVT_LEAVE_WINDOW
)
557 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
558 #endif // wxUSE_TOOLTIPS
559 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
561 if ((currentMouseWindowParent
!= NULL
) &&
562 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
563 currentMouseWindow
= NULL
;
569 // if the user code did _not_ handle the event, then perform the
570 // default processing
571 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
573 // ... that is set focus to this window
574 if (currentMouseWindow
->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
575 currentMouseWindow
->SetFocus();
578 ControlPartCode dummyPart
;
579 // if built-in find control is finding the wrong control (ie static box instead of overlaid
580 // button, we cannot let the standard handler do its job, but must handle manually
582 if ( ( cEvent
.GetKind() == kEventMouseDown
)
585 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
586 wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &dummyPart
) )
590 if ( currentMouseWindow
->MacIsReallyEnabled() )
592 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
593 Point clickLocation
= windowMouseLocation
;
595 if ( toplevelWindow
->MacUsesCompositing() )
596 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
598 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
599 modifiers
, (ControlActionUPP
) -1 ) ;
601 if ((currentMouseWindowParent
!= NULL
) &&
602 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
603 currentMouseWindow
= NULL
;
608 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
610 wxApp::s_captureWindow
= NULL
;
616 wxWindow
* cursorTarget
= currentMouseWindow
;
617 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
619 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
621 cursorTarget
= cursorTarget
->GetParent() ;
623 cursorPoint
+= cursorTarget
->GetPosition();
626 } // else if ( currentMouseWindow )
629 // don't mess with controls we don't know about
630 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
631 // so we try sending them the correct control directly
632 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
634 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
635 Point clickLocation
= windowMouseLocation
;
636 if ( toplevelWindow
->MacUsesCompositing() )
640 hiPoint
.x
= clickLocation
.h
;
641 hiPoint
.y
= clickLocation
.v
;
642 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
643 clickLocation
.h
= (int)hiPoint
.x
;
644 clickLocation
.v
= (int)hiPoint
.y
;
647 HandleControlClick( control
, clickLocation
,
648 modifiers
, (ControlActionUPP
) -1 ) ;
655 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
657 OSStatus result
= eventNotHandledErr
;
659 wxMacCarbonEvent
cEvent( event
) ;
661 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
662 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
664 switch( GetEventKind( event
) )
666 case kEventWindowActivated
:
668 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
669 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
670 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
671 wxevent
.SetEventObject(toplevelWindow
);
672 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
673 // we still sending an eventNotHandledErr in order to allow for default processing
676 case kEventWindowDeactivated
:
678 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
679 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
680 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
681 wxevent
.SetEventObject(toplevelWindow
);
682 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
683 // we still sending an eventNotHandledErr in order to allow for default processing
686 case kEventWindowShown
:
687 toplevelWindow
->Refresh() ;
690 case kEventWindowClose
:
691 toplevelWindow
->Close() ;
694 case kEventWindowBoundsChanged
:
696 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
697 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
698 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
699 if ( attributes
& kWindowBoundsChangeSizeChanged
)
701 // according to the other ports we handle this within the OS level
702 // resize event, not within a wxSizeEvent
703 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
707 frame
->PositionStatusBar();
710 frame
->PositionToolBar();
714 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
715 event
.SetEventObject( toplevelWindow
) ;
717 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
718 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
720 if ( attributes
& kWindowBoundsChangeOriginChanged
)
722 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
723 event
.SetEventObject( toplevelWindow
) ;
724 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
729 case kEventWindowBoundsChanging
:
731 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
732 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
734 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
736 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
737 int left
, top
, right
, bottom
;
738 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
739 wxRect
r( newRect
.left
- left
, newRect
.top
- top
,
740 newRect
.right
- newRect
.left
+ left
+ right
, newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
741 // this is a EVT_SIZING not a EVT_SIZE type !
742 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
743 wxevent
.SetEventObject( toplevelWindow
) ;
745 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
746 adjustR
= wxevent
.GetRect() ;
748 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
749 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
750 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
751 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
752 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
753 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
754 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
755 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
756 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
757 if ( !EqualRect( &newRect
, &adjustedRect
) )
758 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
759 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
771 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
773 OSStatus result
= eventNotHandledErr
;
775 switch ( GetEventClass( event
) )
777 case kEventClassKeyboard
:
778 result
= KeyboardEventHandler( handler
, event
, data
) ;
780 case kEventClassTextInput
:
781 result
= TextInputEventHandler( handler
, event
, data
) ;
783 case kEventClassWindow
:
784 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
786 case kEventClassMouse
:
787 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
795 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
797 // ---------------------------------------------------------------------------
798 // wxWindowMac utility functions
799 // ---------------------------------------------------------------------------
801 // Find an item given the Macintosh Window Reference
803 #if KEY_wxList_DEPRECATED
804 wxList
wxWinMacWindowList(wxKEY_INTEGER
);
805 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
807 wxNode
*node
= wxWinMacWindowList
.Find((long)inWindowRef
);
810 return (wxTopLevelWindowMac
*)node
->GetData();
813 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
814 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
816 // adding NULL WindowRef is (first) surely a result of an error and
817 // (secondly) breaks menu command processing
818 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
820 if ( !wxWinMacWindowList
.Find((long)inWindowRef
) )
821 wxWinMacWindowList
.Append((long)inWindowRef
, win
);
824 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
825 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
827 wxWinMacWindowList
.DeleteObject(win
);
831 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
833 static MacWindowMap wxWinMacWindowList
;
835 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
837 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
839 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
842 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
843 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
845 // adding NULL WindowRef is (first) surely a result of an error and
847 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
849 wxWinMacWindowList
[inWindowRef
] = win
;
852 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
853 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
855 MacWindowMap::iterator it
;
856 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
858 if ( it
->second
== win
)
860 wxWinMacWindowList
.erase(it
);
865 #endif // deprecated wxList
867 // ----------------------------------------------------------------------------
868 // wxTopLevelWindowMac creation
869 // ----------------------------------------------------------------------------
871 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
879 void wxTopLevelWindowMac::Init()
882 m_maximizeOnShow
= FALSE
;
884 #if TARGET_API_MAC_OSX
885 if ( UMAGetSystemVersion() >= 0x1030 )
887 m_macUsesCompositing
= TRUE
;
892 m_macUsesCompositing
= FALSE
;
894 m_macEventHandler
= NULL
;
895 m_macFullScreenData
= NULL
;
898 class wxMacDeferredWindowDeleter
: public wxObject
901 wxMacDeferredWindowDeleter( WindowRef windowRef
)
903 m_macWindow
= windowRef
;
905 virtual ~wxMacDeferredWindowDeleter()
907 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
910 WindowRef m_macWindow
;
913 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
915 const wxString
& title
,
919 const wxString
& name
)
924 m_windowStyle
= style
;
928 m_windowId
= id
== -1 ? NewControlId() : id
;
929 wxWindow::SetTitle( title
) ;
931 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
933 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
935 if (GetExtraStyle() & wxFRAME_EX_METAL
)
936 MacSetMetalAppearance(true);
938 wxTopLevelWindows
.Append(this);
941 parent
->AddChild(this);
946 wxTopLevelWindowMac::~wxTopLevelWindowMac()
951 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
953 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
956 if ( m_macEventHandler
)
958 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
959 m_macEventHandler
= NULL
;
962 wxRemoveMacWindowAssociation( this ) ;
964 if ( wxModelessWindows
.Find(this) )
965 wxModelessWindows
.DeleteObject(this);
967 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
969 m_macFullScreenData
= NULL
;
973 // ----------------------------------------------------------------------------
974 // wxTopLevelWindowMac maximize/minimize
975 // ----------------------------------------------------------------------------
977 void wxTopLevelWindowMac::Maximize(bool maximize
)
979 // TODO Check, is this still necessary
981 wxMacPortStateHelper
help( (GrafPtr
) GetWindowPort( (WindowRef
) m_macWindow
) ) ;
982 wxMacWindowClipper
clip (this);
984 if ( !IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) )
987 GetWindowBounds((WindowRef
)m_macWindow
, kWindowGlobalPortRgn
, &rect
);
988 SetWindowIdealUserState((WindowRef
)m_macWindow
, &rect
);
989 SetWindowUserState((WindowRef
)m_macWindow
, &rect
);
991 ZoomWindow( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, false ) ;
994 bool wxTopLevelWindowMac::IsMaximized() const
996 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
999 void wxTopLevelWindowMac::Iconize(bool iconize
)
1001 if ( IsWindowCollapsable((WindowRef
)m_macWindow
) )
1002 CollapseWindow((WindowRef
)m_macWindow
, iconize
) ;
1005 bool wxTopLevelWindowMac::IsIconized() const
1007 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1010 void wxTopLevelWindowMac::Restore()
1012 if ( IsMaximized() )
1014 else if ( IsIconized() )
1018 // ----------------------------------------------------------------------------
1019 // wxTopLevelWindowMac misc
1020 // ----------------------------------------------------------------------------
1022 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1024 return wxPoint(0,0) ;
1027 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
1030 wxTopLevelWindowBase::SetIcon(icon
);
1033 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1035 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1037 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1039 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1043 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1045 if ( m_macEventHandler
!= NULL
)
1047 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1049 InstallWindowEventHandler(MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1050 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1053 void wxTopLevelWindowMac::MacCreateRealWindow( const wxString
& title
,
1057 const wxString
& name
)
1059 OSStatus err
= noErr
;
1061 m_windowStyle
= style
;
1071 wxRect display
= wxGetClientDisplayRect() ;
1073 if ( x
== wxDefaultPosition
.x
)
1076 if ( y
== wxDefaultPosition
.y
)
1079 int w
= WidthDefault(size
.x
);
1080 int h
= HeightDefault(size
.y
);
1082 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1084 // translate the window attributes in the appropriate window class and attributes
1086 WindowClass wclass
= 0;
1087 WindowAttributes attr
= kWindowNoAttributes
;
1088 WindowGroupRef group
= NULL
;
1090 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1093 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1094 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1095 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1098 wclass
= kFloatingWindowClass
;
1099 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1101 attr
|= kWindowSideTitlebarAttribute
;
1106 wclass
= kPlainWindowClass
;
1109 else if ( HasFlag( wxCAPTION
) )
1111 wclass
= kDocumentWindowClass
;
1112 attr
|= kWindowInWindowMenuAttribute
;
1114 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1115 else if ( HasFlag( wxFRAME_DRAWER
) )
1117 wclass
= kDrawerWindowClass
;
1118 // we must force compositing on a drawer
1119 m_macUsesCompositing
= TRUE
;
1121 #endif //10.2 and up
1124 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1125 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1127 wclass
= kDocumentWindowClass
;
1131 wclass
= kPlainWindowClass
;
1135 if ( HasFlag( wxMINIMIZE_BOX
) && wclass
!= kPlainWindowClass
)
1137 attr
|= kWindowCollapseBoxAttribute
;
1139 if ( HasFlag( wxMAXIMIZE_BOX
) && wclass
!= kPlainWindowClass
)
1141 attr
|= kWindowFullZoomAttribute
;
1143 if ( HasFlag( wxRESIZE_BORDER
) && wclass
!= kPlainWindowClass
)
1145 attr
|= kWindowResizableAttribute
;
1147 if ( HasFlag( wxCLOSE_BOX
) && wclass
!= kPlainWindowClass
)
1149 attr
|= kWindowCloseBoxAttribute
;
1152 if (UMAGetSystemVersion() >= 0x1000)
1154 // turn on live resizing (OS X only)
1155 attr
|= kWindowLiveResizeAttribute
;
1158 if ( HasFlag(wxSTAY_ON_TOP
) )
1160 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1163 #if TARGET_API_MAC_OSX
1164 if ( m_macUsesCompositing
)
1165 attr
|= kWindowCompositingAttribute
;
1168 if ( HasFlag(wxFRAME_SHAPED
) )
1170 WindowDefSpec customWindowDefSpec
;
1171 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1172 customWindowDefSpec
.u
.defProc
= NewWindowDefUPP(wxShapedMacWindowDef
);
1174 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1175 attr
, &theBoundsRect
,
1176 (WindowRef
*) &m_macWindow
);
1180 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1183 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1184 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1186 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1188 // the create commands are only for content rect, so we have to set the size again as
1190 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1192 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1193 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1194 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1195 #if TARGET_API_MAC_OSX
1197 if ( m_macUsesCompositing
)
1199 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1200 // the content view, so we have to retrieve it explicitely
1201 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1202 m_peer
->GetControlRefAddr() ) ;
1203 if ( !m_peer
->Ok() )
1205 // compatibility mode fallback
1206 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1211 ::CreateRootControl( (WindowRef
)m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1213 // the root control level handleer
1214 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1216 // the frame window event handler
1217 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1218 MacInstallTopLevelWindowEventHandler() ;
1220 DoSetWindowVariant( m_windowVariant
) ;
1224 if ( HasFlag(wxFRAME_SHAPED
) )
1226 // default shape matches the window size
1227 wxRegion
rgn(0, 0, w
, h
);
1231 wxWindowCreateEvent
event(this);
1232 GetEventHandler()->ProcessEvent(event
);
1235 void wxTopLevelWindowMac::ClearBackground()
1237 wxWindow::ClearBackground() ;
1240 // Raise the window to the top of the Z order
1241 void wxTopLevelWindowMac::Raise()
1243 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1246 // Lower the window to the bottom of the Z order
1247 void wxTopLevelWindowMac::Lower()
1249 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1253 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1255 if(s_macDeactivateWindow
)
1257 wxLogDebug(wxT("Doing delayed deactivation of %p"),s_macDeactivateWindow
);
1258 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1262 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1264 // wxLogDebug(wxT("TopLevel=%p::MacActivate"),this);
1266 if(s_macDeactivateWindow
==this)
1267 s_macDeactivateWindow
=NULL
;
1268 MacDelayedDeactivation(timestamp
);
1269 MacPropagateHiliteChanged() ;
1272 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1274 wxWindow::SetTitle( title
) ;
1275 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1278 bool wxTopLevelWindowMac::Show(bool show
)
1280 if ( !wxTopLevelWindowBase::Show(show
) )
1285 #if wxUSE_SYSTEM_OPTIONS //code contributed by Ryan Wilcox December 18, 2003
1286 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1288 ::ShowWindow( (WindowRef
)m_macWindow
);
1293 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowShowTransitionAction
,nil
);
1295 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1296 // as apps expect a size event to occur at this moment
1297 wxSizeEvent
event( GetSize() , m_windowId
);
1298 event
.SetEventObject(this);
1299 GetEventHandler()->ProcessEvent(event
);
1303 #if wxUSE_SYSTEM_OPTIONS
1304 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1306 ::HideWindow((WindowRef
) m_macWindow
);
1311 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowHideTransitionAction
,nil
);
1315 MacPropagateVisibilityChanged() ;
1320 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1324 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1326 data
= new FullScreenData() ;
1328 m_macFullScreenData
= data
;
1329 data
->m_position
= GetPosition() ;
1330 data
->m_size
= GetSize() ;
1332 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1336 int left
, top
, right
, bottom
;
1337 wxRect client
= wxGetClientDisplayRect() ;
1346 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1348 if ( style
& wxFULLSCREEN_NOCAPTION
)
1353 if ( style
& wxFULLSCREEN_NOBORDER
)
1359 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1363 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1367 SetSize( x
, y
, w
, h
) ;
1372 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1373 SetPosition( data
->m_position
) ;
1374 SetSize( data
->m_size
) ;
1376 m_macFullScreenData
= NULL
;
1381 bool wxTopLevelWindowMac::IsFullScreen() const
1383 return m_macFullScreenData
!= NULL
;
1386 // we are still using coordinates of the content view, todo switch to structure bounds
1388 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1392 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1393 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1395 left
= content
.left
- structure
.left
;
1396 top
= content
.top
- structure
.top
;
1397 right
= structure
.right
- content
.right
;
1398 bottom
= structure
.bottom
- content
.bottom
;
1401 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1403 m_cachedClippedRectValid
= false ;
1404 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1405 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1406 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1409 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1412 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1413 if(x
) *x
= bounds
.left
;
1414 if(y
) *y
= bounds
.top
;
1416 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1419 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1420 if(width
) *width
= bounds
.right
- bounds
.left
;
1421 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1424 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1427 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1428 if(width
) *width
= bounds
.right
- bounds
.left
;
1429 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1432 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1434 #if TARGET_API_MAC_OSX
1435 wxASSERT_MSG( m_macUsesCompositing
,
1436 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1438 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1439 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1443 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1445 #if TARGET_API_MAC_OSX
1446 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1452 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1454 ChangeWindowAttributes ( (WindowRef
) m_macWindow
, attributesToSet
, attributesToClear
) ;
1457 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1460 GetWindowAttributes((WindowRef
) m_macWindow
, &attr
) ;
1464 void wxTopLevelWindowMac::MacPerformUpdates()
1466 #if TARGET_API_MAC_OSX
1467 if ( m_macUsesCompositing
)
1469 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1470 // for composited windows this also triggers a redraw of all
1471 // invalid views in the window
1472 if( UMAGetSystemVersion() >= 0x1030 )
1473 HIWindowFlush((WindowRef
) m_macWindow
) ;
1477 // the only way to trigger the redrawing on earlier systems is to call
1480 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1481 UInt32 currentEventClass
= 0 ;
1482 UInt32 currentEventKind
= 0 ;
1483 if ( currentEvent
!= NULL
)
1485 currentEventClass
= ::GetEventClass( currentEvent
) ;
1486 currentEventKind
= ::GetEventKind( currentEvent
) ;
1488 if ( currentEventClass
!= kEventClassMenu
)
1490 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1492 OSStatus status
= noErr
;
1493 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1500 BeginUpdate( (WindowRef
) m_macWindow
) ;
1502 RgnHandle updateRgn
= NewRgn();
1505 GetPortVisibleRegion( GetWindowPort( (WindowRef
)m_macWindow
), updateRgn
);
1506 UpdateControls( (WindowRef
)m_macWindow
, updateRgn
) ;
1507 // if ( !EmptyRgn( updateRgn ) )
1508 // MacDoRedraw( updateRgn , 0 , true) ;
1509 DisposeRgn( updateRgn
);
1511 EndUpdate( (WindowRef
)m_macWindow
) ;
1512 QDFlushPortBuffer( GetWindowPort( (WindowRef
)m_macWindow
) , NULL
) ;
1516 // Attracts the users attention to this window if the application is
1517 // inactive (should be called when a background event occurs)
1519 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1522 DisposePtr( (Ptr
) ptr
) ;
1526 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1528 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1529 static wxMacNMUPP
nmupp( wxMacNMResponse
)
1531 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1532 notificationRequest
->qType
= nmType
;
1533 notificationRequest
->nmMark
= 1 ;
1534 notificationRequest
->nmIcon
= 0 ;
1535 notificationRequest
->nmSound
= 0 ;
1536 notificationRequest
->nmStr
= NULL
;
1537 notificationRequest
->nmResp
= nmupp
;
1538 verify_noerr( NMInstall( notificationRequest
) ) ;
1541 // ---------------------------------------------------------------------------
1542 // Shape implementation
1543 // ---------------------------------------------------------------------------
1546 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1548 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
1549 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1551 // The empty region signifies that the shape should be removed from the
1553 if ( region
.IsEmpty() )
1555 wxSize sz
= GetClientSize();
1556 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1557 return SetShape(rgn
);
1560 // Make a copy of the region
1561 RgnHandle shapeRegion
= NewRgn();
1562 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1564 // Dispose of any shape region we may already have
1565 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1569 // Save the region so we can use it later
1570 SetWRefCon((WindowRef
)MacGetWindowRef(), (SInt32
)shapeRegion
);
1572 // Tell the window manager that the window has changed shape
1573 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1577 // ---------------------------------------------------------------------------
1578 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1579 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1580 // ---------------------------------------------------------------------------
1582 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1584 GetWindowPortBounds(window
, inRect
);
1585 Point pt
= {inRect
->left
, inRect
->top
};
1586 QDLocalToGlobalPoint( GetWindowPort(window
) , &pt
) ;
1588 inRect
->left
= pt
.h
;
1589 inRect
->bottom
+= pt
.v
;
1590 inRect
->right
+= pt
.h
;
1594 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1596 /*------------------------------------------------------
1597 Define which options your custom window supports.
1598 --------------------------------------------------------*/
1599 //just enable everything for our demo
1600 *(OptionBits
*)param
=//kWindowCanGrow|
1602 //kWindowCanCollapse|
1603 //kWindowCanGetWindowRegion|
1604 //kWindowHasTitleBar|
1605 //kWindowSupportsDragHilite|
1606 kWindowCanDrawInCurrentPort
|
1607 //kWindowCanMeasureTitle|
1608 kWindowWantsDisposeAtProcessDeath
|
1609 kWindowSupportsGetGrowImageRegion
|
1610 kWindowDefSupportsColorGrafPort
;
1614 // The content region is left as a rectangle matching the window size, this is
1615 // so the origin in the paint event, and etc. still matches what the
1616 // programmer expects.
1617 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1620 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1624 wxShapedMacWindowGetPos(window
, &r
) ;
1625 RectRgn( rgn
, &r
) ;
1629 // The structure region is set to the shape given to the SetShape method.
1630 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1632 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1638 wxShapedMacWindowGetPos(window
, &windowRect
); //how big is the window
1639 CopyRgn(cachedRegion
, rgn
); //make a copy of our cached region
1640 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1641 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1647 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1649 GetWindowRegionPtr rgnRec
=(GetWindowRegionPtr
)param
;
1651 switch(rgnRec
->regionCode
)
1653 case kWindowStructureRgn
:
1654 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1656 case kWindowContentRgn
:
1657 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1660 SetEmptyRgn(rgnRec
->winRgn
);
1667 static SInt32
wxShapedMacWindowHitTest(WindowRef window
,SInt32 param
)
1669 /*------------------------------------------------------
1670 Determine the region of the window which was hit
1671 --------------------------------------------------------*/
1673 static RgnHandle tempRgn
=nil
;
1678 SetPt(&hitPoint
,LoWord(param
),HiWord(param
));//get the point clicked
1680 //Mac OS 8.5 or later
1681 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1682 if (PtInRgn(hitPoint
, tempRgn
)) //in window content region?
1685 return wNoHit
;//no significant area was hit.
1689 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1693 case kWindowMsgHitTest
:
1694 return wxShapedMacWindowHitTest(window
,param
);
1696 case kWindowMsgGetFeatures
:
1697 return wxShapedMacWindowGetFeatures(window
,param
);
1699 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1700 case kWindowMsgGetRegion
:
1701 return wxShapedMacWindowGetRegion(window
,param
);
1707 // ---------------------------------------------------------------------------