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
);
154 OSStatus err
= HIWindowChangeFeatures( m_macWindow
, kWindowIsOpaque
, 0 );
156 err
= ReshapeCustomWindow( m_macWindow
);
163 bool wxNonOwnedWindowCarbonImpl::CanSetTransparent()
168 void wxNonOwnedWindowCarbonImpl::GetContentArea( int &left
, int &top
, int &width
, int &height
) const
170 Rect content
, structure
;
172 GetWindowBounds( m_macWindow
, kWindowStructureRgn
, &structure
) ;
173 GetWindowBounds( m_macWindow
, kWindowContentRgn
, &content
) ;
175 left
= content
.left
- structure
.left
;
176 top
= content
.top
- structure
.top
;
177 width
= content
.right
- content
.left
;
178 height
= content
.bottom
- content
.top
;
181 void wxNonOwnedWindowCarbonImpl::MoveWindow(int x
, int y
, int width
, int height
)
183 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
184 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
187 void wxNonOwnedWindowCarbonImpl::GetPosition( int &x
, int &y
) const
191 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
197 void wxNonOwnedWindowCarbonImpl::GetSize( int &width
, int &height
) const
201 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
203 width
= bounds
.right
- bounds
.left
;
204 height
= bounds
.bottom
- bounds
.top
;
207 bool wxNonOwnedWindowCarbonImpl::MacGetUnifiedAppearance() const
209 return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute
;
212 void wxNonOwnedWindowCarbonImpl::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
214 ChangeWindowAttributes( m_macWindow
, attributesToSet
, attributesToClear
) ;
217 wxUint32
wxNonOwnedWindowCarbonImpl::MacGetWindowAttributes() const
220 GetWindowAttributes( m_macWindow
, &attr
) ;
224 void wxNonOwnedWindowCarbonImpl::MacSetMetalAppearance( bool set
)
226 if ( MacGetUnifiedAppearance() )
227 MacSetUnifiedAppearance( false ) ;
229 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
230 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
233 bool wxNonOwnedWindowCarbonImpl::MacGetMetalAppearance() const
235 return MacGetWindowAttributes() & kWindowMetalAttribute
;
238 void wxNonOwnedWindowCarbonImpl::MacSetUnifiedAppearance( bool set
)
240 if ( MacGetMetalAppearance() )
241 MacSetMetalAppearance( false ) ;
243 MacChangeWindowAttributes( set
? kWindowUnifiedTitleAndToolbarAttribute
: kWindowNoAttributes
,
244 set
? kWindowNoAttributes
: kWindowUnifiedTitleAndToolbarAttribute
) ;
246 // For some reason, Tiger uses white as the background color for this appearance,
247 // while most apps using it use the typical striped background. Restore that behavior
249 // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
251 // since when creating the peering is not yet completely set-up we call both setters
253 m_wxPeer
->SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
) ) ;
254 SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
) ) ;
258 // ----------------------------------------------------------------------------
260 // ----------------------------------------------------------------------------
262 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
264 void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
);
266 // ---------------------------------------------------------------------------
268 // ---------------------------------------------------------------------------
270 static const EventTypeSpec eventList
[] =
272 // TODO: remove control related event like key and mouse (except for WindowLeave events)
274 { kEventClassKeyboard
, kEventRawKeyDown
} ,
275 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
276 { kEventClassKeyboard
, kEventRawKeyUp
} ,
277 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
279 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
280 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
282 { kEventClassWindow
, kEventWindowShown
} ,
283 { kEventClassWindow
, kEventWindowActivated
} ,
284 { kEventClassWindow
, kEventWindowDeactivated
} ,
285 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
286 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
287 { kEventClassWindow
, kEventWindowClose
} ,
288 { kEventClassWindow
, kEventWindowGetRegion
} ,
290 // we have to catch these events on the toplevel window level,
291 // as controls don't get the raw mouse events anymore
293 { kEventClassMouse
, kEventMouseDown
} ,
294 { kEventClassMouse
, kEventMouseUp
} ,
295 { kEventClassMouse
, kEventMouseWheelMoved
} ,
296 { kEventClassMouse
, kEventMouseMoved
} ,
297 { kEventClassMouse
, kEventMouseDragged
} ,
300 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
302 OSStatus result
= eventNotHandledErr
;
303 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
304 // FindFocus does not return the actual focus window, but the enclosing window
305 wxWindow
* focus
= wxWindow::DoFindFocus();
307 focus
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
309 unsigned char charCode
;
317 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
320 ByteCount dataSize
= 0 ;
321 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
324 int numChars
= dataSize
/ sizeof( UniChar
) + 1;
326 UniChar
* charBuf
= buf
;
328 if ( numChars
* 2 > 4 )
329 charBuf
= new UniChar
[ numChars
] ;
330 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
331 charBuf
[ numChars
- 1 ] = 0;
333 #if SIZEOF_WCHAR_T == 2
334 uniChar
= charBuf
[0] ;
336 wxMBConvUTF16 converter
;
337 converter
.MB2WC( uniChar
, (const char*)charBuf
, 2 ) ;
340 if ( numChars
* 2 > 4 )
345 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
346 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
347 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
348 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
350 UInt32 message
= (keyCode
<< 8) + charCode
;
351 switch ( GetEventKind( event
) )
353 case kEventRawKeyRepeat
:
354 case kEventRawKeyDown
:
356 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
357 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
358 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
359 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
360 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
364 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
368 case kEventRawKeyUp
:
369 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
370 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
376 case kEventRawKeyModifiersChanged
:
378 wxKeyEvent
event(wxEVT_KEY_DOWN
);
380 event
.m_shiftDown
= modifiers
& shiftKey
;
381 event
.m_controlDown
= modifiers
& controlKey
;
382 event
.m_altDown
= modifiers
& optionKey
;
383 event
.m_metaDown
= modifiers
& cmdKey
;
388 event
.m_uniChar
= uniChar
[0] ;
391 event
.SetTimestamp(when
);
392 event
.SetEventObject(focus
);
394 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
396 event
.m_keyCode
= WXK_CONTROL
;
397 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
398 focus
->HandleWindowEvent( event
) ;
400 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
402 event
.m_keyCode
= WXK_SHIFT
;
403 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
404 focus
->HandleWindowEvent( event
) ;
406 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
408 event
.m_keyCode
= WXK_ALT
;
409 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
410 focus
->HandleWindowEvent( event
) ;
412 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
414 event
.m_keyCode
= WXK_COMMAND
;
415 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
416 focus
->HandleWindowEvent( event
) ;
419 wxApp::s_lastModifiers
= modifiers
;
430 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
431 // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
434 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
436 EventMouseButton g_lastButton
= 0 ;
437 bool g_lastButtonWasFakeRight
= false ;
439 void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
441 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
442 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
444 // these parameters are not given for all events
445 EventMouseButton button
= 0 ;
446 UInt32 clickCount
= 0 ;
447 UInt32 mouseChord
= 0;
449 cEvent
.GetParameter
<EventMouseButton
>( kEventParamMouseButton
, typeMouseButton
, &button
) ;
450 cEvent
.GetParameter
<UInt32
>( kEventParamClickCount
, typeUInt32
, &clickCount
) ;
451 // the chord is the state of the buttons pressed currently
452 cEvent
.GetParameter
<UInt32
>( kEventParamMouseChord
, typeUInt32
, &mouseChord
) ;
454 wxevent
.m_x
= screenMouseLocation
.h
;
455 wxevent
.m_y
= screenMouseLocation
.v
;
456 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
457 wxevent
.m_controlDown
= modifiers
& controlKey
;
458 wxevent
.m_altDown
= modifiers
& optionKey
;
459 wxevent
.m_metaDown
= modifiers
& cmdKey
;
460 wxevent
.m_clickCount
= clickCount
;
461 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
463 // a control click is interpreted as a right click
464 bool thisButtonIsFakeRight
= false ;
465 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
467 button
= kEventMouseButtonSecondary
;
468 thisButtonIsFakeRight
= true ;
471 // otherwise we report double clicks by connecting a left click with a ctrl-left click
472 if ( clickCount
> 1 && button
!= g_lastButton
)
475 // we must make sure that our synthetic 'right' button corresponds in
476 // mouse down, moved and mouse up, and does not deliver a right down and left up
478 if ( cEvent
.GetKind() == kEventMouseDown
)
480 g_lastButton
= button
;
481 g_lastButtonWasFakeRight
= thisButtonIsFakeRight
;
487 g_lastButtonWasFakeRight
= false ;
489 else if ( g_lastButton
== kEventMouseButtonSecondary
&& g_lastButtonWasFakeRight
)
490 button
= g_lastButton
;
492 // Adjust the chord mask to remove the primary button and add the
493 // secondary button. It is possible that the secondary button is
494 // already pressed, e.g. on a mouse connected to a laptop, but this
495 // possibility is ignored here:
496 if( thisButtonIsFakeRight
&& ( mouseChord
& 1U ) )
497 mouseChord
= ((mouseChord
& ~1U) | 2U);
500 wxevent
.m_leftDown
= true ;
502 wxevent
.m_rightDown
= true ;
504 wxevent
.m_middleDown
= true ;
506 // translate into wx types
507 switch ( cEvent
.GetKind() )
509 case kEventMouseDown
:
512 case kEventMouseButtonPrimary
:
513 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
516 case kEventMouseButtonSecondary
:
517 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
520 case kEventMouseButtonTertiary
:
521 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
532 case kEventMouseButtonPrimary
:
533 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
536 case kEventMouseButtonSecondary
:
537 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
540 case kEventMouseButtonTertiary
:
541 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
548 // TODO http://developer.apple.com/qa/qa2005/qa1453.html
549 // add declaration for 10.4 and change to kEventMouseScroll
550 case kEventMouseWheelMoved
:
552 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
554 EventMouseWheelAxis axis
= cEvent
.GetParameter
<EventMouseWheelAxis
>(kEventParamMouseWheelAxis
, typeMouseWheelAxis
) ;
555 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeSInt32
) ;
557 wxevent
.m_wheelRotation
= delta
;
558 wxevent
.m_wheelDelta
= 1;
559 wxevent
.m_linesPerAction
= 1;
560 if ( axis
== kEventMouseWheelAxisX
)
561 wxevent
.m_wheelAxis
= 1;
565 case kEventMouseEntered
:
566 case kEventMouseExited
:
567 case kEventMouseDragged
:
568 case kEventMouseMoved
:
569 wxevent
.SetEventType( wxEVT_MOTION
) ;
576 #define NEW_CAPTURE_HANDLING 1
579 wxMacTopLevelMouseEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
583 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
585 OSStatus result
= eventNotHandledErr
;
587 wxMacCarbonEvent
cEvent( event
) ;
589 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
590 Point windowMouseLocation
= screenMouseLocation
;
592 WindowRef window
= NULL
;
593 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
595 wxWindow
* currentMouseWindow
= NULL
;
596 ControlRef control
= NULL
;
598 #if NEW_CAPTURE_HANDLING
599 if ( wxApp::s_captureWindow
)
601 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
602 windowPart
= inContent
;
608 QDGlobalToLocalPoint( GetWindowPort( window
), &windowMouseLocation
);
610 if ( wxApp::s_captureWindow
611 #if !NEW_CAPTURE_HANDLING
612 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
616 currentMouseWindow
= wxApp::s_captureWindow
;
618 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
620 ControlPartCode part
;
621 control
= FindControlUnderMouse( windowMouseLocation
, window
, &part
) ;
622 // if there is no control below the mouse position, send the event to the toplevel window itself
625 currentMouseWindow
= (wxWindow
*) toplevelWindow
;
629 currentMouseWindow
= (wxWindow
*) wxFindWindowFromWXWidget( (WXWidget
) control
) ;
630 #ifndef __WXUNIVERSAL__
631 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
634 // for wxToolBar to function we have to send certaint events to it
635 // instead of its children (wxToolBarTools)
637 GetSuperControl(control
, &parent
);
638 wxWindow
*wxparent
= (wxWindow
*) wxFindWindowFromWXWidget((WXWidget
) parent
) ;
639 if ( wxparent
&& wxparent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
640 currentMouseWindow
= wxparent
;
646 // disabled windows must not get any input messages
647 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
648 currentMouseWindow
= NULL
;
652 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
653 SetupMouseEvent( wxevent
, cEvent
) ;
655 // handle all enter / leave events
657 if ( currentMouseWindow
!= g_MacLastWindow
)
659 if ( g_MacLastWindow
)
661 wxMouseEvent
eventleave(wxevent
);
662 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
663 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
664 eventleave
.SetEventObject( g_MacLastWindow
) ;
665 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
668 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
671 g_MacLastWindow
->HandleWindowEvent(eventleave
);
674 if ( currentMouseWindow
)
676 wxMouseEvent
evententer(wxevent
);
677 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
678 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
679 evententer
.SetEventObject( currentMouseWindow
) ;
680 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
683 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
686 currentMouseWindow
->HandleWindowEvent(evententer
);
689 g_MacLastWindow
= currentMouseWindow
;
692 if ( windowPart
== inMenuBar
)
694 // special case menu bar, as we are having a low-level runloop we must do it ourselves
695 if ( cEvent
.GetKind() == kEventMouseDown
)
697 ::MenuSelect( screenMouseLocation
) ;
702 else if ( window
&& windowPart
== inProxyIcon
)
704 // special case proxy icon bar, as we are having a low-level runloop we must do it ourselves
705 if ( cEvent
.GetKind() == kEventMouseDown
)
707 if ( ::TrackWindowProxyDrag( window
, screenMouseLocation
) != errUserWantsToDragWindow
)
709 // TODO Track change of file path and report back
714 else if ( currentMouseWindow
)
716 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
718 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
720 wxevent
.SetEventObject( currentMouseWindow
) ;
721 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
723 // make tooltips current
726 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
727 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
730 if ( currentMouseWindow
->HandleWindowEvent(wxevent
) )
732 if ((currentMouseWindowParent
!= NULL
) &&
733 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
734 currentMouseWindow
= NULL
;
740 // if the user code did _not_ handle the event, then perform the
741 // default processing
742 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
744 // ... that is set focus to this window
745 if (currentMouseWindow
->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
746 currentMouseWindow
->SetFocus();
750 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
752 wxApp::s_captureWindow
= NULL
;
758 wxWindow
* cursorTarget
= currentMouseWindow
;
759 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
761 extern wxCursor gGlobalCursor
;
763 if (!gGlobalCursor
.IsOk())
765 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
767 cursorTarget
= cursorTarget
->GetParent() ;
769 cursorPoint
+= cursorTarget
->GetPosition();
774 else // currentMouseWindow == NULL
776 if (toplevelWindow
&& !control
)
778 extern wxCursor gGlobalCursor
;
779 if (!gGlobalCursor
.IsOk())
781 // update cursor when over toolbar and titlebar etc.
782 wxSTANDARD_CURSOR
->MacInstall() ;
786 // don't mess with controls we don't know about
787 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
788 // so we try sending them the correct control directly
789 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
791 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
792 Point clickLocation
= windowMouseLocation
;
795 hiPoint
.x
= clickLocation
.h
;
796 hiPoint
.y
= clickLocation
.v
;
797 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
798 clickLocation
.h
= (int)hiPoint
.x
;
799 clickLocation
.v
= (int)hiPoint
.y
;
801 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
809 static pascal OSStatus
810 wxNonOwnedWindowEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
814 OSStatus result
= eventNotHandledErr
;
816 wxMacCarbonEvent
cEvent( event
) ;
818 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
819 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
821 switch ( GetEventKind( event
) )
823 case kEventWindowActivated
:
825 toplevelWindow
->HandleActivated( cEvent
.GetTicks() , true) ;
826 // we still sending an eventNotHandledErr in order to allow for default processing
830 case kEventWindowDeactivated
:
832 toplevelWindow
->HandleActivated( cEvent
.GetTicks() , false) ;
833 // we still sending an eventNotHandledErr in order to allow for default processing
837 case kEventWindowShown
:
838 toplevelWindow
->Refresh() ;
842 case kEventWindowClose
:
843 toplevelWindow
->Close() ;
847 case kEventWindowBoundsChanged
:
849 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
850 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
851 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
852 if ( attributes
& kWindowBoundsChangeSizeChanged
)
854 toplevelWindow
->HandleResized(cEvent
.GetTicks() ) ;
857 if ( attributes
& kWindowBoundsChangeOriginChanged
)
859 toplevelWindow
->HandleMoved(cEvent
.GetTicks() ) ;
866 case kEventWindowBoundsChanging
:
868 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
869 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
871 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
873 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
874 int left
, top
, width
, height
;
878 toplevelWindow
->GetNonOwnedPeer()->GetContentArea(left
, top
, width
, height
);
879 toplevelWindow
->GetNonOwnedPeer()->GetSize(swidth
, sheight
);
880 int deltawidth
= swidth
- width
;
881 int deltaheight
= sheight
- height
;
885 newRect
.right
- newRect
.left
+ deltawidth
,
886 newRect
.bottom
- newRect
.top
+ deltaheight
) ;
888 toplevelWindow
->HandleResizing( cEvent
.GetTicks(), &adjustR
);
890 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ top
+ adjustR
.height
- deltaheight
,
891 adjustR
.x
+ left
+ adjustR
.width
- deltawidth
} ;
892 if ( !EqualRect( &newRect
, &adjustedRect
) )
893 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
900 case kEventWindowGetRegion
:
902 if ( toplevelWindow
->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
904 WindowRegionCode windowRegionCode
;
906 // Fetch the region code that is being queried
907 GetEventParameter( event
,
908 kEventParamWindowRegionCode
,
909 typeWindowRegionCode
, NULL
,
910 sizeof windowRegionCode
, NULL
,
911 &windowRegionCode
) ;
913 // If it is the opaque region code then set the
914 // region to empty and return noErr to stop event
916 if ( windowRegionCode
== kWindowOpaqueRgn
) {
918 GetEventParameter( event
,
919 kEventParamRgnHandle
,
920 typeQDRgnHandle
, NULL
,
923 SetEmptyRgn(region
) ;
937 // mix this in from window.cpp
938 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
940 static pascal OSStatus
wxNonOwnedEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
942 OSStatus result
= eventNotHandledErr
;
944 switch ( GetEventClass( event
) )
946 case kEventClassTextInput
:
948 // TODO remove as soon as all events are on implementation classes only
949 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
951 result
= wxMacUnicodeTextEventHandler( handler
, event
, toplevelWindow
) ;
955 case kEventClassKeyboard
:
956 result
= KeyboardEventHandler( handler
, event
, data
) ;
959 case kEventClassWindow
:
960 result
= wxNonOwnedWindowEventHandler( handler
, event
, data
) ;
963 case kEventClassMouse
:
964 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
974 DEFINE_ONE_SHOT_HANDLER_GETTER( wxNonOwnedEventHandler
)
976 // ---------------------------------------------------------------------------
977 // Support functions for shaped windows, based on Apple's CustomWindow sample at
978 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
979 // ---------------------------------------------------------------------------
981 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
983 GetWindowPortBounds(window
, inRect
);
984 Point pt
= { inRect
->top
,inRect
->left
};
985 QDLocalToGlobalPoint( GetWindowPort( window
), &pt
);
986 inRect
->bottom
+= pt
.v
- inRect
->top
;
987 inRect
->right
+= pt
.h
- inRect
->left
;
992 static SInt32
wxShapedMacWindowGetFeatures(WindowRef
WXUNUSED(window
), SInt32 param
)
994 /*------------------------------------------------------
995 Define which options your custom window supports.
996 --------------------------------------------------------*/
997 //just enable everything for our demo
998 *(OptionBits
*)param
=
1001 kWindowCanCollapse
|
1002 //kWindowCanGetWindowRegion |
1003 //kWindowHasTitleBar |
1004 //kWindowSupportsDragHilite |
1005 kWindowCanDrawInCurrentPort
|
1006 //kWindowCanMeasureTitle |
1007 kWindowWantsDisposeAtProcessDeath
|
1008 kWindowSupportsGetGrowImageRegion
|
1009 kWindowDefSupportsColorGrafPort
;
1014 // The content region is left as a rectangle matching the window size, this is
1015 // so the origin in the paint event, and etc. still matches what the
1016 // programmer expects.
1017 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1020 wxNonOwnedWindow
* win
= wxNonOwnedWindow::GetFromWXWindow((WXWindow
)window
);
1024 wxShapedMacWindowGetPos( window
, &r
) ;
1025 RectRgn( rgn
, &r
) ;
1029 // The structure region is set to the shape given to the SetShape method.
1030 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1032 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1038 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1039 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1040 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1041 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1045 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1047 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1052 switch (rgnRec
->regionCode
)
1054 case kWindowStructureRgn
:
1055 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1058 case kWindowContentRgn
:
1059 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1063 SetEmptyRgn(rgnRec
->winRgn
);
1070 // Determine the region of the window which was hit
1072 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1075 static RgnHandle tempRgn
= NULL
;
1077 if (tempRgn
== NULL
)
1080 // get the point clicked
1081 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1083 // Mac OS 8.5 or later
1084 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1085 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1088 // no significant area was hit
1092 static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode
), WindowRef window
, SInt16 message
, SInt32 param
)
1096 case kWindowMsgHitTest
:
1097 return wxShapedMacWindowHitTest(window
, param
);
1099 case kWindowMsgGetFeatures
:
1100 return wxShapedMacWindowGetFeatures(window
, param
);
1102 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1103 case kWindowMsgGetRegion
:
1104 return wxShapedMacWindowGetRegion(window
, param
);
1117 wxPoint m_position
;
1119 bool m_wasResizable
;
1122 wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl()
1126 wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl( wxNonOwnedWindow
* nonownedwnd
) : wxNonOwnedWindowImpl( nonownedwnd
)
1128 m_macEventHandler
= NULL
;
1130 m_macFullScreenData
= NULL
;
1133 wxNonOwnedWindowCarbonImpl::~wxNonOwnedWindowCarbonImpl()
1136 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
1139 if ( m_macEventHandler
)
1141 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1142 m_macEventHandler
= NULL
;
1145 if ( m_macWindow
&& !m_wxPeer
->IsNativeWindowWrapper())
1146 DisposeWindow( m_macWindow
);
1148 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1150 m_macFullScreenData
= NULL
;
1156 void wxNonOwnedWindowCarbonImpl::WillBeDestroyed()
1158 if ( m_macEventHandler
)
1160 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1161 m_macEventHandler
= NULL
;
1165 static void wxNonOwnedWindowInstallTopLevelWindowEventHandler(WindowRef window
, EventHandlerRef
* handler
, void *ref
)
1167 InstallWindowEventHandler(window
, GetwxNonOwnedEventHandlerUPP(),
1168 GetEventTypeCount(eventList
), eventList
, ref
, handler
);
1171 bool wxNonOwnedWindowCarbonImpl::SetShape(const wxRegion
& region
)
1173 // Make a copy of the region
1174 RgnHandle shapeRegion
= NewRgn();
1175 HIShapeGetAsQDRgn( region
.GetWXHRGN(), shapeRegion
);
1177 // Dispose of any shape region we may already have
1178 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
) m_wxPeer
->GetWXWindow() );
1182 // Save the region so we can use it later
1183 SetWRefCon((WindowRef
) m_wxPeer
->GetWXWindow(), (URefCon
)shapeRegion
);
1185 // inform the window manager that the window has changed shape
1186 ReshapeCustomWindow((WindowRef
) m_wxPeer
->GetWXWindow());
1192 void wxNonOwnedWindowCarbonImpl::MacInstallTopLevelWindowEventHandler()
1194 if ( m_macEventHandler
!= NULL
)
1196 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1198 wxNonOwnedWindowInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow
),(EventHandlerRef
*)&m_macEventHandler
,this);
1201 void wxNonOwnedWindowCarbonImpl::Create(
1203 WXWindow nativeWindow
)
1205 m_macWindow
= nativeWindow
;
1208 void wxNonOwnedWindowCarbonImpl::Create(
1212 long style
, long extraStyle
,
1213 const wxString
& WXUNUSED(name
) )
1216 OSStatus err
= noErr
;
1225 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1227 // translate the window attributes in the appropriate window class and attributes
1228 WindowClass wclass
= 0;
1229 WindowAttributes attr
= kWindowNoAttributes
;
1230 WindowGroupRef group
= NULL
;
1231 bool activationScopeSet
= false;
1232 WindowActivationScope activationScope
= kWindowActivationScopeNone
;
1234 if ( style
& wxFRAME_TOOL_WINDOW
)
1237 ( style
& wxMINIMIZE_BOX
) || ( style
& wxMAXIMIZE_BOX
) ||
1238 ( style
& wxSYSTEM_MENU
) || ( style
& wxCAPTION
) ||
1239 ( style
&wxTINY_CAPTION_HORIZ
) || ( style
&wxTINY_CAPTION_VERT
)
1242 if ( ( style
& wxSTAY_ON_TOP
) )
1243 wclass
= kUtilityWindowClass
;
1245 wclass
= kFloatingWindowClass
;
1247 if ( ( style
&wxTINY_CAPTION_VERT
) )
1248 attr
|= kWindowSideTitlebarAttribute
;
1252 if ( style
& wxNO_BORDER
)
1254 wclass
= kSimpleWindowClass
;
1258 wclass
= kPlainWindowClass
;
1260 activationScopeSet
= true;
1261 activationScope
= kWindowActivationScopeNone
;
1264 else if ( ( style
& wxPOPUP_WINDOW
) )
1266 if ( ( style
& wxBORDER_NONE
) )
1268 wclass
= kHelpWindowClass
; // has no border
1269 attr
|= kWindowNoShadowAttribute
;
1273 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1275 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1276 // make sure we don't deactivate something
1277 activationScopeSet
= true;
1278 activationScope
= kWindowActivationScopeNone
;
1280 else if ( ( style
& wxCAPTION
) )
1282 wclass
= kDocumentWindowClass
;
1283 attr
|= kWindowInWindowMenuAttribute
;
1285 else if ( ( style
& wxFRAME_DRAWER
) )
1287 wclass
= kDrawerWindowClass
;
1291 if ( ( style
& wxMINIMIZE_BOX
) || ( style
& wxMAXIMIZE_BOX
) ||
1292 ( style
& wxCLOSE_BOX
) || ( style
& wxSYSTEM_MENU
) )
1294 wclass
= kDocumentWindowClass
;
1296 else if ( ( style
& wxNO_BORDER
) )
1298 wclass
= kSimpleWindowClass
;
1302 wclass
= kPlainWindowClass
;
1306 if ( wclass
!= kPlainWindowClass
)
1308 if ( ( style
& wxMINIMIZE_BOX
) )
1309 attr
|= kWindowCollapseBoxAttribute
;
1311 if ( ( style
& wxMAXIMIZE_BOX
) )
1312 attr
|= kWindowFullZoomAttribute
;
1314 if ( ( style
& wxRESIZE_BORDER
) )
1315 attr
|= kWindowResizableAttribute
;
1317 if ( ( style
& wxCLOSE_BOX
) )
1318 attr
|= kWindowCloseBoxAttribute
;
1320 attr
|= kWindowLiveResizeAttribute
;
1322 if ( ( style
&wxSTAY_ON_TOP
) )
1323 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1325 if ( ( style
& wxFRAME_FLOAT_ON_PARENT
) )
1326 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1328 if ( group
== NULL
&& parent
!= NULL
)
1330 WindowRef parenttlw
= (WindowRef
) parent
->MacGetTopLevelWindowRef();
1332 group
= GetWindowGroupParent( GetWindowGroup( parenttlw
) );
1335 attr
|= kWindowCompositingAttribute
;
1336 #if 0 // TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1337 attr
|= kWindowFrameworkScaledAttribute
;
1340 if ( ( style
&wxFRAME_SHAPED
) )
1342 WindowDefSpec customWindowDefSpec
;
1343 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1344 customWindowDefSpec
.u
.defProc
=
1346 (WindowDefUPP
) wxShapedMacWindowDef
;
1348 NewWindowDefUPP(wxShapedMacWindowDef
);
1350 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1351 attr
, &theBoundsRect
,
1352 (WindowRef
*) &m_macWindow
);
1356 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1359 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1360 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1362 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1364 // setup a separate group for each window, so that overlays can be handled easily
1366 WindowGroupRef overlaygroup
= NULL
;
1367 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &overlaygroup
));
1368 verify_noerr( SetWindowGroupParent( overlaygroup
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1369 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, overlaygroup
));
1371 if ( activationScopeSet
)
1373 verify_noerr( SetWindowActivationScope( (WindowRef
) m_macWindow
, activationScope
));
1376 // the create commands are only for content rect,
1377 // so we have to set the size again as structure bounds
1378 SetWindowBounds( m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1380 // Causes the inner part of the window not to be metal
1381 // if the style is used before window creation.
1382 #if 0 // TARGET_API_MAC_OSX
1383 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1385 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1386 MacSetMetalAppearance( true ) ;
1390 if ( m_macWindow
!= NULL
)
1392 MacSetUnifiedAppearance( true ) ;
1395 HIViewRef growBoxRef
= 0 ;
1396 err
= HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowGrowBoxID
, &growBoxRef
);
1397 if ( err
== noErr
&& growBoxRef
!= 0 )
1398 HIGrowBoxViewSetTransparent( growBoxRef
, true ) ;
1400 // the frame window event handler
1401 InstallStandardEventHandler( GetWindowEventTarget(m_macWindow
) ) ;
1402 MacInstallTopLevelWindowEventHandler() ;
1404 if ( extraStyle
& wxFRAME_EX_METAL
)
1405 MacSetMetalAppearance(true);
1407 if ( ( style
&wxFRAME_SHAPED
) )
1409 // default shape matches the window size
1410 wxRegion
rgn( 0, 0, w
, h
);
1415 bool wxNonOwnedWindowCarbonImpl::ShowWithEffect(bool show
,
1416 wxShowEffect effect
,
1419 WindowTransitionEffect transition
= 0 ;
1422 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1423 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1424 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1425 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1426 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1427 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1428 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1429 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1430 transition
= kWindowGenieTransitionEffect
;
1432 case wxSHOW_EFFECT_BLEND
:
1433 transition
= kWindowFadeTransitionEffect
;
1435 case wxSHOW_EFFECT_EXPAND
:
1436 // having sheets would be fine, but this might lead to a repositioning
1439 transition
= kWindowSheetTransitionEffect
;
1442 transition
= kWindowZoomTransitionEffect
;
1445 case wxSHOW_EFFECT_NONE
:
1446 // wxNonOwnedWindow is supposed to call Show() itself in this case
1447 wxFAIL_MSG( "ShowWithEffect() shouldn't be called" );
1450 case wxSHOW_EFFECT_MAX
:
1451 wxFAIL_MSG( "invalid effect flag" );
1455 TransitionWindowOptions options
;
1456 options
.version
= 0;
1457 options
.duration
= timeout
/ 1000.0;
1458 options
.window
= transition
== kWindowSheetTransitionEffect
? (WindowRef
) m_wxPeer
->GetParent()->MacGetTopLevelWindowRef() :0;
1459 options
.userData
= 0;
1461 wxSize size
= wxGetDisplaySize();
1463 GetWindowBounds( (WindowRef
)m_macWindow
, kWindowStructureRgn
, &bounds
);
1464 CGRect hiBounds
= CGRectMake( bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
);
1468 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1469 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1470 hiBounds
.origin
.x
= 0;
1471 hiBounds
.size
.width
= 0;
1474 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1475 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1476 hiBounds
.origin
.x
= size
.x
;
1477 hiBounds
.size
.width
= 0;
1480 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1481 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1482 hiBounds
.origin
.y
= size
.y
;
1483 hiBounds
.size
.height
= 0;
1486 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1487 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1488 hiBounds
.origin
.y
= 0;
1489 hiBounds
.size
.height
= 0;
1493 break; // direction doesn't make sense
1496 ::TransitionWindowWithOptions
1498 (WindowRef
)m_macWindow
,
1500 show
? kWindowShowTransitionAction
: kWindowHideTransitionAction
,
1501 transition
== kWindowGenieTransitionEffect
? &hiBounds
: NULL
,
1508 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1514 void wxNonOwnedWindowCarbonImpl::SetTitle( const wxString
& title
, wxFontEncoding encoding
)
1516 SetWindowTitleWithCFString( m_macWindow
, wxCFStringRef( title
, encoding
) ) ;
1519 bool wxNonOwnedWindowCarbonImpl::IsMaximized() const
1521 return IsWindowInStandardState( m_macWindow
, NULL
, NULL
) ;
1524 bool wxNonOwnedWindowCarbonImpl::IsIconized() const
1526 return IsWindowCollapsed((WindowRef
)GetWXWindow() ) ;
1529 void wxNonOwnedWindowCarbonImpl::Iconize( bool iconize
)
1531 if ( IsWindowCollapsable( m_macWindow
) )
1532 CollapseWindow( m_macWindow
, iconize
) ;
1535 void wxNonOwnedWindowCarbonImpl::Maximize(bool maximize
)
1537 Point idealSize
= { 0 , 0 } ;
1540 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1542 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
1544 idealSize
.h
= bounds
.size
.width
;
1545 idealSize
.v
= bounds
.size
.height
;
1548 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
1549 idealSize
.h
= rect
.right
- rect
.left
;
1550 idealSize
.v
= rect
.bottom
- rect
.top
;
1553 ZoomWindowIdeal( (WindowRef
)GetWXWindow() , maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
1556 bool wxNonOwnedWindowCarbonImpl::IsFullScreen() const
1558 return m_macFullScreenData
!= NULL
;
1561 bool wxNonOwnedWindowCarbonImpl::ShowFullScreen(bool show
, long style
)
1565 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1567 data
= new FullScreenData() ;
1569 m_macFullScreenData
= data
;
1570 data
->m_position
= m_wxPeer
->GetPosition() ;
1571 data
->m_size
= m_wxPeer
->GetSize() ;
1572 #if wxOSX_USE_CARBON
1573 WindowAttributes attr
= 0;
1574 GetWindowAttributes((WindowRef
) GetWXWindow(), &attr
);
1575 data
->m_wasResizable
= attr
& kWindowResizableAttribute
;
1576 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1580 wxRect client
= wxGetClientDisplayRect() ;
1582 int left
, top
, width
, height
;
1590 GetContentArea( left
, top
, width
, height
) ;
1591 int outerwidth
, outerheight
;
1592 GetSize( outerwidth
, outerheight
);
1594 if ( style
& wxFULLSCREEN_NOCAPTION
)
1598 // avoid adding the caption twice to the height
1602 if ( style
& wxFULLSCREEN_NOBORDER
)
1605 w
+= outerwidth
- width
;
1606 h
+= outerheight
- height
;
1609 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1614 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1619 m_wxPeer
->SetSize( x
, y
, w
, h
) ;
1620 if ( data
->m_wasResizable
)
1622 #if wxOSX_USE_CARBON
1623 ChangeWindowAttributes( (WindowRef
) GetWXWindow() , kWindowNoAttributes
, kWindowResizableAttribute
) ;
1627 else if ( m_macFullScreenData
!= NULL
)
1629 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1630 #if wxOSX_USE_CARBON
1632 if ( data
->m_wasResizable
)
1633 ChangeWindowAttributes( (WindowRef
) GetWXWindow() , kWindowResizableAttribute
, kWindowNoAttributes
) ;
1635 m_wxPeer
->SetPosition( data
->m_position
) ;
1636 m_wxPeer
->SetSize( data
->m_size
) ;
1639 m_macFullScreenData
= NULL
;
1645 // Attracts the users attention to this window if the application is
1646 // inactive (should be called when a background event occurs)
1648 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1651 DisposePtr( (Ptr
)ptr
) ;
1654 void wxNonOwnedWindowCarbonImpl::RequestUserAttention(int WXUNUSED(flags
))
1656 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1658 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1659 notificationRequest
->qType
= nmType
;
1660 notificationRequest
->nmMark
= 1 ;
1661 notificationRequest
->nmIcon
= 0 ;
1662 notificationRequest
->nmSound
= 0 ;
1663 notificationRequest
->nmStr
= NULL
;
1664 notificationRequest
->nmResp
= wxMacNMResponse
;
1666 verify_noerr( NMInstall( notificationRequest
) ) ;
1669 void wxNonOwnedWindowCarbonImpl::ScreenToWindow( int *x
, int *y
)
1671 HIPoint p
= CGPointMake( (x
? *x
: 0), (y
? *y
: 0) );
1672 HIViewRef contentView
;
1673 // TODO check toolbar offset
1674 HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowContentID
, &contentView
) ;
1675 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
1682 void wxNonOwnedWindowCarbonImpl::WindowToScreen( int *x
, int *y
)
1684 HIPoint p
= CGPointMake( (x
? *x
: 0), (y
? *y
: 0) );
1685 HIViewRef contentView
;
1686 // TODO check toolbar offset
1687 HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowContentID
, &contentView
) ;
1688 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
1695 bool wxNonOwnedWindowCarbonImpl::IsActive()
1697 return ActiveNonFloatingWindow() == m_macWindow
;
1700 wxNonOwnedWindowImpl
* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
1701 long style
, long extraStyle
, const wxString
& name
)
1703 wxNonOwnedWindowImpl
* now
= new wxNonOwnedWindowCarbonImpl( wxpeer
);
1704 now
->Create( parent
, pos
, size
, style
, extraStyle
, name
);
1708 wxNonOwnedWindowImpl
* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, WXWindow nativeWindow
)
1710 wxNonOwnedWindowCarbonImpl
* now
= new wxNonOwnedWindowCarbonImpl( wxpeer
);
1711 now
->Create( parent
, nativeWindow
);