1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/nonownedwnd.cpp
3 // Purpose: implementation of wxNonOwnedWindow
4 // Author: Stefan Csomor
6 // RCS-ID: $Id: nonownedwnd.cpp 50329 2007-11-29 17:00:58Z VS $
7 // Copyright: (c) Stefan Csomor 2008
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #include "wx/hashmap.h"
19 #include "wx/evtloop.h"
20 #include "wx/tooltip.h"
21 #include "wx/nonownedwnd.h"
23 #include "wx/osx/private.h"
24 #include "wx/settings.h"
27 #if wxUSE_SYSTEM_OPTIONS
28 #include "wx/sysopt.h"
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 // unified title and toolbar constant - not in Tiger headers, so we duplicate it here
36 #define kWindowUnifiedTitleAndToolbarAttribute (1 << 7)
38 // trace mask for activation tracing messages
39 #define TRACE_ACTIVATE "activation"
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
47 // ============================================================================
48 // wxNonOwnedWindow implementation
49 // ============================================================================
51 // ---------------------------------------------------------------------------
53 // ---------------------------------------------------------------------------
55 static const EventTypeSpec eventList
[] =
57 // TODO: remove control related event like key and mouse (except for WindowLeave events)
59 { kEventClassKeyboard
, kEventRawKeyDown
} ,
60 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
61 { kEventClassKeyboard
, kEventRawKeyUp
} ,
62 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
64 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
65 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
67 { kEventClassWindow
, kEventWindowShown
} ,
68 { kEventClassWindow
, kEventWindowActivated
} ,
69 { kEventClassWindow
, kEventWindowDeactivated
} ,
70 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
71 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
72 { kEventClassWindow
, kEventWindowClose
} ,
73 { kEventClassWindow
, kEventWindowGetRegion
} ,
75 // we have to catch these events on the toplevel window level,
76 // as controls don't get the raw mouse events anymore
78 { kEventClassMouse
, kEventMouseDown
} ,
79 { kEventClassMouse
, kEventMouseUp
} ,
80 { kEventClassMouse
, kEventMouseWheelMoved
} ,
81 { kEventClassMouse
, kEventMouseMoved
} ,
82 { kEventClassMouse
, kEventMouseDragged
} ,
85 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
87 OSStatus result
= eventNotHandledErr
;
88 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
89 // FindFocus does not return the actual focus window, but the enclosing window
90 wxWindow
* focus
= wxWindow::DoFindFocus();
92 focus
= (wxNonOwnedWindow
*) data
;
94 unsigned char charCode
;
102 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
105 ByteCount dataSize
= 0 ;
106 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
109 int numChars
= dataSize
/ sizeof( UniChar
) + 1;
111 UniChar
* charBuf
= buf
;
113 if ( numChars
* 2 > 4 )
114 charBuf
= new UniChar
[ numChars
] ;
115 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
116 charBuf
[ numChars
- 1 ] = 0;
118 #if SIZEOF_WCHAR_T == 2
119 uniChar
= charBuf
[0] ;
121 wxMBConvUTF16 converter
;
122 converter
.MB2WC( uniChar
, (const char*)charBuf
, 2 ) ;
125 if ( numChars
* 2 > 4 )
130 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
131 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
132 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
133 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
135 UInt32 message
= (keyCode
<< 8) + charCode
;
136 switch ( GetEventKind( event
) )
138 case kEventRawKeyRepeat
:
139 case kEventRawKeyDown
:
141 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
142 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
143 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
144 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
145 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
149 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
153 case kEventRawKeyUp
:
154 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
155 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
161 case kEventRawKeyModifiersChanged
:
163 wxKeyEvent
event(wxEVT_KEY_DOWN
);
165 event
.m_shiftDown
= modifiers
& shiftKey
;
166 event
.m_controlDown
= modifiers
& controlKey
;
167 event
.m_altDown
= modifiers
& optionKey
;
168 event
.m_metaDown
= modifiers
& cmdKey
;
173 event
.m_uniChar
= uniChar
[0] ;
176 event
.SetTimestamp(when
);
177 event
.SetEventObject(focus
);
179 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
181 event
.m_keyCode
= WXK_CONTROL
;
182 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
183 focus
->HandleWindowEvent( event
) ;
185 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
187 event
.m_keyCode
= WXK_SHIFT
;
188 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
189 focus
->HandleWindowEvent( event
) ;
191 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
193 event
.m_keyCode
= WXK_ALT
;
194 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
195 focus
->HandleWindowEvent( event
) ;
197 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
199 event
.m_keyCode
= WXK_COMMAND
;
200 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
201 focus
->HandleWindowEvent( event
) ;
204 wxApp::s_lastModifiers
= modifiers
;
215 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
216 // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
219 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
221 wxWindow
* g_MacLastWindow
= NULL
;
223 EventMouseButton g_lastButton
= 0 ;
224 bool g_lastButtonWasFakeRight
= false ;
226 void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
228 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
229 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
231 // these parameters are not given for all events
232 EventMouseButton button
= 0 ;
233 UInt32 clickCount
= 0 ;
234 UInt32 mouseChord
= 0;
236 cEvent
.GetParameter
<EventMouseButton
>( kEventParamMouseButton
, typeMouseButton
, &button
) ;
237 cEvent
.GetParameter
<UInt32
>( kEventParamClickCount
, typeUInt32
, &clickCount
) ;
238 // the chord is the state of the buttons pressed currently
239 cEvent
.GetParameter
<UInt32
>( kEventParamMouseChord
, typeUInt32
, &mouseChord
) ;
241 wxevent
.m_x
= screenMouseLocation
.h
;
242 wxevent
.m_y
= screenMouseLocation
.v
;
243 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
244 wxevent
.m_controlDown
= modifiers
& controlKey
;
245 wxevent
.m_altDown
= modifiers
& optionKey
;
246 wxevent
.m_metaDown
= modifiers
& cmdKey
;
247 wxevent
.m_clickCount
= clickCount
;
248 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
250 // a control click is interpreted as a right click
251 bool thisButtonIsFakeRight
= false ;
252 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
254 button
= kEventMouseButtonSecondary
;
255 thisButtonIsFakeRight
= true ;
258 // otherwise we report double clicks by connecting a left click with a ctrl-left click
259 if ( clickCount
> 1 && button
!= g_lastButton
)
262 // we must make sure that our synthetic 'right' button corresponds in
263 // mouse down, moved and mouse up, and does not deliver a right down and left up
265 if ( cEvent
.GetKind() == kEventMouseDown
)
267 g_lastButton
= button
;
268 g_lastButtonWasFakeRight
= thisButtonIsFakeRight
;
274 g_lastButtonWasFakeRight
= false ;
276 else if ( g_lastButton
== kEventMouseButtonSecondary
&& g_lastButtonWasFakeRight
)
277 button
= g_lastButton
;
279 // Adjust the chord mask to remove the primary button and add the
280 // secondary button. It is possible that the secondary button is
281 // already pressed, e.g. on a mouse connected to a laptop, but this
282 // possibility is ignored here:
283 if( thisButtonIsFakeRight
&& ( mouseChord
& 1U ) )
284 mouseChord
= ((mouseChord
& ~1U) | 2U);
287 wxevent
.m_leftDown
= true ;
289 wxevent
.m_rightDown
= true ;
291 wxevent
.m_middleDown
= true ;
293 // translate into wx types
294 switch ( cEvent
.GetKind() )
296 case kEventMouseDown
:
299 case kEventMouseButtonPrimary
:
300 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
303 case kEventMouseButtonSecondary
:
304 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
307 case kEventMouseButtonTertiary
:
308 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
319 case kEventMouseButtonPrimary
:
320 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
323 case kEventMouseButtonSecondary
:
324 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
327 case kEventMouseButtonTertiary
:
328 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
336 case kEventMouseWheelMoved
:
338 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
340 EventMouseWheelAxis axis
= cEvent
.GetParameter
<EventMouseWheelAxis
>(kEventParamMouseWheelAxis
, typeMouseWheelAxis
) ;
341 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeSInt32
) ;
343 wxevent
.m_wheelRotation
= delta
;
344 wxevent
.m_wheelDelta
= 1;
345 wxevent
.m_linesPerAction
= 1;
346 if ( axis
== kEventMouseWheelAxisX
)
347 wxevent
.m_wheelAxis
= 1;
351 case kEventMouseEntered
:
352 case kEventMouseExited
:
353 case kEventMouseDragged
:
354 case kEventMouseMoved
:
355 wxevent
.SetEventType( wxEVT_MOTION
) ;
362 #define NEW_CAPTURE_HANDLING 1
365 wxMacTopLevelMouseEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
369 wxNonOwnedWindow
* toplevelWindow
= (wxNonOwnedWindow
*) data
;
371 OSStatus result
= eventNotHandledErr
;
373 wxMacCarbonEvent
cEvent( event
) ;
375 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
376 Point windowMouseLocation
= screenMouseLocation
;
378 WindowRef window
= NULL
;
379 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
381 wxWindow
* currentMouseWindow
= NULL
;
382 ControlRef control
= NULL
;
384 #if NEW_CAPTURE_HANDLING
385 if ( wxApp::s_captureWindow
)
387 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
388 windowPart
= inContent
;
394 wxMacGlobalToLocal( window
, &windowMouseLocation
) ;
396 if ( wxApp::s_captureWindow
397 #if !NEW_CAPTURE_HANDLING
398 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
402 currentMouseWindow
= wxApp::s_captureWindow
;
404 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
406 ControlPartCode part
;
407 control
= FindControlUnderMouse( windowMouseLocation
, window
, &part
) ;
408 // if there is no control below the mouse position, send the event to the toplevel window itself
411 currentMouseWindow
= (wxWindow
*) data
;
415 currentMouseWindow
= (wxWindow
*) wxFindControlFromMacControl( control
) ;
416 #ifndef __WXUNIVERSAL__
417 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
420 // for wxToolBar to function we have to send certaint events to it
421 // instead of its children (wxToolBarTools)
423 GetSuperControl(control
, &parent
);
424 wxWindow
*wxParent
= (wxWindow
*) wxFindControlFromMacControl( parent
) ;
425 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
426 currentMouseWindow
= wxParent
;
432 // disabled windows must not get any input messages
433 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
434 currentMouseWindow
= NULL
;
438 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
439 SetupMouseEvent( wxevent
, cEvent
) ;
441 // handle all enter / leave events
443 if ( currentMouseWindow
!= g_MacLastWindow
)
445 if ( g_MacLastWindow
)
447 wxMouseEvent
eventleave(wxevent
);
448 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
449 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
450 eventleave
.SetEventObject( g_MacLastWindow
) ;
451 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
454 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
457 g_MacLastWindow
->HandleWindowEvent(eventleave
);
460 if ( currentMouseWindow
)
462 wxMouseEvent
evententer(wxevent
);
463 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
464 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
465 evententer
.SetEventObject( currentMouseWindow
) ;
466 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
469 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
472 currentMouseWindow
->HandleWindowEvent(evententer
);
475 g_MacLastWindow
= currentMouseWindow
;
478 if ( windowPart
== inMenuBar
)
480 // special case menu bar, as we are having a low-level runloop we must do it ourselves
481 if ( cEvent
.GetKind() == kEventMouseDown
)
483 ::MenuSelect( screenMouseLocation
) ;
488 else if ( currentMouseWindow
)
490 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
492 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
494 wxevent
.SetEventObject( currentMouseWindow
) ;
495 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
497 // make tooltips current
500 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
501 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
504 if ( currentMouseWindow
->HandleWindowEvent(wxevent
) )
506 if ((currentMouseWindowParent
!= NULL
) &&
507 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
508 currentMouseWindow
= NULL
;
514 // if the user code did _not_ handle the event, then perform the
515 // default processing
516 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
518 // ... that is set focus to this window
519 if (currentMouseWindow
->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
520 currentMouseWindow
->SetFocus();
524 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
526 wxApp::s_captureWindow
= NULL
;
532 wxWindow
* cursorTarget
= currentMouseWindow
;
533 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
535 extern wxCursor gGlobalCursor
;
537 if (!gGlobalCursor
.IsOk())
539 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
541 cursorTarget
= cursorTarget
->GetParent() ;
543 cursorPoint
+= cursorTarget
->GetPosition();
548 else // currentMouseWindow == NULL
550 // don't mess with controls we don't know about
551 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
552 // so we try sending them the correct control directly
553 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
555 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
556 Point clickLocation
= windowMouseLocation
;
559 hiPoint
.x
= clickLocation
.h
;
560 hiPoint
.y
= clickLocation
.v
;
561 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
562 clickLocation
.h
= (int)hiPoint
.x
;
563 clickLocation
.v
= (int)hiPoint
.y
;
565 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
573 static pascal OSStatus
574 wxNonOwnedWindowEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
578 OSStatus result
= eventNotHandledErr
;
580 wxMacCarbonEvent
cEvent( event
) ;
582 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
583 wxNonOwnedWindow
* toplevelWindow
= (wxNonOwnedWindow
*) data
;
585 switch ( GetEventKind( event
) )
587 case kEventWindowActivated
:
589 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
590 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
591 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
592 wxevent
.SetEventObject(toplevelWindow
);
593 toplevelWindow
->HandleWindowEvent(wxevent
);
594 // we still sending an eventNotHandledErr in order to allow for default processing
598 case kEventWindowDeactivated
:
600 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
601 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
602 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
603 wxevent
.SetEventObject(toplevelWindow
);
604 toplevelWindow
->HandleWindowEvent(wxevent
);
605 // we still sending an eventNotHandledErr in order to allow for default processing
609 case kEventWindowShown
:
610 toplevelWindow
->Refresh() ;
614 case kEventWindowClose
:
615 toplevelWindow
->Close() ;
619 case kEventWindowBoundsChanged
:
621 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
622 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
623 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
624 if ( attributes
& kWindowBoundsChangeSizeChanged
)
626 #ifndef __WXUNIVERSAL__
627 // according to the other ports we handle this within the OS level
628 // resize event, not within a wxSizeEvent
629 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
632 frame
->PositionBars();
635 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
636 event
.SetEventObject( toplevelWindow
) ;
638 toplevelWindow
->HandleWindowEvent(event
) ;
639 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
642 if ( attributes
& kWindowBoundsChangeOriginChanged
)
644 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
645 event
.SetEventObject( toplevelWindow
) ;
646 toplevelWindow
->HandleWindowEvent(event
) ;
653 case kEventWindowBoundsChanging
:
655 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
656 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
658 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
660 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
661 int left
, top
, right
, bottom
;
662 toplevelWindow
->MacGetContentAreaInset( left
, top
, right
, bottom
) ;
667 newRect
.right
- newRect
.left
+ left
+ right
,
668 newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
670 // this is a EVT_SIZING not a EVT_SIZE type !
671 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
672 wxevent
.SetEventObject( toplevelWindow
) ;
674 if ( toplevelWindow
->HandleWindowEvent(wxevent
) )
675 adjustR
= wxevent
.GetRect() ;
677 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
678 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
679 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
680 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
681 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
682 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
683 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
684 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
685 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
686 if ( !EqualRect( &newRect
, &adjustedRect
) )
687 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
688 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
695 case kEventWindowGetRegion
:
697 if ( toplevelWindow
->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
699 WindowRegionCode windowRegionCode
;
701 // Fetch the region code that is being queried
702 GetEventParameter( event
,
703 kEventParamWindowRegionCode
,
704 typeWindowRegionCode
, NULL
,
705 sizeof windowRegionCode
, NULL
,
706 &windowRegionCode
) ;
708 // If it is the opaque region code then set the
709 // region to empty and return noErr to stop event
711 if ( windowRegionCode
== kWindowOpaqueRgn
) {
713 GetEventParameter( event
,
714 kEventParamRgnHandle
,
715 typeQDRgnHandle
, NULL
,
718 SetEmptyRgn(region
) ;
732 // mix this in from window.cpp
733 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
735 pascal OSStatus
wxNonOwnedEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
737 OSStatus result
= eventNotHandledErr
;
739 switch ( GetEventClass( event
) )
741 case kEventClassTextInput
:
742 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
745 case kEventClassKeyboard
:
746 result
= KeyboardEventHandler( handler
, event
, data
) ;
749 case kEventClassWindow
:
750 result
= wxNonOwnedWindowEventHandler( handler
, event
, data
) ;
753 case kEventClassMouse
:
754 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
764 DEFINE_ONE_SHOT_HANDLER_GETTER( wxNonOwnedEventHandler
)
766 // ---------------------------------------------------------------------------
767 // wxWindowMac utility functions
768 // ---------------------------------------------------------------------------
770 // Find an item given the Macintosh Window Reference
772 WX_DECLARE_HASH_MAP(WindowRef
, wxNonOwnedWindow
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
774 static MacWindowMap wxWinMacWindowList
;
776 wxNonOwnedWindow
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
778 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
780 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
783 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxNonOwnedWindow
*win
) ;
784 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxNonOwnedWindow
*win
)
786 // adding NULL WindowRef is (first) surely a result of an error and
788 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
790 wxWinMacWindowList
[inWindowRef
] = win
;
793 void wxRemoveMacWindowAssociation(wxNonOwnedWindow
*win
) ;
794 void wxRemoveMacWindowAssociation(wxNonOwnedWindow
*win
)
796 MacWindowMap::iterator it
;
797 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
799 if ( it
->second
== win
)
801 wxWinMacWindowList
.erase(it
);
807 // ----------------------------------------------------------------------------
808 // wxNonOwnedWindow creation
809 // ----------------------------------------------------------------------------
811 wxNonOwnedWindow
*wxNonOwnedWindow::s_macDeactivateWindow
= NULL
;
813 void wxNonOwnedWindow::Init()
816 m_macEventHandler
= NULL
;
819 wxMacDeferredWindowDeleter::wxMacDeferredWindowDeleter( WindowRef windowRef
)
821 m_macWindow
= windowRef
;
824 wxMacDeferredWindowDeleter::~wxMacDeferredWindowDeleter()
826 DisposeWindow( (WindowRef
) m_macWindow
) ;
829 bool wxNonOwnedWindow::Create(wxWindow
*parent
,
834 const wxString
& name
)
839 m_windowStyle
= style
;
843 m_windowId
= id
== -1 ? NewControlId() : id
;
845 DoMacCreateRealWindow( parent
, pos
, size
, style
, name
) ;
847 SetBackgroundColour(wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE
));
849 if (GetExtraStyle() & wxFRAME_EX_METAL
)
850 MacSetMetalAppearance(true);
853 parent
->AddChild(this);
858 wxNonOwnedWindow::~wxNonOwnedWindow()
863 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
865 wxPendingDelete
.Append( new wxMacDeferredWindowDeleter( (WindowRef
) m_macWindow
) ) ;
868 if ( m_macEventHandler
)
870 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
871 m_macEventHandler
= NULL
;
874 wxRemoveMacWindowAssociation( this ) ;
876 // avoid dangling refs
877 if ( s_macDeactivateWindow
== this )
878 s_macDeactivateWindow
= NULL
;
881 // ----------------------------------------------------------------------------
882 // wxNonOwnedWindow misc
883 // ----------------------------------------------------------------------------
885 wxPoint
wxNonOwnedWindow::GetClientAreaOrigin() const
887 return wxPoint(0, 0) ;
890 bool wxNonOwnedWindow::SetBackgroundColour(const wxColour
& c
)
893 if ( col
== wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
) )
894 col
= wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDocumentWindowBackground
));
895 else if ( col
== wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE
) )
896 col
= wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive
));
898 if ( !wxWindow::SetBackgroundColour(col
) && m_hasBgCol
)
901 if ( GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
903 if ( col
== wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDocumentWindowBackground
)) )
905 SetThemeWindowBackground( (WindowRef
) m_macWindow
, kThemeBrushDocumentWindowBackground
, false ) ;
906 SetBackgroundStyle(wxBG_STYLE_SYSTEM
);
908 else if ( col
== wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive
)) )
910 SetThemeWindowBackground( (WindowRef
) m_macWindow
, kThemeBrushDialogBackgroundActive
, false ) ;
911 SetBackgroundStyle(wxBG_STYLE_SYSTEM
);
917 void wxNonOwnedWindowInstallTopLevelWindowEventHandler(WindowRef window
, EventHandlerRef
* handler
, void *ref
)
919 InstallWindowEventHandler(window
, GetwxNonOwnedEventHandlerUPP(),
920 GetEventTypeCount(eventList
), eventList
, ref
, handler
);
923 void wxNonOwnedWindow::MacInstallTopLevelWindowEventHandler()
925 if ( m_macEventHandler
!= NULL
)
927 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
929 wxNonOwnedWindowInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow
),(EventHandlerRef
*)&m_macEventHandler
,this);
932 void wxNonOwnedWindow::MacCreateRealWindow(
936 const wxString
& name
)
938 DoMacCreateRealWindow( NULL
, pos
, size
, style
, name
);
941 void wxNonOwnedWindow::DoMacCreateRealWindow(
946 const wxString
& name
)
948 OSStatus err
= noErr
;
950 m_windowStyle
= style
;
958 wxRect display
= wxGetClientDisplayRect() ;
960 if ( x
== wxDefaultPosition
.x
)
963 if ( y
== wxDefaultPosition
.y
)
966 int w
= WidthDefault(size
.x
);
967 int h
= HeightDefault(size
.y
);
969 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
971 // translate the window attributes in the appropriate window class and attributes
972 WindowClass wclass
= 0;
973 WindowAttributes attr
= kWindowNoAttributes
;
974 WindowGroupRef group
= NULL
;
975 bool activationScopeSet
= false;
976 WindowActivationScope activationScope
= kWindowActivationScopeNone
;
978 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
981 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
982 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
983 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
986 if ( HasFlag( wxSTAY_ON_TOP
) )
987 wclass
= kUtilityWindowClass
;
989 wclass
= kFloatingWindowClass
;
991 if ( HasFlag(wxTINY_CAPTION_VERT
) )
992 attr
|= kWindowSideTitlebarAttribute
;
996 wclass
= kPlainWindowClass
;
997 activationScopeSet
= true;
998 activationScope
= kWindowActivationScopeNone
;
1001 else if ( HasFlag( wxPOPUP_WINDOW
) )
1003 if ( HasFlag( wxBORDER_NONE
) )
1005 wclass
= kHelpWindowClass
; // has no border
1006 attr
|= kWindowNoShadowAttribute
;
1010 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1012 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1013 // make sure we don't deactivate something
1014 activationScopeSet
= true;
1015 activationScope
= kWindowActivationScopeNone
;
1017 else if ( HasFlag( wxCAPTION
) )
1019 wclass
= kDocumentWindowClass
;
1020 attr
|= kWindowInWindowMenuAttribute
;
1022 else if ( HasFlag( wxFRAME_DRAWER
) )
1024 wclass
= kDrawerWindowClass
;
1028 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1029 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1031 wclass
= kDocumentWindowClass
;
1033 else if ( HasFlag( wxNO_BORDER
) )
1035 wclass
= kSimpleWindowClass
;
1039 wclass
= kPlainWindowClass
;
1043 if ( wclass
!= kPlainWindowClass
)
1045 if ( HasFlag( wxMINIMIZE_BOX
) )
1046 attr
|= kWindowCollapseBoxAttribute
;
1048 if ( HasFlag( wxMAXIMIZE_BOX
) )
1049 attr
|= kWindowFullZoomAttribute
;
1051 if ( HasFlag( wxRESIZE_BORDER
) )
1052 attr
|= kWindowResizableAttribute
;
1054 if ( HasFlag( wxCLOSE_BOX
) )
1055 attr
|= kWindowCloseBoxAttribute
;
1057 attr
|= kWindowLiveResizeAttribute
;
1059 if ( HasFlag(wxSTAY_ON_TOP
) )
1060 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1062 if ( HasFlag( wxFRAME_FLOAT_ON_PARENT
) )
1063 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1065 if ( group
== NULL
&& parent
!= NULL
)
1067 WindowRef parenttlw
= (WindowRef
) parent
->MacGetTopLevelWindowRef();
1069 group
= GetWindowGroupParent( GetWindowGroup( parenttlw
) );
1072 attr
|= kWindowCompositingAttribute
;
1073 #if 0 // wxMAC_USE_CORE_GRAPHICS ; TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1074 attr
|= kWindowFrameworkScaledAttribute
;
1077 if ( HasFlag(wxFRAME_SHAPED
) )
1079 WindowDefSpec customWindowDefSpec
;
1080 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1081 customWindowDefSpec
.u
.defProc
=
1083 (WindowDefUPP
) wxShapedMacWindowDef
;
1085 NewWindowDefUPP(wxShapedMacWindowDef
);
1087 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1088 attr
, &theBoundsRect
,
1089 (WindowRef
*) &m_macWindow
);
1093 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1096 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1097 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1099 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1101 // setup a separate group for each window, so that overlays can be handled easily
1103 WindowGroupRef overlaygroup
= NULL
;
1104 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &overlaygroup
));
1105 verify_noerr( SetWindowGroupParent( overlaygroup
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1106 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, overlaygroup
));
1108 if ( activationScopeSet
)
1110 verify_noerr( SetWindowActivationScope( (WindowRef
) m_macWindow
, activationScope
));
1113 // the create commands are only for content rect,
1114 // so we have to set the size again as structure bounds
1115 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1117 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1118 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1120 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1121 // the content view, so we have to retrieve it explicitly
1122 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1123 m_peer
->GetControlRefAddr() ) ;
1124 if ( !m_peer
->Ok() )
1126 // compatibility mode fallback
1127 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1130 // the root control level handler
1131 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1133 // Causes the inner part of the window not to be metal
1134 // if the style is used before window creation.
1135 #if 0 // TARGET_API_MAC_OSX
1136 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1138 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1139 MacSetMetalAppearance( true ) ;
1143 if ( m_macWindow
!= NULL
)
1145 MacSetUnifiedAppearance( true ) ;
1148 HIViewRef growBoxRef
= 0 ;
1149 err
= HIViewFindByID( HIViewGetRoot( (WindowRef
)m_macWindow
), kHIViewWindowGrowBoxID
, &growBoxRef
);
1150 if ( err
== noErr
&& growBoxRef
!= 0 )
1151 HIGrowBoxViewSetTransparent( growBoxRef
, true ) ;
1153 // the frame window event handler
1154 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1155 MacInstallTopLevelWindowEventHandler() ;
1157 DoSetWindowVariant( m_windowVariant
) ;
1161 if ( HasFlag(wxFRAME_SHAPED
) )
1163 // default shape matches the window size
1164 wxRegion
rgn( 0, 0, w
, h
);
1168 wxWindowCreateEvent
event(this);
1169 HandleWindowEvent(event
);
1172 // Raise the window to the top of the Z order
1173 void wxNonOwnedWindow::Raise()
1175 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1178 // Lower the window to the bottom of the Z order
1179 void wxNonOwnedWindow::Lower()
1181 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1184 void wxNonOwnedWindow::MacDelayedDeactivation(long timestamp
)
1186 if (s_macDeactivateWindow
)
1188 wxLogTrace(TRACE_ACTIVATE
,
1189 wxT("Doing delayed deactivation of %p"),
1190 s_macDeactivateWindow
);
1192 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1196 void wxNonOwnedWindow::MacActivate( long timestamp
, bool WXUNUSED(inIsActivating
) )
1198 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1200 if (s_macDeactivateWindow
== this)
1201 s_macDeactivateWindow
= NULL
;
1203 MacDelayedDeactivation(timestamp
);
1206 bool wxNonOwnedWindow::Show(bool show
)
1208 if ( !wxWindow::Show(show
) )
1211 bool plainTransition
= true;
1213 #if wxUSE_SYSTEM_OPTIONS
1214 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1215 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1220 if ( plainTransition
)
1221 ::ShowWindow( (WindowRef
)m_macWindow
);
1223 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1225 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1227 // because apps expect a size event to occur at this moment
1228 wxSizeEvent
event(GetSize() , m_windowId
);
1229 event
.SetEventObject(this);
1230 HandleWindowEvent(event
);
1234 if ( plainTransition
)
1235 ::HideWindow( (WindowRef
)m_macWindow
);
1237 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1243 bool wxNonOwnedWindow::MacShowWithEffect(bool show
,
1244 wxShowEffect effect
,
1247 if ( !wxWindow::Show(show
) )
1250 WindowTransitionEffect transition
= 0 ;
1253 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1254 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1255 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1256 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1257 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1258 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1259 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1260 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1261 transition
= kWindowGenieTransitionEffect
;
1263 case wxSHOW_EFFECT_BLEND
:
1264 transition
= kWindowFadeTransitionEffect
;
1266 case wxSHOW_EFFECT_EXPAND
:
1267 // having sheets would be fine, but this might lead to a repositioning
1270 transition
= kWindowSheetTransitionEffect
;
1273 transition
= kWindowZoomTransitionEffect
;
1276 case wxSHOW_EFFECT_MAX
:
1277 wxFAIL_MSG( "invalid effect flag" );
1281 TransitionWindowOptions options
;
1282 options
.version
= 0;
1283 options
.duration
= timeout
/ 1000.0;
1284 options
.window
= transition
== kWindowSheetTransitionEffect
? (WindowRef
) GetParent()->MacGetTopLevelWindowRef() :0;
1285 options
.userData
= 0;
1287 wxSize size
= wxGetDisplaySize();
1289 GetWindowBounds( (WindowRef
)m_macWindow
, kWindowStructureRgn
, &bounds
);
1290 CGRect hiBounds
= CGRectMake( bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
);
1294 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1295 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1296 hiBounds
.origin
.x
= 0;
1297 hiBounds
.size
.width
= 0;
1300 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1301 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1302 hiBounds
.origin
.x
= size
.x
;
1303 hiBounds
.size
.width
= 0;
1306 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1307 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1308 hiBounds
.origin
.y
= size
.y
;
1309 hiBounds
.size
.height
= 0;
1312 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1313 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1314 hiBounds
.origin
.y
= 0;
1315 hiBounds
.size
.height
= 0;
1319 break; // direction doesn't make sense
1322 ::TransitionWindowWithOptions
1324 (WindowRef
)m_macWindow
,
1326 show
? kWindowShowTransitionAction
: kWindowHideTransitionAction
,
1327 transition
== kWindowGenieTransitionEffect
? &hiBounds
: NULL
,
1334 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1336 // because apps expect a size event to occur at this moment
1337 wxSizeEvent
event(GetSize() , m_windowId
);
1338 event
.SetEventObject(this);
1339 HandleWindowEvent(event
);
1345 bool wxNonOwnedWindow::SetTransparent(wxByte alpha
)
1347 OSStatus result
= SetWindowAlpha((WindowRef
)m_macWindow
, (CGFloat
)((alpha
)/255.0));
1348 return result
== noErr
;
1352 bool wxNonOwnedWindow::CanSetTransparent()
1358 void wxNonOwnedWindow::SetExtraStyle(long exStyle
)
1360 if ( GetExtraStyle() == exStyle
)
1363 wxWindow::SetExtraStyle( exStyle
) ;
1365 if ( m_macWindow
!= NULL
)
1367 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1369 if ( MacGetMetalAppearance() != metal
)
1371 if ( MacGetUnifiedAppearance() )
1372 MacSetUnifiedAppearance( !metal
) ;
1374 MacSetMetalAppearance( metal
) ;
1379 bool wxNonOwnedWindow::SetBackgroundStyle(wxBackgroundStyle style
)
1381 if ( !wxWindow::SetBackgroundStyle(style
) )
1384 WindowRef windowRef
= HIViewGetWindow( (HIViewRef
)GetHandle() );
1386 if ( GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
1388 OSStatus err
= HIWindowChangeFeatures( windowRef
, 0, kWindowIsOpaque
);
1389 verify_noerr( err
);
1390 err
= ReshapeCustomWindow( windowRef
);
1391 verify_noerr( err
);
1397 // TODO: switch to structure bounds -
1398 // we are still using coordinates of the content view
1400 void wxNonOwnedWindow::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1402 Rect content
, structure
;
1404 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1405 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1407 left
= content
.left
- structure
.left
;
1408 top
= content
.top
- structure
.top
;
1409 right
= structure
.right
- content
.right
;
1410 bottom
= structure
.bottom
- content
.bottom
;
1413 void wxNonOwnedWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
1415 m_cachedClippedRectValid
= false ;
1416 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1417 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1418 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1421 void wxNonOwnedWindow::DoGetPosition( int *x
, int *y
) const
1425 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1433 void wxNonOwnedWindow::DoGetSize( int *width
, int *height
) const
1437 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1440 *width
= bounds
.right
- bounds
.left
;
1442 *height
= bounds
.bottom
- bounds
.top
;
1445 void wxNonOwnedWindow::DoGetClientSize( int *width
, int *height
) const
1449 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1452 *width
= bounds
.right
- bounds
.left
;
1454 *height
= bounds
.bottom
- bounds
.top
;
1457 void wxNonOwnedWindow::MacSetMetalAppearance( bool set
)
1459 if ( MacGetUnifiedAppearance() )
1460 MacSetUnifiedAppearance( false ) ;
1462 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1463 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1466 bool wxNonOwnedWindow::MacGetMetalAppearance() const
1468 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1471 void wxNonOwnedWindow::MacSetUnifiedAppearance( bool set
)
1473 if ( MacGetMetalAppearance() )
1474 MacSetMetalAppearance( false ) ;
1476 MacChangeWindowAttributes( set
? kWindowUnifiedTitleAndToolbarAttribute
: kWindowNoAttributes
,
1477 set
? kWindowNoAttributes
: kWindowUnifiedTitleAndToolbarAttribute
) ;
1479 // For some reason, Tiger uses white as the background color for this appearance,
1480 // while most apps using it use the typical striped background. Restore that behavior
1482 // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
1484 SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
) ) ;
1487 bool wxNonOwnedWindow::MacGetUnifiedAppearance() const
1489 return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute
;
1492 void wxNonOwnedWindow::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1494 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1497 wxUint32
wxNonOwnedWindow::MacGetWindowAttributes() const
1500 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1505 void wxNonOwnedWindow::MacPerformUpdates()
1507 // for composited windows this also triggers a redraw of all
1508 // invalid views in the window
1509 HIWindowFlush((WindowRef
) m_macWindow
) ;
1512 // ---------------------------------------------------------------------------
1513 // Shape implementation
1514 // ---------------------------------------------------------------------------
1517 bool wxNonOwnedWindow::SetShape(const wxRegion
& region
)
1519 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1520 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1522 // The empty region signifies that the shape
1523 // should be removed from the window.
1524 if ( region
.IsEmpty() )
1526 wxSize sz
= GetClientSize();
1527 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1528 if ( rgn
.IsEmpty() )
1531 return SetShape(rgn
);
1534 // Make a copy of the region
1535 RgnHandle shapeRegion
= NewRgn();
1536 HIShapeGetAsQDRgn( region
.GetWXHRGN(), shapeRegion
);
1538 // Dispose of any shape region we may already have
1539 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1543 // Save the region so we can use it later
1544 SetWRefCon((WindowRef
)MacGetWindowRef(), (URefCon
)shapeRegion
);
1546 // inform the window manager that the window has changed shape
1547 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1552 // ---------------------------------------------------------------------------
1553 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1554 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1555 // ---------------------------------------------------------------------------
1557 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1559 GetWindowPortBounds(window
, inRect
);
1560 Point pt
= { inRect
->top
,inRect
->left
};
1561 wxMacLocalToGlobal( window
, &pt
) ;
1562 inRect
->bottom
+= pt
.v
- inRect
->top
;
1563 inRect
->right
+= pt
.h
- inRect
->left
;
1565 inRect
->left
= pt
.h
;
1568 static SInt32
wxShapedMacWindowGetFeatures(WindowRef
WXUNUSED(window
), SInt32 param
)
1570 /*------------------------------------------------------
1571 Define which options your custom window supports.
1572 --------------------------------------------------------*/
1573 //just enable everything for our demo
1574 *(OptionBits
*)param
=
1577 kWindowCanCollapse
|
1578 //kWindowCanGetWindowRegion |
1579 //kWindowHasTitleBar |
1580 //kWindowSupportsDragHilite |
1581 kWindowCanDrawInCurrentPort
|
1582 //kWindowCanMeasureTitle |
1583 kWindowWantsDisposeAtProcessDeath
|
1584 kWindowSupportsGetGrowImageRegion
|
1585 kWindowDefSupportsColorGrafPort
;
1590 // The content region is left as a rectangle matching the window size, this is
1591 // so the origin in the paint event, and etc. still matches what the
1592 // programmer expects.
1593 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1596 wxNonOwnedWindow
* win
= wxFindWinFromMacWindow(window
);
1600 wxShapedMacWindowGetPos( window
, &r
) ;
1601 RectRgn( rgn
, &r
) ;
1605 // The structure region is set to the shape given to the SetShape method.
1606 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1608 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1614 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1615 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1616 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1617 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1621 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1623 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1628 switch (rgnRec
->regionCode
)
1630 case kWindowStructureRgn
:
1631 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1634 case kWindowContentRgn
:
1635 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1639 SetEmptyRgn(rgnRec
->winRgn
);
1646 // Determine the region of the window which was hit
1648 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1651 static RgnHandle tempRgn
= NULL
;
1653 if (tempRgn
== NULL
)
1656 // get the point clicked
1657 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1659 // Mac OS 8.5 or later
1660 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1661 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1664 // no significant area was hit
1668 static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode
), WindowRef window
, SInt16 message
, SInt32 param
)
1672 case kWindowMsgHitTest
:
1673 return wxShapedMacWindowHitTest(window
, param
);
1675 case kWindowMsgGetFeatures
:
1676 return wxShapedMacWindowGetFeatures(window
, param
);
1678 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1679 case kWindowMsgGetRegion
:
1680 return wxShapedMacWindowGetRegion(window
, param
);