1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/nonownedwnd.cpp
3 // Purpose: implementation of wxNonOwnedWindow
4 // Author: Stefan Csomor
6 // Copyright: (c) Stefan Csomor 2008
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
17 #include "wx/hashmap.h"
18 #include "wx/evtloop.h"
19 #include "wx/tooltip.h"
20 #include "wx/nonownedwnd.h"
22 #include "wx/osx/private.h"
23 #include "wx/settings.h"
26 #if wxUSE_SYSTEM_OPTIONS
27 #include "wx/sysopt.h"
30 // ============================================================================
31 // wxNonOwnedWindow implementation
32 // ============================================================================
34 // unified title and toolbar constant - not in Tiger headers, so we duplicate it here
35 #define kWindowUnifiedTitleAndToolbarAttribute (1 << 7)
37 IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCarbonImpl
, wxNonOwnedWindowImpl
)
39 WXWindow
wxNonOwnedWindowCarbonImpl::GetWXWindow() const
41 return (WXWindow
) m_macWindow
;
43 void wxNonOwnedWindowCarbonImpl::Raise()
45 ::SelectWindow( m_macWindow
) ;
48 void wxNonOwnedWindowCarbonImpl::Lower()
50 ::SendBehind( m_macWindow
, NULL
) ;
53 void wxNonOwnedWindowCarbonImpl::ShowWithoutActivating()
55 bool plainTransition
= true;
57 #if wxUSE_SYSTEM_OPTIONS
58 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
59 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
62 if ( plainTransition
)
63 ::ShowWindow( (WindowRef
)m_macWindow
);
65 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
68 bool wxNonOwnedWindowCarbonImpl::Show(bool show
)
70 bool plainTransition
= true;
72 #if wxUSE_SYSTEM_OPTIONS
73 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
74 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
79 ShowWithoutActivating();
80 ::SelectWindow( (WindowRef
)m_macWindow
) ;
85 if ( plainTransition
)
86 ::HideWindow( (WindowRef
)m_macWindow
);
88 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
94 void wxNonOwnedWindowCarbonImpl::Update()
96 HIWindowFlush(m_macWindow
) ;
99 bool wxNonOwnedWindowCarbonImpl::SetTransparent(wxByte alpha
)
101 OSStatus result
= SetWindowAlpha((WindowRef
)m_macWindow
, (CGFloat
)((alpha
)/255.0));
102 return result
== noErr
;
105 bool wxNonOwnedWindowCarbonImpl::SetBackgroundColour(const wxColour
& col
)
107 if ( col
== wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDocumentWindowBackground
)) )
109 SetThemeWindowBackground( (WindowRef
) m_macWindow
, kThemeBrushDocumentWindowBackground
, false ) ;
110 m_wxPeer
->SetBackgroundStyle(wxBG_STYLE_SYSTEM
);
111 // call directly if object is not yet completely constructed
112 if ( m_wxPeer
->GetNonOwnedPeer() == NULL
)
113 SetBackgroundStyle(wxBG_STYLE_SYSTEM
);
115 else if ( col
== wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive
)) )
117 SetThemeWindowBackground( (WindowRef
) m_macWindow
, kThemeBrushDialogBackgroundActive
, false ) ;
118 m_wxPeer
->SetBackgroundStyle(wxBG_STYLE_SYSTEM
);
119 // call directly if object is not yet completely constructed
120 if ( m_wxPeer
->GetNonOwnedPeer() == NULL
)
121 SetBackgroundStyle(wxBG_STYLE_SYSTEM
);
126 void wxNonOwnedWindowCarbonImpl::SetExtraStyle( long exStyle
)
128 if ( m_macWindow
!= NULL
)
130 bool metal
= exStyle
& wxFRAME_EX_METAL
;
132 if ( MacGetMetalAppearance() != metal
)
134 if ( MacGetUnifiedAppearance() )
135 MacSetUnifiedAppearance( !metal
) ;
137 MacSetMetalAppearance( metal
) ;
142 bool wxNonOwnedWindowCarbonImpl::SetBackgroundStyle(wxBackgroundStyle style
)
144 if ( style
== wxBG_STYLE_TRANSPARENT
)
146 OSStatus err
= HIWindowChangeFeatures( m_macWindow
, 0, kWindowIsOpaque
);
148 err
= ReshapeCustomWindow( m_macWindow
);
155 bool wxNonOwnedWindowCarbonImpl::CanSetTransparent()
160 void wxNonOwnedWindowCarbonImpl::GetContentArea( int &left
, int &top
, int &width
, int &height
) const
162 Rect content
, structure
;
164 GetWindowBounds( m_macWindow
, kWindowStructureRgn
, &structure
) ;
165 GetWindowBounds( m_macWindow
, kWindowContentRgn
, &content
) ;
167 left
= content
.left
- structure
.left
;
168 top
= content
.top
- structure
.top
;
169 width
= content
.right
- content
.left
;
170 height
= content
.bottom
- content
.top
;
173 void wxNonOwnedWindowCarbonImpl::MoveWindow(int x
, int y
, int width
, int height
)
175 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
176 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
179 void wxNonOwnedWindowCarbonImpl::GetPosition( int &x
, int &y
) const
183 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
189 void wxNonOwnedWindowCarbonImpl::GetSize( int &width
, int &height
) const
193 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
195 width
= bounds
.right
- bounds
.left
;
196 height
= bounds
.bottom
- bounds
.top
;
199 bool wxNonOwnedWindowCarbonImpl::MacGetUnifiedAppearance() const
201 return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute
;
204 void wxNonOwnedWindowCarbonImpl::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
206 ChangeWindowAttributes( m_macWindow
, attributesToSet
, attributesToClear
) ;
209 wxUint32
wxNonOwnedWindowCarbonImpl::MacGetWindowAttributes() const
212 GetWindowAttributes( m_macWindow
, &attr
) ;
216 void wxNonOwnedWindowCarbonImpl::MacSetMetalAppearance( bool set
)
218 if ( MacGetUnifiedAppearance() )
219 MacSetUnifiedAppearance( false ) ;
221 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
222 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
225 bool wxNonOwnedWindowCarbonImpl::MacGetMetalAppearance() const
227 return MacGetWindowAttributes() & kWindowMetalAttribute
;
230 void wxNonOwnedWindowCarbonImpl::MacSetUnifiedAppearance( bool set
)
232 if ( MacGetMetalAppearance() )
233 MacSetMetalAppearance( false ) ;
235 MacChangeWindowAttributes( set
? kWindowUnifiedTitleAndToolbarAttribute
: kWindowNoAttributes
,
236 set
? kWindowNoAttributes
: kWindowUnifiedTitleAndToolbarAttribute
) ;
238 // For some reason, Tiger uses white as the background color for this appearance,
239 // while most apps using it use the typical striped background. Restore that behaviour
241 // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
243 // since when creating the peering is not yet completely set-up we call both setters
245 m_wxPeer
->SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
) ) ;
246 SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
) ) ;
250 // ----------------------------------------------------------------------------
252 // ----------------------------------------------------------------------------
254 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
256 WXDLLEXPORT
void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
);
258 // ---------------------------------------------------------------------------
260 // ---------------------------------------------------------------------------
262 static const EventTypeSpec eventList
[] =
264 // TODO: remove control related event like key and mouse (except for WindowLeave events)
266 { kEventClassKeyboard
, kEventRawKeyDown
} ,
267 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
268 { kEventClassKeyboard
, kEventRawKeyUp
} ,
269 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
271 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
272 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
274 { kEventClassWindow
, kEventWindowShown
} ,
275 { kEventClassWindow
, kEventWindowActivated
} ,
276 { kEventClassWindow
, kEventWindowDeactivated
} ,
277 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
278 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
279 { kEventClassWindow
, kEventWindowClose
} ,
280 { kEventClassWindow
, kEventWindowGetRegion
} ,
282 // we have to catch these events on the toplevel window level,
283 // as controls don't get the raw mouse events anymore
285 { kEventClassMouse
, kEventMouseDown
} ,
286 { kEventClassMouse
, kEventMouseUp
} ,
287 { kEventClassMouse
, kEventMouseWheelMoved
} ,
288 { kEventClassMouse
, kEventMouseMoved
} ,
289 { kEventClassMouse
, kEventMouseDragged
} ,
292 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
294 OSStatus result
= eventNotHandledErr
;
295 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
296 // FindFocus does not return the actual focus window, but the enclosing window
297 wxWindow
* focus
= wxWindow::DoFindFocus();
299 focus
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
301 unsigned char charCode
;
308 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
311 ByteCount dataSize
= 0 ;
312 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
315 int numChars
= dataSize
/ sizeof( UniChar
) + 1;
317 UniChar
* charBuf
= buf
;
319 if ( numChars
* 2 > 4 )
320 charBuf
= new UniChar
[ numChars
] ;
321 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
322 charBuf
[ numChars
- 1 ] = 0;
324 wxMBConvUTF16 converter
;
325 converter
.MB2WC( uniChar
, (const char*)charBuf
, 2 ) ;
327 if ( numChars
* 2 > 4 )
330 #endif // wxUSE_UNICODE
332 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
333 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
334 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
336 UInt32 message
= (keyCode
<< 8) + charCode
;
337 switch ( GetEventKind( event
) )
339 case kEventRawKeyRepeat
:
340 case kEventRawKeyDown
:
342 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
343 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
344 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
345 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
346 focus
, message
, modifiers
, when
, uniChar
[0] ) )
350 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
354 case kEventRawKeyUp
:
355 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
356 focus
, message
, modifiers
, when
, uniChar
[0] ) )
362 case kEventRawKeyModifiersChanged
:
364 wxKeyEvent
event(wxEVT_KEY_DOWN
);
366 event
.m_shiftDown
= modifiers
& shiftKey
;
367 event
.m_rawControlDown
= modifiers
& controlKey
;
368 event
.m_altDown
= modifiers
& optionKey
;
369 event
.m_controlDown
= event
.m_metaDown
= modifiers
& cmdKey
;
372 event
.m_uniChar
= uniChar
[0] ;
375 event
.SetTimestamp(when
);
376 event
.SetEventObject(focus
);
378 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
380 event
.m_keyCode
= WXK_RAW_CONTROL
;
381 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
382 focus
->HandleWindowEvent( event
) ;
384 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
386 event
.m_keyCode
= WXK_SHIFT
;
387 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
388 focus
->HandleWindowEvent( event
) ;
390 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
392 event
.m_keyCode
= WXK_ALT
;
393 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
394 focus
->HandleWindowEvent( event
) ;
396 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
398 event
.m_keyCode
= WXK_CONTROL
;
399 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
400 focus
->HandleWindowEvent( event
) ;
403 wxApp::s_lastModifiers
= modifiers
;
414 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
415 // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
418 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
420 EventMouseButton g_lastButton
= 0 ;
421 bool g_lastButtonWasFakeRight
= false ;
423 WXDLLEXPORT
void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
425 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
426 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
428 // these parameters are not given for all events
429 EventMouseButton button
= 0 ;
430 UInt32 clickCount
= 0 ;
431 UInt32 mouseChord
= 0;
433 cEvent
.GetParameter
<EventMouseButton
>( kEventParamMouseButton
, typeMouseButton
, &button
) ;
434 cEvent
.GetParameter
<UInt32
>( kEventParamClickCount
, typeUInt32
, &clickCount
) ;
435 // the chord is the state of the buttons pressed currently
436 cEvent
.GetParameter
<UInt32
>( kEventParamMouseChord
, typeUInt32
, &mouseChord
) ;
438 wxevent
.m_x
= screenMouseLocation
.h
;
439 wxevent
.m_y
= screenMouseLocation
.v
;
440 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
441 wxevent
.m_rawControlDown
= modifiers
& controlKey
;
442 wxevent
.m_altDown
= modifiers
& optionKey
;
443 wxevent
.m_controlDown
= wxevent
.m_metaDown
= modifiers
& cmdKey
;
444 wxevent
.m_clickCount
= clickCount
;
445 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
447 // a control click is interpreted as a right click
448 bool thisButtonIsFakeRight
= false ;
449 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
451 button
= kEventMouseButtonSecondary
;
452 thisButtonIsFakeRight
= true ;
455 // otherwise we report double clicks by connecting a left click with a ctrl-left click
456 if ( clickCount
> 1 && button
!= g_lastButton
)
459 // we must make sure that our synthetic 'right' button corresponds in
460 // mouse down, moved and mouse up, and does not deliver a right down and left up
462 if ( cEvent
.GetKind() == kEventMouseDown
)
464 g_lastButton
= button
;
465 g_lastButtonWasFakeRight
= thisButtonIsFakeRight
;
471 g_lastButtonWasFakeRight
= false ;
473 else if ( g_lastButton
== kEventMouseButtonSecondary
&& g_lastButtonWasFakeRight
)
474 button
= g_lastButton
;
476 // Adjust the chord mask to remove the primary button and add the
477 // secondary button. It is possible that the secondary button is
478 // already pressed, e.g. on a mouse connected to a laptop, but this
479 // possibility is ignored here:
480 if( thisButtonIsFakeRight
&& ( mouseChord
& 1U ) )
481 mouseChord
= ((mouseChord
& ~1U) | 2U);
484 wxevent
.m_leftDown
= true ;
486 wxevent
.m_rightDown
= true ;
488 wxevent
.m_middleDown
= true ;
490 // translate into wx types
491 switch ( cEvent
.GetKind() )
493 case kEventMouseDown
:
496 case kEventMouseButtonPrimary
:
497 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
500 case kEventMouseButtonSecondary
:
501 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
504 case kEventMouseButtonTertiary
:
505 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
516 case kEventMouseButtonPrimary
:
517 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
520 case kEventMouseButtonSecondary
:
521 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
524 case kEventMouseButtonTertiary
:
525 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
532 // TODO http://developer.apple.com/qa/qa2005/qa1453.html
533 // add declaration for 10.4 and change to kEventMouseScroll
534 case kEventMouseWheelMoved
:
536 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
538 EventMouseWheelAxis axis
= cEvent
.GetParameter
<EventMouseWheelAxis
>(kEventParamMouseWheelAxis
, typeMouseWheelAxis
) ;
539 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeSInt32
) ;
541 wxevent
.m_wheelRotation
= delta
;
542 wxevent
.m_wheelDelta
= 1;
543 wxevent
.m_linesPerAction
= 1;
544 wxevent
.m_columnsPerAction
= 1;
545 if ( axis
== kEventMouseWheelAxisX
)
546 wxevent
.m_wheelAxis
= wxMOUSE_WHEEL_HORIZONTAL
;
550 case kEventMouseEntered
:
551 case kEventMouseExited
:
552 case kEventMouseDragged
:
553 case kEventMouseMoved
:
554 wxevent
.SetEventType( wxEVT_MOTION
) ;
561 #define NEW_CAPTURE_HANDLING 1
564 wxMacTopLevelMouseEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
568 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
570 OSStatus result
= eventNotHandledErr
;
572 wxMacCarbonEvent
cEvent( event
) ;
574 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
575 Point windowMouseLocation
= screenMouseLocation
;
577 WindowRef window
= NULL
;
578 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
580 wxWindow
* currentMouseWindow
= NULL
;
581 ControlRef control
= NULL
;
583 #if NEW_CAPTURE_HANDLING
584 if ( wxApp::s_captureWindow
)
586 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
587 windowPart
= inContent
;
593 QDGlobalToLocalPoint( GetWindowPort( window
), &windowMouseLocation
);
595 if ( wxApp::s_captureWindow
596 #if !NEW_CAPTURE_HANDLING
597 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
601 currentMouseWindow
= wxApp::s_captureWindow
;
603 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
605 ControlPartCode part
;
606 control
= FindControlUnderMouse( windowMouseLocation
, window
, &part
) ;
607 // if there is no control below the mouse position, send the event to the toplevel window itself
610 currentMouseWindow
= (wxWindow
*) toplevelWindow
;
614 currentMouseWindow
= (wxWindow
*) wxFindWindowFromWXWidget( (WXWidget
) control
) ;
615 #ifndef __WXUNIVERSAL__
616 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
619 // for wxToolBar to function we have to send certaint events to it
620 // instead of its children (wxToolBarTools)
622 GetSuperControl(control
, &parent
);
623 wxWindow
*wxparent
= (wxWindow
*) wxFindWindowFromWXWidget((WXWidget
) parent
) ;
624 if ( wxparent
&& wxparent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
625 currentMouseWindow
= wxparent
;
631 // disabled windows must not get any input messages
632 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
633 currentMouseWindow
= NULL
;
637 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
638 SetupMouseEvent( wxevent
, cEvent
) ;
640 // handle all enter / leave events
642 if ( currentMouseWindow
!= g_MacLastWindow
)
644 if ( g_MacLastWindow
)
646 wxMouseEvent
eventleave(wxevent
);
647 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
648 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
649 eventleave
.SetEventObject( g_MacLastWindow
) ;
650 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
653 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
656 g_MacLastWindow
->HandleWindowEvent(eventleave
);
659 if ( currentMouseWindow
)
661 wxMouseEvent
evententer(wxevent
);
662 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
663 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
664 evententer
.SetEventObject( currentMouseWindow
) ;
665 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
668 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
671 currentMouseWindow
->HandleWindowEvent(evententer
);
674 g_MacLastWindow
= currentMouseWindow
;
677 if ( windowPart
== inMenuBar
)
679 // special case menu bar, as we are having a low-level runloop we must do it ourselves
680 if ( cEvent
.GetKind() == kEventMouseDown
)
682 ::MenuSelect( screenMouseLocation
) ;
687 else if ( window
&& windowPart
== inProxyIcon
)
689 // special case proxy icon bar, as we are having a low-level runloop we must do it ourselves
690 if ( cEvent
.GetKind() == kEventMouseDown
)
692 if ( ::TrackWindowProxyDrag( window
, screenMouseLocation
) != errUserWantsToDragWindow
)
694 // TODO Track change of file path and report back
699 else if ( currentMouseWindow
)
701 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
703 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
705 wxevent
.SetEventObject( currentMouseWindow
) ;
706 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
708 // make tooltips current
711 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
712 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
715 if ( currentMouseWindow
->HandleWindowEvent(wxevent
) )
717 if ( currentMouseWindowParent
&&
718 !currentMouseWindowParent
->GetChildren().Member(currentMouseWindow
) )
719 currentMouseWindow
= NULL
;
725 // if the user code did _not_ handle the event, then perform the
726 // default processing
727 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
729 // ... that is set focus to this window
730 if (currentMouseWindow
->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
731 currentMouseWindow
->SetFocus();
735 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
737 wxApp::s_captureWindow
= NULL
;
743 wxWindow
* cursorTarget
= currentMouseWindow
;
744 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
746 extern wxCursor gGlobalCursor
;
748 if (!gGlobalCursor
.IsOk())
750 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
752 cursorTarget
= cursorTarget
->GetParent() ;
754 cursorPoint
+= cursorTarget
->GetPosition();
759 else // currentMouseWindow == NULL
761 if (toplevelWindow
&& !control
)
763 extern wxCursor gGlobalCursor
;
764 if (!gGlobalCursor
.IsOk())
766 // update cursor when over toolbar and titlebar etc.
767 wxSTANDARD_CURSOR
->MacInstall() ;
771 // don't mess with controls we don't know about
772 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
773 // so we try sending them the correct control directly
774 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
776 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
777 Point clickLocation
= windowMouseLocation
;
780 hiPoint
.x
= clickLocation
.h
;
781 hiPoint
.y
= clickLocation
.v
;
782 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
783 clickLocation
.h
= (int)hiPoint
.x
;
784 clickLocation
.v
= (int)hiPoint
.y
;
786 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
794 static pascal OSStatus
795 wxNonOwnedWindowEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
799 OSStatus result
= eventNotHandledErr
;
801 wxMacCarbonEvent
cEvent( event
) ;
803 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
804 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
806 switch ( GetEventKind( event
) )
808 case kEventWindowActivated
:
810 toplevelWindow
->HandleActivated( cEvent
.GetTicks() , true) ;
811 // we still sending an eventNotHandledErr in order to allow for default processing
815 case kEventWindowDeactivated
:
817 toplevelWindow
->HandleActivated( cEvent
.GetTicks() , false) ;
818 // we still sending an eventNotHandledErr in order to allow for default processing
822 case kEventWindowShown
:
823 toplevelWindow
->Refresh() ;
827 case kEventWindowClose
:
828 toplevelWindow
->Close() ;
832 case kEventWindowBoundsChanged
:
834 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
835 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
836 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
837 if ( attributes
& kWindowBoundsChangeSizeChanged
)
839 toplevelWindow
->HandleResized(cEvent
.GetTicks() ) ;
842 if ( attributes
& kWindowBoundsChangeOriginChanged
)
844 toplevelWindow
->HandleMoved(cEvent
.GetTicks() ) ;
851 case kEventWindowBoundsChanging
:
853 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
854 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
856 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
858 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
859 int left
, top
, width
, height
;
863 toplevelWindow
->GetNonOwnedPeer()->GetContentArea(left
, top
, width
, height
);
864 toplevelWindow
->GetNonOwnedPeer()->GetSize(swidth
, sheight
);
865 int deltawidth
= swidth
- width
;
866 int deltaheight
= sheight
- height
;
870 newRect
.right
- newRect
.left
+ deltawidth
,
871 newRect
.bottom
- newRect
.top
+ deltaheight
) ;
873 toplevelWindow
->HandleResizing( cEvent
.GetTicks(), &adjustR
);
875 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ top
+ adjustR
.height
- deltaheight
,
876 adjustR
.x
+ left
+ adjustR
.width
- deltawidth
} ;
877 if ( !EqualRect( &newRect
, &adjustedRect
) )
878 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
885 case kEventWindowGetRegion
:
887 if ( toplevelWindow
->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
889 WindowRegionCode windowRegionCode
;
891 // Fetch the region code that is being queried
892 GetEventParameter( event
,
893 kEventParamWindowRegionCode
,
894 typeWindowRegionCode
, NULL
,
895 sizeof windowRegionCode
, NULL
,
896 &windowRegionCode
) ;
898 // If it is the opaque region code then set the
899 // region to empty and return noErr to stop event
901 if ( windowRegionCode
== kWindowOpaqueRgn
) {
903 GetEventParameter( event
,
904 kEventParamRgnHandle
,
905 typeQDRgnHandle
, NULL
,
908 SetEmptyRgn(region
) ;
922 // mix this in from window.cpp
923 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
925 static pascal OSStatus
wxNonOwnedEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
927 OSStatus result
= eventNotHandledErr
;
929 switch ( GetEventClass( event
) )
931 case kEventClassTextInput
:
933 // TODO remove as soon as all events are on implementation classes only
934 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
936 result
= wxMacUnicodeTextEventHandler( handler
, event
, toplevelWindow
) ;
940 case kEventClassKeyboard
:
941 result
= KeyboardEventHandler( handler
, event
, data
) ;
944 case kEventClassWindow
:
945 result
= wxNonOwnedWindowEventHandler( handler
, event
, data
) ;
948 case kEventClassMouse
:
949 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
959 DEFINE_ONE_SHOT_HANDLER_GETTER( wxNonOwnedEventHandler
)
961 // ---------------------------------------------------------------------------
962 // Support functions for shaped windows, based on Apple's CustomWindow sample at
963 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
964 // ---------------------------------------------------------------------------
966 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
968 GetWindowPortBounds(window
, inRect
);
969 Point pt
= { inRect
->top
,inRect
->left
};
970 QDLocalToGlobalPoint( GetWindowPort( window
), &pt
);
971 inRect
->bottom
+= pt
.v
- inRect
->top
;
972 inRect
->right
+= pt
.h
- inRect
->left
;
977 static SInt32
wxShapedMacWindowGetFeatures(WindowRef
WXUNUSED(window
), SInt32 param
)
979 /*------------------------------------------------------
980 Define which options your custom window supports.
981 --------------------------------------------------------*/
982 //just enable everything for our demo
983 *(OptionBits
*)param
=
987 //kWindowCanGetWindowRegion |
988 //kWindowHasTitleBar |
989 //kWindowSupportsDragHilite |
990 kWindowCanDrawInCurrentPort
|
991 //kWindowCanMeasureTitle |
992 kWindowWantsDisposeAtProcessDeath
|
993 kWindowSupportsGetGrowImageRegion
|
994 kWindowDefSupportsColorGrafPort
;
999 // The content region is left as a rectangle matching the window size, this is
1000 // so the origin in the paint event, and etc. still matches what the
1001 // programmer expects.
1002 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1005 wxNonOwnedWindow
* win
= wxNonOwnedWindow::GetFromWXWindow((WXWindow
)window
);
1009 wxShapedMacWindowGetPos( window
, &r
) ;
1010 RectRgn( rgn
, &r
) ;
1014 // The structure region is set to the shape given to the SetShape method.
1015 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1017 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1023 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1024 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1025 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1026 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1030 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1032 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1037 switch (rgnRec
->regionCode
)
1039 case kWindowStructureRgn
:
1040 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1043 case kWindowContentRgn
:
1044 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1048 SetEmptyRgn(rgnRec
->winRgn
);
1055 // Determine the region of the window which was hit
1057 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1060 static RgnHandle tempRgn
= NULL
;
1062 if (tempRgn
== NULL
)
1065 // get the point clicked
1066 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1068 // Mac OS 8.5 or later
1069 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1070 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1073 // no significant area was hit
1077 static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode
), WindowRef window
, SInt16 message
, SInt32 param
)
1081 case kWindowMsgHitTest
:
1082 return wxShapedMacWindowHitTest(window
, param
);
1084 case kWindowMsgGetFeatures
:
1085 return wxShapedMacWindowGetFeatures(window
, param
);
1087 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1088 case kWindowMsgGetRegion
:
1089 return wxShapedMacWindowGetRegion(window
, param
);
1102 wxPoint m_position
;
1104 bool m_wasResizable
;
1107 wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl()
1111 wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl( wxNonOwnedWindow
* nonownedwnd
) : wxNonOwnedWindowImpl( nonownedwnd
)
1113 m_macEventHandler
= NULL
;
1115 m_macFullScreenData
= NULL
;
1118 wxNonOwnedWindowCarbonImpl::~wxNonOwnedWindowCarbonImpl()
1121 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
1124 if ( m_macEventHandler
)
1126 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1127 m_macEventHandler
= NULL
;
1130 if ( m_macWindow
&& !m_wxPeer
->IsNativeWindowWrapper())
1131 DisposeWindow( m_macWindow
);
1133 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1135 m_macFullScreenData
= NULL
;
1141 void wxNonOwnedWindowCarbonImpl::WillBeDestroyed()
1143 if ( m_macEventHandler
)
1145 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1146 m_macEventHandler
= NULL
;
1150 static void wxNonOwnedWindowInstallTopLevelWindowEventHandler(WindowRef window
, EventHandlerRef
* handler
, void *ref
)
1152 InstallWindowEventHandler(window
, GetwxNonOwnedEventHandlerUPP(),
1153 GetEventTypeCount(eventList
), eventList
, ref
, handler
);
1156 bool wxNonOwnedWindowCarbonImpl::SetShape(const wxRegion
& region
)
1158 // Make a copy of the region
1159 RgnHandle shapeRegion
= NewRgn();
1160 HIShapeGetAsQDRgn( region
.GetWXHRGN(), shapeRegion
);
1162 // Dispose of any shape region we may already have
1163 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
) m_wxPeer
->GetWXWindow() );
1167 // Save the region so we can use it later
1168 SetWRefCon((WindowRef
) m_wxPeer
->GetWXWindow(), (URefCon
)shapeRegion
);
1170 // inform the window manager that the window has changed shape
1171 ReshapeCustomWindow((WindowRef
) m_wxPeer
->GetWXWindow());
1177 void wxNonOwnedWindowCarbonImpl::MacInstallTopLevelWindowEventHandler()
1179 if ( m_macEventHandler
!= NULL
)
1181 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1183 wxNonOwnedWindowInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow
),(EventHandlerRef
*)&m_macEventHandler
,this);
1186 void wxNonOwnedWindowCarbonImpl::Create(
1187 wxWindow
* WXUNUSED(parent
),
1188 WXWindow nativeWindow
)
1190 m_macWindow
= nativeWindow
;
1193 void wxNonOwnedWindowCarbonImpl::Create(
1197 long style
, long extraStyle
,
1198 const wxString
& WXUNUSED(name
) )
1201 OSStatus err
= noErr
;
1210 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1212 // translate the window attributes in the appropriate window class and attributes
1213 WindowClass wclass
= 0;
1214 WindowAttributes attr
= kWindowNoAttributes
;
1215 WindowGroupRef group
= NULL
;
1216 bool activationScopeSet
= false;
1217 WindowActivationScope activationScope
= kWindowActivationScopeNone
;
1219 if ( style
& wxFRAME_TOOL_WINDOW
)
1222 ( style
& wxMINIMIZE_BOX
) || ( style
& wxMAXIMIZE_BOX
) ||
1223 ( style
& wxSYSTEM_MENU
) || ( style
& wxCAPTION
) ||
1224 ( style
& wxTINY_CAPTION
)
1227 if ( ( style
& wxSTAY_ON_TOP
) )
1228 wclass
= kUtilityWindowClass
;
1230 wclass
= kFloatingWindowClass
;
1232 if ( ( style
& wxTINY_CAPTION
) )
1233 attr
|= kWindowSideTitlebarAttribute
;
1237 if ( style
& wxNO_BORDER
)
1239 wclass
= kSimpleWindowClass
;
1243 wclass
= kPlainWindowClass
;
1245 activationScopeSet
= true;
1246 activationScope
= kWindowActivationScopeNone
;
1249 else if ( ( style
& wxPOPUP_WINDOW
) )
1251 if ( ( style
& wxBORDER_NONE
) )
1253 wclass
= kHelpWindowClass
; // has no border
1254 attr
|= kWindowNoShadowAttribute
;
1258 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1260 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1261 // make sure we don't deactivate something
1262 activationScopeSet
= true;
1263 activationScope
= kWindowActivationScopeNone
;
1265 else if ( ( style
& wxCAPTION
) )
1267 wclass
= kDocumentWindowClass
;
1268 attr
|= kWindowInWindowMenuAttribute
;
1270 else if ( ( style
& wxFRAME_DRAWER
) )
1272 wclass
= kDrawerWindowClass
;
1276 if ( ( style
& wxMINIMIZE_BOX
) || ( style
& wxMAXIMIZE_BOX
) ||
1277 ( style
& wxCLOSE_BOX
) || ( style
& wxSYSTEM_MENU
) )
1279 wclass
= kDocumentWindowClass
;
1281 else if ( ( style
& wxNO_BORDER
) )
1283 wclass
= kSimpleWindowClass
;
1287 wclass
= kPlainWindowClass
;
1291 if ( wclass
!= kPlainWindowClass
)
1293 if ( ( style
& wxMINIMIZE_BOX
) )
1294 attr
|= kWindowCollapseBoxAttribute
;
1296 if ( ( style
& wxMAXIMIZE_BOX
) )
1297 attr
|= kWindowFullZoomAttribute
;
1299 if ( ( style
& wxRESIZE_BORDER
) )
1300 attr
|= kWindowResizableAttribute
;
1302 if ( ( style
& wxCLOSE_BOX
) )
1303 attr
|= kWindowCloseBoxAttribute
;
1305 attr
|= kWindowLiveResizeAttribute
;
1307 if ( ( style
&wxSTAY_ON_TOP
) )
1308 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1310 if ( ( style
& wxFRAME_FLOAT_ON_PARENT
) )
1311 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1313 if ( group
== NULL
&& parent
!= NULL
)
1315 WindowRef parenttlw
= (WindowRef
) parent
->MacGetTopLevelWindowRef();
1317 group
= GetWindowGroupParent( GetWindowGroup( parenttlw
) );
1320 attr
|= kWindowCompositingAttribute
;
1321 #if 0 // TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1322 attr
|= kWindowFrameworkScaledAttribute
;
1325 if ( ( style
&wxFRAME_SHAPED
) )
1327 WindowDefSpec customWindowDefSpec
;
1328 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1329 customWindowDefSpec
.u
.defProc
=
1331 (WindowDefUPP
) wxShapedMacWindowDef
;
1333 NewWindowDefUPP(wxShapedMacWindowDef
);
1335 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1336 attr
, &theBoundsRect
,
1337 (WindowRef
*) &m_macWindow
);
1341 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1344 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1345 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1347 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1349 // setup a separate group for each window, so that overlays can be handled easily
1351 WindowGroupRef overlaygroup
= NULL
;
1352 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &overlaygroup
));
1353 verify_noerr( SetWindowGroupParent( overlaygroup
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1354 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, overlaygroup
));
1356 if ( activationScopeSet
)
1358 verify_noerr( SetWindowActivationScope( (WindowRef
) m_macWindow
, activationScope
));
1361 // the create commands are only for content rect,
1362 // so we have to set the size again as structure bounds
1363 SetWindowBounds( m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1365 // Causes the inner part of the window not to be metal
1366 // if the style is used before window creation.
1367 #if 0 // TARGET_API_MAC_OSX
1368 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1370 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1371 MacSetMetalAppearance( true ) ;
1375 if ( m_macWindow
!= NULL
)
1377 MacSetUnifiedAppearance( true ) ;
1380 HIViewRef growBoxRef
= 0 ;
1381 err
= HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowGrowBoxID
, &growBoxRef
);
1382 if ( err
== noErr
&& growBoxRef
!= 0 )
1383 HIGrowBoxViewSetTransparent( growBoxRef
, true ) ;
1385 // the frame window event handler
1386 InstallStandardEventHandler( GetWindowEventTarget(m_macWindow
) ) ;
1387 MacInstallTopLevelWindowEventHandler() ;
1389 if ( extraStyle
& wxFRAME_EX_METAL
)
1390 MacSetMetalAppearance(true);
1392 if ( ( style
&wxFRAME_SHAPED
) )
1394 // default shape matches the window size
1395 wxRegion
rgn( 0, 0, w
, h
);
1400 bool wxNonOwnedWindowCarbonImpl::ShowWithEffect(bool show
,
1401 wxShowEffect effect
,
1404 WindowTransitionEffect transition
= 0 ;
1407 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1408 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1409 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1410 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1411 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1412 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1413 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1414 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1415 transition
= kWindowGenieTransitionEffect
;
1417 case wxSHOW_EFFECT_BLEND
:
1418 transition
= kWindowFadeTransitionEffect
;
1420 case wxSHOW_EFFECT_EXPAND
:
1421 // having sheets would be fine, but this might lead to a repositioning
1424 transition
= kWindowSheetTransitionEffect
;
1427 transition
= kWindowZoomTransitionEffect
;
1430 case wxSHOW_EFFECT_NONE
:
1431 // wxNonOwnedWindow is supposed to call Show() itself in this case
1432 wxFAIL_MSG( "ShowWithEffect() shouldn't be called" );
1435 case wxSHOW_EFFECT_MAX
:
1436 wxFAIL_MSG( "invalid effect flag" );
1440 TransitionWindowOptions options
;
1441 options
.version
= 0;
1442 options
.duration
= timeout
/ 1000.0;
1443 options
.window
= transition
== kWindowSheetTransitionEffect
? (WindowRef
) m_wxPeer
->GetParent()->MacGetTopLevelWindowRef() :0;
1444 options
.userData
= 0;
1446 wxSize size
= wxGetDisplaySize();
1448 GetWindowBounds( (WindowRef
)m_macWindow
, kWindowStructureRgn
, &bounds
);
1449 CGRect hiBounds
= CGRectMake( bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
);
1453 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1454 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1455 hiBounds
.origin
.x
= 0;
1456 hiBounds
.size
.width
= 0;
1459 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1460 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1461 hiBounds
.origin
.x
= size
.x
;
1462 hiBounds
.size
.width
= 0;
1465 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1466 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1467 hiBounds
.origin
.y
= size
.y
;
1468 hiBounds
.size
.height
= 0;
1471 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1472 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1473 hiBounds
.origin
.y
= 0;
1474 hiBounds
.size
.height
= 0;
1478 break; // direction doesn't make sense
1481 ::TransitionWindowWithOptions
1483 (WindowRef
)m_macWindow
,
1485 show
? kWindowShowTransitionAction
: kWindowHideTransitionAction
,
1486 transition
== kWindowGenieTransitionEffect
? &hiBounds
: NULL
,
1493 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1499 void wxNonOwnedWindowCarbonImpl::SetTitle( const wxString
& title
, wxFontEncoding encoding
)
1501 SetWindowTitleWithCFString( m_macWindow
, wxCFStringRef( title
, encoding
) ) ;
1504 bool wxNonOwnedWindowCarbonImpl::IsMaximized() const
1506 return IsWindowInStandardState( m_macWindow
, NULL
, NULL
) ;
1509 bool wxNonOwnedWindowCarbonImpl::IsIconized() const
1511 return IsWindowCollapsed((WindowRef
)GetWXWindow() ) ;
1514 void wxNonOwnedWindowCarbonImpl::Iconize( bool iconize
)
1516 if ( IsWindowCollapsable( m_macWindow
) )
1517 CollapseWindow( m_macWindow
, iconize
) ;
1520 void wxNonOwnedWindowCarbonImpl::Maximize(bool maximize
)
1522 Point idealSize
= { 0 , 0 } ;
1525 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1527 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
1529 idealSize
.h
= bounds
.size
.width
;
1530 idealSize
.v
= bounds
.size
.height
;
1533 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
1534 idealSize
.h
= rect
.right
- rect
.left
;
1535 idealSize
.v
= rect
.bottom
- rect
.top
;
1538 ZoomWindowIdeal( (WindowRef
)GetWXWindow() , maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
1541 bool wxNonOwnedWindowCarbonImpl::IsFullScreen() const
1543 return m_macFullScreenData
!= NULL
;
1546 bool wxNonOwnedWindowCarbonImpl::ShowFullScreen(bool show
, long style
)
1550 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1552 data
= new FullScreenData() ;
1554 m_macFullScreenData
= data
;
1555 data
->m_position
= m_wxPeer
->GetPosition() ;
1556 data
->m_size
= m_wxPeer
->GetSize() ;
1557 #if wxOSX_USE_CARBON
1558 WindowAttributes attr
= 0;
1559 GetWindowAttributes((WindowRef
) GetWXWindow(), &attr
);
1560 data
->m_wasResizable
= attr
& kWindowResizableAttribute
;
1561 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1565 wxRect client
= wxGetClientDisplayRect() ;
1567 int left
, top
, width
, height
;
1575 GetContentArea( left
, top
, width
, height
) ;
1576 int outerwidth
, outerheight
;
1577 GetSize( outerwidth
, outerheight
);
1579 if ( style
& wxFULLSCREEN_NOCAPTION
)
1583 // avoid adding the caption twice to the height
1587 if ( style
& wxFULLSCREEN_NOBORDER
)
1590 w
+= outerwidth
- width
;
1591 h
+= outerheight
- height
;
1594 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1599 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1604 m_wxPeer
->SetSize( x
, y
, w
, h
) ;
1605 if ( data
->m_wasResizable
)
1607 #if wxOSX_USE_CARBON
1608 ChangeWindowAttributes( (WindowRef
) GetWXWindow() , kWindowNoAttributes
, kWindowResizableAttribute
) ;
1612 else if ( m_macFullScreenData
!= NULL
)
1614 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1615 #if wxOSX_USE_CARBON
1617 if ( data
->m_wasResizable
)
1618 ChangeWindowAttributes( (WindowRef
) GetWXWindow() , kWindowResizableAttribute
, kWindowNoAttributes
) ;
1620 m_wxPeer
->SetPosition( data
->m_position
) ;
1621 m_wxPeer
->SetSize( data
->m_size
) ;
1624 m_macFullScreenData
= NULL
;
1630 // Attracts the users attention to this window if the application is
1631 // inactive (should be called when a background event occurs)
1633 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1636 DisposePtr( (Ptr
)ptr
) ;
1639 void wxNonOwnedWindowCarbonImpl::RequestUserAttention(int WXUNUSED(flags
))
1641 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1643 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1644 notificationRequest
->qType
= nmType
;
1645 notificationRequest
->nmMark
= 1 ;
1646 notificationRequest
->nmIcon
= 0 ;
1647 notificationRequest
->nmSound
= 0 ;
1648 notificationRequest
->nmStr
= NULL
;
1649 notificationRequest
->nmResp
= wxMacNMResponse
;
1651 verify_noerr( NMInstall( notificationRequest
) ) ;
1654 void wxNonOwnedWindowCarbonImpl::ScreenToWindow( int *x
, int *y
)
1656 HIPoint p
= CGPointMake( (x
? *x
: 0), (y
? *y
: 0) );
1657 HIViewRef contentView
;
1658 // TODO check toolbar offset
1659 HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowContentID
, &contentView
) ;
1660 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
1667 void wxNonOwnedWindowCarbonImpl::WindowToScreen( int *x
, int *y
)
1669 HIPoint p
= CGPointMake( (x
? *x
: 0), (y
? *y
: 0) );
1670 HIViewRef contentView
;
1671 // TODO check toolbar offset
1672 HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowContentID
, &contentView
) ;
1673 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
1680 bool wxNonOwnedWindowCarbonImpl::IsActive()
1682 return ActiveNonFloatingWindow() == m_macWindow
;
1685 wxNonOwnedWindowImpl
* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
1686 long style
, long extraStyle
, const wxString
& name
)
1688 wxNonOwnedWindowImpl
* now
= new wxNonOwnedWindowCarbonImpl( wxpeer
);
1689 now
->Create( parent
, pos
, size
, style
, extraStyle
, name
);
1693 wxNonOwnedWindowImpl
* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, WXWindow nativeWindow
)
1695 wxNonOwnedWindowCarbonImpl
* now
= new wxNonOwnedWindowCarbonImpl( wxpeer
);
1696 now
->Create( parent
, nativeWindow
);