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 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
);
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
;
309 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
312 ByteCount dataSize
= 0 ;
313 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
316 int numChars
= dataSize
/ sizeof( UniChar
) + 1;
318 UniChar
* charBuf
= buf
;
320 if ( numChars
* 2 > 4 )
321 charBuf
= new UniChar
[ numChars
] ;
322 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
323 charBuf
[ numChars
- 1 ] = 0;
325 #if SIZEOF_WCHAR_T == 2
326 uniChar
= charBuf
[0] ;
328 wxMBConvUTF16 converter
;
329 converter
.MB2WC( uniChar
, (const char*)charBuf
, 2 ) ;
332 if ( numChars
* 2 > 4 )
337 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
338 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
339 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
340 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
342 UInt32 message
= (keyCode
<< 8) + charCode
;
343 switch ( GetEventKind( event
) )
345 case kEventRawKeyRepeat
:
346 case kEventRawKeyDown
:
348 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
349 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
350 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
351 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
352 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
356 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
360 case kEventRawKeyUp
:
361 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
362 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
368 case kEventRawKeyModifiersChanged
:
370 wxKeyEvent
event(wxEVT_KEY_DOWN
);
372 event
.m_shiftDown
= modifiers
& shiftKey
;
373 event
.m_controlDown
= modifiers
& controlKey
;
374 event
.m_altDown
= modifiers
& optionKey
;
375 event
.m_metaDown
= modifiers
& cmdKey
;
380 event
.m_uniChar
= uniChar
[0] ;
383 event
.SetTimestamp(when
);
384 event
.SetEventObject(focus
);
386 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
388 event
.m_keyCode
= WXK_CONTROL
;
389 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
390 focus
->HandleWindowEvent( event
) ;
392 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
394 event
.m_keyCode
= WXK_SHIFT
;
395 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
396 focus
->HandleWindowEvent( event
) ;
398 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
400 event
.m_keyCode
= WXK_ALT
;
401 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
402 focus
->HandleWindowEvent( event
) ;
404 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
406 event
.m_keyCode
= WXK_COMMAND
;
407 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
408 focus
->HandleWindowEvent( event
) ;
411 wxApp::s_lastModifiers
= modifiers
;
422 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
423 // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
426 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
428 EventMouseButton g_lastButton
= 0 ;
429 bool g_lastButtonWasFakeRight
= false ;
431 void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
433 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
434 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
436 // these parameters are not given for all events
437 EventMouseButton button
= 0 ;
438 UInt32 clickCount
= 0 ;
439 UInt32 mouseChord
= 0;
441 cEvent
.GetParameter
<EventMouseButton
>( kEventParamMouseButton
, typeMouseButton
, &button
) ;
442 cEvent
.GetParameter
<UInt32
>( kEventParamClickCount
, typeUInt32
, &clickCount
) ;
443 // the chord is the state of the buttons pressed currently
444 cEvent
.GetParameter
<UInt32
>( kEventParamMouseChord
, typeUInt32
, &mouseChord
) ;
446 wxevent
.m_x
= screenMouseLocation
.h
;
447 wxevent
.m_y
= screenMouseLocation
.v
;
448 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
449 wxevent
.m_controlDown
= modifiers
& controlKey
;
450 wxevent
.m_altDown
= modifiers
& optionKey
;
451 wxevent
.m_metaDown
= modifiers
& cmdKey
;
452 wxevent
.m_clickCount
= clickCount
;
453 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
455 // a control click is interpreted as a right click
456 bool thisButtonIsFakeRight
= false ;
457 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
459 button
= kEventMouseButtonSecondary
;
460 thisButtonIsFakeRight
= true ;
463 // otherwise we report double clicks by connecting a left click with a ctrl-left click
464 if ( clickCount
> 1 && button
!= g_lastButton
)
467 // we must make sure that our synthetic 'right' button corresponds in
468 // mouse down, moved and mouse up, and does not deliver a right down and left up
470 if ( cEvent
.GetKind() == kEventMouseDown
)
472 g_lastButton
= button
;
473 g_lastButtonWasFakeRight
= thisButtonIsFakeRight
;
479 g_lastButtonWasFakeRight
= false ;
481 else if ( g_lastButton
== kEventMouseButtonSecondary
&& g_lastButtonWasFakeRight
)
482 button
= g_lastButton
;
484 // Adjust the chord mask to remove the primary button and add the
485 // secondary button. It is possible that the secondary button is
486 // already pressed, e.g. on a mouse connected to a laptop, but this
487 // possibility is ignored here:
488 if( thisButtonIsFakeRight
&& ( mouseChord
& 1U ) )
489 mouseChord
= ((mouseChord
& ~1U) | 2U);
492 wxevent
.m_leftDown
= true ;
494 wxevent
.m_rightDown
= true ;
496 wxevent
.m_middleDown
= true ;
498 // translate into wx types
499 switch ( cEvent
.GetKind() )
501 case kEventMouseDown
:
504 case kEventMouseButtonPrimary
:
505 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
508 case kEventMouseButtonSecondary
:
509 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
512 case kEventMouseButtonTertiary
:
513 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
524 case kEventMouseButtonPrimary
:
525 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
528 case kEventMouseButtonSecondary
:
529 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
532 case kEventMouseButtonTertiary
:
533 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
541 case kEventMouseWheelMoved
:
543 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
545 EventMouseWheelAxis axis
= cEvent
.GetParameter
<EventMouseWheelAxis
>(kEventParamMouseWheelAxis
, typeMouseWheelAxis
) ;
546 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeSInt32
) ;
548 wxevent
.m_wheelRotation
= delta
;
549 wxevent
.m_wheelDelta
= 1;
550 wxevent
.m_linesPerAction
= 1;
551 if ( axis
== kEventMouseWheelAxisX
)
552 wxevent
.m_wheelAxis
= 1;
556 case kEventMouseEntered
:
557 case kEventMouseExited
:
558 case kEventMouseDragged
:
559 case kEventMouseMoved
:
560 wxevent
.SetEventType( wxEVT_MOTION
) ;
567 #define NEW_CAPTURE_HANDLING 1
570 wxMacTopLevelMouseEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
574 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
576 OSStatus result
= eventNotHandledErr
;
578 wxMacCarbonEvent
cEvent( event
) ;
580 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
581 Point windowMouseLocation
= screenMouseLocation
;
583 WindowRef window
= NULL
;
584 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
586 wxWindow
* currentMouseWindow
= NULL
;
587 ControlRef control
= NULL
;
589 #if NEW_CAPTURE_HANDLING
590 if ( wxApp::s_captureWindow
)
592 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
593 windowPart
= inContent
;
599 QDGlobalToLocalPoint( GetWindowPort( window
), &windowMouseLocation
);
601 if ( wxApp::s_captureWindow
602 #if !NEW_CAPTURE_HANDLING
603 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
607 currentMouseWindow
= wxApp::s_captureWindow
;
609 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
611 ControlPartCode part
;
612 control
= FindControlUnderMouse( windowMouseLocation
, window
, &part
) ;
613 // if there is no control below the mouse position, send the event to the toplevel window itself
616 currentMouseWindow
= (wxWindow
*) toplevelWindow
;
620 currentMouseWindow
= (wxWindow
*) wxFindWindowFromWXWidget( (WXWidget
) control
) ;
621 #ifndef __WXUNIVERSAL__
622 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
625 // for wxToolBar to function we have to send certaint events to it
626 // instead of its children (wxToolBarTools)
628 GetSuperControl(control
, &parent
);
629 wxWindow
*wxparent
= (wxWindow
*) wxFindWindowFromWXWidget((WXWidget
) parent
) ;
630 if ( wxparent
&& wxparent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
631 currentMouseWindow
= wxparent
;
637 // disabled windows must not get any input messages
638 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
639 currentMouseWindow
= NULL
;
643 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
644 SetupMouseEvent( wxevent
, cEvent
) ;
646 // handle all enter / leave events
648 if ( currentMouseWindow
!= g_MacLastWindow
)
650 if ( g_MacLastWindow
)
652 wxMouseEvent
eventleave(wxevent
);
653 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
654 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
655 eventleave
.SetEventObject( g_MacLastWindow
) ;
656 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
659 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
662 g_MacLastWindow
->HandleWindowEvent(eventleave
);
665 if ( currentMouseWindow
)
667 wxMouseEvent
evententer(wxevent
);
668 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
669 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
670 evententer
.SetEventObject( currentMouseWindow
) ;
671 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
674 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
677 currentMouseWindow
->HandleWindowEvent(evententer
);
680 g_MacLastWindow
= currentMouseWindow
;
683 if ( windowPart
== inMenuBar
)
685 // special case menu bar, as we are having a low-level runloop we must do it ourselves
686 if ( cEvent
.GetKind() == kEventMouseDown
)
688 ::MenuSelect( screenMouseLocation
) ;
693 else if ( window
&& windowPart
== inProxyIcon
)
695 // special case proxy icon bar, as we are having a low-level runloop we must do it ourselves
696 if ( cEvent
.GetKind() == kEventMouseDown
)
698 if ( ::TrackWindowProxyDrag( window
, screenMouseLocation
) != errUserWantsToDragWindow
)
700 // TODO Track change of file path and report back
705 else if ( currentMouseWindow
)
707 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
709 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
711 wxevent
.SetEventObject( currentMouseWindow
) ;
712 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
714 // make tooltips current
717 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
718 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
721 if ( currentMouseWindow
->HandleWindowEvent(wxevent
) )
723 if ((currentMouseWindowParent
!= NULL
) &&
724 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
725 currentMouseWindow
= NULL
;
731 // if the user code did _not_ handle the event, then perform the
732 // default processing
733 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
735 // ... that is set focus to this window
736 if (currentMouseWindow
->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
737 currentMouseWindow
->SetFocus();
741 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
743 wxApp::s_captureWindow
= NULL
;
749 wxWindow
* cursorTarget
= currentMouseWindow
;
750 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
752 extern wxCursor gGlobalCursor
;
754 if (!gGlobalCursor
.IsOk())
756 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
758 cursorTarget
= cursorTarget
->GetParent() ;
760 cursorPoint
+= cursorTarget
->GetPosition();
765 else // currentMouseWindow == NULL
767 if (toplevelWindow
&& !control
)
769 extern wxCursor gGlobalCursor
;
770 if (!gGlobalCursor
.IsOk())
772 // update cursor when over toolbar and titlebar etc.
773 wxSTANDARD_CURSOR
->MacInstall() ;
777 // don't mess with controls we don't know about
778 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
779 // so we try sending them the correct control directly
780 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
782 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
783 Point clickLocation
= windowMouseLocation
;
786 hiPoint
.x
= clickLocation
.h
;
787 hiPoint
.y
= clickLocation
.v
;
788 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
789 clickLocation
.h
= (int)hiPoint
.x
;
790 clickLocation
.v
= (int)hiPoint
.y
;
792 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
800 static pascal OSStatus
801 wxNonOwnedWindowEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
805 OSStatus result
= eventNotHandledErr
;
807 wxMacCarbonEvent
cEvent( event
) ;
809 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
810 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
812 switch ( GetEventKind( event
) )
814 case kEventWindowActivated
:
816 toplevelWindow
->HandleActivated( cEvent
.GetTicks() , true) ;
817 // we still sending an eventNotHandledErr in order to allow for default processing
821 case kEventWindowDeactivated
:
823 toplevelWindow
->HandleActivated( cEvent
.GetTicks() , false) ;
824 // we still sending an eventNotHandledErr in order to allow for default processing
828 case kEventWindowShown
:
829 toplevelWindow
->Refresh() ;
833 case kEventWindowClose
:
834 toplevelWindow
->Close() ;
838 case kEventWindowBoundsChanged
:
840 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
841 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
842 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
843 if ( attributes
& kWindowBoundsChangeSizeChanged
)
845 toplevelWindow
->HandleResized(cEvent
.GetTicks() ) ;
848 if ( attributes
& kWindowBoundsChangeOriginChanged
)
850 toplevelWindow
->HandleMoved(cEvent
.GetTicks() ) ;
857 case kEventWindowBoundsChanging
:
859 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
860 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
862 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
864 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
865 int left
, top
, width
, height
;
869 toplevelWindow
->GetNonOwnedPeer()->GetContentArea(left
, top
, width
, height
);
870 toplevelWindow
->GetNonOwnedPeer()->GetSize(swidth
, sheight
);
871 int deltawidth
= swidth
- width
;
872 int deltaheight
= sheight
- height
;
876 newRect
.right
- newRect
.left
+ deltawidth
,
877 newRect
.bottom
- newRect
.top
+ deltaheight
) ;
879 toplevelWindow
->HandleResizing( cEvent
.GetTicks(), &adjustR
);
881 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ top
+ adjustR
.height
- deltaheight
,
882 adjustR
.x
+ left
+ adjustR
.width
- deltawidth
} ;
883 if ( !EqualRect( &newRect
, &adjustedRect
) )
884 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
891 case kEventWindowGetRegion
:
893 if ( toplevelWindow
->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
895 WindowRegionCode windowRegionCode
;
897 // Fetch the region code that is being queried
898 GetEventParameter( event
,
899 kEventParamWindowRegionCode
,
900 typeWindowRegionCode
, NULL
,
901 sizeof windowRegionCode
, NULL
,
902 &windowRegionCode
) ;
904 // If it is the opaque region code then set the
905 // region to empty and return noErr to stop event
907 if ( windowRegionCode
== kWindowOpaqueRgn
) {
909 GetEventParameter( event
,
910 kEventParamRgnHandle
,
911 typeQDRgnHandle
, NULL
,
914 SetEmptyRgn(region
) ;
928 // mix this in from window.cpp
929 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
931 pascal OSStatus
wxNonOwnedEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
933 OSStatus result
= eventNotHandledErr
;
935 switch ( GetEventClass( event
) )
937 case kEventClassTextInput
:
939 // TODO remove as soon as all events are on implementation classes only
940 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
942 result
= wxMacUnicodeTextEventHandler( handler
, event
, toplevelWindow
) ;
946 case kEventClassKeyboard
:
947 result
= KeyboardEventHandler( handler
, event
, data
) ;
950 case kEventClassWindow
:
951 result
= wxNonOwnedWindowEventHandler( handler
, event
, data
) ;
954 case kEventClassMouse
:
955 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
965 DEFINE_ONE_SHOT_HANDLER_GETTER( wxNonOwnedEventHandler
)
967 // ---------------------------------------------------------------------------
968 // Support functions for shaped windows, based on Apple's CustomWindow sample at
969 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
970 // ---------------------------------------------------------------------------
972 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
974 GetWindowPortBounds(window
, inRect
);
975 Point pt
= { inRect
->top
,inRect
->left
};
976 QDLocalToGlobalPoint( GetWindowPort( window
), &pt
);
977 inRect
->bottom
+= pt
.v
- inRect
->top
;
978 inRect
->right
+= pt
.h
- inRect
->left
;
983 static SInt32
wxShapedMacWindowGetFeatures(WindowRef
WXUNUSED(window
), SInt32 param
)
985 /*------------------------------------------------------
986 Define which options your custom window supports.
987 --------------------------------------------------------*/
988 //just enable everything for our demo
989 *(OptionBits
*)param
=
993 //kWindowCanGetWindowRegion |
994 //kWindowHasTitleBar |
995 //kWindowSupportsDragHilite |
996 kWindowCanDrawInCurrentPort
|
997 //kWindowCanMeasureTitle |
998 kWindowWantsDisposeAtProcessDeath
|
999 kWindowSupportsGetGrowImageRegion
|
1000 kWindowDefSupportsColorGrafPort
;
1005 // The content region is left as a rectangle matching the window size, this is
1006 // so the origin in the paint event, and etc. still matches what the
1007 // programmer expects.
1008 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1011 wxNonOwnedWindow
* win
= wxNonOwnedWindow::GetFromWXWindow((WXWindow
)window
);
1015 wxShapedMacWindowGetPos( window
, &r
) ;
1016 RectRgn( rgn
, &r
) ;
1020 // The structure region is set to the shape given to the SetShape method.
1021 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1023 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1029 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1030 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1031 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1032 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1036 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1038 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1043 switch (rgnRec
->regionCode
)
1045 case kWindowStructureRgn
:
1046 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1049 case kWindowContentRgn
:
1050 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1054 SetEmptyRgn(rgnRec
->winRgn
);
1061 // Determine the region of the window which was hit
1063 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1066 static RgnHandle tempRgn
= NULL
;
1068 if (tempRgn
== NULL
)
1071 // get the point clicked
1072 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1074 // Mac OS 8.5 or later
1075 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1076 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1079 // no significant area was hit
1083 static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode
), WindowRef window
, SInt16 message
, SInt32 param
)
1087 case kWindowMsgHitTest
:
1088 return wxShapedMacWindowHitTest(window
, param
);
1090 case kWindowMsgGetFeatures
:
1091 return wxShapedMacWindowGetFeatures(window
, param
);
1093 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1094 case kWindowMsgGetRegion
:
1095 return wxShapedMacWindowGetRegion(window
, param
);
1108 wxPoint m_position
;
1110 bool m_wasResizable
;
1113 wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl()
1117 wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl( wxNonOwnedWindow
* nonownedwnd
) : wxNonOwnedWindowImpl( nonownedwnd
)
1119 m_macEventHandler
= NULL
;
1121 m_macFullScreenData
= NULL
;
1124 wxNonOwnedWindowCarbonImpl::~wxNonOwnedWindowCarbonImpl()
1127 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
1130 if ( m_macEventHandler
)
1132 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1133 m_macEventHandler
= NULL
;
1137 DisposeWindow( m_macWindow
);
1139 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1141 m_macFullScreenData
= NULL
;
1147 void wxNonOwnedWindowCarbonImpl::Destroy()
1149 if ( m_macEventHandler
)
1151 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1152 m_macEventHandler
= NULL
;
1155 wxPendingDelete
.Append( new wxDeferredObjectDeleter( this ) ) ;
1158 void wxNonOwnedWindowInstallTopLevelWindowEventHandler(WindowRef window
, EventHandlerRef
* handler
, void *ref
)
1160 InstallWindowEventHandler(window
, GetwxNonOwnedEventHandlerUPP(),
1161 GetEventTypeCount(eventList
), eventList
, ref
, handler
);
1164 bool wxNonOwnedWindowCarbonImpl::SetShape(const wxRegion
& region
)
1166 // Make a copy of the region
1167 RgnHandle shapeRegion
= NewRgn();
1168 HIShapeGetAsQDRgn( region
.GetWXHRGN(), shapeRegion
);
1170 // Dispose of any shape region we may already have
1171 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
) m_wxPeer
->GetWXWindow() );
1175 // Save the region so we can use it later
1176 SetWRefCon((WindowRef
) m_wxPeer
->GetWXWindow(), (URefCon
)shapeRegion
);
1178 // inform the window manager that the window has changed shape
1179 ReshapeCustomWindow((WindowRef
) m_wxPeer
->GetWXWindow());
1185 void wxNonOwnedWindowCarbonImpl::MacInstallTopLevelWindowEventHandler()
1187 if ( m_macEventHandler
!= NULL
)
1189 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1191 wxNonOwnedWindowInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow
),(EventHandlerRef
*)&m_macEventHandler
,this);
1194 void wxNonOwnedWindowCarbonImpl::Create(
1198 long style
, long extraStyle
,
1199 const wxString
& WXUNUSED(name
) )
1202 OSStatus err
= noErr
;
1211 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1213 // translate the window attributes in the appropriate window class and attributes
1214 WindowClass wclass
= 0;
1215 WindowAttributes attr
= kWindowNoAttributes
;
1216 WindowGroupRef group
= NULL
;
1217 bool activationScopeSet
= false;
1218 WindowActivationScope activationScope
= kWindowActivationScopeNone
;
1220 if ( style
& wxFRAME_TOOL_WINDOW
)
1223 ( style
& wxMINIMIZE_BOX
) || ( style
& wxMAXIMIZE_BOX
) ||
1224 ( style
& wxSYSTEM_MENU
) || ( style
& wxCAPTION
) ||
1225 ( style
&wxTINY_CAPTION_HORIZ
) || ( style
&wxTINY_CAPTION_VERT
)
1228 if ( ( style
& wxSTAY_ON_TOP
) )
1229 wclass
= kUtilityWindowClass
;
1231 wclass
= kFloatingWindowClass
;
1233 if ( ( style
&wxTINY_CAPTION_VERT
) )
1234 attr
|= kWindowSideTitlebarAttribute
;
1238 if ( style
& wxNO_BORDER
)
1240 wclass
= kSimpleWindowClass
;
1244 wclass
= kPlainWindowClass
;
1246 activationScopeSet
= true;
1247 activationScope
= kWindowActivationScopeNone
;
1250 else if ( ( style
& wxPOPUP_WINDOW
) )
1252 if ( ( style
& wxBORDER_NONE
) )
1254 wclass
= kHelpWindowClass
; // has no border
1255 attr
|= kWindowNoShadowAttribute
;
1259 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1261 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1262 // make sure we don't deactivate something
1263 activationScopeSet
= true;
1264 activationScope
= kWindowActivationScopeNone
;
1266 else if ( ( style
& wxCAPTION
) )
1268 wclass
= kDocumentWindowClass
;
1269 attr
|= kWindowInWindowMenuAttribute
;
1271 else if ( ( style
& wxFRAME_DRAWER
) )
1273 wclass
= kDrawerWindowClass
;
1277 if ( ( style
& wxMINIMIZE_BOX
) || ( style
& wxMAXIMIZE_BOX
) ||
1278 ( style
& wxCLOSE_BOX
) || ( style
& wxSYSTEM_MENU
) )
1280 wclass
= kDocumentWindowClass
;
1282 else if ( ( style
& wxNO_BORDER
) )
1284 wclass
= kSimpleWindowClass
;
1288 wclass
= kPlainWindowClass
;
1292 if ( wclass
!= kPlainWindowClass
)
1294 if ( ( style
& wxMINIMIZE_BOX
) )
1295 attr
|= kWindowCollapseBoxAttribute
;
1297 if ( ( style
& wxMAXIMIZE_BOX
) )
1298 attr
|= kWindowFullZoomAttribute
;
1300 if ( ( style
& wxRESIZE_BORDER
) )
1301 attr
|= kWindowResizableAttribute
;
1303 if ( ( style
& wxCLOSE_BOX
) )
1304 attr
|= kWindowCloseBoxAttribute
;
1306 attr
|= kWindowLiveResizeAttribute
;
1308 if ( ( style
&wxSTAY_ON_TOP
) )
1309 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1311 if ( ( style
& wxFRAME_FLOAT_ON_PARENT
) )
1312 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1314 if ( group
== NULL
&& parent
!= NULL
)
1316 WindowRef parenttlw
= (WindowRef
) parent
->MacGetTopLevelWindowRef();
1318 group
= GetWindowGroupParent( GetWindowGroup( parenttlw
) );
1321 attr
|= kWindowCompositingAttribute
;
1322 #if 0 // TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1323 attr
|= kWindowFrameworkScaledAttribute
;
1326 if ( ( style
&wxFRAME_SHAPED
) )
1328 WindowDefSpec customWindowDefSpec
;
1329 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1330 customWindowDefSpec
.u
.defProc
=
1332 (WindowDefUPP
) wxShapedMacWindowDef
;
1334 NewWindowDefUPP(wxShapedMacWindowDef
);
1336 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1337 attr
, &theBoundsRect
,
1338 (WindowRef
*) &m_macWindow
);
1342 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1345 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1346 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1348 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1350 // setup a separate group for each window, so that overlays can be handled easily
1352 WindowGroupRef overlaygroup
= NULL
;
1353 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &overlaygroup
));
1354 verify_noerr( SetWindowGroupParent( overlaygroup
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1355 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, overlaygroup
));
1357 if ( activationScopeSet
)
1359 verify_noerr( SetWindowActivationScope( (WindowRef
) m_macWindow
, activationScope
));
1362 // the create commands are only for content rect,
1363 // so we have to set the size again as structure bounds
1364 SetWindowBounds( m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1366 // Causes the inner part of the window not to be metal
1367 // if the style is used before window creation.
1368 #if 0 // TARGET_API_MAC_OSX
1369 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1371 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1372 MacSetMetalAppearance( true ) ;
1376 if ( m_macWindow
!= NULL
)
1378 MacSetUnifiedAppearance( true ) ;
1381 HIViewRef growBoxRef
= 0 ;
1382 err
= HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowGrowBoxID
, &growBoxRef
);
1383 if ( err
== noErr
&& growBoxRef
!= 0 )
1384 HIGrowBoxViewSetTransparent( growBoxRef
, true ) ;
1386 // the frame window event handler
1387 InstallStandardEventHandler( GetWindowEventTarget(m_macWindow
) ) ;
1388 MacInstallTopLevelWindowEventHandler() ;
1390 if ( extraStyle
& wxFRAME_EX_METAL
)
1391 MacSetMetalAppearance(true);
1393 if ( ( style
&wxFRAME_SHAPED
) )
1395 // default shape matches the window size
1396 wxRegion
rgn( 0, 0, w
, h
);
1401 bool wxNonOwnedWindowCarbonImpl::ShowWithEffect(bool show
,
1402 wxShowEffect effect
,
1405 WindowTransitionEffect transition
= 0 ;
1408 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1409 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1410 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1411 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1412 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1413 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1414 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1415 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1416 transition
= kWindowGenieTransitionEffect
;
1418 case wxSHOW_EFFECT_BLEND
:
1419 transition
= kWindowFadeTransitionEffect
;
1421 case wxSHOW_EFFECT_EXPAND
:
1422 // having sheets would be fine, but this might lead to a repositioning
1425 transition
= kWindowSheetTransitionEffect
;
1428 transition
= kWindowZoomTransitionEffect
;
1431 case wxSHOW_EFFECT_NONE
:
1432 // wxNonOwnedWindow is supposed to call Show() itself in this case
1433 wxFAIL_MSG( "ShowWithEffect() shouldn't be called" );
1436 case wxSHOW_EFFECT_MAX
:
1437 wxFAIL_MSG( "invalid effect flag" );
1441 TransitionWindowOptions options
;
1442 options
.version
= 0;
1443 options
.duration
= timeout
/ 1000.0;
1444 options
.window
= transition
== kWindowSheetTransitionEffect
? (WindowRef
) m_wxPeer
->GetParent()->MacGetTopLevelWindowRef() :0;
1445 options
.userData
= 0;
1447 wxSize size
= wxGetDisplaySize();
1449 GetWindowBounds( (WindowRef
)m_macWindow
, kWindowStructureRgn
, &bounds
);
1450 CGRect hiBounds
= CGRectMake( bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
);
1454 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1455 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1456 hiBounds
.origin
.x
= 0;
1457 hiBounds
.size
.width
= 0;
1460 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1461 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1462 hiBounds
.origin
.x
= size
.x
;
1463 hiBounds
.size
.width
= 0;
1466 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1467 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1468 hiBounds
.origin
.y
= size
.y
;
1469 hiBounds
.size
.height
= 0;
1472 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1473 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1474 hiBounds
.origin
.y
= 0;
1475 hiBounds
.size
.height
= 0;
1479 break; // direction doesn't make sense
1482 ::TransitionWindowWithOptions
1484 (WindowRef
)m_macWindow
,
1486 show
? kWindowShowTransitionAction
: kWindowHideTransitionAction
,
1487 transition
== kWindowGenieTransitionEffect
? &hiBounds
: NULL
,
1494 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1500 void wxNonOwnedWindowCarbonImpl::SetTitle( const wxString
& title
, wxFontEncoding encoding
)
1502 SetWindowTitleWithCFString( m_macWindow
, wxCFStringRef( title
, encoding
) ) ;
1505 bool wxNonOwnedWindowCarbonImpl::IsMaximized() const
1507 return IsWindowInStandardState( m_macWindow
, NULL
, NULL
) ;
1510 bool wxNonOwnedWindowCarbonImpl::IsIconized() const
1512 return IsWindowCollapsed((WindowRef
)GetWXWindow() ) ;
1515 void wxNonOwnedWindowCarbonImpl::Iconize( bool iconize
)
1517 if ( IsWindowCollapsable( m_macWindow
) )
1518 CollapseWindow( m_macWindow
, iconize
) ;
1521 void wxNonOwnedWindowCarbonImpl::Maximize(bool maximize
)
1523 Point idealSize
= { 0 , 0 } ;
1526 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1528 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
1530 idealSize
.h
= bounds
.size
.width
;
1531 idealSize
.v
= bounds
.size
.height
;
1534 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
1535 idealSize
.h
= rect
.right
- rect
.left
;
1536 idealSize
.v
= rect
.bottom
- rect
.top
;
1539 ZoomWindowIdeal( (WindowRef
)GetWXWindow() , maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
1542 bool wxNonOwnedWindowCarbonImpl::IsFullScreen() const
1544 return m_macFullScreenData
!= NULL
;
1547 bool wxNonOwnedWindowCarbonImpl::ShowFullScreen(bool show
, long style
)
1551 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1553 data
= new FullScreenData() ;
1555 m_macFullScreenData
= data
;
1556 data
->m_position
= m_wxPeer
->GetPosition() ;
1557 data
->m_size
= m_wxPeer
->GetSize() ;
1558 #if wxOSX_USE_CARBON
1559 WindowAttributes attr
= 0;
1560 GetWindowAttributes((WindowRef
) GetWXWindow(), &attr
);
1561 data
->m_wasResizable
= attr
& kWindowResizableAttribute
;
1562 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1566 wxRect client
= wxGetClientDisplayRect() ;
1568 int left
, top
, width
, height
;
1576 GetContentArea( left
, top
, width
, height
) ;
1577 int outerwidth
, outerheight
;
1578 GetSize( outerwidth
, outerheight
);
1580 if ( style
& wxFULLSCREEN_NOCAPTION
)
1584 // avoid adding the caption twice to the height
1588 if ( style
& wxFULLSCREEN_NOBORDER
)
1591 w
+= outerwidth
- width
;
1592 h
+= outerheight
- height
;
1595 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1600 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1605 m_wxPeer
->SetSize( x
, y
, w
, h
) ;
1606 if ( data
->m_wasResizable
)
1608 #if wxOSX_USE_CARBON
1609 ChangeWindowAttributes( (WindowRef
) GetWXWindow() , kWindowNoAttributes
, kWindowResizableAttribute
) ;
1613 else if ( m_macFullScreenData
!= NULL
)
1615 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1616 #if wxOSX_USE_CARBON
1618 if ( data
->m_wasResizable
)
1619 ChangeWindowAttributes( (WindowRef
) GetWXWindow() , kWindowResizableAttribute
, kWindowNoAttributes
) ;
1621 m_wxPeer
->SetPosition( data
->m_position
) ;
1622 m_wxPeer
->SetSize( data
->m_size
) ;
1625 m_macFullScreenData
= NULL
;
1631 // Attracts the users attention to this window if the application is
1632 // inactive (should be called when a background event occurs)
1634 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1637 DisposePtr( (Ptr
)ptr
) ;
1640 void wxNonOwnedWindowCarbonImpl::RequestUserAttention(int WXUNUSED(flags
))
1642 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1644 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1645 notificationRequest
->qType
= nmType
;
1646 notificationRequest
->nmMark
= 1 ;
1647 notificationRequest
->nmIcon
= 0 ;
1648 notificationRequest
->nmSound
= 0 ;
1649 notificationRequest
->nmStr
= NULL
;
1650 notificationRequest
->nmResp
= wxMacNMResponse
;
1652 verify_noerr( NMInstall( notificationRequest
) ) ;
1655 void wxNonOwnedWindowCarbonImpl::ScreenToWindow( int *x
, int *y
)
1657 HIPoint p
= CGPointMake( (x
? *x
: 0), (y
? *y
: 0) );
1658 HIViewRef contentView
;
1659 // TODO check toolbar offset
1660 HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowContentID
, &contentView
) ;
1661 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
1668 void wxNonOwnedWindowCarbonImpl::WindowToScreen( int *x
, int *y
)
1670 HIPoint p
= CGPointMake( (x
? *x
: 0), (y
? *y
: 0) );
1671 HIViewRef contentView
;
1672 // TODO check toolbar offset
1673 HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowContentID
, &contentView
) ;
1674 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
1681 bool wxNonOwnedWindowCarbonImpl::IsActive()
1683 return ActiveNonFloatingWindow() == m_macWindow
;
1686 wxNonOwnedWindowImpl
* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
1687 long style
, long extraStyle
, const wxString
& name
)
1689 wxNonOwnedWindowImpl
* now
= new wxNonOwnedWindowCarbonImpl( wxpeer
);
1690 now
->Create( parent
, pos
, size
, style
, extraStyle
, name
);