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 if ( style
& wxNO_BORDER
)
1586 wclass
= kSimpleWindowClass
;
1590 wclass
= kPlainWindowClass
;
1592 activationScopeSet
= true;
1593 activationScope
= kWindowActivationScopeNone
;
1596 else if ( ( style
& wxPOPUP_WINDOW
) )
1598 if ( ( style
& wxBORDER_NONE
) )
1600 wclass
= kHelpWindowClass
; // has no border
1601 attr
|= kWindowNoShadowAttribute
;
1605 wclass
= kPlainWindowClass
; // has a single line border, it will have to do for now
1607 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1608 // make sure we don't deactivate something
1609 activationScopeSet
= true;
1610 activationScope
= kWindowActivationScopeNone
;
1612 else if ( ( style
& wxCAPTION
) )
1614 wclass
= kDocumentWindowClass
;
1615 attr
|= kWindowInWindowMenuAttribute
;
1617 else if ( ( style
& wxFRAME_DRAWER
) )
1619 wclass
= kDrawerWindowClass
;
1623 if ( ( style
& wxMINIMIZE_BOX
) || ( style
& wxMAXIMIZE_BOX
) ||
1624 ( style
& wxCLOSE_BOX
) || ( style
& wxSYSTEM_MENU
) )
1626 wclass
= kDocumentWindowClass
;
1628 else if ( ( style
& wxNO_BORDER
) )
1630 wclass
= kSimpleWindowClass
;
1634 wclass
= kPlainWindowClass
;
1638 if ( wclass
!= kPlainWindowClass
)
1640 if ( ( style
& wxMINIMIZE_BOX
) )
1641 attr
|= kWindowCollapseBoxAttribute
;
1643 if ( ( style
& wxMAXIMIZE_BOX
) )
1644 attr
|= kWindowFullZoomAttribute
;
1646 if ( ( style
& wxRESIZE_BORDER
) )
1647 attr
|= kWindowResizableAttribute
;
1649 if ( ( style
& wxCLOSE_BOX
) )
1650 attr
|= kWindowCloseBoxAttribute
;
1652 attr
|= kWindowLiveResizeAttribute
;
1654 if ( ( style
&wxSTAY_ON_TOP
) )
1655 group
= GetWindowGroupOfClass(kUtilityWindowClass
) ;
1657 if ( ( style
& wxFRAME_FLOAT_ON_PARENT
) )
1658 group
= GetWindowGroupOfClass(kFloatingWindowClass
) ;
1660 if ( group
== NULL
&& parent
!= NULL
)
1662 WindowRef parenttlw
= (WindowRef
) parent
->MacGetTopLevelWindowRef();
1664 group
= GetWindowGroupParent( GetWindowGroup( parenttlw
) );
1667 attr
|= kWindowCompositingAttribute
;
1668 #if 0 // TODO : decide on overall handling of high dpi screens (pixel vs userscale)
1669 attr
|= kWindowFrameworkScaledAttribute
;
1672 if ( ( style
&wxFRAME_SHAPED
) )
1674 WindowDefSpec customWindowDefSpec
;
1675 customWindowDefSpec
.defType
= kWindowDefProcPtr
;
1676 customWindowDefSpec
.u
.defProc
=
1678 (WindowDefUPP
) wxShapedMacWindowDef
;
1680 NewWindowDefUPP(wxShapedMacWindowDef
);
1682 err
= ::CreateCustomWindow( &customWindowDefSpec
, wclass
,
1683 attr
, &theBoundsRect
,
1684 (WindowRef
*) &m_macWindow
);
1688 err
= ::CreateNewWindow( wclass
, attr
, &theBoundsRect
, (WindowRef
*)&m_macWindow
) ;
1691 if ( err
== noErr
&& m_macWindow
!= NULL
&& group
!= NULL
)
1692 SetWindowGroup( (WindowRef
) m_macWindow
, group
) ;
1694 wxCHECK_RET( err
== noErr
, wxT("Mac OS error when trying to create new window") );
1696 // setup a separate group for each window, so that overlays can be handled easily
1698 WindowGroupRef overlaygroup
= NULL
;
1699 verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether
| kWindowGroupAttrLayerTogether
| kWindowGroupAttrHideOnCollapse
, &overlaygroup
));
1700 verify_noerr( SetWindowGroupParent( overlaygroup
, GetWindowGroup( (WindowRef
) m_macWindow
)));
1701 verify_noerr( SetWindowGroup( (WindowRef
) m_macWindow
, overlaygroup
));
1703 if ( activationScopeSet
)
1705 verify_noerr( SetWindowActivationScope( (WindowRef
) m_macWindow
, activationScope
));
1708 // the create commands are only for content rect,
1709 // so we have to set the size again as structure bounds
1710 SetWindowBounds( m_macWindow
, kWindowStructureRgn
, &theBoundsRect
) ;
1712 // Causes the inner part of the window not to be metal
1713 // if the style is used before window creation.
1714 #if 0 // TARGET_API_MAC_OSX
1715 if ( m_macUsesCompositing
&& m_macWindow
!= NULL
)
1717 if ( GetExtraStyle() & wxFRAME_EX_METAL
)
1718 MacSetMetalAppearance( true ) ;
1722 if ( m_macWindow
!= NULL
)
1724 MacSetUnifiedAppearance( true ) ;
1727 HIViewRef growBoxRef
= 0 ;
1728 err
= HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowGrowBoxID
, &growBoxRef
);
1729 if ( err
== noErr
&& growBoxRef
!= 0 )
1730 HIGrowBoxViewSetTransparent( growBoxRef
, true ) ;
1732 // the frame window event handler
1733 InstallStandardEventHandler( GetWindowEventTarget(m_macWindow
) ) ;
1734 MacInstallTopLevelWindowEventHandler() ;
1736 if ( extraStyle
& wxFRAME_EX_METAL
)
1737 MacSetMetalAppearance(true);
1739 if ( ( style
&wxFRAME_SHAPED
) )
1741 // default shape matches the window size
1742 wxRegion
rgn( 0, 0, w
, h
);
1747 bool wxNonOwnedWindowCarbonImpl::ShowWithEffect(bool show
,
1748 wxShowEffect effect
,
1751 WindowTransitionEffect transition
= 0 ;
1754 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1755 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1756 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1757 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1758 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1759 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1760 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1761 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1762 transition
= kWindowGenieTransitionEffect
;
1764 case wxSHOW_EFFECT_BLEND
:
1765 transition
= kWindowFadeTransitionEffect
;
1767 case wxSHOW_EFFECT_EXPAND
:
1768 // having sheets would be fine, but this might lead to a repositioning
1771 transition
= kWindowSheetTransitionEffect
;
1774 transition
= kWindowZoomTransitionEffect
;
1777 case wxSHOW_EFFECT_MAX
:
1778 wxFAIL_MSG( "invalid effect flag" );
1782 TransitionWindowOptions options
;
1783 options
.version
= 0;
1784 options
.duration
= timeout
/ 1000.0;
1785 options
.window
= transition
== kWindowSheetTransitionEffect
? (WindowRef
) m_wxPeer
->GetParent()->MacGetTopLevelWindowRef() :0;
1786 options
.userData
= 0;
1788 wxSize size
= wxGetDisplaySize();
1790 GetWindowBounds( (WindowRef
)m_macWindow
, kWindowStructureRgn
, &bounds
);
1791 CGRect hiBounds
= CGRectMake( bounds
.left
, bounds
.top
, bounds
.right
- bounds
.left
, bounds
.bottom
- bounds
.top
);
1795 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
1796 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
1797 hiBounds
.origin
.x
= 0;
1798 hiBounds
.size
.width
= 0;
1801 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
1802 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
1803 hiBounds
.origin
.x
= size
.x
;
1804 hiBounds
.size
.width
= 0;
1807 case wxSHOW_EFFECT_ROLL_TO_TOP
:
1808 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
1809 hiBounds
.origin
.y
= size
.y
;
1810 hiBounds
.size
.height
= 0;
1813 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
1814 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
1815 hiBounds
.origin
.y
= 0;
1816 hiBounds
.size
.height
= 0;
1820 break; // direction doesn't make sense
1823 ::TransitionWindowWithOptions
1825 (WindowRef
)m_macWindow
,
1827 show
? kWindowShowTransitionAction
: kWindowHideTransitionAction
,
1828 transition
== kWindowGenieTransitionEffect
? &hiBounds
: NULL
,
1835 ::SelectWindow( (WindowRef
)m_macWindow
) ;
1841 void wxNonOwnedWindowCarbonImpl::SetTitle( const wxString
& title
, wxFontEncoding encoding
)
1843 SetWindowTitleWithCFString( m_macWindow
, wxCFStringRef( title
, encoding
) ) ;
1846 bool wxNonOwnedWindowCarbonImpl::IsMaximized() const
1848 return IsWindowInStandardState( m_macWindow
, NULL
, NULL
) ;
1851 bool wxNonOwnedWindowCarbonImpl::IsIconized() const
1853 return IsWindowCollapsed((WindowRef
)GetWXWindow() ) ;
1856 void wxNonOwnedWindowCarbonImpl::Iconize( bool iconize
)
1858 if ( IsWindowCollapsable( m_macWindow
) )
1859 CollapseWindow( m_macWindow
, iconize
) ;
1862 void wxNonOwnedWindowCarbonImpl::Maximize(bool maximize
)
1864 Point idealSize
= { 0 , 0 } ;
1867 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
1869 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
1871 idealSize
.h
= bounds
.size
.width
;
1872 idealSize
.v
= bounds
.size
.height
;
1875 GetAvailableWindowPositioningBounds(GetMainDevice(),&rect
) ;
1876 idealSize
.h
= rect
.right
- rect
.left
;
1877 idealSize
.v
= rect
.bottom
- rect
.top
;
1880 ZoomWindowIdeal( (WindowRef
)GetWXWindow() , maximize
? inZoomOut
: inZoomIn
, &idealSize
) ;
1883 bool wxNonOwnedWindowCarbonImpl::IsFullScreen() const
1885 return m_macFullScreenData
!= NULL
;
1888 bool wxNonOwnedWindowCarbonImpl::ShowFullScreen(bool show
, long style
)
1892 FullScreenData
*data
= (FullScreenData
*)m_macFullScreenData
;
1894 data
= new FullScreenData() ;
1896 m_macFullScreenData
= data
;
1897 data
->m_position
= m_wxPeer
->GetPosition() ;
1898 data
->m_size
= m_wxPeer
->GetSize() ;
1899 #if wxOSX_USE_CARBON
1900 WindowAttributes attr
= 0;
1901 GetWindowAttributes((WindowRef
) GetWXWindow(), &attr
);
1902 data
->m_wasResizable
= attr
& kWindowResizableAttribute
;
1903 if ( style
& wxFULLSCREEN_NOMENUBAR
)
1907 wxRect client
= wxGetClientDisplayRect() ;
1909 int left
, top
, right
, bottom
;
1917 GetContentArea( left
, top
, right
, bottom
) ;
1919 if ( style
& wxFULLSCREEN_NOCAPTION
)
1925 if ( style
& wxFULLSCREEN_NOBORDER
)
1932 if ( style
& wxFULLSCREEN_NOTOOLBAR
)
1937 if ( style
& wxFULLSCREEN_NOSTATUSBAR
)
1942 m_wxPeer
->SetSize( x
, y
, w
, h
) ;
1943 if ( data
->m_wasResizable
)
1945 #if wxOSX_USE_CARBON
1946 ChangeWindowAttributes( (WindowRef
) GetWXWindow() , kWindowNoAttributes
, kWindowResizableAttribute
) ;
1950 else if ( m_macFullScreenData
!= NULL
)
1952 FullScreenData
*data
= (FullScreenData
*) m_macFullScreenData
;
1953 #if wxOSX_USE_CARBON
1955 if ( data
->m_wasResizable
)
1956 ChangeWindowAttributes( (WindowRef
) GetWXWindow() , kWindowResizableAttribute
, kWindowNoAttributes
) ;
1958 m_wxPeer
->SetPosition( data
->m_position
) ;
1959 m_wxPeer
->SetSize( data
->m_size
) ;
1962 m_macFullScreenData
= NULL
;
1968 // Attracts the users attention to this window if the application is
1969 // inactive (should be called when a background event occurs)
1971 static pascal void wxMacNMResponse( NMRecPtr ptr
)
1974 DisposePtr( (Ptr
)ptr
) ;
1977 void wxNonOwnedWindowCarbonImpl::RequestUserAttention(int WXUNUSED(flags
))
1979 NMRecPtr notificationRequest
= (NMRecPtr
) NewPtr( sizeof( NMRec
) ) ;
1981 memset( notificationRequest
, 0 , sizeof(*notificationRequest
) ) ;
1982 notificationRequest
->qType
= nmType
;
1983 notificationRequest
->nmMark
= 1 ;
1984 notificationRequest
->nmIcon
= 0 ;
1985 notificationRequest
->nmSound
= 0 ;
1986 notificationRequest
->nmStr
= NULL
;
1987 notificationRequest
->nmResp
= wxMacNMResponse
;
1989 verify_noerr( NMInstall( notificationRequest
) ) ;
1992 void wxNonOwnedWindowCarbonImpl::ScreenToWindow( int *x
, int *y
)
1994 HIPoint p
= CGPointMake( (x
? *x
: 0), (y
? *y
: 0) );
1995 HIViewRef contentView
;
1996 // TODO check toolbar offset
1997 HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowContentID
, &contentView
) ;
1998 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
2005 void wxNonOwnedWindowCarbonImpl::WindowToScreen( int *x
, int *y
)
2007 HIPoint p
= CGPointMake( (x
? *x
: 0), (y
? *y
: 0) );
2008 HIViewRef contentView
;
2009 // TODO check toolbar offset
2010 HIViewFindByID( HIViewGetRoot( m_macWindow
), kHIViewWindowContentID
, &contentView
) ;
2011 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
2017 #endif // wxOSX_USE_CARBON