1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/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"
32 // TODO BEGIN move to nonowned_osx.cpp
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 // trace mask for activation tracing messages
40 #define TRACE_ACTIVATE "activation"
42 wxWindow
* g_MacLastWindow
= NULL
;
44 // unified title and toolbar constant - not in Tiger headers, so we duplicate it here
45 #define kWindowUnifiedTitleAndToolbarAttribute (1 << 7)
47 // ---------------------------------------------------------------------------
48 // wxWindowMac utility functions
49 // ---------------------------------------------------------------------------
51 // Find an item given the Macintosh Window Reference
53 WX_DECLARE_HASH_MAP(WXWindow
, wxNonOwnedWindow
*, wxPointerHash
, wxPointerEqual
, MacWindowMap
);
55 static MacWindowMap wxWinMacWindowList
;
57 wxNonOwnedWindow
*wxFindWindowFromWXWindow(WXWindow inWindowRef
)
59 MacWindowMap::iterator node
= wxWinMacWindowList
.find(inWindowRef
);
61 return (node
== wxWinMacWindowList
.end()) ? NULL
: node
->second
;
64 void wxAssociateWindowWithWXWindow(WXWindow inWindowRef
, wxNonOwnedWindow
*win
) ;
65 void wxAssociateWindowWithWXWindow(WXWindow inWindowRef
, wxNonOwnedWindow
*win
)
67 // adding NULL WindowRef is (first) surely a result of an error and
69 wxCHECK_RET( inWindowRef
!= (WXWindow
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
71 wxWinMacWindowList
[inWindowRef
] = win
;
74 void wxRemoveWXWindowAssociation(wxNonOwnedWindow
*win
) ;
75 void wxRemoveWXWindowAssociation(wxNonOwnedWindow
*win
)
77 MacWindowMap::iterator it
;
78 for ( it
= wxWinMacWindowList
.begin(); it
!= wxWinMacWindowList
.end(); ++it
)
80 if ( it
->second
== win
)
82 wxWinMacWindowList
.erase(it
);
88 wxNonOwnedWindow
* wxNonOwnedWindow::GetFromWXWindow( WXWindow win
)
90 return wxFindWindowFromWXWindow( win
);
93 // ----------------------------------------------------------------------------
94 // wxNonOwnedWindow creation
95 // ----------------------------------------------------------------------------
97 IMPLEMENT_ABSTRACT_CLASS( wxNonOwnedWindowImpl
, wxObject
)
99 wxNonOwnedWindow
*wxNonOwnedWindow::s_macDeactivateWindow
= NULL
;
101 void wxNonOwnedWindow::Init()
106 bool wxNonOwnedWindow::Create(wxWindow
*parent
,
111 const wxString
& name
)
116 m_windowStyle
= style
;
120 m_windowId
= id
== -1 ? NewControlId() : id
;
121 m_windowStyle
= style
;
128 wxRect display
= wxGetClientDisplayRect() ;
130 if ( x
== wxDefaultPosition
.x
)
133 if ( y
== wxDefaultPosition
.y
)
136 int w
= WidthDefault(size
.x
);
137 int h
= HeightDefault(size
.y
);
139 // temporary define, TODO
141 m_nowpeer
= new wxNonOwnedWindowCarbonImpl( this );
142 #elif wxOSX_USE_COCOA
143 m_nowpeer
= new wxNonOwnedWindowCocoaImpl( this );
144 #elif wxOSX_USE_IPHONE
145 m_nowpeer
= new wxNonOwnedWindowIPhoneImpl( this );
148 m_nowpeer
->Create( parent
, wxPoint(x
,y
) , wxSize(w
,h
) , style
, GetExtraStyle(), name
) ;
149 wxAssociateWindowWithWXWindow( m_nowpeer
->GetWXWindow() , this ) ;
151 // temporary cast, TODO
152 m_peer
= (wxMacControl
*) wxWidgetImpl::CreateContentView(this);
154 m_peer
= wxWidgetImpl::CreateContentView(this);
157 DoSetWindowVariant( m_windowVariant
) ;
159 wxWindowCreateEvent
event(this);
160 HandleWindowEvent(event
);
162 SetBackgroundColour(wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE
));
165 parent
->AddChild(this);
170 wxNonOwnedWindow::~wxNonOwnedWindow()
172 wxRemoveWXWindowAssociation( this ) ;
174 m_nowpeer
->Destroy();
176 // avoid dangling refs
177 if ( s_macDeactivateWindow
== this )
178 s_macDeactivateWindow
= NULL
;
181 // ----------------------------------------------------------------------------
182 // wxNonOwnedWindow misc
183 // ----------------------------------------------------------------------------
185 bool wxNonOwnedWindow::ShowWithEffect(wxShowEffect effect
,
188 if ( !wxWindow::Show(true) )
191 // because apps expect a size event to occur at this moment
192 wxSizeEvent
event(GetSize() , m_windowId
);
193 event
.SetEventObject(this);
194 HandleWindowEvent(event
);
197 return m_nowpeer
->ShowWithEffect(true, effect
, timeout
);
200 bool wxNonOwnedWindow::HideWithEffect(wxShowEffect effect
,
203 if ( !wxWindow::Show(false) )
206 return m_nowpeer
->ShowWithEffect(false, effect
, timeout
);
209 wxPoint
wxNonOwnedWindow::GetClientAreaOrigin() const
211 int left
, top
, width
, height
;
212 m_nowpeer
->GetContentArea(left
, top
, width
, height
);
213 return wxPoint(left
, top
);
216 bool wxNonOwnedWindow::SetBackgroundColour(const wxColour
& c
)
218 if ( !wxWindow::SetBackgroundColour(c
) && m_hasBgCol
)
221 if ( GetBackgroundStyle() != wxBG_STYLE_CUSTOM
)
223 return m_nowpeer
->SetBackgroundColour(c
);
228 // Raise the window to the top of the Z order
229 void wxNonOwnedWindow::Raise()
234 // Lower the window to the bottom of the Z order
235 void wxNonOwnedWindow::Lower()
240 void wxNonOwnedWindow::MacDelayedDeactivation(long timestamp
)
242 if (s_macDeactivateWindow
)
244 wxLogTrace(TRACE_ACTIVATE
,
245 wxT("Doing delayed deactivation of %p"),
246 s_macDeactivateWindow
);
248 s_macDeactivateWindow
->MacActivate(timestamp
, false);
252 void wxNonOwnedWindow::MacActivate( long timestamp
, bool WXUNUSED(inIsActivating
) )
254 wxLogTrace(TRACE_ACTIVATE
, wxT("TopLevel=%p::MacActivate"), this);
256 if (s_macDeactivateWindow
== this)
257 s_macDeactivateWindow
= NULL
;
259 MacDelayedDeactivation(timestamp
);
262 bool wxNonOwnedWindow::Show(bool show
)
264 if ( !wxWindow::Show(show
) )
268 m_nowpeer
->Show(show
);
272 // because apps expect a size event to occur at this moment
273 wxSizeEvent
event(GetSize() , m_windowId
);
274 event
.SetEventObject(this);
275 HandleWindowEvent(event
);
281 bool wxNonOwnedWindow::SetTransparent(wxByte alpha
)
283 return m_nowpeer
->SetTransparent(alpha
);
287 bool wxNonOwnedWindow::CanSetTransparent()
289 return m_nowpeer
->CanSetTransparent();
293 void wxNonOwnedWindow::SetExtraStyle(long exStyle
)
295 if ( GetExtraStyle() == exStyle
)
298 wxWindow::SetExtraStyle( exStyle
) ;
301 m_nowpeer
->SetExtraStyle(exStyle
);
304 bool wxNonOwnedWindow::SetBackgroundStyle(wxBackgroundStyle style
)
306 if ( !wxWindow::SetBackgroundStyle(style
) )
309 return m_nowpeer
->SetBackgroundStyle(style
);
312 void wxNonOwnedWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
314 m_cachedClippedRectValid
= false ;
316 m_nowpeer
->MoveWindow(x
, y
, width
, height
);
317 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
320 void wxNonOwnedWindow::DoGetPosition( int *x
, int *y
) const
323 m_nowpeer
->GetPosition(x1
, y1
);
331 void wxNonOwnedWindow::DoGetSize( int *width
, int *height
) const
335 m_nowpeer
->GetSize(w
, h
);
343 void wxNonOwnedWindow::DoGetClientSize( int *width
, int *height
) const
346 m_nowpeer
->GetContentArea(left
, top
, w
, h
);
355 void wxNonOwnedWindow::Update()
360 WXWindow
wxNonOwnedWindow::GetWXWindow() const
362 return m_nowpeer
? m_nowpeer
->GetWXWindow() : NULL
;
365 // ---------------------------------------------------------------------------
366 // Shape implementation
367 // ---------------------------------------------------------------------------
370 bool wxNonOwnedWindow::SetShape(const wxRegion
& region
)
372 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
373 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
375 // The empty region signifies that the shape
376 // should be removed from the window.
377 if ( region
.IsEmpty() )
379 wxSize sz
= GetClientSize();
380 wxRegion
rgn(0, 0, sz
.x
, sz
.y
);
384 return SetShape(rgn
);
387 return m_nowpeer
->SetShape(region
);
391 // TODO END move to nonowned_osx.cpp
396 IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCarbonImpl
, wxNonOwnedWindowImpl
)
399 WXWindow
wxNonOwnedWindowCarbonImpl::GetWXWindow() const
401 return (WXWindow
) m_macWindow
;
403 void wxNonOwnedWindowCarbonImpl::Raise()
405 ::SelectWindow( m_macWindow
) ;
408 void wxNonOwnedWindowCarbonImpl::Lower()
410 ::SendBehind( m_macWindow
, NULL
) ;
413 bool wxNonOwnedWindowCarbonImpl::Show(bool show
)
415 bool plainTransition
= true;
417 #if wxUSE_SYSTEM_OPTIONS
418 if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION
) )
419 plainTransition
= ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION
) == 1 ) ;
425 if ( plainTransition
)
426 ::ShowWindow( (WindowRef
)m_macWindow
);
428 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowShowTransitionAction
, NULL
);
430 ::SelectWindow( (WindowRef
)m_macWindow
) ;
436 if ( plainTransition
)
437 ::HideWindow( (WindowRef
)m_macWindow
);
439 ::TransitionWindow( (WindowRef
)m_macWindow
, kWindowZoomTransitionEffect
, kWindowHideTransitionAction
, NULL
);
445 void wxNonOwnedWindowCarbonImpl::Update()
447 HIWindowFlush(m_macWindow
) ;
450 bool wxNonOwnedWindowCarbonImpl::SetTransparent(wxByte alpha
)
452 OSStatus result
= SetWindowAlpha((WindowRef
)m_macWindow
, (CGFloat
)((alpha
)/255.0));
453 return result
== noErr
;
456 bool wxNonOwnedWindowCarbonImpl::SetBackgroundColour(const wxColour
& col
)
458 if ( col
== wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDocumentWindowBackground
)) )
460 SetThemeWindowBackground( (WindowRef
) m_macWindow
, kThemeBrushDocumentWindowBackground
, false ) ;
461 SetBackgroundStyle(wxBG_STYLE_SYSTEM
);
463 else if ( col
== wxColour(wxMacCreateCGColorFromHITheme(kThemeBrushDialogBackgroundActive
)) )
465 SetThemeWindowBackground( (WindowRef
) m_macWindow
, kThemeBrushDialogBackgroundActive
, false ) ;
466 SetBackgroundStyle(wxBG_STYLE_SYSTEM
);
471 void wxNonOwnedWindowCarbonImpl::SetExtraStyle( long exStyle
)
473 if ( m_macWindow
!= NULL
)
475 bool metal
= exStyle
& wxFRAME_EX_METAL
;
477 if ( MacGetMetalAppearance() != metal
)
479 if ( MacGetUnifiedAppearance() )
480 MacSetUnifiedAppearance( !metal
) ;
482 MacSetMetalAppearance( metal
) ;
487 bool wxNonOwnedWindowCarbonImpl::SetBackgroundStyle(wxBackgroundStyle style
)
489 if ( style
== wxBG_STYLE_TRANSPARENT
)
491 OSStatus err
= HIWindowChangeFeatures( m_macWindow
, 0, kWindowIsOpaque
);
493 err
= ReshapeCustomWindow( m_macWindow
);
500 bool wxNonOwnedWindowCarbonImpl::CanSetTransparent()
505 void wxNonOwnedWindowCarbonImpl::GetContentArea( int &left
, int &top
, int &width
, int &height
) const
507 Rect content
, structure
;
509 GetWindowBounds( m_macWindow
, kWindowStructureRgn
, &structure
) ;
510 GetWindowBounds( m_macWindow
, kWindowContentRgn
, &content
) ;
512 left
= content
.left
- structure
.left
;
513 top
= content
.top
- structure
.top
;
514 width
= content
.right
- content
.left
;
515 height
= content
.bottom
- content
.top
;
518 void wxNonOwnedWindowCarbonImpl::MoveWindow(int x
, int y
, int width
, int height
)
520 Rect bounds
= { y
, x
, y
+ height
, x
+ width
} ;
521 verify_noerr(SetWindowBounds( (WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
524 void wxNonOwnedWindowCarbonImpl::GetPosition( int &x
, int &y
) const
528 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
534 void wxNonOwnedWindowCarbonImpl::GetSize( int &width
, int &height
) const
538 verify_noerr(GetWindowBounds((WindowRef
) m_macWindow
, kWindowStructureRgn
, &bounds
)) ;
540 width
= bounds
.right
- bounds
.left
;
541 height
= bounds
.bottom
- bounds
.top
;
544 bool wxNonOwnedWindowCarbonImpl::MacGetUnifiedAppearance() const
546 return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute
;
549 void wxNonOwnedWindowCarbonImpl::MacChangeWindowAttributes( wxUint32 attributesToSet
, wxUint32 attributesToClear
)
551 ChangeWindowAttributes( m_macWindow
, attributesToSet
, attributesToClear
) ;
554 wxUint32
wxNonOwnedWindowCarbonImpl::MacGetWindowAttributes() const
557 GetWindowAttributes( m_macWindow
, &attr
) ;
561 void wxNonOwnedWindowCarbonImpl::MacSetMetalAppearance( bool set
)
563 if ( MacGetUnifiedAppearance() )
564 MacSetUnifiedAppearance( false ) ;
566 MacChangeWindowAttributes( set
? kWindowMetalAttribute
: kWindowNoAttributes
,
567 set
? kWindowNoAttributes
: kWindowMetalAttribute
) ;
570 bool wxNonOwnedWindowCarbonImpl::MacGetMetalAppearance() const
572 return MacGetWindowAttributes() & kWindowMetalAttribute
;
575 void wxNonOwnedWindowCarbonImpl::MacSetUnifiedAppearance( bool set
)
577 if ( MacGetMetalAppearance() )
578 MacSetMetalAppearance( false ) ;
580 MacChangeWindowAttributes( set
? kWindowUnifiedTitleAndToolbarAttribute
: kWindowNoAttributes
,
581 set
? kWindowNoAttributes
: kWindowUnifiedTitleAndToolbarAttribute
) ;
583 // For some reason, Tiger uses white as the background color for this appearance,
584 // while most apps using it use the typical striped background. Restore that behavior
586 // TODO: Determine if we need this on Leopard as well. (should be harmless either way,
588 m_wxPeer
->SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
) ) ;
592 // ----------------------------------------------------------------------------
594 // ----------------------------------------------------------------------------
596 static pascal long wxShapedMacWindowDef(short varCode
, WindowRef window
, SInt16 message
, SInt32 param
);
598 // ============================================================================
599 // wxNonOwnedWindow implementation
600 // ============================================================================
602 // unified title and toolbar constant - not in Tiger headers, so we duplicate it here
603 #define kWindowUnifiedTitleAndToolbarAttribute (1 << 7)
605 // ---------------------------------------------------------------------------
607 // ---------------------------------------------------------------------------
609 static const EventTypeSpec eventList
[] =
611 // TODO: remove control related event like key and mouse (except for WindowLeave events)
613 { kEventClassKeyboard
, kEventRawKeyDown
} ,
614 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
615 { kEventClassKeyboard
, kEventRawKeyUp
} ,
616 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
618 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
619 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
621 { kEventClassWindow
, kEventWindowShown
} ,
622 { kEventClassWindow
, kEventWindowActivated
} ,
623 { kEventClassWindow
, kEventWindowDeactivated
} ,
624 { kEventClassWindow
, kEventWindowBoundsChanging
} ,
625 { kEventClassWindow
, kEventWindowBoundsChanged
} ,
626 { kEventClassWindow
, kEventWindowClose
} ,
627 { kEventClassWindow
, kEventWindowGetRegion
} ,
629 // we have to catch these events on the toplevel window level,
630 // as controls don't get the raw mouse events anymore
632 { kEventClassMouse
, kEventMouseDown
} ,
633 { kEventClassMouse
, kEventMouseUp
} ,
634 { kEventClassMouse
, kEventMouseWheelMoved
} ,
635 { kEventClassMouse
, kEventMouseMoved
} ,
636 { kEventClassMouse
, kEventMouseDragged
} ,
639 static pascal OSStatus
KeyboardEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
641 OSStatus result
= eventNotHandledErr
;
642 // call DoFindFocus instead of FindFocus, because for Composite Windows(like WxGenericListCtrl)
643 // FindFocus does not return the actual focus window, but the enclosing window
644 wxWindow
* focus
= wxWindow::DoFindFocus();
646 focus
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
648 unsigned char charCode
;
656 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
659 ByteCount dataSize
= 0 ;
660 if ( GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
663 int numChars
= dataSize
/ sizeof( UniChar
) + 1;
665 UniChar
* charBuf
= buf
;
667 if ( numChars
* 2 > 4 )
668 charBuf
= new UniChar
[ numChars
] ;
669 GetEventParameter( event
, kEventParamKeyUnicodes
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
670 charBuf
[ numChars
- 1 ] = 0;
672 #if SIZEOF_WCHAR_T == 2
673 uniChar
= charBuf
[0] ;
675 wxMBConvUTF16 converter
;
676 converter
.MB2WC( uniChar
, (const char*)charBuf
, 2 ) ;
679 if ( numChars
* 2 > 4 )
684 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
685 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
686 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
687 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
689 UInt32 message
= (keyCode
<< 8) + charCode
;
690 switch ( GetEventKind( event
) )
692 case kEventRawKeyRepeat
:
693 case kEventRawKeyDown
:
695 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
696 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
697 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
698 if ( /* focus && */ wxTheApp
->MacSendKeyDownEvent(
699 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
703 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
707 case kEventRawKeyUp
:
708 if ( /* focus && */ wxTheApp
->MacSendKeyUpEvent(
709 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChar
[0] ) )
715 case kEventRawKeyModifiersChanged
:
717 wxKeyEvent
event(wxEVT_KEY_DOWN
);
719 event
.m_shiftDown
= modifiers
& shiftKey
;
720 event
.m_controlDown
= modifiers
& controlKey
;
721 event
.m_altDown
= modifiers
& optionKey
;
722 event
.m_metaDown
= modifiers
& cmdKey
;
727 event
.m_uniChar
= uniChar
[0] ;
730 event
.SetTimestamp(when
);
731 event
.SetEventObject(focus
);
733 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & controlKey
)
735 event
.m_keyCode
= WXK_CONTROL
;
736 event
.SetEventType( ( modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
737 focus
->HandleWindowEvent( event
) ;
739 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & shiftKey
)
741 event
.m_keyCode
= WXK_SHIFT
;
742 event
.SetEventType( ( modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
743 focus
->HandleWindowEvent( event
) ;
745 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & optionKey
)
747 event
.m_keyCode
= WXK_ALT
;
748 event
.SetEventType( ( modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
749 focus
->HandleWindowEvent( event
) ;
751 if ( /* focus && */ (modifiers
^ wxApp::s_lastModifiers
) & cmdKey
)
753 event
.m_keyCode
= WXK_COMMAND
;
754 event
.SetEventType( ( modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
755 focus
->HandleWindowEvent( event
) ;
758 wxApp::s_lastModifiers
= modifiers
;
769 // we don't interfere with foreign controls on our toplevel windows, therefore we always give back eventNotHandledErr
770 // for windows that we didn't create (like eg Scrollbars in a databrowser), or for controls where we did not handle the
773 // This handler can also be called from app level where data (ie target window) may be null or a non wx window
775 EventMouseButton g_lastButton
= 0 ;
776 bool g_lastButtonWasFakeRight
= false ;
778 void SetupMouseEvent( wxMouseEvent
&wxevent
, wxMacCarbonEvent
&cEvent
)
780 UInt32 modifiers
= cEvent
.GetParameter
<UInt32
>(kEventParamKeyModifiers
, typeUInt32
) ;
781 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
783 // these parameters are not given for all events
784 EventMouseButton button
= 0 ;
785 UInt32 clickCount
= 0 ;
786 UInt32 mouseChord
= 0;
788 cEvent
.GetParameter
<EventMouseButton
>( kEventParamMouseButton
, typeMouseButton
, &button
) ;
789 cEvent
.GetParameter
<UInt32
>( kEventParamClickCount
, typeUInt32
, &clickCount
) ;
790 // the chord is the state of the buttons pressed currently
791 cEvent
.GetParameter
<UInt32
>( kEventParamMouseChord
, typeUInt32
, &mouseChord
) ;
793 wxevent
.m_x
= screenMouseLocation
.h
;
794 wxevent
.m_y
= screenMouseLocation
.v
;
795 wxevent
.m_shiftDown
= modifiers
& shiftKey
;
796 wxevent
.m_controlDown
= modifiers
& controlKey
;
797 wxevent
.m_altDown
= modifiers
& optionKey
;
798 wxevent
.m_metaDown
= modifiers
& cmdKey
;
799 wxevent
.m_clickCount
= clickCount
;
800 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
802 // a control click is interpreted as a right click
803 bool thisButtonIsFakeRight
= false ;
804 if ( button
== kEventMouseButtonPrimary
&& (modifiers
& controlKey
) )
806 button
= kEventMouseButtonSecondary
;
807 thisButtonIsFakeRight
= true ;
810 // otherwise we report double clicks by connecting a left click with a ctrl-left click
811 if ( clickCount
> 1 && button
!= g_lastButton
)
814 // we must make sure that our synthetic 'right' button corresponds in
815 // mouse down, moved and mouse up, and does not deliver a right down and left up
817 if ( cEvent
.GetKind() == kEventMouseDown
)
819 g_lastButton
= button
;
820 g_lastButtonWasFakeRight
= thisButtonIsFakeRight
;
826 g_lastButtonWasFakeRight
= false ;
828 else if ( g_lastButton
== kEventMouseButtonSecondary
&& g_lastButtonWasFakeRight
)
829 button
= g_lastButton
;
831 // Adjust the chord mask to remove the primary button and add the
832 // secondary button. It is possible that the secondary button is
833 // already pressed, e.g. on a mouse connected to a laptop, but this
834 // possibility is ignored here:
835 if( thisButtonIsFakeRight
&& ( mouseChord
& 1U ) )
836 mouseChord
= ((mouseChord
& ~1U) | 2U);
839 wxevent
.m_leftDown
= true ;
841 wxevent
.m_rightDown
= true ;
843 wxevent
.m_middleDown
= true ;
845 // translate into wx types
846 switch ( cEvent
.GetKind() )
848 case kEventMouseDown
:
851 case kEventMouseButtonPrimary
:
852 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
) ;
855 case kEventMouseButtonSecondary
:
856 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
) ;
859 case kEventMouseButtonTertiary
:
860 wxevent
.SetEventType( clickCount
> 1 ? wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
) ;
871 case kEventMouseButtonPrimary
:
872 wxevent
.SetEventType( wxEVT_LEFT_UP
) ;
875 case kEventMouseButtonSecondary
:
876 wxevent
.SetEventType( wxEVT_RIGHT_UP
) ;
879 case kEventMouseButtonTertiary
:
880 wxevent
.SetEventType( wxEVT_MIDDLE_UP
) ;
888 case kEventMouseWheelMoved
:
890 wxevent
.SetEventType( wxEVT_MOUSEWHEEL
) ;
892 EventMouseWheelAxis axis
= cEvent
.GetParameter
<EventMouseWheelAxis
>(kEventParamMouseWheelAxis
, typeMouseWheelAxis
) ;
893 SInt32 delta
= cEvent
.GetParameter
<SInt32
>(kEventParamMouseWheelDelta
, typeSInt32
) ;
895 wxevent
.m_wheelRotation
= delta
;
896 wxevent
.m_wheelDelta
= 1;
897 wxevent
.m_linesPerAction
= 1;
898 if ( axis
== kEventMouseWheelAxisX
)
899 wxevent
.m_wheelAxis
= 1;
903 case kEventMouseEntered
:
904 case kEventMouseExited
:
905 case kEventMouseDragged
:
906 case kEventMouseMoved
:
907 wxevent
.SetEventType( wxEVT_MOTION
) ;
914 #define NEW_CAPTURE_HANDLING 1
917 wxMacTopLevelMouseEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
921 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
923 OSStatus result
= eventNotHandledErr
;
925 wxMacCarbonEvent
cEvent( event
) ;
927 Point screenMouseLocation
= cEvent
.GetParameter
<Point
>(kEventParamMouseLocation
) ;
928 Point windowMouseLocation
= screenMouseLocation
;
930 WindowRef window
= NULL
;
931 short windowPart
= ::FindWindow(screenMouseLocation
, &window
);
933 wxWindow
* currentMouseWindow
= NULL
;
934 ControlRef control
= NULL
;
936 #if NEW_CAPTURE_HANDLING
937 if ( wxApp::s_captureWindow
)
939 window
= (WindowRef
) wxApp::s_captureWindow
->MacGetTopLevelWindowRef() ;
940 windowPart
= inContent
;
946 QDGlobalToLocalPoint( GetWindowPort( window
), &windowMouseLocation
);
948 if ( wxApp::s_captureWindow
949 #if !NEW_CAPTURE_HANDLING
950 && wxApp::s_captureWindow
->MacGetTopLevelWindowRef() == (WXWindow
) window
&& windowPart
== inContent
954 currentMouseWindow
= wxApp::s_captureWindow
;
956 else if ( (IsWindowActive(window
) && windowPart
== inContent
) )
958 ControlPartCode part
;
959 control
= FindControlUnderMouse( windowMouseLocation
, window
, &part
) ;
960 // if there is no control below the mouse position, send the event to the toplevel window itself
963 currentMouseWindow
= (wxWindow
*) toplevelWindow
;
967 currentMouseWindow
= (wxWindow
*) wxFindWindowFromWXWidget( (WXWidget
) control
) ;
968 #ifndef __WXUNIVERSAL__
969 if ( currentMouseWindow
== NULL
&& cEvent
.GetKind() == kEventMouseMoved
)
972 // for wxToolBar to function we have to send certaint events to it
973 // instead of its children (wxToolBarTools)
975 GetSuperControl(control
, &parent
);
976 wxWindow
*wxParent
= (wxWindow
*) wxFindWindowFromWXWidget((WXWidget
) parent
) ;
977 if ( wxParent
&& wxParent
->IsKindOf( CLASSINFO( wxToolBar
) ) )
978 currentMouseWindow
= wxParent
;
984 // disabled windows must not get any input messages
985 if ( currentMouseWindow
&& !currentMouseWindow
->MacIsReallyEnabled() )
986 currentMouseWindow
= NULL
;
990 wxMouseEvent
wxevent(wxEVT_LEFT_DOWN
);
991 SetupMouseEvent( wxevent
, cEvent
) ;
993 // handle all enter / leave events
995 if ( currentMouseWindow
!= g_MacLastWindow
)
997 if ( g_MacLastWindow
)
999 wxMouseEvent
eventleave(wxevent
);
1000 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
1001 g_MacLastWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
1002 eventleave
.SetEventObject( g_MacLastWindow
) ;
1003 wxevent
.SetId( g_MacLastWindow
->GetId() ) ;
1006 wxToolTip::RelayEvent( g_MacLastWindow
, eventleave
);
1009 g_MacLastWindow
->HandleWindowEvent(eventleave
);
1012 if ( currentMouseWindow
)
1014 wxMouseEvent
evententer(wxevent
);
1015 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
1016 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
1017 evententer
.SetEventObject( currentMouseWindow
) ;
1018 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
1021 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
1024 currentMouseWindow
->HandleWindowEvent(evententer
);
1027 g_MacLastWindow
= currentMouseWindow
;
1030 if ( windowPart
== inMenuBar
)
1032 // special case menu bar, as we are having a low-level runloop we must do it ourselves
1033 if ( cEvent
.GetKind() == kEventMouseDown
)
1035 ::MenuSelect( screenMouseLocation
) ;
1040 else if ( currentMouseWindow
)
1042 wxWindow
*currentMouseWindowParent
= currentMouseWindow
->GetParent();
1044 currentMouseWindow
->ScreenToClient( &wxevent
.m_x
, &wxevent
.m_y
) ;
1046 wxevent
.SetEventObject( currentMouseWindow
) ;
1047 wxevent
.SetId( currentMouseWindow
->GetId() ) ;
1049 // make tooltips current
1052 if ( wxevent
.GetEventType() == wxEVT_MOTION
)
1053 wxToolTip::RelayEvent( currentMouseWindow
, wxevent
);
1056 if ( currentMouseWindow
->HandleWindowEvent(wxevent
) )
1058 if ((currentMouseWindowParent
!= NULL
) &&
1059 (currentMouseWindowParent
->GetChildren().Find(currentMouseWindow
) == NULL
))
1060 currentMouseWindow
= NULL
;
1066 // if the user code did _not_ handle the event, then perform the
1067 // default processing
1068 if ( wxevent
.GetEventType() == wxEVT_LEFT_DOWN
)
1070 // ... that is set focus to this window
1071 if (currentMouseWindow
->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow
)
1072 currentMouseWindow
->SetFocus();
1076 if ( cEvent
.GetKind() == kEventMouseUp
&& wxApp::s_captureWindow
)
1078 wxApp::s_captureWindow
= NULL
;
1084 wxWindow
* cursorTarget
= currentMouseWindow
;
1085 wxPoint
cursorPoint( wxevent
.m_x
, wxevent
.m_y
) ;
1087 extern wxCursor gGlobalCursor
;
1089 if (!gGlobalCursor
.IsOk())
1091 while ( cursorTarget
&& !cursorTarget
->MacSetupCursor( cursorPoint
) )
1093 cursorTarget
= cursorTarget
->GetParent() ;
1095 cursorPoint
+= cursorTarget
->GetPosition();
1100 else // currentMouseWindow == NULL
1102 // don't mess with controls we don't know about
1103 // for some reason returning eventNotHandledErr does not lead to the correct behaviour
1104 // so we try sending them the correct control directly
1105 if ( cEvent
.GetKind() == kEventMouseDown
&& toplevelWindow
&& control
)
1107 EventModifiers modifiers
= cEvent
.GetParameter
<EventModifiers
>(kEventParamKeyModifiers
, typeUInt32
) ;
1108 Point clickLocation
= windowMouseLocation
;
1111 hiPoint
.x
= clickLocation
.h
;
1112 hiPoint
.y
= clickLocation
.v
;
1113 HIViewConvertPoint( &hiPoint
, (ControlRef
) toplevelWindow
->GetHandle() , control
) ;
1114 clickLocation
.h
= (int)hiPoint
.x
;
1115 clickLocation
.v
= (int)hiPoint
.y
;
1117 HandleControlClick( control
, clickLocation
, modifiers
, (ControlActionUPP
) -1 ) ;
1125 static pascal OSStatus
1126 wxNonOwnedWindowEventHandler(EventHandlerCallRef
WXUNUSED(handler
),
1130 OSStatus result
= eventNotHandledErr
;
1132 wxMacCarbonEvent
cEvent( event
) ;
1134 // WindowRef windowRef = cEvent.GetParameter<WindowRef>(kEventParamDirectObject) ;
1135 wxNonOwnedWindow
* toplevelWindow
= data
? ((wxNonOwnedWindowImpl
*) data
)->GetWXPeer() : NULL
;
1137 switch ( GetEventKind( event
) )
1139 case kEventWindowActivated
:
1141 toplevelWindow
->MacActivate( cEvent
.GetTicks() , true) ;
1142 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, true , toplevelWindow
->GetId());
1143 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
1144 wxevent
.SetEventObject(toplevelWindow
);
1145 toplevelWindow
->HandleWindowEvent(wxevent
);
1146 // we still sending an eventNotHandledErr in order to allow for default processing
1150 case kEventWindowDeactivated
:
1152 toplevelWindow
->MacActivate(cEvent
.GetTicks() , false) ;
1153 wxActivateEvent
wxevent(wxEVT_ACTIVATE
, false , toplevelWindow
->GetId());
1154 wxevent
.SetTimestamp( cEvent
.GetTicks() ) ;
1155 wxevent
.SetEventObject(toplevelWindow
);
1156 toplevelWindow
->HandleWindowEvent(wxevent
);
1157 // we still sending an eventNotHandledErr in order to allow for default processing
1161 case kEventWindowShown
:
1162 toplevelWindow
->Refresh() ;
1166 case kEventWindowClose
:
1167 toplevelWindow
->Close() ;
1171 case kEventWindowBoundsChanged
:
1173 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
, typeUInt32
) ;
1174 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
1175 wxRect
r( newRect
.left
, newRect
.top
, newRect
.right
- newRect
.left
, newRect
.bottom
- newRect
.top
) ;
1176 if ( attributes
& kWindowBoundsChangeSizeChanged
)
1178 #ifndef __WXUNIVERSAL__
1179 // according to the other ports we handle this within the OS level
1180 // resize event, not within a wxSizeEvent
1181 wxFrame
*frame
= wxDynamicCast( toplevelWindow
, wxFrame
) ;
1184 frame
->PositionBars();
1187 wxSizeEvent
event( r
.GetSize() , toplevelWindow
->GetId() ) ;
1188 event
.SetEventObject( toplevelWindow
) ;
1190 toplevelWindow
->HandleWindowEvent(event
) ;
1191 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1194 if ( attributes
& kWindowBoundsChangeOriginChanged
)
1196 wxMoveEvent
event( r
.GetLeftTop() , toplevelWindow
->GetId() ) ;
1197 event
.SetEventObject( toplevelWindow
) ;
1198 toplevelWindow
->HandleWindowEvent(event
) ;
1205 case kEventWindowBoundsChanging
:
1207 UInt32 attributes
= cEvent
.GetParameter
<UInt32
>(kEventParamAttributes
,typeUInt32
) ;
1208 Rect newRect
= cEvent
.GetParameter
<Rect
>(kEventParamCurrentBounds
) ;
1210 if ( (attributes
& kWindowBoundsChangeSizeChanged
) || (attributes
& kWindowBoundsChangeOriginChanged
) )
1212 // all (Mac) rects are in content area coordinates, all wxRects in structure coordinates
1213 int left
, top
, right
, bottom
;
1215 toplevelWindow
->GetNonOwnedPeer()->GetContentArea(left
, top
, right
, bottom
);
1218 newRect
.left
- left
,
1220 newRect
.right
- newRect
.left
+ left
+ right
,
1221 newRect
.bottom
- newRect
.top
+ top
+ bottom
) ;
1223 // this is a EVT_SIZING not a EVT_SIZE type !
1224 wxSizeEvent
wxevent( r
, toplevelWindow
->GetId() ) ;
1225 wxevent
.SetEventObject( toplevelWindow
) ;
1226 wxRect adjustR
= r
;
1227 if ( toplevelWindow
->HandleWindowEvent(wxevent
) )
1228 adjustR
= wxevent
.GetRect() ;
1230 if ( toplevelWindow
->GetMaxWidth() != -1 && adjustR
.GetWidth() > toplevelWindow
->GetMaxWidth() )
1231 adjustR
.SetWidth( toplevelWindow
->GetMaxWidth() ) ;
1232 if ( toplevelWindow
->GetMaxHeight() != -1 && adjustR
.GetHeight() > toplevelWindow
->GetMaxHeight() )
1233 adjustR
.SetHeight( toplevelWindow
->GetMaxHeight() ) ;
1234 if ( toplevelWindow
->GetMinWidth() != -1 && adjustR
.GetWidth() < toplevelWindow
->GetMinWidth() )
1235 adjustR
.SetWidth( toplevelWindow
->GetMinWidth() ) ;
1236 if ( toplevelWindow
->GetMinHeight() != -1 && adjustR
.GetHeight() < toplevelWindow
->GetMinHeight() )
1237 adjustR
.SetHeight( toplevelWindow
->GetMinHeight() ) ;
1238 const Rect adjustedRect
= { adjustR
.y
+ top
, adjustR
.x
+ left
, adjustR
.y
+ adjustR
.height
- bottom
, adjustR
.x
+ adjustR
.width
- right
} ;
1239 if ( !EqualRect( &newRect
, &adjustedRect
) )
1240 cEvent
.SetParameter
<Rect
>( kEventParamCurrentBounds
, &adjustedRect
) ;
1241 toplevelWindow
->wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1248 case kEventWindowGetRegion
:
1250 if ( toplevelWindow
->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT
)
1252 WindowRegionCode windowRegionCode
;
1254 // Fetch the region code that is being queried
1255 GetEventParameter( event
,
1256 kEventParamWindowRegionCode
,
1257 typeWindowRegionCode
, NULL
,
1258 sizeof windowRegionCode
, NULL
,
1259 &windowRegionCode
) ;
1261 // If it is the opaque region code then set the
1262 // region to empty and return noErr to stop event
1264 if ( windowRegionCode
== kWindowOpaqueRgn
) {
1266 GetEventParameter( event
,
1267 kEventParamRgnHandle
,
1268 typeQDRgnHandle
, NULL
,
1269 sizeof region
, NULL
,
1271 SetEmptyRgn(region
) ;
1285 // mix this in from window.cpp
1286 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
1288 pascal OSStatus
wxNonOwnedEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1290 OSStatus result
= eventNotHandledErr
;
1292 switch ( GetEventClass( event
) )
1294 case kEventClassTextInput
:
1295 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
1298 case kEventClassKeyboard
:
1299 result
= KeyboardEventHandler( handler
, event
, data
) ;
1302 case kEventClassWindow
:
1303 result
= wxNonOwnedWindowEventHandler( handler
, event
, data
) ;
1306 case kEventClassMouse
:
1307 result
= wxMacTopLevelMouseEventHandler( handler
, event
, data
) ;
1317 DEFINE_ONE_SHOT_HANDLER_GETTER( wxNonOwnedEventHandler
)
1319 // ---------------------------------------------------------------------------
1320 // Support functions for shaped windows, based on Apple's CustomWindow sample at
1321 // http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm
1322 // ---------------------------------------------------------------------------
1324 static void wxShapedMacWindowGetPos(WindowRef window
, Rect
* inRect
)
1326 GetWindowPortBounds(window
, inRect
);
1327 Point pt
= { inRect
->top
,inRect
->left
};
1328 QDLocalToGlobalPoint( GetWindowPort( window
), &pt
);
1329 inRect
->bottom
+= pt
.v
- inRect
->top
;
1330 inRect
->right
+= pt
.h
- inRect
->left
;
1332 inRect
->left
= pt
.h
;
1335 static SInt32
wxShapedMacWindowGetFeatures(WindowRef
WXUNUSED(window
), SInt32 param
)
1337 /*------------------------------------------------------
1338 Define which options your custom window supports.
1339 --------------------------------------------------------*/
1340 //just enable everything for our demo
1341 *(OptionBits
*)param
=
1344 kWindowCanCollapse
|
1345 //kWindowCanGetWindowRegion |
1346 //kWindowHasTitleBar |
1347 //kWindowSupportsDragHilite |
1348 kWindowCanDrawInCurrentPort
|
1349 //kWindowCanMeasureTitle |
1350 kWindowWantsDisposeAtProcessDeath
|
1351 kWindowSupportsGetGrowImageRegion
|
1352 kWindowDefSupportsColorGrafPort
;
1357 // The content region is left as a rectangle matching the window size, this is
1358 // so the origin in the paint event, and etc. still matches what the
1359 // programmer expects.
1360 static void wxShapedMacWindowContentRegion(WindowRef window
, RgnHandle rgn
)
1363 wxNonOwnedWindow
* win
= wxNonOwnedWindow::GetFromWXWindow((WXWindow
)window
);
1367 wxShapedMacWindowGetPos( window
, &r
) ;
1368 RectRgn( rgn
, &r
) ;
1372 // The structure region is set to the shape given to the SetShape method.
1373 static void wxShapedMacWindowStructureRegion(WindowRef window
, RgnHandle rgn
)
1375 RgnHandle cachedRegion
= (RgnHandle
) GetWRefCon(window
);
1381 wxShapedMacWindowGetPos(window
, &windowRect
); // how big is the window
1382 CopyRgn(cachedRegion
, rgn
); // make a copy of our cached region
1383 OffsetRgn(rgn
, windowRect
.left
, windowRect
.top
); // position it over window
1384 //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size
1388 static SInt32
wxShapedMacWindowGetRegion(WindowRef window
, SInt32 param
)
1390 GetWindowRegionPtr rgnRec
= (GetWindowRegionPtr
)param
;
1395 switch (rgnRec
->regionCode
)
1397 case kWindowStructureRgn
:
1398 wxShapedMacWindowStructureRegion(window
, rgnRec
->winRgn
);
1401 case kWindowContentRgn
:
1402 wxShapedMacWindowContentRegion(window
, rgnRec
->winRgn
);
1406 SetEmptyRgn(rgnRec
->winRgn
);
1413 // Determine the region of the window which was hit
1415 static SInt32
wxShapedMacWindowHitTest(WindowRef window
, SInt32 param
)
1418 static RgnHandle tempRgn
= NULL
;
1420 if (tempRgn
== NULL
)
1423 // get the point clicked
1424 SetPt( &hitPoint
, LoWord(param
), HiWord(param
) );
1426 // Mac OS 8.5 or later
1427 wxShapedMacWindowStructureRegion(window
, tempRgn
);
1428 if (PtInRgn( hitPoint
, tempRgn
)) //in window content region?
1431 // no significant area was hit
1435 static pascal long wxShapedMacWindowDef(short WXUNUSED(varCode
), WindowRef window
, SInt16 message
, SInt32 param
)
1439 case kWindowMsgHitTest
:
1440 return wxShapedMacWindowHitTest(window
, param
);
1442 case kWindowMsgGetFeatures
:
1443 return wxShapedMacWindowGetFeatures(window
, param
);
1445 // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow
1446 case kWindowMsgGetRegion
:
1447 return wxShapedMacWindowGetRegion(window
, param
);
1460 wxPoint m_position
;
1462 bool m_wasResizable
;
1465 wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl()
1469 wxNonOwnedWindowCarbonImpl::wxNonOwnedWindowCarbonImpl( wxNonOwnedWindow
* nonownedwnd
) : wxNonOwnedWindowImpl( nonownedwnd
)
1471 m_macEventHandler
= NULL
;
1473 m_macFullScreenData
= NULL
;
1476 wxNonOwnedWindowCarbonImpl::~wxNonOwnedWindowCarbonImpl()
1479 wxToolTip::NotifyWindowDelete(m_macWindow
) ;
1482 if ( m_macEventHandler
)
1484 ::RemoveEventHandler((EventHandlerRef
) m_macEventHandler
);
1485 m_macEventHandler
= NULL
;
1489 DisposeWindow( m_macWindow
);
1491 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1493 m_macFullScreenData
= NULL
;
1499 void wxNonOwnedWindowCarbonImpl::Destroy()
1501 wxPendingDelete
.Append( new wxDeferredObjectDeleter( this ) ) ;
1504 void wxNonOwnedWindowInstallTopLevelWindowEventHandler(WindowRef window
, EventHandlerRef
* handler
, void *ref
)
1506 InstallWindowEventHandler(window
, GetwxNonOwnedEventHandlerUPP(),
1507 GetEventTypeCount(eventList
), eventList
, ref
, handler
);
1510 bool wxNonOwnedWindowCarbonImpl::SetShape(const wxRegion
& region
)
1512 // Make a copy of the region
1513 RgnHandle shapeRegion
= NewRgn();
1514 HIShapeGetAsQDRgn( region
.GetWXHRGN(), shapeRegion
);
1516 // Dispose of any shape region we may already have
1517 RgnHandle oldRgn
= (RgnHandle
)GetWRefCon( (WindowRef
) m_wxPeer
->GetWXWindow() );
1521 // Save the region so we can use it later
1522 SetWRefCon((WindowRef
) m_wxPeer
->GetWXWindow(), (URefCon
)shapeRegion
);
1524 // inform the window manager that the window has changed shape
1525 ReshapeCustomWindow((WindowRef
) m_wxPeer
->GetWXWindow());
1531 void wxNonOwnedWindowCarbonImpl::MacInstallTopLevelWindowEventHandler()
1533 if ( m_macEventHandler
!= NULL
)
1535 verify_noerr( ::RemoveEventHandler( (EventHandlerRef
) m_macEventHandler
) ) ;
1537 wxNonOwnedWindowInstallTopLevelWindowEventHandler(MAC_WXHWND(m_macWindow
),(EventHandlerRef
*)&m_macEventHandler
,this);
1540 void wxNonOwnedWindowCarbonImpl::Create(
1544 long style
, long extraStyle
,
1545 const wxString
& name
)
1548 OSStatus err
= noErr
;
1557 ::SetRect(&theBoundsRect
, x
, y
, x
+ w
, y
+ h
);
1559 // translate the window attributes in the appropriate window class and attributes
1560 WindowClass wclass
= 0;
1561 WindowAttributes attr
= kWindowNoAttributes
;
1562 WindowGroupRef group
= NULL
;
1563 bool activationScopeSet
= false;
1564 WindowActivationScope activationScope
= kWindowActivationScopeNone
;
1566 if ( style
& wxFRAME_TOOL_WINDOW
)
1569 ( style
& wxMINIMIZE_BOX
) || ( style
& wxMAXIMIZE_BOX
) ||
1570 ( style
& wxSYSTEM_MENU
) || ( style
& wxCAPTION
) ||
1571 ( style
&wxTINY_CAPTION_HORIZ
) || ( style
&wxTINY_CAPTION_VERT
)
1574 if ( ( style
& wxSTAY_ON_TOP
) )
1575 wclass
= kUtilityWindowClass
;
1577 wclass
= kFloatingWindowClass
;
1579 if ( ( style
&wxTINY_CAPTION_VERT
) )
1580 attr
|= kWindowSideTitlebarAttribute
;
1584 wclass
= kPlainWindowClass
;
1585 activationScopeSet
= true;
1586 activationScope
= kWindowActivationScopeNone
;
1589 else if ( ( style
& wxPOPUP_WINDOW
) )
1591 if ( ( style
& wxBORDER_NONE
) )
1593 wclass
= kHelpWindowClass
; // has no border
1594 attr
|= kWindowNoShadowAttribute
;
1598 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1600 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1601 // make sure we don't deactivate something
1602 activationScopeSet
= true;
1603 activationScope
= kWindowActivationScopeNone
;
1605 else if ( ( style
& wxCAPTION
) )
1607 wclass
= kDocumentWindowClass
;
1608 attr
|= kWindowInWindowMenuAttribute
;
1610 else if ( ( style
& wxFRAME_DRAWER
) )
1612 wclass
= kDrawerWindowClass
;
1616 if ( ( style
& wxMINIMIZE_BOX
) || ( style
& wxMAXIMIZE_BOX
) ||
1617 ( style
& wxCLOSE_BOX
) || ( style
& wxSYSTEM_MENU
) )
1619 wclass
= kDocumentWindowClass
;
1621 else if ( ( style
& wxNO_BORDER
) )
1623 wclass
= kSimpleWindowClass
;
1627 wclass
= kPlainWindowClass
;
1631 if ( wclass
!= kPlainWindowClass
)
1633 if ( ( style
& wxMINIMIZE_BOX
) )
1634 attr
|= kWindowCollapseBoxAttribute
;
1636 if ( ( style
& wxMAXIMIZE_BOX
) )
1637 attr
|= kWindowFullZoomAttribute
;
1639 if ( ( style
& wxRESIZE_BORDER
) )
1640 attr
|= kWindowResizableAttribute
;
1642 if ( ( style
& wxCLOSE_BOX
) )
1643 attr
|= kWindowCloseBoxAttribute
;
1645 attr
|= kWindowLiveResizeAttribute
;
1647 if ( ( style
&wxSTAY_ON_TOP
) )
1648 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1650 if ( ( style
& wxFRAME_FLOAT_ON_PARENT
) )
1651 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1653 if ( group
== NULL
&& parent
!= NULL
)
1655 WindowRef parenttlw
= (WindowRef
) parent
->MacGetTopLevelWindowRef();
1657 group
= GetWindowGroupParent( GetWindowGroup( parenttlw
) );
1660 attr
|= kWindowCompositingAttribute
;
1661 #if 0 // TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1662 attr
|= kWindowFrameworkScaledAttribute
;
1665 if ( ( style
&wxFRAME_SHAPED
) )
1667 WindowDefSpec customWindowDefSpec
;
1668 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1669 customWindowDefSpec
.u
.defProc
=
1671 (WindowDefUPP
) wxShapedMacWindowDef
;
1673 NewWindowDefUPP(wxShapedMacWindowDef
);
1675 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1676 attr
, &theBoundsRect
,
1677 (WindowRef
*) &m_macWindow
);
1681 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1684 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1685 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1687 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1689 // setup a separate group for each window, so that overlays can be handled easily
1691 WindowGroupRef overlaygroup
= NULL
;
1692 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &overlaygroup
));
1693 verify_noerr( SetWindowGroupParent( overlaygroup
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1694 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, overlaygroup
));
1696 if ( activationScopeSet
)
1698 verify_noerr( SetWindowActivationScope( (WindowRef
) m_macWindow
, activationScope
));
1701 // the create commands are only for content rect,
1702 // so we have to set the size again as structure bounds
1703 SetWindowBounds( m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1705 // Causes the inner part of the window not to be metal
1706 // if the style is used before window creation.
1707 #if 0 // TARGET_API_MAC_OSX
1708 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1710 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1711 MacSetMetalAppearance( true ) ;
1715 if ( m_macWindow
!= NULL
)
1717 MacSetUnifiedAppearance( true ) ;
1720 HIViewRef growBoxRef
= 0 ;
1721 err
= HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowGrowBoxID
, &growBoxRef
);
1722 if ( err
== noErr
&& growBoxRef
!= 0 )
1723 HIGrowBoxViewSetTransparent( growBoxRef
, true ) ;
1725 // the frame window event handler
1726 InstallStandardEventHandler( GetWindowEventTarget(m_macWindow
) ) ;
1727 MacInstallTopLevelWindowEventHandler() ;
1729 if ( extraStyle
& wxFRAME_EX_METAL
)
1730 MacSetMetalAppearance(true);
1732 if ( ( style
&wxFRAME_SHAPED
) )
1734 // default shape matches the window size
1735 wxRegion
rgn( 0, 0, w
, h
);
1740 bool wxNonOwnedWindowCarbonImpl::ShowWithEffect(bool show
,
1741 wxShowEffect effect
,
1744 WindowTransitionEffect transition
= 0 ;
1747 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1748 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1749 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1750 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1751 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1752 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1753 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1754 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1755 transition
= kWindowGenieTransitionEffect
;
1757 case wxSHOW_EFFECT_BLEND
:
1758 transition
= kWindowFadeTransitionEffect
;
1760 case wxSHOW_EFFECT_EXPAND
:
1761 // having sheets would be fine, but this might lead to a repositioning
1764 transition
= kWindowSheetTransitionEffect
;
1767 transition
= kWindowZoomTransitionEffect
;
1770 case wxSHOW_EFFECT_MAX
:
1771 wxFAIL_MSG( "invalid effect flag" );
1775 TransitionWindowOptions options
;
1776 options
.version
= 0;
1777 options
.duration
= timeout
/ 1000.0;
1778 options
.window
= transition
== kWindowSheetTransitionEffect
? (WindowRef
) m_wxPeer
->GetParent()->MacGetTopLevelWindowRef() :0;
1779 options
.userData
= 0;
1781 wxSize size
= wxGetDisplaySize();
1783 GetWindowBounds( (WindowRef
)m_macWindow
, kWindowStructureRgn
, &bounds
);
1784 CGRect hiBounds
= CGRectMake( bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
);
1788 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1789 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1790 hiBounds
.origin
.x
= 0;
1791 hiBounds
.size
.width
= 0;
1794 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1795 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1796 hiBounds
.origin
.x
= size
.x
;
1797 hiBounds
.size
.width
= 0;
1800 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1801 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1802 hiBounds
.origin
.y
= size
.y
;
1803 hiBounds
.size
.height
= 0;
1806 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1807 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1808 hiBounds
.origin
.y
= 0;
1809 hiBounds
.size
.height
= 0;
1813 break; // direction doesn't make sense
1816 ::TransitionWindowWithOptions
1818 (WindowRef
)m_macWindow
,
1820 show
? kWindowShowTransitionAction
: kWindowHideTransitionAction
,
1821 transition
== kWindowGenieTransitionEffect
? &hiBounds
: NULL
,
1828 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1834 void wxNonOwnedWindowCarbonImpl::SetTitle( const wxString
& title
, wxFontEncoding encoding
)
1836 SetWindowTitleWithCFString( m_macWindow
, wxCFStringRef( title
, encoding
) ) ;
1839 bool wxNonOwnedWindowCarbonImpl::IsMaximized() const
1841 return IsWindowInStandardState( m_macWindow
, NULL
, NULL
) ;
1844 bool wxNonOwnedWindowCarbonImpl::IsIconized() const
1846 return IsWindowCollapsed((WindowRef
)GetWXWindow() ) ;
1849 void wxNonOwnedWindowCarbonImpl::Iconize( bool iconize
)
1851 if ( IsWindowCollapsable( m_macWindow
) )
1852 CollapseWindow( m_macWindow
, iconize
) ;
1855 void wxNonOwnedWindowCarbonImpl::Maximize(bool maximize
)
1857 Point idealSize
= { 0 , 0 } ;
1860 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1862 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
1864 idealSize
.h
= bounds
.size
.width
;
1865 idealSize
.v
= bounds
.size
.height
;
1868 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
1869 idealSize
.h
= rect
.right
- rect
.left
;
1870 idealSize
.v
= rect
.bottom
- rect
.top
;
1873 ZoomWindowIdeal( (WindowRef
)GetWXWindow() , maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
1876 bool wxNonOwnedWindowCarbonImpl::IsFullScreen() const
1878 return m_macFullScreenData
!= NULL
;
1881 bool wxNonOwnedWindowCarbonImpl::ShowFullScreen(bool show
, long style
)
1885 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1887 data
= new FullScreenData() ;
1889 m_macFullScreenData
= data
;
1890 data
->m_position
= m_wxPeer
->GetPosition() ;
1891 data
->m_size
= m_wxPeer
->GetSize() ;
1892 #if wxOSX_USE_CARBON
1893 WindowAttributes attr
= 0;
1894 GetWindowAttributes((WindowRef
) GetWXWindow(), &attr
);
1895 data
->m_wasResizable
= attr
& kWindowResizableAttribute
;
1896 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1900 wxRect client
= wxGetClientDisplayRect() ;
1902 int left
, top
, right
, bottom
;
1910 GetContentArea( left
, top
, right
, bottom
) ;
1912 if ( style
& wxFULLSCREEN_NOCAPTION
)
1918 if ( style
& wxFULLSCREEN_NOBORDER
)
1925 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1930 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1935 m_wxPeer
->SetSize( x
, y
, w
, h
) ;
1936 if ( data
->m_wasResizable
)
1938 #if wxOSX_USE_CARBON
1939 ChangeWindowAttributes( (WindowRef
) GetWXWindow() , kWindowNoAttributes
, kWindowResizableAttribute
) ;
1943 else if ( m_macFullScreenData
!= NULL
)
1945 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1946 #if wxOSX_USE_CARBON
1948 if ( data
->m_wasResizable
)
1949 ChangeWindowAttributes( (WindowRef
) GetWXWindow() , kWindowResizableAttribute
, kWindowNoAttributes
) ;
1951 m_wxPeer
->SetPosition( data
->m_position
) ;
1952 m_wxPeer
->SetSize( data
->m_size
) ;
1955 m_macFullScreenData
= NULL
;
1961 // Attracts the users attention to this window if the application is
1962 // inactive (should be called when a background event occurs)
1964 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1967 DisposePtr( (Ptr
)ptr
) ;
1970 void wxNonOwnedWindowCarbonImpl::RequestUserAttention(int WXUNUSED(flags
))
1972 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1974 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1975 notificationRequest
->qType
= nmType
;
1976 notificationRequest
->nmMark
= 1 ;
1977 notificationRequest
->nmIcon
= 0 ;
1978 notificationRequest
->nmSound
= 0 ;
1979 notificationRequest
->nmStr
= NULL
;
1980 notificationRequest
->nmResp
= wxMacNMResponse
;
1982 verify_noerr( NMInstall( notificationRequest
) ) ;
1985 void wxNonOwnedWindowCarbonImpl::ScreenToWindow( int *x
, int *y
)
1987 HIPoint p
= CGPointMake( (x
? *x
: 0), (y
? *y
: 0) );
1988 HIViewRef contentView
;
1989 // TODO check toolbar offset
1990 HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowContentID
, &contentView
) ;
1991 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
1998 void wxNonOwnedWindowCarbonImpl::WindowToScreen( int *x
, int *y
)
2000 HIPoint p
= CGPointMake( (x
? *x
: 0), (y
? *y
: 0) );
2001 HIViewRef contentView
;
2002 // TODO check toolbar offset
2003 HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowContentID
, &contentView
) ;
2004 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
2010 #endif // wxOSX_USE_CARBON