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 // ----------------------------------------------------------------------------
21 #pragma implementation "toplevel.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/toplevel.h"
35 #include "wx/string.h"
38 #include "wx/settings.h"
41 #include "wx/mac/uma.h"
42 #include "wx/mac/aga.h"
44 #include "wx/tooltip.h"
46 #if wxUSE_SYSTEM_OPTIONS
47 #include "wx/sysopt.h"
50 #include <ToolUtils.h>
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 // list of all frames and modeless dialogs
57 wxWindowList wxModelessWindows
;
59 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
61 // ============================================================================
62 // wxTopLevelWindowMac implementation
63 // ============================================================================
65 BEGIN_EVENT_TABLE(wxTopLevelWindowMac
, wxTopLevelWindowBase
)
69 // ---------------------------------------------------------------------------
71 // ---------------------------------------------------------------------------
73 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
75 static const EventTypeSpec eventList
[] =
77 // TODO remove control related event like key and mouse (except for WindowLeave events)
79 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
81 { kEventClassKeyboard
, kEventRawKeyDown
} ,
82 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
83 { kEventClassKeyboard
, kEventRawKeyUp
} ,
84 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
87 { kEventClassWindow
, kEventWindowShown
} ,
88 { kEventClassWindow
, kEventWindowActivated
} ,
89 { kEventClassWindow
, kEventWindowDeactivated
} ,
90 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
91 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
92 { kEventClassWindow
, kEventWindowClose
} ,
94 // we have to catch these events on the toplevel window level, as controls don't get the
95 // raw mouse events anymore
97 { kEventClassMouse
, kEventMouseDown
} ,
98 { kEventClassMouse
, kEventMouseUp
} ,
99 { kEventClassMouse
, kEventMouseWheelMoved
} ,
100 { kEventClassMouse
, kEventMouseMoved
} ,
101 { kEventClassMouse
, kEventMouseDragged
} ,
104 static pascal OSStatus
TextInputEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
106 OSStatus result
= eventNotHandledErr
;
108 wxWindow
* focus
= wxWindow::FindFocus() ;
116 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent
) ;
118 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
,sizeof(char), NULL
,&charCode
);
119 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
120 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
121 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
122 sizeof( Point
), NULL
, &point
);
124 switch ( GetEventKind( event
) )
126 case kEventTextInputUnicodeForKeyEvent
:
127 // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not
128 // get its own kEventTextInputUnicodeForKeyEvent, so we route back the
129 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
132 ControlRef macControl
= (ControlRef
) control
->GetHandle() ;
135 ::HandleControlKey( macControl
, keyCode
, charCode
, modifiers
) ;
140 // this may lead to double events sent to a window in case all handlers have skipped the key down event
141 UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
142 UInt32 message = (keyCode << 8) + charCode;
144 if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent(
145 focus , message , modifiers , when , point.h , point.v ) )
156 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
158 OSStatus result
= eventNotHandledErr
;
160 wxWindow
* focus
= wxWindow::FindFocus() ;
168 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
170 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
,sizeof(char), NULL
,&charCode
);
171 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
172 GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
173 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
174 sizeof( Point
), NULL
, &point
);
176 UInt32 message
= (keyCode
<< 8) + charCode
;
177 switch( GetEventKind( event
) )
179 case kEventRawKeyRepeat
:
180 case kEventRawKeyDown
:
182 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
183 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
184 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
185 if ( (focus
!= NULL
) && wxTheApp
->MacSendKeyDownEvent(
186 focus
, message
, modifiers
, when
, point
.h
, point
.v
) )
190 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
193 case kEventRawKeyUp
:
194 if ( (focus
!= NULL
) && wxTheApp
->MacSendKeyUpEvent(
195 focus
, message
, modifiers
, when
, point
.h
, point
.v
) )
200 case kEventRawKeyModifiersChanged
:
202 wxKeyEvent
event(wxEVT_KEY_DOWN
);
204 event
.m_shiftDown
= modifiers
& shiftKey
;
205 event
.m_controlDown
= modifiers
& controlKey
;
206 event
.m_altDown
= modifiers
& optionKey
;
207 event
.m_metaDown
= modifiers
& cmdKey
;
211 event
.m_timeStamp
= when
;
212 wxWindow
* focus
= wxWindow::FindFocus() ;
213 event
.SetEventObject(focus
);
215 if ( focus
&& (modifiers
^ wxTheApp
->s_lastModifiers
) & controlKey
)
217 event
.m_keyCode
= WXK_CONTROL
;
218 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
219 focus
->GetEventHandler()->ProcessEvent( event
) ;
221 if ( focus
&& (modifiers
^ wxTheApp
->s_lastModifiers
) & shiftKey
)
223 event
.m_keyCode
= WXK_SHIFT
;
224 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
225 focus
->GetEventHandler()->ProcessEvent( event
) ;
227 if ( focus
&& (modifiers
^ wxTheApp
->s_lastModifiers
) & optionKey
)
229 event
.m_keyCode
= WXK_ALT
;
230 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
231 focus
->GetEventHandler()->ProcessEvent( event
) ;
233 if ( focus
&& (modifiers
^ wxTheApp
->s_lastModifiers
) & cmdKey
)
235 event
.m_keyCode
= WXK_COMMAND
;
236 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
237 focus
->GetEventHandler()->ProcessEvent( event
) ;
239 wxTheApp
->s_lastModifiers
= modifiers
;
247 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
248 // for windows that we didn't create (like eg Scrollbars in a databrowser) , or for controls where we did not handle the
251 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
253 wxWindow
* g_MacLastWindow
= NULL
;
255 static EventMouseButton lastButton
= 0 ;
257 static void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
259 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
260 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
262 // this parameter are not given for all events
263 EventMouseButton button
= 0 ;
264 UInt32 clickCount
= 0 ;
265 cEvent
.GetParameter
<EventMouseButton
>(kEventParamMouseButton
, typeMouseButton
, &button
) ;
266 cEvent
.GetParameter
<UInt32
>(kEventParamClickCount
, typeUInt32
, &clickCount
) ;
268 wxevent
.m_x
= screenMouseLocation
.h
;
269 wxevent
.m_y
= screenMouseLocation
.v
;
270 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
271 wxevent
.m_controlDown
= modifiers
& controlKey
;
272 wxevent
.m_altDown
= modifiers
& optionKey
;
273 wxevent
.m_metaDown
= modifiers
& cmdKey
;
274 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
275 // a control click is interpreted as a right click
276 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
278 button
= kEventMouseButtonSecondary
;
281 // we must make sure that our synthetic 'right' button corresponds in
282 // mouse down, moved and mouse up, and does not deliver a right down and left up
284 if ( cEvent
.GetKind() == kEventMouseDown
)
285 lastButton
= button
;
289 else if ( lastButton
)
290 button
= lastButton
;
292 // determinate the correct down state, wx does not want a 'down' for a mouseUp event, while mac delivers
294 if ( button
!= 0 && cEvent
.GetKind() != kEventMouseUp
)
298 case kEventMouseButtonPrimary
:
299 wxevent
.m_leftDown
= true ;
301 case kEventMouseButtonSecondary
:
302 wxevent
.m_rightDown
= true ;
304 case kEventMouseButtonTertiary
:
305 wxevent
.m_middleDown
= true ;
309 // translate into wx types
310 switch ( cEvent
.GetKind() )
312 case kEventMouseDown
:
315 case kEventMouseButtonPrimary
:
316 wxevent
.SetEventType(clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
318 case kEventMouseButtonSecondary
:
319 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
321 case kEventMouseButtonTertiary
:
322 wxevent
.SetEventType(clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
329 case kEventMouseButtonPrimary
:
330 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
332 case kEventMouseButtonSecondary
:
333 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
335 case kEventMouseButtonTertiary
:
336 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
340 case kEventMouseWheelMoved
:
342 wxevent
.SetEventType(wxEVT_MOUSEWHEEL
) ;
344 // EventMouseWheelAxis axis = cEvent.GetParameter<EventMouseWheelAxis>(kEventParamMouseWheelAxis, typeMouseWheelAxis) ;
345 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeLongInteger
) ;
347 wxevent
.m_wheelRotation
= delta
;
348 wxevent
.m_wheelDelta
= 1;
349 wxevent
.m_linesPerAction
= 1;
353 wxevent
.SetEventType(wxEVT_MOTION
) ;
358 ControlRef
wxMacFindSubControl( Point location
, ControlRef superControl
, ControlPartCode
*outPart
)
362 UInt16 childrenCount
= 0 ;
363 OSStatus err
= CountSubControls( superControl
, &childrenCount
) ;
364 if ( err
== errControlIsNotEmbedder
)
366 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
368 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
370 ControlHandle sibling
;
371 err
= GetIndexedSubControl( superControl
, i
, & sibling
) ;
372 if ( err
== errControlIsNotEmbedder
)
375 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
376 if ( IsControlVisible( sibling
) )
379 UMAGetControlBoundsInWindowCoords( sibling
, &r
) ;
380 if ( MacPtInRect( location
, &r
) )
382 ControlHandle child
= wxMacFindSubControl( location
, sibling
, outPart
) ;
387 Point testLocation
= location
;
388 #if TARGET_API_MAC_OSX
389 testLocation
.h
-= r
.left
;
390 testLocation
.v
-= r
.top
;
392 *outPart
= TestControl( sibling
, testLocation
) ;
402 ControlRef
wxMacFindControlUnderMouse( Point location
, WindowRef window
, ControlPartCode
*outPart
)
404 #if TARGET_API_MAC_OSX
405 if ( UMAGetSystemVersion() >= 0x1030 )
406 return FindControlUnderMouse( location
, window
, outPart
) ;
408 ControlRef rootControl
= NULL
;
409 verify_noerr( GetRootControl( window
, &rootControl
) ) ;
410 return wxMacFindSubControl( location
, rootControl
, outPart
) ;
413 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
416 OSStatus result
= eventNotHandledErr
;
418 wxMacCarbonEvent
cEvent( event
) ;
420 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
421 Point windowMouseLocation
= screenMouseLocation
;
424 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
426 wxWindow
* currentMouseWindow
= NULL
;
427 ControlRef control
= NULL
;
431 QDGlobalToLocalPoint( UMAGetWindowPort(window
) , &windowMouseLocation
) ;
433 if ( wxTheApp
->s_captureWindow
&& wxTheApp
->s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
)
435 currentMouseWindow
= wxTheApp
->s_captureWindow
;
437 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
439 ControlPartCode part
;
440 control
= wxMacFindControlUnderMouse( windowMouseLocation
, window
, &part
) ;
441 // if there is no control below the mouse position, send the event to the toplevel window itself
443 currentMouseWindow
= (wxWindow
*) data
;
446 currentMouseWindow
= wxFindControlFromMacControl( control
) ;
447 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
449 // for wxToolBar to function we have to send certaint events to it
450 // instead of its children (wxToolBarTools)
452 GetSuperControl(control
, &parent
);
453 wxWindow
*wxParent
= wxFindControlFromMacControl( parent
) ;
454 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
455 currentMouseWindow
= wxParent
;
461 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
462 SetupMouseEvent( wxevent
, cEvent
) ;
464 // handle all enter / leave events
466 if ( currentMouseWindow
!= g_MacLastWindow
)
468 if ( g_MacLastWindow
)
470 wxMouseEvent
eventleave(wxevent
);
471 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
472 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
473 eventleave
.SetEventObject( g_MacLastWindow
) ;
476 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
477 #endif // wxUSE_TOOLTIPS
478 g_MacLastWindow
->GetEventHandler()->ProcessEvent(eventleave
);
480 if ( currentMouseWindow
)
482 wxMouseEvent
evententer(wxevent
);
483 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
484 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
485 evententer
.SetEventObject( currentMouseWindow
) ;
487 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
488 #endif // wxUSE_TOOLTIPS
489 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
491 g_MacLastWindow
= currentMouseWindow
;
494 if ( windowPart
== inMenuBar
)
496 // special case menu bar, as we are having a low-level runloop we must do it ourselves
497 if ( cEvent
.GetKind() == kEventMouseDown
)
499 ::MenuSelect( screenMouseLocation
) ;
502 } // if ( windowPart == inMenuBar )
503 else if ( currentMouseWindow
)
505 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
507 wxevent
.SetEventObject( currentMouseWindow
) ;
511 wxWindow
* cursorTarget
= currentMouseWindow
;
512 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
514 while( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
516 cursorTarget
= cursorTarget
->GetParent() ;
518 cursorPoint
+= cursorTarget
->GetPosition() ;
523 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
525 // set focus to this window
526 if (currentMouseWindow
->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
527 currentMouseWindow
->SetFocus();
530 // make tooltips current
533 if ( wxevent
.GetEventType() == wxEVT_MOTION
534 || wxevent
.GetEventType() == wxEVT_ENTER_WINDOW
535 || wxevent
.GetEventType() == wxEVT_LEAVE_WINDOW
)
536 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
537 #endif // wxUSE_TOOLTIPS
538 if ( currentMouseWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
542 ControlPartCode dummyPart
;
543 // if built-in find control is finding the wrong control (ie static box instead of overlaid
544 // button, we cannot let the standard handler do its job, but must handle manually
546 if ( ( cEvent
.GetKind() == kEventMouseDown
) &&
547 (FindControlUnderMouse(windowMouseLocation
, window
, &dummyPart
) !=
548 wxMacFindControlUnderMouse( windowMouseLocation
, window
, &dummyPart
) ) )
550 if ( currentMouseWindow
->MacIsReallyEnabled() )
552 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
553 Point clickLocation
= windowMouseLocation
;
554 #if TARGET_API_MAC_OSX
555 currentMouseWindow
->MacRootWindowToWindow( &clickLocation
.h
, &clickLocation
.v
) ;
557 HandleControlClick( (ControlRef
) currentMouseWindow
->GetHandle() , clickLocation
,
558 modifiers
, (ControlActionUPP
) -1 ) ;
563 if ( cEvent
.GetKind() == kEventMouseUp
&& wxTheApp
->s_captureWindow
)
565 wxTheApp
->s_captureWindow
= NULL
;
568 } // else if ( currentMouseWindow )
571 // don't mess with controls we don't know about
572 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
573 // so we try sending them the correct control directly
574 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
575 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
577 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
578 Point clickLocation
= windowMouseLocation
;
579 #if TARGET_API_MAC_OSX
581 hiPoint
.x
= clickLocation
.h
;
582 hiPoint
.y
= clickLocation
.v
;
583 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
584 clickLocation
.h
= (int)hiPoint
.x
;
585 clickLocation
.v
= (int)hiPoint
.y
;
587 HandleControlClick( control
, clickLocation
,
588 modifiers
, (ControlActionUPP
) -1 ) ;
595 static pascal OSStatus
wxMacTopLevelWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
597 OSStatus result
= eventNotHandledErr
;
599 wxMacCarbonEvent
cEvent( event
) ;
601 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
602 wxTopLevelWindowMac
* toplevelWindow
= (wxTopLevelWindowMac
*) data
;
604 switch( GetEventKind( event
) )
606 case kEventWindowActivated
:
608 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
609 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
610 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
611 wxevent
.SetEventObject(toplevelWindow
);
612 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
613 // we still sending an eventNotHandledErr in order to allow for default processing
616 case kEventWindowDeactivated
:
618 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
619 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
620 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
621 wxevent
.SetEventObject(toplevelWindow
);
622 toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
);
623 // we still sending an eventNotHandledErr in order to allow for default processing
626 case kEventWindowShown
:
627 toplevelWindow
->Refresh() ;
630 case kEventWindowClose
:
631 toplevelWindow
->Close() ;
634 case kEventWindowBoundsChanged
:
636 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
637 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
638 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
639 if ( attributes
& kWindowBoundsChangeSizeChanged
)
641 // according to the other ports we handle this within the OS level
642 // resize event, not within a wxSizeEvent
643 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
647 frame
->PositionStatusBar();
650 frame
->PositionToolBar();
654 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
655 event
.SetEventObject( toplevelWindow
) ;
657 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
659 if ( attributes
& kWindowBoundsChangeOriginChanged
)
661 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
662 event
.SetEventObject( toplevelWindow
) ;
663 toplevelWindow
->GetEventHandler()->ProcessEvent(event
) ;
668 case kEventWindowBoundsChanging
:
670 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
671 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
673 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
675 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
676 int left
, top
, right
, bottom
;
677 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
678 wxRect
r( newRect
.left
- left
, newRect
.top
- top
,
679 newRect
.right
- newRect
.left
+ left
+ right
, newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
680 // this is a EVT_SIZING not a EVT_SIZE type !
681 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
682 wxevent
.SetEventObject( toplevelWindow
) ;
684 if ( toplevelWindow
->GetEventHandler()->ProcessEvent(wxevent
) )
685 adjustR
= wxevent
.GetRect() ;
687 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
688 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
689 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
690 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
691 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
692 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
693 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
694 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
695 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
696 if ( !EqualRect( &newRect
, &adjustedRect
) )
697 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
709 pascal OSStatus
wxMacTopLevelEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
711 OSStatus result
= eventNotHandledErr
;
713 switch ( GetEventClass( event
) )
715 case kEventClassKeyboard
:
716 result
= KeyboardEventHandler( handler
, event
, data
) ;
718 case kEventClassTextInput
:
719 result
= TextInputEventHandler( handler
, event
, data
) ;
721 case kEventClassWindow
:
722 result
= wxMacTopLevelWindowEventHandler( handler
, event
, data
) ;
724 case kEventClassMouse
:
725 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
733 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTopLevelEventHandler
)
735 // ---------------------------------------------------------------------------
736 // wxWindowMac utility functions
737 // ---------------------------------------------------------------------------
739 // Find an item given the Macintosh Window Reference
741 wxList
wxWinMacWindowList(wxKEY_INTEGER
);
742 wxTopLevelWindowMac
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
744 wxNode
*node
= wxWinMacWindowList
.Find((long)inWindowRef
);
747 return (wxTopLevelWindowMac
*)node
->GetData();
750 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
) ;
751 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxTopLevelWindowMac
*win
)
753 // adding NULL WindowRef is (first) surely a result of an error and
754 // (secondly) breaks menu command processing
755 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
757 if ( !wxWinMacWindowList
.Find((long)inWindowRef
) )
758 wxWinMacWindowList
.Append((long)inWindowRef
, win
);
761 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
) ;
762 void wxRemoveMacWindowAssociation(wxTopLevelWindowMac
*win
)
764 wxWinMacWindowList
.DeleteObject(win
);
768 // ----------------------------------------------------------------------------
769 // wxTopLevelWindowMac creation
770 // ----------------------------------------------------------------------------
772 wxTopLevelWindowMac
*wxTopLevelWindowMac::s_macDeactivateWindow
= NULL
;
780 void wxTopLevelWindowMac::Init()
783 m_maximizeOnShow
= FALSE
;
785 #if TARGET_API_MAC_OSX
786 m_macUsesCompositing
= TRUE
;
788 m_macUsesCompositing
= FALSE
;
790 m_macEventHandler
= NULL
;
791 m_macFullScreenData
= NULL
;
794 class wxMacDeferredWindowDeleter
: public wxObject
797 wxMacDeferredWindowDeleter( WindowRef windowRef
)
799 m_macWindow
= windowRef
;
801 virtual ~wxMacDeferredWindowDeleter()
803 UMADisposeWindow( (WindowRef
) m_macWindow
) ;
806 WindowRef m_macWindow
;
809 bool wxTopLevelWindowMac::Create(wxWindow
*parent
,
811 const wxString
& title
,
815 const wxString
& name
)
820 m_windowStyle
= style
;
824 m_windowId
= id
== -1 ? NewControlId() : id
;
825 wxWindow::SetTitle( title
) ;
827 MacCreateRealWindow( title
, pos
, size
, MacRemoveBordersFromStyle(style
) , name
) ;
829 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
831 wxTopLevelWindows
.Append(this);
834 parent
->AddChild(this);
839 wxTopLevelWindowMac::~wxTopLevelWindowMac()
843 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
844 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
847 if ( m_macEventHandler
)
849 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
850 m_macEventHandler
= NULL
;
853 wxRemoveMacWindowAssociation( this ) ;
855 if ( wxModelessWindows
.Find(this) )
856 wxModelessWindows
.DeleteObject(this);
858 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
860 m_macFullScreenData
= NULL
;
864 // ----------------------------------------------------------------------------
865 // wxTopLevelWindowMac maximize/minimize
866 // ----------------------------------------------------------------------------
868 void wxTopLevelWindowMac::Maximize(bool maximize
)
870 wxMacPortStateHelper
help( (GrafPtr
) GetWindowPort( (WindowRef
) m_macWindow
) ) ;
871 wxMacWindowClipper
clip (this);
872 ZoomWindow( (WindowRef
)m_macWindow
, maximize
? inZoomOut
: inZoomIn
, false ) ;
875 bool wxTopLevelWindowMac::IsMaximized() const
877 return IsWindowInStandardState( (WindowRef
)m_macWindow
, NULL
, NULL
) ;
880 void wxTopLevelWindowMac::Iconize(bool iconize
)
882 if ( IsWindowCollapsable((WindowRef
)m_macWindow
) )
883 CollapseWindow((WindowRef
)m_macWindow
, iconize
) ;
886 bool wxTopLevelWindowMac::IsIconized() const
888 return IsWindowCollapsed((WindowRef
)m_macWindow
) ;
891 void wxTopLevelWindowMac::Restore()
893 // not available on mac
896 // ----------------------------------------------------------------------------
897 // wxTopLevelWindowMac misc
898 // ----------------------------------------------------------------------------
900 wxPoint
wxTopLevelWindowMac::GetClientAreaOrigin() const
902 return wxPoint(0,0) ;
905 void wxTopLevelWindowMac::SetIcon(const wxIcon
& icon
)
908 wxTopLevelWindowBase::SetIcon(icon
);
911 void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
913 wxTopLevelWindowBase::MacSetBackgroundBrush( brush
) ;
915 if ( m_macBackgroundBrush
.Ok() && m_macBackgroundBrush
.GetStyle() != wxTRANSPARENT
&& m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
917 SetThemeWindowBackground( (WindowRef
) m_macWindow
, m_macBackgroundBrush
.MacGetTheme() , false ) ;
921 void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler()
923 if ( m_macEventHandler
!= NULL
)
925 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
927 InstallWindowEventHandler(MAC_WXHWND(m_macWindow
), GetwxMacTopLevelEventHandlerUPP(),
928 GetEventTypeCount(eventList
), eventList
, this, (EventHandlerRef
*)&m_macEventHandler
);
931 void wxTopLevelWindowMac::MacCreateRealWindow( const wxString
& title
,
935 const wxString
& name
)
937 OSStatus err
= noErr
;
939 m_windowStyle
= style
;
953 int w
= WidthDefault(size
.x
);
954 int h
= HeightDefault(size
.y
);
956 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
958 // translate the window attributes in the appropriate window class and attributes
960 WindowClass wclass
= 0;
961 WindowAttributes attr
= kWindowNoAttributes
;
963 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
966 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
967 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
968 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
971 wclass
= kFloatingWindowClass
;
972 if ( HasFlag(wxTINY_CAPTION_VERT
) )
974 attr
|= kWindowSideTitlebarAttribute
;
979 wclass
= kPlainWindowClass
;
982 else if ( HasFlag( wxCAPTION
) )
984 wclass
= kDocumentWindowClass
;
988 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
989 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
991 wclass
= kDocumentWindowClass
;
995 wclass
= kPlainWindowClass
;
999 if ( HasFlag( wxMINIMIZE_BOX
) )
1001 attr
|= kWindowCollapseBoxAttribute
;
1003 if ( HasFlag( wxMAXIMIZE_BOX
) )
1005 attr
|= kWindowFullZoomAttribute
;
1007 if ( HasFlag( wxRESIZE_BORDER
) )
1009 attr
|= kWindowResizableAttribute
;
1011 if ( HasFlag( wxCLOSE_BOX
) )
1013 attr
|= kWindowCloseBoxAttribute
;
1016 if (UMAGetSystemVersion() >= 0x1000)
1018 // turn on live resizing (OS X only)
1019 attr
|= kWindowLiveResizeAttribute
;
1022 if (HasFlag(wxSTAY_ON_TOP
))
1023 wclass
= kUtilityWindowClass
;
1025 #if TARGET_API_MAC_OSX
1026 attr
|= kWindowCompositingAttribute
;
1029 if ( HasFlag(wxFRAME_SHAPED
) )
1031 WindowDefSpec customWindowDefSpec
;
1032 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1033 customWindowDefSpec
.u
.defProc
= NewWindowDefUPP(wxShapedMacWindowDef
);
1035 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1036 attr
, &theBoundsRect
,
1037 (WindowRef
*) &m_macWindow
);
1041 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1044 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1046 // the create commands are only for content rect, so we have to set the size again as
1048 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1050 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1051 UMASetWTitle( (WindowRef
) m_macWindow
, title
, m_font
.GetEncoding() ) ;
1052 m_peer
= new wxMacControl() ;
1053 #if TARGET_API_MAC_OSX
1054 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1055 // the content view, so we have to retrieve it explicitely
1056 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1057 m_peer
->GetControlRefAddr() ) ;
1058 if ( !m_peer
->Ok() )
1060 // compatibility mode fallback
1061 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1064 ::CreateRootControl( (WindowRef
)m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1066 // the root control level handleer
1067 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1069 // the frame window event handler
1070 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1071 MacInstallTopLevelWindowEventHandler() ;
1075 if ( HasFlag(wxFRAME_SHAPED
) )
1077 // default shape matches the window size
1078 wxRegion
rgn(0, 0, w
, h
);
1082 wxWindowCreateEvent
event(this);
1083 GetEventHandler()->ProcessEvent(event
);
1086 void wxTopLevelWindowMac::ClearBackground()
1088 wxWindow::ClearBackground() ;
1091 // Raise the window to the top of the Z order
1092 void wxTopLevelWindowMac::Raise()
1094 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1097 // Lower the window to the bottom of the Z order
1098 void wxTopLevelWindowMac::Lower()
1100 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1104 void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp
)
1106 if(s_macDeactivateWindow
)
1108 wxLogDebug(wxT("Doing delayed deactivation of %p"),s_macDeactivateWindow
);
1109 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1113 void wxTopLevelWindowMac::MacActivate( long timestamp
, bool inIsActivating
)
1115 // wxLogDebug(wxT("TopLevel=%p::MacActivate"),this);
1117 if(s_macDeactivateWindow
==this)
1118 s_macDeactivateWindow
=NULL
;
1119 MacDelayedDeactivation(timestamp
);
1120 MacPropagateHiliteChanged() ;
1123 void wxTopLevelWindowMac::SetTitle(const wxString
& title
)
1125 wxWindow::SetTitle( title
) ;
1126 UMASetWTitle( (WindowRef
)m_macWindow
, title
, m_font
.GetEncoding() ) ;
1129 bool wxTopLevelWindowMac::Show(bool show
)
1131 if ( !wxTopLevelWindowBase::Show(show
) )
1136 #if wxUSE_SYSTEM_OPTIONS //code contributed by Ryan Wilcox December 18, 2003
1137 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1139 ::ShowWindow( (WindowRef
)m_macWindow
);
1144 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowShowTransitionAction
,nil
);
1146 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1147 // as apps expect a size event to occur at this moment
1148 wxSizeEvent
event( GetSize() , m_windowId
);
1149 event
.SetEventObject(this);
1150 GetEventHandler()->ProcessEvent(event
);
1154 #if wxUSE_SYSTEM_OPTIONS
1155 if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1) )
1157 ::HideWindow((WindowRef
) m_macWindow
);
1162 ::TransitionWindow((WindowRef
)m_macWindow
,kWindowZoomTransitionEffect
,kWindowHideTransitionAction
,nil
);
1166 MacPropagateVisibilityChanged() ;
1171 bool wxTopLevelWindowMac::ShowFullScreen(bool show
, long style
)
1175 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1177 data
= new FullScreenData() ;
1179 m_macFullScreenData
= data
;
1180 data
->m_position
= GetPosition() ;
1181 data
->m_size
= GetSize() ;
1183 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1187 int left
, top
, right
, bottom
;
1188 wxRect client
= wxGetClientDisplayRect() ;
1197 MacGetContentAreaInset( left
, top
, right
, bottom
) ;
1199 if ( style
& wxFULLSCREEN_NOCAPTION
)
1204 if ( style
& wxFULLSCREEN_NOBORDER
)
1210 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1214 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1218 SetSize( x
, y
, w
, h
) ;
1223 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1224 SetPosition( data
->m_position
) ;
1225 SetSize( data
->m_size
) ;
1227 m_macFullScreenData
= NULL
;
1232 bool wxTopLevelWindowMac::IsFullScreen() const
1234 return m_macFullScreenData
!= NULL
;
1237 // we are still using coordinates of the content view, todo switch to structure bounds
1239 void wxTopLevelWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1243 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1244 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1246 left
= content
.left
- structure
.left
;
1247 top
= content
.top
- structure
.top
;
1248 right
= structure
.right
- content
.right
;
1249 bottom
= structure
.bottom
- content
.bottom
;
1252 void wxTopLevelWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1254 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1255 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1258 void wxTopLevelWindowMac::DoGetPosition( int *x
, int *y
) const
1261 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1262 if(x
) *x
= bounds
.left
;
1263 if(y
) *y
= bounds
.top
;
1265 void wxTopLevelWindowMac::DoGetSize( int *width
, int *height
) const
1268 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1269 if(width
) *width
= bounds
.right
- bounds
.left
;
1270 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1273 void wxTopLevelWindowMac::DoGetClientSize( int *width
, int *height
) const
1276 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1277 if(width
) *width
= bounds
.right
- bounds
.left
;
1278 if(height
) *height
= bounds
.bottom
- bounds
.top
;
1281 void wxTopLevelWindowMac::MacSetMetalAppearance( bool set
)
1283 #if TARGET_API_MAC_OSX
1285 GetWindowAttributes((WindowRef
) m_macWindow
, &attr
) ;
1286 wxASSERT_MSG( attr
& kWindowCompositingAttribute
,
1287 wxT("Cannot set metal appearance on a non-compositing window") ) ;
1289 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1290 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1294 bool wxTopLevelWindowMac::MacGetMetalAppearance() const
1296 #if TARGET_API_MAC_OSX
1297 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1303 void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1305 ChangeWindowAttributes ( (WindowRef
) m_macWindow
, attributesToSet
, attributesToClear
) ;
1308 wxUint32
wxTopLevelWindowMac::MacGetWindowAttributes() const
1311 GetWindowAttributes((WindowRef
) m_macWindow
, &attr
) ;
1315 // ---------------------------------------------------------------------------
1316 // Shape implementation
1317 // ---------------------------------------------------------------------------
1320 bool wxTopLevelWindowMac::SetShape(const wxRegion
& region
)
1322 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
1323 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1325 // The empty region signifies that the shape should be removed from the
1327 if ( region
.IsEmpty() )
1329 wxSize sz
= GetClientSize();
1330 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1331 return SetShape(rgn
);
1334 // Make a copy of the region
1335 RgnHandle shapeRegion
= NewRgn();
1336 CopyRgn( (RgnHandle
)region
.GetWXHRGN(), shapeRegion
);
1338 // Dispose of any shape region we may already have
1339 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1343 // Save the region so we can use it later
1344 SetWRefCon((WindowRef
)MacGetWindowRef(), (SInt32
)shapeRegion
);
1346 // Tell the window manager that the window has changed shape
1347 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1351 // ---------------------------------------------------------------------------
1352 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1353 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1354 // ---------------------------------------------------------------------------
1356 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1358 GetWindowPortBounds(window
, inRect
);
1359 Point pt
= {inRect
->left
, inRect
->top
};
1360 QDLocalToGlobalPoint( GetWindowPort(window
) , &pt
) ;
1362 inRect
->left
= pt
.h
;
1363 inRect
->bottom
+= pt
.v
;
1364 inRect
->right
+= pt
.h
;
1368 static SInt32
wxShapedMacWindowGetFeatures(WindowRef window
, SInt32 param
)
1370 /*------------------------------------------------------
1371 Define which options your custom window supports.
1372 --------------------------------------------------------*/
1373 //just enable everything for our demo
1374 *(OptionBits
*)param
=//kWindowCanGrow|
1376 //kWindowCanCollapse|
1377 //kWindowCanGetWindowRegion|
1378 //kWindowHasTitleBar|
1379 //kWindowSupportsDragHilite|
1380 kWindowCanDrawInCurrentPort
|
1381 //kWindowCanMeasureTitle|
1382 kWindowWantsDisposeAtProcessDeath
|
1383 kWindowSupportsGetGrowImageRegion
|
1384 kWindowDefSupportsColorGrafPort
;
1388 // The content region is left as a rectangle matching the window size, this is
1389 // so the origin in the paint event, and etc. still matches what the
1390 // programmer expects.
1391 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1394 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow(window
);
1398 wxShapedMacWindowGetPos(window
, &r
) ;
1399 RectRgn( rgn
, &r
) ;
1403 // The structure region is set to the shape given to the SetShape method.
1404 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1406 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1412 wxShapedMacWindowGetPos(window
, &windowRect
); //how big is the window
1413 CopyRgn(cachedRegion
, rgn
); //make a copy of our cached region
1414 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1415 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1421 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1423 GetWindowRegionPtr rgnRec
=(GetWindowRegionPtr
)param
;
1425 switch(rgnRec
->regionCode
)
1427 case kWindowStructureRgn
:
1428 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1430 case kWindowContentRgn
:
1431 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1434 SetEmptyRgn(rgnRec
->winRgn
);
1441 static SInt32
wxShapedMacWindowHitTest(WindowRef window
,SInt32 param
)
1443 /*------------------------------------------------------
1444 Determine the region of the window which was hit
1445 --------------------------------------------------------*/
1447 static RgnHandle tempRgn
=nil
;
1452 SetPt(&hitPoint
,LoWord(param
),HiWord(param
));//get the point clicked
1454 //Mac OS 8.5 or later
1455 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1456 if (PtInRgn(hitPoint
, tempRgn
)) //in window content region?
1459 return wNoHit
;//no significant area was hit.
1463 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
)
1467 case kWindowMsgHitTest
:
1468 return wxShapedMacWindowHitTest(window
,param
);
1470 case kWindowMsgGetFeatures
:
1471 return wxShapedMacWindowGetFeatures(window
,param
);
1473 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1474 case kWindowMsgGetRegion
:
1475 return wxShapedMacWindowGetRegion(window
,param
);
1481 // ---------------------------------------------------------------------------