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 // 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
) ;
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
) ;
547 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
548 #endif // wxUSE_TOOLTIPS
549 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
551 g_MacLastWindow
= currentMouseWindow
;
554 if ( windowPart
== inMenuBar
)
556 // special case menu bar, as we are having a low-level runloop we must do it ourselves
557 if ( cEvent
.GetKind() == kEventMouseDown
)
559 ::MenuSelect( screenMouseLocation
) ;
562 } // if ( windowPart == inMenuBar )
563 else if ( currentMouseWindow
)
565 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
567 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
569 wxevent
.SetEventObject( currentMouseWindow
) ;
571 // make tooltips current
574 if ( wxevent
.GetEventType() == wxEVT_MOTION
575 || wxevent
.GetEventType() == wxEVT_ENTER_WINDOW
576 || wxevent
.GetEventType() == wxEVT_LEAVE_WINDOW
)
577 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
578 #endif // wxUSE_TOOLTIPS
579 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
581 if ((currentMouseWindowParent
!= NULL
) &&
582 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
583 currentMouseWindow
= NULL
;
589 // if the user code did _not_ handle the event, then perform the
590 // default processing
591 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
593 // ... that is set focus to this window
594 if (currentMouseWindow
->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
595 currentMouseWindow
->SetFocus();
598 ControlPartCode dummyPart
;
599 // if built-in find control is finding the wrong control (ie static box instead of overlaid
600 // button, we cannot let the standard handler do its job, but must handle manually
602 if ( ( cEvent
.GetKind() == kEventMouseDown
)
605 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
606 wxMacFindControlUnderMouse( toplevelWindow
, windowMouseLocation
, window
, &dummyPart
) )
610 if ( currentMouseWindow
->MacIsReallyEnabled() )
612 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
613 Point clickLocation
= windowMouseLocation
;
615 if ( toplevelWindow
->MacUsesCompositing() )
616 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
618 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
619 modifiers
, (ControlActionUPP
) -1 ) ;
621 if ((currentMouseWindowParent
!= NULL
) &&
622 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
623 currentMouseWindow
= NULL
;
628 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
630 wxApp::s_captureWindow
= NULL
;
636 wxWindow
* cursorTarget
= currentMouseWindow
;
637 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
639 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
641 cursorTarget
= cursorTarget
->GetParent() ;
643 cursorPoint
+= cursorTarget
->GetPosition();
646 } // else if ( currentMouseWindow )
649 // don't mess with controls we don't know about
650 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
651 // so we try sending them the correct control directly
652 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
654 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
655 Point clickLocation
= windowMouseLocation
;
656 if ( toplevelWindow
->MacUsesCompositing() )
660 hiPoint
.x
= clickLocation
.h
;
661 hiPoint
.y
= clickLocation
.v
;
662 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
663 clickLocation
.h
= (int)hiPoint
.x
;
664 clickLocation
.v
= (int)hiPoint
.y
;
667 HandleControlClick( control
, clickLocation
,
668 modifiers
, (ControlActionUPP
) -1 ) ;
675 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
677 OSStatus result
= eventNotHandledErr
;
679 wxMacCarbonEvent
cEvent( event
) ;
681 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
682 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
684 switch( GetEventKind( event
) )
686 case kEventWindowActivated
:
688 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
689 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
690 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
691 wxevent
.SetEventObject(toplevelWindow
);
692 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
693 // we still sending an eventNotHandledErr in order to allow for default processing
696 case kEventWindowDeactivated
:
698 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
699 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
700 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
701 wxevent
.SetEventObject(toplevelWindow
);
702 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
703 // we still sending an eventNotHandledErr in order to allow for default processing
706 case kEventWindowShown
:
708 toplevelWindow
->Refresh() ;
712 case kEventWindowClose
:
713 toplevelWindow
->Close() ;
716 case kEventWindowBoundsChanged
:
718 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
719 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
720 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
721 if ( attributes
& kWindowBoundsChangeSizeChanged
)
723 // according to the other ports we handle this within the OS level
724 // resize event, not within a wxSizeEvent
725 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
729 frame
->PositionStatusBar();
732 frame
->PositionToolBar();
736 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
737 event
.SetEventObject( toplevelWindow
) ;
739 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
740 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
742 if ( attributes
& kWindowBoundsChangeOriginChanged
)
744 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
745 event
.SetEventObject( toplevelWindow
) ;
746 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
751 case kEventWindowBoundsChanging
:
753 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
754 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
756 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
758 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
759 int left
, top
, right
, bottom
;
760 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
761 wxRect
r( newRect
.left
- left
, newRect
.top
- top
,
762 newRect
.right
- newRect
.left
+ left
+ right
, newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
763 // this is a EVT_SIZING not a EVT_SIZE type !
764 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
765 wxevent
.SetEventObject( toplevelWindow
) ;
767 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
768 adjustR
= wxevent
.GetRect() ;
770 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
771 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
772 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
773 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
774 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
775 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
776 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
777 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
778 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
779 if ( !EqualRect( &newRect
, &adjustedRect
) )
780 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
781 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
793 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
795 OSStatus result
= eventNotHandledErr
;
797 switch ( GetEventClass( event
) )
799 case kEventClassKeyboard
:
800 result
= KeyboardEventHandler( handler
, event
, data
) ;
802 case kEventClassTextInput
:
803 result
= TextInputEventHandler( handler
, event
, data
) ;
805 case kEventClassWindow
:
806 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
808 case kEventClassMouse
:
809 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
817 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
819 // ---------------------------------------------------------------------------
820 // wxWindowMac utility functions
821 // ---------------------------------------------------------------------------
823 // Find an item given the Macintosh Window Reference
825 WX_DECLARE_HASH_MAP(WindowRef
, wxTopLevelWindowMac
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
827 static MacWindowMap wxWinMacWindowList
;
829 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
831 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
833 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
836 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
837 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
839 // adding NULL WindowRef is (first) surely a result of an error and
841 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
843 wxWinMacWindowList
[inWindowRef
] = win
;
846 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
847 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
849 MacWindowMap::iterator it
;
850 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
852 if ( it
->second
== win
)
854 wxWinMacWindowList
.erase(it
);
860 // ----------------------------------------------------------------------------
861 // wxTopLevelWindowMac creation
862 // ----------------------------------------------------------------------------
864 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
872 void wxTopLevelWindowMac::Init()
875 m_maximizeOnShow
= false;
877 #if TARGET_API_MAC_OSX
878 if ( UMAGetSystemVersion() >= 0x1030 )
880 m_macUsesCompositing
= true;
885 m_macUsesCompositing
= false;
887 m_macEventHandler
= NULL
;
888 m_macFullScreenData
= NULL
;
891 class wxMacDeferredWindowDeleter
: public wxObject
894 wxMacDeferredWindowDeleter( WindowRef windowRef
)
896 m_macWindow
= windowRef
;
898 virtual ~wxMacDeferredWindowDeleter()
900 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
903 WindowRef m_macWindow
;
906 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
908 const wxString
& title
,
912 const wxString
& name
)
917 m_windowStyle
= style
;
921 m_windowId
= id
== -1 ? NewControlId() : id
;
922 wxWindow::SetTitle( title
) ;
924 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
926 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
928 if (GetExtraStyle() & wxFRAME_EX_METAL
)
929 MacSetMetalAppearance(true);
931 wxTopLevelWindows
.Append(this);
934 parent
->AddChild(this);
939 wxTopLevelWindowMac::~wxTopLevelWindowMac()
944 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
946 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
949 if ( m_macEventHandler
)
951 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
952 m_macEventHandler
= NULL
;
955 wxRemoveMacWindowAssociation( this ) ;
957 if ( wxModelessWindows
.Find(this) )
958 wxModelessWindows
.DeleteObject(this);
960 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
962 m_macFullScreenData
= NULL
;
966 // ----------------------------------------------------------------------------
967 // wxTopLevelWindowMac maximize/minimize
968 // ----------------------------------------------------------------------------
970 void wxTopLevelWindowMac::Maximize(bool maximize
)
972 // TODO Check, is this still necessary
974 wxMacPortStateHelper
help( (GrafPtr
) GetWindowPort( (WindowRef
) m_macWindow
) ) ;
975 wxMacWindowClipper
clip (this);
977 if ( !IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) )
980 GetWindowBounds((WindowRef
)m_macWindow
, kWindowGlobalPortRgn
, &rect
);
981 SetWindowIdealUserState((WindowRef
)m_macWindow
, &rect
);
982 SetWindowUserState((WindowRef
)m_macWindow
, &rect
);
984 ZoomWindow( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, false ) ;
987 bool wxTopLevelWindowMac::IsMaximized() const
989 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
992 void wxTopLevelWindowMac::Iconize(bool iconize
)
994 if ( IsWindowCollapsable((WindowRef
)m_macWindow
) )
995 CollapseWindow((WindowRef
)m_macWindow
, iconize
) ;
998 bool wxTopLevelWindowMac::IsIconized() const
1000 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
1003 void wxTopLevelWindowMac::Restore()
1005 if ( IsMaximized() )
1007 else if ( IsIconized() )
1011 // ----------------------------------------------------------------------------
1012 // wxTopLevelWindowMac misc
1013 // ----------------------------------------------------------------------------
1015 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
1017 return wxPoint(0,0) ;
1020 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
1023 wxTopLevelWindowBase::SetIcon(icon
);
1026 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1028 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
1030 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
1032 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
1036 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
1038 if ( m_macEventHandler
!= NULL
)
1040 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1042 InstallWindowEventHandler(MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
1043 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
1046 void wxTopLevelWindowMac::MacCreateRealWindow( const wxString
& title
,
1050 const wxString
& name
)
1052 OSStatus err
= noErr
;
1054 m_windowStyle
= style
;
1064 wxRect display
= wxGetClientDisplayRect() ;
1066 if ( x
== wxDefaultPosition
.x
)
1069 if ( y
== wxDefaultPosition
.y
)
1072 int w
= WidthDefault(size
.x
);
1073 int h
= HeightDefault(size
.y
);
1075 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1077 // translate the window attributes in the appropriate window class and attributes
1079 WindowClass wclass
= 0;
1080 WindowAttributes attr
= kWindowNoAttributes
;
1081 WindowGroupRef group
= NULL
;
1083 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
1086 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1087 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
1088 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
1091 wclass
= kFloatingWindowClass
;
1092 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1094 attr
|= kWindowSideTitlebarAttribute
;
1099 wclass
= kPlainWindowClass
;
1102 else if ( HasFlag( wxCAPTION
) )
1104 wclass
= kDocumentWindowClass
;
1105 attr
|= kWindowInWindowMenuAttribute
;
1107 #if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )
1108 else if ( HasFlag( wxFRAME_DRAWER
) )
1110 wclass
= kDrawerWindowClass
;
1111 // we must force compositing on a drawer
1112 m_macUsesCompositing
= true ;
1114 #endif //10.2 and up
1117 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1118 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1120 wclass
= kDocumentWindowClass
;
1124 wclass
= kPlainWindowClass
;
1128 if ( HasFlag( wxMINIMIZE_BOX
) && wclass
!= kPlainWindowClass
)
1130 attr
|= kWindowCollapseBoxAttribute
;
1132 if ( HasFlag( wxMAXIMIZE_BOX
) && wclass
!= kPlainWindowClass
)
1134 attr
|= kWindowFullZoomAttribute
;
1136 if ( HasFlag( wxRESIZE_BORDER
) && wclass
!= kPlainWindowClass
)
1138 attr
|= kWindowResizableAttribute
;
1140 if ( HasFlag( wxCLOSE_BOX
) && wclass
!= kPlainWindowClass
)
1142 attr
|= kWindowCloseBoxAttribute
;
1145 if (UMAGetSystemVersion() >= 0x1000)
1147 // turn on live resizing (OS X only)
1148 attr
|= kWindowLiveResizeAttribute
;
1151 if ( HasFlag(wxSTAY_ON_TOP
) )
1153 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1156 #if TARGET_API_MAC_OSX
1157 if ( m_macUsesCompositing
)
1158 attr
|= kWindowCompositingAttribute
;
1161 if ( HasFlag(wxFRAME_SHAPED
) )
1163 WindowDefSpec customWindowDefSpec
;
1164 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1165 customWindowDefSpec
.u
.defProc
= NewWindowDefUPP(wxShapedMacWindowDef
);
1167 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1168 attr
, &theBoundsRect
,
1169 (WindowRef
*) &m_macWindow
);
1173 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1176 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1177 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1179 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1181 // the create commands are only for content rect, so we have to set the size again as
1183 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1185 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1186 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1187 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1188 #if TARGET_API_MAC_OSX
1190 if ( m_macUsesCompositing
)
1192 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1193 // the content view, so we have to retrieve it explicitly
1194 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1195 m_peer
->GetControlRefAddr() ) ;
1196 if ( !m_peer
->Ok() )
1198 // compatibility mode fallback
1199 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1204 ::CreateRootControl( (WindowRef
)m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1206 // the root control level handleer
1207 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1209 // the frame window event handler
1210 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1211 MacInstallTopLevelWindowEventHandler() ;
1213 DoSetWindowVariant( m_windowVariant
) ;
1217 if ( HasFlag(wxFRAME_SHAPED
) )
1219 // default shape matches the window size
1220 wxRegion
rgn(0, 0, w
, h
);
1224 wxWindowCreateEvent
event(this);
1225 GetEventHandler()->ProcessEvent(event
);
1228 void wxTopLevelWindowMac::ClearBackground()
1230 wxWindow::ClearBackground() ;
1233 // Raise the window to the top of the Z order
1234 void wxTopLevelWindowMac::Raise()
1236 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1239 // Lower the window to the bottom of the Z order
1240 void wxTopLevelWindowMac::Lower()
1242 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1246 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1248 if(s_macDeactivateWindow
)
1250 wxLogTrace(TRACE_ACTIVATE
,
1251 wxT("Doing delayed deactivation of %p"),
1252 s_macDeactivateWindow
);
1253 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1257 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1259 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1261 if(s_macDeactivateWindow
==this)
1262 s_macDeactivateWindow
=NULL
;
1263 MacDelayedDeactivation(timestamp
);
1264 MacPropagateHiliteChanged() ;
1267 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1269 wxWindow::SetTitle( title
) ;
1270 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1273 bool wxTopLevelWindowMac::Show(bool show
)
1275 if ( !wxTopLevelWindowBase::Show(show
) )
1280 #if wxUSE_SYSTEM_OPTIONS //code contributed by Ryan Wilcox December 18, 2003
1281 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1283 ::ShowWindow( (WindowRef
)m_macWindow
);
1288 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowShowTransitionAction
,nil
);
1290 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1291 // as apps expect a size event to occur at this moment
1292 wxSizeEvent
event( GetSize() , m_windowId
);
1293 event
.SetEventObject(this);
1294 GetEventHandler()->ProcessEvent(event
);
1298 #if wxUSE_SYSTEM_OPTIONS
1299 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1301 ::HideWindow((WindowRef
) m_macWindow
);
1306 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowHideTransitionAction
,nil
);
1310 MacPropagateVisibilityChanged() ;
1315 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1319 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1321 data
= new FullScreenData() ;
1323 m_macFullScreenData
= data
;
1324 data
->m_position
= GetPosition() ;
1325 data
->m_size
= GetSize() ;
1327 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1331 int left
, top
, right
, bottom
;
1332 wxRect client
= wxGetClientDisplayRect() ;
1341 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1343 if ( style
& wxFULLSCREEN_NOCAPTION
)
1348 if ( style
& wxFULLSCREEN_NOBORDER
)
1354 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1358 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1362 SetSize( x
, y
, w
, h
) ;
1367 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1368 SetPosition( data
->m_position
) ;
1369 SetSize( data
->m_size
) ;
1371 m_macFullScreenData
= NULL
;
1376 bool wxTopLevelWindowMac::IsFullScreen() const
1378 return m_macFullScreenData
!= NULL
;
1381 // we are still using coordinates of the content view, todo switch to structure bounds
1383 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1387 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1388 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1390 left
= content
.left
- structure
.left
;
1391 top
= content
.top
- structure
.top
;
1392 right
= structure
.right
- content
.right
;
1393 bottom
= structure
.bottom
- content
.bottom
;
1396 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1398 m_cachedClippedRectValid
= false ;
1399 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1400 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1401 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1404 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1407 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1408 if(x
) *x
= bounds
.left
;
1409 if(y
) *y
= bounds
.top
;
1411 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1414 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1415 if(width
) *width
= bounds
.right
- bounds
.left
;
1416 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1419 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1422 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1423 if(width
) *width
= bounds
.right
- bounds
.left
;
1424 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1427 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1429 #if TARGET_API_MAC_OSX
1430 wxASSERT_MSG( m_macUsesCompositing
,
1431 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1433 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1434 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1438 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1440 #if TARGET_API_MAC_OSX
1441 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1447 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1449 ChangeWindowAttributes ( (WindowRef
) m_macWindow
, attributesToSet
, attributesToClear
) ;
1452 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1455 GetWindowAttributes((WindowRef
) m_macWindow
, &attr
) ;
1459 void wxTopLevelWindowMac::MacPerformUpdates()
1461 #if TARGET_API_MAC_OSX
1462 if ( m_macUsesCompositing
)
1464 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
1465 // for composited windows this also triggers a redraw of all
1466 // invalid views in the window
1467 if( UMAGetSystemVersion() >= 0x1030 )
1468 HIWindowFlush((WindowRef
) m_macWindow
) ;
1472 // the only way to trigger the redrawing on earlier systems is to call
1475 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
1476 UInt32 currentEventClass
= 0 ;
1477 UInt32 currentEventKind
= 0 ;
1478 if ( currentEvent
!= NULL
)
1480 currentEventClass
= ::GetEventClass( currentEvent
) ;
1481 currentEventKind
= ::GetEventKind( currentEvent
) ;
1483 if ( currentEventClass
!= kEventClassMenu
)
1485 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
1487 OSStatus status
= noErr
;
1488 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
1495 BeginUpdate( (WindowRef
) m_macWindow
) ;
1497 RgnHandle updateRgn
= NewRgn();
1500 GetPortVisibleRegion( GetWindowPort( (WindowRef
)m_macWindow
), updateRgn
);
1501 UpdateControls( (WindowRef
)m_macWindow
, updateRgn
) ;
1502 // if ( !EmptyRgn( updateRgn ) )
1503 // MacDoRedraw( updateRgn , 0 , true) ;
1504 DisposeRgn( updateRgn
);
1506 EndUpdate( (WindowRef
)m_macWindow
) ;
1507 QDFlushPortBuffer( GetWindowPort( (WindowRef
)m_macWindow
) , NULL
) ;
1511 // Attracts the users attention to this window if the application is
1512 // inactive (should be called when a background event occurs)
1514 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1517 DisposePtr( (Ptr
) ptr
) ;
1521 void wxTopLevelWindowMac::RequestUserAttention(int flags
)
1523 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1524 static wxMacNMUPP
nmupp( wxMacNMResponse
)
1526 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1527 notificationRequest
->qType
= nmType
;
1528 notificationRequest
->nmMark
= 1 ;
1529 notificationRequest
->nmIcon
= 0 ;
1530 notificationRequest
->nmSound
= 0 ;
1531 notificationRequest
->nmStr
= NULL
;
1532 notificationRequest
->nmResp
= nmupp
;
1533 verify_noerr( NMInstall( notificationRequest
) ) ;
1536 // ---------------------------------------------------------------------------
1537 // Shape implementation
1538 // ---------------------------------------------------------------------------
1541 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1543 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1544 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1546 // The empty region signifies that the shape should be removed from the
1548 if ( region
.IsEmpty() )
1550 wxSize sz
= GetClientSize();
1551 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1552 if ( rgn
.IsEmpty() )
1555 return SetShape(rgn
);
1558 // Make a copy of the region
1559 RgnHandle shapeRegion
= NewRgn();
1560 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1562 // Dispose of any shape region we may already have
1563 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1567 // Save the region so we can use it later
1568 SetWRefCon((WindowRef
)MacGetWindowRef(), (SInt32
)shapeRegion
);
1570 // Tell the window manager that the window has changed shape
1571 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1575 // ---------------------------------------------------------------------------
1576 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1577 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1578 // ---------------------------------------------------------------------------
1580 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1582 GetWindowPortBounds(window
, inRect
);
1583 Point pt
= {inRect
->left
, inRect
->top
};
1584 QDLocalToGlobalPoint( GetWindowPort(window
) , &pt
) ;
1586 inRect
->left
= pt
.h
;
1587 inRect
->bottom
+= pt
.v
;
1588 inRect
->right
+= pt
.h
;
1592 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1594 /*------------------------------------------------------
1595 Define which options your custom window supports.
1596 --------------------------------------------------------*/
1597 //just enable everything for our demo
1598 *(OptionBits
*)param
=//kWindowCanGrow|
1600 //kWindowCanCollapse|
1601 //kWindowCanGetWindowRegion|
1602 //kWindowHasTitleBar|
1603 //kWindowSupportsDragHilite|
1604 kWindowCanDrawInCurrentPort
|
1605 //kWindowCanMeasureTitle|
1606 kWindowWantsDisposeAtProcessDeath
|
1607 kWindowSupportsGetGrowImageRegion
|
1608 kWindowDefSupportsColorGrafPort
;
1612 // The content region is left as a rectangle matching the window size, this is
1613 // so the origin in the paint event, and etc. still matches what the
1614 // programmer expects.
1615 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1618 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1622 wxShapedMacWindowGetPos(window
, &r
) ;
1623 RectRgn( rgn
, &r
) ;
1627 // The structure region is set to the shape given to the SetShape method.
1628 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1630 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1636 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1637 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1638 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1639 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1645 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1647 GetWindowRegionPtr rgnRec
=(GetWindowRegionPtr
)param
;
1649 switch(rgnRec
->regionCode
)
1651 case kWindowStructureRgn
:
1652 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1654 case kWindowContentRgn
:
1655 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1658 SetEmptyRgn(rgnRec
->winRgn
);
1665 static SInt32
wxShapedMacWindowHitTest(WindowRef window
,SInt32 param
)
1667 /*------------------------------------------------------
1668 Determine the region of the window which was hit
1669 --------------------------------------------------------*/
1671 static RgnHandle tempRgn
=nil
;
1676 SetPt(&hitPoint
,LoWord(param
),HiWord(param
));//get the point clicked
1678 //Mac OS 8.5 or later
1679 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1680 if (PtInRgn(hitPoint
, tempRgn
)) //in window content region?
1683 return wNoHit
;//no significant area was hit.
1687 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1691 case kWindowMsgHitTest
:
1692 return wxShapedMacWindowHitTest(window
,param
);
1694 case kWindowMsgGetFeatures
:
1695 return wxShapedMacWindowGetFeatures(window
,param
);
1697 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1698 case kWindowMsgGetRegion
:
1699 return wxShapedMacWindowGetRegion(window
,param
);
1705 // ---------------------------------------------------------------------------