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
);
257 void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
);
259 // ---------------------------------------------------------------------------
261 // ---------------------------------------------------------------------------
263 static const EventTypeSpec eventList
[] =
265 // TODO: remove control related event like key and mouse (except for WindowLeave events)
267 { kEventClassKeyboard
, kEventRawKeyDown
} ,
268 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
269 { kEventClassKeyboard
, kEventRawKeyUp
} ,
270 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
272 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
273 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
275 { kEventClassWindow
, kEventWindowShown
} ,
276 { kEventClassWindow
, kEventWindowActivated
} ,
277 { kEventClassWindow
, kEventWindowDeactivated
} ,
278 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
279 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
280 { kEventClassWindow
, kEventWindowClose
} ,
281 { kEventClassWindow
, kEventWindowGetRegion
} ,
283 // we have to catch these events on the toplevel window level,
284 // as controls don't get the raw mouse events anymore
286 { kEventClassMouse
, kEventMouseDown
} ,
287 { kEventClassMouse
, kEventMouseUp
} ,
288 { kEventClassMouse
, kEventMouseWheelMoved
} ,
289 { kEventClassMouse
, kEventMouseMoved
} ,
290 { kEventClassMouse
, kEventMouseDragged
} ,
293 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
295 OSStatus result
= eventNotHandledErr
;
296 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
297 // FindFocus does not return the actual focus window, but the enclosing window
298 wxWindow
* focus
= wxWindow::DoFindFocus();
300 focus
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
302 unsigned char charCode
;
310 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
313 ByteCount dataSize
= 0 ;
314 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
317 int numChars
= dataSize
/ sizeof( UniChar
) + 1;
319 UniChar
* charBuf
= buf
;
321 if ( numChars
* 2 > 4 )
322 charBuf
= new UniChar
[ numChars
] ;
323 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
324 charBuf
[ numChars
- 1 ] = 0;
326 #if SIZEOF_WCHAR_T == 2
327 uniChar
= charBuf
[0] ;
329 wxMBConvUTF16 converter
;
330 converter
.MB2WC( uniChar
, (const char*)charBuf
, 2 ) ;
333 if ( numChars
* 2 > 4 )
338 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
339 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
340 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
341 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
343 UInt32 message
= (keyCode
<< 8) + charCode
;
344 switch ( GetEventKind( event
) )
346 case kEventRawKeyRepeat
:
347 case kEventRawKeyDown
:
349 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
350 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
351 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
352 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
353 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
357 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
361 case kEventRawKeyUp
:
362 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
363 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
369 case kEventRawKeyModifiersChanged
:
371 wxKeyEvent
event(wxEVT_KEY_DOWN
);
373 event
.m_shiftDown
= modifiers
& shiftKey
;
374 event
.m_controlDown
= modifiers
& controlKey
;
375 event
.m_altDown
= modifiers
& optionKey
;
376 event
.m_metaDown
= modifiers
& cmdKey
;
381 event
.m_uniChar
= uniChar
[0] ;
384 event
.SetTimestamp(when
);
385 event
.SetEventObject(focus
);
387 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
389 event
.m_keyCode
= WXK_CONTROL
;
390 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
391 focus
->HandleWindowEvent( event
) ;
393 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
395 event
.m_keyCode
= WXK_SHIFT
;
396 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
397 focus
->HandleWindowEvent( event
) ;
399 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
401 event
.m_keyCode
= WXK_ALT
;
402 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
403 focus
->HandleWindowEvent( event
) ;
405 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
407 event
.m_keyCode
= WXK_COMMAND
;
408 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
409 focus
->HandleWindowEvent( event
) ;
412 wxApp::s_lastModifiers
= modifiers
;
423 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
424 // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
427 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
429 EventMouseButton g_lastButton
= 0 ;
430 bool g_lastButtonWasFakeRight
= false ;
432 void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
434 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
435 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
437 // these parameters are not given for all events
438 EventMouseButton button
= 0 ;
439 UInt32 clickCount
= 0 ;
440 UInt32 mouseChord
= 0;
442 cEvent
.GetParameter
<EventMouseButton
>( kEventParamMouseButton
, typeMouseButton
, &button
) ;
443 cEvent
.GetParameter
<UInt32
>( kEventParamClickCount
, typeUInt32
, &clickCount
) ;
444 // the chord is the state of the buttons pressed currently
445 cEvent
.GetParameter
<UInt32
>( kEventParamMouseChord
, typeUInt32
, &mouseChord
) ;
447 wxevent
.m_x
= screenMouseLocation
.h
;
448 wxevent
.m_y
= screenMouseLocation
.v
;
449 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
450 wxevent
.m_controlDown
= modifiers
& controlKey
;
451 wxevent
.m_altDown
= modifiers
& optionKey
;
452 wxevent
.m_metaDown
= modifiers
& cmdKey
;
453 wxevent
.m_clickCount
= clickCount
;
454 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
456 // a control click is interpreted as a right click
457 bool thisButtonIsFakeRight
= false ;
458 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
460 button
= kEventMouseButtonSecondary
;
461 thisButtonIsFakeRight
= true ;
464 // otherwise we report double clicks by connecting a left click with a ctrl-left click
465 if ( clickCount
> 1 && button
!= g_lastButton
)
468 // we must make sure that our synthetic 'right' button corresponds in
469 // mouse down, moved and mouse up, and does not deliver a right down and left up
471 if ( cEvent
.GetKind() == kEventMouseDown
)
473 g_lastButton
= button
;
474 g_lastButtonWasFakeRight
= thisButtonIsFakeRight
;
480 g_lastButtonWasFakeRight
= false ;
482 else if ( g_lastButton
== kEventMouseButtonSecondary
&& g_lastButtonWasFakeRight
)
483 button
= g_lastButton
;
485 // Adjust the chord mask to remove the primary button and add the
486 // secondary button. It is possible that the secondary button is
487 // already pressed, e.g. on a mouse connected to a laptop, but this
488 // possibility is ignored here:
489 if( thisButtonIsFakeRight
&& ( mouseChord
& 1U ) )
490 mouseChord
= ((mouseChord
& ~1U) | 2U);
493 wxevent
.m_leftDown
= true ;
495 wxevent
.m_rightDown
= true ;
497 wxevent
.m_middleDown
= true ;
499 // translate into wx types
500 switch ( cEvent
.GetKind() )
502 case kEventMouseDown
:
505 case kEventMouseButtonPrimary
:
506 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
509 case kEventMouseButtonSecondary
:
510 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
513 case kEventMouseButtonTertiary
:
514 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
525 case kEventMouseButtonPrimary
:
526 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
529 case kEventMouseButtonSecondary
:
530 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
533 case kEventMouseButtonTertiary
:
534 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
541 // TODO http://developer.apple.com/qa/qa2005/qa1453.html
542 // add declaration for 10.4 and change to kEventMouseScroll
543 case kEventMouseWheelMoved
:
545 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
547 EventMouseWheelAxis axis
= cEvent
.GetParameter
<EventMouseWheelAxis
>(kEventParamMouseWheelAxis
, typeMouseWheelAxis
) ;
548 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeSInt32
) ;
550 wxevent
.m_wheelRotation
= delta
;
551 wxevent
.m_wheelDelta
= 1;
552 wxevent
.m_linesPerAction
= 1;
553 if ( axis
== kEventMouseWheelAxisX
)
554 wxevent
.m_wheelAxis
= 1;
558 case kEventMouseEntered
:
559 case kEventMouseExited
:
560 case kEventMouseDragged
:
561 case kEventMouseMoved
:
562 wxevent
.SetEventType( wxEVT_MOTION
) ;
569 #define NEW_CAPTURE_HANDLING 1
572 wxMacTopLevelMouseEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
576 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
578 OSStatus result
= eventNotHandledErr
;
580 wxMacCarbonEvent
cEvent( event
) ;
582 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
583 Point windowMouseLocation
= screenMouseLocation
;
585 WindowRef window
= NULL
;
586 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
588 wxWindow
* currentMouseWindow
= NULL
;
589 ControlRef control
= NULL
;
591 #if NEW_CAPTURE_HANDLING
592 if ( wxApp::s_captureWindow
)
594 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
595 windowPart
= inContent
;
601 QDGlobalToLocalPoint( GetWindowPort( window
), &windowMouseLocation
);
603 if ( wxApp::s_captureWindow
604 #if !NEW_CAPTURE_HANDLING
605 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
609 currentMouseWindow
= wxApp::s_captureWindow
;
611 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
613 ControlPartCode part
;
614 control
= FindControlUnderMouse( windowMouseLocation
, window
, &part
) ;
615 // if there is no control below the mouse position, send the event to the toplevel window itself
618 currentMouseWindow
= (wxWindow
*) toplevelWindow
;
622 currentMouseWindow
= (wxWindow
*) wxFindWindowFromWXWidget( (WXWidget
) control
) ;
623 #ifndef __WXUNIVERSAL__
624 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
627 // for wxToolBar to function we have to send certaint events to it
628 // instead of its children (wxToolBarTools)
630 GetSuperControl(control
, &parent
);
631 wxWindow
*wxparent
= (wxWindow
*) wxFindWindowFromWXWidget((WXWidget
) parent
) ;
632 if ( wxparent
&& wxparent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
633 currentMouseWindow
= wxparent
;
639 // disabled windows must not get any input messages
640 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
641 currentMouseWindow
= NULL
;
645 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
646 SetupMouseEvent( wxevent
, cEvent
) ;
648 // handle all enter / leave events
650 if ( currentMouseWindow
!= g_MacLastWindow
)
652 if ( g_MacLastWindow
)
654 wxMouseEvent
eventleave(wxevent
);
655 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
656 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
657 eventleave
.SetEventObject( g_MacLastWindow
) ;
658 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
661 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
664 g_MacLastWindow
->HandleWindowEvent(eventleave
);
667 if ( currentMouseWindow
)
669 wxMouseEvent
evententer(wxevent
);
670 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
671 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
672 evententer
.SetEventObject( currentMouseWindow
) ;
673 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
676 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
679 currentMouseWindow
->HandleWindowEvent(evententer
);
682 g_MacLastWindow
= currentMouseWindow
;
685 if ( windowPart
== inMenuBar
)
687 // special case menu bar, as we are having a low-level runloop we must do it ourselves
688 if ( cEvent
.GetKind() == kEventMouseDown
)
690 ::MenuSelect( screenMouseLocation
) ;
695 else if ( window
&& windowPart
== inProxyIcon
)
697 // special case proxy icon bar, as we are having a low-level runloop we must do it ourselves
698 if ( cEvent
.GetKind() == kEventMouseDown
)
700 if ( ::TrackWindowProxyDrag( window
, screenMouseLocation
) != errUserWantsToDragWindow
)
702 // TODO Track change of file path and report back
707 else if ( currentMouseWindow
)
709 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
711 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
713 wxevent
.SetEventObject( currentMouseWindow
) ;
714 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
716 // make tooltips current
719 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
720 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
723 if ( currentMouseWindow
->HandleWindowEvent(wxevent
) )
725 if ((currentMouseWindowParent
!= NULL
) &&
726 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
727 currentMouseWindow
= NULL
;
733 // if the user code did _not_ handle the event, then perform the
734 // default processing
735 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
737 // ... that is set focus to this window
738 if (currentMouseWindow
->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
739 currentMouseWindow
->SetFocus();
743 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
745 wxApp::s_captureWindow
= NULL
;
751 wxWindow
* cursorTarget
= currentMouseWindow
;
752 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
754 extern wxCursor gGlobalCursor
;
756 if (!gGlobalCursor
.IsOk())
758 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
760 cursorTarget
= cursorTarget
->GetParent() ;
762 cursorPoint
+= cursorTarget
->GetPosition();
767 else // currentMouseWindow == NULL
769 if (toplevelWindow
&& !control
)
771 extern wxCursor gGlobalCursor
;
772 if (!gGlobalCursor
.IsOk())
774 // update cursor when over toolbar and titlebar etc.
775 wxSTANDARD_CURSOR
->MacInstall() ;
779 // don't mess with controls we don't know about
780 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
781 // so we try sending them the correct control directly
782 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
784 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
785 Point clickLocation
= windowMouseLocation
;
788 hiPoint
.x
= clickLocation
.h
;
789 hiPoint
.y
= clickLocation
.v
;
790 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
791 clickLocation
.h
= (int)hiPoint
.x
;
792 clickLocation
.v
= (int)hiPoint
.y
;
794 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
802 static pascal OSStatus
803 wxNonOwnedWindowEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
807 OSStatus result
= eventNotHandledErr
;
809 wxMacCarbonEvent
cEvent( event
) ;
811 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
812 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
814 switch ( GetEventKind( event
) )
816 case kEventWindowActivated
:
818 toplevelWindow
->HandleActivated( cEvent
.GetTicks() , true) ;
819 // we still sending an eventNotHandledErr in order to allow for default processing
823 case kEventWindowDeactivated
:
825 toplevelWindow
->HandleActivated( cEvent
.GetTicks() , false) ;
826 // we still sending an eventNotHandledErr in order to allow for default processing
830 case kEventWindowShown
:
831 toplevelWindow
->Refresh() ;
835 case kEventWindowClose
:
836 toplevelWindow
->Close() ;
840 case kEventWindowBoundsChanged
:
842 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
843 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
844 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
845 if ( attributes
& kWindowBoundsChangeSizeChanged
)
847 toplevelWindow
->HandleResized(cEvent
.GetTicks() ) ;
850 if ( attributes
& kWindowBoundsChangeOriginChanged
)
852 toplevelWindow
->HandleMoved(cEvent
.GetTicks() ) ;
859 case kEventWindowBoundsChanging
:
861 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
862 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
864 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
866 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
867 int left
, top
, width
, height
;
871 toplevelWindow
->GetNonOwnedPeer()->GetContentArea(left
, top
, width
, height
);
872 toplevelWindow
->GetNonOwnedPeer()->GetSize(swidth
, sheight
);
873 int deltawidth
= swidth
- width
;
874 int deltaheight
= sheight
- height
;
878 newRect
.right
- newRect
.left
+ deltawidth
,
879 newRect
.bottom
- newRect
.top
+ deltaheight
) ;
881 toplevelWindow
->HandleResizing( cEvent
.GetTicks(), &adjustR
);
883 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ top
+ adjustR
.height
- deltaheight
,
884 adjustR
.x
+ left
+ adjustR
.width
- deltawidth
} ;
885 if ( !EqualRect( &newRect
, &adjustedRect
) )
886 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
893 case kEventWindowGetRegion
:
895 if ( toplevelWindow
->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
897 WindowRegionCode windowRegionCode
;
899 // Fetch the region code that is being queried
900 GetEventParameter( event
,
901 kEventParamWindowRegionCode
,
902 typeWindowRegionCode
, NULL
,
903 sizeof windowRegionCode
, NULL
,
904 &windowRegionCode
) ;
906 // If it is the opaque region code then set the
907 // region to empty and return noErr to stop event
909 if ( windowRegionCode
== kWindowOpaqueRgn
) {
911 GetEventParameter( event
,
912 kEventParamRgnHandle
,
913 typeQDRgnHandle
, NULL
,
916 SetEmptyRgn(region
) ;
930 // mix this in from window.cpp
931 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
933 static pascal OSStatus
wxNonOwnedEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
935 OSStatus result
= eventNotHandledErr
;
937 switch ( GetEventClass( event
) )
939 case kEventClassTextInput
:
941 // TODO remove as soon as all events are on implementation classes only
942 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
944 result
= wxMacUnicodeTextEventHandler( handler
, event
, toplevelWindow
) ;
948 case kEventClassKeyboard
:
949 result
= KeyboardEventHandler( handler
, event
, data
) ;
952 case kEventClassWindow
:
953 result
= wxNonOwnedWindowEventHandler( handler
, event
, data
) ;
956 case kEventClassMouse
:
957 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
967 DEFINE_ONE_SHOT_HANDLER_GETTER( wxNonOwnedEventHandler
)
969 // ---------------------------------------------------------------------------
970 // Support functions for shaped windows, based on Apple's CustomWindow sample at
971 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
972 // ---------------------------------------------------------------------------
974 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
976 GetWindowPortBounds(window
, inRect
);
977 Point pt
= { inRect
->top
,inRect
->left
};
978 QDLocalToGlobalPoint( GetWindowPort( window
), &pt
);
979 inRect
->bottom
+= pt
.v
- inRect
->top
;
980 inRect
->right
+= pt
.h
- inRect
->left
;
985 static SInt32
wxShapedMacWindowGetFeatures(WindowRef
WXUNUSED(window
), SInt32 param
)
987 /*------------------------------------------------------
988 Define which options your custom window supports.
989 --------------------------------------------------------*/
990 //just enable everything for our demo
991 *(OptionBits
*)param
=
995 //kWindowCanGetWindowRegion |
996 //kWindowHasTitleBar |
997 //kWindowSupportsDragHilite |
998 kWindowCanDrawInCurrentPort
|
999 //kWindowCanMeasureTitle |
1000 kWindowWantsDisposeAtProcessDeath
|
1001 kWindowSupportsGetGrowImageRegion
|
1002 kWindowDefSupportsColorGrafPort
;
1007 // The content region is left as a rectangle matching the window size, this is
1008 // so the origin in the paint event, and etc. still matches what the
1009 // programmer expects.
1010 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1013 wxNonOwnedWindow
* win
= wxNonOwnedWindow::GetFromWXWindow((WXWindow
)window
);
1017 wxShapedMacWindowGetPos( window
, &r
) ;
1018 RectRgn( rgn
, &r
) ;
1022 // The structure region is set to the shape given to the SetShape method.
1023 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1025 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1031 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1032 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1033 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1034 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1038 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1040 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1045 switch (rgnRec
->regionCode
)
1047 case kWindowStructureRgn
:
1048 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1051 case kWindowContentRgn
:
1052 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1056 SetEmptyRgn(rgnRec
->winRgn
);
1063 // Determine the region of the window which was hit
1065 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1068 static RgnHandle tempRgn
= NULL
;
1070 if (tempRgn
== NULL
)
1073 // get the point clicked
1074 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1076 // Mac OS 8.5 or later
1077 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1078 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1081 // no significant area was hit
1085 static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode
), WindowRef window
, SInt16 message
, SInt32 param
)
1089 case kWindowMsgHitTest
:
1090 return wxShapedMacWindowHitTest(window
, param
);
1092 case kWindowMsgGetFeatures
:
1093 return wxShapedMacWindowGetFeatures(window
, param
);
1095 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1096 case kWindowMsgGetRegion
:
1097 return wxShapedMacWindowGetRegion(window
, param
);
1110 wxPoint m_position
;
1112 bool m_wasResizable
;
1115 wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl()
1119 wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl( wxNonOwnedWindow
* nonownedwnd
) : wxNonOwnedWindowImpl( nonownedwnd
)
1121 m_macEventHandler
= NULL
;
1123 m_macFullScreenData
= NULL
;
1126 wxNonOwnedWindowCarbonImpl::~wxNonOwnedWindowCarbonImpl()
1129 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
1132 if ( m_macEventHandler
)
1134 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1135 m_macEventHandler
= NULL
;
1138 if ( m_macWindow
&& !m_wxPeer
->IsNativeWindowWrapper())
1139 DisposeWindow( m_macWindow
);
1141 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1143 m_macFullScreenData
= NULL
;
1149 void wxNonOwnedWindowCarbonImpl::WillBeDestroyed()
1151 if ( m_macEventHandler
)
1153 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1154 m_macEventHandler
= NULL
;
1158 static 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(
1196 WXWindow nativeWindow
)
1198 m_macWindow
= nativeWindow
;
1201 void wxNonOwnedWindowCarbonImpl::Create(
1205 long style
, long extraStyle
,
1206 const wxString
& WXUNUSED(name
) )
1209 OSStatus err
= noErr
;
1218 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1220 // translate the window attributes in the appropriate window class and attributes
1221 WindowClass wclass
= 0;
1222 WindowAttributes attr
= kWindowNoAttributes
;
1223 WindowGroupRef group
= NULL
;
1224 bool activationScopeSet
= false;
1225 WindowActivationScope activationScope
= kWindowActivationScopeNone
;
1227 if ( style
& wxFRAME_TOOL_WINDOW
)
1230 ( style
& wxMINIMIZE_BOX
) || ( style
& wxMAXIMIZE_BOX
) ||
1231 ( style
& wxSYSTEM_MENU
) || ( style
& wxCAPTION
) ||
1232 ( style
&wxTINY_CAPTION_HORIZ
) || ( style
&wxTINY_CAPTION_VERT
)
1235 if ( ( style
& wxSTAY_ON_TOP
) )
1236 wclass
= kUtilityWindowClass
;
1238 wclass
= kFloatingWindowClass
;
1240 if ( ( style
&wxTINY_CAPTION_VERT
) )
1241 attr
|= kWindowSideTitlebarAttribute
;
1245 if ( style
& wxNO_BORDER
)
1247 wclass
= kSimpleWindowClass
;
1251 wclass
= kPlainWindowClass
;
1253 activationScopeSet
= true;
1254 activationScope
= kWindowActivationScopeNone
;
1257 else if ( ( style
& wxPOPUP_WINDOW
) )
1259 if ( ( style
& wxBORDER_NONE
) )
1261 wclass
= kHelpWindowClass
; // has no border
1262 attr
|= kWindowNoShadowAttribute
;
1266 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1268 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1269 // make sure we don't deactivate something
1270 activationScopeSet
= true;
1271 activationScope
= kWindowActivationScopeNone
;
1273 else if ( ( style
& wxCAPTION
) )
1275 wclass
= kDocumentWindowClass
;
1276 attr
|= kWindowInWindowMenuAttribute
;
1278 else if ( ( style
& wxFRAME_DRAWER
) )
1280 wclass
= kDrawerWindowClass
;
1284 if ( ( style
& wxMINIMIZE_BOX
) || ( style
& wxMAXIMIZE_BOX
) ||
1285 ( style
& wxCLOSE_BOX
) || ( style
& wxSYSTEM_MENU
) )
1287 wclass
= kDocumentWindowClass
;
1289 else if ( ( style
& wxNO_BORDER
) )
1291 wclass
= kSimpleWindowClass
;
1295 wclass
= kPlainWindowClass
;
1299 if ( wclass
!= kPlainWindowClass
)
1301 if ( ( style
& wxMINIMIZE_BOX
) )
1302 attr
|= kWindowCollapseBoxAttribute
;
1304 if ( ( style
& wxMAXIMIZE_BOX
) )
1305 attr
|= kWindowFullZoomAttribute
;
1307 if ( ( style
& wxRESIZE_BORDER
) )
1308 attr
|= kWindowResizableAttribute
;
1310 if ( ( style
& wxCLOSE_BOX
) )
1311 attr
|= kWindowCloseBoxAttribute
;
1313 attr
|= kWindowLiveResizeAttribute
;
1315 if ( ( style
&wxSTAY_ON_TOP
) )
1316 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1318 if ( ( style
& wxFRAME_FLOAT_ON_PARENT
) )
1319 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1321 if ( group
== NULL
&& parent
!= NULL
)
1323 WindowRef parenttlw
= (WindowRef
) parent
->MacGetTopLevelWindowRef();
1325 group
= GetWindowGroupParent( GetWindowGroup( parenttlw
) );
1328 attr
|= kWindowCompositingAttribute
;
1329 #if 0 // TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1330 attr
|= kWindowFrameworkScaledAttribute
;
1333 if ( ( style
&wxFRAME_SHAPED
) )
1335 WindowDefSpec customWindowDefSpec
;
1336 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1337 customWindowDefSpec
.u
.defProc
=
1339 (WindowDefUPP
) wxShapedMacWindowDef
;
1341 NewWindowDefUPP(wxShapedMacWindowDef
);
1343 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1344 attr
, &theBoundsRect
,
1345 (WindowRef
*) &m_macWindow
);
1349 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1352 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1353 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1355 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1357 // setup a separate group for each window, so that overlays can be handled easily
1359 WindowGroupRef overlaygroup
= NULL
;
1360 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &overlaygroup
));
1361 verify_noerr( SetWindowGroupParent( overlaygroup
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1362 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, overlaygroup
));
1364 if ( activationScopeSet
)
1366 verify_noerr( SetWindowActivationScope( (WindowRef
) m_macWindow
, activationScope
));
1369 // the create commands are only for content rect,
1370 // so we have to set the size again as structure bounds
1371 SetWindowBounds( m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1373 // Causes the inner part of the window not to be metal
1374 // if the style is used before window creation.
1375 #if 0 // TARGET_API_MAC_OSX
1376 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1378 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1379 MacSetMetalAppearance( true ) ;
1383 if ( m_macWindow
!= NULL
)
1385 MacSetUnifiedAppearance( true ) ;
1388 HIViewRef growBoxRef
= 0 ;
1389 err
= HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowGrowBoxID
, &growBoxRef
);
1390 if ( err
== noErr
&& growBoxRef
!= 0 )
1391 HIGrowBoxViewSetTransparent( growBoxRef
, true ) ;
1393 // the frame window event handler
1394 InstallStandardEventHandler( GetWindowEventTarget(m_macWindow
) ) ;
1395 MacInstallTopLevelWindowEventHandler() ;
1397 if ( extraStyle
& wxFRAME_EX_METAL
)
1398 MacSetMetalAppearance(true);
1400 if ( ( style
&wxFRAME_SHAPED
) )
1402 // default shape matches the window size
1403 wxRegion
rgn( 0, 0, w
, h
);
1408 bool wxNonOwnedWindowCarbonImpl::ShowWithEffect(bool show
,
1409 wxShowEffect effect
,
1412 WindowTransitionEffect transition
= 0 ;
1415 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1416 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1417 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1418 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1419 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1420 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1421 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1422 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1423 transition
= kWindowGenieTransitionEffect
;
1425 case wxSHOW_EFFECT_BLEND
:
1426 transition
= kWindowFadeTransitionEffect
;
1428 case wxSHOW_EFFECT_EXPAND
:
1429 // having sheets would be fine, but this might lead to a repositioning
1432 transition
= kWindowSheetTransitionEffect
;
1435 transition
= kWindowZoomTransitionEffect
;
1438 case wxSHOW_EFFECT_NONE
:
1439 // wxNonOwnedWindow is supposed to call Show() itself in this case
1440 wxFAIL_MSG( "ShowWithEffect() shouldn't be called" );
1443 case wxSHOW_EFFECT_MAX
:
1444 wxFAIL_MSG( "invalid effect flag" );
1448 TransitionWindowOptions options
;
1449 options
.version
= 0;
1450 options
.duration
= timeout
/ 1000.0;
1451 options
.window
= transition
== kWindowSheetTransitionEffect
? (WindowRef
) m_wxPeer
->GetParent()->MacGetTopLevelWindowRef() :0;
1452 options
.userData
= 0;
1454 wxSize size
= wxGetDisplaySize();
1456 GetWindowBounds( (WindowRef
)m_macWindow
, kWindowStructureRgn
, &bounds
);
1457 CGRect hiBounds
= CGRectMake( bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
);
1461 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1462 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1463 hiBounds
.origin
.x
= 0;
1464 hiBounds
.size
.width
= 0;
1467 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1468 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1469 hiBounds
.origin
.x
= size
.x
;
1470 hiBounds
.size
.width
= 0;
1473 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1474 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1475 hiBounds
.origin
.y
= size
.y
;
1476 hiBounds
.size
.height
= 0;
1479 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1480 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1481 hiBounds
.origin
.y
= 0;
1482 hiBounds
.size
.height
= 0;
1486 break; // direction doesn't make sense
1489 ::TransitionWindowWithOptions
1491 (WindowRef
)m_macWindow
,
1493 show
? kWindowShowTransitionAction
: kWindowHideTransitionAction
,
1494 transition
== kWindowGenieTransitionEffect
? &hiBounds
: NULL
,
1501 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1507 void wxNonOwnedWindowCarbonImpl::SetTitle( const wxString
& title
, wxFontEncoding encoding
)
1509 SetWindowTitleWithCFString( m_macWindow
, wxCFStringRef( title
, encoding
) ) ;
1512 bool wxNonOwnedWindowCarbonImpl::IsMaximized() const
1514 return IsWindowInStandardState( m_macWindow
, NULL
, NULL
) ;
1517 bool wxNonOwnedWindowCarbonImpl::IsIconized() const
1519 return IsWindowCollapsed((WindowRef
)GetWXWindow() ) ;
1522 void wxNonOwnedWindowCarbonImpl::Iconize( bool iconize
)
1524 if ( IsWindowCollapsable( m_macWindow
) )
1525 CollapseWindow( m_macWindow
, iconize
) ;
1528 void wxNonOwnedWindowCarbonImpl::Maximize(bool maximize
)
1530 Point idealSize
= { 0 , 0 } ;
1533 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1535 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
1537 idealSize
.h
= bounds
.size
.width
;
1538 idealSize
.v
= bounds
.size
.height
;
1541 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
1542 idealSize
.h
= rect
.right
- rect
.left
;
1543 idealSize
.v
= rect
.bottom
- rect
.top
;
1546 ZoomWindowIdeal( (WindowRef
)GetWXWindow() , maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
1549 bool wxNonOwnedWindowCarbonImpl::IsFullScreen() const
1551 return m_macFullScreenData
!= NULL
;
1554 bool wxNonOwnedWindowCarbonImpl::ShowFullScreen(bool show
, long style
)
1558 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1560 data
= new FullScreenData() ;
1562 m_macFullScreenData
= data
;
1563 data
->m_position
= m_wxPeer
->GetPosition() ;
1564 data
->m_size
= m_wxPeer
->GetSize() ;
1565 #if wxOSX_USE_CARBON
1566 WindowAttributes attr
= 0;
1567 GetWindowAttributes((WindowRef
) GetWXWindow(), &attr
);
1568 data
->m_wasResizable
= attr
& kWindowResizableAttribute
;
1569 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1573 wxRect client
= wxGetClientDisplayRect() ;
1575 int left
, top
, width
, height
;
1583 GetContentArea( left
, top
, width
, height
) ;
1584 int outerwidth
, outerheight
;
1585 GetSize( outerwidth
, outerheight
);
1587 if ( style
& wxFULLSCREEN_NOCAPTION
)
1591 // avoid adding the caption twice to the height
1595 if ( style
& wxFULLSCREEN_NOBORDER
)
1598 w
+= outerwidth
- width
;
1599 h
+= outerheight
- height
;
1602 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1607 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1612 m_wxPeer
->SetSize( x
, y
, w
, h
) ;
1613 if ( data
->m_wasResizable
)
1615 #if wxOSX_USE_CARBON
1616 ChangeWindowAttributes( (WindowRef
) GetWXWindow() , kWindowNoAttributes
, kWindowResizableAttribute
) ;
1620 else if ( m_macFullScreenData
!= NULL
)
1622 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1623 #if wxOSX_USE_CARBON
1625 if ( data
->m_wasResizable
)
1626 ChangeWindowAttributes( (WindowRef
) GetWXWindow() , kWindowResizableAttribute
, kWindowNoAttributes
) ;
1628 m_wxPeer
->SetPosition( data
->m_position
) ;
1629 m_wxPeer
->SetSize( data
->m_size
) ;
1632 m_macFullScreenData
= NULL
;
1638 // Attracts the users attention to this window if the application is
1639 // inactive (should be called when a background event occurs)
1641 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1644 DisposePtr( (Ptr
)ptr
) ;
1647 void wxNonOwnedWindowCarbonImpl::RequestUserAttention(int WXUNUSED(flags
))
1649 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1651 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1652 notificationRequest
->qType
= nmType
;
1653 notificationRequest
->nmMark
= 1 ;
1654 notificationRequest
->nmIcon
= 0 ;
1655 notificationRequest
->nmSound
= 0 ;
1656 notificationRequest
->nmStr
= NULL
;
1657 notificationRequest
->nmResp
= wxMacNMResponse
;
1659 verify_noerr( NMInstall( notificationRequest
) ) ;
1662 void wxNonOwnedWindowCarbonImpl::ScreenToWindow( int *x
, int *y
)
1664 HIPoint p
= CGPointMake( (x
? *x
: 0), (y
? *y
: 0) );
1665 HIViewRef contentView
;
1666 // TODO check toolbar offset
1667 HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowContentID
, &contentView
) ;
1668 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
1675 void wxNonOwnedWindowCarbonImpl::WindowToScreen( int *x
, int *y
)
1677 HIPoint p
= CGPointMake( (x
? *x
: 0), (y
? *y
: 0) );
1678 HIViewRef contentView
;
1679 // TODO check toolbar offset
1680 HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowContentID
, &contentView
) ;
1681 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
1688 bool wxNonOwnedWindowCarbonImpl::IsActive()
1690 return ActiveNonFloatingWindow() == m_macWindow
;
1693 wxNonOwnedWindowImpl
* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
1694 long style
, long extraStyle
, const wxString
& name
)
1696 wxNonOwnedWindowImpl
* now
= new wxNonOwnedWindowCarbonImpl( wxpeer
);
1697 now
->Create( parent
, pos
, size
, style
, extraStyle
, name
);
1701 wxNonOwnedWindowImpl
* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, WXWindow nativeWindow
)
1703 wxNonOwnedWindowCarbonImpl
* now
= new wxNonOwnedWindowCarbonImpl( wxpeer
);
1704 now
->Create( parent
, nativeWindow
);