1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/window_osx.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/window.h"
23 #include "wx/dcclient.h"
24 #include "wx/button.h"
26 #include "wx/dialog.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
29 #include "wx/scrolbar.h"
30 #include "wx/statbox.h"
31 #include "wx/textctrl.h"
32 #include "wx/toolbar.h"
33 #include "wx/layout.h"
34 #include "wx/statusbr.h"
35 #include "wx/menuitem.h"
36 #include "wx/treectrl.h"
37 #include "wx/listctrl.h"
40 #include "wx/tooltip.h"
41 #include "wx/spinctrl.h"
42 #include "wx/geometry.h"
45 #include "wx/listctrl.h"
49 #include "wx/treectrl.h"
57 #include "wx/popupwin.h"
60 #if wxUSE_DRAG_AND_DROP
64 #include "wx/graphics.h"
67 #include "wx/osx/uma.h"
69 #include "wx/osx/private.h"
72 #define MAC_SCROLLBAR_SIZE 15
73 #define MAC_SMALL_SCROLLBAR_SIZE 11
77 #ifdef __WXUNIVERSAL__
78 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
81 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
82 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
85 #define wxMAC_DEBUG_REDRAW 0
86 #ifndef wxMAC_DEBUG_REDRAW
87 #define wxMAC_DEBUG_REDRAW 0
90 wxWidgetImplType
* kOSXNoWidgetImpl
= (wxWidgetImplType
*) -1L;
92 #if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
100 wxVector
<wxHotKeyRec
> s_hotkeys
;
104 // ===========================================================================
106 // ===========================================================================
108 // the grow box has to be implemented as an inactive window, so that nothing can direct
111 class WXDLLIMPEXP_CORE wxBlindPlateWindow
: public wxWindow
114 wxBlindPlateWindow() { Init(); }
116 // Old-style constructor (no default values for coordinates to avoid
117 // ambiguity with the new one)
118 wxBlindPlateWindow(wxWindow
*parent
,
119 int x
, int y
, int width
, int height
,
120 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
121 const wxString
& name
= wxPanelNameStr
)
125 Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(width
, height
), style
, name
);
129 wxBlindPlateWindow(wxWindow
*parent
,
130 wxWindowID winid
= wxID_ANY
,
131 const wxPoint
& pos
= wxDefaultPosition
,
132 const wxSize
& size
= wxDefaultSize
,
133 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
134 const wxString
& name
= wxPanelNameStr
)
138 Create(parent
, winid
, pos
, size
, style
, name
);
142 bool Create(wxWindow
*parent
,
143 wxWindowID winid
= wxID_ANY
,
144 const wxPoint
& pos
= wxDefaultPosition
,
145 const wxSize
& size
= wxDefaultSize
,
146 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
147 const wxString
& name
= wxPanelNameStr
)
149 if ( !wxWindow::Create(parent
, winid
, pos
, size
, style
, name
) )
152 // so that non-solid background renders correctly under GTK+:
153 SetThemeEnabled(true);
157 virtual ~wxBlindPlateWindow();
159 virtual bool AcceptsFocus() const
165 // common part of all ctors
170 DECLARE_DYNAMIC_CLASS_NO_COPY(wxBlindPlateWindow
)
171 DECLARE_EVENT_TABLE()
174 wxBlindPlateWindow::~wxBlindPlateWindow()
178 IMPLEMENT_DYNAMIC_CLASS(wxBlindPlateWindow
, wxWindow
)
180 BEGIN_EVENT_TABLE(wxBlindPlateWindow
, wxWindow
)
184 // ----------------------------------------------------------------------------
185 // constructors and such
186 // ----------------------------------------------------------------------------
188 wxWindowMac::wxWindowMac()
193 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
198 const wxString
& name
)
201 Create(parent
, id
, pos
, size
, style
, name
);
204 void wxWindowMac::Init()
208 m_cgContextRef
= NULL
;
210 // as all windows are created with WS_VISIBLE style...
213 m_hScrollBar
= NULL
;
214 m_vScrollBar
= NULL
;
215 m_hScrollBarAlwaysShown
= false;
216 m_vScrollBarAlwaysShown
= false;
219 m_clipChildren
= false ;
220 m_cachedClippedRectValid
= false ;
221 m_isNativeWindowWrapper
= false;
224 wxWindowMac::~wxWindowMac()
228 #if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
229 for ( int i
= s_hotkeys
.size()-1; i
>=0; -- i
)
231 if ( s_hotkeys
[i
].window
== this )
233 EventHotKeyRef ref
= s_hotkeys
[i
].ref
;
234 s_hotkeys
.erase(s_hotkeys
.begin() + i
);
235 if ( UnregisterEventHotKey(ref
) != noErr
)
237 wxLogLastError(wxT("UnregisterHotKey"));
243 MacInvalidateBorders() ;
245 #ifndef __WXUNIVERSAL__
246 // VS: make sure there's no wxFrame with last focus set to us:
247 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
249 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
252 if ( frame
->GetLastFocus() == this )
253 frame
->SetLastFocus(NULL
);
259 // destroy children before destroying this window itself
262 // wxRemoveMacControlAssociation( this ) ;
263 // If we delete an item, we should initialize the parent panel,
264 // because it could now be invalid.
265 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this), wxTopLevelWindow
);
268 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
269 tlw
->SetDefaultItem(NULL
);
272 if ( g_MacLastWindow
== this )
273 g_MacLastWindow
= NULL
;
275 #ifndef __WXUNIVERSAL__
276 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
279 if ( frame
->GetLastFocus() == this )
280 frame
->SetLastFocus( NULL
) ;
284 // delete our drop target if we've got one
285 #if wxUSE_DRAG_AND_DROP
286 wxDELETE(m_dropTarget
);
292 WXWidget
wxWindowMac::GetHandle() const
295 return (WXWidget
) GetPeer()->GetWXWidget() ;
299 wxOSXWidgetImpl
* wxWindowMac::GetPeer() const
301 return m_peer
== kOSXNoWidgetImpl
? NULL
: m_peer
;
304 void wxWindowMac::DontCreatePeer()
306 m_peer
= kOSXNoWidgetImpl
;
309 void wxWindowMac::SetWrappingPeer(wxOSXWidgetImpl
* wrapper
)
311 wxOSXWidgetImpl
* inner
= GetPeer();
312 wxASSERT_MSG( inner
!= NULL
&& inner
->IsOk(), "missing or incomplete inner peer" );
313 wxASSERT_MSG( wrapper
!= NULL
&& wrapper
->IsOk(), "missing or incomplete wrapper" );
315 if ( !(inner
!= NULL
&& inner
->IsOk() && wrapper
!= NULL
&& wrapper
->IsOk()) )
318 inner
->RemoveFromParent();
319 wrapper
->InstallEventHandler();
320 wrapper
->Embed(inner
);
324 void wxWindowMac::SetPeer(wxOSXWidgetImpl
* peer
)
328 if ( !GetPeer()->IsRootControl() )
329 GetPeer()->RemoveFromParent();
335 if ( GetPeer() && !GetPeer()->IsRootControl())
337 wxASSERT_MSG( GetPeer()->IsOk() , wxT("The native control must exist already") ) ;
339 if (!GetParent()->GetChildren().Find((wxWindow
*)this))
340 GetParent()->AddChild( this );
342 GetPeer()->InstallEventHandler();
343 GetPeer()->Embed(GetParent()->GetPeer());
345 GetParent()->MacChildAdded() ;
347 // adjust font, controlsize etc
348 DoSetWindowVariant( m_windowVariant
) ;
350 GetPeer()->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
352 // for controls we want to use best size for wxDefaultSize params )
353 if ( !GetPeer()->IsUserPane() )
354 SetInitialSize(GetMinSize());
356 SetCursor( *wxSTANDARD_CURSOR
) ;
360 #if WXWIN_COMPATIBILITY_2_8
362 bool wxWindowMac::MacIsUserPane()
364 return GetPeer() == NULL
|| GetPeer()->IsUserPane();
369 bool wxWindowMac::MacIsUserPane() const
371 return GetPeer() == NULL
|| GetPeer()->IsUserPane();
374 // ---------------------------------------------------------------------------
375 // Utility Routines to move between different coordinate systems
376 // ---------------------------------------------------------------------------
379 * Right now we have the following setup :
380 * a border that is not part of the native control is always outside the
381 * control's border (otherwise we loose all native intelligence, future ways
382 * may be to have a second embedding control responsible for drawing borders
383 * and backgrounds eventually)
384 * so all this border calculations have to be taken into account when calling
385 * native methods or getting native oriented data
386 * so we have three coordinate systems here
387 * wx client coordinates
388 * wx window coordinates (including window frames)
396 bool wxWindowMac::Create(wxWindowMac
*parent
,
401 const wxString
& name
)
403 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
405 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
408 m_windowVariant
= parent
->GetWindowVariant() ;
410 if ( m_peer
!= kOSXNoWidgetImpl
)
412 SetPeer(wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() ));
413 MacPostControlCreate(pos
, size
) ;
416 #ifndef __WXUNIVERSAL__
417 // Don't give scrollbars to wxControls unless they ask for them
418 if ( (! IsKindOf(CLASSINFO(wxControl
))
420 && ! IsKindOf(CLASSINFO(wxStatusBar
))
423 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
425 MacCreateScrollBars( style
) ;
429 wxWindowCreateEvent
event((wxWindow
*)this);
430 GetEventHandler()->AddPendingEvent(event
);
435 void wxWindowMac::MacChildAdded()
439 m_vScrollBar
->Raise() ;
441 m_hScrollBar
->Raise() ;
447 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
),
448 const wxSize
& WXUNUSED(size
))
450 // todo remove if refactoring works correctly
452 wxASSERT_MSG( GetPeer() != NULL
&& GetPeer()->IsOk() , wxT("No valid mac control") ) ;
454 if (!GetParent()->GetChildren().Find((wxWindow
*)this))
455 GetParent()->AddChild( this );
457 GetPeer()->InstallEventHandler();
458 GetPeer()->Embed(GetParent()->GetPeer());
460 GetParent()->MacChildAdded() ;
462 // adjust font, controlsize etc
463 DoSetWindowVariant( m_windowVariant
) ;
465 GetPeer()->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
467 // for controls we want to use best size for wxDefaultSize params )
468 if ( !GetPeer()->IsUserPane() )
469 SetInitialSize(size
);
471 SetCursor( *wxSTANDARD_CURSOR
) ;
475 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
477 // Don't assert, in case we set the window variant before
478 // the window is created
479 // wxASSERT( GetPeer()->IsOk() ) ;
481 m_windowVariant
= variant
;
483 if (GetPeer() == NULL
|| !GetPeer()->IsOk())
486 GetPeer()->SetControlSize( variant
);
490 // we will get that from the settings later
491 // and make this NORMAL later, but first
492 // we have a few calculations that we must fix
496 case wxWINDOW_VARIANT_NORMAL
:
497 size
= kControlSizeNormal
;
500 case wxWINDOW_VARIANT_SMALL
:
501 size
= kControlSizeSmall
;
504 case wxWINDOW_VARIANT_MINI
:
505 // not always defined in the headers
509 case wxWINDOW_VARIANT_LARGE
:
510 size
= kControlSizeLarge
;
514 wxFAIL_MSG(wxT("unexpected window variant"));
517 GetPeer()->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
523 case wxWINDOW_VARIANT_NORMAL
:
524 static wxFont
sysNormal(wxOSX_SYSTEM_FONT_NORMAL
);
528 case wxWINDOW_VARIANT_SMALL
:
529 static wxFont
sysSmall(wxOSX_SYSTEM_FONT_SMALL
);
533 case wxWINDOW_VARIANT_MINI
:
534 static wxFont
sysMini(wxOSX_SYSTEM_FONT_MINI
);
538 case wxWINDOW_VARIANT_LARGE
:
539 static wxFont
sysLarge(wxOSX_SYSTEM_FONT_NORMAL
);
544 wxFAIL_MSG(wxT("unexpected window variant"));
549 void wxWindowMac::MacUpdateControlFont()
552 GetPeer()->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
554 // do not trigger refreshes upon invisible and possible partly created objects
555 if ( IsShownOnScreen() )
559 bool wxWindowMac::SetFont(const wxFont
& font
)
561 bool retval
= wxWindowBase::SetFont( font
);
563 MacUpdateControlFont() ;
568 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
570 bool retval
= wxWindowBase::SetForegroundColour( col
);
573 MacUpdateControlFont();
578 bool wxWindowMac::SetBackgroundStyle(wxBackgroundStyle style
)
580 if ( !wxWindowBase::SetBackgroundStyle(style
) )
584 GetPeer()->SetBackgroundStyle(style
);
588 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
592 if ( m_backgroundColour
.IsOk() )
593 m_growBox
->SetBackgroundColour(m_backgroundColour
);
595 m_growBox
->SetBackgroundColour(*wxWHITE
);
598 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
602 GetPeer()->SetBackgroundColour( col
) ;
607 static bool wxIsWindowOrParentDisabled(wxWindow
* w
)
609 while (w
&& !w
->IsTopLevel())
618 void wxWindowMac::SetFocus()
620 if ( !AcceptsFocus() )
623 if (wxIsWindowOrParentDisabled((wxWindow
*) this))
626 wxWindow
* former
= FindFocus() ;
627 if ( former
== this )
630 GetPeer()->SetFocus() ;
633 void wxWindowMac::DoCaptureMouse()
635 wxApp::s_captureWindow
= (wxWindow
*) this ;
636 GetPeer()->CaptureMouse() ;
639 wxWindow
* wxWindowBase::GetCapture()
641 return wxApp::s_captureWindow
;
644 void wxWindowMac::DoReleaseMouse()
646 wxApp::s_captureWindow
= NULL
;
648 GetPeer()->ReleaseMouse() ;
651 #if wxUSE_DRAG_AND_DROP
653 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
657 m_dropTarget
= pDropTarget
;
659 GetPeer()->SetDropTarget(m_dropTarget
) ;
664 // Old-style File Manager Drag & Drop
665 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
670 // From a wx position / size calculate the appropriate size of the native control
672 bool wxWindowMac::MacGetBoundsForControl(
676 int& w
, int& h
, bool adjustOrigin
) const
678 // the desired size, minus the border pixels gives the correct size of the control
682 w
= WidthDefault( size
.x
);
683 h
= HeightDefault( size
.y
);
685 x
+= MacGetLeftBorderSize() ;
686 y
+= MacGetTopBorderSize() ;
687 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
688 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
691 AdjustForParentClientOrigin( x
, y
) ;
693 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
694 if ( GetParent() && !GetParent()->IsTopLevel() )
696 x
-= GetParent()->MacGetLeftBorderSize() ;
697 y
-= GetParent()->MacGetTopBorderSize() ;
703 // Get window size (not client size)
704 void wxWindowMac::DoGetSize(int *x
, int *y
) const
707 GetPeer()->GetSize( width
, height
);
710 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
712 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
715 // get the position of the bounds of this window in client coordinates of its parent
716 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
720 GetPeer()->GetPosition( x1
, y1
) ;
722 // get the wx window position from the native one
723 x1
-= MacGetLeftBorderSize() ;
724 y1
-= MacGetTopBorderSize() ;
728 wxWindow
*parent
= GetParent();
731 // we must first adjust it to be in window coordinates of the parent,
732 // as otherwise it gets lost by the ClientAreaOrigin fix
733 x1
+= parent
->MacGetLeftBorderSize() ;
734 y1
+= parent
->MacGetTopBorderSize() ;
736 // and now to client coordinates
737 wxPoint
pt(parent
->GetClientAreaOrigin());
749 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
751 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
752 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
753 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
754 MacRootWindowToWindow( x
, y
) ;
756 wxPoint origin
= GetClientAreaOrigin() ;
763 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
765 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
766 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
768 wxPoint origin
= GetClientAreaOrigin() ;
774 MacWindowToRootWindow( x
, y
) ;
775 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
778 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
780 wxPoint origin
= GetClientAreaOrigin() ;
786 MacWindowToRootWindow( x
, y
) ;
789 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
800 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
803 pt
.x
-= MacGetLeftBorderSize() ;
804 pt
.y
-= MacGetTopBorderSize() ;
805 wxWidgetImpl::Convert( &pt
, GetPeer() , top
->GetPeer() ) ;
815 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
826 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
829 wxWidgetImpl::Convert( &pt
, top
->GetPeer() , GetPeer() ) ;
830 pt
.x
+= MacGetLeftBorderSize() ;
831 pt
.y
+= MacGetTopBorderSize() ;
841 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
843 wxSize sizeTotal
= size
;
845 int innerwidth
, innerheight
;
847 int outerwidth
, outerheight
;
849 GetPeer()->GetContentArea( left
, top
, innerwidth
, innerheight
);
850 GetPeer()->GetSize( outerwidth
, outerheight
);
852 sizeTotal
.x
+= outerwidth
-innerwidth
;
853 sizeTotal
.y
+= outerheight
-innerheight
;
855 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
856 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
861 // Get size *available for subwindows* i.e. excluding menu bar etc.
862 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
868 GetPeer()->GetContentArea( left
, top
, ww
, hh
);
870 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
871 hh
-= m_hScrollBar
->GetSize().y
;
873 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
874 ww
-= m_vScrollBar
->GetSize().x
;
883 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
885 if (m_cursor
.IsSameAs(cursor
))
890 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
895 if ( ! wxWindowBase::SetCursor( cursor
) )
899 wxASSERT_MSG( m_cursor
.IsOk(),
900 wxT("cursor must be valid after call to the base version"));
902 if ( GetPeer() != NULL
)
903 GetPeer()->SetCursor( m_cursor
);
909 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
911 #ifndef __WXUNIVERSAL__
914 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
916 wxPoint mouse
= wxGetMousePosition();
922 ClientToScreen( &x
, &y
) ;
924 menu
->GetPeer()->PopUp(this, x
, y
);
927 // actually this shouldn't be called, because universal is having its own implementation
933 // ----------------------------------------------------------------------------
935 // ----------------------------------------------------------------------------
939 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
941 wxWindowBase::DoSetToolTip(tooltip
);
944 m_tooltip
->SetWindow(this);
947 GetPeer()->SetToolTip(tooltip
);
952 void wxWindowMac::MacInvalidateBorders()
954 if ( GetPeer() == NULL
)
957 bool vis
= IsShownOnScreen() ;
961 int outerBorder
= MacGetLeftBorderSize() ;
963 if ( GetPeer()->NeedsFocusRect() )
966 if ( outerBorder
== 0 )
969 // now we know that we have something to do at all
973 GetPeer()->GetSize( tw
, th
);
974 GetPeer()->GetPosition( tx
, ty
);
976 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
977 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
978 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
979 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
982 GetParent()->GetPeer()->SetNeedsDisplay(&leftupdate
);
983 GetParent()->GetPeer()->SetNeedsDisplay(&rightupdate
);
984 GetParent()->GetPeer()->SetNeedsDisplay(&topupdate
);
985 GetParent()->GetPeer()->SetNeedsDisplay(&bottomupdate
);
989 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
991 // this is never called for a toplevel window, so we know we have a parent
992 int former_x
, former_y
, former_w
, former_h
;
994 // Get true coordinates of former position
995 DoGetPosition( &former_x
, &former_y
) ;
996 DoGetSize( &former_w
, &former_h
) ;
998 wxWindow
*parent
= GetParent();
1001 wxPoint
pt(parent
->GetClientAreaOrigin());
1006 int actualWidth
= width
;
1007 int actualHeight
= height
;
1012 // min and max sizes are only for sizers, not for explicit size setting
1013 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1014 actualWidth
= m_minWidth
;
1015 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1016 actualHeight
= m_minHeight
;
1017 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1018 actualWidth
= m_maxWidth
;
1019 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1020 actualHeight
= m_maxHeight
;
1023 bool doMove
= false, doResize
= false ;
1025 if ( actualX
!= former_x
|| actualY
!= former_y
)
1028 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1031 if ( doMove
|| doResize
)
1033 // as the borders are drawn outside the native control, we adjust now
1035 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1036 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1037 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1039 if ( parent
&& !parent
->IsTopLevel() )
1041 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
1044 MacInvalidateBorders() ;
1046 m_cachedClippedRectValid
= false ;
1048 GetPeer()->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
1050 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1052 MacInvalidateBorders() ;
1054 MacRepositionScrollBars() ;
1057 wxPoint
point(actualX
, actualY
);
1058 wxMoveEvent
event(point
, m_windowId
);
1059 event
.SetEventObject(this);
1060 HandleWindowEvent(event
) ;
1065 MacRepositionScrollBars() ;
1066 MacOnInternalSize();
1067 wxSize
size(actualWidth
, actualHeight
);
1068 wxSizeEvent
event(size
, m_windowId
);
1069 event
.SetEventObject(this);
1070 HandleWindowEvent(event
);
1075 wxSize
wxWindowMac::DoGetBestSize() const
1077 if ( GetPeer() == NULL
|| GetPeer()->IsUserPane() || IsTopLevel() )
1079 return wxWindowBase::DoGetBestSize() ;
1085 GetPeer()->GetBestRect(&r
);
1087 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
1095 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1102 if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1109 // return wxWindowBase::DoGetBestSize() ;
1113 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
1114 MacGetRightBorderSize();
1115 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
1116 MacGetBottomBorderSize();
1117 if ( bestHeight
< 10 )
1120 return wxSize(bestWidth
, bestHeight
);
1124 // set the size of the window: if the dimensions are positive, just use them,
1125 // but if any of them is equal to -1, it means that we must find the value for
1126 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1127 // which case -1 is a valid value for x and y)
1129 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1130 // the width/height to best suit our contents, otherwise we reuse the current
1132 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1134 // get the current size and position...
1135 int currentX
, currentY
;
1136 int currentW
, currentH
;
1138 GetPosition(¤tX
, ¤tY
);
1139 GetSize(¤tW
, ¤tH
);
1141 // ... and don't do anything (avoiding flicker) if it's already ok
1142 if ( x
== currentX
&& y
== currentY
&&
1143 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1146 MacRepositionScrollBars() ; // we might have a real position shift
1148 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
1150 MacOnInternalSize();
1151 wxSizeEvent
event( wxSize(width
,height
), GetId() );
1152 event
.SetEventObject( this );
1153 HandleWindowEvent( event
);
1159 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1161 if ( x
== wxDefaultCoord
)
1163 if ( y
== wxDefaultCoord
)
1167 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1169 wxSize size
= wxDefaultSize
;
1170 if ( width
== wxDefaultCoord
)
1172 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1174 size
= DoGetBestSize();
1179 // just take the current one
1184 if ( height
== wxDefaultCoord
)
1186 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1188 if ( size
.x
== wxDefaultCoord
)
1189 size
= DoGetBestSize();
1190 // else: already called DoGetBestSize() above
1196 // just take the current one
1201 DoMoveWindow( x
, y
, width
, height
);
1204 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1206 int left
,top
,width
,height
;
1207 GetPeer()->GetContentArea( left
, top
, width
, height
);
1208 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1211 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1213 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1215 int currentclientwidth
, currentclientheight
;
1216 int currentwidth
, currentheight
;
1218 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1219 GetSize( ¤twidth
, ¤theight
) ;
1221 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1222 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1226 float wxWindowMac::GetContentScaleFactor() const
1228 return GetPeer()->GetContentScaleFactor();
1231 void wxWindowMac::SetLabel(const wxString
& title
)
1233 if ( title
== m_label
)
1238 InvalidateBestSize();
1240 if ( GetPeer() && GetPeer()->IsOk() )
1241 GetPeer()->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1243 // do not trigger refreshes upon invisible and possible partly created objects
1244 if ( IsShownOnScreen() )
1248 wxString
wxWindowMac::GetLabel() const
1253 bool wxWindowMac::Show(bool show
)
1256 MacInvalidateBorders();
1258 if ( !wxWindowBase::Show(show
) )
1262 GetPeer()->SetVisibility( show
) ;
1265 MacInvalidateBorders();
1267 #ifdef __WXOSX_IPHONE__
1268 // only when there's no native event support
1269 if ( !IsTopLevel() )
1272 wxShowEvent
eventShow(GetId(), show
);
1273 eventShow
.SetEventObject(this);
1275 HandleWindowEvent(eventShow
);
1281 bool wxWindowMac::OSXShowWithEffect(bool show
,
1282 wxShowEffect effect
,
1285 if ( effect
== wxSHOW_EFFECT_NONE
||
1286 !GetPeer() || !GetPeer()->ShowWithEffect(show
, effect
, timeout
) )
1292 void wxWindowMac::DoEnable(bool enable
)
1294 GetPeer()->Enable( enable
) ;
1295 MacInvalidateBorders();
1299 // status change notifications
1302 void wxWindowMac::MacVisibilityChanged()
1306 void wxWindowMac::MacHiliteChanged()
1310 void wxWindowMac::MacEnabledStateChanged()
1312 OnEnabled( GetPeer()->IsEnabled() );
1316 // status queries on the inherited window's state
1319 bool wxWindowMac::MacIsReallyEnabled()
1321 return GetPeer()->IsEnabled() ;
1324 bool wxWindowMac::MacIsReallyHilited()
1326 #if wxOSX_USE_CARBON
1327 return GetPeer()->IsActive();
1329 return true; // TODO
1333 int wxWindowMac::GetCharHeight() const
1336 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1341 int wxWindowMac::GetCharWidth() const
1344 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1349 void wxWindowMac::DoGetTextExtent(const wxString
& str
,
1352 int *externalLeading
,
1353 const wxFont
*theFont
) const
1355 const wxFont
*fontToUse
= theFont
;
1359 tempFont
= GetFont();
1360 fontToUse
= &tempFont
;
1363 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1364 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1366 wxDouble h
, d
, e
, w
;
1367 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1371 if ( externalLeading
)
1372 *externalLeading
= (wxCoord
)(e
+0.5);
1374 *descent
= (wxCoord
)(d
+0.5);
1376 *x
= (wxCoord
)(w
+0.5);
1378 *y
= (wxCoord
)(h
+0.5);
1382 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1383 * we always intersect with the entire window, not only with the client area
1386 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1388 if ( GetPeer() == NULL
)
1391 if ( !IsShownOnScreen() )
1394 GetPeer()->SetNeedsDisplay( rect
) ;
1397 void wxWindowMac::DoFreeze()
1399 #if wxOSX_USE_CARBON
1400 if ( GetPeer() && GetPeer()->IsOk() )
1401 GetPeer()->SetDrawingEnabled( false ) ;
1405 void wxWindowMac::DoThaw()
1407 #if wxOSX_USE_CARBON
1408 if ( GetPeer() && GetPeer()->IsOk() )
1410 GetPeer()->SetDrawingEnabled( true ) ;
1411 GetPeer()->InvalidateWithChildren() ;
1416 wxWindow
*wxGetActiveWindow()
1418 // actually this is a windows-only concept
1422 // Coordinates relative to the window
1423 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
1425 #if wxOSX_USE_COCOA_OR_CARBON
1428 DoClientToScreen(&x
, &y
);
1429 CGPoint cgpoint
= CGPointMake( x
, y
);
1430 CGWarpMouseCursorPosition( cgpoint
);
1432 // At least GTK sends a mouse moved event after WarpMouse
1433 wxMouseEvent
event(wxEVT_MOTION
);
1436 wxMouseState mState
= ::wxGetMouseState();
1438 event
.m_altDown
= mState
.AltDown();
1439 event
.m_controlDown
= mState
.ControlDown();
1440 event
.m_leftDown
= mState
.LeftIsDown();
1441 event
.m_middleDown
= mState
.MiddleIsDown();
1442 event
.m_rightDown
= mState
.RightIsDown();
1443 event
.m_metaDown
= mState
.MetaDown();
1444 event
.m_shiftDown
= mState
.ShiftDown();
1445 event
.SetId(GetId());
1446 event
.SetEventObject(this);
1447 GetEventHandler()->ProcessEvent(event
);
1451 int wxWindowMac::GetScrollPos(int orient
) const
1454 if ( orient
== wxHORIZONTAL
)
1457 return m_hScrollBar
->GetThumbPosition() ;
1462 return m_vScrollBar
->GetThumbPosition() ;
1468 // This now returns the whole range, not just the number
1469 // of positions that we can scroll.
1470 int wxWindowMac::GetScrollRange(int orient
) const
1473 if ( orient
== wxHORIZONTAL
)
1476 return m_hScrollBar
->GetRange() ;
1481 return m_vScrollBar
->GetRange() ;
1487 int wxWindowMac::GetScrollThumb(int orient
) const
1490 if ( orient
== wxHORIZONTAL
)
1493 return m_hScrollBar
->GetThumbSize() ;
1498 return m_vScrollBar
->GetThumbSize() ;
1504 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1507 if ( orient
== wxHORIZONTAL
)
1510 m_hScrollBar
->SetThumbPosition( pos
) ;
1515 m_vScrollBar
->SetThumbPosition( pos
) ;
1521 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1523 bool needVisibilityUpdate
= false;
1525 if ( m_hScrollBarAlwaysShown
!= hflag
)
1527 m_hScrollBarAlwaysShown
= hflag
;
1528 needVisibilityUpdate
= true;
1531 if ( m_vScrollBarAlwaysShown
!= vflag
)
1533 m_vScrollBarAlwaysShown
= vflag
;
1534 needVisibilityUpdate
= true;
1537 if ( needVisibilityUpdate
)
1538 DoUpdateScrollbarVisibility();
1542 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1543 // our own window origin is at leftOrigin/rightOrigin
1546 void wxWindowMac::MacPaintGrowBox()
1552 if ( MacHasScrollBarCorner() )
1555 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1556 wxASSERT( cgContext
) ;
1560 GetPeer()->GetSize( tw
, th
);
1561 GetPeer()->GetPosition( tx
, ty
);
1563 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1566 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1567 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1568 CGContextSaveGState( cgContext
);
1570 if ( m_backgroundColour
.IsOk() )
1572 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1576 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1578 CGContextFillRect( cgContext
, cgrect
);
1579 CGContextRestoreGState( cgContext
);
1583 if ( m_backgroundColour
.IsOk() )
1584 m_growBox
->SetBackgroundColour(m_backgroundColour
);
1586 m_growBox
->SetBackgroundColour(*wxWHITE
);
1594 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1599 bool hasFocus
= GetPeer()->NeedsFocusRect() && HasFocus();
1601 // back to the surrounding frame rectangle
1604 GetPeer()->GetSize( tw
, th
);
1605 GetPeer()->GetPosition( tx
, ty
);
1607 #if wxOSX_USE_COCOA_OR_CARBON
1610 CGRect cgrect
= CGRectMake( tx
-1 , ty
-1 , tw
+2 ,
1613 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1614 wxASSERT( cgContext
) ;
1616 if ( GetPeer()->NeedsFrame() )
1618 HIThemeFrameDrawInfo info
;
1619 memset( &info
, 0 , sizeof(info
) ) ;
1623 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1624 info
.isFocused
= hasFocus
;
1626 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1628 info
.kind
= kHIThemeFrameTextFieldSquare
;
1629 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1631 else if ( HasFlag(wxSIMPLE_BORDER
) )
1633 info
.kind
= kHIThemeFrameListBox
;
1634 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1640 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1643 #endif // wxOSX_USE_COCOA_OR_CARBON
1646 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1649 if ( child
== m_hScrollBar
)
1650 m_hScrollBar
= NULL
;
1651 if ( child
== m_vScrollBar
)
1652 m_vScrollBar
= NULL
;
1653 if ( child
== m_growBox
)
1656 wxWindowBase::RemoveChild( child
) ;
1659 void wxWindowMac::DoUpdateScrollbarVisibility()
1662 bool triggerSizeEvent
= false;
1666 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1668 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1670 m_hScrollBar
->Show( showHScrollBar
);
1671 triggerSizeEvent
= true;
1677 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1679 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1681 m_vScrollBar
->Show( showVScrollBar
) ;
1682 triggerSizeEvent
= true;
1686 MacRepositionScrollBars() ;
1687 if ( triggerSizeEvent
)
1689 MacOnInternalSize();
1690 wxSizeEvent
event(GetSize(), m_windowId
);
1691 event
.SetEventObject(this);
1692 HandleWindowEvent(event
);
1697 // New function that will replace some of the above.
1698 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1699 int range
, bool refresh
)
1702 // Updating scrollbars when window is being deleted is useless and
1703 // currently results in asserts in client-to-screen coordinates conversion
1704 // code which is used by DoUpdateScrollbarVisibility() so just skip it.
1705 if ( m_isBeingDeleted
)
1708 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1709 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1710 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1711 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1713 DoUpdateScrollbarVisibility();
1717 // Does a physical scroll
1718 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1720 if ( dx
== 0 && dy
== 0 )
1723 int width
, height
;
1724 GetClientSize( &width
, &height
) ;
1727 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1729 scrollrect
.Intersect( *rect
) ;
1730 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1731 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1733 GetPeer()->ScrollRect( &scrollrect
, dx
, dy
);
1738 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1740 child
= node
->GetData();
1744 if (child
->IsTopLevel())
1747 if ( !IsClientAreaChild(child
) )
1750 child
->GetPosition( &x
, &y
);
1751 child
->GetSize( &w
, &h
);
1754 wxRect
rc( x
, y
, w
, h
);
1755 if (rect
->Intersects( rc
))
1756 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1760 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1765 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1768 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1770 wxScrollWinEvent wevent
;
1771 wevent
.SetPosition(event
.GetPosition());
1772 wevent
.SetOrientation(event
.GetOrientation());
1773 wevent
.SetEventObject(this);
1775 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1776 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1777 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1778 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1779 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1780 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1781 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1782 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1783 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1784 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1785 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1786 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1787 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1788 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1789 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1790 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1792 HandleWindowEvent(wevent
);
1797 wxWindow
*wxWindowBase::DoFindFocus()
1799 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
1802 // Raise the window to the top of the Z order
1803 void wxWindowMac::Raise()
1808 // Lower the window to the bottom of the Z order
1809 void wxWindowMac::Lower()
1814 // static wxWindow *gs_lastWhich = NULL;
1816 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1818 // first trigger a set cursor event
1820 wxPoint clientorigin
= GetClientAreaOrigin() ;
1821 wxSize clientsize
= GetClientSize() ;
1823 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1825 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1827 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1828 if ( processedEvtSetCursor
&& event
.HasCursor() )
1830 cursor
= event
.GetCursor() ;
1834 // the test for processedEvtSetCursor is here to prevent using m_cursor
1835 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1836 // it - this is a way to say that our cursor shouldn't be used for this
1838 if ( !processedEvtSetCursor
&& m_cursor
.IsOk() )
1841 if ( !wxIsBusy() && !GetParent() )
1842 cursor
= *wxSTANDARD_CURSOR
;
1845 if ( cursor
.IsOk() )
1846 cursor
.MacInstall() ;
1849 return cursor
.IsOk() ;
1852 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1856 return m_tooltip
->GetTip() ;
1859 return wxEmptyString
;
1862 void wxWindowMac::ClearBackground()
1868 void wxWindowMac::Update()
1870 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1875 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1877 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1881 if ( iter
->IsTopLevel() )
1883 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1887 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1892 iter
= iter
->GetParent() ;
1898 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1900 MacUpdateClippedRects() ;
1902 return m_cachedClippedClientRect
;
1905 const wxRect
& wxWindowMac::MacGetClippedRect() const
1907 MacUpdateClippedRects() ;
1909 return m_cachedClippedRect
;
1912 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1914 MacUpdateClippedRects() ;
1916 return m_cachedClippedRectWithOuterStructure
;
1919 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1921 static wxRegion emptyrgn
;
1923 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1925 MacUpdateClippedRects() ;
1926 if ( includeOuterStructures
)
1927 return m_cachedClippedRegionWithOuterStructure
;
1929 return m_cachedClippedRegion
;
1937 void wxWindowMac::MacUpdateClippedRects() const
1939 #if wxOSX_USE_CARBON
1940 if ( m_cachedClippedRectValid
)
1943 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1944 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1945 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1946 // to add focus borders everywhere
1948 Rect rIncludingOuterStructures
;
1952 GetPeer()->GetSize( tw
, th
);
1953 GetPeer()->GetPosition( tx
, ty
);
1955 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1957 r
.left
-= MacGetLeftBorderSize() ;
1958 r
.top
-= MacGetTopBorderSize() ;
1959 r
.bottom
+= MacGetBottomBorderSize() ;
1960 r
.right
+= MacGetRightBorderSize() ;
1967 rIncludingOuterStructures
= r
;
1968 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1970 wxRect cl
= GetClientRect() ;
1971 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1975 const wxWindow
* child
= (wxWindow
*) this ;
1976 const wxWindow
* parent
= NULL
;
1978 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1980 if ( parent
->MacIsChildOfClientArea(child
) )
1982 size
= parent
->GetClientSize() ;
1983 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1989 // this will be true for scrollbars, toolbars etc.
1990 size
= parent
->GetSize() ;
1991 y
= parent
->MacGetTopBorderSize() ;
1992 x
= parent
->MacGetLeftBorderSize() ;
1993 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1994 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1997 parent
->MacWindowToRootWindow( &x
, &y
) ;
1998 MacRootWindowToWindow( &x
, &y
) ;
2000 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2002 // the wxwindow and client rects will always be clipped
2003 SectRect( &r
, &rparent
, &r
) ;
2004 SectRect( &rClient
, &rparent
, &rClient
) ;
2006 // the structure only at 'hard' borders
2007 if ( parent
->MacClipChildren() ||
2008 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2010 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2016 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2017 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2018 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2019 m_cachedClippedRectWithOuterStructure
= wxRect(
2020 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2021 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2022 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2024 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2025 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2026 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2028 m_cachedClippedRectValid
= true ;
2033 This function must not change the updatergn !
2035 bool wxWindowMac::MacDoRedraw( long time
)
2037 bool handled
= false ;
2039 wxRegion formerUpdateRgn
= m_updateRegion
;
2040 wxRegion clientUpdateRgn
= formerUpdateRgn
;
2042 const wxRect clientRect
= GetClientRect();
2044 clientUpdateRgn
.Intersect(clientRect
);
2046 // first send an erase event to the entire update area
2047 const wxBackgroundStyle bgStyle
= GetBackgroundStyle();
2050 case wxBG_STYLE_ERASE
:
2051 case wxBG_STYLE_SYSTEM
:
2052 case wxBG_STYLE_COLOUR
:
2054 // for the toplevel window this really is the entire area for
2055 // all the others only their client area, otherwise they might
2056 // be drawing with full alpha and eg put blue into the grow-box
2057 // area of a scrolled window (scroll sample)
2058 wxWindowDC
dc(this);
2060 dc
.SetDeviceClippingRegion(formerUpdateRgn
);
2062 dc
.SetDeviceClippingRegion(clientUpdateRgn
);
2064 if ( bgStyle
== wxBG_STYLE_ERASE
)
2066 wxEraseEvent
eevent( GetId(), &dc
);
2067 eevent
.SetEventObject( this );
2068 if ( ProcessWindowEvent( eevent
) )
2074 dc
.SetBackground(GetBackgroundColour());
2080 case wxBG_STYLE_PAINT
:
2081 case wxBG_STYLE_TRANSPARENT
:
2082 // nothing to do, user-defined EVT_PAINT handler will overwrite the
2083 // entire window client area
2087 wxFAIL_MSG( "unsupported background style" );
2090 // as this is a full window, shouldn't be necessary anymore
2091 // MacPaintGrowBox();
2093 // calculate a client-origin version of the update rgn and set
2094 // m_updateRegion to that
2095 clientUpdateRgn
.Offset(-clientRect
.GetPosition());
2096 m_updateRegion
= clientUpdateRgn
;
2098 if ( !m_updateRegion
.Empty() )
2100 // paint the window itself
2102 wxPaintEvent
event(GetId());
2103 event
.SetTimestamp(time
);
2104 event
.SetEventObject(this);
2105 handled
= HandleWindowEvent(event
);
2108 m_updateRegion
= formerUpdateRgn
;
2110 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
2112 top
->WindowWasPainted() ;
2117 void wxWindowMac::MacPaintChildrenBorders()
2119 // now we cannot rely on having its borders drawn by a window itself, as it does not
2120 // get the updateRgn wide enough to always do so, so we do it from the parent
2121 // this would also be the place to draw any custom backgrounds for native controls
2122 // in Composited windowing
2123 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2127 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2129 child
= node
->GetData();
2133 if (child
== m_vScrollBar
)
2135 if (child
== m_hScrollBar
)
2137 if (child
== m_growBox
)
2140 if (child
->IsTopLevel())
2142 if (!child
->IsShown())
2145 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2147 child
->GetPosition( &x
, &y
);
2148 child
->GetSize( &w
, &h
);
2150 if ( m_updateRegion
.Contains(clientOrigin
.x
+x
-10, clientOrigin
.y
+y
-10, w
+20, h
+20) )
2152 // paint custom borders
2153 wxNcPaintEvent
eventNc( child
->GetId() );
2154 eventNc
.SetEventObject( child
);
2155 if ( !child
->HandleWindowEvent( eventNc
) )
2157 child
->MacPaintBorders(0, 0) ;
2164 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2166 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
2167 return tlw
? tlw
->GetWXWindow() : NULL
;
2170 bool wxWindowMac::MacHasScrollBarCorner() const
2173 /* Returns whether the scroll bars in a wxScrolledWindow should be
2174 * shortened. Scroll bars should be shortened if either:
2176 * - both scroll bars are visible, or
2178 * - there is a resize box in the parent frame's corner and this
2179 * window shares the bottom and right edge with the parent
2183 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
2186 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
2187 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
2189 // Both scroll bars visible
2194 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
2196 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
2198 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
2201 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
2203 // Parent frame has resize handle
2204 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
2206 // Note: allow for some wiggle room here as wxMac's
2207 // window rect calculations seem to be imprecise
2208 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
2209 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
2211 // Parent frame has resize handle and shares
2212 // right bottom corner
2217 // Parent frame has resize handle but doesn't
2218 // share right bottom corner
2224 // Parent frame doesn't have resize handle
2230 // No parent frame found
2238 void wxWindowMac::MacCreateScrollBars( long style
)
2241 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2243 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2245 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2246 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2248 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2251 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2253 GetClientSize( &width
, &height
) ;
2255 wxPoint
vPoint(width
- scrlsize
, 0) ;
2256 wxSize
vSize(scrlsize
, height
- adjust
) ;
2257 wxPoint
hPoint(0, height
- scrlsize
) ;
2258 wxSize
hSize(width
- adjust
, scrlsize
) ;
2260 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2261 if ( style
& wxVSCROLL
)
2263 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2264 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2267 if ( style
& wxHSCROLL
)
2269 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2270 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2273 wxPoint
gPoint(width
- scrlsize
, height
- scrlsize
);
2274 wxSize
gSize(scrlsize
, scrlsize
);
2275 m_growBox
= new wxBlindPlateWindow((wxWindow
*)this, wxID_ANY
, gPoint
, gSize
, 0);
2278 // because the create does not take into account the client area origin
2279 // we might have a real position shift
2280 MacRepositionScrollBars() ;
2284 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2286 bool result
= ((child
== NULL
)
2288 || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
) && (child
!= m_growBox
))
2295 void wxWindowMac::MacRepositionScrollBars()
2298 if ( !m_hScrollBar
&& !m_vScrollBar
)
2301 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2302 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2304 // get real client area
2306 GetSize( &width
, &height
);
2308 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2309 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2311 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2312 wxSize
vSize( scrlsize
, height
- adjust
) ;
2313 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2314 wxSize
hSize( width
- adjust
, scrlsize
) ;
2317 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2319 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2322 if ( MacHasScrollBarCorner() )
2324 m_growBox
->SetSize( width
- scrlsize
, height
- scrlsize
, wxDefaultCoord
, wxDefaultCoord
, wxSIZE_USE_EXISTING
);
2325 if ( !m_growBox
->IsShown() )
2330 if ( m_growBox
->IsShown() )
2337 bool wxWindowMac::AcceptsFocus() const
2339 if ( GetPeer() == NULL
|| GetPeer()->IsUserPane() )
2340 return wxWindowBase::AcceptsFocus();
2342 return GetPeer()->CanFocus();
2345 void wxWindowMac::MacSuperChangedPosition()
2347 // only window-absolute structures have to be moved i.e. controls
2349 m_cachedClippedRectValid
= false ;
2352 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2355 child
= node
->GetData();
2356 child
->MacSuperChangedPosition() ;
2358 node
= node
->GetNext();
2362 void wxWindowMac::MacTopLevelWindowChangedPosition()
2364 // only screen-absolute structures have to be moved i.e. glcanvas
2367 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2370 child
= node
->GetData();
2371 child
->MacTopLevelWindowChangedPosition() ;
2373 node
= node
->GetNext();
2377 long wxWindowMac::MacGetWXBorderSize() const
2384 if ( GetPeer() && GetPeer()->NeedsFrame() )
2386 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2388 #if wxOSX_USE_COCOA_OR_CARBON
2389 // this metric is only the 'outset' outside the simple frame rect
2390 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2396 else if (HasFlag(wxSIMPLE_BORDER
))
2398 #if wxOSX_USE_COCOA_OR_CARBON
2399 // this metric is only the 'outset' outside the simple frame rect
2400 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2411 long wxWindowMac::MacGetLeftBorderSize() const
2413 // the wx borders are all symmetric in mac themes
2414 long border
= MacGetWXBorderSize() ;
2418 int left
, top
, right
, bottom
;
2419 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2427 long wxWindowMac::MacGetRightBorderSize() const
2429 // the wx borders are all symmetric in mac themes
2430 long border
= MacGetWXBorderSize() ;
2434 int left
, top
, right
, bottom
;
2435 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2442 long wxWindowMac::MacGetTopBorderSize() const
2444 // the wx borders are all symmetric in mac themes
2445 long border
= MacGetWXBorderSize() ;
2449 int left
, top
, right
, bottom
;
2450 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2457 long wxWindowMac::MacGetBottomBorderSize() const
2459 // the wx borders are all symmetric in mac themes
2460 long border
= MacGetWXBorderSize() ;
2464 int left
, top
, right
, bottom
;
2465 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2472 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2474 return style
& ~wxBORDER_MASK
;
2477 // Find the wxWindowMac at the current mouse position, returning the mouse
2479 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2481 pt
= wxGetMousePosition();
2482 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2484 return (wxWindow
*) found
;
2487 // Get the current mouse position.
2488 wxPoint
wxGetMousePosition()
2492 wxGetMousePosition( &x
, &y
);
2494 return wxPoint(x
, y
);
2497 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2499 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2501 // copied from wxGTK : CS
2502 // VZ: shouldn't we move this to base class then?
2504 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2507 // (a) it's a command event and so is propagated to the parent
2508 // (b) under MSW it can be generated from kbd too
2509 // (c) it uses screen coords (because of (a))
2510 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2512 this->ClientToScreen(event
.GetPosition()));
2513 evtCtx
.SetEventObject(this);
2514 if ( ! HandleWindowEvent(evtCtx
) )
2523 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2527 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2531 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2532 Rect bounds
= { static_cast<short>(y
), static_cast<short>(x
), static_cast<short>(y
+ h
), static_cast<short>(x
+ w
) };
2537 bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec
) )
2542 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2544 #if wxOSX_USE_COCOA_OR_CARBON
2545 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2548 return eventNotHandledErr
;
2554 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2556 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2557 if ( !wxWindowBase::Reparent(newParent
) )
2560 GetPeer()->RemoveFromParent();
2561 GetPeer()->Embed( GetParent()->GetPeer() );
2567 bool wxWindowMac::SetTransparent(wxByte alpha
)
2569 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2571 if ( alpha
!= m_macAlpha
)
2573 m_macAlpha
= alpha
;
2580 bool wxWindowMac::CanSetTransparent()
2585 wxByte
wxWindowMac::GetTransparent() const
2590 bool wxWindowMac::IsShownOnScreen() const
2592 if ( GetPeer() && GetPeer()->IsOk() )
2594 bool peerVis
= GetPeer()->IsVisible();
2595 bool wxVis
= wxWindowBase::IsShownOnScreen();
2596 if( peerVis
!= wxVis
)
2598 // CS : put a breakpoint here to investigate differences
2599 // between native an wx visibilities
2600 // the only place where I've encountered them until now
2601 // are the hiding/showing sequences where the vis-changed event is
2602 // first sent to the innermost control, while wx does things
2603 // from the outmost control
2604 wxVis
= wxWindowBase::IsShownOnScreen();
2608 return GetPeer()->IsVisible();
2610 return wxWindowBase::IsShownOnScreen();
2613 #if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
2616 wxHotKeyHandler(EventHandlerCallRef
WXUNUSED(nextHandler
),
2618 void* WXUNUSED(userData
))
2620 EventHotKeyID hotKeyId
;
2622 GetEventParameter( event
, kEventParamDirectObject
, typeEventHotKeyID
, NULL
, sizeof(hotKeyId
), NULL
, &hotKeyId
);
2624 for ( unsigned i
= 0; i
< s_hotkeys
.size(); ++i
)
2626 if ( s_hotkeys
[i
].keyId
== static_cast<int>(hotKeyId
.id
) )
2628 unsigned char charCode
;
2632 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
2634 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
2635 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
2636 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
2637 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &where
);
2639 UInt32 keymessage
= (keyCode
<< 8) + charCode
;
2641 wxKeyEvent
wxevent(wxEVT_HOTKEY
);
2642 wxevent
.SetId(hotKeyId
.id
);
2643 wxTheApp
->MacCreateKeyEvent( wxevent
, s_hotkeys
[i
].window
, keymessage
,
2644 modifiers
, when
, where
.h
, where
.v
, 0 ) ;
2646 s_hotkeys
[i
].window
->HandleWindowEvent(wxevent
);
2653 bool wxWindowMac::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
2655 for ( unsigned i
= 0; i
< s_hotkeys
.size(); ++i
)
2657 if ( s_hotkeys
[i
].keyId
== hotkeyId
)
2659 wxLogLastError(wxT("hotkeyId already registered"));
2665 static bool installed
= false;
2668 EventTypeSpec eventType
;
2669 eventType
.eventClass
=kEventClassKeyboard
;
2670 eventType
.eventKind
=kEventHotKeyPressed
;
2672 InstallApplicationEventHandler(&wxHotKeyHandler
, 1, &eventType
, NULL
, NULL
);
2676 UInt32 mac_modifiers
=0;
2677 if ( modifiers
& wxMOD_ALT
)
2678 mac_modifiers
|= optionKey
;
2679 if ( modifiers
& wxMOD_SHIFT
)
2680 mac_modifiers
|= shiftKey
;
2681 if ( modifiers
& wxMOD_RAW_CONTROL
)
2682 mac_modifiers
|= controlKey
;
2683 if ( modifiers
& wxMOD_CONTROL
)
2684 mac_modifiers
|= cmdKey
;
2686 EventHotKeyRef hotKeyRef
;
2687 EventHotKeyID hotKeyIDmac
;
2689 hotKeyIDmac
.signature
= 'WXMC';
2690 hotKeyIDmac
.id
= hotkeyId
;
2692 if ( RegisterEventHotKey(wxCharCodeWXToOSX((wxKeyCode
)keycode
), mac_modifiers
, hotKeyIDmac
,
2693 GetApplicationEventTarget(), 0, &hotKeyRef
) != noErr
)
2695 wxLogLastError(wxT("RegisterHotKey"));
2706 s_hotkeys
.push_back(v
);
2712 bool wxWindowMac::UnregisterHotKey(int hotkeyId
)
2714 for ( int i
= ((int)s_hotkeys
.size())-1; i
>=0; -- i
)
2716 if ( s_hotkeys
[i
].keyId
== hotkeyId
)
2718 EventHotKeyRef ref
= s_hotkeys
[i
].ref
;
2719 s_hotkeys
.erase(s_hotkeys
.begin() + i
);
2720 if ( UnregisterEventHotKey(ref
) != noErr
)
2722 wxLogLastError(wxT("UnregisterHotKey"));
2734 #endif // wxUSE_HOTKEY
2736 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2738 bool handled
= false;
2740 // moved the ordinary key event sending AFTER the accel evaluation
2743 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2745 wxWindow
*ancestor
= this;
2748 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2751 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2753 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
2754 handled
= handler
->ProcessEvent( command_event
);
2758 // accelerators can also be used with buttons, try them too
2759 command_event
.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED
);
2760 handled
= handler
->ProcessEvent( command_event
);
2766 if (ancestor
->IsTopLevel())
2769 ancestor
= ancestor
->GetParent();
2772 #endif // wxUSE_ACCEL
2776 handled
= HandleWindowEvent( event
) ;
2777 if ( handled
&& event
.GetSkipped() )
2788 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2790 static MacControlMap wxWinMacControlList
;
2792 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2794 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2796 return impl
->GetWXPeer();
2801 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2803 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2805 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2808 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2810 // adding NULL ControlRef is (first) surely a result of an error and
2811 // (secondly) breaks native event processing
2812 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2814 wxWinMacControlList
[inControl
] = impl
;
2817 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2819 // iterate over all the elements in the class
2820 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2821 // we should go on...
2827 MacControlMap::iterator it
;
2828 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2830 if ( it
->second
== impl
)
2832 wxWinMacControlList
.erase(it
);
2840 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2842 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
, bool isUserPane
)
2845 m_isRootControl
= isRootControl
;
2846 m_isUserPane
= isUserPane
;
2848 m_shouldSendEvents
= true;
2851 wxWidgetImpl::wxWidgetImpl()
2856 wxWidgetImpl::~wxWidgetImpl()
2860 void wxWidgetImpl::Init()
2862 m_isRootControl
= false;
2864 m_needsFocusRect
= false;
2865 m_needsFrame
= true;
2868 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2870 m_needsFocusRect
= needs
;
2873 bool wxWidgetImpl::NeedsFocusRect() const
2875 return m_needsFocusRect
;
2878 void wxWidgetImpl::SetNeedsFrame( bool needs
)
2880 m_needsFrame
= needs
;
2883 bool wxWidgetImpl::NeedsFrame() const
2885 return m_needsFrame
;