1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/nonownedwnd.cpp
3 // Purpose: implementation of wxNonOwnedWindow
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor 2008
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #include "wx/hashmap.h"
19 #include "wx/evtloop.h"
20 #include "wx/tooltip.h"
21 #include "wx/nonownedwnd.h"
23 #include "wx/osx/private.h"
24 #include "wx/settings.h"
27 #if wxUSE_SYSTEM_OPTIONS
28 #include "wx/sysopt.h"
31 // ============================================================================
32 // wxNonOwnedWindow implementation
33 // ============================================================================
35 // unified title and toolbar constant - not in Tiger headers, so we duplicate it here
36 #define kWindowUnifiedTitleAndToolbarAttribute (1 << 7)
38 IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCarbonImpl
, wxNonOwnedWindowImpl
)
40 WXWindow
wxNonOwnedWindowCarbonImpl::GetWXWindow() const
42 return (WXWindow
) m_macWindow
;
44 void wxNonOwnedWindowCarbonImpl::Raise()
46 ::SelectWindow( m_macWindow
) ;
49 void wxNonOwnedWindowCarbonImpl::Lower()
51 ::SendBehind( m_macWindow
, NULL
) ;
54 void wxNonOwnedWindowCarbonImpl::ShowWithoutActivating()
56 bool plainTransition
= true;
58 #if wxUSE_SYSTEM_OPTIONS
59 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
60 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
63 if ( plainTransition
)
64 ::ShowWindow( (WindowRef
)m_macWindow
);
66 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
69 bool wxNonOwnedWindowCarbonImpl::Show(bool show
)
71 bool plainTransition
= true;
73 #if wxUSE_SYSTEM_OPTIONS
74 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
75 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
80 ShowWithoutActivating();
81 ::SelectWindow( (WindowRef
)m_macWindow
) ;
86 if ( plainTransition
)
87 ::HideWindow( (WindowRef
)m_macWindow
);
89 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
95 void wxNonOwnedWindowCarbonImpl::Update()
97 HIWindowFlush(m_macWindow
) ;
100 bool wxNonOwnedWindowCarbonImpl::SetTransparent(wxByte alpha
)
102 OSStatus result
= SetWindowAlpha((WindowRef
)m_macWindow
, (CGFloat
)((alpha
)/255.0));
103 return result
== noErr
;
106 bool wxNonOwnedWindowCarbonImpl::SetBackgroundColour(const wxColour
& col
)
108 if ( col
== wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDocumentWindowBackground
)) )
110 SetThemeWindowBackground( (WindowRef
) m_macWindow
, kThemeBrushDocumentWindowBackground
, false ) ;
111 m_wxPeer
->SetBackgroundStyle(wxBG_STYLE_SYSTEM
);
112 // call directly if object is not yet completely constructed
113 if ( m_wxPeer
->GetNonOwnedPeer() == NULL
)
114 SetBackgroundStyle(wxBG_STYLE_SYSTEM
);
116 else if ( col
== wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive
)) )
118 SetThemeWindowBackground( (WindowRef
) m_macWindow
, kThemeBrushDialogBackgroundActive
, false ) ;
119 m_wxPeer
->SetBackgroundStyle(wxBG_STYLE_SYSTEM
);
120 // call directly if object is not yet completely constructed
121 if ( m_wxPeer
->GetNonOwnedPeer() == NULL
)
122 SetBackgroundStyle(wxBG_STYLE_SYSTEM
);
127 void wxNonOwnedWindowCarbonImpl::SetExtraStyle( long exStyle
)
129 if ( m_macWindow
!= NULL
)
131 bool metal
= exStyle
& wxFRAME_EX_METAL
;
133 if ( MacGetMetalAppearance() != metal
)
135 if ( MacGetUnifiedAppearance() )
136 MacSetUnifiedAppearance( !metal
) ;
138 MacSetMetalAppearance( metal
) ;
143 bool wxNonOwnedWindowCarbonImpl::SetBackgroundStyle(wxBackgroundStyle style
)
145 if ( style
== wxBG_STYLE_TRANSPARENT
)
147 OSStatus err
= HIWindowChangeFeatures( m_macWindow
, 0, kWindowIsOpaque
);
149 err
= ReshapeCustomWindow( m_macWindow
);
156 bool wxNonOwnedWindowCarbonImpl::CanSetTransparent()
161 void wxNonOwnedWindowCarbonImpl::GetContentArea( int &left
, int &top
, int &width
, int &height
) const
163 Rect content
, structure
;
165 GetWindowBounds( m_macWindow
, kWindowStructureRgn
, &structure
) ;
166 GetWindowBounds( m_macWindow
, kWindowContentRgn
, &content
) ;
168 left
= content
.left
- structure
.left
;
169 top
= content
.top
- structure
.top
;
170 width
= content
.right
- content
.left
;
171 height
= content
.bottom
- content
.top
;
174 void wxNonOwnedWindowCarbonImpl::MoveWindow(int x
, int y
, int width
, int height
)
176 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
177 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
180 void wxNonOwnedWindowCarbonImpl::GetPosition( int &x
, int &y
) const
184 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
190 void wxNonOwnedWindowCarbonImpl::GetSize( int &width
, int &height
) const
194 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
196 width
= bounds
.right
- bounds
.left
;
197 height
= bounds
.bottom
- bounds
.top
;
200 bool wxNonOwnedWindowCarbonImpl::MacGetUnifiedAppearance() const
202 return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute
;
205 void wxNonOwnedWindowCarbonImpl::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
207 ChangeWindowAttributes( m_macWindow
, attributesToSet
, attributesToClear
) ;
210 wxUint32
wxNonOwnedWindowCarbonImpl::MacGetWindowAttributes() const
213 GetWindowAttributes( m_macWindow
, &attr
) ;
217 void wxNonOwnedWindowCarbonImpl::MacSetMetalAppearance( bool set
)
219 if ( MacGetUnifiedAppearance() )
220 MacSetUnifiedAppearance( false ) ;
222 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
223 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
226 bool wxNonOwnedWindowCarbonImpl::MacGetMetalAppearance() const
228 return MacGetWindowAttributes() & kWindowMetalAttribute
;
231 void wxNonOwnedWindowCarbonImpl::MacSetUnifiedAppearance( bool set
)
233 if ( MacGetMetalAppearance() )
234 MacSetMetalAppearance( false ) ;
236 MacChangeWindowAttributes( set
? kWindowUnifiedTitleAndToolbarAttribute
: kWindowNoAttributes
,
237 set
? kWindowNoAttributes
: kWindowUnifiedTitleAndToolbarAttribute
) ;
239 // For some reason, Tiger uses white as the background color for this appearance,
240 // while most apps using it use the typical striped background. Restore that behavior
242 // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
244 // since when creating the peering is not yet completely set-up we call both setters
246 m_wxPeer
->SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
) ) ;
247 SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
) ) ;
251 // ----------------------------------------------------------------------------
253 // ----------------------------------------------------------------------------
255 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
257 void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
);
259 // ---------------------------------------------------------------------------
261 // ---------------------------------------------------------------------------
263 static const EventTypeSpec eventList
[] =
265 // TODO: remove control related event like key and mouse (except for WindowLeave events)
267 { kEventClassKeyboard
, kEventRawKeyDown
} ,
268 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
269 { kEventClassKeyboard
, kEventRawKeyUp
} ,
270 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
272 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
273 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
275 { kEventClassWindow
, kEventWindowShown
} ,
276 { kEventClassWindow
, kEventWindowActivated
} ,
277 { kEventClassWindow
, kEventWindowDeactivated
} ,
278 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
279 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
280 { kEventClassWindow
, kEventWindowClose
} ,
281 { kEventClassWindow
, kEventWindowGetRegion
} ,
283 // we have to catch these events on the toplevel window level,
284 // as controls don't get the raw mouse events anymore
286 { kEventClassMouse
, kEventMouseDown
} ,
287 { kEventClassMouse
, kEventMouseUp
} ,
288 { kEventClassMouse
, kEventMouseWheelMoved
} ,
289 { kEventClassMouse
, kEventMouseMoved
} ,
290 { kEventClassMouse
, kEventMouseDragged
} ,
293 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
295 OSStatus result
= eventNotHandledErr
;
296 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
297 // FindFocus does not return the actual focus window, but the enclosing window
298 wxWindow
* focus
= wxWindow::DoFindFocus();
300 focus
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
302 unsigned char charCode
;
310 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
313 ByteCount dataSize
= 0 ;
314 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
317 int numChars
= dataSize
/ sizeof( UniChar
) + 1;
319 UniChar
* charBuf
= buf
;
321 if ( numChars
* 2 > 4 )
322 charBuf
= new UniChar
[ numChars
] ;
323 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
324 charBuf
[ numChars
- 1 ] = 0;
326 wxMBConvUTF16 converter
;
327 converter
.MB2WC( uniChar
, (const char*)charBuf
, 2 ) ;
329 if ( numChars
* 2 > 4 )
332 #endif // wxUSE_UNICODE
334 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
335 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
336 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
337 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
339 UInt32 message
= (keyCode
<< 8) + charCode
;
340 switch ( GetEventKind( event
) )
342 case kEventRawKeyRepeat
:
343 case kEventRawKeyDown
:
345 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
346 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
347 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
348 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
349 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
353 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
357 case kEventRawKeyUp
:
358 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
359 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
365 case kEventRawKeyModifiersChanged
:
367 wxKeyEvent
event(wxEVT_KEY_DOWN
);
369 event
.m_shiftDown
= modifiers
& shiftKey
;
370 event
.m_controlDown
= modifiers
& controlKey
;
371 event
.m_altDown
= modifiers
& optionKey
;
372 event
.m_metaDown
= modifiers
& cmdKey
;
377 event
.m_uniChar
= uniChar
[0] ;
380 event
.SetTimestamp(when
);
381 event
.SetEventObject(focus
);
383 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
385 event
.m_keyCode
= WXK_CONTROL
;
386 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
387 focus
->HandleWindowEvent( event
) ;
389 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
391 event
.m_keyCode
= WXK_SHIFT
;
392 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
393 focus
->HandleWindowEvent( event
) ;
395 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
397 event
.m_keyCode
= WXK_ALT
;
398 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
399 focus
->HandleWindowEvent( event
) ;
401 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
403 event
.m_keyCode
= WXK_COMMAND
;
404 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
405 focus
->HandleWindowEvent( event
) ;
408 wxApp::s_lastModifiers
= modifiers
;
419 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
420 // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
423 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
425 EventMouseButton g_lastButton
= 0 ;
426 bool g_lastButtonWasFakeRight
= false ;
428 void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
430 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
431 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
433 // these parameters are not given for all events
434 EventMouseButton button
= 0 ;
435 UInt32 clickCount
= 0 ;
436 UInt32 mouseChord
= 0;
438 cEvent
.GetParameter
<EventMouseButton
>( kEventParamMouseButton
, typeMouseButton
, &button
) ;
439 cEvent
.GetParameter
<UInt32
>( kEventParamClickCount
, typeUInt32
, &clickCount
) ;
440 // the chord is the state of the buttons pressed currently
441 cEvent
.GetParameter
<UInt32
>( kEventParamMouseChord
, typeUInt32
, &mouseChord
) ;
443 wxevent
.m_x
= screenMouseLocation
.h
;
444 wxevent
.m_y
= screenMouseLocation
.v
;
445 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
446 wxevent
.m_controlDown
= modifiers
& controlKey
;
447 wxevent
.m_altDown
= modifiers
& optionKey
;
448 wxevent
.m_metaDown
= modifiers
& cmdKey
;
449 wxevent
.m_clickCount
= clickCount
;
450 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
452 // a control click is interpreted as a right click
453 bool thisButtonIsFakeRight
= false ;
454 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
456 button
= kEventMouseButtonSecondary
;
457 thisButtonIsFakeRight
= true ;
460 // otherwise we report double clicks by connecting a left click with a ctrl-left click
461 if ( clickCount
> 1 && button
!= g_lastButton
)
464 // we must make sure that our synthetic 'right' button corresponds in
465 // mouse down, moved and mouse up, and does not deliver a right down and left up
467 if ( cEvent
.GetKind() == kEventMouseDown
)
469 g_lastButton
= button
;
470 g_lastButtonWasFakeRight
= thisButtonIsFakeRight
;
476 g_lastButtonWasFakeRight
= false ;
478 else if ( g_lastButton
== kEventMouseButtonSecondary
&& g_lastButtonWasFakeRight
)
479 button
= g_lastButton
;
481 // Adjust the chord mask to remove the primary button and add the
482 // secondary button. It is possible that the secondary button is
483 // already pressed, e.g. on a mouse connected to a laptop, but this
484 // possibility is ignored here:
485 if( thisButtonIsFakeRight
&& ( mouseChord
& 1U ) )
486 mouseChord
= ((mouseChord
& ~1U) | 2U);
489 wxevent
.m_leftDown
= true ;
491 wxevent
.m_rightDown
= true ;
493 wxevent
.m_middleDown
= true ;
495 // translate into wx types
496 switch ( cEvent
.GetKind() )
498 case kEventMouseDown
:
501 case kEventMouseButtonPrimary
:
502 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
505 case kEventMouseButtonSecondary
:
506 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
509 case kEventMouseButtonTertiary
:
510 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
521 case kEventMouseButtonPrimary
:
522 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
525 case kEventMouseButtonSecondary
:
526 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
529 case kEventMouseButtonTertiary
:
530 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
537 // TODO http://developer.apple.com/qa/qa2005/qa1453.html
538 // add declaration for 10.4 and change to kEventMouseScroll
539 case kEventMouseWheelMoved
:
541 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
543 EventMouseWheelAxis axis
= cEvent
.GetParameter
<EventMouseWheelAxis
>(kEventParamMouseWheelAxis
, typeMouseWheelAxis
) ;
544 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeSInt32
) ;
546 wxevent
.m_wheelRotation
= delta
;
547 wxevent
.m_wheelDelta
= 1;
548 wxevent
.m_linesPerAction
= 1;
549 if ( axis
== kEventMouseWheelAxisX
)
550 wxevent
.m_wheelAxis
= 1;
554 case kEventMouseEntered
:
555 case kEventMouseExited
:
556 case kEventMouseDragged
:
557 case kEventMouseMoved
:
558 wxevent
.SetEventType( wxEVT_MOTION
) ;
565 #define NEW_CAPTURE_HANDLING 1
568 wxMacTopLevelMouseEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
572 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
574 OSStatus result
= eventNotHandledErr
;
576 wxMacCarbonEvent
cEvent( event
) ;
578 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
579 Point windowMouseLocation
= screenMouseLocation
;
581 WindowRef window
= NULL
;
582 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
584 wxWindow
* currentMouseWindow
= NULL
;
585 ControlRef control
= NULL
;
587 #if NEW_CAPTURE_HANDLING
588 if ( wxApp::s_captureWindow
)
590 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
591 windowPart
= inContent
;
597 QDGlobalToLocalPoint( GetWindowPort( window
), &windowMouseLocation
);
599 if ( wxApp::s_captureWindow
600 #if !NEW_CAPTURE_HANDLING
601 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
605 currentMouseWindow
= wxApp::s_captureWindow
;
607 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
609 ControlPartCode part
;
610 control
= FindControlUnderMouse( windowMouseLocation
, window
, &part
) ;
611 // if there is no control below the mouse position, send the event to the toplevel window itself
614 currentMouseWindow
= (wxWindow
*) toplevelWindow
;
618 currentMouseWindow
= (wxWindow
*) wxFindWindowFromWXWidget( (WXWidget
) control
) ;
619 #ifndef __WXUNIVERSAL__
620 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
623 // for wxToolBar to function we have to send certaint events to it
624 // instead of its children (wxToolBarTools)
626 GetSuperControl(control
, &parent
);
627 wxWindow
*wxparent
= (wxWindow
*) wxFindWindowFromWXWidget((WXWidget
) parent
) ;
628 if ( wxparent
&& wxparent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
629 currentMouseWindow
= wxparent
;
635 // disabled windows must not get any input messages
636 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
637 currentMouseWindow
= NULL
;
641 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
642 SetupMouseEvent( wxevent
, cEvent
) ;
644 // handle all enter / leave events
646 if ( currentMouseWindow
!= g_MacLastWindow
)
648 if ( g_MacLastWindow
)
650 wxMouseEvent
eventleave(wxevent
);
651 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
652 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
653 eventleave
.SetEventObject( g_MacLastWindow
) ;
654 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
657 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
660 g_MacLastWindow
->HandleWindowEvent(eventleave
);
663 if ( currentMouseWindow
)
665 wxMouseEvent
evententer(wxevent
);
666 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
667 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
668 evententer
.SetEventObject( currentMouseWindow
) ;
669 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
672 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
675 currentMouseWindow
->HandleWindowEvent(evententer
);
678 g_MacLastWindow
= currentMouseWindow
;
681 if ( windowPart
== inMenuBar
)
683 // special case menu bar, as we are having a low-level runloop we must do it ourselves
684 if ( cEvent
.GetKind() == kEventMouseDown
)
686 ::MenuSelect( screenMouseLocation
) ;
691 else if ( window
&& windowPart
== inProxyIcon
)
693 // special case proxy icon bar, as we are having a low-level runloop we must do it ourselves
694 if ( cEvent
.GetKind() == kEventMouseDown
)
696 if ( ::TrackWindowProxyDrag( window
, screenMouseLocation
) != errUserWantsToDragWindow
)
698 // TODO Track change of file path and report back
703 else if ( currentMouseWindow
)
705 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
707 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
709 wxevent
.SetEventObject( currentMouseWindow
) ;
710 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
712 // make tooltips current
715 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
716 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
719 if ( currentMouseWindow
->HandleWindowEvent(wxevent
) )
721 if ( currentMouseWindowParent
&&
722 !currentMouseWindowParent
->GetChildren().Member(currentMouseWindow
) )
723 currentMouseWindow
= NULL
;
729 // if the user code did _not_ handle the event, then perform the
730 // default processing
731 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
733 // ... that is set focus to this window
734 if (currentMouseWindow
->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
735 currentMouseWindow
->SetFocus();
739 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
741 wxApp::s_captureWindow
= NULL
;
747 wxWindow
* cursorTarget
= currentMouseWindow
;
748 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
750 extern wxCursor gGlobalCursor
;
752 if (!gGlobalCursor
.IsOk())
754 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
756 cursorTarget
= cursorTarget
->GetParent() ;
758 cursorPoint
+= cursorTarget
->GetPosition();
763 else // currentMouseWindow == NULL
765 if (toplevelWindow
&& !control
)
767 extern wxCursor gGlobalCursor
;
768 if (!gGlobalCursor
.IsOk())
770 // update cursor when over toolbar and titlebar etc.
771 wxSTANDARD_CURSOR
->MacInstall() ;
775 // don't mess with controls we don't know about
776 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
777 // so we try sending them the correct control directly
778 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
780 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
781 Point clickLocation
= windowMouseLocation
;
784 hiPoint
.x
= clickLocation
.h
;
785 hiPoint
.y
= clickLocation
.v
;
786 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
787 clickLocation
.h
= (int)hiPoint
.x
;
788 clickLocation
.v
= (int)hiPoint
.y
;
790 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
798 static pascal OSStatus
799 wxNonOwnedWindowEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
803 OSStatus result
= eventNotHandledErr
;
805 wxMacCarbonEvent
cEvent( event
) ;
807 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
808 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
810 switch ( GetEventKind( event
) )
812 case kEventWindowActivated
:
814 toplevelWindow
->HandleActivated( cEvent
.GetTicks() , true) ;
815 // we still sending an eventNotHandledErr in order to allow for default processing
819 case kEventWindowDeactivated
:
821 toplevelWindow
->HandleActivated( cEvent
.GetTicks() , false) ;
822 // we still sending an eventNotHandledErr in order to allow for default processing
826 case kEventWindowShown
:
827 toplevelWindow
->Refresh() ;
831 case kEventWindowClose
:
832 toplevelWindow
->Close() ;
836 case kEventWindowBoundsChanged
:
838 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
839 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
840 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
841 if ( attributes
& kWindowBoundsChangeSizeChanged
)
843 toplevelWindow
->HandleResized(cEvent
.GetTicks() ) ;
846 if ( attributes
& kWindowBoundsChangeOriginChanged
)
848 toplevelWindow
->HandleMoved(cEvent
.GetTicks() ) ;
855 case kEventWindowBoundsChanging
:
857 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
858 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
860 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
862 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
863 int left
, top
, width
, height
;
867 toplevelWindow
->GetNonOwnedPeer()->GetContentArea(left
, top
, width
, height
);
868 toplevelWindow
->GetNonOwnedPeer()->GetSize(swidth
, sheight
);
869 int deltawidth
= swidth
- width
;
870 int deltaheight
= sheight
- height
;
874 newRect
.right
- newRect
.left
+ deltawidth
,
875 newRect
.bottom
- newRect
.top
+ deltaheight
) ;
877 toplevelWindow
->HandleResizing( cEvent
.GetTicks(), &adjustR
);
879 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ top
+ adjustR
.height
- deltaheight
,
880 adjustR
.x
+ left
+ adjustR
.width
- deltawidth
} ;
881 if ( !EqualRect( &newRect
, &adjustedRect
) )
882 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
889 case kEventWindowGetRegion
:
891 if ( toplevelWindow
->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
893 WindowRegionCode windowRegionCode
;
895 // Fetch the region code that is being queried
896 GetEventParameter( event
,
897 kEventParamWindowRegionCode
,
898 typeWindowRegionCode
, NULL
,
899 sizeof windowRegionCode
, NULL
,
900 &windowRegionCode
) ;
902 // If it is the opaque region code then set the
903 // region to empty and return noErr to stop event
905 if ( windowRegionCode
== kWindowOpaqueRgn
) {
907 GetEventParameter( event
,
908 kEventParamRgnHandle
,
909 typeQDRgnHandle
, NULL
,
912 SetEmptyRgn(region
) ;
926 // mix this in from window.cpp
927 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
929 static pascal OSStatus
wxNonOwnedEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
931 OSStatus result
= eventNotHandledErr
;
933 switch ( GetEventClass( event
) )
935 case kEventClassTextInput
:
937 // TODO remove as soon as all events are on implementation classes only
938 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
940 result
= wxMacUnicodeTextEventHandler( handler
, event
, toplevelWindow
) ;
944 case kEventClassKeyboard
:
945 result
= KeyboardEventHandler( handler
, event
, data
) ;
948 case kEventClassWindow
:
949 result
= wxNonOwnedWindowEventHandler( handler
, event
, data
) ;
952 case kEventClassMouse
:
953 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
963 DEFINE_ONE_SHOT_HANDLER_GETTER( wxNonOwnedEventHandler
)
965 // ---------------------------------------------------------------------------
966 // Support functions for shaped windows, based on Apple's CustomWindow sample at
967 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
968 // ---------------------------------------------------------------------------
970 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
972 GetWindowPortBounds(window
, inRect
);
973 Point pt
= { inRect
->top
,inRect
->left
};
974 QDLocalToGlobalPoint( GetWindowPort( window
), &pt
);
975 inRect
->bottom
+= pt
.v
- inRect
->top
;
976 inRect
->right
+= pt
.h
- inRect
->left
;
981 static SInt32
wxShapedMacWindowGetFeatures(WindowRef
WXUNUSED(window
), SInt32 param
)
983 /*------------------------------------------------------
984 Define which options your custom window supports.
985 --------------------------------------------------------*/
986 //just enable everything for our demo
987 *(OptionBits
*)param
=
991 //kWindowCanGetWindowRegion |
992 //kWindowHasTitleBar |
993 //kWindowSupportsDragHilite |
994 kWindowCanDrawInCurrentPort
|
995 //kWindowCanMeasureTitle |
996 kWindowWantsDisposeAtProcessDeath
|
997 kWindowSupportsGetGrowImageRegion
|
998 kWindowDefSupportsColorGrafPort
;
1003 // The content region is left as a rectangle matching the window size, this is
1004 // so the origin in the paint event, and etc. still matches what the
1005 // programmer expects.
1006 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1009 wxNonOwnedWindow
* win
= wxNonOwnedWindow::GetFromWXWindow((WXWindow
)window
);
1013 wxShapedMacWindowGetPos( window
, &r
) ;
1014 RectRgn( rgn
, &r
) ;
1018 // The structure region is set to the shape given to the SetShape method.
1019 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1021 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1027 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1028 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1029 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1030 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1034 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1036 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1041 switch (rgnRec
->regionCode
)
1043 case kWindowStructureRgn
:
1044 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1047 case kWindowContentRgn
:
1048 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1052 SetEmptyRgn(rgnRec
->winRgn
);
1059 // Determine the region of the window which was hit
1061 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1064 static RgnHandle tempRgn
= NULL
;
1066 if (tempRgn
== NULL
)
1069 // get the point clicked
1070 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1072 // Mac OS 8.5 or later
1073 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1074 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1077 // no significant area was hit
1081 static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode
), WindowRef window
, SInt16 message
, SInt32 param
)
1085 case kWindowMsgHitTest
:
1086 return wxShapedMacWindowHitTest(window
, param
);
1088 case kWindowMsgGetFeatures
:
1089 return wxShapedMacWindowGetFeatures(window
, param
);
1091 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1092 case kWindowMsgGetRegion
:
1093 return wxShapedMacWindowGetRegion(window
, param
);
1106 wxPoint m_position
;
1108 bool m_wasResizable
;
1111 wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl()
1115 wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl( wxNonOwnedWindow
* nonownedwnd
) : wxNonOwnedWindowImpl( nonownedwnd
)
1117 m_macEventHandler
= NULL
;
1119 m_macFullScreenData
= NULL
;
1122 wxNonOwnedWindowCarbonImpl::~wxNonOwnedWindowCarbonImpl()
1125 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
1128 if ( m_macEventHandler
)
1130 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1131 m_macEventHandler
= NULL
;
1134 if ( m_macWindow
&& !m_wxPeer
->IsNativeWindowWrapper())
1135 DisposeWindow( m_macWindow
);
1137 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1139 m_macFullScreenData
= NULL
;
1145 void wxNonOwnedWindowCarbonImpl::WillBeDestroyed()
1147 if ( m_macEventHandler
)
1149 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1150 m_macEventHandler
= NULL
;
1154 static void wxNonOwnedWindowInstallTopLevelWindowEventHandler(WindowRef window
, EventHandlerRef
* handler
, void *ref
)
1156 InstallWindowEventHandler(window
, GetwxNonOwnedEventHandlerUPP(),
1157 GetEventTypeCount(eventList
), eventList
, ref
, handler
);
1160 bool wxNonOwnedWindowCarbonImpl::SetShape(const wxRegion
& region
)
1162 // Make a copy of the region
1163 RgnHandle shapeRegion
= NewRgn();
1164 HIShapeGetAsQDRgn( region
.GetWXHRGN(), shapeRegion
);
1166 // Dispose of any shape region we may already have
1167 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
) m_wxPeer
->GetWXWindow() );
1171 // Save the region so we can use it later
1172 SetWRefCon((WindowRef
) m_wxPeer
->GetWXWindow(), (URefCon
)shapeRegion
);
1174 // inform the window manager that the window has changed shape
1175 ReshapeCustomWindow((WindowRef
) m_wxPeer
->GetWXWindow());
1181 void wxNonOwnedWindowCarbonImpl::MacInstallTopLevelWindowEventHandler()
1183 if ( m_macEventHandler
!= NULL
)
1185 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1187 wxNonOwnedWindowInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow
),(EventHandlerRef
*)&m_macEventHandler
,this);
1190 void wxNonOwnedWindowCarbonImpl::Create(
1191 wxWindow
* WXUNUSED(parent
),
1192 WXWindow nativeWindow
)
1194 m_macWindow
= nativeWindow
;
1197 void wxNonOwnedWindowCarbonImpl::Create(
1201 long style
, long extraStyle
,
1202 const wxString
& WXUNUSED(name
) )
1205 OSStatus err
= noErr
;
1214 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1216 // translate the window attributes in the appropriate window class and attributes
1217 WindowClass wclass
= 0;
1218 WindowAttributes attr
= kWindowNoAttributes
;
1219 WindowGroupRef group
= NULL
;
1220 bool activationScopeSet
= false;
1221 WindowActivationScope activationScope
= kWindowActivationScopeNone
;
1223 if ( style
& wxFRAME_TOOL_WINDOW
)
1226 ( style
& wxMINIMIZE_BOX
) || ( style
& wxMAXIMIZE_BOX
) ||
1227 ( style
& wxSYSTEM_MENU
) || ( style
& wxCAPTION
) ||
1228 ( style
& wxTINY_CAPTION
)
1231 if ( ( style
& wxSTAY_ON_TOP
) )
1232 wclass
= kUtilityWindowClass
;
1234 wclass
= kFloatingWindowClass
;
1236 if ( ( style
& wxTINY_CAPTION
) )
1237 attr
|= kWindowSideTitlebarAttribute
;
1241 if ( style
& wxNO_BORDER
)
1243 wclass
= kSimpleWindowClass
;
1247 wclass
= kPlainWindowClass
;
1249 activationScopeSet
= true;
1250 activationScope
= kWindowActivationScopeNone
;
1253 else if ( ( style
& wxPOPUP_WINDOW
) )
1255 if ( ( style
& wxBORDER_NONE
) )
1257 wclass
= kHelpWindowClass
; // has no border
1258 attr
|= kWindowNoShadowAttribute
;
1262 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1264 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1265 // make sure we don't deactivate something
1266 activationScopeSet
= true;
1267 activationScope
= kWindowActivationScopeNone
;
1269 else if ( ( style
& wxCAPTION
) )
1271 wclass
= kDocumentWindowClass
;
1272 attr
|= kWindowInWindowMenuAttribute
;
1274 else if ( ( style
& wxFRAME_DRAWER
) )
1276 wclass
= kDrawerWindowClass
;
1280 if ( ( style
& wxMINIMIZE_BOX
) || ( style
& wxMAXIMIZE_BOX
) ||
1281 ( style
& wxCLOSE_BOX
) || ( style
& wxSYSTEM_MENU
) )
1283 wclass
= kDocumentWindowClass
;
1285 else if ( ( style
& wxNO_BORDER
) )
1287 wclass
= kSimpleWindowClass
;
1291 wclass
= kPlainWindowClass
;
1295 if ( wclass
!= kPlainWindowClass
)
1297 if ( ( style
& wxMINIMIZE_BOX
) )
1298 attr
|= kWindowCollapseBoxAttribute
;
1300 if ( ( style
& wxMAXIMIZE_BOX
) )
1301 attr
|= kWindowFullZoomAttribute
;
1303 if ( ( style
& wxRESIZE_BORDER
) )
1304 attr
|= kWindowResizableAttribute
;
1306 if ( ( style
& wxCLOSE_BOX
) )
1307 attr
|= kWindowCloseBoxAttribute
;
1309 attr
|= kWindowLiveResizeAttribute
;
1311 if ( ( style
&wxSTAY_ON_TOP
) )
1312 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1314 if ( ( style
& wxFRAME_FLOAT_ON_PARENT
) )
1315 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1317 if ( group
== NULL
&& parent
!= NULL
)
1319 WindowRef parenttlw
= (WindowRef
) parent
->MacGetTopLevelWindowRef();
1321 group
= GetWindowGroupParent( GetWindowGroup( parenttlw
) );
1324 attr
|= kWindowCompositingAttribute
;
1325 #if 0 // TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1326 attr
|= kWindowFrameworkScaledAttribute
;
1329 if ( ( style
&wxFRAME_SHAPED
) )
1331 WindowDefSpec customWindowDefSpec
;
1332 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1333 customWindowDefSpec
.u
.defProc
=
1335 (WindowDefUPP
) wxShapedMacWindowDef
;
1337 NewWindowDefUPP(wxShapedMacWindowDef
);
1339 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1340 attr
, &theBoundsRect
,
1341 (WindowRef
*) &m_macWindow
);
1345 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1348 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1349 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1351 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1353 // setup a separate group for each window, so that overlays can be handled easily
1355 WindowGroupRef overlaygroup
= NULL
;
1356 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &overlaygroup
));
1357 verify_noerr( SetWindowGroupParent( overlaygroup
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1358 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, overlaygroup
));
1360 if ( activationScopeSet
)
1362 verify_noerr( SetWindowActivationScope( (WindowRef
) m_macWindow
, activationScope
));
1365 // the create commands are only for content rect,
1366 // so we have to set the size again as structure bounds
1367 SetWindowBounds( m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1369 // Causes the inner part of the window not to be metal
1370 // if the style is used before window creation.
1371 #if 0 // TARGET_API_MAC_OSX
1372 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1374 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1375 MacSetMetalAppearance( true ) ;
1379 if ( m_macWindow
!= NULL
)
1381 MacSetUnifiedAppearance( true ) ;
1384 HIViewRef growBoxRef
= 0 ;
1385 err
= HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowGrowBoxID
, &growBoxRef
);
1386 if ( err
== noErr
&& growBoxRef
!= 0 )
1387 HIGrowBoxViewSetTransparent( growBoxRef
, true ) ;
1389 // the frame window event handler
1390 InstallStandardEventHandler( GetWindowEventTarget(m_macWindow
) ) ;
1391 MacInstallTopLevelWindowEventHandler() ;
1393 if ( extraStyle
& wxFRAME_EX_METAL
)
1394 MacSetMetalAppearance(true);
1396 if ( ( style
&wxFRAME_SHAPED
) )
1398 // default shape matches the window size
1399 wxRegion
rgn( 0, 0, w
, h
);
1404 bool wxNonOwnedWindowCarbonImpl::ShowWithEffect(bool show
,
1405 wxShowEffect effect
,
1408 WindowTransitionEffect transition
= 0 ;
1411 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1412 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1413 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1414 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1415 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1416 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1417 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1418 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1419 transition
= kWindowGenieTransitionEffect
;
1421 case wxSHOW_EFFECT_BLEND
:
1422 transition
= kWindowFadeTransitionEffect
;
1424 case wxSHOW_EFFECT_EXPAND
:
1425 // having sheets would be fine, but this might lead to a repositioning
1428 transition
= kWindowSheetTransitionEffect
;
1431 transition
= kWindowZoomTransitionEffect
;
1434 case wxSHOW_EFFECT_NONE
:
1435 // wxNonOwnedWindow is supposed to call Show() itself in this case
1436 wxFAIL_MSG( "ShowWithEffect() shouldn't be called" );
1439 case wxSHOW_EFFECT_MAX
:
1440 wxFAIL_MSG( "invalid effect flag" );
1444 TransitionWindowOptions options
;
1445 options
.version
= 0;
1446 options
.duration
= timeout
/ 1000.0;
1447 options
.window
= transition
== kWindowSheetTransitionEffect
? (WindowRef
) m_wxPeer
->GetParent()->MacGetTopLevelWindowRef() :0;
1448 options
.userData
= 0;
1450 wxSize size
= wxGetDisplaySize();
1452 GetWindowBounds( (WindowRef
)m_macWindow
, kWindowStructureRgn
, &bounds
);
1453 CGRect hiBounds
= CGRectMake( bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
);
1457 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1458 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1459 hiBounds
.origin
.x
= 0;
1460 hiBounds
.size
.width
= 0;
1463 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1464 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1465 hiBounds
.origin
.x
= size
.x
;
1466 hiBounds
.size
.width
= 0;
1469 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1470 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1471 hiBounds
.origin
.y
= size
.y
;
1472 hiBounds
.size
.height
= 0;
1475 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1476 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1477 hiBounds
.origin
.y
= 0;
1478 hiBounds
.size
.height
= 0;
1482 break; // direction doesn't make sense
1485 ::TransitionWindowWithOptions
1487 (WindowRef
)m_macWindow
,
1489 show
? kWindowShowTransitionAction
: kWindowHideTransitionAction
,
1490 transition
== kWindowGenieTransitionEffect
? &hiBounds
: NULL
,
1497 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1503 void wxNonOwnedWindowCarbonImpl::SetTitle( const wxString
& title
, wxFontEncoding encoding
)
1505 SetWindowTitleWithCFString( m_macWindow
, wxCFStringRef( title
, encoding
) ) ;
1508 bool wxNonOwnedWindowCarbonImpl::IsMaximized() const
1510 return IsWindowInStandardState( m_macWindow
, NULL
, NULL
) ;
1513 bool wxNonOwnedWindowCarbonImpl::IsIconized() const
1515 return IsWindowCollapsed((WindowRef
)GetWXWindow() ) ;
1518 void wxNonOwnedWindowCarbonImpl::Iconize( bool iconize
)
1520 if ( IsWindowCollapsable( m_macWindow
) )
1521 CollapseWindow( m_macWindow
, iconize
) ;
1524 void wxNonOwnedWindowCarbonImpl::Maximize(bool maximize
)
1526 Point idealSize
= { 0 , 0 } ;
1529 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1531 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
1533 idealSize
.h
= bounds
.size
.width
;
1534 idealSize
.v
= bounds
.size
.height
;
1537 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
1538 idealSize
.h
= rect
.right
- rect
.left
;
1539 idealSize
.v
= rect
.bottom
- rect
.top
;
1542 ZoomWindowIdeal( (WindowRef
)GetWXWindow() , maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
1545 bool wxNonOwnedWindowCarbonImpl::IsFullScreen() const
1547 return m_macFullScreenData
!= NULL
;
1550 bool wxNonOwnedWindowCarbonImpl::ShowFullScreen(bool show
, long style
)
1554 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1556 data
= new FullScreenData() ;
1558 m_macFullScreenData
= data
;
1559 data
->m_position
= m_wxPeer
->GetPosition() ;
1560 data
->m_size
= m_wxPeer
->GetSize() ;
1561 #if wxOSX_USE_CARBON
1562 WindowAttributes attr
= 0;
1563 GetWindowAttributes((WindowRef
) GetWXWindow(), &attr
);
1564 data
->m_wasResizable
= attr
& kWindowResizableAttribute
;
1565 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1569 wxRect client
= wxGetClientDisplayRect() ;
1571 int left
, top
, width
, height
;
1579 GetContentArea( left
, top
, width
, height
) ;
1580 int outerwidth
, outerheight
;
1581 GetSize( outerwidth
, outerheight
);
1583 if ( style
& wxFULLSCREEN_NOCAPTION
)
1587 // avoid adding the caption twice to the height
1591 if ( style
& wxFULLSCREEN_NOBORDER
)
1594 w
+= outerwidth
- width
;
1595 h
+= outerheight
- height
;
1598 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1603 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1608 m_wxPeer
->SetSize( x
, y
, w
, h
) ;
1609 if ( data
->m_wasResizable
)
1611 #if wxOSX_USE_CARBON
1612 ChangeWindowAttributes( (WindowRef
) GetWXWindow() , kWindowNoAttributes
, kWindowResizableAttribute
) ;
1616 else if ( m_macFullScreenData
!= NULL
)
1618 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1619 #if wxOSX_USE_CARBON
1621 if ( data
->m_wasResizable
)
1622 ChangeWindowAttributes( (WindowRef
) GetWXWindow() , kWindowResizableAttribute
, kWindowNoAttributes
) ;
1624 m_wxPeer
->SetPosition( data
->m_position
) ;
1625 m_wxPeer
->SetSize( data
->m_size
) ;
1628 m_macFullScreenData
= NULL
;
1634 // Attracts the users attention to this window if the application is
1635 // inactive (should be called when a background event occurs)
1637 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1640 DisposePtr( (Ptr
)ptr
) ;
1643 void wxNonOwnedWindowCarbonImpl::RequestUserAttention(int WXUNUSED(flags
))
1645 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1647 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1648 notificationRequest
->qType
= nmType
;
1649 notificationRequest
->nmMark
= 1 ;
1650 notificationRequest
->nmIcon
= 0 ;
1651 notificationRequest
->nmSound
= 0 ;
1652 notificationRequest
->nmStr
= NULL
;
1653 notificationRequest
->nmResp
= wxMacNMResponse
;
1655 verify_noerr( NMInstall( notificationRequest
) ) ;
1658 void wxNonOwnedWindowCarbonImpl::ScreenToWindow( int *x
, int *y
)
1660 HIPoint p
= CGPointMake( (x
? *x
: 0), (y
? *y
: 0) );
1661 HIViewRef contentView
;
1662 // TODO check toolbar offset
1663 HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowContentID
, &contentView
) ;
1664 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
1671 void wxNonOwnedWindowCarbonImpl::WindowToScreen( int *x
, int *y
)
1673 HIPoint p
= CGPointMake( (x
? *x
: 0), (y
? *y
: 0) );
1674 HIViewRef contentView
;
1675 // TODO check toolbar offset
1676 HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowContentID
, &contentView
) ;
1677 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
1684 bool wxNonOwnedWindowCarbonImpl::IsActive()
1686 return ActiveNonFloatingWindow() == m_macWindow
;
1689 wxNonOwnedWindowImpl
* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
1690 long style
, long extraStyle
, const wxString
& name
)
1692 wxNonOwnedWindowImpl
* now
= new wxNonOwnedWindowCarbonImpl( wxpeer
);
1693 now
->Create( parent
, pos
, size
, style
, extraStyle
, name
);
1697 wxNonOwnedWindowImpl
* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, WXWindow nativeWindow
)
1699 wxNonOwnedWindowCarbonImpl
* now
= new wxNonOwnedWindowCarbonImpl( wxpeer
);
1700 now
->Create( parent
, nativeWindow
);