1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for Mac
4 // Author: Stefan Csomor
8 // Copyright: (c) 2001-2004 Stefan Csomor
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/toplevel.h"
31 #include "wx/string.h"
34 #include "wx/settings.h"
35 #include "wx/strconv.h"
36 #include "wx/control.h"
39 #include "wx/mac/uma.h"
40 #include "wx/mac/aga.h"
42 #include "wx/tooltip.h"
44 #if wxUSE_SYSTEM_OPTIONS
45 #include "wx/sysopt.h"
49 #include <ToolUtils.h>
53 #include "wx/mac/private.h"
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 // trace mask for activation tracing messages
60 static const wxChar
*TRACE_ACTIVATE
= _T("activation");
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 // list of all frames and modeless dialogs
67 wxWindowList wxModelessWindows
;
69 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
71 // ============================================================================
72 // wxTopLevelWindowMac implementation
73 // ============================================================================
75 BEGIN_EVENT_TABLE(wxTopLevelWindowMac
, wxTopLevelWindowBase
)
79 // ---------------------------------------------------------------------------
81 // ---------------------------------------------------------------------------
83 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
85 static const EventTypeSpec eventList
[] =
87 // TODO remove control related event like key and mouse (except for WindowLeave events)
89 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
91 { kEventClassKeyboard
, kEventRawKeyDown
} ,
92 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
93 { kEventClassKeyboard
, kEventRawKeyUp
} ,
94 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
97 { kEventClassWindow
, kEventWindowShown
} ,
98 { kEventClassWindow
, kEventWindowActivated
} ,
99 { kEventClassWindow
, kEventWindowDeactivated
} ,
100 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
101 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
102 { kEventClassWindow
, kEventWindowClose
} ,
104 // we have to catch these events on the toplevel window level, as controls don't get the
105 // raw mouse events anymore
107 { kEventClassMouse
, kEventMouseDown
} ,
108 { kEventClassMouse
, kEventMouseUp
} ,
109 { kEventClassMouse
, kEventMouseWheelMoved
} ,
110 { kEventClassMouse
, kEventMouseMoved
} ,
111 { kEventClassMouse
, kEventMouseDragged
} ,
114 static pascal OSStatus
TextInputEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
116 OSStatus result
= eventNotHandledErr
;
118 wxWindow
* focus
= wxWindow::FindFocus() ;
119 unsigned char charCode
;
126 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent
) ;
128 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
,sizeof(char), NULL
,&charCode
);
129 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
130 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
131 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
132 sizeof( Point
), NULL
, &point
);
134 switch ( GetEventKind( event
) )
136 case kEventTextInputUnicodeForKeyEvent
:
137 // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not
138 // get its own kEventTextInputUnicodeForKeyEvent, so we route back the
139 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
142 ControlRef macControl
= (ControlRef
) control
->GetHandle() ;
145 ::HandleControlKey( macControl
, keyCode
, charCode
, modifiers
) ;
150 // this may lead to double events sent to a window in case all handlers have skipped the key down event
151 UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
152 UInt32 message = (keyCode << 8) + charCode;
154 if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent(
155 focus , message , modifiers , when , point.h , point.v ) )
166 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
168 OSStatus result
= eventNotHandledErr
;
169 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
170 // FindFocus does not return the actual focus window,but the enclosing window
171 wxWindow
* focus
= wxWindow::DoFindFocus();
175 unsigned char charCode
;
180 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
183 UInt32 dataSize
= 0 ;
184 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
188 UniChar
* charBuf
= buf
;
191 charBuf
= new UniChar
[ dataSize
/ sizeof( UniChar
) ] ;
192 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
193 #if SIZEOF_WCHAR_T == 2
194 uniChar
= charBuf
[0] ;
196 wxMBConvUTF16 converter
;
197 converter
.MB2WC( &uniChar
, (const char*)charBuf
, 1 ) ;
204 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
,sizeof(char), NULL
,&charCode
);
205 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
206 GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
207 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
208 sizeof( Point
), NULL
, &point
);
210 UInt32 message
= (keyCode
<< 8) + charCode
;
211 switch( GetEventKind( event
) )
213 case kEventRawKeyRepeat
:
214 case kEventRawKeyDown
:
216 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
217 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
218 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
219 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
220 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
) )
224 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
227 case kEventRawKeyUp
:
228 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
229 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
) )
234 case kEventRawKeyModifiersChanged
:
236 wxKeyEvent
event(wxEVT_KEY_DOWN
);
238 event
.m_shiftDown
= modifiers
& shiftKey
;
239 event
.m_controlDown
= modifiers
& controlKey
;
240 event
.m_altDown
= modifiers
& optionKey
;
241 event
.m_metaDown
= modifiers
& cmdKey
;
243 event
.m_uniChar
= uniChar
;
247 event
.SetTimestamp(when
);
248 event
.SetEventObject(focus
);
250 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
252 event
.m_keyCode
= WXK_CONTROL
;
253 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
254 focus
->GetEventHandler()->ProcessEvent( event
) ;
256 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
258 event
.m_keyCode
= WXK_SHIFT
;
259 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
260 focus
->GetEventHandler()->ProcessEvent( event
) ;
262 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
264 event
.m_keyCode
= WXK_ALT
;
265 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
266 focus
->GetEventHandler()->ProcessEvent( event
) ;
268 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
270 event
.m_keyCode
= WXK_COMMAND
;
271 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
272 focus
->GetEventHandler()->ProcessEvent( event
) ;
274 wxApp::s_lastModifiers
= modifiers
;
282 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
283 // for windows that we didn't create (like eg Scrollbars in a databrowser) , or for controls where we did not handle the
286 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
288 wxWindow
* g_MacLastWindow
= NULL
;
290 static EventMouseButton lastButton
= 0 ;
292 static void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
294 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
295 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
297 // this parameter are not given for all events
298 EventMouseButton button
= 0 ;
299 UInt32 clickCount
= 0 ;
300 cEvent
.GetParameter
<EventMouseButton
>(kEventParamMouseButton
, typeMouseButton
, &button
) ;
301 cEvent
.GetParameter
<UInt32
>(kEventParamClickCount
, typeUInt32
, &clickCount
) ;
303 wxevent
.m_x
= screenMouseLocation
.h
;
304 wxevent
.m_y
= screenMouseLocation
.v
;
305 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
306 wxevent
.m_controlDown
= modifiers
& controlKey
;
307 wxevent
.m_altDown
= modifiers
& optionKey
;
308 wxevent
.m_metaDown
= modifiers
& cmdKey
;
309 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
310 // a control click is interpreted as a right click
311 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
313 button
= kEventMouseButtonSecondary
;
316 // otherwise we report double clicks by connecting a left click with a ctrl-left click
317 if ( clickCount
> 1 && button
!= lastButton
)
320 // we must make sure that our synthetic 'right' button corresponds in
321 // mouse down, moved and mouse up, and does not deliver a right down and left up
323 if ( cEvent
.GetKind() == kEventMouseDown
)
324 lastButton
= button
;
328 else if ( lastButton
)
329 button
= lastButton
;
331 // determinate the correct down state, wx does not want a 'down' for a mouseUp event, while mac delivers
333 if ( button
!= 0 && cEvent
.GetKind() != kEventMouseUp
)
337 case kEventMouseButtonPrimary
:
338 wxevent
.m_leftDown
= true ;
340 case kEventMouseButtonSecondary
:
341 wxevent
.m_rightDown
= true ;
343 case kEventMouseButtonTertiary
:
344 wxevent
.m_middleDown
= true ;
348 // translate into wx types
349 switch ( cEvent
.GetKind() )
351 case kEventMouseDown
:
354 case kEventMouseButtonPrimary
:
355 wxevent
.SetEventType(clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
357 case kEventMouseButtonSecondary
:
358 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
360 case kEventMouseButtonTertiary
:
361 wxevent
.SetEventType(clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
368 case kEventMouseButtonPrimary
:
369 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
371 case kEventMouseButtonSecondary
:
372 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
374 case kEventMouseButtonTertiary
:
375 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
379 case kEventMouseWheelMoved
:
381 wxevent
.SetEventType(wxEVT_MOUSEWHEEL
) ;
383 // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
384 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeLongInteger
) ;
386 wxevent
.m_wheelRotation
= delta
;
387 wxevent
.m_wheelDelta
= 1;
388 wxevent
.m_linesPerAction
= 1;
392 wxevent
.SetEventType(wxEVT_MOTION
) ;
397 ControlRef
wxMacFindSubControl( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, ControlRef superControl
, ControlPartCode
*outPart
)
401 UInt16 childrenCount
= 0 ;
402 OSStatus err
= CountSubControls( superControl
, &childrenCount
) ;
403 if ( err
== errControlIsNotEmbedder
)
405 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
407 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
409 ControlHandle sibling
;
410 err
= GetIndexedSubControl( superControl
, i
, & sibling
) ;
411 if ( err
== errControlIsNotEmbedder
)
414 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
415 if ( IsControlVisible( sibling
) )
418 UMAGetControlBoundsInWindowCoords( sibling
, &r
) ;
419 if ( MacPtInRect( location
, &r
) )
421 ControlHandle child
= wxMacFindSubControl( toplevelWindow
, location
, sibling
, outPart
) ;
426 Point testLocation
= location
;
428 if ( toplevelWindow
&& toplevelWindow
->MacUsesCompositing() )
430 testLocation
.h
-= r
.left
;
431 testLocation
.v
-= r
.top
;
434 *outPart
= TestControl( sibling
, testLocation
) ;
444 ControlRef
wxMacFindControlUnderMouse( wxTopLevelWindowMac
* toplevelWindow
, const Point
& location
, WindowRef window
, ControlPartCode
*outPart
)
446 #if TARGET_API_MAC_OSX
447 if ( UMAGetSystemVersion() >= 0x1030 && ( toplevelWindow
== 0 || toplevelWindow
->MacUsesCompositing() ) )
448 return FindControlUnderMouse( location
, window
, outPart
) ;
450 ControlRef rootControl
= NULL
;
451 verify_noerr( GetRootControl( window
, &rootControl
) ) ;
452 return wxMacFindSubControl( toplevelWindow
, location
, rootControl
, outPart
) ;
456 #define NEW_CAPTURE_HANDLING 1
458 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
460 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
462 OSStatus result
= eventNotHandledErr
;
464 wxMacCarbonEvent
cEvent( event
) ;
466 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
467 Point windowMouseLocation
= screenMouseLocation
;
470 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
472 wxWindow
* currentMouseWindow
= NULL
;
473 ControlRef control
= NULL
;
475 #if NEW_CAPTURE_HANDLING
476 if ( wxApp::s_captureWindow
)
478 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
479 windowPart
= inContent
;
485 QDGlobalToLocalPoint( UMAGetWindowPort(window
) , &windowMouseLocation
) ;
487 if ( wxApp::s_captureWindow
488 #if !NEW_CAPTURE_HANDLING
489 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
493 currentMouseWindow
= wxApp::s_captureWindow
;
495 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
497 ControlPartCode part
;
498 control
= wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &part
) ;
499 // if there is no control below the mouse position, send the event to the toplevel window itself
501 currentMouseWindow
= (wxWindow
*) data
;
504 currentMouseWindow
= wxFindControlFromMacControl( control
) ;
505 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
508 // for wxToolBar to function we have to send certaint events to it
509 // instead of its children (wxToolBarTools)
511 GetSuperControl(control
, &parent
);
512 wxWindow
*wxParent
= wxFindControlFromMacControl( parent
) ;
513 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
514 currentMouseWindow
= wxParent
;
521 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
522 SetupMouseEvent( wxevent
, cEvent
) ;
524 // handle all enter / leave events
526 if ( currentMouseWindow
!= g_MacLastWindow
)
528 if ( g_MacLastWindow
)
530 wxMouseEvent
eventleave(wxevent
);
531 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
532 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
533 eventleave
.SetEventObject( g_MacLastWindow
) ;
534 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
536 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
537 #endif // wxUSE_TOOLTIPS
538 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
540 if ( currentMouseWindow
)
542 wxMouseEvent
evententer(wxevent
);
543 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
544 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
545 evententer
.SetEventObject( currentMouseWindow
) ;
546 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
548 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
549 #endif // wxUSE_TOOLTIPS
550 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
552 g_MacLastWindow
= currentMouseWindow
;
555 if ( windowPart
== inMenuBar
)
557 // special case menu bar, as we are having a low-level runloop we must do it ourselves
558 if ( cEvent
.GetKind() == kEventMouseDown
)
560 ::MenuSelect( screenMouseLocation
) ;
563 } // if ( windowPart == inMenuBar )
564 else if ( currentMouseWindow
)
566 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
568 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
570 wxevent
.SetEventObject( currentMouseWindow
) ;
571 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
573 // make tooltips current
576 if ( wxevent
.GetEventType() == wxEVT_MOTION
577 || wxevent
.GetEventType() == wxEVT_ENTER_WINDOW
578 || wxevent
.GetEventType() == wxEVT_LEAVE_WINDOW
)
579 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
580 #endif // wxUSE_TOOLTIPS
581 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
583 if ((currentMouseWindowParent
!= NULL
) &&
584 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
585 currentMouseWindow
= NULL
;
591 // if the user code did _not_ handle the event, then perform the
592 // default processing
593 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
595 // ... that is set focus to this window
596 if (currentMouseWindow
->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
597 currentMouseWindow
->SetFocus();
600 ControlPartCode dummyPart
;
601 // if built-in find control is finding the wrong control (ie static box instead of overlaid
602 // button, we cannot let the standard handler do its job, but must handle manually
604 if ( ( cEvent
.GetKind() == kEventMouseDown
)
607 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
608 wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &dummyPart
) )
612 if ( currentMouseWindow
->MacIsReallyEnabled() )
614 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
615 Point clickLocation
= windowMouseLocation
;
617 if ( toplevelWindow
->MacUsesCompositing() )
618 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
620 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
621 modifiers
, (ControlActionUPP
) -1 ) ;
623 if ((currentMouseWindowParent
!= NULL
) &&
624 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
625 currentMouseWindow
= NULL
;
630 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
632 wxApp::s_captureWindow
= NULL
;
638 wxWindow
* cursorTarget
= currentMouseWindow
;
639 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
641 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
643 cursorTarget
= cursorTarget
->GetParent() ;
645 cursorPoint
+= cursorTarget
->GetPosition();
648 } // else if ( currentMouseWindow )
651 // don't mess with controls we don't know about
652 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
653 // so we try sending them the correct control directly
654 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
656 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
657 Point clickLocation
= windowMouseLocation
;
658 if ( toplevelWindow
->MacUsesCompositing() )
662 hiPoint
.x
= clickLocation
.h
;
663 hiPoint
.y
= clickLocation
.v
;
664 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
665 clickLocation
.h
= (int)hiPoint
.x
;
666 clickLocation
.v
= (int)hiPoint
.y
;
669 HandleControlClick( control
, clickLocation
,
670 modifiers
, (ControlActionUPP
) -1 ) ;
677 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
679 OSStatus result
= eventNotHandledErr
;
681 wxMacCarbonEvent
cEvent( event
) ;
683 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
684 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
686 switch( GetEventKind( event
) )
688 case kEventWindowActivated
:
690 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
691 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
692 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
693 wxevent
.SetEventObject(toplevelWindow
);
694 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
695 // we still sending an eventNotHandledErr in order to allow for default processing
698 case kEventWindowDeactivated
:
700 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
701 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
702 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
703 wxevent
.SetEventObject(toplevelWindow
);
704 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
705 // we still sending an eventNotHandledErr in order to allow for default processing
708 case kEventWindowShown
:
710 toplevelWindow
->Refresh() ;
714 case kEventWindowClose
:
715 toplevelWindow
->Close() ;
718 case kEventWindowBoundsChanged
:
720 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
721 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
722 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
723 if ( attributes
& kWindowBoundsChangeSizeChanged
)
725 // according to the other ports we handle this within the OS level
726 // resize event, not within a wxSizeEvent
727 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
731 frame
->PositionStatusBar();
734 frame
->PositionToolBar();
738 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
739 event
.SetEventObject( toplevelWindow
) ;
741 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
742 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
744 if ( attributes
& kWindowBoundsChangeOriginChanged
)
746 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
747 event
.SetEventObject( toplevelWindow
) ;
748 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
753 case kEventWindowBoundsChanging
:
755 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
756 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
758 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
760 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
761 int left
, top
, right
, bottom
;
762 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
763 wxRect
r( newRect
.left
- left
, newRect
.top
- top
,
764 newRect
.right
- newRect
.left
+ left
+ right
, newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
765 // this is a EVT_SIZING not a EVT_SIZE type !
766 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
767 wxevent
.SetEventObject( toplevelWindow
) ;
769 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
770 adjustR
= wxevent
.GetRect() ;
772 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
773 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
774 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
775 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
776 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
777 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
778 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
779 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
780 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
781 if ( !EqualRect( &newRect
, &adjustedRect
) )
782 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
783 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
795 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
797 OSStatus result
= eventNotHandledErr
;
799 switch ( GetEventClass( event
) )
801 case kEventClassKeyboard
:
802 result
= KeyboardEventHandler( handler
, event
, data
) ;
804 case kEventClassTextInput
:
805 result
= TextInputEventHandler( handler
, event
, data
) ;
807 case kEventClassWindow
:
808 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
810 case kEventClassMouse
:
811 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
819 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
821 // ---------------------------------------------------------------------------
822 // wxWindowMac utility functions
823 // ---------------------------------------------------------------------------
825 // Find an item given the Macintosh Window Reference
827 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
829 static MacWindowMap wxWinMacWindowList
;
831 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
833 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
835 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
838 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
839 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
841 // adding NULL WindowRef is (first) surely a result of an error and
843 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
845 wxWinMacWindowList
[inWindowRef
] = win
;
848 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
849 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
851 MacWindowMap::iterator it
;
852 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
854 if ( it
->second
== win
)
856 wxWinMacWindowList
.erase(it
);
862 // ----------------------------------------------------------------------------
863 // wxTopLevelWindowMac creation
864 // ----------------------------------------------------------------------------
866 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
874 void wxTopLevelWindowMac::Init()
877 m_maximizeOnShow
= false;
879 #if TARGET_API_MAC_OSX
880 if ( UMAGetSystemVersion() >= 0x1030 )
882 m_macUsesCompositing
= true;
887 m_macUsesCompositing
= false;
889 m_macEventHandler
= NULL
;
890 m_macFullScreenData
= NULL
;
893 class wxMacDeferredWindowDeleter
: public wxObject
896 wxMacDeferredWindowDeleter( WindowRef windowRef
)
898 m_macWindow
= windowRef
;
900 virtual ~wxMacDeferredWindowDeleter()
902 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
905 WindowRef m_macWindow
;
908 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
910 const wxString
& title
,
914 const wxString
& name
)
919 m_windowStyle
= style
;
923 m_windowId
= id
== -1 ? NewControlId() : id
;
924 wxWindow::SetLabel( title
) ;
926 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
928 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
930 if (GetExtraStyle() & wxFRAME_EX_METAL
)
931 MacSetMetalAppearance(true);
933 wxTopLevelWindows
.Append(this);
936 parent
->AddChild(this);
941 wxTopLevelWindowMac::~wxTopLevelWindowMac()
946 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
948 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
951 if ( m_macEventHandler
)
953 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
954 m_macEventHandler
= NULL
;
957 wxRemoveMacWindowAssociation( this ) ;
959 if ( wxModelessWindows
.Find(this) )
960 wxModelessWindows
.DeleteObject(this);
962 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
964 m_macFullScreenData
= NULL
;
968 // ----------------------------------------------------------------------------
969 // wxTopLevelWindowMac maximize/minimize
970 // ----------------------------------------------------------------------------
972 void wxTopLevelWindowMac::Maximize(bool maximize
)
974 // TODO Check, is this still necessary
976 wxMacPortStateHelper
help( (GrafPtr
) GetWindowPort( (WindowRef
) m_macWindow
) ) ;
977 wxMacWindowClipper
clip (this);
979 if ( !IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) )
982 GetWindowBounds((WindowRef
)m_macWindow
, kWindowGlobalPortRgn
, &rect
);
983 SetWindowIdealUserState((WindowRef
)m_macWindow
, &rect
);
984 SetWindowUserState((WindowRef
)m_macWindow
, &rect
);
986 ZoomWindow( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, false ) ;
989 bool wxTopLevelWindowMac::IsMaximized() const
991 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
994 void wxTopLevelWindowMac::Iconize(bool iconize
)
996 if ( IsWindowCollapsable((WindowRef
)m_macWindow
) )
997 CollapseWindow((WindowRef
)m_macWindow
, iconize
) ;
1000 bool wxTopLevelWindowMac::IsIconized() const
1002 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1005 void wxTopLevelWindowMac::Restore()
1007 if ( IsMaximized() )
1009 else if ( IsIconized() )
1013 // ----------------------------------------------------------------------------
1014 // wxTopLevelWindowMac misc
1015 // ----------------------------------------------------------------------------
1017 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1019 return wxPoint(0,0) ;
1022 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
1025 wxTopLevelWindowBase::SetIcon(icon
);
1028 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1030 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1032 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1034 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1038 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1040 if ( m_macEventHandler
!= NULL
)
1042 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1044 InstallWindowEventHandler(MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1045 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1048 void wxTopLevelWindowMac::MacCreateRealWindow( const wxString
& title
,
1052 const wxString
& name
)
1054 OSStatus err
= noErr
;
1056 m_windowStyle
= style
;
1066 wxRect display
= wxGetClientDisplayRect() ;
1068 if ( x
== wxDefaultPosition
.x
)
1071 if ( y
== wxDefaultPosition
.y
)
1074 int w
= WidthDefault(size
.x
);
1075 int h
= HeightDefault(size
.y
);
1077 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1079 // translate the window attributes in the appropriate window class and attributes
1081 WindowClass wclass
= 0;
1082 WindowAttributes attr
= kWindowNoAttributes
;
1083 WindowGroupRef group
= NULL
;
1085 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1088 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1089 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1090 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1093 wclass
= kFloatingWindowClass
;
1094 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1096 attr
|= kWindowSideTitlebarAttribute
;
1101 wclass
= kPlainWindowClass
;
1104 else if ( HasFlag( wxCAPTION
) )
1106 wclass
= kDocumentWindowClass
;
1107 attr
|= kWindowInWindowMenuAttribute
;
1109 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1110 else if ( HasFlag( wxFRAME_DRAWER
) )
1112 wclass
= kDrawerWindowClass
;
1113 // we must force compositing on a drawer
1114 m_macUsesCompositing
= true ;
1116 #endif //10.2 and up
1119 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1120 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1122 wclass
= kDocumentWindowClass
;
1126 wclass
= kPlainWindowClass
;
1130 if ( HasFlag( wxMINIMIZE_BOX
) && wclass
!= kPlainWindowClass
)
1132 attr
|= kWindowCollapseBoxAttribute
;
1134 if ( HasFlag( wxMAXIMIZE_BOX
) && wclass
!= kPlainWindowClass
)
1136 attr
|= kWindowFullZoomAttribute
;
1138 if ( HasFlag( wxRESIZE_BORDER
) && wclass
!= kPlainWindowClass
)
1140 attr
|= kWindowResizableAttribute
;
1142 if ( HasFlag( wxCLOSE_BOX
) && wclass
!= kPlainWindowClass
)
1144 attr
|= kWindowCloseBoxAttribute
;
1147 if (UMAGetSystemVersion() >= 0x1000)
1149 // turn on live resizing (OS X only)
1150 attr
|= kWindowLiveResizeAttribute
;
1153 if ( HasFlag(wxSTAY_ON_TOP
) )
1155 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1158 #if TARGET_API_MAC_OSX
1159 if ( m_macUsesCompositing
)
1160 attr
|= kWindowCompositingAttribute
;
1163 if ( HasFlag(wxFRAME_SHAPED
) )
1165 WindowDefSpec customWindowDefSpec
;
1166 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1167 customWindowDefSpec
.u
.defProc
= NewWindowDefUPP(wxShapedMacWindowDef
);
1169 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1170 attr
, &theBoundsRect
,
1171 (WindowRef
*) &m_macWindow
);
1175 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1178 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1179 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1181 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1183 // the create commands are only for content rect, so we have to set the size again as
1185 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1187 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1188 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1189 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1190 #if TARGET_API_MAC_OSX
1192 if ( m_macUsesCompositing
)
1194 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1195 // the content view, so we have to retrieve it explicitly
1196 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1197 m_peer
->GetControlRefAddr() ) ;
1198 if ( !m_peer
->Ok() )
1200 // compatibility mode fallback
1201 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1206 ::CreateRootControl( (WindowRef
)m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1208 // the root control level handleer
1209 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1211 // the frame window event handler
1212 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1213 MacInstallTopLevelWindowEventHandler() ;
1215 DoSetWindowVariant( m_windowVariant
) ;
1219 if ( HasFlag(wxFRAME_SHAPED
) )
1221 // default shape matches the window size
1222 wxRegion
rgn(0, 0, w
, h
);
1226 wxWindowCreateEvent
event(this);
1227 GetEventHandler()->ProcessEvent(event
);
1230 void wxTopLevelWindowMac::ClearBackground()
1232 wxWindow::ClearBackground() ;
1235 // Raise the window to the top of the Z order
1236 void wxTopLevelWindowMac::Raise()
1238 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1241 // Lower the window to the bottom of the Z order
1242 void wxTopLevelWindowMac::Lower()
1244 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1248 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1250 if(s_macDeactivateWindow
)
1252 wxLogTrace(TRACE_ACTIVATE
,
1253 wxT("Doing delayed deactivation of %p"),
1254 s_macDeactivateWindow
);
1255 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1259 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1261 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1263 if(s_macDeactivateWindow
==this)
1264 s_macDeactivateWindow
=NULL
;
1265 MacDelayedDeactivation(timestamp
);
1266 MacPropagateHiliteChanged() ;
1269 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1271 wxWindow::SetLabel( title
) ;
1272 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1275 wxString
wxTopLevelWindowMac::GetTitle() const
1277 return wxWindow::GetLabel();
1280 bool wxTopLevelWindowMac::Show(bool show
)
1282 if ( !wxTopLevelWindowBase::Show(show
) )
1287 #if wxUSE_SYSTEM_OPTIONS //code contributed by Ryan Wilcox December 18, 2003
1288 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1290 ::ShowWindow( (WindowRef
)m_macWindow
);
1295 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowShowTransitionAction
,nil
);
1297 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1298 // as apps expect a size event to occur at this moment
1299 wxSizeEvent
event( GetSize() , m_windowId
);
1300 event
.SetEventObject(this);
1301 GetEventHandler()->ProcessEvent(event
);
1305 #if wxUSE_SYSTEM_OPTIONS
1306 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1308 ::HideWindow((WindowRef
) m_macWindow
);
1313 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowHideTransitionAction
,nil
);
1317 MacPropagateVisibilityChanged() ;
1322 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1326 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1328 data
= new FullScreenData() ;
1330 m_macFullScreenData
= data
;
1331 data
->m_position
= GetPosition() ;
1332 data
->m_size
= GetSize() ;
1334 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1338 int left
, top
, right
, bottom
;
1339 wxRect client
= wxGetClientDisplayRect() ;
1348 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1350 if ( style
& wxFULLSCREEN_NOCAPTION
)
1355 if ( style
& wxFULLSCREEN_NOBORDER
)
1361 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1365 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1369 SetSize( x
, y
, w
, h
) ;
1374 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1375 SetPosition( data
->m_position
) ;
1376 SetSize( data
->m_size
) ;
1378 m_macFullScreenData
= NULL
;
1383 bool wxTopLevelWindowMac::IsFullScreen() const
1385 return m_macFullScreenData
!= NULL
;
1388 // we are still using coordinates of the content view, todo switch to structure bounds
1390 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1394 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1395 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1397 left
= content
.left
- structure
.left
;
1398 top
= content
.top
- structure
.top
;
1399 right
= structure
.right
- content
.right
;
1400 bottom
= structure
.bottom
- content
.bottom
;
1403 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1405 m_cachedClippedRectValid
= false ;
1406 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1407 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1408 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1411 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1414 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1415 if(x
) *x
= bounds
.left
;
1416 if(y
) *y
= bounds
.top
;
1418 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1421 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1422 if(width
) *width
= bounds
.right
- bounds
.left
;
1423 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1426 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1429 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1430 if(width
) *width
= bounds
.right
- bounds
.left
;
1431 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1434 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1436 #if TARGET_API_MAC_OSX
1437 wxASSERT_MSG( m_macUsesCompositing
,
1438 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1440 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1441 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1445 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1447 #if TARGET_API_MAC_OSX
1448 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1454 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1456 ChangeWindowAttributes ( (WindowRef
) m_macWindow
, attributesToSet
, attributesToClear
) ;
1459 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1462 GetWindowAttributes((WindowRef
) m_macWindow
, &attr
) ;
1466 void wxTopLevelWindowMac::MacPerformUpdates()
1468 #if TARGET_API_MAC_OSX
1469 if ( m_macUsesCompositing
)
1471 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1472 // for composited windows this also triggers a redraw of all
1473 // invalid views in the window
1474 if( UMAGetSystemVersion() >= 0x1030 )
1475 HIWindowFlush((WindowRef
) m_macWindow
) ;
1479 // the only way to trigger the redrawing on earlier systems is to call
1482 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1483 UInt32 currentEventClass
= 0 ;
1484 UInt32 currentEventKind
= 0 ;
1485 if ( currentEvent
!= NULL
)
1487 currentEventClass
= ::GetEventClass( currentEvent
) ;
1488 currentEventKind
= ::GetEventKind( currentEvent
) ;
1490 if ( currentEventClass
!= kEventClassMenu
)
1492 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1494 OSStatus status
= noErr
;
1495 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1502 BeginUpdate( (WindowRef
) m_macWindow
) ;
1504 RgnHandle updateRgn
= NewRgn();
1507 GetPortVisibleRegion( GetWindowPort( (WindowRef
)m_macWindow
), updateRgn
);
1508 UpdateControls( (WindowRef
)m_macWindow
, updateRgn
) ;
1509 // if ( !EmptyRgn( updateRgn ) )
1510 // MacDoRedraw( updateRgn , 0 , true) ;
1511 DisposeRgn( updateRgn
);
1513 EndUpdate( (WindowRef
)m_macWindow
) ;
1514 QDFlushPortBuffer( GetWindowPort( (WindowRef
)m_macWindow
) , NULL
) ;
1518 // Attracts the users attention to this window if the application is
1519 // inactive (should be called when a background event occurs)
1521 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1524 DisposePtr( (Ptr
) ptr
) ;
1528 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1530 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1531 static wxMacNMUPP
nmupp( wxMacNMResponse
)
1533 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1534 notificationRequest
->qType
= nmType
;
1535 notificationRequest
->nmMark
= 1 ;
1536 notificationRequest
->nmIcon
= 0 ;
1537 notificationRequest
->nmSound
= 0 ;
1538 notificationRequest
->nmStr
= NULL
;
1539 notificationRequest
->nmResp
= nmupp
;
1540 verify_noerr( NMInstall( notificationRequest
) ) ;
1543 // ---------------------------------------------------------------------------
1544 // Shape implementation
1545 // ---------------------------------------------------------------------------
1548 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1550 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1551 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1553 // The empty region signifies that the shape should be removed from the
1555 if ( region
.IsEmpty() )
1557 wxSize sz
= GetClientSize();
1558 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1559 if ( rgn
.IsEmpty() )
1562 return SetShape(rgn
);
1565 // Make a copy of the region
1566 RgnHandle shapeRegion
= NewRgn();
1567 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1569 // Dispose of any shape region we may already have
1570 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1574 // Save the region so we can use it later
1575 SetWRefCon((WindowRef
)MacGetWindowRef(), (SInt32
)shapeRegion
);
1577 // Tell the window manager that the window has changed shape
1578 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1582 // ---------------------------------------------------------------------------
1583 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1584 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1585 // ---------------------------------------------------------------------------
1587 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1589 GetWindowPortBounds(window
, inRect
);
1590 Point pt
= {inRect
->left
, inRect
->top
};
1591 QDLocalToGlobalPoint( GetWindowPort(window
) , &pt
) ;
1593 inRect
->left
= pt
.h
;
1594 inRect
->bottom
+= pt
.v
;
1595 inRect
->right
+= pt
.h
;
1599 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1601 /*------------------------------------------------------
1602 Define which options your custom window supports.
1603 --------------------------------------------------------*/
1604 //just enable everything for our demo
1605 *(OptionBits
*)param
=//kWindowCanGrow|
1607 //kWindowCanCollapse|
1608 //kWindowCanGetWindowRegion|
1609 //kWindowHasTitleBar|
1610 //kWindowSupportsDragHilite|
1611 kWindowCanDrawInCurrentPort
|
1612 //kWindowCanMeasureTitle|
1613 kWindowWantsDisposeAtProcessDeath
|
1614 kWindowSupportsGetGrowImageRegion
|
1615 kWindowDefSupportsColorGrafPort
;
1619 // The content region is left as a rectangle matching the window size, this is
1620 // so the origin in the paint event, and etc. still matches what the
1621 // programmer expects.
1622 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1625 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1629 wxShapedMacWindowGetPos(window
, &r
) ;
1630 RectRgn( rgn
, &r
) ;
1634 // The structure region is set to the shape given to the SetShape method.
1635 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1637 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1643 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1644 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1645 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1646 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1652 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1654 GetWindowRegionPtr rgnRec
=(GetWindowRegionPtr
)param
;
1656 switch(rgnRec
->regionCode
)
1658 case kWindowStructureRgn
:
1659 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1661 case kWindowContentRgn
:
1662 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1665 SetEmptyRgn(rgnRec
->winRgn
);
1672 static SInt32
wxShapedMacWindowHitTest(WindowRef window
,SInt32 param
)
1674 /*------------------------------------------------------
1675 Determine the region of the window which was hit
1676 --------------------------------------------------------*/
1678 static RgnHandle tempRgn
=nil
;
1683 SetPt(&hitPoint
,LoWord(param
),HiWord(param
));//get the point clicked
1685 //Mac OS 8.5 or later
1686 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1687 if (PtInRgn(hitPoint
, tempRgn
)) //in window content region?
1690 return wNoHit
;//no significant area was hit.
1694 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1698 case kWindowMsgHitTest
:
1699 return wxShapedMacWindowHitTest(window
,param
);
1701 case kWindowMsgGetFeatures
:
1702 return wxShapedMacWindowGetFeatures(window
,param
);
1704 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1705 case kWindowMsgGetRegion
:
1706 return wxShapedMacWindowGetRegion(window
,param
);
1712 // ---------------------------------------------------------------------------