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/mac/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 ( col
== wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDocumentWindowBackground
)) )
903 SetThemeWindowBackground( (WindowRef
) m_macWindow
, kThemeBrushDocumentWindowBackground
, false ) ;
904 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
906 else if ( col
== wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive
)) )
908 SetThemeWindowBackground( (WindowRef
) m_macWindow
, kThemeBrushDialogBackgroundActive
, false ) ;
909 SetBackgroundStyle(wxBG_STYLE_CUSTOM
);
913 SetBackgroundStyle(wxBG_STYLE_COLOUR
);
918 void wxNonOwnedWindowInstallTopLevelWindowEventHandler(WindowRef window
, EventHandlerRef
* handler
, void *ref
)
920 InstallWindowEventHandler(window
, GetwxNonOwnedEventHandlerUPP(),
921 GetEventTypeCount(eventList
), eventList
, ref
, handler
);
924 void wxNonOwnedWindow::MacInstallTopLevelWindowEventHandler()
926 if ( m_macEventHandler
!= NULL
)
928 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
930 wxNonOwnedWindowInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow
),(EventHandlerRef
*)&m_macEventHandler
,this);
933 void wxNonOwnedWindow::MacCreateRealWindow(
937 const wxString
& name
)
939 DoMacCreateRealWindow( NULL
, pos
, size
, style
, name
);
942 void wxNonOwnedWindow::DoMacCreateRealWindow(
947 const wxString
& name
)
949 OSStatus err
= noErr
;
951 m_windowStyle
= style
;
959 wxRect display
= wxGetClientDisplayRect() ;
961 if ( x
== wxDefaultPosition
.x
)
964 if ( y
== wxDefaultPosition
.y
)
967 int w
= WidthDefault(size
.x
);
968 int h
= HeightDefault(size
.y
);
970 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
972 // translate the window attributes in the appropriate window class and attributes
973 WindowClass wclass
= 0;
974 WindowAttributes attr
= kWindowNoAttributes
;
975 WindowGroupRef group
= NULL
;
976 bool activationScopeSet
= false;
977 WindowActivationScope activationScope
= kWindowActivationScopeNone
;
979 if ( HasFlag( wxFRAME_TOOL_WINDOW
) )
982 HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
983 HasFlag( wxSYSTEM_MENU
) || HasFlag( wxCAPTION
) ||
984 HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
)
987 if ( HasFlag( wxSTAY_ON_TOP
) )
988 wclass
= kUtilityWindowClass
;
990 wclass
= kFloatingWindowClass
;
992 if ( HasFlag(wxTINY_CAPTION_VERT
) )
993 attr
|= kWindowSideTitlebarAttribute
;
997 wclass
= kPlainWindowClass
;
998 activationScopeSet
= true;
999 activationScope
= kWindowActivationScopeNone
;
1002 else if ( HasFlag( wxPOPUP_WINDOW
) )
1005 // Until we've got a real wxPopupWindow class on wxMac make it a
1006 // little easier for wxFrame to be used to emulate it and workaround
1007 // the lack of wxPopupWindow.
1008 if ( HasFlag( wxBORDER_NONE
) )
1009 wclass
= kHelpWindowClass
; // has no border
1011 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1012 //attr |= kWindowNoShadowAttribute; // turn off the shadow Should we??
1013 group
= GetWindowGroupOfClass( // float above other windows
1014 kFloatingWindowClass
) ;
1016 else if ( HasFlag( wxCAPTION
) )
1018 wclass
= kDocumentWindowClass
;
1019 attr
|= kWindowInWindowMenuAttribute
;
1021 else if ( HasFlag( wxFRAME_DRAWER
) )
1023 wclass
= kDrawerWindowClass
;
1027 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) ||
1028 HasFlag( wxCLOSE_BOX
) || HasFlag( wxSYSTEM_MENU
) )
1030 wclass
= kDocumentWindowClass
;
1032 else if ( HasFlag( wxNO_BORDER
) )
1034 wclass
= kSimpleWindowClass
;
1038 wclass
= kPlainWindowClass
;
1042 if ( wclass
!= kPlainWindowClass
)
1044 if ( HasFlag( wxMINIMIZE_BOX
) )
1045 attr
|= kWindowCollapseBoxAttribute
;
1047 if ( HasFlag( wxMAXIMIZE_BOX
) )
1048 attr
|= kWindowFullZoomAttribute
;
1050 if ( HasFlag( wxRESIZE_BORDER
) )
1051 attr
|= kWindowResizableAttribute
;
1053 if ( HasFlag( wxCLOSE_BOX
) )
1054 attr
|= kWindowCloseBoxAttribute
;
1056 attr
|= kWindowLiveResizeAttribute
;
1058 if ( HasFlag(wxSTAY_ON_TOP
) )
1059 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1061 if ( HasFlag( wxFRAME_FLOAT_ON_PARENT
) )
1062 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1064 if ( group
== NULL
&& parent
!= NULL
)
1066 WindowRef parenttlw
= (WindowRef
) parent
->MacGetTopLevelWindowRef();
1068 group
= GetWindowGroupParent( GetWindowGroup( parenttlw
) );
1071 attr
|= kWindowCompositingAttribute
;
1072 #if 0 // wxMAC_USE_CORE_GRAPHICS ; TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1073 attr
|= kWindowFrameworkScaledAttribute
;
1076 if ( HasFlag(wxFRAME_SHAPED
) )
1078 WindowDefSpec customWindowDefSpec
;
1079 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1080 customWindowDefSpec
.u
.defProc
=
1082 (WindowDefUPP
) wxShapedMacWindowDef
;
1084 NewWindowDefUPP(wxShapedMacWindowDef
);
1086 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1087 attr
, &theBoundsRect
,
1088 (WindowRef
*) &m_macWindow
);
1092 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1095 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1096 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1098 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1100 // setup a separate group for each window, so that overlays can be handled easily
1102 WindowGroupRef overlaygroup
= NULL
;
1103 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &overlaygroup
));
1104 verify_noerr( SetWindowGroupParent( overlaygroup
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1105 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, overlaygroup
));
1107 if ( activationScopeSet
)
1109 verify_noerr( SetWindowActivationScope( (WindowRef
) m_macWindow
, activationScope
));
1112 // the create commands are only for content rect,
1113 // so we have to set the size again as structure bounds
1114 SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1116 wxAssociateWinWithMacWindow( (WindowRef
) m_macWindow
, this ) ;
1117 m_peer
= new wxMacControl(this , true /*isRootControl*/) ;
1119 // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of
1120 // the content view, so we have to retrieve it explicitly
1121 HIViewFindByID( HIViewGetRoot( (WindowRef
) m_macWindow
) , kHIViewWindowContentID
,
1122 m_peer
->GetControlRefAddr() ) ;
1123 if ( !m_peer
->Ok() )
1125 // compatibility mode fallback
1126 GetRootControl( (WindowRef
) m_macWindow
, m_peer
->GetControlRefAddr() ) ;
1129 // the root control level handler
1130 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() ) ;
1132 // Causes the inner part of the window not to be metal
1133 // if the style is used before window creation.
1134 #if 0 // TARGET_API_MAC_OSX
1135 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1137 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1138 MacSetMetalAppearance( true ) ;
1142 if ( m_macWindow
!= NULL
)
1144 MacSetUnifiedAppearance( true ) ;
1147 HIViewRef growBoxRef
= 0 ;
1148 err
= HIViewFindByID( HIViewGetRoot( (WindowRef
)m_macWindow
), kHIViewWindowGrowBoxID
, &growBoxRef
);
1149 if ( err
== noErr
&& growBoxRef
!= 0 )
1150 HIGrowBoxViewSetTransparent( growBoxRef
, true ) ;
1152 // the frame window event handler
1153 InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow
)) ) ;
1154 MacInstallTopLevelWindowEventHandler() ;
1156 DoSetWindowVariant( m_windowVariant
) ;
1160 if ( HasFlag(wxFRAME_SHAPED
) )
1162 // default shape matches the window size
1163 wxRegion
rgn( 0, 0, w
, h
);
1167 wxWindowCreateEvent
event(this);
1168 HandleWindowEvent(event
);
1171 // Raise the window to the top of the Z order
1172 void wxNonOwnedWindow::Raise()
1174 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1177 // Lower the window to the bottom of the Z order
1178 void wxNonOwnedWindow::Lower()
1180 ::SendBehind( (WindowRef
)m_macWindow
, NULL
) ;
1183 void wxNonOwnedWindow::MacDelayedDeactivation(long timestamp
)
1185 if (s_macDeactivateWindow
)
1187 wxLogTrace(TRACE_ACTIVATE
,
1188 wxT("Doing delayed deactivation of %p"),
1189 s_macDeactivateWindow
);
1191 s_macDeactivateWindow
->MacActivate(timestamp
, false);
1195 void wxNonOwnedWindow::MacActivate( long timestamp
, bool WXUNUSED(inIsActivating
) )
1197 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
1199 if (s_macDeactivateWindow
== this)
1200 s_macDeactivateWindow
= NULL
;
1202 MacDelayedDeactivation(timestamp
);
1205 bool wxNonOwnedWindow::Show(bool show
)
1207 if ( !wxWindow::Show(show
) )
1210 bool plainTransition
= true;
1212 #if wxUSE_SYSTEM_OPTIONS
1213 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
1214 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
1219 if ( plainTransition
)
1220 ::ShowWindow( (WindowRef
)m_macWindow
);
1222 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
1224 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1226 // because apps expect a size event to occur at this moment
1227 wxSizeEvent
event(GetSize() , m_windowId
);
1228 event
.SetEventObject(this);
1229 HandleWindowEvent(event
);
1233 if ( plainTransition
)
1234 ::HideWindow( (WindowRef
)m_macWindow
);
1236 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
1242 bool wxNonOwnedWindow::ShowWithEffect(wxShowEffect effect
,
1246 // TODO factor common code
1247 if ( !wxWindow::Show(true) )
1250 WindowTransitionEffect transition
= 0 ;
1253 case wxSHOW_EFFECT_ROLL
:
1254 case wxSHOW_EFFECT_SLIDE
:
1255 transition
= kWindowGenieTransitionEffect
;
1257 case wxSHOW_EFFECT_BLEND
:
1258 transition
= kWindowFadeTransitionEffect
;
1260 case wxSHOW_EFFECT_EXPAND
:
1262 // having sheets would be fine, but this might lead to a repositioning
1265 transition
= kWindowSheetTransitionEffect
;
1268 transition
= kWindowZoomTransitionEffect
;
1272 TransitionWindowOptions options
;
1273 options
.version
= 0;
1274 options
.duration
= timeout
/ 1000.0;
1275 options
.window
= transition
== kWindowSheetTransitionEffect
? (WindowRef
) GetParent()->MacGetTopLevelWindowRef() :0;
1276 options
.userData
= 0;
1278 wxSize size
= wxGetDisplaySize();
1280 GetWindowBounds( (WindowRef
)m_macWindow
, kWindowStructureRgn
, &bounds
);
1281 CGRect hiBounds
= CGRectMake( bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
);
1283 if ( dir
& wxRIGHT
)
1285 hiBounds
.origin
.x
= size
.x
;
1286 hiBounds
.size
.width
= 0;
1290 hiBounds
.origin
.y
= 0;
1291 hiBounds
.size
.height
= 0;
1295 hiBounds
.origin
.y
= size
.y
;
1296 hiBounds
.size
.height
= 0;
1300 hiBounds
.origin
.x
= 0;
1301 hiBounds
.size
.width
= 0;
1304 ::TransitionWindowWithOptions( (WindowRef
)m_macWindow
, transition
, kWindowShowTransitionAction
, transition
== kWindowGenieTransitionEffect
? &hiBounds
: NULL
,
1307 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1309 // because apps expect a size event to occur at this moment
1310 wxSizeEvent
event(GetSize() , m_windowId
);
1311 event
.SetEventObject(this);
1312 HandleWindowEvent(event
);
1317 bool wxNonOwnedWindow::HideWithEffect(wxShowEffect effect
,
1321 if ( !wxWindow::Show(false) )
1324 WindowTransitionEffect transition
= 0 ;
1327 case wxSHOW_EFFECT_ROLL
:
1328 case wxSHOW_EFFECT_SLIDE
:
1329 transition
= kWindowGenieTransitionEffect
;
1331 case wxSHOW_EFFECT_BLEND
:
1332 transition
= kWindowFadeTransitionEffect
;
1334 case wxSHOW_EFFECT_EXPAND
:
1338 transition
= kWindowSheetTransitionEffect
;
1341 transition
= kWindowZoomTransitionEffect
;
1344 TransitionWindowOptions options
;
1345 options
.version
= 0;
1346 options
.duration
= timeout
/ 1000.0;
1347 options
.window
= transition
== kWindowSheetTransitionEffect
? (WindowRef
) GetParent()->MacGetTopLevelWindowRef() :0;
1348 options
.userData
= 0;
1350 wxSize size
= wxGetDisplaySize();
1352 GetWindowBounds( (WindowRef
)m_macWindow
, kWindowStructureRgn
, &bounds
);
1353 CGRect hiBounds
= CGRectMake( bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
);
1355 if ( dir
& wxRIGHT
)
1357 hiBounds
.origin
.x
= size
.x
;
1358 hiBounds
.size
.width
= 0;
1362 hiBounds
.origin
.y
= 0;
1363 hiBounds
.size
.height
= 0;
1367 hiBounds
.origin
.y
= size
.y
;
1368 hiBounds
.size
.height
= 0;
1372 hiBounds
.origin
.x
= 0;
1373 hiBounds
.size
.width
= 0;
1375 ::TransitionWindowWithOptions( (WindowRef
)m_macWindow
, transition
, kWindowHideTransitionAction
, transition
== kWindowGenieTransitionEffect
? &hiBounds
: NULL
,
1381 bool wxNonOwnedWindow::SetTransparent(wxByte alpha
)
1383 OSStatus result
= SetWindowAlpha((WindowRef
)m_macWindow
, (CGFloat
)((alpha
)/255.0));
1384 return result
== noErr
;
1388 bool wxNonOwnedWindow::CanSetTransparent()
1394 void wxNonOwnedWindow::SetExtraStyle(long exStyle
)
1396 if ( GetExtraStyle() == exStyle
)
1399 wxWindow::SetExtraStyle( exStyle
) ;
1401 if ( m_macWindow
!= NULL
)
1403 bool metal
= GetExtraStyle() & wxFRAME_EX_METAL
;
1405 if ( MacGetMetalAppearance() != metal
)
1407 if ( MacGetUnifiedAppearance() )
1408 MacSetUnifiedAppearance( !metal
) ;
1410 MacSetMetalAppearance( metal
) ;
1415 bool wxNonOwnedWindow::SetBackgroundStyle(wxBackgroundStyle style
)
1417 if ( !wxWindow::SetBackgroundStyle(style
) )
1420 WindowRef windowRef
= HIViewGetWindow( (HIViewRef
)GetHandle() );
1422 if ( GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
1424 OSStatus err
= HIWindowChangeFeatures( windowRef
, 0, kWindowIsOpaque
);
1425 verify_noerr( err
);
1426 err
= ReshapeCustomWindow( windowRef
);
1427 verify_noerr( err
);
1433 // TODO: switch to structure bounds -
1434 // we are still using coordinates of the content view
1436 void wxNonOwnedWindow::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1438 Rect content
, structure
;
1440 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &structure
) ;
1441 GetWindowBounds( (WindowRef
) m_macWindow
, kWindowContentRgn
, &content
) ;
1443 left
= content
.left
- structure
.left
;
1444 top
= content
.top
- structure
.top
;
1445 right
= structure
.right
- content
.right
;
1446 bottom
= structure
.bottom
- content
.bottom
;
1449 void wxNonOwnedWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
1451 m_cachedClippedRectValid
= false ;
1452 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
1453 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1454 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1457 void wxNonOwnedWindow::DoGetPosition( int *x
, int *y
) const
1461 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1469 void wxNonOwnedWindow::DoGetSize( int *width
, int *height
) const
1473 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
1476 *width
= bounds
.right
- bounds
.left
;
1478 *height
= bounds
.bottom
- bounds
.top
;
1481 void wxNonOwnedWindow::DoGetClientSize( int *width
, int *height
) const
1485 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowContentRgn
, &bounds
)) ;
1488 *width
= bounds
.right
- bounds
.left
;
1490 *height
= bounds
.bottom
- bounds
.top
;
1493 void wxNonOwnedWindow::MacSetMetalAppearance( bool set
)
1495 if ( MacGetUnifiedAppearance() )
1496 MacSetUnifiedAppearance( false ) ;
1498 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
1499 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
1502 bool wxNonOwnedWindow::MacGetMetalAppearance() const
1504 return MacGetWindowAttributes() & kWindowMetalAttribute
;
1507 void wxNonOwnedWindow::MacSetUnifiedAppearance( bool set
)
1509 if ( MacGetMetalAppearance() )
1510 MacSetMetalAppearance( false ) ;
1512 MacChangeWindowAttributes( set
? kWindowUnifiedTitleAndToolbarAttribute
: kWindowNoAttributes
,
1513 set
? kWindowNoAttributes
: kWindowUnifiedTitleAndToolbarAttribute
) ;
1515 // For some reason, Tiger uses white as the background color for this appearance,
1516 // while most apps using it use the typical striped background. Restore that behavior
1518 // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
1520 SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
) ) ;
1523 bool wxNonOwnedWindow::MacGetUnifiedAppearance() const
1525 return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute
;
1528 void wxNonOwnedWindow::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
1530 ChangeWindowAttributes( (WindowRef
)m_macWindow
, attributesToSet
, attributesToClear
) ;
1533 wxUint32
wxNonOwnedWindow::MacGetWindowAttributes() const
1536 GetWindowAttributes( (WindowRef
) m_macWindow
, &attr
) ;
1541 void wxNonOwnedWindow::MacPerformUpdates()
1543 // for composited windows this also triggers a redraw of all
1544 // invalid views in the window
1545 HIWindowFlush((WindowRef
) m_macWindow
) ;
1548 // ---------------------------------------------------------------------------
1549 // Shape implementation
1550 // ---------------------------------------------------------------------------
1553 bool wxNonOwnedWindow::SetShape(const wxRegion
& region
)
1555 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1556 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1558 // The empty region signifies that the shape
1559 // should be removed from the window.
1560 if ( region
.IsEmpty() )
1562 wxSize sz
= GetClientSize();
1563 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
1564 if ( rgn
.IsEmpty() )
1567 return SetShape(rgn
);
1570 // Make a copy of the region
1571 RgnHandle shapeRegion
= NewRgn();
1572 HIShapeGetAsQDRgn( region
.GetWXHRGN(), shapeRegion
);
1574 // Dispose of any shape region we may already have
1575 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
)MacGetWindowRef() );
1579 // Save the region so we can use it later
1580 SetWRefCon((WindowRef
)MacGetWindowRef(), (URefCon
)shapeRegion
);
1582 // inform the window manager that the window has changed shape
1583 ReshapeCustomWindow((WindowRef
)MacGetWindowRef());
1588 // ---------------------------------------------------------------------------
1589 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1590 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1591 // ---------------------------------------------------------------------------
1593 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1595 GetWindowPortBounds(window
, inRect
);
1596 Point pt
= { inRect
->top
,inRect
->left
};
1597 wxMacLocalToGlobal( window
, &pt
) ;
1598 inRect
->bottom
+= pt
.v
- inRect
->top
;
1599 inRect
->right
+= pt
.h
- inRect
->left
;
1601 inRect
->left
= pt
.h
;
1604 static SInt32
wxShapedMacWindowGetFeatures(WindowRef
WXUNUSED(window
), SInt32 param
)
1606 /*------------------------------------------------------
1607 Define which options your custom window supports.
1608 --------------------------------------------------------*/
1609 //just enable everything for our demo
1610 *(OptionBits
*)param
=
1613 kWindowCanCollapse
|
1614 //kWindowCanGetWindowRegion |
1615 //kWindowHasTitleBar |
1616 //kWindowSupportsDragHilite |
1617 kWindowCanDrawInCurrentPort
|
1618 //kWindowCanMeasureTitle |
1619 kWindowWantsDisposeAtProcessDeath
|
1620 kWindowSupportsGetGrowImageRegion
|
1621 kWindowDefSupportsColorGrafPort
;
1626 // The content region is left as a rectangle matching the window size, this is
1627 // so the origin in the paint event, and etc. still matches what the
1628 // programmer expects.
1629 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1632 wxNonOwnedWindow
* win
= wxFindWinFromMacWindow(window
);
1636 wxShapedMacWindowGetPos( window
, &r
) ;
1637 RectRgn( rgn
, &r
) ;
1641 // The structure region is set to the shape given to the SetShape method.
1642 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1644 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1650 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1651 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1652 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1653 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1657 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1659 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1664 switch (rgnRec
->regionCode
)
1666 case kWindowStructureRgn
:
1667 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1670 case kWindowContentRgn
:
1671 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1675 SetEmptyRgn(rgnRec
->winRgn
);
1682 // Determine the region of the window which was hit
1684 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1687 static RgnHandle tempRgn
= NULL
;
1689 if (tempRgn
== NULL
)
1692 // get the point clicked
1693 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1695 // Mac OS 8.5 or later
1696 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1697 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1700 // no significant area was hit
1704 static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode
), WindowRef window
, SInt16 message
, SInt32 param
)
1708 case kWindowMsgHitTest
:
1709 return wxShapedMacWindowHitTest(window
, param
);
1711 case kWindowMsgGetFeatures
:
1712 return wxShapedMacWindowGetFeatures(window
, param
);
1714 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1715 case kWindowMsgGetRegion
:
1716 return wxShapedMacWindowGetRegion(window
, param
);