1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: mac/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for Mac
4 // Author: Stefan Csomor
8 // Copyright: (c) 2001-2004 Stefan Csomor
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "toplevel.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/toplevel.h"
35 #include "wx/string.h"
38 #include "wx/settings.h"
39 #include "wx/strconv.h"
40 #include "wx/control.h"
43 #include "wx/mac/uma.h"
44 #include "wx/mac/aga.h"
46 #include "wx/tooltip.h"
48 #if wxUSE_SYSTEM_OPTIONS
49 #include "wx/sysopt.h"
53 #include <ToolUtils.h>
57 #include "wx/mac/private.h"
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 // list of all frames and modeless dialogs
64 wxWindowList wxModelessWindows
;
66 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
68 // ============================================================================
69 // wxTopLevelWindowMac implementation
70 // ============================================================================
72 BEGIN_EVENT_TABLE(wxTopLevelWindowMac
, wxTopLevelWindowBase
)
76 // ---------------------------------------------------------------------------
78 // ---------------------------------------------------------------------------
80 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
82 static const EventTypeSpec eventList
[] =
84 // TODO remove control related event like key and mouse (except for WindowLeave events)
86 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
88 { kEventClassKeyboard
, kEventRawKeyDown
} ,
89 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
90 { kEventClassKeyboard
, kEventRawKeyUp
} ,
91 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
94 { kEventClassWindow
, kEventWindowShown
} ,
95 { kEventClassWindow
, kEventWindowActivated
} ,
96 { kEventClassWindow
, kEventWindowDeactivated
} ,
97 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
98 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
99 { kEventClassWindow
, kEventWindowClose
} ,
101 // we have to catch these events on the toplevel window level, as controls don't get the
102 // raw mouse events anymore
104 { kEventClassMouse
, kEventMouseDown
} ,
105 { kEventClassMouse
, kEventMouseUp
} ,
106 { kEventClassMouse
, kEventMouseWheelMoved
} ,
107 { kEventClassMouse
, kEventMouseMoved
} ,
108 { kEventClassMouse
, kEventMouseDragged
} ,
111 static pascal OSStatus
TextInputEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
113 OSStatus result
= eventNotHandledErr
;
115 wxWindow
* focus
= wxWindow::FindFocus() ;
116 unsigned char charCode
;
123 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent
) ;
125 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
,sizeof(char), NULL
,&charCode
);
126 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
127 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
128 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
129 sizeof( Point
), NULL
, &point
);
131 switch ( GetEventKind( event
) )
133 case kEventTextInputUnicodeForKeyEvent
:
134 // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not
135 // get its own kEventTextInputUnicodeForKeyEvent, so we route back the
136 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
139 ControlRef macControl
= (ControlRef
) control
->GetHandle() ;
142 ::HandleControlKey( macControl
, keyCode
, charCode
, modifiers
) ;
147 // this may lead to double events sent to a window in case all handlers have skipped the key down event
148 UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
149 UInt32 message = (keyCode << 8) + charCode;
151 if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent(
152 focus , message , modifiers , when , point.h , point.v ) )
163 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
165 OSStatus result
= eventNotHandledErr
;
166 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
167 // FindFocus does not return the actual focus window,but the enclosing window
168 wxWindow
* focus
= wxWindow::DoFindFocus();
172 unsigned char charCode
;
177 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
180 UInt32 dataSize
= 0 ;
181 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
185 UniChar
* charBuf
= buf
;
188 charBuf
= new UniChar
[ dataSize
/ sizeof( UniChar
) ] ;
189 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
190 #if SIZEOF_WCHAR_T == 2
191 uniChar
= charBuf
[0] ;
193 wxMBConvUTF16 converter
;
194 converter
.MB2WC( &uniChar
, (const char*)charBuf
, 1 ) ;
201 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
,sizeof(char), NULL
,&charCode
);
202 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
203 GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
204 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
205 sizeof( Point
), NULL
, &point
);
207 UInt32 message
= (keyCode
<< 8) + charCode
;
208 switch( GetEventKind( event
) )
210 case kEventRawKeyRepeat
:
211 case kEventRawKeyDown
:
213 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
214 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
215 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
216 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
217 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
) )
221 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
224 case kEventRawKeyUp
:
225 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
226 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
) )
231 case kEventRawKeyModifiersChanged
:
233 wxKeyEvent
event(wxEVT_KEY_DOWN
);
235 event
.m_shiftDown
= modifiers
& shiftKey
;
236 event
.m_controlDown
= modifiers
& controlKey
;
237 event
.m_altDown
= modifiers
& optionKey
;
238 event
.m_metaDown
= modifiers
& cmdKey
;
240 event
.m_uniChar
= uniChar
;
244 event
.SetTimestamp(when
);
245 event
.SetEventObject(focus
);
247 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
249 event
.m_keyCode
= WXK_CONTROL
;
250 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
251 focus
->GetEventHandler()->ProcessEvent( event
) ;
253 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
255 event
.m_keyCode
= WXK_SHIFT
;
256 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
257 focus
->GetEventHandler()->ProcessEvent( event
) ;
259 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
261 event
.m_keyCode
= WXK_ALT
;
262 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
263 focus
->GetEventHandler()->ProcessEvent( event
) ;
265 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
267 event
.m_keyCode
= WXK_COMMAND
;
268 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
269 focus
->GetEventHandler()->ProcessEvent( event
) ;
271 wxApp::s_lastModifiers
= modifiers
;
279 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
280 // for windows that we didn't create (like eg Scrollbars in a databrowser) , or for controls where we did not handle the
283 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
285 wxWindow
* g_MacLastWindow
= NULL
;
287 static EventMouseButton lastButton
= 0 ;
289 static void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
291 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
292 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
294 // this parameter are not given for all events
295 EventMouseButton button
= 0 ;
296 UInt32 clickCount
= 0 ;
297 cEvent
.GetParameter
<EventMouseButton
>(kEventParamMouseButton
, typeMouseButton
, &button
) ;
298 cEvent
.GetParameter
<UInt32
>(kEventParamClickCount
, typeUInt32
, &clickCount
) ;
300 wxevent
.m_x
= screenMouseLocation
.h
;
301 wxevent
.m_y
= screenMouseLocation
.v
;
302 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
303 wxevent
.m_controlDown
= modifiers
& controlKey
;
304 wxevent
.m_altDown
= modifiers
& optionKey
;
305 wxevent
.m_metaDown
= modifiers
& cmdKey
;
306 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
307 // a control click is interpreted as a right click
308 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
310 button
= kEventMouseButtonSecondary
;
313 // otherwise we report double clicks by connecting a left click with a ctrl-left click
314 if ( clickCount
> 1 && button
!= lastButton
)
317 // we must make sure that our synthetic 'right' button corresponds in
318 // mouse down, moved and mouse up, and does not deliver a right down and left up
320 if ( cEvent
.GetKind() == kEventMouseDown
)
321 lastButton
= button
;
325 else if ( lastButton
)
326 button
= lastButton
;
328 // determinate the correct down state, wx does not want a 'down' for a mouseUp event, while mac delivers
330 if ( button
!= 0 && cEvent
.GetKind() != kEventMouseUp
)
334 case kEventMouseButtonPrimary
:
335 wxevent
.m_leftDown
= true ;
337 case kEventMouseButtonSecondary
:
338 wxevent
.m_rightDown
= true ;
340 case kEventMouseButtonTertiary
:
341 wxevent
.m_middleDown
= true ;
345 // translate into wx types
346 switch ( cEvent
.GetKind() )
348 case kEventMouseDown
:
351 case kEventMouseButtonPrimary
:
352 wxevent
.SetEventType(clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
354 case kEventMouseButtonSecondary
:
355 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
357 case kEventMouseButtonTertiary
:
358 wxevent
.SetEventType(clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
365 case kEventMouseButtonPrimary
:
366 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
368 case kEventMouseButtonSecondary
:
369 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
371 case kEventMouseButtonTertiary
:
372 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
376 case kEventMouseWheelMoved
:
378 wxevent
.SetEventType(wxEVT_MOUSEWHEEL
) ;
380 // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
381 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeLongInteger
) ;
383 wxevent
.m_wheelRotation
= delta
;
384 wxevent
.m_wheelDelta
= 1;
385 wxevent
.m_linesPerAction
= 1;
389 wxevent
.SetEventType(wxEVT_MOTION
) ;
394 ControlRef
wxMacFindSubControl( wxTopLevelWindowMac
* toplevelWindow
, Point location
, ControlRef superControl
, ControlPartCode
*outPart
)
398 UInt16 childrenCount
= 0 ;
399 OSStatus err
= CountSubControls( superControl
, &childrenCount
) ;
400 if ( err
== errControlIsNotEmbedder
)
402 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
404 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
406 ControlHandle sibling
;
407 err
= GetIndexedSubControl( superControl
, i
, & sibling
) ;
408 if ( err
== errControlIsNotEmbedder
)
411 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
412 if ( IsControlVisible( sibling
) )
415 UMAGetControlBoundsInWindowCoords( sibling
, &r
) ;
416 if ( MacPtInRect( location
, &r
) )
418 ControlHandle child
= wxMacFindSubControl( toplevelWindow
, location
, sibling
, outPart
) ;
423 Point testLocation
= location
;
425 if ( toplevelWindow
&& toplevelWindow
->MacUsesCompositing() )
427 testLocation
.h
-= r
.left
;
428 testLocation
.v
-= r
.top
;
431 *outPart
= TestControl( sibling
, testLocation
) ;
441 ControlRef
wxMacFindControlUnderMouse( wxTopLevelWindowMac
* toplevelWindow
, Point location
, WindowRef window
, ControlPartCode
*outPart
)
443 #if TARGET_API_MAC_OSX
444 if ( UMAGetSystemVersion() >= 0x1030 && ( toplevelWindow
== 0 || toplevelWindow
->MacUsesCompositing() ) )
445 return FindControlUnderMouse( location
, window
, outPart
) ;
447 ControlRef rootControl
= NULL
;
448 verify_noerr( GetRootControl( window
, &rootControl
) ) ;
449 return wxMacFindSubControl( toplevelWindow
, location
, rootControl
, outPart
) ;
453 #define NEW_CAPTURE_HANDLING 1
455 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
457 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
459 OSStatus result
= eventNotHandledErr
;
461 wxMacCarbonEvent
cEvent( event
) ;
463 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
464 Point windowMouseLocation
= screenMouseLocation
;
467 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
469 wxWindow
* currentMouseWindow
= NULL
;
470 ControlRef control
= NULL
;
472 #if NEW_CAPTURE_HANDLING
473 if ( wxApp::s_captureWindow
)
475 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
481 QDGlobalToLocalPoint( UMAGetWindowPort(window
) , &windowMouseLocation
) ;
483 if ( wxApp::s_captureWindow
484 #if !NEW_CAPTURE_HANDLING
485 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
489 currentMouseWindow
= wxApp::s_captureWindow
;
491 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
493 ControlPartCode part
;
494 control
= wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &part
) ;
495 // if there is no control below the mouse position, send the event to the toplevel window itself
497 currentMouseWindow
= (wxWindow
*) data
;
500 currentMouseWindow
= wxFindControlFromMacControl( control
) ;
501 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
504 // for wxToolBar to function we have to send certaint events to it
505 // instead of its children (wxToolBarTools)
507 GetSuperControl(control
, &parent
);
508 wxWindow
*wxParent
= wxFindControlFromMacControl( parent
) ;
509 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
510 currentMouseWindow
= wxParent
;
517 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
518 SetupMouseEvent( wxevent
, cEvent
) ;
520 // handle all enter / leave events
522 if ( currentMouseWindow
!= g_MacLastWindow
)
524 if ( g_MacLastWindow
)
526 wxMouseEvent
eventleave(wxevent
);
527 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
528 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
529 eventleave
.SetEventObject( g_MacLastWindow
) ;
532 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
533 #endif // wxUSE_TOOLTIPS
534 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
536 if ( currentMouseWindow
)
538 wxMouseEvent
evententer(wxevent
);
539 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
540 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
541 evententer
.SetEventObject( currentMouseWindow
) ;
543 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
544 #endif // wxUSE_TOOLTIPS
545 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
547 g_MacLastWindow
= currentMouseWindow
;
550 if ( windowPart
== inMenuBar
)
552 // special case menu bar, as we are having a low-level runloop we must do it ourselves
553 if ( cEvent
.GetKind() == kEventMouseDown
)
555 ::MenuSelect( screenMouseLocation
) ;
558 } // if ( windowPart == inMenuBar )
559 else if ( currentMouseWindow
)
561 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
563 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
565 wxevent
.SetEventObject( currentMouseWindow
) ;
567 // make tooltips current
570 if ( wxevent
.GetEventType() == wxEVT_MOTION
571 || wxevent
.GetEventType() == wxEVT_ENTER_WINDOW
572 || wxevent
.GetEventType() == wxEVT_LEAVE_WINDOW
)
573 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
574 #endif // wxUSE_TOOLTIPS
575 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
577 if ((currentMouseWindowParent
!= NULL
) &&
578 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
579 currentMouseWindow
= NULL
;
585 // if the user code did _not_ handle the event, then perform the
586 // default processing
587 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
589 // ... that is set focus to this window
590 if (currentMouseWindow
->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
591 currentMouseWindow
->SetFocus();
594 ControlPartCode dummyPart
;
595 // if built-in find control is finding the wrong control (ie static box instead of overlaid
596 // button, we cannot let the standard handler do its job, but must handle manually
598 if ( ( cEvent
.GetKind() == kEventMouseDown
)
601 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
602 wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &dummyPart
) )
606 if ( currentMouseWindow
->MacIsReallyEnabled() )
608 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
609 Point clickLocation
= windowMouseLocation
;
611 if ( toplevelWindow
->MacUsesCompositing() )
612 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
614 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
615 modifiers
, (ControlActionUPP
) -1 ) ;
617 if ((currentMouseWindowParent
!= NULL
) &&
618 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
619 currentMouseWindow
= NULL
;
624 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
626 wxApp::s_captureWindow
= NULL
;
632 wxWindow
* cursorTarget
= currentMouseWindow
;
633 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
635 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
637 cursorTarget
= cursorTarget
->GetParent() ;
639 cursorPoint
+= cursorTarget
->GetPosition();
642 } // else if ( currentMouseWindow )
645 // don't mess with controls we don't know about
646 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
647 // so we try sending them the correct control directly
648 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
650 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
651 Point clickLocation
= windowMouseLocation
;
652 if ( toplevelWindow
->MacUsesCompositing() )
656 hiPoint
.x
= clickLocation
.h
;
657 hiPoint
.y
= clickLocation
.v
;
658 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
659 clickLocation
.h
= (int)hiPoint
.x
;
660 clickLocation
.v
= (int)hiPoint
.y
;
663 HandleControlClick( control
, clickLocation
,
664 modifiers
, (ControlActionUPP
) -1 ) ;
671 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
673 OSStatus result
= eventNotHandledErr
;
675 wxMacCarbonEvent
cEvent( event
) ;
677 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
678 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
680 switch( GetEventKind( event
) )
682 case kEventWindowActivated
:
684 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
685 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
686 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
687 wxevent
.SetEventObject(toplevelWindow
);
688 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
689 // we still sending an eventNotHandledErr in order to allow for default processing
692 case kEventWindowDeactivated
:
694 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
695 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
696 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
697 wxevent
.SetEventObject(toplevelWindow
);
698 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
699 // we still sending an eventNotHandledErr in order to allow for default processing
702 case kEventWindowShown
:
704 toplevelWindow
->Refresh() ;
708 case kEventWindowClose
:
709 toplevelWindow
->Close() ;
712 case kEventWindowBoundsChanged
:
714 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
715 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
716 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
717 if ( attributes
& kWindowBoundsChangeSizeChanged
)
719 // according to the other ports we handle this within the OS level
720 // resize event, not within a wxSizeEvent
721 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
725 frame
->PositionStatusBar();
728 frame
->PositionToolBar();
732 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
733 event
.SetEventObject( toplevelWindow
) ;
735 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
736 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
738 if ( attributes
& kWindowBoundsChangeOriginChanged
)
740 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
741 event
.SetEventObject( toplevelWindow
) ;
742 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
747 case kEventWindowBoundsChanging
:
749 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
750 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
752 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
754 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
755 int left
, top
, right
, bottom
;
756 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
757 wxRect
r( newRect
.left
- left
, newRect
.top
- top
,
758 newRect
.right
- newRect
.left
+ left
+ right
, newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
759 // this is a EVT_SIZING not a EVT_SIZE type !
760 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
761 wxevent
.SetEventObject( toplevelWindow
) ;
763 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
764 adjustR
= wxevent
.GetRect() ;
766 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
767 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
768 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
769 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
770 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
771 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
772 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
773 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
774 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
775 if ( !EqualRect( &newRect
, &adjustedRect
) )
776 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
777 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
789 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
791 OSStatus result
= eventNotHandledErr
;
793 switch ( GetEventClass( event
) )
795 case kEventClassKeyboard
:
796 result
= KeyboardEventHandler( handler
, event
, data
) ;
798 case kEventClassTextInput
:
799 result
= TextInputEventHandler( handler
, event
, data
) ;
801 case kEventClassWindow
:
802 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
804 case kEventClassMouse
:
805 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
813 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
815 // ---------------------------------------------------------------------------
816 // wxWindowMac utility functions
817 // ---------------------------------------------------------------------------
819 // Find an item given the Macintosh Window Reference
821 #if KEY_wxList_DEPRECATED
822 wxList
wxWinMacWindowList(wxKEY_INTEGER
);
823 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
825 wxNode
*node
= wxWinMacWindowList
.Find((long)inWindowRef
);
828 return (wxTopLevelWindowMac
*)node
->GetData();
831 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
832 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
834 // adding NULL WindowRef is (first) surely a result of an error and
835 // (secondly) breaks menu command processing
836 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
838 if ( !wxWinMacWindowList
.Find((long)inWindowRef
) )
839 wxWinMacWindowList
.Append((long)inWindowRef
, win
);
842 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
843 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
845 wxWinMacWindowList
.DeleteObject(win
);
849 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
851 static MacWindowMap wxWinMacWindowList
;
853 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
855 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
857 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
860 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
861 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
863 // adding NULL WindowRef is (first) surely a result of an error and
865 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
867 wxWinMacWindowList
[inWindowRef
] = win
;
870 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
871 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
873 MacWindowMap::iterator it
;
874 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
876 if ( it
->second
== win
)
878 wxWinMacWindowList
.erase(it
);
883 #endif // deprecated wxList
885 // ----------------------------------------------------------------------------
886 // wxTopLevelWindowMac creation
887 // ----------------------------------------------------------------------------
889 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
897 void wxTopLevelWindowMac::Init()
900 m_maximizeOnShow
= false;
902 #if TARGET_API_MAC_OSX
903 if ( UMAGetSystemVersion() >= 0x1030 )
905 m_macUsesCompositing
= true;
910 m_macUsesCompositing
= false;
912 m_macEventHandler
= NULL
;
913 m_macFullScreenData
= NULL
;
916 class wxMacDeferredWindowDeleter
: public wxObject
919 wxMacDeferredWindowDeleter( WindowRef windowRef
)
921 m_macWindow
= windowRef
;
923 virtual ~wxMacDeferredWindowDeleter()
925 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
928 WindowRef m_macWindow
;
931 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
933 const wxString
& title
,
937 const wxString
& name
)
942 m_windowStyle
= style
;
946 m_windowId
= id
== -1 ? NewControlId() : id
;
947 wxWindow::SetTitle( title
) ;
949 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
951 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
953 if (GetExtraStyle() & wxFRAME_EX_METAL
)
954 MacSetMetalAppearance(true);
956 wxTopLevelWindows
.Append(this);
959 parent
->AddChild(this);
964 wxTopLevelWindowMac::~wxTopLevelWindowMac()
969 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
971 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
974 if ( m_macEventHandler
)
976 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
977 m_macEventHandler
= NULL
;
980 wxRemoveMacWindowAssociation( this ) ;
982 if ( wxModelessWindows
.Find(this) )
983 wxModelessWindows
.DeleteObject(this);
985 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
987 m_macFullScreenData
= NULL
;
991 // ----------------------------------------------------------------------------
992 // wxTopLevelWindowMac maximize/minimize
993 // ----------------------------------------------------------------------------
995 void wxTopLevelWindowMac::Maximize(bool maximize
)
997 // TODO Check, is this still necessary
999 wxMacPortStateHelper
help( (GrafPtr
) GetWindowPort( (WindowRef
) m_macWindow
) ) ;
1000 wxMacWindowClipper
clip (this);
1002 if ( !IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) )
1005 GetWindowBounds((WindowRef
)m_macWindow
, kWindowGlobalPortRgn
, &rect
);
1006 SetWindowIdealUserState((WindowRef
)m_macWindow
, &rect
);
1007 SetWindowUserState((WindowRef
)m_macWindow
, &rect
);
1009 ZoomWindow( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, false ) ;
1012 bool wxTopLevelWindowMac::IsMaximized() const
1014 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
1017 void wxTopLevelWindowMac::Iconize(bool iconize
)
1019 if ( IsWindowCollapsable((WindowRef
)m_macWindow
) )
1020 CollapseWindow((WindowRef
)m_macWindow
, iconize
) ;
1023 bool wxTopLevelWindowMac::IsIconized() const
1025 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1028 void wxTopLevelWindowMac::Restore()
1030 if ( IsMaximized() )
1032 else if ( IsIconized() )
1036 // ----------------------------------------------------------------------------
1037 // wxTopLevelWindowMac misc
1038 // ----------------------------------------------------------------------------
1040 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1042 return wxPoint(0,0) ;
1045 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
1048 wxTopLevelWindowBase::SetIcon(icon
);
1051 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1053 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1055 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1057 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1061 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1063 if ( m_macEventHandler
!= NULL
)
1065 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1067 InstallWindowEventHandler(MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1068 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1071 void wxTopLevelWindowMac::MacCreateRealWindow( const wxString
& title
,
1075 const wxString
& name
)
1077 OSStatus err
= noErr
;
1079 m_windowStyle
= style
;
1089 wxRect display
= wxGetClientDisplayRect() ;
1091 if ( x
== wxDefaultPosition
.x
)
1094 if ( y
== wxDefaultPosition
.y
)
1097 int w
= WidthDefault(size
.x
);
1098 int h
= HeightDefault(size
.y
);
1100 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1102 // translate the window attributes in the appropriate window class and attributes
1104 WindowClass wclass
= 0;
1105 WindowAttributes attr
= kWindowNoAttributes
;
1106 WindowGroupRef group
= NULL
;
1108 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1111 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1112 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1113 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1116 wclass
= kFloatingWindowClass
;
1117 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1119 attr
|= kWindowSideTitlebarAttribute
;
1124 wclass
= kPlainWindowClass
;
1127 else if ( HasFlag( wxCAPTION
) )
1129 wclass
= kDocumentWindowClass
;
1130 attr
|= kWindowInWindowMenuAttribute
;
1132 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1133 else if ( HasFlag( wxFRAME_DRAWER
) )
1135 wclass
= kDrawerWindowClass
;
1136 // we must force compositing on a drawer
1137 m_macUsesCompositing
= true ;
1139 #endif //10.2 and up
1142 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1143 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1145 wclass
= kDocumentWindowClass
;
1149 wclass
= kPlainWindowClass
;
1153 if ( HasFlag( wxMINIMIZE_BOX
) && wclass
!= kPlainWindowClass
)
1155 attr
|= kWindowCollapseBoxAttribute
;
1157 if ( HasFlag( wxMAXIMIZE_BOX
) && wclass
!= kPlainWindowClass
)
1159 attr
|= kWindowFullZoomAttribute
;
1161 if ( HasFlag( wxRESIZE_BORDER
) && wclass
!= kPlainWindowClass
)
1163 attr
|= kWindowResizableAttribute
;
1165 if ( HasFlag( wxCLOSE_BOX
) && wclass
!= kPlainWindowClass
)
1167 attr
|= kWindowCloseBoxAttribute
;
1170 if (UMAGetSystemVersion() >= 0x1000)
1172 // turn on live resizing (OS X only)
1173 attr
|= kWindowLiveResizeAttribute
;
1176 if ( HasFlag(wxSTAY_ON_TOP
) )
1178 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1181 #if TARGET_API_MAC_OSX
1182 if ( m_macUsesCompositing
)
1183 attr
|= kWindowCompositingAttribute
;
1186 if ( HasFlag(wxFRAME_SHAPED
) )
1188 WindowDefSpec customWindowDefSpec
;
1189 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1190 customWindowDefSpec
.u
.defProc
= NewWindowDefUPP(wxShapedMacWindowDef
);
1192 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1193 attr
, &theBoundsRect
,
1194 (WindowRef
*) &m_macWindow
);
1198 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1201 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1202 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1204 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1206 // the create commands are only for content rect, so we have to set the size again as
1208 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1210 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1211 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1212 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1213 #if TARGET_API_MAC_OSX
1215 if ( m_macUsesCompositing
)
1217 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1218 // the content view, so we have to retrieve it explicitly
1219 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1220 m_peer
->GetControlRefAddr() ) ;
1221 if ( !m_peer
->Ok() )
1223 // compatibility mode fallback
1224 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1229 ::CreateRootControl( (WindowRef
)m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1231 // the root control level handleer
1232 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1234 // the frame window event handler
1235 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1236 MacInstallTopLevelWindowEventHandler() ;
1238 DoSetWindowVariant( m_windowVariant
) ;
1242 if ( HasFlag(wxFRAME_SHAPED
) )
1244 // default shape matches the window size
1245 wxRegion
rgn(0, 0, w
, h
);
1249 wxWindowCreateEvent
event(this);
1250 GetEventHandler()->ProcessEvent(event
);
1253 void wxTopLevelWindowMac::ClearBackground()
1255 wxWindow::ClearBackground() ;
1258 // Raise the window to the top of the Z order
1259 void wxTopLevelWindowMac::Raise()
1261 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1264 // Lower the window to the bottom of the Z order
1265 void wxTopLevelWindowMac::Lower()
1267 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1271 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1273 if(s_macDeactivateWindow
)
1275 wxLogDebug(wxT("Doing delayed deactivation of %p"),s_macDeactivateWindow
);
1276 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1280 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1282 // wxLogDebug(wxT("TopLevel=%p::MacActivate"),this);
1284 if(s_macDeactivateWindow
==this)
1285 s_macDeactivateWindow
=NULL
;
1286 MacDelayedDeactivation(timestamp
);
1287 MacPropagateHiliteChanged() ;
1290 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1292 wxWindow::SetTitle( title
) ;
1293 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1296 bool wxTopLevelWindowMac::Show(bool show
)
1298 if ( !wxTopLevelWindowBase::Show(show
) )
1303 #if wxUSE_SYSTEM_OPTIONS //code contributed by Ryan Wilcox December 18, 2003
1304 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1306 ::ShowWindow( (WindowRef
)m_macWindow
);
1311 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowShowTransitionAction
,nil
);
1313 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1314 // as apps expect a size event to occur at this moment
1315 wxSizeEvent
event( GetSize() , m_windowId
);
1316 event
.SetEventObject(this);
1317 GetEventHandler()->ProcessEvent(event
);
1321 #if wxUSE_SYSTEM_OPTIONS
1322 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1324 ::HideWindow((WindowRef
) m_macWindow
);
1329 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowHideTransitionAction
,nil
);
1333 MacPropagateVisibilityChanged() ;
1338 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1342 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1344 data
= new FullScreenData() ;
1346 m_macFullScreenData
= data
;
1347 data
->m_position
= GetPosition() ;
1348 data
->m_size
= GetSize() ;
1350 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1354 int left
, top
, right
, bottom
;
1355 wxRect client
= wxGetClientDisplayRect() ;
1364 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1366 if ( style
& wxFULLSCREEN_NOCAPTION
)
1371 if ( style
& wxFULLSCREEN_NOBORDER
)
1377 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1381 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1385 SetSize( x
, y
, w
, h
) ;
1390 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1391 SetPosition( data
->m_position
) ;
1392 SetSize( data
->m_size
) ;
1394 m_macFullScreenData
= NULL
;
1399 bool wxTopLevelWindowMac::IsFullScreen() const
1401 return m_macFullScreenData
!= NULL
;
1404 // we are still using coordinates of the content view, todo switch to structure bounds
1406 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1410 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1411 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1413 left
= content
.left
- structure
.left
;
1414 top
= content
.top
- structure
.top
;
1415 right
= structure
.right
- content
.right
;
1416 bottom
= structure
.bottom
- content
.bottom
;
1419 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1421 m_cachedClippedRectValid
= false ;
1422 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1423 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1424 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1427 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1430 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1431 if(x
) *x
= bounds
.left
;
1432 if(y
) *y
= bounds
.top
;
1434 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1437 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1438 if(width
) *width
= bounds
.right
- bounds
.left
;
1439 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1442 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1445 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1446 if(width
) *width
= bounds
.right
- bounds
.left
;
1447 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1450 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1452 #if TARGET_API_MAC_OSX
1453 wxASSERT_MSG( m_macUsesCompositing
,
1454 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1456 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1457 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1461 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1463 #if TARGET_API_MAC_OSX
1464 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1470 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1472 ChangeWindowAttributes ( (WindowRef
) m_macWindow
, attributesToSet
, attributesToClear
) ;
1475 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1478 GetWindowAttributes((WindowRef
) m_macWindow
, &attr
) ;
1482 void wxTopLevelWindowMac::MacPerformUpdates()
1484 #if TARGET_API_MAC_OSX
1485 if ( m_macUsesCompositing
)
1487 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1488 // for composited windows this also triggers a redraw of all
1489 // invalid views in the window
1490 if( UMAGetSystemVersion() >= 0x1030 )
1491 HIWindowFlush((WindowRef
) m_macWindow
) ;
1495 // the only way to trigger the redrawing on earlier systems is to call
1498 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1499 UInt32 currentEventClass
= 0 ;
1500 UInt32 currentEventKind
= 0 ;
1501 if ( currentEvent
!= NULL
)
1503 currentEventClass
= ::GetEventClass( currentEvent
) ;
1504 currentEventKind
= ::GetEventKind( currentEvent
) ;
1506 if ( currentEventClass
!= kEventClassMenu
)
1508 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1510 OSStatus status
= noErr
;
1511 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1518 BeginUpdate( (WindowRef
) m_macWindow
) ;
1520 RgnHandle updateRgn
= NewRgn();
1523 GetPortVisibleRegion( GetWindowPort( (WindowRef
)m_macWindow
), updateRgn
);
1524 UpdateControls( (WindowRef
)m_macWindow
, updateRgn
) ;
1525 // if ( !EmptyRgn( updateRgn ) )
1526 // MacDoRedraw( updateRgn , 0 , true) ;
1527 DisposeRgn( updateRgn
);
1529 EndUpdate( (WindowRef
)m_macWindow
) ;
1530 QDFlushPortBuffer( GetWindowPort( (WindowRef
)m_macWindow
) , NULL
) ;
1534 // Attracts the users attention to this window if the application is
1535 // inactive (should be called when a background event occurs)
1537 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1540 DisposePtr( (Ptr
) ptr
) ;
1544 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1546 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1547 static wxMacNMUPP
nmupp( wxMacNMResponse
)
1549 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1550 notificationRequest
->qType
= nmType
;
1551 notificationRequest
->nmMark
= 1 ;
1552 notificationRequest
->nmIcon
= 0 ;
1553 notificationRequest
->nmSound
= 0 ;
1554 notificationRequest
->nmStr
= NULL
;
1555 notificationRequest
->nmResp
= nmupp
;
1556 verify_noerr( NMInstall( notificationRequest
) ) ;
1559 // ---------------------------------------------------------------------------
1560 // Shape implementation
1561 // ---------------------------------------------------------------------------
1564 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1566 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1567 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1569 // The empty region signifies that the shape should be removed from the
1571 if ( region
.IsEmpty() )
1573 wxSize sz
= GetClientSize();
1574 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1575 if ( rgn
.IsEmpty() )
1578 return SetShape(rgn
);
1581 // Make a copy of the region
1582 RgnHandle shapeRegion
= NewRgn();
1583 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1585 // Dispose of any shape region we may already have
1586 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1590 // Save the region so we can use it later
1591 SetWRefCon((WindowRef
)MacGetWindowRef(), (SInt32
)shapeRegion
);
1593 // Tell the window manager that the window has changed shape
1594 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1598 // ---------------------------------------------------------------------------
1599 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1600 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1601 // ---------------------------------------------------------------------------
1603 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1605 GetWindowPortBounds(window
, inRect
);
1606 Point pt
= {inRect
->left
, inRect
->top
};
1607 QDLocalToGlobalPoint( GetWindowPort(window
) , &pt
) ;
1609 inRect
->left
= pt
.h
;
1610 inRect
->bottom
+= pt
.v
;
1611 inRect
->right
+= pt
.h
;
1615 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1617 /*------------------------------------------------------
1618 Define which options your custom window supports.
1619 --------------------------------------------------------*/
1620 //just enable everything for our demo
1621 *(OptionBits
*)param
=//kWindowCanGrow|
1623 //kWindowCanCollapse|
1624 //kWindowCanGetWindowRegion|
1625 //kWindowHasTitleBar|
1626 //kWindowSupportsDragHilite|
1627 kWindowCanDrawInCurrentPort
|
1628 //kWindowCanMeasureTitle|
1629 kWindowWantsDisposeAtProcessDeath
|
1630 kWindowSupportsGetGrowImageRegion
|
1631 kWindowDefSupportsColorGrafPort
;
1635 // The content region is left as a rectangle matching the window size, this is
1636 // so the origin in the paint event, and etc. still matches what the
1637 // programmer expects.
1638 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1641 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1645 wxShapedMacWindowGetPos(window
, &r
) ;
1646 RectRgn( rgn
, &r
) ;
1650 // The structure region is set to the shape given to the SetShape method.
1651 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1653 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1659 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1660 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1661 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1662 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1668 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1670 GetWindowRegionPtr rgnRec
=(GetWindowRegionPtr
)param
;
1672 switch(rgnRec
->regionCode
)
1674 case kWindowStructureRgn
:
1675 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1677 case kWindowContentRgn
:
1678 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1681 SetEmptyRgn(rgnRec
->winRgn
);
1688 static SInt32
wxShapedMacWindowHitTest(WindowRef window
,SInt32 param
)
1690 /*------------------------------------------------------
1691 Determine the region of the window which was hit
1692 --------------------------------------------------------*/
1694 static RgnHandle tempRgn
=nil
;
1699 SetPt(&hitPoint
,LoWord(param
),HiWord(param
));//get the point clicked
1701 //Mac OS 8.5 or later
1702 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1703 if (PtInRgn(hitPoint
, tempRgn
)) //in window content region?
1706 return wNoHit
;//no significant area was hit.
1710 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1714 case kWindowMsgHitTest
:
1715 return wxShapedMacWindowHitTest(window
,param
);
1717 case kWindowMsgGetFeatures
:
1718 return wxShapedMacWindowGetFeatures(window
,param
);
1720 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1721 case kWindowMsgGetRegion
:
1722 return wxShapedMacWindowGetRegion(window
,param
);
1728 // ---------------------------------------------------------------------------