1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/nonownedwnd.cpp
3 // Purpose: implementation of wxNonOwnedWindow
4 // Author: Stefan Csomor
6 // RCS-ID: $Id: nonownedwnd.cpp 50329 2007-11-29 17:00:58Z VS $
7 // Copyright: (c) Stefan Csomor 2008
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #include "wx/hashmap.h"
19 #include "wx/evtloop.h"
20 #include "wx/tooltip.h"
21 #include "wx/nonownedwnd.h"
23 #include "wx/osx/private.h"
24 #include "wx/settings.h"
27 #if wxUSE_SYSTEM_OPTIONS
28 #include "wx/sysopt.h"
31 // ============================================================================
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 bool wxNonOwnedWindowCarbonImpl::Show(bool show
)
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 ) ;
66 if ( plainTransition
)
67 ::ShowWindow( (WindowRef
)m_macWindow
);
69 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
71 ::SelectWindow( (WindowRef
)m_macWindow
) ;
77 if ( plainTransition
)
78 ::HideWindow( (WindowRef
)m_macWindow
);
80 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
86 void wxNonOwnedWindowCarbonImpl::Update()
88 HIWindowFlush(m_macWindow
) ;
91 bool wxNonOwnedWindowCarbonImpl::SetTransparent(wxByte alpha
)
93 OSStatus result
= SetWindowAlpha((WindowRef
)m_macWindow
, (CGFloat
)((alpha
)/255.0));
94 return result
== noErr
;
97 bool wxNonOwnedWindowCarbonImpl::SetBackgroundColour(const wxColour
& col
)
99 if ( col
== wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDocumentWindowBackground
)) )
101 SetThemeWindowBackground( (WindowRef
) m_macWindow
, kThemeBrushDocumentWindowBackground
, false ) ;
102 SetBackgroundStyle(wxBG_STYLE_SYSTEM
);
104 else if ( col
== wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive
)) )
106 SetThemeWindowBackground( (WindowRef
) m_macWindow
, kThemeBrushDialogBackgroundActive
, false ) ;
107 SetBackgroundStyle(wxBG_STYLE_SYSTEM
);
112 void wxNonOwnedWindowCarbonImpl::SetExtraStyle( long exStyle
)
114 if ( m_macWindow
!= NULL
)
116 bool metal
= exStyle
& wxFRAME_EX_METAL
;
118 if ( MacGetMetalAppearance() != metal
)
120 if ( MacGetUnifiedAppearance() )
121 MacSetUnifiedAppearance( !metal
) ;
123 MacSetMetalAppearance( metal
) ;
128 bool wxNonOwnedWindowCarbonImpl::SetBackgroundStyle(wxBackgroundStyle style
)
130 if ( style
== wxBG_STYLE_TRANSPARENT
)
132 OSStatus err
= HIWindowChangeFeatures( m_macWindow
, 0, kWindowIsOpaque
);
134 err
= ReshapeCustomWindow( m_macWindow
);
141 bool wxNonOwnedWindowCarbonImpl::CanSetTransparent()
146 void wxNonOwnedWindowCarbonImpl::GetContentArea( int &left
, int &top
, int &width
, int &height
) const
148 Rect content
, structure
;
150 GetWindowBounds( m_macWindow
, kWindowStructureRgn
, &structure
) ;
151 GetWindowBounds( m_macWindow
, kWindowContentRgn
, &content
) ;
153 left
= content
.left
- structure
.left
;
154 top
= content
.top
- structure
.top
;
155 width
= content
.right
- content
.left
;
156 height
= content
.bottom
- content
.top
;
159 void wxNonOwnedWindowCarbonImpl::MoveWindow(int x
, int y
, int width
, int height
)
161 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
162 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
165 void wxNonOwnedWindowCarbonImpl::GetPosition( int &x
, int &y
) const
169 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
175 void wxNonOwnedWindowCarbonImpl::GetSize( int &width
, int &height
) const
179 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
181 width
= bounds
.right
- bounds
.left
;
182 height
= bounds
.bottom
- bounds
.top
;
185 bool wxNonOwnedWindowCarbonImpl::MacGetUnifiedAppearance() const
187 return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute
;
190 void wxNonOwnedWindowCarbonImpl::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
192 ChangeWindowAttributes( m_macWindow
, attributesToSet
, attributesToClear
) ;
195 wxUint32
wxNonOwnedWindowCarbonImpl::MacGetWindowAttributes() const
198 GetWindowAttributes( m_macWindow
, &attr
) ;
202 void wxNonOwnedWindowCarbonImpl::MacSetMetalAppearance( bool set
)
204 if ( MacGetUnifiedAppearance() )
205 MacSetUnifiedAppearance( false ) ;
207 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
208 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
211 bool wxNonOwnedWindowCarbonImpl::MacGetMetalAppearance() const
213 return MacGetWindowAttributes() & kWindowMetalAttribute
;
216 void wxNonOwnedWindowCarbonImpl::MacSetUnifiedAppearance( bool set
)
218 if ( MacGetMetalAppearance() )
219 MacSetMetalAppearance( false ) ;
221 MacChangeWindowAttributes( set
? kWindowUnifiedTitleAndToolbarAttribute
: kWindowNoAttributes
,
222 set
? kWindowNoAttributes
: kWindowUnifiedTitleAndToolbarAttribute
) ;
224 // For some reason, Tiger uses white as the background color for this appearance,
225 // while most apps using it use the typical striped background. Restore that behavior
227 // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
229 // since when creating the peering is not yet completely set-up we call both setters
231 m_wxPeer
->SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
) ) ;
232 SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
) ) ;
236 // ----------------------------------------------------------------------------
238 // ----------------------------------------------------------------------------
240 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
243 // ---------------------------------------------------------------------------
245 // ---------------------------------------------------------------------------
247 static const EventTypeSpec eventList
[] =
249 // TODO: remove control related event like key and mouse (except for WindowLeave events)
251 { kEventClassKeyboard
, kEventRawKeyDown
} ,
252 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
253 { kEventClassKeyboard
, kEventRawKeyUp
} ,
254 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
256 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
257 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
259 { kEventClassWindow
, kEventWindowShown
} ,
260 { kEventClassWindow
, kEventWindowActivated
} ,
261 { kEventClassWindow
, kEventWindowDeactivated
} ,
262 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
263 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
264 { kEventClassWindow
, kEventWindowClose
} ,
265 { kEventClassWindow
, kEventWindowGetRegion
} ,
267 // we have to catch these events on the toplevel window level,
268 // as controls don't get the raw mouse events anymore
270 { kEventClassMouse
, kEventMouseDown
} ,
271 { kEventClassMouse
, kEventMouseUp
} ,
272 { kEventClassMouse
, kEventMouseWheelMoved
} ,
273 { kEventClassMouse
, kEventMouseMoved
} ,
274 { kEventClassMouse
, kEventMouseDragged
} ,
277 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
279 OSStatus result
= eventNotHandledErr
;
280 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
281 // FindFocus does not return the actual focus window, but the enclosing window
282 wxWindow
* focus
= wxWindow::DoFindFocus();
284 focus
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
286 unsigned char charCode
;
294 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
297 ByteCount dataSize
= 0 ;
298 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
301 int numChars
= dataSize
/ sizeof( UniChar
) + 1;
303 UniChar
* charBuf
= buf
;
305 if ( numChars
* 2 > 4 )
306 charBuf
= new UniChar
[ numChars
] ;
307 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
308 charBuf
[ numChars
- 1 ] = 0;
310 #if SIZEOF_WCHAR_T == 2
311 uniChar
= charBuf
[0] ;
313 wxMBConvUTF16 converter
;
314 converter
.MB2WC( uniChar
, (const char*)charBuf
, 2 ) ;
317 if ( numChars
* 2 > 4 )
322 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
323 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
324 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
325 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
327 UInt32 message
= (keyCode
<< 8) + charCode
;
328 switch ( GetEventKind( event
) )
330 case kEventRawKeyRepeat
:
331 case kEventRawKeyDown
:
333 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
334 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
335 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
336 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
337 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
341 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
345 case kEventRawKeyUp
:
346 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
347 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
353 case kEventRawKeyModifiersChanged
:
355 wxKeyEvent
event(wxEVT_KEY_DOWN
);
357 event
.m_shiftDown
= modifiers
& shiftKey
;
358 event
.m_controlDown
= modifiers
& controlKey
;
359 event
.m_altDown
= modifiers
& optionKey
;
360 event
.m_metaDown
= modifiers
& cmdKey
;
365 event
.m_uniChar
= uniChar
[0] ;
368 event
.SetTimestamp(when
);
369 event
.SetEventObject(focus
);
371 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
373 event
.m_keyCode
= WXK_CONTROL
;
374 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
375 focus
->HandleWindowEvent( event
) ;
377 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
379 event
.m_keyCode
= WXK_SHIFT
;
380 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
381 focus
->HandleWindowEvent( event
) ;
383 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
385 event
.m_keyCode
= WXK_ALT
;
386 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
387 focus
->HandleWindowEvent( event
) ;
389 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
391 event
.m_keyCode
= WXK_COMMAND
;
392 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
393 focus
->HandleWindowEvent( event
) ;
396 wxApp::s_lastModifiers
= modifiers
;
407 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
408 // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
411 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
413 EventMouseButton g_lastButton
= 0 ;
414 bool g_lastButtonWasFakeRight
= false ;
416 void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
418 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
419 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
421 // these parameters are not given for all events
422 EventMouseButton button
= 0 ;
423 UInt32 clickCount
= 0 ;
424 UInt32 mouseChord
= 0;
426 cEvent
.GetParameter
<EventMouseButton
>( kEventParamMouseButton
, typeMouseButton
, &button
) ;
427 cEvent
.GetParameter
<UInt32
>( kEventParamClickCount
, typeUInt32
, &clickCount
) ;
428 // the chord is the state of the buttons pressed currently
429 cEvent
.GetParameter
<UInt32
>( kEventParamMouseChord
, typeUInt32
, &mouseChord
) ;
431 wxevent
.m_x
= screenMouseLocation
.h
;
432 wxevent
.m_y
= screenMouseLocation
.v
;
433 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
434 wxevent
.m_controlDown
= modifiers
& controlKey
;
435 wxevent
.m_altDown
= modifiers
& optionKey
;
436 wxevent
.m_metaDown
= modifiers
& cmdKey
;
437 wxevent
.m_clickCount
= clickCount
;
438 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
440 // a control click is interpreted as a right click
441 bool thisButtonIsFakeRight
= false ;
442 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
444 button
= kEventMouseButtonSecondary
;
445 thisButtonIsFakeRight
= true ;
448 // otherwise we report double clicks by connecting a left click with a ctrl-left click
449 if ( clickCount
> 1 && button
!= g_lastButton
)
452 // we must make sure that our synthetic 'right' button corresponds in
453 // mouse down, moved and mouse up, and does not deliver a right down and left up
455 if ( cEvent
.GetKind() == kEventMouseDown
)
457 g_lastButton
= button
;
458 g_lastButtonWasFakeRight
= thisButtonIsFakeRight
;
464 g_lastButtonWasFakeRight
= false ;
466 else if ( g_lastButton
== kEventMouseButtonSecondary
&& g_lastButtonWasFakeRight
)
467 button
= g_lastButton
;
469 // Adjust the chord mask to remove the primary button and add the
470 // secondary button. It is possible that the secondary button is
471 // already pressed, e.g. on a mouse connected to a laptop, but this
472 // possibility is ignored here:
473 if( thisButtonIsFakeRight
&& ( mouseChord
& 1U ) )
474 mouseChord
= ((mouseChord
& ~1U) | 2U);
477 wxevent
.m_leftDown
= true ;
479 wxevent
.m_rightDown
= true ;
481 wxevent
.m_middleDown
= true ;
483 // translate into wx types
484 switch ( cEvent
.GetKind() )
486 case kEventMouseDown
:
489 case kEventMouseButtonPrimary
:
490 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
493 case kEventMouseButtonSecondary
:
494 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
497 case kEventMouseButtonTertiary
:
498 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
509 case kEventMouseButtonPrimary
:
510 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
513 case kEventMouseButtonSecondary
:
514 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
517 case kEventMouseButtonTertiary
:
518 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
526 case kEventMouseWheelMoved
:
528 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
530 EventMouseWheelAxis axis
= cEvent
.GetParameter
<EventMouseWheelAxis
>(kEventParamMouseWheelAxis
, typeMouseWheelAxis
) ;
531 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeSInt32
) ;
533 wxevent
.m_wheelRotation
= delta
;
534 wxevent
.m_wheelDelta
= 1;
535 wxevent
.m_linesPerAction
= 1;
536 if ( axis
== kEventMouseWheelAxisX
)
537 wxevent
.m_wheelAxis
= 1;
541 case kEventMouseEntered
:
542 case kEventMouseExited
:
543 case kEventMouseDragged
:
544 case kEventMouseMoved
:
545 wxevent
.SetEventType( wxEVT_MOTION
) ;
552 #define NEW_CAPTURE_HANDLING 1
555 wxMacTopLevelMouseEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
559 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
561 OSStatus result
= eventNotHandledErr
;
563 wxMacCarbonEvent
cEvent( event
) ;
565 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
566 Point windowMouseLocation
= screenMouseLocation
;
568 WindowRef window
= NULL
;
569 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
571 wxWindow
* currentMouseWindow
= NULL
;
572 ControlRef control
= NULL
;
574 #if NEW_CAPTURE_HANDLING
575 if ( wxApp::s_captureWindow
)
577 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
578 windowPart
= inContent
;
584 QDGlobalToLocalPoint( GetWindowPort( window
), &windowMouseLocation
);
586 if ( wxApp::s_captureWindow
587 #if !NEW_CAPTURE_HANDLING
588 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
592 currentMouseWindow
= wxApp::s_captureWindow
;
594 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
596 ControlPartCode part
;
597 control
= FindControlUnderMouse( windowMouseLocation
, window
, &part
) ;
598 // if there is no control below the mouse position, send the event to the toplevel window itself
601 currentMouseWindow
= (wxWindow
*) toplevelWindow
;
605 currentMouseWindow
= (wxWindow
*) wxFindWindowFromWXWidget( (WXWidget
) control
) ;
606 #ifndef __WXUNIVERSAL__
607 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
610 // for wxToolBar to function we have to send certaint events to it
611 // instead of its children (wxToolBarTools)
613 GetSuperControl(control
, &parent
);
614 wxWindow
*wxparent
= (wxWindow
*) wxFindWindowFromWXWidget((WXWidget
) parent
) ;
615 if ( wxparent
&& wxparent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
616 currentMouseWindow
= wxparent
;
622 // disabled windows must not get any input messages
623 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
624 currentMouseWindow
= NULL
;
628 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
629 SetupMouseEvent( wxevent
, cEvent
) ;
631 // handle all enter / leave events
633 if ( currentMouseWindow
!= g_MacLastWindow
)
635 if ( g_MacLastWindow
)
637 wxMouseEvent
eventleave(wxevent
);
638 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
639 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
640 eventleave
.SetEventObject( g_MacLastWindow
) ;
641 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
644 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
647 g_MacLastWindow
->HandleWindowEvent(eventleave
);
650 if ( currentMouseWindow
)
652 wxMouseEvent
evententer(wxevent
);
653 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
654 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
655 evententer
.SetEventObject( currentMouseWindow
) ;
656 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
659 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
662 currentMouseWindow
->HandleWindowEvent(evententer
);
665 g_MacLastWindow
= currentMouseWindow
;
668 if ( windowPart
== inMenuBar
)
670 // special case menu bar, as we are having a low-level runloop we must do it ourselves
671 if ( cEvent
.GetKind() == kEventMouseDown
)
673 ::MenuSelect( screenMouseLocation
) ;
678 else if ( window
&& windowPart
== inProxyIcon
)
680 // special case proxy icon bar, as we are having a low-level runloop we must do it ourselves
681 if ( cEvent
.GetKind() == kEventMouseDown
)
683 if ( ::TrackWindowProxyDrag( window
, screenMouseLocation
) != errUserWantsToDragWindow
)
685 // TODO Track change of file path and report back
690 else if ( currentMouseWindow
)
692 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
694 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
696 wxevent
.SetEventObject( currentMouseWindow
) ;
697 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
699 // make tooltips current
702 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
703 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
706 if ( currentMouseWindow
->HandleWindowEvent(wxevent
) )
708 if ((currentMouseWindowParent
!= NULL
) &&
709 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
710 currentMouseWindow
= NULL
;
716 // if the user code did _not_ handle the event, then perform the
717 // default processing
718 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
720 // ... that is set focus to this window
721 if (currentMouseWindow
->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
722 currentMouseWindow
->SetFocus();
726 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
728 wxApp::s_captureWindow
= NULL
;
734 wxWindow
* cursorTarget
= currentMouseWindow
;
735 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
737 extern wxCursor gGlobalCursor
;
739 if (!gGlobalCursor
.IsOk())
741 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
743 cursorTarget
= cursorTarget
->GetParent() ;
745 cursorPoint
+= cursorTarget
->GetPosition();
750 else // currentMouseWindow == NULL
752 if (toplevelWindow
&& !control
)
754 extern wxCursor gGlobalCursor
;
755 if (!gGlobalCursor
.IsOk())
757 // update cursor when over toolbar and titlebar etc.
758 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
759 toplevelWindow
->MacSetupCursor( cursorPoint
);
763 // don't mess with controls we don't know about
764 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
765 // so we try sending them the correct control directly
766 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
768 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
769 Point clickLocation
= windowMouseLocation
;
772 hiPoint
.x
= clickLocation
.h
;
773 hiPoint
.y
= clickLocation
.v
;
774 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
775 clickLocation
.h
= (int)hiPoint
.x
;
776 clickLocation
.v
= (int)hiPoint
.y
;
778 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
786 static pascal OSStatus
787 wxNonOwnedWindowEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
791 OSStatus result
= eventNotHandledErr
;
793 wxMacCarbonEvent
cEvent( event
) ;
795 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
796 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
798 switch ( GetEventKind( event
) )
800 case kEventWindowActivated
:
802 toplevelWindow
->HandleActivated( cEvent
.GetTicks() , true) ;
803 // we still sending an eventNotHandledErr in order to allow for default processing
807 case kEventWindowDeactivated
:
809 toplevelWindow
->HandleActivated( cEvent
.GetTicks() , false) ;
810 // we still sending an eventNotHandledErr in order to allow for default processing
814 case kEventWindowShown
:
815 toplevelWindow
->Refresh() ;
819 case kEventWindowClose
:
820 toplevelWindow
->Close() ;
824 case kEventWindowBoundsChanged
:
826 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
827 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
828 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
829 if ( attributes
& kWindowBoundsChangeSizeChanged
)
831 toplevelWindow
->HandleResized(cEvent
.GetTicks() ) ;
834 if ( attributes
& kWindowBoundsChangeOriginChanged
)
836 toplevelWindow
->HandleMoved(cEvent
.GetTicks() ) ;
843 case kEventWindowBoundsChanging
:
845 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
846 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
848 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
850 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
851 int left
, top
, width
, height
;
855 toplevelWindow
->GetNonOwnedPeer()->GetContentArea(left
, top
, width
, height
);
856 toplevelWindow
->GetNonOwnedPeer()->GetSize(swidth
, sheight
);
857 int deltawidth
= swidth
- width
;
858 int deltaheight
= sheight
- height
;
862 newRect
.right
- newRect
.left
+ deltawidth
,
863 newRect
.bottom
- newRect
.top
+ deltaheight
) ;
865 toplevelWindow
->HandleResizing( cEvent
.GetTicks(), &adjustR
);
867 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ top
+ adjustR
.height
- deltaheight
,
868 adjustR
.x
+ left
+ adjustR
.width
- deltawidth
} ;
869 if ( !EqualRect( &newRect
, &adjustedRect
) )
870 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
877 case kEventWindowGetRegion
:
879 if ( toplevelWindow
->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
881 WindowRegionCode windowRegionCode
;
883 // Fetch the region code that is being queried
884 GetEventParameter( event
,
885 kEventParamWindowRegionCode
,
886 typeWindowRegionCode
, NULL
,
887 sizeof windowRegionCode
, NULL
,
888 &windowRegionCode
) ;
890 // If it is the opaque region code then set the
891 // region to empty and return noErr to stop event
893 if ( windowRegionCode
== kWindowOpaqueRgn
) {
895 GetEventParameter( event
,
896 kEventParamRgnHandle
,
897 typeQDRgnHandle
, NULL
,
900 SetEmptyRgn(region
) ;
914 // mix this in from window.cpp
915 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
917 pascal OSStatus
wxNonOwnedEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
919 OSStatus result
= eventNotHandledErr
;
921 switch ( GetEventClass( event
) )
923 case kEventClassTextInput
:
925 // TODO remove as soon as all events are on implementation classes only
926 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
928 result
= wxMacUnicodeTextEventHandler( handler
, event
, toplevelWindow
) ;
932 case kEventClassKeyboard
:
933 result
= KeyboardEventHandler( handler
, event
, data
) ;
936 case kEventClassWindow
:
937 result
= wxNonOwnedWindowEventHandler( handler
, event
, data
) ;
940 case kEventClassMouse
:
941 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
951 DEFINE_ONE_SHOT_HANDLER_GETTER( wxNonOwnedEventHandler
)
953 // ---------------------------------------------------------------------------
954 // Support functions for shaped windows, based on Apple's CustomWindow sample at
955 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
956 // ---------------------------------------------------------------------------
958 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
960 GetWindowPortBounds(window
, inRect
);
961 Point pt
= { inRect
->top
,inRect
->left
};
962 QDLocalToGlobalPoint( GetWindowPort( window
), &pt
);
963 inRect
->bottom
+= pt
.v
- inRect
->top
;
964 inRect
->right
+= pt
.h
- inRect
->left
;
969 static SInt32
wxShapedMacWindowGetFeatures(WindowRef
WXUNUSED(window
), SInt32 param
)
971 /*------------------------------------------------------
972 Define which options your custom window supports.
973 --------------------------------------------------------*/
974 //just enable everything for our demo
975 *(OptionBits
*)param
=
979 //kWindowCanGetWindowRegion |
980 //kWindowHasTitleBar |
981 //kWindowSupportsDragHilite |
982 kWindowCanDrawInCurrentPort
|
983 //kWindowCanMeasureTitle |
984 kWindowWantsDisposeAtProcessDeath
|
985 kWindowSupportsGetGrowImageRegion
|
986 kWindowDefSupportsColorGrafPort
;
991 // The content region is left as a rectangle matching the window size, this is
992 // so the origin in the paint event, and etc. still matches what the
993 // programmer expects.
994 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
997 wxNonOwnedWindow
* win
= wxNonOwnedWindow::GetFromWXWindow((WXWindow
)window
);
1001 wxShapedMacWindowGetPos( window
, &r
) ;
1002 RectRgn( rgn
, &r
) ;
1006 // The structure region is set to the shape given to the SetShape method.
1007 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1009 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1015 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1016 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1017 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1018 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1022 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1024 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1029 switch (rgnRec
->regionCode
)
1031 case kWindowStructureRgn
:
1032 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1035 case kWindowContentRgn
:
1036 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1040 SetEmptyRgn(rgnRec
->winRgn
);
1047 // Determine the region of the window which was hit
1049 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1052 static RgnHandle tempRgn
= NULL
;
1054 if (tempRgn
== NULL
)
1057 // get the point clicked
1058 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1060 // Mac OS 8.5 or later
1061 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1062 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1065 // no significant area was hit
1069 static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode
), WindowRef window
, SInt16 message
, SInt32 param
)
1073 case kWindowMsgHitTest
:
1074 return wxShapedMacWindowHitTest(window
, param
);
1076 case kWindowMsgGetFeatures
:
1077 return wxShapedMacWindowGetFeatures(window
, param
);
1079 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1080 case kWindowMsgGetRegion
:
1081 return wxShapedMacWindowGetRegion(window
, param
);
1094 wxPoint m_position
;
1096 bool m_wasResizable
;
1099 wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl()
1103 wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl( wxNonOwnedWindow
* nonownedwnd
) : wxNonOwnedWindowImpl( nonownedwnd
)
1105 m_macEventHandler
= NULL
;
1107 m_macFullScreenData
= NULL
;
1110 wxNonOwnedWindowCarbonImpl::~wxNonOwnedWindowCarbonImpl()
1113 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
1116 if ( m_macEventHandler
)
1118 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1119 m_macEventHandler
= NULL
;
1123 DisposeWindow( m_macWindow
);
1125 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1127 m_macFullScreenData
= NULL
;
1133 void wxNonOwnedWindowCarbonImpl::Destroy()
1135 if ( m_macEventHandler
)
1137 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1138 m_macEventHandler
= NULL
;
1141 wxPendingDelete
.Append( new wxDeferredObjectDeleter( this ) ) ;
1144 void wxNonOwnedWindowInstallTopLevelWindowEventHandler(WindowRef window
, EventHandlerRef
* handler
, void *ref
)
1146 InstallWindowEventHandler(window
, GetwxNonOwnedEventHandlerUPP(),
1147 GetEventTypeCount(eventList
), eventList
, ref
, handler
);
1150 bool wxNonOwnedWindowCarbonImpl::SetShape(const wxRegion
& region
)
1152 // Make a copy of the region
1153 RgnHandle shapeRegion
= NewRgn();
1154 HIShapeGetAsQDRgn( region
.GetWXHRGN(), shapeRegion
);
1156 // Dispose of any shape region we may already have
1157 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
) m_wxPeer
->GetWXWindow() );
1161 // Save the region so we can use it later
1162 SetWRefCon((WindowRef
) m_wxPeer
->GetWXWindow(), (URefCon
)shapeRegion
);
1164 // inform the window manager that the window has changed shape
1165 ReshapeCustomWindow((WindowRef
) m_wxPeer
->GetWXWindow());
1171 void wxNonOwnedWindowCarbonImpl::MacInstallTopLevelWindowEventHandler()
1173 if ( m_macEventHandler
!= NULL
)
1175 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1177 wxNonOwnedWindowInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow
),(EventHandlerRef
*)&m_macEventHandler
,this);
1180 void wxNonOwnedWindowCarbonImpl::Create(
1184 long style
, long extraStyle
,
1185 const wxString
& name
)
1188 OSStatus err
= noErr
;
1197 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1199 // translate the window attributes in the appropriate window class and attributes
1200 WindowClass wclass
= 0;
1201 WindowAttributes attr
= kWindowNoAttributes
;
1202 WindowGroupRef group
= NULL
;
1203 bool activationScopeSet
= false;
1204 WindowActivationScope activationScope
= kWindowActivationScopeNone
;
1206 if ( style
& wxFRAME_TOOL_WINDOW
)
1209 ( style
& wxMINIMIZE_BOX
) || ( style
& wxMAXIMIZE_BOX
) ||
1210 ( style
& wxSYSTEM_MENU
) || ( style
& wxCAPTION
) ||
1211 ( style
&wxTINY_CAPTION_HORIZ
) || ( style
&wxTINY_CAPTION_VERT
)
1214 if ( ( style
& wxSTAY_ON_TOP
) )
1215 wclass
= kUtilityWindowClass
;
1217 wclass
= kFloatingWindowClass
;
1219 if ( ( style
&wxTINY_CAPTION_VERT
) )
1220 attr
|= kWindowSideTitlebarAttribute
;
1224 if ( style
& wxNO_BORDER
)
1226 wclass
= kSimpleWindowClass
;
1230 wclass
= kPlainWindowClass
;
1232 activationScopeSet
= true;
1233 activationScope
= kWindowActivationScopeNone
;
1236 else if ( ( style
& wxPOPUP_WINDOW
) )
1238 if ( ( style
& wxBORDER_NONE
) )
1240 wclass
= kHelpWindowClass
; // has no border
1241 attr
|= kWindowNoShadowAttribute
;
1245 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1247 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1248 // make sure we don't deactivate something
1249 activationScopeSet
= true;
1250 activationScope
= kWindowActivationScopeNone
;
1252 else if ( ( style
& wxCAPTION
) )
1254 wclass
= kDocumentWindowClass
;
1255 attr
|= kWindowInWindowMenuAttribute
;
1257 else if ( ( style
& wxFRAME_DRAWER
) )
1259 wclass
= kDrawerWindowClass
;
1263 if ( ( style
& wxMINIMIZE_BOX
) || ( style
& wxMAXIMIZE_BOX
) ||
1264 ( style
& wxCLOSE_BOX
) || ( style
& wxSYSTEM_MENU
) )
1266 wclass
= kDocumentWindowClass
;
1268 else if ( ( style
& wxNO_BORDER
) )
1270 wclass
= kSimpleWindowClass
;
1274 wclass
= kPlainWindowClass
;
1278 if ( wclass
!= kPlainWindowClass
)
1280 if ( ( style
& wxMINIMIZE_BOX
) )
1281 attr
|= kWindowCollapseBoxAttribute
;
1283 if ( ( style
& wxMAXIMIZE_BOX
) )
1284 attr
|= kWindowFullZoomAttribute
;
1286 if ( ( style
& wxRESIZE_BORDER
) )
1287 attr
|= kWindowResizableAttribute
;
1289 if ( ( style
& wxCLOSE_BOX
) )
1290 attr
|= kWindowCloseBoxAttribute
;
1292 attr
|= kWindowLiveResizeAttribute
;
1294 if ( ( style
&wxSTAY_ON_TOP
) )
1295 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1297 if ( ( style
& wxFRAME_FLOAT_ON_PARENT
) )
1298 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1300 if ( group
== NULL
&& parent
!= NULL
)
1302 WindowRef parenttlw
= (WindowRef
) parent
->MacGetTopLevelWindowRef();
1304 group
= GetWindowGroupParent( GetWindowGroup( parenttlw
) );
1307 attr
|= kWindowCompositingAttribute
;
1308 #if 0 // TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1309 attr
|= kWindowFrameworkScaledAttribute
;
1312 if ( ( style
&wxFRAME_SHAPED
) )
1314 WindowDefSpec customWindowDefSpec
;
1315 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1316 customWindowDefSpec
.u
.defProc
=
1318 (WindowDefUPP
) wxShapedMacWindowDef
;
1320 NewWindowDefUPP(wxShapedMacWindowDef
);
1322 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1323 attr
, &theBoundsRect
,
1324 (WindowRef
*) &m_macWindow
);
1328 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1331 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1332 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1334 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1336 // setup a separate group for each window, so that overlays can be handled easily
1338 WindowGroupRef overlaygroup
= NULL
;
1339 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &overlaygroup
));
1340 verify_noerr( SetWindowGroupParent( overlaygroup
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1341 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, overlaygroup
));
1343 if ( activationScopeSet
)
1345 verify_noerr( SetWindowActivationScope( (WindowRef
) m_macWindow
, activationScope
));
1348 // the create commands are only for content rect,
1349 // so we have to set the size again as structure bounds
1350 SetWindowBounds( m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1352 // Causes the inner part of the window not to be metal
1353 // if the style is used before window creation.
1354 #if 0 // TARGET_API_MAC_OSX
1355 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1357 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1358 MacSetMetalAppearance( true ) ;
1362 if ( m_macWindow
!= NULL
)
1364 MacSetUnifiedAppearance( true ) ;
1367 HIViewRef growBoxRef
= 0 ;
1368 err
= HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowGrowBoxID
, &growBoxRef
);
1369 if ( err
== noErr
&& growBoxRef
!= 0 )
1370 HIGrowBoxViewSetTransparent( growBoxRef
, true ) ;
1372 // the frame window event handler
1373 InstallStandardEventHandler( GetWindowEventTarget(m_macWindow
) ) ;
1374 MacInstallTopLevelWindowEventHandler() ;
1376 if ( extraStyle
& wxFRAME_EX_METAL
)
1377 MacSetMetalAppearance(true);
1379 if ( ( style
&wxFRAME_SHAPED
) )
1381 // default shape matches the window size
1382 wxRegion
rgn( 0, 0, w
, h
);
1387 bool wxNonOwnedWindowCarbonImpl::ShowWithEffect(bool show
,
1388 wxShowEffect effect
,
1391 WindowTransitionEffect transition
= 0 ;
1394 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1395 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1396 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1397 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1398 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1399 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1400 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1401 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1402 transition
= kWindowGenieTransitionEffect
;
1404 case wxSHOW_EFFECT_BLEND
:
1405 transition
= kWindowFadeTransitionEffect
;
1407 case wxSHOW_EFFECT_EXPAND
:
1408 // having sheets would be fine, but this might lead to a repositioning
1411 transition
= kWindowSheetTransitionEffect
;
1414 transition
= kWindowZoomTransitionEffect
;
1417 case wxSHOW_EFFECT_MAX
:
1418 wxFAIL_MSG( "invalid effect flag" );
1422 TransitionWindowOptions options
;
1423 options
.version
= 0;
1424 options
.duration
= timeout
/ 1000.0;
1425 options
.window
= transition
== kWindowSheetTransitionEffect
? (WindowRef
) m_wxPeer
->GetParent()->MacGetTopLevelWindowRef() :0;
1426 options
.userData
= 0;
1428 wxSize size
= wxGetDisplaySize();
1430 GetWindowBounds( (WindowRef
)m_macWindow
, kWindowStructureRgn
, &bounds
);
1431 CGRect hiBounds
= CGRectMake( bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
);
1435 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1436 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1437 hiBounds
.origin
.x
= 0;
1438 hiBounds
.size
.width
= 0;
1441 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1442 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1443 hiBounds
.origin
.x
= size
.x
;
1444 hiBounds
.size
.width
= 0;
1447 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1448 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1449 hiBounds
.origin
.y
= size
.y
;
1450 hiBounds
.size
.height
= 0;
1453 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1454 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1455 hiBounds
.origin
.y
= 0;
1456 hiBounds
.size
.height
= 0;
1460 break; // direction doesn't make sense
1463 ::TransitionWindowWithOptions
1465 (WindowRef
)m_macWindow
,
1467 show
? kWindowShowTransitionAction
: kWindowHideTransitionAction
,
1468 transition
== kWindowGenieTransitionEffect
? &hiBounds
: NULL
,
1475 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1481 void wxNonOwnedWindowCarbonImpl::SetTitle( const wxString
& title
, wxFontEncoding encoding
)
1483 SetWindowTitleWithCFString( m_macWindow
, wxCFStringRef( title
, encoding
) ) ;
1486 bool wxNonOwnedWindowCarbonImpl::IsMaximized() const
1488 return IsWindowInStandardState( m_macWindow
, NULL
, NULL
) ;
1491 bool wxNonOwnedWindowCarbonImpl::IsIconized() const
1493 return IsWindowCollapsed((WindowRef
)GetWXWindow() ) ;
1496 void wxNonOwnedWindowCarbonImpl::Iconize( bool iconize
)
1498 if ( IsWindowCollapsable( m_macWindow
) )
1499 CollapseWindow( m_macWindow
, iconize
) ;
1502 void wxNonOwnedWindowCarbonImpl::Maximize(bool maximize
)
1504 Point idealSize
= { 0 , 0 } ;
1507 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1509 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
1511 idealSize
.h
= bounds
.size
.width
;
1512 idealSize
.v
= bounds
.size
.height
;
1515 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
1516 idealSize
.h
= rect
.right
- rect
.left
;
1517 idealSize
.v
= rect
.bottom
- rect
.top
;
1520 ZoomWindowIdeal( (WindowRef
)GetWXWindow() , maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
1523 bool wxNonOwnedWindowCarbonImpl::IsFullScreen() const
1525 return m_macFullScreenData
!= NULL
;
1528 bool wxNonOwnedWindowCarbonImpl::ShowFullScreen(bool show
, long style
)
1532 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1534 data
= new FullScreenData() ;
1536 m_macFullScreenData
= data
;
1537 data
->m_position
= m_wxPeer
->GetPosition() ;
1538 data
->m_size
= m_wxPeer
->GetSize() ;
1539 #if wxOSX_USE_CARBON
1540 WindowAttributes attr
= 0;
1541 GetWindowAttributes((WindowRef
) GetWXWindow(), &attr
);
1542 data
->m_wasResizable
= attr
& kWindowResizableAttribute
;
1543 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1547 wxRect client
= wxGetClientDisplayRect() ;
1549 int left
, top
, width
, height
;
1557 GetContentArea( left
, top
, width
, height
) ;
1558 int outerwidth
, outerheight
;
1559 GetSize( outerwidth
, outerheight
);
1561 if ( style
& wxFULLSCREEN_NOCAPTION
)
1565 // avoid adding the caption twice to the height
1569 if ( style
& wxFULLSCREEN_NOBORDER
)
1572 w
+= outerwidth
- width
;
1573 h
+= outerheight
- height
;
1576 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1581 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1586 m_wxPeer
->SetSize( x
, y
, w
, h
) ;
1587 if ( data
->m_wasResizable
)
1589 #if wxOSX_USE_CARBON
1590 ChangeWindowAttributes( (WindowRef
) GetWXWindow() , kWindowNoAttributes
, kWindowResizableAttribute
) ;
1594 else if ( m_macFullScreenData
!= NULL
)
1596 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1597 #if wxOSX_USE_CARBON
1599 if ( data
->m_wasResizable
)
1600 ChangeWindowAttributes( (WindowRef
) GetWXWindow() , kWindowResizableAttribute
, kWindowNoAttributes
) ;
1602 m_wxPeer
->SetPosition( data
->m_position
) ;
1603 m_wxPeer
->SetSize( data
->m_size
) ;
1606 m_macFullScreenData
= NULL
;
1612 // Attracts the users attention to this window if the application is
1613 // inactive (should be called when a background event occurs)
1615 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1618 DisposePtr( (Ptr
)ptr
) ;
1621 void wxNonOwnedWindowCarbonImpl::RequestUserAttention(int WXUNUSED(flags
))
1623 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1625 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1626 notificationRequest
->qType
= nmType
;
1627 notificationRequest
->nmMark
= 1 ;
1628 notificationRequest
->nmIcon
= 0 ;
1629 notificationRequest
->nmSound
= 0 ;
1630 notificationRequest
->nmStr
= NULL
;
1631 notificationRequest
->nmResp
= wxMacNMResponse
;
1633 verify_noerr( NMInstall( notificationRequest
) ) ;
1636 void wxNonOwnedWindowCarbonImpl::ScreenToWindow( int *x
, int *y
)
1638 HIPoint p
= CGPointMake( (x
? *x
: 0), (y
? *y
: 0) );
1639 HIViewRef contentView
;
1640 // TODO check toolbar offset
1641 HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowContentID
, &contentView
) ;
1642 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
1649 void wxNonOwnedWindowCarbonImpl::WindowToScreen( int *x
, int *y
)
1651 HIPoint p
= CGPointMake( (x
? *x
: 0), (y
? *y
: 0) );
1652 HIViewRef contentView
;
1653 // TODO check toolbar offset
1654 HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowContentID
, &contentView
) ;
1655 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
1662 wxNonOwnedWindowImpl
* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
1663 long style
, long extraStyle
, const wxString
& name
)
1665 wxNonOwnedWindowImpl
* now
= new wxNonOwnedWindowCarbonImpl( wxpeer
);
1666 now
->Create( parent
, pos
, size
, style
, extraStyle
, name
);