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() ;
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();
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
^ wxTheApp
->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
^ wxTheApp
->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
^ wxTheApp
->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
^ wxTheApp
->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 wxTheApp
->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 // we must make sure that our synthetic 'right' button corresponds in
312 // mouse down, moved and mouse up, and does not deliver a right down and left up
314 if ( cEvent
.GetKind() == kEventMouseDown
)
315 lastButton
= button
;
319 else if ( lastButton
)
320 button
= lastButton
;
322 // determinate the correct down state, wx does not want a 'down' for a mouseUp event, while mac delivers
324 if ( button
!= 0 && cEvent
.GetKind() != kEventMouseUp
)
328 case kEventMouseButtonPrimary
:
329 wxevent
.m_leftDown
= true ;
331 case kEventMouseButtonSecondary
:
332 wxevent
.m_rightDown
= true ;
334 case kEventMouseButtonTertiary
:
335 wxevent
.m_middleDown
= true ;
339 // translate into wx types
340 switch ( cEvent
.GetKind() )
342 case kEventMouseDown
:
345 case kEventMouseButtonPrimary
:
346 wxevent
.SetEventType(clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
348 case kEventMouseButtonSecondary
:
349 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
351 case kEventMouseButtonTertiary
:
352 wxevent
.SetEventType(clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
359 case kEventMouseButtonPrimary
:
360 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
362 case kEventMouseButtonSecondary
:
363 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
365 case kEventMouseButtonTertiary
:
366 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
370 case kEventMouseWheelMoved
:
372 wxevent
.SetEventType(wxEVT_MOUSEWHEEL
) ;
374 // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
375 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeLongInteger
) ;
377 wxevent
.m_wheelRotation
= delta
;
378 wxevent
.m_wheelDelta
= 1;
379 wxevent
.m_linesPerAction
= 1;
383 wxevent
.SetEventType(wxEVT_MOTION
) ;
388 ControlRef
wxMacFindSubControl( wxTopLevelWindowMac
* toplevelWindow
, Point location
, ControlRef superControl
, ControlPartCode
*outPart
)
392 UInt16 childrenCount
= 0 ;
393 OSStatus err
= CountSubControls( superControl
, &childrenCount
) ;
394 if ( err
== errControlIsNotEmbedder
)
396 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
398 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
400 ControlHandle sibling
;
401 err
= GetIndexedSubControl( superControl
, i
, & sibling
) ;
402 if ( err
== errControlIsNotEmbedder
)
405 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
406 if ( IsControlVisible( sibling
) )
409 UMAGetControlBoundsInWindowCoords( sibling
, &r
) ;
410 if ( MacPtInRect( location
, &r
) )
412 ControlHandle child
= wxMacFindSubControl( toplevelWindow
, location
, sibling
, outPart
) ;
417 Point testLocation
= location
;
419 if ( toplevelWindow
&& toplevelWindow
->MacUsesCompositing() )
421 testLocation
.h
-= r
.left
;
422 testLocation
.v
-= r
.top
;
425 *outPart
= TestControl( sibling
, testLocation
) ;
435 ControlRef
wxMacFindControlUnderMouse( wxTopLevelWindowMac
* toplevelWindow
, Point location
, WindowRef window
, ControlPartCode
*outPart
)
437 #if TARGET_API_MAC_OSX
438 if ( UMAGetSystemVersion() >= 0x1030 && ( toplevelWindow
== 0 || toplevelWindow
->MacUsesCompositing() ) )
439 return FindControlUnderMouse( location
, window
, outPart
) ;
441 ControlRef rootControl
= NULL
;
442 verify_noerr( GetRootControl( window
, &rootControl
) ) ;
443 return wxMacFindSubControl( toplevelWindow
, location
, rootControl
, outPart
) ;
446 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
448 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
450 OSStatus result
= eventNotHandledErr
;
452 wxMacCarbonEvent
cEvent( event
) ;
454 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
455 Point windowMouseLocation
= screenMouseLocation
;
458 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
460 wxWindow
* currentMouseWindow
= NULL
;
461 ControlRef control
= NULL
;
465 QDGlobalToLocalPoint( UMAGetWindowPort(window
) , &windowMouseLocation
) ;
467 if ( wxTheApp
->s_captureWindow
&& wxTheApp
->s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
)
469 currentMouseWindow
= wxTheApp
->s_captureWindow
;
471 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
473 ControlPartCode part
;
474 control
= wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &part
) ;
475 // if there is no control below the mouse position, send the event to the toplevel window itself
477 currentMouseWindow
= (wxWindow
*) data
;
480 currentMouseWindow
= wxFindControlFromMacControl( control
) ;
481 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
484 // for wxToolBar to function we have to send certaint events to it
485 // instead of its children (wxToolBarTools)
487 GetSuperControl(control
, &parent
);
488 wxWindow
*wxParent
= wxFindControlFromMacControl( parent
) ;
489 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
490 currentMouseWindow
= wxParent
;
497 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
498 SetupMouseEvent( wxevent
, cEvent
) ;
500 // handle all enter / leave events
502 if ( currentMouseWindow
!= g_MacLastWindow
)
504 if ( g_MacLastWindow
)
506 wxMouseEvent
eventleave(wxevent
);
507 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
508 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
509 eventleave
.SetEventObject( g_MacLastWindow
) ;
512 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
513 #endif // wxUSE_TOOLTIPS
514 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
516 if ( currentMouseWindow
)
518 wxMouseEvent
evententer(wxevent
);
519 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
520 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
521 evententer
.SetEventObject( currentMouseWindow
) ;
523 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
524 #endif // wxUSE_TOOLTIPS
525 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
527 g_MacLastWindow
= currentMouseWindow
;
530 if ( windowPart
== inMenuBar
)
532 // special case menu bar, as we are having a low-level runloop we must do it ourselves
533 if ( cEvent
.GetKind() == kEventMouseDown
)
535 ::MenuSelect( screenMouseLocation
) ;
538 } // if ( windowPart == inMenuBar )
539 else if ( currentMouseWindow
)
541 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
543 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
545 wxevent
.SetEventObject( currentMouseWindow
) ;
547 // make tooltips current
550 if ( wxevent
.GetEventType() == wxEVT_MOTION
551 || wxevent
.GetEventType() == wxEVT_ENTER_WINDOW
552 || wxevent
.GetEventType() == wxEVT_LEAVE_WINDOW
)
553 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
554 #endif // wxUSE_TOOLTIPS
555 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
557 if ((currentMouseWindowParent
!= NULL
) &&
558 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
559 currentMouseWindow
= NULL
;
565 // if the user code did _not_ handle the event, then perform the
566 // default processing
567 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
569 // ... that is set focus to this window
570 if (currentMouseWindow
->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
571 currentMouseWindow
->SetFocus();
574 ControlPartCode dummyPart
;
575 // if built-in find control is finding the wrong control (ie static box instead of overlaid
576 // button, we cannot let the standard handler do its job, but must handle manually
578 if ( ( cEvent
.GetKind() == kEventMouseDown
)
581 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
582 wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &dummyPart
) )
586 if ( currentMouseWindow
->MacIsReallyEnabled() )
588 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
589 Point clickLocation
= windowMouseLocation
;
591 if ( toplevelWindow
->MacUsesCompositing() )
592 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
594 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
595 modifiers
, (ControlActionUPP
) -1 ) ;
597 if ((currentMouseWindowParent
!= NULL
) &&
598 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
599 currentMouseWindow
= NULL
;
604 if ( cEvent
.GetKind() == kEventMouseUp
&& wxTheApp
->s_captureWindow
)
606 wxTheApp
->s_captureWindow
= NULL
;
612 wxWindow
* cursorTarget
= currentMouseWindow
;
613 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
615 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
617 cursorTarget
= cursorTarget
->GetParent() ;
619 cursorPoint
+= cursorTarget
->GetPosition();
622 } // else if ( currentMouseWindow )
625 // don't mess with controls we don't know about
626 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
627 // so we try sending them the correct control directly
628 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
630 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
631 Point clickLocation
= windowMouseLocation
;
632 if ( toplevelWindow
->MacUsesCompositing() )
636 hiPoint
.x
= clickLocation
.h
;
637 hiPoint
.y
= clickLocation
.v
;
638 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
639 clickLocation
.h
= (int)hiPoint
.x
;
640 clickLocation
.v
= (int)hiPoint
.y
;
643 HandleControlClick( control
, clickLocation
,
644 modifiers
, (ControlActionUPP
) -1 ) ;
651 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
653 OSStatus result
= eventNotHandledErr
;
655 wxMacCarbonEvent
cEvent( event
) ;
657 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
658 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
660 switch( GetEventKind( event
) )
662 case kEventWindowActivated
:
664 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
665 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
666 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
667 wxevent
.SetEventObject(toplevelWindow
);
668 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
669 // we still sending an eventNotHandledErr in order to allow for default processing
672 case kEventWindowDeactivated
:
674 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
675 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
676 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
677 wxevent
.SetEventObject(toplevelWindow
);
678 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
679 // we still sending an eventNotHandledErr in order to allow for default processing
682 case kEventWindowShown
:
683 toplevelWindow
->Refresh() ;
686 case kEventWindowClose
:
687 toplevelWindow
->Close() ;
690 case kEventWindowBoundsChanged
:
692 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
693 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
694 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
695 if ( attributes
& kWindowBoundsChangeSizeChanged
)
697 // according to the other ports we handle this within the OS level
698 // resize event, not within a wxSizeEvent
699 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
703 frame
->PositionStatusBar();
706 frame
->PositionToolBar();
710 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
711 event
.SetEventObject( toplevelWindow
) ;
713 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
715 if ( attributes
& kWindowBoundsChangeOriginChanged
)
717 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
718 event
.SetEventObject( toplevelWindow
) ;
719 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
724 case kEventWindowBoundsChanging
:
726 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
727 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
729 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
731 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
732 int left
, top
, right
, bottom
;
733 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
734 wxRect
r( newRect
.left
- left
, newRect
.top
- top
,
735 newRect
.right
- newRect
.left
+ left
+ right
, newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
736 // this is a EVT_SIZING not a EVT_SIZE type !
737 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
738 wxevent
.SetEventObject( toplevelWindow
) ;
740 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
741 adjustR
= wxevent
.GetRect() ;
743 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
744 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
745 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
746 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
747 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
748 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
749 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
750 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
751 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
752 if ( !EqualRect( &newRect
, &adjustedRect
) )
753 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
765 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
767 OSStatus result
= eventNotHandledErr
;
769 switch ( GetEventClass( event
) )
771 case kEventClassKeyboard
:
772 result
= KeyboardEventHandler( handler
, event
, data
) ;
774 case kEventClassTextInput
:
775 result
= TextInputEventHandler( handler
, event
, data
) ;
777 case kEventClassWindow
:
778 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
780 case kEventClassMouse
:
781 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
789 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
791 // ---------------------------------------------------------------------------
792 // wxWindowMac utility functions
793 // ---------------------------------------------------------------------------
795 // Find an item given the Macintosh Window Reference
797 #if KEY_wxList_DEPRECATED
798 wxList
wxWinMacWindowList(wxKEY_INTEGER
);
799 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
801 wxNode
*node
= wxWinMacWindowList
.Find((long)inWindowRef
);
804 return (wxTopLevelWindowMac
*)node
->GetData();
807 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
808 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
810 // adding NULL WindowRef is (first) surely a result of an error and
811 // (secondly) breaks menu command processing
812 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
814 if ( !wxWinMacWindowList
.Find((long)inWindowRef
) )
815 wxWinMacWindowList
.Append((long)inWindowRef
, win
);
818 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
819 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
821 wxWinMacWindowList
.DeleteObject(win
);
825 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
827 static MacWindowMap wxWinMacWindowList
;
829 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
831 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
833 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
836 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
837 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
839 // adding NULL WindowRef is (first) surely a result of an error and
841 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
843 wxWinMacWindowList
[inWindowRef
] = win
;
846 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
847 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
849 MacWindowMap::iterator it
;
850 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
852 if ( it
->second
== win
)
854 wxWinMacWindowList
.erase(it
);
859 #endif // deprecated wxList
861 // ----------------------------------------------------------------------------
862 // wxTopLevelWindowMac creation
863 // ----------------------------------------------------------------------------
865 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
873 void wxTopLevelWindowMac::Init()
876 m_maximizeOnShow
= FALSE
;
878 #if TARGET_API_MAC_OSX
879 if ( UMAGetSystemVersion() >= 0x1030 )
881 m_macUsesCompositing
= TRUE
;
886 m_macUsesCompositing
= FALSE
;
888 m_macEventHandler
= NULL
;
889 m_macFullScreenData
= NULL
;
892 class wxMacDeferredWindowDeleter
: public wxObject
895 wxMacDeferredWindowDeleter( WindowRef windowRef
)
897 m_macWindow
= windowRef
;
899 virtual ~wxMacDeferredWindowDeleter()
901 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
904 WindowRef m_macWindow
;
907 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
909 const wxString
& title
,
913 const wxString
& name
)
918 m_windowStyle
= style
;
922 m_windowId
= id
== -1 ? NewControlId() : id
;
923 wxWindow::SetTitle( title
) ;
925 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
927 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
929 if (GetExtraStyle() & wxFRAME_EX_METAL
)
930 MacSetMetalAppearance(true);
932 wxTopLevelWindows
.Append(this);
935 parent
->AddChild(this);
940 wxTopLevelWindowMac::~wxTopLevelWindowMac()
945 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
947 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
950 if ( m_macEventHandler
)
952 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
953 m_macEventHandler
= NULL
;
956 wxRemoveMacWindowAssociation( this ) ;
958 if ( wxModelessWindows
.Find(this) )
959 wxModelessWindows
.DeleteObject(this);
961 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
963 m_macFullScreenData
= NULL
;
967 // ----------------------------------------------------------------------------
968 // wxTopLevelWindowMac maximize/minimize
969 // ----------------------------------------------------------------------------
971 void wxTopLevelWindowMac::Maximize(bool maximize
)
973 wxMacPortStateHelper
help( (GrafPtr
) GetWindowPort( (WindowRef
) m_macWindow
) ) ;
974 wxMacWindowClipper
clip (this);
975 ZoomWindow( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, false ) ;
978 bool wxTopLevelWindowMac::IsMaximized() const
980 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
983 void wxTopLevelWindowMac::Iconize(bool iconize
)
985 if ( IsWindowCollapsable((WindowRef
)m_macWindow
) )
986 CollapseWindow((WindowRef
)m_macWindow
, iconize
) ;
989 bool wxTopLevelWindowMac::IsIconized() const
991 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
994 void wxTopLevelWindowMac::Restore()
996 // not available on mac
999 // ----------------------------------------------------------------------------
1000 // wxTopLevelWindowMac misc
1001 // ----------------------------------------------------------------------------
1003 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1005 return wxPoint(0,0) ;
1008 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
1011 wxTopLevelWindowBase::SetIcon(icon
);
1014 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1016 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1018 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1020 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1024 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1026 if ( m_macEventHandler
!= NULL
)
1028 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1030 InstallWindowEventHandler(MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1031 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1034 void wxTopLevelWindowMac::MacCreateRealWindow( const wxString
& title
,
1038 const wxString
& name
)
1040 OSStatus err
= noErr
;
1042 m_windowStyle
= style
;
1052 wxRect display
= wxGetClientDisplayRect() ;
1054 if ( x
== wxDefaultPosition
.x
)
1057 if ( y
== wxDefaultPosition
.y
)
1060 int w
= WidthDefault(size
.x
);
1061 int h
= HeightDefault(size
.y
);
1063 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1065 // translate the window attributes in the appropriate window class and attributes
1067 WindowClass wclass
= 0;
1068 WindowAttributes attr
= kWindowNoAttributes
;
1069 WindowGroupRef group
= NULL
;
1071 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1074 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1075 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1076 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1079 wclass
= kFloatingWindowClass
;
1080 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1082 attr
|= kWindowSideTitlebarAttribute
;
1087 wclass
= kPlainWindowClass
;
1090 else if ( HasFlag( wxCAPTION
) )
1092 wclass
= kDocumentWindowClass
;
1094 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1095 else if ( HasFlag( wxFRAME_DRAWER
) )
1097 wclass
= kDrawerWindowClass
;
1098 // we must force compositing on a drawer
1099 m_macUsesCompositing
= TRUE
;
1101 #endif //10.2 and up
1104 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1105 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1107 wclass
= kDocumentWindowClass
;
1111 wclass
= kPlainWindowClass
;
1115 if ( HasFlag( wxMINIMIZE_BOX
) && wclass
!= kPlainWindowClass
)
1117 attr
|= kWindowCollapseBoxAttribute
;
1119 if ( HasFlag( wxMAXIMIZE_BOX
) && wclass
!= kPlainWindowClass
)
1121 attr
|= kWindowFullZoomAttribute
;
1123 if ( HasFlag( wxRESIZE_BORDER
) && wclass
!= kPlainWindowClass
)
1125 attr
|= kWindowResizableAttribute
;
1127 if ( HasFlag( wxCLOSE_BOX
) && wclass
!= kPlainWindowClass
)
1129 attr
|= kWindowCloseBoxAttribute
;
1132 if (UMAGetSystemVersion() >= 0x1000)
1134 // turn on live resizing (OS X only)
1135 attr
|= kWindowLiveResizeAttribute
;
1138 if ( HasFlag(wxSTAY_ON_TOP
) )
1140 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1143 #if TARGET_API_MAC_OSX
1144 if ( m_macUsesCompositing
)
1145 attr
|= kWindowCompositingAttribute
;
1148 if ( HasFlag(wxFRAME_SHAPED
) )
1150 WindowDefSpec customWindowDefSpec
;
1151 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1152 customWindowDefSpec
.u
.defProc
= NewWindowDefUPP(wxShapedMacWindowDef
);
1154 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1155 attr
, &theBoundsRect
,
1156 (WindowRef
*) &m_macWindow
);
1160 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1163 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1164 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1166 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1168 // the create commands are only for content rect, so we have to set the size again as
1170 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1172 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1173 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1174 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1175 #if TARGET_API_MAC_OSX
1177 if ( m_macUsesCompositing
)
1179 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1180 // the content view, so we have to retrieve it explicitely
1181 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1182 m_peer
->GetControlRefAddr() ) ;
1183 if ( !m_peer
->Ok() )
1185 // compatibility mode fallback
1186 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1191 ::CreateRootControl( (WindowRef
)m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1193 // the root control level handleer
1194 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1196 // the frame window event handler
1197 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1198 MacInstallTopLevelWindowEventHandler() ;
1202 if ( HasFlag(wxFRAME_SHAPED
) )
1204 // default shape matches the window size
1205 wxRegion
rgn(0, 0, w
, h
);
1209 wxWindowCreateEvent
event(this);
1210 GetEventHandler()->ProcessEvent(event
);
1213 void wxTopLevelWindowMac::ClearBackground()
1215 wxWindow::ClearBackground() ;
1218 // Raise the window to the top of the Z order
1219 void wxTopLevelWindowMac::Raise()
1221 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1224 // Lower the window to the bottom of the Z order
1225 void wxTopLevelWindowMac::Lower()
1227 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1231 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1233 if(s_macDeactivateWindow
)
1235 wxLogDebug(wxT("Doing delayed deactivation of %p"),s_macDeactivateWindow
);
1236 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1240 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1242 // wxLogDebug(wxT("TopLevel=%p::MacActivate"),this);
1244 if(s_macDeactivateWindow
==this)
1245 s_macDeactivateWindow
=NULL
;
1246 MacDelayedDeactivation(timestamp
);
1247 MacPropagateHiliteChanged() ;
1250 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1252 wxWindow::SetTitle( title
) ;
1253 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1256 bool wxTopLevelWindowMac::Show(bool show
)
1258 if ( !wxTopLevelWindowBase::Show(show
) )
1263 #if wxUSE_SYSTEM_OPTIONS //code contributed by Ryan Wilcox December 18, 2003
1264 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1266 ::ShowWindow( (WindowRef
)m_macWindow
);
1271 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowShowTransitionAction
,nil
);
1273 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1274 // as apps expect a size event to occur at this moment
1275 wxSizeEvent
event( GetSize() , m_windowId
);
1276 event
.SetEventObject(this);
1277 GetEventHandler()->ProcessEvent(event
);
1281 #if wxUSE_SYSTEM_OPTIONS
1282 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1284 ::HideWindow((WindowRef
) m_macWindow
);
1289 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowHideTransitionAction
,nil
);
1293 MacPropagateVisibilityChanged() ;
1298 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1302 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1304 data
= new FullScreenData() ;
1306 m_macFullScreenData
= data
;
1307 data
->m_position
= GetPosition() ;
1308 data
->m_size
= GetSize() ;
1310 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1314 int left
, top
, right
, bottom
;
1315 wxRect client
= wxGetClientDisplayRect() ;
1324 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1326 if ( style
& wxFULLSCREEN_NOCAPTION
)
1331 if ( style
& wxFULLSCREEN_NOBORDER
)
1337 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1341 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1345 SetSize( x
, y
, w
, h
) ;
1350 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1351 SetPosition( data
->m_position
) ;
1352 SetSize( data
->m_size
) ;
1354 m_macFullScreenData
= NULL
;
1359 bool wxTopLevelWindowMac::IsFullScreen() const
1361 return m_macFullScreenData
!= NULL
;
1364 // we are still using coordinates of the content view, todo switch to structure bounds
1366 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1370 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1371 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1373 left
= content
.left
- structure
.left
;
1374 top
= content
.top
- structure
.top
;
1375 right
= structure
.right
- content
.right
;
1376 bottom
= structure
.bottom
- content
.bottom
;
1379 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1381 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1382 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1385 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1388 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1389 if(x
) *x
= bounds
.left
;
1390 if(y
) *y
= bounds
.top
;
1392 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1395 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1396 if(width
) *width
= bounds
.right
- bounds
.left
;
1397 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1400 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1403 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1404 if(width
) *width
= bounds
.right
- bounds
.left
;
1405 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1408 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1410 #if TARGET_API_MAC_OSX
1411 wxASSERT_MSG( m_macUsesCompositing
,
1412 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1414 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1415 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1419 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1421 #if TARGET_API_MAC_OSX
1422 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1428 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1430 ChangeWindowAttributes ( (WindowRef
) m_macWindow
, attributesToSet
, attributesToClear
) ;
1433 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1436 GetWindowAttributes((WindowRef
) m_macWindow
, &attr
) ;
1440 void wxTopLevelWindowMac::MacPerformUpdates()
1442 #if TARGET_API_MAC_OSX
1443 if ( m_macUsesCompositing
)
1445 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1446 // for composited windows this also triggers a redraw of all
1447 // invalid views in the window
1448 if( UMAGetSystemVersion() >= 0x1030 )
1449 HIWindowFlush((WindowRef
) m_macWindow
) ;
1453 // the only way to trigger the redrawing on earlier systems is to call
1456 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1457 UInt32 currentEventClass
= 0 ;
1458 UInt32 currentEventKind
= 0 ;
1459 if ( currentEvent
!= NULL
)
1461 currentEventClass
= ::GetEventClass( currentEvent
) ;
1462 currentEventKind
= ::GetEventKind( currentEvent
) ;
1464 if ( currentEventClass
!= kEventClassMenu
)
1466 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1468 OSStatus status
= noErr
;
1469 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1476 BeginUpdate( (WindowRef
) m_macWindow
) ;
1478 RgnHandle updateRgn
= NewRgn();
1481 GetPortVisibleRegion( GetWindowPort( (WindowRef
)m_macWindow
), updateRgn
);
1482 UpdateControls( (WindowRef
)m_macWindow
, updateRgn
) ;
1483 // if ( !EmptyRgn( updateRgn ) )
1484 // MacDoRedraw( updateRgn , 0 , true) ;
1485 DisposeRgn( updateRgn
);
1487 EndUpdate( (WindowRef
)m_macWindow
) ;
1488 QDFlushPortBuffer( GetWindowPort( (WindowRef
)m_macWindow
) , NULL
) ;
1492 // Attracts the users attention to this window if the application is
1493 // inactive (should be called when a background event occurs)
1495 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1498 DisposePtr( (Ptr
) ptr
) ;
1502 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1504 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1505 static wxMacNMUPP
nmupp( wxMacNMResponse
)
1507 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1508 notificationRequest
->qType
= nmType
;
1509 notificationRequest
->nmMark
= 1 ;
1510 notificationRequest
->nmIcon
= 0 ;
1511 notificationRequest
->nmSound
= 0 ;
1512 notificationRequest
->nmStr
= NULL
;
1513 notificationRequest
->nmResp
= nmupp
;
1514 verify_noerr( NMInstall( notificationRequest
) ) ;
1517 // ---------------------------------------------------------------------------
1518 // Shape implementation
1519 // ---------------------------------------------------------------------------
1522 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1524 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
1525 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1527 // The empty region signifies that the shape should be removed from the
1529 if ( region
.IsEmpty() )
1531 wxSize sz
= GetClientSize();
1532 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1533 return SetShape(rgn
);
1536 // Make a copy of the region
1537 RgnHandle shapeRegion
= NewRgn();
1538 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1540 // Dispose of any shape region we may already have
1541 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1545 // Save the region so we can use it later
1546 SetWRefCon((WindowRef
)MacGetWindowRef(), (SInt32
)shapeRegion
);
1548 // Tell the window manager that the window has changed shape
1549 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1553 // ---------------------------------------------------------------------------
1554 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1555 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1556 // ---------------------------------------------------------------------------
1558 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1560 GetWindowPortBounds(window
, inRect
);
1561 Point pt
= {inRect
->left
, inRect
->top
};
1562 QDLocalToGlobalPoint( GetWindowPort(window
) , &pt
) ;
1564 inRect
->left
= pt
.h
;
1565 inRect
->bottom
+= pt
.v
;
1566 inRect
->right
+= pt
.h
;
1570 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1572 /*------------------------------------------------------
1573 Define which options your custom window supports.
1574 --------------------------------------------------------*/
1575 //just enable everything for our demo
1576 *(OptionBits
*)param
=//kWindowCanGrow|
1578 //kWindowCanCollapse|
1579 //kWindowCanGetWindowRegion|
1580 //kWindowHasTitleBar|
1581 //kWindowSupportsDragHilite|
1582 kWindowCanDrawInCurrentPort
|
1583 //kWindowCanMeasureTitle|
1584 kWindowWantsDisposeAtProcessDeath
|
1585 kWindowSupportsGetGrowImageRegion
|
1586 kWindowDefSupportsColorGrafPort
;
1590 // The content region is left as a rectangle matching the window size, this is
1591 // so the origin in the paint event, and etc. still matches what the
1592 // programmer expects.
1593 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1596 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1600 wxShapedMacWindowGetPos(window
, &r
) ;
1601 RectRgn( rgn
, &r
) ;
1605 // The structure region is set to the shape given to the SetShape method.
1606 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1608 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1614 wxShapedMacWindowGetPos(window
, &windowRect
); //how big is the window
1615 CopyRgn(cachedRegion
, rgn
); //make a copy of our cached region
1616 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1617 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1623 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1625 GetWindowRegionPtr rgnRec
=(GetWindowRegionPtr
)param
;
1627 switch(rgnRec
->regionCode
)
1629 case kWindowStructureRgn
:
1630 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1632 case kWindowContentRgn
:
1633 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1636 SetEmptyRgn(rgnRec
->winRgn
);
1643 static SInt32
wxShapedMacWindowHitTest(WindowRef window
,SInt32 param
)
1645 /*------------------------------------------------------
1646 Determine the region of the window which was hit
1647 --------------------------------------------------------*/
1649 static RgnHandle tempRgn
=nil
;
1654 SetPt(&hitPoint
,LoWord(param
),HiWord(param
));//get the point clicked
1656 //Mac OS 8.5 or later
1657 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1658 if (PtInRgn(hitPoint
, tempRgn
)) //in window content region?
1661 return wNoHit
;//no significant area was hit.
1665 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1669 case kWindowMsgHitTest
:
1670 return wxShapedMacWindowHitTest(window
,param
);
1672 case kWindowMsgGetFeatures
:
1673 return wxShapedMacWindowGetFeatures(window
,param
);
1675 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1676 case kWindowMsgGetRegion
:
1677 return wxShapedMacWindowGetRegion(window
,param
);
1683 // ---------------------------------------------------------------------------