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
) ;
540 // TODO http://developer.apple.com/qa/qa2005/qa1453.html
541 // add declaration for 10.4 and change to kEventMouseScroll
542 case kEventMouseWheelMoved
:
544 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
546 EventMouseWheelAxis axis
= cEvent
.GetParameter
<EventMouseWheelAxis
>(kEventParamMouseWheelAxis
, typeMouseWheelAxis
) ;
547 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeSInt32
) ;
549 wxevent
.m_wheelRotation
= delta
;
550 wxevent
.m_wheelDelta
= 1;
551 wxevent
.m_linesPerAction
= 1;
552 if ( axis
== kEventMouseWheelAxisX
)
553 wxevent
.m_wheelAxis
= 1;
557 case kEventMouseEntered
:
558 case kEventMouseExited
:
559 case kEventMouseDragged
:
560 case kEventMouseMoved
:
561 wxevent
.SetEventType( wxEVT_MOTION
) ;
568 #define NEW_CAPTURE_HANDLING 1
571 wxMacTopLevelMouseEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
575 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
577 OSStatus result
= eventNotHandledErr
;
579 wxMacCarbonEvent
cEvent( event
) ;
581 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
582 Point windowMouseLocation
= screenMouseLocation
;
584 WindowRef window
= NULL
;
585 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
587 wxWindow
* currentMouseWindow
= NULL
;
588 ControlRef control
= NULL
;
590 #if NEW_CAPTURE_HANDLING
591 if ( wxApp::s_captureWindow
)
593 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
594 windowPart
= inContent
;
600 QDGlobalToLocalPoint( GetWindowPort( window
), &windowMouseLocation
);
602 if ( wxApp::s_captureWindow
603 #if !NEW_CAPTURE_HANDLING
604 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
608 currentMouseWindow
= wxApp::s_captureWindow
;
610 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
612 ControlPartCode part
;
613 control
= FindControlUnderMouse( windowMouseLocation
, window
, &part
) ;
614 // if there is no control below the mouse position, send the event to the toplevel window itself
617 currentMouseWindow
= (wxWindow
*) toplevelWindow
;
621 currentMouseWindow
= (wxWindow
*) wxFindWindowFromWXWidget( (WXWidget
) control
) ;
622 #ifndef __WXUNIVERSAL__
623 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
626 // for wxToolBar to function we have to send certaint events to it
627 // instead of its children (wxToolBarTools)
629 GetSuperControl(control
, &parent
);
630 wxWindow
*wxparent
= (wxWindow
*) wxFindWindowFromWXWidget((WXWidget
) parent
) ;
631 if ( wxparent
&& wxparent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
632 currentMouseWindow
= wxparent
;
638 // disabled windows must not get any input messages
639 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
640 currentMouseWindow
= NULL
;
644 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
645 SetupMouseEvent( wxevent
, cEvent
) ;
647 // handle all enter / leave events
649 if ( currentMouseWindow
!= g_MacLastWindow
)
651 if ( g_MacLastWindow
)
653 wxMouseEvent
eventleave(wxevent
);
654 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
655 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
656 eventleave
.SetEventObject( g_MacLastWindow
) ;
657 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
660 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
663 g_MacLastWindow
->HandleWindowEvent(eventleave
);
666 if ( currentMouseWindow
)
668 wxMouseEvent
evententer(wxevent
);
669 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
670 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
671 evententer
.SetEventObject( currentMouseWindow
) ;
672 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
675 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
678 currentMouseWindow
->HandleWindowEvent(evententer
);
681 g_MacLastWindow
= currentMouseWindow
;
684 if ( windowPart
== inMenuBar
)
686 // special case menu bar, as we are having a low-level runloop we must do it ourselves
687 if ( cEvent
.GetKind() == kEventMouseDown
)
689 ::MenuSelect( screenMouseLocation
) ;
694 else if ( window
&& windowPart
== inProxyIcon
)
696 // special case proxy icon bar, as we are having a low-level runloop we must do it ourselves
697 if ( cEvent
.GetKind() == kEventMouseDown
)
699 if ( ::TrackWindowProxyDrag( window
, screenMouseLocation
) != errUserWantsToDragWindow
)
701 // TODO Track change of file path and report back
706 else if ( currentMouseWindow
)
708 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
710 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
712 wxevent
.SetEventObject( currentMouseWindow
) ;
713 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
715 // make tooltips current
718 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
719 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
722 if ( currentMouseWindow
->HandleWindowEvent(wxevent
) )
724 if ((currentMouseWindowParent
!= NULL
) &&
725 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
726 currentMouseWindow
= NULL
;
732 // if the user code did _not_ handle the event, then perform the
733 // default processing
734 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
736 // ... that is set focus to this window
737 if (currentMouseWindow
->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
738 currentMouseWindow
->SetFocus();
742 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
744 wxApp::s_captureWindow
= NULL
;
750 wxWindow
* cursorTarget
= currentMouseWindow
;
751 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
753 extern wxCursor gGlobalCursor
;
755 if (!gGlobalCursor
.IsOk())
757 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
759 cursorTarget
= cursorTarget
->GetParent() ;
761 cursorPoint
+= cursorTarget
->GetPosition();
766 else // currentMouseWindow == NULL
768 if (toplevelWindow
&& !control
)
770 extern wxCursor gGlobalCursor
;
771 if (!gGlobalCursor
.IsOk())
773 // update cursor when over toolbar and titlebar etc.
774 wxSTANDARD_CURSOR
->MacInstall() ;
778 // don't mess with controls we don't know about
779 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
780 // so we try sending them the correct control directly
781 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
783 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
784 Point clickLocation
= windowMouseLocation
;
787 hiPoint
.x
= clickLocation
.h
;
788 hiPoint
.y
= clickLocation
.v
;
789 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
790 clickLocation
.h
= (int)hiPoint
.x
;
791 clickLocation
.v
= (int)hiPoint
.y
;
793 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
801 static pascal OSStatus
802 wxNonOwnedWindowEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
806 OSStatus result
= eventNotHandledErr
;
808 wxMacCarbonEvent
cEvent( event
) ;
810 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
811 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
813 switch ( GetEventKind( event
) )
815 case kEventWindowActivated
:
817 toplevelWindow
->HandleActivated( cEvent
.GetTicks() , true) ;
818 // we still sending an eventNotHandledErr in order to allow for default processing
822 case kEventWindowDeactivated
:
824 toplevelWindow
->HandleActivated( cEvent
.GetTicks() , false) ;
825 // we still sending an eventNotHandledErr in order to allow for default processing
829 case kEventWindowShown
:
830 toplevelWindow
->Refresh() ;
834 case kEventWindowClose
:
835 toplevelWindow
->Close() ;
839 case kEventWindowBoundsChanged
:
841 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
842 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
843 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
844 if ( attributes
& kWindowBoundsChangeSizeChanged
)
846 toplevelWindow
->HandleResized(cEvent
.GetTicks() ) ;
849 if ( attributes
& kWindowBoundsChangeOriginChanged
)
851 toplevelWindow
->HandleMoved(cEvent
.GetTicks() ) ;
858 case kEventWindowBoundsChanging
:
860 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
861 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
863 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
865 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
866 int left
, top
, width
, height
;
870 toplevelWindow
->GetNonOwnedPeer()->GetContentArea(left
, top
, width
, height
);
871 toplevelWindow
->GetNonOwnedPeer()->GetSize(swidth
, sheight
);
872 int deltawidth
= swidth
- width
;
873 int deltaheight
= sheight
- height
;
877 newRect
.right
- newRect
.left
+ deltawidth
,
878 newRect
.bottom
- newRect
.top
+ deltaheight
) ;
880 toplevelWindow
->HandleResizing( cEvent
.GetTicks(), &adjustR
);
882 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ top
+ adjustR
.height
- deltaheight
,
883 adjustR
.x
+ left
+ adjustR
.width
- deltawidth
} ;
884 if ( !EqualRect( &newRect
, &adjustedRect
) )
885 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
892 case kEventWindowGetRegion
:
894 if ( toplevelWindow
->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
896 WindowRegionCode windowRegionCode
;
898 // Fetch the region code that is being queried
899 GetEventParameter( event
,
900 kEventParamWindowRegionCode
,
901 typeWindowRegionCode
, NULL
,
902 sizeof windowRegionCode
, NULL
,
903 &windowRegionCode
) ;
905 // If it is the opaque region code then set the
906 // region to empty and return noErr to stop event
908 if ( windowRegionCode
== kWindowOpaqueRgn
) {
910 GetEventParameter( event
,
911 kEventParamRgnHandle
,
912 typeQDRgnHandle
, NULL
,
915 SetEmptyRgn(region
) ;
929 // mix this in from window.cpp
930 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
932 pascal OSStatus
wxNonOwnedEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
934 OSStatus result
= eventNotHandledErr
;
936 switch ( GetEventClass( event
) )
938 case kEventClassTextInput
:
940 // TODO remove as soon as all events are on implementation classes only
941 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
943 result
= wxMacUnicodeTextEventHandler( handler
, event
, toplevelWindow
) ;
947 case kEventClassKeyboard
:
948 result
= KeyboardEventHandler( handler
, event
, data
) ;
951 case kEventClassWindow
:
952 result
= wxNonOwnedWindowEventHandler( handler
, event
, data
) ;
955 case kEventClassMouse
:
956 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
966 DEFINE_ONE_SHOT_HANDLER_GETTER( wxNonOwnedEventHandler
)
968 // ---------------------------------------------------------------------------
969 // Support functions for shaped windows, based on Apple's CustomWindow sample at
970 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
971 // ---------------------------------------------------------------------------
973 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
975 GetWindowPortBounds(window
, inRect
);
976 Point pt
= { inRect
->top
,inRect
->left
};
977 QDLocalToGlobalPoint( GetWindowPort( window
), &pt
);
978 inRect
->bottom
+= pt
.v
- inRect
->top
;
979 inRect
->right
+= pt
.h
- inRect
->left
;
984 static SInt32
wxShapedMacWindowGetFeatures(WindowRef
WXUNUSED(window
), SInt32 param
)
986 /*------------------------------------------------------
987 Define which options your custom window supports.
988 --------------------------------------------------------*/
989 //just enable everything for our demo
990 *(OptionBits
*)param
=
994 //kWindowCanGetWindowRegion |
995 //kWindowHasTitleBar |
996 //kWindowSupportsDragHilite |
997 kWindowCanDrawInCurrentPort
|
998 //kWindowCanMeasureTitle |
999 kWindowWantsDisposeAtProcessDeath
|
1000 kWindowSupportsGetGrowImageRegion
|
1001 kWindowDefSupportsColorGrafPort
;
1006 // The content region is left as a rectangle matching the window size, this is
1007 // so the origin in the paint event, and etc. still matches what the
1008 // programmer expects.
1009 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1012 wxNonOwnedWindow
* win
= wxNonOwnedWindow::GetFromWXWindow((WXWindow
)window
);
1016 wxShapedMacWindowGetPos( window
, &r
) ;
1017 RectRgn( rgn
, &r
) ;
1021 // The structure region is set to the shape given to the SetShape method.
1022 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1024 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1030 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1031 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1032 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1033 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1037 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1039 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1044 switch (rgnRec
->regionCode
)
1046 case kWindowStructureRgn
:
1047 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1050 case kWindowContentRgn
:
1051 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1055 SetEmptyRgn(rgnRec
->winRgn
);
1062 // Determine the region of the window which was hit
1064 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1067 static RgnHandle tempRgn
= NULL
;
1069 if (tempRgn
== NULL
)
1072 // get the point clicked
1073 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1075 // Mac OS 8.5 or later
1076 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1077 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1080 // no significant area was hit
1084 static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode
), WindowRef window
, SInt16 message
, SInt32 param
)
1088 case kWindowMsgHitTest
:
1089 return wxShapedMacWindowHitTest(window
, param
);
1091 case kWindowMsgGetFeatures
:
1092 return wxShapedMacWindowGetFeatures(window
, param
);
1094 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1095 case kWindowMsgGetRegion
:
1096 return wxShapedMacWindowGetRegion(window
, param
);
1109 wxPoint m_position
;
1111 bool m_wasResizable
;
1114 wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl()
1118 wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl( wxNonOwnedWindow
* nonownedwnd
) : wxNonOwnedWindowImpl( nonownedwnd
)
1120 m_macEventHandler
= NULL
;
1122 m_macFullScreenData
= NULL
;
1125 wxNonOwnedWindowCarbonImpl::~wxNonOwnedWindowCarbonImpl()
1128 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
1131 if ( m_macEventHandler
)
1133 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1134 m_macEventHandler
= NULL
;
1138 DisposeWindow( m_macWindow
);
1140 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1142 m_macFullScreenData
= NULL
;
1148 void wxNonOwnedWindowCarbonImpl::WillBeDestroyed()
1150 if ( m_macEventHandler
)
1152 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1153 m_macEventHandler
= NULL
;
1157 void wxNonOwnedWindowInstallTopLevelWindowEventHandler(WindowRef window
, EventHandlerRef
* handler
, void *ref
)
1159 InstallWindowEventHandler(window
, GetwxNonOwnedEventHandlerUPP(),
1160 GetEventTypeCount(eventList
), eventList
, ref
, handler
);
1163 bool wxNonOwnedWindowCarbonImpl::SetShape(const wxRegion
& region
)
1165 // Make a copy of the region
1166 RgnHandle shapeRegion
= NewRgn();
1167 HIShapeGetAsQDRgn( region
.GetWXHRGN(), shapeRegion
);
1169 // Dispose of any shape region we may already have
1170 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
) m_wxPeer
->GetWXWindow() );
1174 // Save the region so we can use it later
1175 SetWRefCon((WindowRef
) m_wxPeer
->GetWXWindow(), (URefCon
)shapeRegion
);
1177 // inform the window manager that the window has changed shape
1178 ReshapeCustomWindow((WindowRef
) m_wxPeer
->GetWXWindow());
1184 void wxNonOwnedWindowCarbonImpl::MacInstallTopLevelWindowEventHandler()
1186 if ( m_macEventHandler
!= NULL
)
1188 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1190 wxNonOwnedWindowInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow
),(EventHandlerRef
*)&m_macEventHandler
,this);
1193 void wxNonOwnedWindowCarbonImpl::Create(
1197 long style
, long extraStyle
,
1198 const wxString
& WXUNUSED(name
) )
1201 OSStatus err
= noErr
;
1210 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1212 // translate the window attributes in the appropriate window class and attributes
1213 WindowClass wclass
= 0;
1214 WindowAttributes attr
= kWindowNoAttributes
;
1215 WindowGroupRef group
= NULL
;
1216 bool activationScopeSet
= false;
1217 WindowActivationScope activationScope
= kWindowActivationScopeNone
;
1219 if ( style
& wxFRAME_TOOL_WINDOW
)
1222 ( style
& wxMINIMIZE_BOX
) || ( style
& wxMAXIMIZE_BOX
) ||
1223 ( style
& wxSYSTEM_MENU
) || ( style
& wxCAPTION
) ||
1224 ( style
&wxTINY_CAPTION_HORIZ
) || ( style
&wxTINY_CAPTION_VERT
)
1227 if ( ( style
& wxSTAY_ON_TOP
) )
1228 wclass
= kUtilityWindowClass
;
1230 wclass
= kFloatingWindowClass
;
1232 if ( ( style
&wxTINY_CAPTION_VERT
) )
1233 attr
|= kWindowSideTitlebarAttribute
;
1237 if ( style
& wxNO_BORDER
)
1239 wclass
= kSimpleWindowClass
;
1243 wclass
= kPlainWindowClass
;
1245 activationScopeSet
= true;
1246 activationScope
= kWindowActivationScopeNone
;
1249 else if ( ( style
& wxPOPUP_WINDOW
) )
1251 if ( ( style
& wxBORDER_NONE
) )
1253 wclass
= kHelpWindowClass
; // has no border
1254 attr
|= kWindowNoShadowAttribute
;
1258 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1260 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1261 // make sure we don't deactivate something
1262 activationScopeSet
= true;
1263 activationScope
= kWindowActivationScopeNone
;
1265 else if ( ( style
& wxCAPTION
) )
1267 wclass
= kDocumentWindowClass
;
1268 attr
|= kWindowInWindowMenuAttribute
;
1270 else if ( ( style
& wxFRAME_DRAWER
) )
1272 wclass
= kDrawerWindowClass
;
1276 if ( ( style
& wxMINIMIZE_BOX
) || ( style
& wxMAXIMIZE_BOX
) ||
1277 ( style
& wxCLOSE_BOX
) || ( style
& wxSYSTEM_MENU
) )
1279 wclass
= kDocumentWindowClass
;
1281 else if ( ( style
& wxNO_BORDER
) )
1283 wclass
= kSimpleWindowClass
;
1287 wclass
= kPlainWindowClass
;
1291 if ( wclass
!= kPlainWindowClass
)
1293 if ( ( style
& wxMINIMIZE_BOX
) )
1294 attr
|= kWindowCollapseBoxAttribute
;
1296 if ( ( style
& wxMAXIMIZE_BOX
) )
1297 attr
|= kWindowFullZoomAttribute
;
1299 if ( ( style
& wxRESIZE_BORDER
) )
1300 attr
|= kWindowResizableAttribute
;
1302 if ( ( style
& wxCLOSE_BOX
) )
1303 attr
|= kWindowCloseBoxAttribute
;
1305 attr
|= kWindowLiveResizeAttribute
;
1307 if ( ( style
&wxSTAY_ON_TOP
) )
1308 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1310 if ( ( style
& wxFRAME_FLOAT_ON_PARENT
) )
1311 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1313 if ( group
== NULL
&& parent
!= NULL
)
1315 WindowRef parenttlw
= (WindowRef
) parent
->MacGetTopLevelWindowRef();
1317 group
= GetWindowGroupParent( GetWindowGroup( parenttlw
) );
1320 attr
|= kWindowCompositingAttribute
;
1321 #if 0 // TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1322 attr
|= kWindowFrameworkScaledAttribute
;
1325 if ( ( style
&wxFRAME_SHAPED
) )
1327 WindowDefSpec customWindowDefSpec
;
1328 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1329 customWindowDefSpec
.u
.defProc
=
1331 (WindowDefUPP
) wxShapedMacWindowDef
;
1333 NewWindowDefUPP(wxShapedMacWindowDef
);
1335 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1336 attr
, &theBoundsRect
,
1337 (WindowRef
*) &m_macWindow
);
1341 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1344 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1345 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1347 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1349 // setup a separate group for each window, so that overlays can be handled easily
1351 WindowGroupRef overlaygroup
= NULL
;
1352 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &overlaygroup
));
1353 verify_noerr( SetWindowGroupParent( overlaygroup
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1354 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, overlaygroup
));
1356 if ( activationScopeSet
)
1358 verify_noerr( SetWindowActivationScope( (WindowRef
) m_macWindow
, activationScope
));
1361 // the create commands are only for content rect,
1362 // so we have to set the size again as structure bounds
1363 SetWindowBounds( m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1365 // Causes the inner part of the window not to be metal
1366 // if the style is used before window creation.
1367 #if 0 // TARGET_API_MAC_OSX
1368 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1370 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1371 MacSetMetalAppearance( true ) ;
1375 if ( m_macWindow
!= NULL
)
1377 MacSetUnifiedAppearance( true ) ;
1380 HIViewRef growBoxRef
= 0 ;
1381 err
= HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowGrowBoxID
, &growBoxRef
);
1382 if ( err
== noErr
&& growBoxRef
!= 0 )
1383 HIGrowBoxViewSetTransparent( growBoxRef
, true ) ;
1385 // the frame window event handler
1386 InstallStandardEventHandler( GetWindowEventTarget(m_macWindow
) ) ;
1387 MacInstallTopLevelWindowEventHandler() ;
1389 if ( extraStyle
& wxFRAME_EX_METAL
)
1390 MacSetMetalAppearance(true);
1392 if ( ( style
&wxFRAME_SHAPED
) )
1394 // default shape matches the window size
1395 wxRegion
rgn( 0, 0, w
, h
);
1400 bool wxNonOwnedWindowCarbonImpl::ShowWithEffect(bool show
,
1401 wxShowEffect effect
,
1404 WindowTransitionEffect transition
= 0 ;
1407 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1408 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1409 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1410 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1411 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1412 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1413 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1414 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1415 transition
= kWindowGenieTransitionEffect
;
1417 case wxSHOW_EFFECT_BLEND
:
1418 transition
= kWindowFadeTransitionEffect
;
1420 case wxSHOW_EFFECT_EXPAND
:
1421 // having sheets would be fine, but this might lead to a repositioning
1424 transition
= kWindowSheetTransitionEffect
;
1427 transition
= kWindowZoomTransitionEffect
;
1430 case wxSHOW_EFFECT_NONE
:
1431 // wxNonOwnedWindow is supposed to call Show() itself in this case
1432 wxFAIL_MSG( "ShowWithEffect() shouldn't be called" );
1435 case wxSHOW_EFFECT_MAX
:
1436 wxFAIL_MSG( "invalid effect flag" );
1440 TransitionWindowOptions options
;
1441 options
.version
= 0;
1442 options
.duration
= timeout
/ 1000.0;
1443 options
.window
= transition
== kWindowSheetTransitionEffect
? (WindowRef
) m_wxPeer
->GetParent()->MacGetTopLevelWindowRef() :0;
1444 options
.userData
= 0;
1446 wxSize size
= wxGetDisplaySize();
1448 GetWindowBounds( (WindowRef
)m_macWindow
, kWindowStructureRgn
, &bounds
);
1449 CGRect hiBounds
= CGRectMake( bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
);
1453 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1454 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1455 hiBounds
.origin
.x
= 0;
1456 hiBounds
.size
.width
= 0;
1459 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1460 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1461 hiBounds
.origin
.x
= size
.x
;
1462 hiBounds
.size
.width
= 0;
1465 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1466 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1467 hiBounds
.origin
.y
= size
.y
;
1468 hiBounds
.size
.height
= 0;
1471 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1472 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1473 hiBounds
.origin
.y
= 0;
1474 hiBounds
.size
.height
= 0;
1478 break; // direction doesn't make sense
1481 ::TransitionWindowWithOptions
1483 (WindowRef
)m_macWindow
,
1485 show
? kWindowShowTransitionAction
: kWindowHideTransitionAction
,
1486 transition
== kWindowGenieTransitionEffect
? &hiBounds
: NULL
,
1493 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1499 void wxNonOwnedWindowCarbonImpl::SetTitle( const wxString
& title
, wxFontEncoding encoding
)
1501 SetWindowTitleWithCFString( m_macWindow
, wxCFStringRef( title
, encoding
) ) ;
1504 bool wxNonOwnedWindowCarbonImpl::IsMaximized() const
1506 return IsWindowInStandardState( m_macWindow
, NULL
, NULL
) ;
1509 bool wxNonOwnedWindowCarbonImpl::IsIconized() const
1511 return IsWindowCollapsed((WindowRef
)GetWXWindow() ) ;
1514 void wxNonOwnedWindowCarbonImpl::Iconize( bool iconize
)
1516 if ( IsWindowCollapsable( m_macWindow
) )
1517 CollapseWindow( m_macWindow
, iconize
) ;
1520 void wxNonOwnedWindowCarbonImpl::Maximize(bool maximize
)
1522 Point idealSize
= { 0 , 0 } ;
1525 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1527 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
1529 idealSize
.h
= bounds
.size
.width
;
1530 idealSize
.v
= bounds
.size
.height
;
1533 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
1534 idealSize
.h
= rect
.right
- rect
.left
;
1535 idealSize
.v
= rect
.bottom
- rect
.top
;
1538 ZoomWindowIdeal( (WindowRef
)GetWXWindow() , maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
1541 bool wxNonOwnedWindowCarbonImpl::IsFullScreen() const
1543 return m_macFullScreenData
!= NULL
;
1546 bool wxNonOwnedWindowCarbonImpl::ShowFullScreen(bool show
, long style
)
1550 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1552 data
= new FullScreenData() ;
1554 m_macFullScreenData
= data
;
1555 data
->m_position
= m_wxPeer
->GetPosition() ;
1556 data
->m_size
= m_wxPeer
->GetSize() ;
1557 #if wxOSX_USE_CARBON
1558 WindowAttributes attr
= 0;
1559 GetWindowAttributes((WindowRef
) GetWXWindow(), &attr
);
1560 data
->m_wasResizable
= attr
& kWindowResizableAttribute
;
1561 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1565 wxRect client
= wxGetClientDisplayRect() ;
1567 int left
, top
, width
, height
;
1575 GetContentArea( left
, top
, width
, height
) ;
1576 int outerwidth
, outerheight
;
1577 GetSize( outerwidth
, outerheight
);
1579 if ( style
& wxFULLSCREEN_NOCAPTION
)
1583 // avoid adding the caption twice to the height
1587 if ( style
& wxFULLSCREEN_NOBORDER
)
1590 w
+= outerwidth
- width
;
1591 h
+= outerheight
- height
;
1594 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1599 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1604 m_wxPeer
->SetSize( x
, y
, w
, h
) ;
1605 if ( data
->m_wasResizable
)
1607 #if wxOSX_USE_CARBON
1608 ChangeWindowAttributes( (WindowRef
) GetWXWindow() , kWindowNoAttributes
, kWindowResizableAttribute
) ;
1612 else if ( m_macFullScreenData
!= NULL
)
1614 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1615 #if wxOSX_USE_CARBON
1617 if ( data
->m_wasResizable
)
1618 ChangeWindowAttributes( (WindowRef
) GetWXWindow() , kWindowResizableAttribute
, kWindowNoAttributes
) ;
1620 m_wxPeer
->SetPosition( data
->m_position
) ;
1621 m_wxPeer
->SetSize( data
->m_size
) ;
1624 m_macFullScreenData
= NULL
;
1630 // Attracts the users attention to this window if the application is
1631 // inactive (should be called when a background event occurs)
1633 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1636 DisposePtr( (Ptr
)ptr
) ;
1639 void wxNonOwnedWindowCarbonImpl::RequestUserAttention(int WXUNUSED(flags
))
1641 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1643 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1644 notificationRequest
->qType
= nmType
;
1645 notificationRequest
->nmMark
= 1 ;
1646 notificationRequest
->nmIcon
= 0 ;
1647 notificationRequest
->nmSound
= 0 ;
1648 notificationRequest
->nmStr
= NULL
;
1649 notificationRequest
->nmResp
= wxMacNMResponse
;
1651 verify_noerr( NMInstall( notificationRequest
) ) ;
1654 void wxNonOwnedWindowCarbonImpl::ScreenToWindow( int *x
, int *y
)
1656 HIPoint p
= CGPointMake( (x
? *x
: 0), (y
? *y
: 0) );
1657 HIViewRef contentView
;
1658 // TODO check toolbar offset
1659 HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowContentID
, &contentView
) ;
1660 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
1667 void wxNonOwnedWindowCarbonImpl::WindowToScreen( int *x
, int *y
)
1669 HIPoint p
= CGPointMake( (x
? *x
: 0), (y
? *y
: 0) );
1670 HIViewRef contentView
;
1671 // TODO check toolbar offset
1672 HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowContentID
, &contentView
) ;
1673 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
1680 bool wxNonOwnedWindowCarbonImpl::IsActive()
1682 return ActiveNonFloatingWindow() == m_macWindow
;
1685 wxNonOwnedWindowImpl
* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
1686 long style
, long extraStyle
, const wxString
& name
)
1688 wxNonOwnedWindowImpl
* now
= new wxNonOwnedWindowCarbonImpl( wxpeer
);
1689 now
->Create( parent
, pos
, size
, style
, extraStyle
, name
);