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 m_wxPeer
->SetBackgroundStyle(wxBG_STYLE_SYSTEM
);
103 // call directly if object is not yet completely constructed
104 if ( m_wxPeer
->GetNonOwnedPeer() == NULL
)
105 SetBackgroundStyle(wxBG_STYLE_SYSTEM
);
107 else if ( col
== wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive
)) )
109 SetThemeWindowBackground( (WindowRef
) m_macWindow
, kThemeBrushDialogBackgroundActive
, false ) ;
110 m_wxPeer
->SetBackgroundStyle(wxBG_STYLE_SYSTEM
);
111 // call directly if object is not yet completely constructed
112 if ( m_wxPeer
->GetNonOwnedPeer() == NULL
)
113 SetBackgroundStyle(wxBG_STYLE_SYSTEM
);
118 void wxNonOwnedWindowCarbonImpl::SetExtraStyle( long exStyle
)
120 if ( m_macWindow
!= NULL
)
122 bool metal
= exStyle
& wxFRAME_EX_METAL
;
124 if ( MacGetMetalAppearance() != metal
)
126 if ( MacGetUnifiedAppearance() )
127 MacSetUnifiedAppearance( !metal
) ;
129 MacSetMetalAppearance( metal
) ;
134 bool wxNonOwnedWindowCarbonImpl::SetBackgroundStyle(wxBackgroundStyle style
)
136 if ( style
== wxBG_STYLE_TRANSPARENT
)
138 OSStatus err
= HIWindowChangeFeatures( m_macWindow
, 0, kWindowIsOpaque
);
140 err
= ReshapeCustomWindow( m_macWindow
);
147 bool wxNonOwnedWindowCarbonImpl::CanSetTransparent()
152 void wxNonOwnedWindowCarbonImpl::GetContentArea( int &left
, int &top
, int &width
, int &height
) const
154 Rect content
, structure
;
156 GetWindowBounds( m_macWindow
, kWindowStructureRgn
, &structure
) ;
157 GetWindowBounds( m_macWindow
, kWindowContentRgn
, &content
) ;
159 left
= content
.left
- structure
.left
;
160 top
= content
.top
- structure
.top
;
161 width
= content
.right
- content
.left
;
162 height
= content
.bottom
- content
.top
;
165 void wxNonOwnedWindowCarbonImpl::MoveWindow(int x
, int y
, int width
, int height
)
167 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
168 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
171 void wxNonOwnedWindowCarbonImpl::GetPosition( int &x
, int &y
) const
175 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
181 void wxNonOwnedWindowCarbonImpl::GetSize( int &width
, int &height
) const
185 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
187 width
= bounds
.right
- bounds
.left
;
188 height
= bounds
.bottom
- bounds
.top
;
191 bool wxNonOwnedWindowCarbonImpl::MacGetUnifiedAppearance() const
193 return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute
;
196 void wxNonOwnedWindowCarbonImpl::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
198 ChangeWindowAttributes( m_macWindow
, attributesToSet
, attributesToClear
) ;
201 wxUint32
wxNonOwnedWindowCarbonImpl::MacGetWindowAttributes() const
204 GetWindowAttributes( m_macWindow
, &attr
) ;
208 void wxNonOwnedWindowCarbonImpl::MacSetMetalAppearance( bool set
)
210 if ( MacGetUnifiedAppearance() )
211 MacSetUnifiedAppearance( false ) ;
213 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
214 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
217 bool wxNonOwnedWindowCarbonImpl::MacGetMetalAppearance() const
219 return MacGetWindowAttributes() & kWindowMetalAttribute
;
222 void wxNonOwnedWindowCarbonImpl::MacSetUnifiedAppearance( bool set
)
224 if ( MacGetMetalAppearance() )
225 MacSetMetalAppearance( false ) ;
227 MacChangeWindowAttributes( set
? kWindowUnifiedTitleAndToolbarAttribute
: kWindowNoAttributes
,
228 set
? kWindowNoAttributes
: kWindowUnifiedTitleAndToolbarAttribute
) ;
230 // For some reason, Tiger uses white as the background color for this appearance,
231 // while most apps using it use the typical striped background. Restore that behavior
233 // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
235 // since when creating the peering is not yet completely set-up we call both setters
237 m_wxPeer
->SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
) ) ;
238 SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
) ) ;
242 // ----------------------------------------------------------------------------
244 // ----------------------------------------------------------------------------
246 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
249 // ---------------------------------------------------------------------------
251 // ---------------------------------------------------------------------------
253 static const EventTypeSpec eventList
[] =
255 // TODO: remove control related event like key and mouse (except for WindowLeave events)
257 { kEventClassKeyboard
, kEventRawKeyDown
} ,
258 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
259 { kEventClassKeyboard
, kEventRawKeyUp
} ,
260 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
262 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
263 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
265 { kEventClassWindow
, kEventWindowShown
} ,
266 { kEventClassWindow
, kEventWindowActivated
} ,
267 { kEventClassWindow
, kEventWindowDeactivated
} ,
268 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
269 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
270 { kEventClassWindow
, kEventWindowClose
} ,
271 { kEventClassWindow
, kEventWindowGetRegion
} ,
273 // we have to catch these events on the toplevel window level,
274 // as controls don't get the raw mouse events anymore
276 { kEventClassMouse
, kEventMouseDown
} ,
277 { kEventClassMouse
, kEventMouseUp
} ,
278 { kEventClassMouse
, kEventMouseWheelMoved
} ,
279 { kEventClassMouse
, kEventMouseMoved
} ,
280 { kEventClassMouse
, kEventMouseDragged
} ,
283 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
285 OSStatus result
= eventNotHandledErr
;
286 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
287 // FindFocus does not return the actual focus window, but the enclosing window
288 wxWindow
* focus
= wxWindow::DoFindFocus();
290 focus
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
292 unsigned char charCode
;
300 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
303 ByteCount dataSize
= 0 ;
304 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
307 int numChars
= dataSize
/ sizeof( UniChar
) + 1;
309 UniChar
* charBuf
= buf
;
311 if ( numChars
* 2 > 4 )
312 charBuf
= new UniChar
[ numChars
] ;
313 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
314 charBuf
[ numChars
- 1 ] = 0;
316 #if SIZEOF_WCHAR_T == 2
317 uniChar
= charBuf
[0] ;
319 wxMBConvUTF16 converter
;
320 converter
.MB2WC( uniChar
, (const char*)charBuf
, 2 ) ;
323 if ( numChars
* 2 > 4 )
328 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
329 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
330 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
331 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
333 UInt32 message
= (keyCode
<< 8) + charCode
;
334 switch ( GetEventKind( event
) )
336 case kEventRawKeyRepeat
:
337 case kEventRawKeyDown
:
339 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
340 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
341 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
342 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
343 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
347 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
351 case kEventRawKeyUp
:
352 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
353 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
359 case kEventRawKeyModifiersChanged
:
361 wxKeyEvent
event(wxEVT_KEY_DOWN
);
363 event
.m_shiftDown
= modifiers
& shiftKey
;
364 event
.m_controlDown
= modifiers
& controlKey
;
365 event
.m_altDown
= modifiers
& optionKey
;
366 event
.m_metaDown
= modifiers
& cmdKey
;
371 event
.m_uniChar
= uniChar
[0] ;
374 event
.SetTimestamp(when
);
375 event
.SetEventObject(focus
);
377 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
379 event
.m_keyCode
= WXK_CONTROL
;
380 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
381 focus
->HandleWindowEvent( event
) ;
383 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
385 event
.m_keyCode
= WXK_SHIFT
;
386 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
387 focus
->HandleWindowEvent( event
) ;
389 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
391 event
.m_keyCode
= WXK_ALT
;
392 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
393 focus
->HandleWindowEvent( event
) ;
395 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
397 event
.m_keyCode
= WXK_COMMAND
;
398 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
399 focus
->HandleWindowEvent( event
) ;
402 wxApp::s_lastModifiers
= modifiers
;
413 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
414 // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
417 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
419 EventMouseButton g_lastButton
= 0 ;
420 bool g_lastButtonWasFakeRight
= false ;
422 void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
424 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
425 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
427 // these parameters are not given for all events
428 EventMouseButton button
= 0 ;
429 UInt32 clickCount
= 0 ;
430 UInt32 mouseChord
= 0;
432 cEvent
.GetParameter
<EventMouseButton
>( kEventParamMouseButton
, typeMouseButton
, &button
) ;
433 cEvent
.GetParameter
<UInt32
>( kEventParamClickCount
, typeUInt32
, &clickCount
) ;
434 // the chord is the state of the buttons pressed currently
435 cEvent
.GetParameter
<UInt32
>( kEventParamMouseChord
, typeUInt32
, &mouseChord
) ;
437 wxevent
.m_x
= screenMouseLocation
.h
;
438 wxevent
.m_y
= screenMouseLocation
.v
;
439 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
440 wxevent
.m_controlDown
= modifiers
& controlKey
;
441 wxevent
.m_altDown
= modifiers
& optionKey
;
442 wxevent
.m_metaDown
= modifiers
& cmdKey
;
443 wxevent
.m_clickCount
= clickCount
;
444 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
446 // a control click is interpreted as a right click
447 bool thisButtonIsFakeRight
= false ;
448 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
450 button
= kEventMouseButtonSecondary
;
451 thisButtonIsFakeRight
= true ;
454 // otherwise we report double clicks by connecting a left click with a ctrl-left click
455 if ( clickCount
> 1 && button
!= g_lastButton
)
458 // we must make sure that our synthetic 'right' button corresponds in
459 // mouse down, moved and mouse up, and does not deliver a right down and left up
461 if ( cEvent
.GetKind() == kEventMouseDown
)
463 g_lastButton
= button
;
464 g_lastButtonWasFakeRight
= thisButtonIsFakeRight
;
470 g_lastButtonWasFakeRight
= false ;
472 else if ( g_lastButton
== kEventMouseButtonSecondary
&& g_lastButtonWasFakeRight
)
473 button
= g_lastButton
;
475 // Adjust the chord mask to remove the primary button and add the
476 // secondary button. It is possible that the secondary button is
477 // already pressed, e.g. on a mouse connected to a laptop, but this
478 // possibility is ignored here:
479 if( thisButtonIsFakeRight
&& ( mouseChord
& 1U ) )
480 mouseChord
= ((mouseChord
& ~1U) | 2U);
483 wxevent
.m_leftDown
= true ;
485 wxevent
.m_rightDown
= true ;
487 wxevent
.m_middleDown
= true ;
489 // translate into wx types
490 switch ( cEvent
.GetKind() )
492 case kEventMouseDown
:
495 case kEventMouseButtonPrimary
:
496 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
499 case kEventMouseButtonSecondary
:
500 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
503 case kEventMouseButtonTertiary
:
504 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
515 case kEventMouseButtonPrimary
:
516 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
519 case kEventMouseButtonSecondary
:
520 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
523 case kEventMouseButtonTertiary
:
524 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
532 case kEventMouseWheelMoved
:
534 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
536 EventMouseWheelAxis axis
= cEvent
.GetParameter
<EventMouseWheelAxis
>(kEventParamMouseWheelAxis
, typeMouseWheelAxis
) ;
537 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeSInt32
) ;
539 wxevent
.m_wheelRotation
= delta
;
540 wxevent
.m_wheelDelta
= 1;
541 wxevent
.m_linesPerAction
= 1;
542 if ( axis
== kEventMouseWheelAxisX
)
543 wxevent
.m_wheelAxis
= 1;
547 case kEventMouseEntered
:
548 case kEventMouseExited
:
549 case kEventMouseDragged
:
550 case kEventMouseMoved
:
551 wxevent
.SetEventType( wxEVT_MOTION
) ;
558 #define NEW_CAPTURE_HANDLING 1
561 wxMacTopLevelMouseEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
565 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
567 OSStatus result
= eventNotHandledErr
;
569 wxMacCarbonEvent
cEvent( event
) ;
571 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
572 Point windowMouseLocation
= screenMouseLocation
;
574 WindowRef window
= NULL
;
575 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
577 wxWindow
* currentMouseWindow
= NULL
;
578 ControlRef control
= NULL
;
580 #if NEW_CAPTURE_HANDLING
581 if ( wxApp::s_captureWindow
)
583 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
584 windowPart
= inContent
;
590 QDGlobalToLocalPoint( GetWindowPort( window
), &windowMouseLocation
);
592 if ( wxApp::s_captureWindow
593 #if !NEW_CAPTURE_HANDLING
594 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
598 currentMouseWindow
= wxApp::s_captureWindow
;
600 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
602 ControlPartCode part
;
603 control
= FindControlUnderMouse( windowMouseLocation
, window
, &part
) ;
604 // if there is no control below the mouse position, send the event to the toplevel window itself
607 currentMouseWindow
= (wxWindow
*) toplevelWindow
;
611 currentMouseWindow
= (wxWindow
*) wxFindWindowFromWXWidget( (WXWidget
) control
) ;
612 #ifndef __WXUNIVERSAL__
613 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
616 // for wxToolBar to function we have to send certaint events to it
617 // instead of its children (wxToolBarTools)
619 GetSuperControl(control
, &parent
);
620 wxWindow
*wxparent
= (wxWindow
*) wxFindWindowFromWXWidget((WXWidget
) parent
) ;
621 if ( wxparent
&& wxparent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
622 currentMouseWindow
= wxparent
;
628 // disabled windows must not get any input messages
629 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
630 currentMouseWindow
= NULL
;
634 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
635 SetupMouseEvent( wxevent
, cEvent
) ;
637 // handle all enter / leave events
639 if ( currentMouseWindow
!= g_MacLastWindow
)
641 if ( g_MacLastWindow
)
643 wxMouseEvent
eventleave(wxevent
);
644 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
645 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
646 eventleave
.SetEventObject( g_MacLastWindow
) ;
647 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
650 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
653 g_MacLastWindow
->HandleWindowEvent(eventleave
);
656 if ( currentMouseWindow
)
658 wxMouseEvent
evententer(wxevent
);
659 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
660 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
661 evententer
.SetEventObject( currentMouseWindow
) ;
662 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
665 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
668 currentMouseWindow
->HandleWindowEvent(evententer
);
671 g_MacLastWindow
= currentMouseWindow
;
674 if ( windowPart
== inMenuBar
)
676 // special case menu bar, as we are having a low-level runloop we must do it ourselves
677 if ( cEvent
.GetKind() == kEventMouseDown
)
679 ::MenuSelect( screenMouseLocation
) ;
684 else if ( window
&& windowPart
== inProxyIcon
)
686 // special case proxy icon bar, as we are having a low-level runloop we must do it ourselves
687 if ( cEvent
.GetKind() == kEventMouseDown
)
689 if ( ::TrackWindowProxyDrag( window
, screenMouseLocation
) != errUserWantsToDragWindow
)
691 // TODO Track change of file path and report back
696 else if ( currentMouseWindow
)
698 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
700 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
702 wxevent
.SetEventObject( currentMouseWindow
) ;
703 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
705 // make tooltips current
708 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
709 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
712 if ( currentMouseWindow
->HandleWindowEvent(wxevent
) )
714 if ((currentMouseWindowParent
!= NULL
) &&
715 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
716 currentMouseWindow
= NULL
;
722 // if the user code did _not_ handle the event, then perform the
723 // default processing
724 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
726 // ... that is set focus to this window
727 if (currentMouseWindow
->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
728 currentMouseWindow
->SetFocus();
732 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
734 wxApp::s_captureWindow
= NULL
;
740 wxWindow
* cursorTarget
= currentMouseWindow
;
741 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
743 extern wxCursor gGlobalCursor
;
745 if (!gGlobalCursor
.IsOk())
747 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
749 cursorTarget
= cursorTarget
->GetParent() ;
751 cursorPoint
+= cursorTarget
->GetPosition();
756 else // currentMouseWindow == NULL
758 if (toplevelWindow
&& !control
)
760 extern wxCursor gGlobalCursor
;
761 if (!gGlobalCursor
.IsOk())
763 // update cursor when over toolbar and titlebar etc.
764 wxSTANDARD_CURSOR
->MacInstall() ;
768 // don't mess with controls we don't know about
769 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
770 // so we try sending them the correct control directly
771 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
773 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
774 Point clickLocation
= windowMouseLocation
;
777 hiPoint
.x
= clickLocation
.h
;
778 hiPoint
.y
= clickLocation
.v
;
779 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
780 clickLocation
.h
= (int)hiPoint
.x
;
781 clickLocation
.v
= (int)hiPoint
.y
;
783 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
791 static pascal OSStatus
792 wxNonOwnedWindowEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
796 OSStatus result
= eventNotHandledErr
;
798 wxMacCarbonEvent
cEvent( event
) ;
800 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
801 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
803 switch ( GetEventKind( event
) )
805 case kEventWindowActivated
:
807 toplevelWindow
->HandleActivated( cEvent
.GetTicks() , true) ;
808 // we still sending an eventNotHandledErr in order to allow for default processing
812 case kEventWindowDeactivated
:
814 toplevelWindow
->HandleActivated( cEvent
.GetTicks() , false) ;
815 // we still sending an eventNotHandledErr in order to allow for default processing
819 case kEventWindowShown
:
820 toplevelWindow
->Refresh() ;
824 case kEventWindowClose
:
825 toplevelWindow
->Close() ;
829 case kEventWindowBoundsChanged
:
831 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
832 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
833 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
834 if ( attributes
& kWindowBoundsChangeSizeChanged
)
836 toplevelWindow
->HandleResized(cEvent
.GetTicks() ) ;
839 if ( attributes
& kWindowBoundsChangeOriginChanged
)
841 toplevelWindow
->HandleMoved(cEvent
.GetTicks() ) ;
848 case kEventWindowBoundsChanging
:
850 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
851 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
853 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
855 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
856 int left
, top
, width
, height
;
860 toplevelWindow
->GetNonOwnedPeer()->GetContentArea(left
, top
, width
, height
);
861 toplevelWindow
->GetNonOwnedPeer()->GetSize(swidth
, sheight
);
862 int deltawidth
= swidth
- width
;
863 int deltaheight
= sheight
- height
;
867 newRect
.right
- newRect
.left
+ deltawidth
,
868 newRect
.bottom
- newRect
.top
+ deltaheight
) ;
870 toplevelWindow
->HandleResizing( cEvent
.GetTicks(), &adjustR
);
872 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ top
+ adjustR
.height
- deltaheight
,
873 adjustR
.x
+ left
+ adjustR
.width
- deltawidth
} ;
874 if ( !EqualRect( &newRect
, &adjustedRect
) )
875 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
882 case kEventWindowGetRegion
:
884 if ( toplevelWindow
->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
886 WindowRegionCode windowRegionCode
;
888 // Fetch the region code that is being queried
889 GetEventParameter( event
,
890 kEventParamWindowRegionCode
,
891 typeWindowRegionCode
, NULL
,
892 sizeof windowRegionCode
, NULL
,
893 &windowRegionCode
) ;
895 // If it is the opaque region code then set the
896 // region to empty and return noErr to stop event
898 if ( windowRegionCode
== kWindowOpaqueRgn
) {
900 GetEventParameter( event
,
901 kEventParamRgnHandle
,
902 typeQDRgnHandle
, NULL
,
905 SetEmptyRgn(region
) ;
919 // mix this in from window.cpp
920 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
922 pascal OSStatus
wxNonOwnedEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
924 OSStatus result
= eventNotHandledErr
;
926 switch ( GetEventClass( event
) )
928 case kEventClassTextInput
:
930 // TODO remove as soon as all events are on implementation classes only
931 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
933 result
= wxMacUnicodeTextEventHandler( handler
, event
, toplevelWindow
) ;
937 case kEventClassKeyboard
:
938 result
= KeyboardEventHandler( handler
, event
, data
) ;
941 case kEventClassWindow
:
942 result
= wxNonOwnedWindowEventHandler( handler
, event
, data
) ;
945 case kEventClassMouse
:
946 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
956 DEFINE_ONE_SHOT_HANDLER_GETTER( wxNonOwnedEventHandler
)
958 // ---------------------------------------------------------------------------
959 // Support functions for shaped windows, based on Apple's CustomWindow sample at
960 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
961 // ---------------------------------------------------------------------------
963 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
965 GetWindowPortBounds(window
, inRect
);
966 Point pt
= { inRect
->top
,inRect
->left
};
967 QDLocalToGlobalPoint( GetWindowPort( window
), &pt
);
968 inRect
->bottom
+= pt
.v
- inRect
->top
;
969 inRect
->right
+= pt
.h
- inRect
->left
;
974 static SInt32
wxShapedMacWindowGetFeatures(WindowRef
WXUNUSED(window
), SInt32 param
)
976 /*------------------------------------------------------
977 Define which options your custom window supports.
978 --------------------------------------------------------*/
979 //just enable everything for our demo
980 *(OptionBits
*)param
=
984 //kWindowCanGetWindowRegion |
985 //kWindowHasTitleBar |
986 //kWindowSupportsDragHilite |
987 kWindowCanDrawInCurrentPort
|
988 //kWindowCanMeasureTitle |
989 kWindowWantsDisposeAtProcessDeath
|
990 kWindowSupportsGetGrowImageRegion
|
991 kWindowDefSupportsColorGrafPort
;
996 // The content region is left as a rectangle matching the window size, this is
997 // so the origin in the paint event, and etc. still matches what the
998 // programmer expects.
999 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1002 wxNonOwnedWindow
* win
= wxNonOwnedWindow::GetFromWXWindow((WXWindow
)window
);
1006 wxShapedMacWindowGetPos( window
, &r
) ;
1007 RectRgn( rgn
, &r
) ;
1011 // The structure region is set to the shape given to the SetShape method.
1012 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1014 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1020 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1021 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1022 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1023 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1027 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1029 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1034 switch (rgnRec
->regionCode
)
1036 case kWindowStructureRgn
:
1037 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1040 case kWindowContentRgn
:
1041 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1045 SetEmptyRgn(rgnRec
->winRgn
);
1052 // Determine the region of the window which was hit
1054 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1057 static RgnHandle tempRgn
= NULL
;
1059 if (tempRgn
== NULL
)
1062 // get the point clicked
1063 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1065 // Mac OS 8.5 or later
1066 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1067 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1070 // no significant area was hit
1074 static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode
), WindowRef window
, SInt16 message
, SInt32 param
)
1078 case kWindowMsgHitTest
:
1079 return wxShapedMacWindowHitTest(window
, param
);
1081 case kWindowMsgGetFeatures
:
1082 return wxShapedMacWindowGetFeatures(window
, param
);
1084 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1085 case kWindowMsgGetRegion
:
1086 return wxShapedMacWindowGetRegion(window
, param
);
1099 wxPoint m_position
;
1101 bool m_wasResizable
;
1104 wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl()
1108 wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl( wxNonOwnedWindow
* nonownedwnd
) : wxNonOwnedWindowImpl( nonownedwnd
)
1110 m_macEventHandler
= NULL
;
1112 m_macFullScreenData
= NULL
;
1115 wxNonOwnedWindowCarbonImpl::~wxNonOwnedWindowCarbonImpl()
1118 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
1121 if ( m_macEventHandler
)
1123 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1124 m_macEventHandler
= NULL
;
1128 DisposeWindow( m_macWindow
);
1130 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1132 m_macFullScreenData
= NULL
;
1138 void wxNonOwnedWindowCarbonImpl::Destroy()
1140 if ( m_macEventHandler
)
1142 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1143 m_macEventHandler
= NULL
;
1146 wxPendingDelete
.Append( new wxDeferredObjectDeleter( this ) ) ;
1149 void wxNonOwnedWindowInstallTopLevelWindowEventHandler(WindowRef window
, EventHandlerRef
* handler
, void *ref
)
1151 InstallWindowEventHandler(window
, GetwxNonOwnedEventHandlerUPP(),
1152 GetEventTypeCount(eventList
), eventList
, ref
, handler
);
1155 bool wxNonOwnedWindowCarbonImpl::SetShape(const wxRegion
& region
)
1157 // Make a copy of the region
1158 RgnHandle shapeRegion
= NewRgn();
1159 HIShapeGetAsQDRgn( region
.GetWXHRGN(), shapeRegion
);
1161 // Dispose of any shape region we may already have
1162 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
) m_wxPeer
->GetWXWindow() );
1166 // Save the region so we can use it later
1167 SetWRefCon((WindowRef
) m_wxPeer
->GetWXWindow(), (URefCon
)shapeRegion
);
1169 // inform the window manager that the window has changed shape
1170 ReshapeCustomWindow((WindowRef
) m_wxPeer
->GetWXWindow());
1176 void wxNonOwnedWindowCarbonImpl::MacInstallTopLevelWindowEventHandler()
1178 if ( m_macEventHandler
!= NULL
)
1180 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1182 wxNonOwnedWindowInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow
),(EventHandlerRef
*)&m_macEventHandler
,this);
1185 void wxNonOwnedWindowCarbonImpl::Create(
1189 long style
, long extraStyle
,
1190 const wxString
& WXUNUSED(name
) )
1193 OSStatus err
= noErr
;
1202 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1204 // translate the window attributes in the appropriate window class and attributes
1205 WindowClass wclass
= 0;
1206 WindowAttributes attr
= kWindowNoAttributes
;
1207 WindowGroupRef group
= NULL
;
1208 bool activationScopeSet
= false;
1209 WindowActivationScope activationScope
= kWindowActivationScopeNone
;
1211 if ( style
& wxFRAME_TOOL_WINDOW
)
1214 ( style
& wxMINIMIZE_BOX
) || ( style
& wxMAXIMIZE_BOX
) ||
1215 ( style
& wxSYSTEM_MENU
) || ( style
& wxCAPTION
) ||
1216 ( style
&wxTINY_CAPTION_HORIZ
) || ( style
&wxTINY_CAPTION_VERT
)
1219 if ( ( style
& wxSTAY_ON_TOP
) )
1220 wclass
= kUtilityWindowClass
;
1222 wclass
= kFloatingWindowClass
;
1224 if ( ( style
&wxTINY_CAPTION_VERT
) )
1225 attr
|= kWindowSideTitlebarAttribute
;
1229 if ( style
& wxNO_BORDER
)
1231 wclass
= kSimpleWindowClass
;
1235 wclass
= kPlainWindowClass
;
1237 activationScopeSet
= true;
1238 activationScope
= kWindowActivationScopeNone
;
1241 else if ( ( style
& wxPOPUP_WINDOW
) )
1243 if ( ( style
& wxBORDER_NONE
) )
1245 wclass
= kHelpWindowClass
; // has no border
1246 attr
|= kWindowNoShadowAttribute
;
1250 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1252 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1253 // make sure we don't deactivate something
1254 activationScopeSet
= true;
1255 activationScope
= kWindowActivationScopeNone
;
1257 else if ( ( style
& wxCAPTION
) )
1259 wclass
= kDocumentWindowClass
;
1260 attr
|= kWindowInWindowMenuAttribute
;
1262 else if ( ( style
& wxFRAME_DRAWER
) )
1264 wclass
= kDrawerWindowClass
;
1268 if ( ( style
& wxMINIMIZE_BOX
) || ( style
& wxMAXIMIZE_BOX
) ||
1269 ( style
& wxCLOSE_BOX
) || ( style
& wxSYSTEM_MENU
) )
1271 wclass
= kDocumentWindowClass
;
1273 else if ( ( style
& wxNO_BORDER
) )
1275 wclass
= kSimpleWindowClass
;
1279 wclass
= kPlainWindowClass
;
1283 if ( wclass
!= kPlainWindowClass
)
1285 if ( ( style
& wxMINIMIZE_BOX
) )
1286 attr
|= kWindowCollapseBoxAttribute
;
1288 if ( ( style
& wxMAXIMIZE_BOX
) )
1289 attr
|= kWindowFullZoomAttribute
;
1291 if ( ( style
& wxRESIZE_BORDER
) )
1292 attr
|= kWindowResizableAttribute
;
1294 if ( ( style
& wxCLOSE_BOX
) )
1295 attr
|= kWindowCloseBoxAttribute
;
1297 attr
|= kWindowLiveResizeAttribute
;
1299 if ( ( style
&wxSTAY_ON_TOP
) )
1300 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1302 if ( ( style
& wxFRAME_FLOAT_ON_PARENT
) )
1303 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1305 if ( group
== NULL
&& parent
!= NULL
)
1307 WindowRef parenttlw
= (WindowRef
) parent
->MacGetTopLevelWindowRef();
1309 group
= GetWindowGroupParent( GetWindowGroup( parenttlw
) );
1312 attr
|= kWindowCompositingAttribute
;
1313 #if 0 // TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1314 attr
|= kWindowFrameworkScaledAttribute
;
1317 if ( ( style
&wxFRAME_SHAPED
) )
1319 WindowDefSpec customWindowDefSpec
;
1320 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1321 customWindowDefSpec
.u
.defProc
=
1323 (WindowDefUPP
) wxShapedMacWindowDef
;
1325 NewWindowDefUPP(wxShapedMacWindowDef
);
1327 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1328 attr
, &theBoundsRect
,
1329 (WindowRef
*) &m_macWindow
);
1333 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1336 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1337 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1339 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1341 // setup a separate group for each window, so that overlays can be handled easily
1343 WindowGroupRef overlaygroup
= NULL
;
1344 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &overlaygroup
));
1345 verify_noerr( SetWindowGroupParent( overlaygroup
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1346 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, overlaygroup
));
1348 if ( activationScopeSet
)
1350 verify_noerr( SetWindowActivationScope( (WindowRef
) m_macWindow
, activationScope
));
1353 // the create commands are only for content rect,
1354 // so we have to set the size again as structure bounds
1355 SetWindowBounds( m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1357 // Causes the inner part of the window not to be metal
1358 // if the style is used before window creation.
1359 #if 0 // TARGET_API_MAC_OSX
1360 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1362 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1363 MacSetMetalAppearance( true ) ;
1367 if ( m_macWindow
!= NULL
)
1369 MacSetUnifiedAppearance( true ) ;
1372 HIViewRef growBoxRef
= 0 ;
1373 err
= HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowGrowBoxID
, &growBoxRef
);
1374 if ( err
== noErr
&& growBoxRef
!= 0 )
1375 HIGrowBoxViewSetTransparent( growBoxRef
, true ) ;
1377 // the frame window event handler
1378 InstallStandardEventHandler( GetWindowEventTarget(m_macWindow
) ) ;
1379 MacInstallTopLevelWindowEventHandler() ;
1381 if ( extraStyle
& wxFRAME_EX_METAL
)
1382 MacSetMetalAppearance(true);
1384 if ( ( style
&wxFRAME_SHAPED
) )
1386 // default shape matches the window size
1387 wxRegion
rgn( 0, 0, w
, h
);
1392 bool wxNonOwnedWindowCarbonImpl::ShowWithEffect(bool show
,
1393 wxShowEffect effect
,
1396 WindowTransitionEffect transition
= 0 ;
1399 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1400 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1401 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1402 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1403 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1404 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1405 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1406 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1407 transition
= kWindowGenieTransitionEffect
;
1409 case wxSHOW_EFFECT_BLEND
:
1410 transition
= kWindowFadeTransitionEffect
;
1412 case wxSHOW_EFFECT_EXPAND
:
1413 // having sheets would be fine, but this might lead to a repositioning
1416 transition
= kWindowSheetTransitionEffect
;
1419 transition
= kWindowZoomTransitionEffect
;
1422 case wxSHOW_EFFECT_MAX
:
1423 wxFAIL_MSG( "invalid effect flag" );
1427 TransitionWindowOptions options
;
1428 options
.version
= 0;
1429 options
.duration
= timeout
/ 1000.0;
1430 options
.window
= transition
== kWindowSheetTransitionEffect
? (WindowRef
) m_wxPeer
->GetParent()->MacGetTopLevelWindowRef() :0;
1431 options
.userData
= 0;
1433 wxSize size
= wxGetDisplaySize();
1435 GetWindowBounds( (WindowRef
)m_macWindow
, kWindowStructureRgn
, &bounds
);
1436 CGRect hiBounds
= CGRectMake( bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
);
1440 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1441 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1442 hiBounds
.origin
.x
= 0;
1443 hiBounds
.size
.width
= 0;
1446 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1447 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1448 hiBounds
.origin
.x
= size
.x
;
1449 hiBounds
.size
.width
= 0;
1452 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1453 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1454 hiBounds
.origin
.y
= size
.y
;
1455 hiBounds
.size
.height
= 0;
1458 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1459 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1460 hiBounds
.origin
.y
= 0;
1461 hiBounds
.size
.height
= 0;
1465 break; // direction doesn't make sense
1468 ::TransitionWindowWithOptions
1470 (WindowRef
)m_macWindow
,
1472 show
? kWindowShowTransitionAction
: kWindowHideTransitionAction
,
1473 transition
== kWindowGenieTransitionEffect
? &hiBounds
: NULL
,
1480 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1486 void wxNonOwnedWindowCarbonImpl::SetTitle( const wxString
& title
, wxFontEncoding encoding
)
1488 SetWindowTitleWithCFString( m_macWindow
, wxCFStringRef( title
, encoding
) ) ;
1491 bool wxNonOwnedWindowCarbonImpl::IsMaximized() const
1493 return IsWindowInStandardState( m_macWindow
, NULL
, NULL
) ;
1496 bool wxNonOwnedWindowCarbonImpl::IsIconized() const
1498 return IsWindowCollapsed((WindowRef
)GetWXWindow() ) ;
1501 void wxNonOwnedWindowCarbonImpl::Iconize( bool iconize
)
1503 if ( IsWindowCollapsable( m_macWindow
) )
1504 CollapseWindow( m_macWindow
, iconize
) ;
1507 void wxNonOwnedWindowCarbonImpl::Maximize(bool maximize
)
1509 Point idealSize
= { 0 , 0 } ;
1512 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1514 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
1516 idealSize
.h
= bounds
.size
.width
;
1517 idealSize
.v
= bounds
.size
.height
;
1520 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
1521 idealSize
.h
= rect
.right
- rect
.left
;
1522 idealSize
.v
= rect
.bottom
- rect
.top
;
1525 ZoomWindowIdeal( (WindowRef
)GetWXWindow() , maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
1528 bool wxNonOwnedWindowCarbonImpl::IsFullScreen() const
1530 return m_macFullScreenData
!= NULL
;
1533 bool wxNonOwnedWindowCarbonImpl::ShowFullScreen(bool show
, long style
)
1537 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1539 data
= new FullScreenData() ;
1541 m_macFullScreenData
= data
;
1542 data
->m_position
= m_wxPeer
->GetPosition() ;
1543 data
->m_size
= m_wxPeer
->GetSize() ;
1544 #if wxOSX_USE_CARBON
1545 WindowAttributes attr
= 0;
1546 GetWindowAttributes((WindowRef
) GetWXWindow(), &attr
);
1547 data
->m_wasResizable
= attr
& kWindowResizableAttribute
;
1548 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1552 wxRect client
= wxGetClientDisplayRect() ;
1554 int left
, top
, width
, height
;
1562 GetContentArea( left
, top
, width
, height
) ;
1563 int outerwidth
, outerheight
;
1564 GetSize( outerwidth
, outerheight
);
1566 if ( style
& wxFULLSCREEN_NOCAPTION
)
1570 // avoid adding the caption twice to the height
1574 if ( style
& wxFULLSCREEN_NOBORDER
)
1577 w
+= outerwidth
- width
;
1578 h
+= outerheight
- height
;
1581 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1586 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1591 m_wxPeer
->SetSize( x
, y
, w
, h
) ;
1592 if ( data
->m_wasResizable
)
1594 #if wxOSX_USE_CARBON
1595 ChangeWindowAttributes( (WindowRef
) GetWXWindow() , kWindowNoAttributes
, kWindowResizableAttribute
) ;
1599 else if ( m_macFullScreenData
!= NULL
)
1601 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1602 #if wxOSX_USE_CARBON
1604 if ( data
->m_wasResizable
)
1605 ChangeWindowAttributes( (WindowRef
) GetWXWindow() , kWindowResizableAttribute
, kWindowNoAttributes
) ;
1607 m_wxPeer
->SetPosition( data
->m_position
) ;
1608 m_wxPeer
->SetSize( data
->m_size
) ;
1611 m_macFullScreenData
= NULL
;
1617 // Attracts the users attention to this window if the application is
1618 // inactive (should be called when a background event occurs)
1620 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1623 DisposePtr( (Ptr
)ptr
) ;
1626 void wxNonOwnedWindowCarbonImpl::RequestUserAttention(int WXUNUSED(flags
))
1628 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1630 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1631 notificationRequest
->qType
= nmType
;
1632 notificationRequest
->nmMark
= 1 ;
1633 notificationRequest
->nmIcon
= 0 ;
1634 notificationRequest
->nmSound
= 0 ;
1635 notificationRequest
->nmStr
= NULL
;
1636 notificationRequest
->nmResp
= wxMacNMResponse
;
1638 verify_noerr( NMInstall( notificationRequest
) ) ;
1641 void wxNonOwnedWindowCarbonImpl::ScreenToWindow( int *x
, int *y
)
1643 HIPoint p
= CGPointMake( (x
? *x
: 0), (y
? *y
: 0) );
1644 HIViewRef contentView
;
1645 // TODO check toolbar offset
1646 HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowContentID
, &contentView
) ;
1647 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
1654 void wxNonOwnedWindowCarbonImpl::WindowToScreen( int *x
, int *y
)
1656 HIPoint p
= CGPointMake( (x
? *x
: 0), (y
? *y
: 0) );
1657 HIViewRef contentView
;
1658 // TODO check toolbar offset
1659 HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowContentID
, &contentView
) ;
1660 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
1667 wxNonOwnedWindowImpl
* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
1668 long style
, long extraStyle
, const wxString
& name
)
1670 wxNonOwnedWindowImpl
* now
= new wxNonOwnedWindowCarbonImpl( wxpeer
);
1671 now
->Create( parent
, pos
, size
, style
, extraStyle
, name
);