1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/window_osx.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
13 #include "wx/window.h"
22 #include "wx/dcclient.h"
23 #include "wx/button.h"
25 #include "wx/dialog.h"
26 #include "wx/settings.h"
27 #include "wx/msgdlg.h"
28 #include "wx/scrolbar.h"
29 #include "wx/statbox.h"
30 #include "wx/textctrl.h"
31 #include "wx/toolbar.h"
32 #include "wx/layout.h"
33 #include "wx/statusbr.h"
34 #include "wx/menuitem.h"
35 #include "wx/treectrl.h"
36 #include "wx/listctrl.h"
39 #include "wx/tooltip.h"
40 #include "wx/spinctrl.h"
41 #include "wx/geometry.h"
44 #include "wx/listctrl.h"
48 #include "wx/treectrl.h"
56 #include "wx/popupwin.h"
59 #if wxUSE_DRAG_AND_DROP
63 #include "wx/graphics.h"
66 #include "wx/osx/uma.h"
68 #include "wx/osx/private.h"
71 #define MAC_SCROLLBAR_SIZE 15
72 #define MAC_SMALL_SCROLLBAR_SIZE 11
76 #ifdef __WXUNIVERSAL__
77 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
80 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
81 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
84 #define wxMAC_DEBUG_REDRAW 0
85 #ifndef wxMAC_DEBUG_REDRAW
86 #define wxMAC_DEBUG_REDRAW 0
89 wxWidgetImplType
* kOSXNoWidgetImpl
= (wxWidgetImplType
*) -1L;
91 #if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
99 wxVector
<wxHotKeyRec
> s_hotkeys
;
103 // ===========================================================================
105 // ===========================================================================
107 // the grow box has to be implemented as an inactive window, so that nothing can direct
110 class WXDLLIMPEXP_CORE wxBlindPlateWindow
: public wxWindow
113 wxBlindPlateWindow() { Init(); }
115 // Old-style constructor (no default values for coordinates to avoid
116 // ambiguity with the new one)
117 wxBlindPlateWindow(wxWindow
*parent
,
118 int x
, int y
, int width
, int height
,
119 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
120 const wxString
& name
= wxPanelNameStr
)
124 Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(width
, height
), style
, name
);
128 wxBlindPlateWindow(wxWindow
*parent
,
129 wxWindowID winid
= wxID_ANY
,
130 const wxPoint
& pos
= wxDefaultPosition
,
131 const wxSize
& size
= wxDefaultSize
,
132 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
133 const wxString
& name
= wxPanelNameStr
)
137 Create(parent
, winid
, pos
, size
, style
, name
);
141 bool Create(wxWindow
*parent
,
142 wxWindowID winid
= wxID_ANY
,
143 const wxPoint
& pos
= wxDefaultPosition
,
144 const wxSize
& size
= wxDefaultSize
,
145 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
146 const wxString
& name
= wxPanelNameStr
)
148 if ( !wxWindow::Create(parent
, winid
, pos
, size
, style
, name
) )
151 // so that non-solid background renders correctly under GTK+:
152 SetThemeEnabled(true);
156 virtual ~wxBlindPlateWindow();
158 virtual bool AcceptsFocus() const
164 // common part of all ctors
169 DECLARE_DYNAMIC_CLASS_NO_COPY(wxBlindPlateWindow
)
170 DECLARE_EVENT_TABLE()
173 wxBlindPlateWindow::~wxBlindPlateWindow()
177 IMPLEMENT_DYNAMIC_CLASS(wxBlindPlateWindow
, wxWindow
)
179 BEGIN_EVENT_TABLE(wxBlindPlateWindow
, wxWindow
)
183 // ----------------------------------------------------------------------------
184 // constructors and such
185 // ----------------------------------------------------------------------------
187 wxWindowMac::wxWindowMac()
192 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
197 const wxString
& name
)
200 Create(parent
, id
, pos
, size
, style
, name
);
203 void wxWindowMac::Init()
207 m_cgContextRef
= NULL
;
209 // as all windows are created with WS_VISIBLE style...
212 m_hScrollBar
= NULL
;
213 m_vScrollBar
= NULL
;
214 m_hScrollBarAlwaysShown
= false;
215 m_vScrollBarAlwaysShown
= false;
218 m_clipChildren
= false ;
219 m_cachedClippedRectValid
= false ;
220 m_isNativeWindowWrapper
= false;
223 wxWindowMac::~wxWindowMac()
227 #if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
228 for ( int i
= s_hotkeys
.size()-1; i
>=0; -- i
)
230 if ( s_hotkeys
[i
].window
== this )
232 EventHotKeyRef ref
= s_hotkeys
[i
].ref
;
233 s_hotkeys
.erase(s_hotkeys
.begin() + i
);
234 if ( UnregisterEventHotKey(ref
) != noErr
)
236 wxLogLastError(wxT("UnregisterHotKey"));
242 MacInvalidateBorders() ;
244 #ifndef __WXUNIVERSAL__
245 // VS: make sure there's no wxFrame with last focus set to us:
246 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
248 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
251 if ( frame
->GetLastFocus() == this )
252 frame
->SetLastFocus(NULL
);
258 // destroy children before destroying this window itself
261 // wxRemoveMacControlAssociation( this ) ;
262 // If we delete an item, we should initialize the parent panel,
263 // because it could now be invalid.
264 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this), wxTopLevelWindow
);
267 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
268 tlw
->SetDefaultItem(NULL
);
271 if ( g_MacLastWindow
== this )
272 g_MacLastWindow
= NULL
;
274 #ifndef __WXUNIVERSAL__
275 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
278 if ( frame
->GetLastFocus() == this )
279 frame
->SetLastFocus( NULL
) ;
283 // delete our drop target if we've got one
284 #if wxUSE_DRAG_AND_DROP
285 wxDELETE(m_dropTarget
);
291 WXWidget
wxWindowMac::GetHandle() const
294 return (WXWidget
) GetPeer()->GetWXWidget() ;
298 wxOSXWidgetImpl
* wxWindowMac::GetPeer() const
300 return m_peer
== kOSXNoWidgetImpl
? NULL
: m_peer
;
303 bool wxWindowMac::ShouldCreatePeer() const
305 return m_peer
!= kOSXNoWidgetImpl
;
308 void wxWindowMac::DontCreatePeer()
310 m_peer
= kOSXNoWidgetImpl
;
313 void wxWindowMac::SetWrappingPeer(wxOSXWidgetImpl
* wrapper
)
315 wxOSXWidgetImpl
* inner
= GetPeer();
316 wxASSERT_MSG( inner
!= NULL
&& inner
->IsOk(), "missing or incomplete inner peer" );
317 wxASSERT_MSG( wrapper
!= NULL
&& wrapper
->IsOk(), "missing or incomplete wrapper" );
319 if ( !(inner
!= NULL
&& inner
->IsOk() && wrapper
!= NULL
&& wrapper
->IsOk()) )
322 inner
->RemoveFromParent();
323 wrapper
->InstallEventHandler();
324 wrapper
->Embed(inner
);
328 void wxWindowMac::SetPeer(wxOSXWidgetImpl
* peer
)
332 if ( !GetPeer()->IsRootControl() )
333 GetPeer()->RemoveFromParent();
339 if ( GetPeer() && !GetPeer()->IsRootControl())
341 wxASSERT_MSG( GetPeer()->IsOk() , wxT("The native control must exist already") ) ;
343 if (!GetParent()->GetChildren().Find((wxWindow
*)this))
344 GetParent()->AddChild( this );
346 GetPeer()->InstallEventHandler();
347 GetPeer()->Embed(GetParent()->GetPeer());
349 GetParent()->MacChildAdded() ;
351 // adjust font, controlsize etc
352 GetPeer()->SetControlSize( m_windowVariant
);
354 // in case nothing has been set, use the variant default fonts
356 DoSetWindowVariant( m_windowVariant
);
358 GetPeer()->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
360 // for controls we want to use best size for wxDefaultSize params )
361 if ( !GetPeer()->IsUserPane() )
362 SetInitialSize(GetMinSize());
364 SetCursor( *wxSTANDARD_CURSOR
) ;
368 #if WXWIN_COMPATIBILITY_2_8
370 bool wxWindowMac::MacIsUserPane()
372 return GetPeer() == NULL
|| GetPeer()->IsUserPane();
377 bool wxWindowMac::MacIsUserPane() const
379 return GetPeer() == NULL
|| GetPeer()->IsUserPane();
382 // ---------------------------------------------------------------------------
383 // Utility Routines to move between different coordinate systems
384 // ---------------------------------------------------------------------------
387 * Right now we have the following setup :
388 * a border that is not part of the native control is always outside the
389 * control's border (otherwise we lose all native intelligence, future ways
390 * may be to have a second embedding control responsible for drawing borders
391 * and backgrounds eventually)
392 * so all this border calculations have to be taken into account when calling
393 * native methods or getting native oriented data
394 * so we have three coordinate systems here
395 * wx client coordinates
396 * wx window coordinates (including window frames)
404 bool wxWindowMac::Create(wxWindowMac
*parent
,
409 const wxString
& name
)
411 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
413 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
416 m_windowVariant
= parent
->GetWindowVariant() ;
418 m_hScrollBarAlwaysShown
=
419 m_vScrollBarAlwaysShown
= HasFlag(wxALWAYS_SHOW_SB
);
421 if ( m_peer
!= kOSXNoWidgetImpl
)
423 SetPeer(wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() ));
424 MacPostControlCreate(pos
, size
) ;
427 #ifndef __WXUNIVERSAL__
428 // Don't give scrollbars to wxControls unless they ask for them
429 if ( (! IsKindOf(CLASSINFO(wxControl
))
431 && ! IsKindOf(CLASSINFO(wxStatusBar
))
434 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
436 MacCreateScrollBars( style
) ;
440 wxWindowCreateEvent
event((wxWindow
*)this);
441 GetEventHandler()->AddPendingEvent(event
);
446 void wxWindowMac::MacChildAdded()
450 m_vScrollBar
->Raise() ;
452 m_hScrollBar
->Raise() ;
458 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
),
459 const wxSize
& WXUNUSED(size
))
461 // todo remove if refactoring works correctly
463 wxASSERT_MSG( GetPeer() != NULL
&& GetPeer()->IsOk() , wxT("No valid mac control") ) ;
465 if (!GetParent()->GetChildren().Find((wxWindow
*)this))
466 GetParent()->AddChild( this );
468 GetPeer()->InstallEventHandler();
469 GetPeer()->Embed(GetParent()->GetPeer());
471 GetParent()->MacChildAdded() ;
473 // adjust font, controlsize etc
474 DoSetWindowVariant( m_windowVariant
) ;
476 GetPeer()->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
478 // for controls we want to use best size for wxDefaultSize params )
479 if ( !GetPeer()->IsUserPane() )
480 SetInitialSize(size
);
482 SetCursor( *wxSTANDARD_CURSOR
) ;
486 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
488 // Don't assert, in case we set the window variant before
489 // the window is created
490 // wxASSERT( GetPeer()->IsOk() ) ;
492 m_windowVariant
= variant
;
494 if (GetPeer() == NULL
|| !GetPeer()->IsOk())
497 GetPeer()->SetControlSize( variant
);
501 case wxWINDOW_VARIANT_NORMAL
:
502 static wxFont
sysNormal(wxOSX_SYSTEM_FONT_NORMAL
);
506 case wxWINDOW_VARIANT_SMALL
:
507 static wxFont
sysSmall(wxOSX_SYSTEM_FONT_SMALL
);
511 case wxWINDOW_VARIANT_MINI
:
512 static wxFont
sysMini(wxOSX_SYSTEM_FONT_MINI
);
516 case wxWINDOW_VARIANT_LARGE
:
517 static wxFont
sysLarge(wxOSX_SYSTEM_FONT_NORMAL
);
522 wxFAIL_MSG(wxT("unexpected window variant"));
527 void wxWindowMac::MacUpdateControlFont()
530 GetPeer()->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
532 // do not trigger refreshes upon invisible and possible partly created objects
533 if ( IsShownOnScreen() )
537 bool wxWindowMac::SetFont(const wxFont
& font
)
539 bool retval
= wxWindowBase::SetFont( font
);
541 MacUpdateControlFont() ;
546 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
548 bool retval
= wxWindowBase::SetForegroundColour( col
);
551 MacUpdateControlFont();
556 bool wxWindowMac::SetBackgroundStyle(wxBackgroundStyle style
)
558 if ( !wxWindowBase::SetBackgroundStyle(style
) )
562 GetPeer()->SetBackgroundStyle(style
);
566 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
570 if ( m_backgroundColour
.IsOk() )
571 m_growBox
->SetBackgroundColour(m_backgroundColour
);
573 m_growBox
->SetBackgroundColour(*wxWHITE
);
576 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
580 GetPeer()->SetBackgroundColour( col
) ;
585 static bool wxIsWindowOrParentDisabled(wxWindow
* w
)
587 while (w
&& !w
->IsTopLevel())
596 void wxWindowMac::SetFocus()
598 if ( !AcceptsFocus() )
601 if (wxIsWindowOrParentDisabled((wxWindow
*) this))
604 wxWindow
* former
= FindFocus() ;
605 if ( former
== this )
608 GetPeer()->SetFocus() ;
611 void wxWindowMac::OSXSimulateFocusEvents()
613 wxWindow
* former
= FindFocus() ;
614 if ( former
!= NULL
&& former
!= this )
617 wxFocusEvent
event( wxEVT_KILL_FOCUS
, former
->GetId());
618 event
.SetEventObject(former
);
619 event
.SetWindow(this);
620 former
->HandleWindowEvent(event
) ;
624 wxFocusEvent
event(wxEVT_SET_FOCUS
, former
->GetId());
625 event
.SetEventObject(former
);
626 event
.SetWindow(this);
627 former
->HandleWindowEvent(event
);
632 void wxWindowMac::DoCaptureMouse()
634 wxApp::s_captureWindow
= (wxWindow
*) this ;
635 GetPeer()->CaptureMouse() ;
638 wxWindow
* wxWindowBase::GetCapture()
640 return wxApp::s_captureWindow
;
643 void wxWindowMac::DoReleaseMouse()
645 wxApp::s_captureWindow
= NULL
;
647 GetPeer()->ReleaseMouse() ;
650 #if wxUSE_DRAG_AND_DROP
652 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
656 m_dropTarget
= pDropTarget
;
658 GetPeer()->SetDropTarget(m_dropTarget
) ;
663 // Old-style File Manager Drag & Drop
664 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
669 // From a wx position / size calculate the appropriate size of the native control
671 bool wxWindowMac::MacGetBoundsForControl(
675 int& w
, int& h
, bool adjustOrigin
) const
677 // the desired size, minus the border pixels gives the correct size of the control
681 w
= WidthDefault( size
.x
);
682 h
= HeightDefault( size
.y
);
684 x
+= MacGetLeftBorderSize() ;
685 y
+= MacGetTopBorderSize() ;
686 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
687 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
690 AdjustForParentClientOrigin( x
, y
) ;
692 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
693 if ( GetParent() && !GetParent()->IsTopLevel() )
695 x
-= GetParent()->MacGetLeftBorderSize() ;
696 y
-= GetParent()->MacGetTopBorderSize() ;
702 // Get window size (not client size)
703 void wxWindowMac::DoGetSize(int *x
, int *y
) const
706 GetPeer()->GetSize( width
, height
);
709 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
711 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
714 // get the position of the bounds of this window in client coordinates of its parent
715 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
719 GetPeer()->GetPosition( x1
, y1
) ;
721 // get the wx window position from the native one
722 x1
-= MacGetLeftBorderSize() ;
723 y1
-= MacGetTopBorderSize() ;
727 wxWindow
*parent
= GetParent();
730 // we must first adjust it to be in window coordinates of the parent,
731 // as otherwise it gets lost by the ClientAreaOrigin fix
732 x1
+= parent
->MacGetLeftBorderSize() ;
733 y1
+= parent
->MacGetTopBorderSize() ;
735 // and now to client coordinates
736 wxPoint
pt(parent
->GetClientAreaOrigin());
748 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
750 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
751 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
752 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
753 MacRootWindowToWindow( x
, y
) ;
755 wxPoint origin
= GetClientAreaOrigin() ;
762 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
764 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
765 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
767 wxPoint origin
= GetClientAreaOrigin() ;
773 MacWindowToRootWindow( x
, y
) ;
774 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
777 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
779 wxPoint origin
= GetClientAreaOrigin() ;
785 MacWindowToRootWindow( x
, y
) ;
788 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
799 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
802 pt
.x
-= MacGetLeftBorderSize() ;
803 pt
.y
-= MacGetTopBorderSize() ;
804 wxWidgetImpl::Convert( &pt
, GetPeer() , top
->GetPeer() ) ;
814 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
825 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
828 wxWidgetImpl::Convert( &pt
, top
->GetPeer() , GetPeer() ) ;
829 pt
.x
+= MacGetLeftBorderSize() ;
830 pt
.y
+= MacGetTopBorderSize() ;
840 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
842 wxSize sizeTotal
= size
;
844 int innerwidth
, innerheight
;
846 int outerwidth
, outerheight
;
848 GetPeer()->GetContentArea( left
, top
, innerwidth
, innerheight
);
849 GetPeer()->GetSize( outerwidth
, outerheight
);
851 sizeTotal
.x
+= outerwidth
-innerwidth
;
852 sizeTotal
.y
+= outerheight
-innerheight
;
854 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
855 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
860 // Get size *available for subwindows* i.e. excluding menu bar etc.
861 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
867 GetPeer()->GetContentArea( left
, top
, ww
, hh
);
869 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
870 hh
-= m_hScrollBar
->GetSize().y
;
872 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
873 ww
-= m_vScrollBar
->GetSize().x
;
878 // we shouldn't return invalid width
887 // we shouldn't return invalid height
895 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
897 if (m_cursor
.IsSameAs(cursor
))
902 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
907 if ( ! wxWindowBase::SetCursor( cursor
) )
911 wxASSERT_MSG( m_cursor
.IsOk(),
912 wxT("cursor must be valid after call to the base version"));
914 if ( GetPeer() != NULL
)
915 GetPeer()->SetCursor( m_cursor
);
921 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
923 #ifndef __WXUNIVERSAL__
926 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
928 wxPoint mouse
= wxGetMousePosition();
934 ClientToScreen( &x
, &y
) ;
936 menu
->GetPeer()->PopUp(this, x
, y
);
939 // actually this shouldn't be called, because universal is having its own implementation
945 // ----------------------------------------------------------------------------
947 // ----------------------------------------------------------------------------
951 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
953 wxWindowBase::DoSetToolTip(tooltip
);
956 m_tooltip
->SetWindow(this);
959 GetPeer()->SetToolTip(tooltip
);
964 void wxWindowMac::MacInvalidateBorders()
966 if ( GetPeer() == NULL
)
969 bool vis
= IsShownOnScreen() ;
973 int outerBorder
= MacGetLeftBorderSize() ;
975 if ( GetPeer()->NeedsFocusRect() )
978 if ( outerBorder
== 0 )
981 // now we know that we have something to do at all
985 GetPeer()->GetSize( tw
, th
);
986 GetPeer()->GetPosition( tx
, ty
);
988 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
989 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
990 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
991 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
994 GetParent()->GetPeer()->SetNeedsDisplay(&leftupdate
);
995 GetParent()->GetPeer()->SetNeedsDisplay(&rightupdate
);
996 GetParent()->GetPeer()->SetNeedsDisplay(&topupdate
);
997 GetParent()->GetPeer()->SetNeedsDisplay(&bottomupdate
);
1001 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1003 // this is never called for a toplevel window, so we know we have a parent
1004 int former_x
, former_y
, former_w
, former_h
;
1006 // Get true coordinates of former position
1007 DoGetPosition( &former_x
, &former_y
) ;
1008 DoGetSize( &former_w
, &former_h
) ;
1010 wxWindow
*parent
= GetParent();
1013 wxPoint
pt(parent
->GetClientAreaOrigin());
1018 int actualWidth
= width
;
1019 int actualHeight
= height
;
1024 // min and max sizes are only for sizers, not for explicit size setting
1025 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1026 actualWidth
= m_minWidth
;
1027 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1028 actualHeight
= m_minHeight
;
1029 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1030 actualWidth
= m_maxWidth
;
1031 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1032 actualHeight
= m_maxHeight
;
1035 bool doMove
= false, doResize
= false ;
1037 if ( actualX
!= former_x
|| actualY
!= former_y
)
1040 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1043 if ( doMove
|| doResize
)
1045 // as the borders are drawn outside the native control, we adjust now
1047 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1048 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1049 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1051 if ( parent
&& !parent
->IsTopLevel() )
1053 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
1056 MacInvalidateBorders() ;
1058 m_cachedClippedRectValid
= false ;
1060 GetPeer()->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
1062 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1064 MacInvalidateBorders() ;
1066 MacRepositionScrollBars() ;
1069 wxPoint
point(actualX
, actualY
);
1070 wxMoveEvent
event(point
, m_windowId
);
1071 event
.SetEventObject(this);
1072 HandleWindowEvent(event
) ;
1077 MacRepositionScrollBars() ;
1083 wxSize
wxWindowMac::DoGetBestSize() const
1085 if ( GetPeer() == NULL
|| GetPeer()->IsUserPane() || IsTopLevel() )
1087 return wxWindowBase::DoGetBestSize() ;
1093 GetPeer()->GetBestRect(&r
);
1095 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
1103 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1110 if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1117 // return wxWindowBase::DoGetBestSize() ;
1121 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
1122 MacGetRightBorderSize();
1123 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
1124 MacGetBottomBorderSize();
1125 if ( bestHeight
< 10 )
1128 return wxSize(bestWidth
, bestHeight
);
1132 void wxWindowMac::SendSizeEvent(int flags
)
1134 MacOnInternalSize();
1135 wxWindowBase::SendSizeEvent(flags
);
1138 // set the size of the window: if the dimensions are positive, just use them,
1139 // but if any of them is equal to -1, it means that we must find the value for
1140 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1141 // which case -1 is a valid value for x and y)
1143 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1144 // the width/height to best suit our contents, otherwise we reuse the current
1146 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1148 // get the current size and position...
1149 int currentX
, currentY
;
1150 int currentW
, currentH
;
1152 GetPosition(¤tX
, ¤tY
);
1153 GetSize(¤tW
, ¤tH
);
1155 // ... and don't do anything (avoiding flicker) if it's already ok
1156 if ( x
== currentX
&& y
== currentY
&&
1157 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1160 MacRepositionScrollBars() ; // we might have a real position shift
1162 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
1170 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1172 if ( x
== wxDefaultCoord
)
1174 if ( y
== wxDefaultCoord
)
1178 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1180 wxSize size
= wxDefaultSize
;
1181 if ( width
== wxDefaultCoord
)
1183 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1185 size
= DoGetBestSize();
1190 // just take the current one
1195 if ( height
== wxDefaultCoord
)
1197 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1199 if ( size
.x
== wxDefaultCoord
)
1200 size
= DoGetBestSize();
1201 // else: already called DoGetBestSize() above
1207 // just take the current one
1212 DoMoveWindow( x
, y
, width
, height
);
1215 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1217 int left
,top
,width
,height
;
1218 GetPeer()->GetContentArea( left
, top
, width
, height
);
1219 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1222 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1224 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1226 int currentclientwidth
, currentclientheight
;
1227 int currentwidth
, currentheight
;
1229 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1230 GetSize( ¤twidth
, ¤theight
) ;
1232 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1233 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1237 double wxWindowMac::GetContentScaleFactor() const
1239 return GetPeer()->GetContentScaleFactor();
1242 void wxWindowMac::SetLabel(const wxString
& title
)
1244 if ( title
== m_label
)
1249 InvalidateBestSize();
1251 if ( GetPeer() && GetPeer()->IsOk() )
1252 GetPeer()->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1254 // do not trigger refreshes upon invisible and possible partly created objects
1255 if ( IsShownOnScreen() )
1259 wxString
wxWindowMac::GetLabel() const
1264 bool wxWindowMac::Show(bool show
)
1267 MacInvalidateBorders();
1269 if ( !wxWindowBase::Show(show
) )
1273 GetPeer()->SetVisibility( show
) ;
1276 MacInvalidateBorders();
1278 #ifdef __WXOSX_IPHONE__
1279 // only when there's no native event support
1280 if ( !IsTopLevel() )
1283 wxShowEvent
eventShow(GetId(), show
);
1284 eventShow
.SetEventObject(this);
1286 HandleWindowEvent(eventShow
);
1292 bool wxWindowMac::OSXShowWithEffect(bool show
,
1293 wxShowEffect effect
,
1296 if ( effect
== wxSHOW_EFFECT_NONE
||
1297 !GetPeer() || !GetPeer()->ShowWithEffect(show
, effect
, timeout
) )
1303 void wxWindowMac::DoEnable(bool enable
)
1305 GetPeer()->Enable( enable
) ;
1306 MacInvalidateBorders();
1310 // status change notifications
1313 void wxWindowMac::MacVisibilityChanged()
1317 void wxWindowMac::MacHiliteChanged()
1321 void wxWindowMac::MacEnabledStateChanged()
1326 // status queries on the inherited window's state
1329 bool wxWindowMac::MacIsReallyEnabled()
1331 return GetPeer()->IsEnabled() ;
1334 bool wxWindowMac::MacIsReallyHilited()
1336 #if wxOSX_USE_CARBON
1337 return GetPeer()->IsActive();
1339 return true; // TODO
1343 int wxWindowMac::GetCharHeight() const
1346 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1351 int wxWindowMac::GetCharWidth() const
1354 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1359 void wxWindowMac::DoGetTextExtent(const wxString
& str
,
1362 int *externalLeading
,
1363 const wxFont
*theFont
) const
1365 const wxFont
*fontToUse
= theFont
;
1369 tempFont
= GetFont();
1370 fontToUse
= &tempFont
;
1373 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1374 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1376 wxDouble h
, d
, e
, w
;
1377 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1381 if ( externalLeading
)
1382 *externalLeading
= (wxCoord
)(e
+0.5);
1384 *descent
= (wxCoord
)(d
+0.5);
1386 *x
= (wxCoord
)(w
+0.5);
1388 *y
= (wxCoord
)(h
+0.5);
1392 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1393 * we always intersect with the entire window, not only with the client area
1396 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1398 if ( GetPeer() == NULL
)
1401 if ( !IsShownOnScreen() )
1407 GetPeer()->SetNeedsDisplay( rect
) ;
1410 void wxWindowMac::DoFreeze()
1412 if ( GetPeer() && GetPeer()->IsOk() )
1413 GetPeer()->SetDrawingEnabled( false ) ;
1416 void wxWindowMac::DoThaw()
1418 if ( GetPeer() && GetPeer()->IsOk() )
1419 GetPeer()->SetDrawingEnabled( true ) ;
1422 wxWindow
*wxGetActiveWindow()
1424 // actually this is a windows-only concept
1428 // Coordinates relative to the window
1429 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
1431 #if wxOSX_USE_COCOA_OR_CARBON
1434 DoClientToScreen(&x
, &y
);
1435 CGPoint cgpoint
= CGPointMake( x
, y
);
1436 CGWarpMouseCursorPosition( cgpoint
);
1438 // At least GTK sends a mouse moved event after WarpMouse
1439 wxMouseEvent
event(wxEVT_MOTION
);
1442 wxMouseState mState
= ::wxGetMouseState();
1444 event
.m_altDown
= mState
.AltDown();
1445 event
.m_controlDown
= mState
.ControlDown();
1446 event
.m_leftDown
= mState
.LeftIsDown();
1447 event
.m_middleDown
= mState
.MiddleIsDown();
1448 event
.m_rightDown
= mState
.RightIsDown();
1449 event
.m_metaDown
= mState
.MetaDown();
1450 event
.m_shiftDown
= mState
.ShiftDown();
1451 event
.SetId(GetId());
1452 event
.SetEventObject(this);
1453 GetEventHandler()->ProcessEvent(event
);
1457 int wxWindowMac::GetScrollPos(int orient
) const
1460 if ( orient
== wxHORIZONTAL
)
1463 return m_hScrollBar
->GetThumbPosition() ;
1468 return m_vScrollBar
->GetThumbPosition() ;
1474 // This now returns the whole range, not just the number
1475 // of positions that we can scroll.
1476 int wxWindowMac::GetScrollRange(int orient
) const
1479 if ( orient
== wxHORIZONTAL
)
1482 return m_hScrollBar
->GetRange() ;
1487 return m_vScrollBar
->GetRange() ;
1493 int wxWindowMac::GetScrollThumb(int orient
) const
1496 if ( orient
== wxHORIZONTAL
)
1499 return m_hScrollBar
->GetThumbSize() ;
1504 return m_vScrollBar
->GetThumbSize() ;
1510 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1513 if ( orient
== wxHORIZONTAL
)
1516 m_hScrollBar
->SetThumbPosition( pos
) ;
1521 m_vScrollBar
->SetThumbPosition( pos
) ;
1527 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1529 bool needVisibilityUpdate
= false;
1531 if ( m_hScrollBarAlwaysShown
!= hflag
)
1533 m_hScrollBarAlwaysShown
= hflag
;
1534 needVisibilityUpdate
= true;
1537 if ( m_vScrollBarAlwaysShown
!= vflag
)
1539 m_vScrollBarAlwaysShown
= vflag
;
1540 needVisibilityUpdate
= true;
1543 if ( needVisibilityUpdate
)
1544 DoUpdateScrollbarVisibility();
1548 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1549 // our own window origin is at leftOrigin/rightOrigin
1552 void wxWindowMac::MacPaintGrowBox()
1558 if ( MacHasScrollBarCorner() )
1561 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1562 wxASSERT( cgContext
) ;
1566 GetPeer()->GetSize( tw
, th
);
1567 GetPeer()->GetPosition( tx
, ty
);
1569 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1572 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1573 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1574 CGContextSaveGState( cgContext
);
1576 if ( m_backgroundColour
.IsOk() )
1578 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1582 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1584 CGContextFillRect( cgContext
, cgrect
);
1585 CGContextRestoreGState( cgContext
);
1589 if ( m_backgroundColour
.IsOk() )
1590 m_growBox
->SetBackgroundColour(m_backgroundColour
);
1592 m_growBox
->SetBackgroundColour(*wxWHITE
);
1600 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1605 bool hasFocus
= GetPeer()->NeedsFocusRect() && HasFocus();
1607 // back to the surrounding frame rectangle
1610 GetPeer()->GetSize( tw
, th
);
1611 GetPeer()->GetPosition( tx
, ty
);
1613 #if wxOSX_USE_COCOA_OR_CARBON
1616 CGRect cgrect
= CGRectMake( tx
-1 , ty
-1 , tw
+2 ,
1619 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1620 wxASSERT( cgContext
) ;
1622 if ( GetPeer()->NeedsFrame() )
1624 HIThemeFrameDrawInfo info
;
1625 memset( &info
, 0 , sizeof(info
) ) ;
1629 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1630 info
.isFocused
= hasFocus
;
1632 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1634 info
.kind
= kHIThemeFrameTextFieldSquare
;
1635 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1637 else if ( HasFlag(wxSIMPLE_BORDER
) )
1639 info
.kind
= kHIThemeFrameListBox
;
1640 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1646 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1649 #endif // wxOSX_USE_COCOA_OR_CARBON
1652 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1655 if ( child
== m_hScrollBar
)
1656 m_hScrollBar
= NULL
;
1657 if ( child
== m_vScrollBar
)
1658 m_vScrollBar
= NULL
;
1659 if ( child
== m_growBox
)
1662 wxWindowBase::RemoveChild( child
) ;
1665 void wxWindowMac::DoUpdateScrollbarVisibility()
1668 bool triggerSizeEvent
= false;
1672 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1674 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1676 m_hScrollBar
->Show( showHScrollBar
);
1677 triggerSizeEvent
= true;
1683 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1685 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1687 m_vScrollBar
->Show( showVScrollBar
) ;
1688 triggerSizeEvent
= true;
1692 MacRepositionScrollBars() ;
1693 if ( triggerSizeEvent
)
1700 // New function that will replace some of the above.
1701 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1702 int range
, bool refresh
)
1705 // Updating scrollbars when window is being deleted is useless and
1706 // currently results in asserts in client-to-screen coordinates conversion
1707 // code which is used by DoUpdateScrollbarVisibility() so just skip it.
1708 if ( m_isBeingDeleted
)
1711 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1712 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1713 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1714 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1716 DoUpdateScrollbarVisibility();
1720 // Does a physical scroll
1721 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1723 if ( dx
== 0 && dy
== 0 )
1726 int width
, height
;
1727 GetClientSize( &width
, &height
) ;
1730 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1732 scrollrect
.Intersect( *rect
) ;
1733 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1734 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1736 GetPeer()->ScrollRect( &scrollrect
, dx
, dy
);
1741 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1743 child
= node
->GetData();
1747 if (child
->IsTopLevel())
1750 if ( !IsClientAreaChild(child
) )
1753 child
->GetPosition( &x
, &y
);
1754 child
->GetSize( &w
, &h
);
1757 wxRect
rc( x
, y
, w
, h
);
1758 if (rect
->Intersects( rc
))
1759 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1763 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1768 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1771 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1773 wxScrollWinEvent wevent
;
1774 wevent
.SetPosition(event
.GetPosition());
1775 wevent
.SetOrientation(event
.GetOrientation());
1776 wevent
.SetEventObject(this);
1778 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1779 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1780 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1781 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1782 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1783 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1784 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1785 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1786 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1787 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1788 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1789 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1790 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1791 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1792 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1793 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1795 HandleWindowEvent(wevent
);
1800 wxWindow
*wxWindowBase::DoFindFocus()
1802 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
1805 // Raise the window to the top of the Z order
1806 void wxWindowMac::Raise()
1811 // Lower the window to the bottom of the Z order
1812 void wxWindowMac::Lower()
1817 // static wxWindow *gs_lastWhich = NULL;
1819 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1821 // first trigger a set cursor event
1823 wxPoint clientorigin
= GetClientAreaOrigin() ;
1824 wxSize clientsize
= GetClientSize() ;
1826 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1828 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1829 event
.SetId(GetId());
1830 event
.SetEventObject(this);
1832 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1833 if ( processedEvtSetCursor
&& event
.HasCursor() )
1835 cursor
= event
.GetCursor() ;
1839 // the test for processedEvtSetCursor is here to prevent using m_cursor
1840 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1841 // it - this is a way to say that our cursor shouldn't be used for this
1843 if ( !processedEvtSetCursor
&& m_cursor
.IsOk() )
1846 if ( !wxIsBusy() && !GetParent() )
1847 cursor
= *wxSTANDARD_CURSOR
;
1850 if ( cursor
.IsOk() )
1851 cursor
.MacInstall() ;
1854 return cursor
.IsOk() ;
1857 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1861 return m_tooltip
->GetTip() ;
1864 return wxEmptyString
;
1867 void wxWindowMac::ClearBackground()
1873 void wxWindowMac::Update()
1875 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1880 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1882 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1886 if ( iter
->IsTopLevel() )
1888 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1892 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1897 iter
= iter
->GetParent() ;
1903 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1905 MacUpdateClippedRects() ;
1907 return m_cachedClippedClientRect
;
1910 const wxRect
& wxWindowMac::MacGetClippedRect() const
1912 MacUpdateClippedRects() ;
1914 return m_cachedClippedRect
;
1917 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1919 MacUpdateClippedRects() ;
1921 return m_cachedClippedRectWithOuterStructure
;
1924 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1926 static wxRegion emptyrgn
;
1928 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1930 MacUpdateClippedRects() ;
1931 if ( includeOuterStructures
)
1932 return m_cachedClippedRegionWithOuterStructure
;
1934 return m_cachedClippedRegion
;
1942 void wxWindowMac::MacUpdateClippedRects() const
1944 #if wxOSX_USE_CARBON
1945 if ( m_cachedClippedRectValid
)
1948 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1949 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1950 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1951 // to add focus borders everywhere
1953 Rect rIncludingOuterStructures
;
1957 GetPeer()->GetSize( tw
, th
);
1958 GetPeer()->GetPosition( tx
, ty
);
1960 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1962 r
.left
-= MacGetLeftBorderSize() ;
1963 r
.top
-= MacGetTopBorderSize() ;
1964 r
.bottom
+= MacGetBottomBorderSize() ;
1965 r
.right
+= MacGetRightBorderSize() ;
1972 rIncludingOuterStructures
= r
;
1973 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1975 wxRect cl
= GetClientRect() ;
1976 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1980 const wxWindow
* child
= (wxWindow
*) this ;
1981 const wxWindow
* parent
= NULL
;
1983 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1985 if ( parent
->MacIsChildOfClientArea(child
) )
1987 size
= parent
->GetClientSize() ;
1988 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1994 // this will be true for scrollbars, toolbars etc.
1995 size
= parent
->GetSize() ;
1996 y
= parent
->MacGetTopBorderSize() ;
1997 x
= parent
->MacGetLeftBorderSize() ;
1998 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1999 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2002 parent
->MacWindowToRootWindow( &x
, &y
) ;
2003 MacRootWindowToWindow( &x
, &y
) ;
2005 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2007 // the wxwindow and client rects will always be clipped
2008 SectRect( &r
, &rparent
, &r
) ;
2009 SectRect( &rClient
, &rparent
, &rClient
) ;
2011 // the structure only at 'hard' borders
2012 if ( parent
->MacClipChildren() ||
2013 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2015 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2021 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2022 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2023 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2024 m_cachedClippedRectWithOuterStructure
= wxRect(
2025 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2026 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2027 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2029 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2030 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2031 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2033 m_cachedClippedRectValid
= true ;
2038 This function must not change the updatergn !
2040 bool wxWindowMac::MacDoRedraw( long time
)
2042 bool handled
= false ;
2044 wxRegion formerUpdateRgn
= m_updateRegion
;
2045 wxRegion clientUpdateRgn
= formerUpdateRgn
;
2047 const wxRect clientRect
= GetClientRect();
2049 clientUpdateRgn
.Intersect(clientRect
);
2051 // first send an erase event to the entire update area
2052 const wxBackgroundStyle bgStyle
= GetBackgroundStyle();
2055 case wxBG_STYLE_ERASE
:
2056 case wxBG_STYLE_SYSTEM
:
2057 case wxBG_STYLE_COLOUR
:
2059 // for the toplevel window this really is the entire area for
2060 // all the others only their client area, otherwise they might
2061 // be drawing with full alpha and eg put blue into the grow-box
2062 // area of a scrolled window (scroll sample)
2063 wxWindowDC
dc(this);
2065 dc
.SetDeviceClippingRegion(formerUpdateRgn
);
2067 dc
.SetDeviceClippingRegion(clientUpdateRgn
);
2069 if ( bgStyle
== wxBG_STYLE_ERASE
)
2071 wxEraseEvent
eevent( GetId(), &dc
);
2072 eevent
.SetEventObject( this );
2073 if ( ProcessWindowEvent( eevent
) )
2079 dc
.SetBackground(GetBackgroundColour());
2085 case wxBG_STYLE_PAINT
:
2086 case wxBG_STYLE_TRANSPARENT
:
2087 // nothing to do, user-defined EVT_PAINT handler will overwrite the
2088 // entire window client area
2092 wxFAIL_MSG( "unsupported background style" );
2095 // as this is a full window, shouldn't be necessary anymore
2096 // MacPaintGrowBox();
2098 // calculate a client-origin version of the update rgn and set
2099 // m_updateRegion to that
2100 clientUpdateRgn
.Offset(-clientRect
.GetPosition());
2101 m_updateRegion
= clientUpdateRgn
;
2103 if ( !m_updateRegion
.Empty() )
2105 // paint the window itself
2107 wxPaintEvent
event(GetId());
2108 event
.SetTimestamp(time
);
2109 event
.SetEventObject(this);
2110 handled
= HandleWindowEvent(event
);
2113 m_updateRegion
= formerUpdateRgn
;
2115 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
2117 top
->WindowWasPainted() ;
2122 void wxWindowMac::MacPaintChildrenBorders()
2124 // now we cannot rely on having its borders drawn by a window itself, as it does not
2125 // get the updateRgn wide enough to always do so, so we do it from the parent
2126 // this would also be the place to draw any custom backgrounds for native controls
2127 // in Composited windowing
2128 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2132 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2134 child
= node
->GetData();
2138 if (child
== m_vScrollBar
)
2140 if (child
== m_hScrollBar
)
2142 if (child
== m_growBox
)
2145 if (child
->IsTopLevel())
2147 if (!child
->IsShown())
2150 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2152 child
->GetPosition( &x
, &y
);
2153 child
->GetSize( &w
, &h
);
2155 if ( m_updateRegion
.Contains(clientOrigin
.x
+x
-10, clientOrigin
.y
+y
-10, w
+20, h
+20) )
2157 // paint custom borders
2158 wxNcPaintEvent
eventNc( child
->GetId() );
2159 eventNc
.SetEventObject( child
);
2160 if ( !child
->HandleWindowEvent( eventNc
) )
2162 child
->MacPaintBorders(0, 0) ;
2169 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2171 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
2172 return tlw
? tlw
->GetWXWindow() : NULL
;
2175 bool wxWindowMac::MacHasScrollBarCorner() const
2178 /* Returns whether the scroll bars in a wxScrolledWindow should be
2179 * shortened. Scroll bars should be shortened if either:
2181 * - both scroll bars are visible, or
2183 * - there is a resize box in the parent frame's corner and this
2184 * window shares the bottom and right edge with the parent
2188 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
2191 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
2192 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
2194 // Both scroll bars visible
2199 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
2201 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
2203 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
2206 // starting from 10.7 there are no resize indicators anymore
2207 if ( (frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
) && UMAGetSystemVersion() < 0x1070)
2209 // Parent frame has resize handle
2210 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
2212 // Note: allow for some wiggle room here as wxMac's
2213 // window rect calculations seem to be imprecise
2214 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
2215 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
2217 // Parent frame has resize handle and shares
2218 // right bottom corner
2223 // Parent frame has resize handle but doesn't
2224 // share right bottom corner
2230 // Parent frame doesn't have resize handle
2236 // No parent frame found
2244 void wxWindowMac::MacCreateScrollBars( long style
)
2247 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2249 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2251 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2252 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2254 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2257 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2259 GetClientSize( &width
, &height
) ;
2261 wxPoint
vPoint(width
- scrlsize
, 0) ;
2262 wxSize
vSize(scrlsize
, height
- adjust
) ;
2263 wxPoint
hPoint(0, height
- scrlsize
) ;
2264 wxSize
hSize(width
- adjust
, scrlsize
) ;
2266 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2267 if ( style
& wxVSCROLL
)
2269 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2270 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2273 if ( style
& wxHSCROLL
)
2275 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2276 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2279 wxPoint
gPoint(width
- scrlsize
, height
- scrlsize
);
2280 wxSize
gSize(scrlsize
, scrlsize
);
2281 m_growBox
= new wxBlindPlateWindow((wxWindow
*)this, wxID_ANY
, gPoint
, gSize
, 0);
2284 // because the create does not take into account the client area origin
2285 // we might have a real position shift
2286 MacRepositionScrollBars() ;
2290 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2292 bool result
= ((child
== NULL
)
2294 || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
) && (child
!= m_growBox
))
2301 void wxWindowMac::MacRepositionScrollBars()
2304 if ( !m_hScrollBar
&& !m_vScrollBar
)
2307 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2308 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2310 // get real client area
2312 GetSize( &width
, &height
);
2314 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2315 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2317 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2318 wxSize
vSize( scrlsize
, height
- adjust
) ;
2319 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2320 wxSize
hSize( width
- adjust
, scrlsize
) ;
2323 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2325 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2328 if ( MacHasScrollBarCorner() )
2330 m_growBox
->SetSize( width
- scrlsize
, height
- scrlsize
, wxDefaultCoord
, wxDefaultCoord
, wxSIZE_USE_EXISTING
);
2331 if ( !m_growBox
->IsShown() )
2336 if ( m_growBox
->IsShown() )
2343 bool wxWindowMac::AcceptsFocus() const
2345 if ( GetPeer() == NULL
|| GetPeer()->IsUserPane() )
2346 return wxWindowBase::AcceptsFocus();
2348 return GetPeer()->CanFocus();
2351 void wxWindowMac::MacSuperChangedPosition()
2353 // only window-absolute structures have to be moved i.e. controls
2355 m_cachedClippedRectValid
= false ;
2358 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2361 child
= node
->GetData();
2362 child
->MacSuperChangedPosition() ;
2364 node
= node
->GetNext();
2368 void wxWindowMac::MacTopLevelWindowChangedPosition()
2370 // only screen-absolute structures have to be moved i.e. glcanvas
2373 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2376 child
= node
->GetData();
2377 child
->MacTopLevelWindowChangedPosition() ;
2379 node
= node
->GetNext();
2383 long wxWindowMac::MacGetWXBorderSize() const
2390 if ( GetPeer() && GetPeer()->NeedsFrame() )
2392 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2394 #if wxOSX_USE_COCOA_OR_CARBON
2395 // this metric is only the 'outset' outside the simple frame rect
2396 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2402 else if (HasFlag(wxSIMPLE_BORDER
))
2404 #if wxOSX_USE_COCOA_OR_CARBON
2405 // this metric is only the 'outset' outside the simple frame rect
2406 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2417 long wxWindowMac::MacGetLeftBorderSize() const
2419 // the wx borders are all symmetric in mac themes
2420 long border
= MacGetWXBorderSize() ;
2424 int left
, top
, right
, bottom
;
2425 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2433 long wxWindowMac::MacGetRightBorderSize() const
2435 // the wx borders are all symmetric in mac themes
2436 long border
= MacGetWXBorderSize() ;
2440 int left
, top
, right
, bottom
;
2441 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2448 long wxWindowMac::MacGetTopBorderSize() const
2450 // the wx borders are all symmetric in mac themes
2451 long border
= MacGetWXBorderSize() ;
2455 int left
, top
, right
, bottom
;
2456 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2463 long wxWindowMac::MacGetBottomBorderSize() const
2465 // the wx borders are all symmetric in mac themes
2466 long border
= MacGetWXBorderSize() ;
2470 int left
, top
, right
, bottom
;
2471 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2478 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2480 return style
& ~wxBORDER_MASK
;
2483 // Find the wxWindowMac at the current mouse position, returning the mouse
2485 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2487 pt
= wxGetMousePosition();
2488 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2490 return (wxWindow
*) found
;
2493 // Get the current mouse position.
2494 wxPoint
wxGetMousePosition()
2498 wxGetMousePosition( &x
, &y
);
2500 return wxPoint(x
, y
);
2503 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2505 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2507 // copied from wxGTK : CS
2508 // VZ: shouldn't we move this to base class then?
2510 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2513 // (a) it's a command event and so is propagated to the parent
2514 // (b) under MSW it can be generated from kbd too
2515 // (c) it uses screen coords (because of (a))
2516 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2518 this->ClientToScreen(event
.GetPosition()));
2519 evtCtx
.SetEventObject(this);
2520 if ( ! HandleWindowEvent(evtCtx
) )
2529 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2533 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2537 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2538 Rect bounds
= { static_cast<short>(y
), static_cast<short>(x
), static_cast<short>(y
+ h
), static_cast<short>(x
+ w
) };
2543 bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec
) )
2548 void *wxWindowMac::OSXGetViewOrWindow() const
2553 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2555 #if wxOSX_USE_COCOA_OR_CARBON
2556 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2559 return eventNotHandledErr
;
2565 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2567 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2568 if ( !wxWindowBase::Reparent(newParent
) )
2571 GetPeer()->RemoveFromParent();
2572 GetPeer()->Embed( GetParent()->GetPeer() );
2578 bool wxWindowMac::SetTransparent(wxByte alpha
)
2580 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2582 if ( alpha
!= m_macAlpha
)
2584 m_macAlpha
= alpha
;
2591 bool wxWindowMac::CanSetTransparent()
2596 wxByte
wxWindowMac::GetTransparent() const
2601 bool wxWindowMac::IsShownOnScreen() const
2603 if ( GetPeer() && GetPeer()->IsOk() )
2605 bool peerVis
= GetPeer()->IsVisible();
2606 bool wxVis
= wxWindowBase::IsShownOnScreen();
2607 if( peerVis
!= wxVis
)
2609 // CS : put a breakpoint here to investigate differences
2610 // between native an wx visibilities
2611 // the only place where I've encountered them until now
2612 // are the hiding/showing sequences where the vis-changed event is
2613 // first sent to the innermost control, while wx does things
2614 // from the outmost control
2615 wxVis
= wxWindowBase::IsShownOnScreen();
2619 return GetPeer()->IsVisible();
2621 return wxWindowBase::IsShownOnScreen();
2624 #if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
2627 wxHotKeyHandler(EventHandlerCallRef
WXUNUSED(nextHandler
),
2629 void* WXUNUSED(userData
))
2631 EventHotKeyID hotKeyId
;
2633 GetEventParameter( event
, kEventParamDirectObject
, typeEventHotKeyID
, NULL
, sizeof(hotKeyId
), NULL
, &hotKeyId
);
2635 for ( unsigned i
= 0; i
< s_hotkeys
.size(); ++i
)
2637 if ( s_hotkeys
[i
].keyId
== static_cast<int>(hotKeyId
.id
) )
2639 unsigned char charCode
;
2642 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
2644 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
2645 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
2646 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
2648 UInt32 keymessage
= (keyCode
<< 8) + charCode
;
2650 wxKeyEvent
wxevent(wxEVT_HOTKEY
);
2651 wxevent
.SetId(hotKeyId
.id
);
2652 wxTheApp
->MacCreateKeyEvent( wxevent
, s_hotkeys
[i
].window
, keymessage
,
2653 modifiers
, when
, 0 ) ;
2655 s_hotkeys
[i
].window
->HandleWindowEvent(wxevent
);
2662 bool wxWindowMac::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
2664 for ( unsigned i
= 0; i
< s_hotkeys
.size(); ++i
)
2666 if ( s_hotkeys
[i
].keyId
== hotkeyId
)
2668 wxLogLastError(wxT("hotkeyId already registered"));
2674 static bool installed
= false;
2677 EventTypeSpec eventType
;
2678 eventType
.eventClass
=kEventClassKeyboard
;
2679 eventType
.eventKind
=kEventHotKeyPressed
;
2681 InstallApplicationEventHandler(&wxHotKeyHandler
, 1, &eventType
, NULL
, NULL
);
2685 UInt32 mac_modifiers
=0;
2686 if ( modifiers
& wxMOD_ALT
)
2687 mac_modifiers
|= optionKey
;
2688 if ( modifiers
& wxMOD_SHIFT
)
2689 mac_modifiers
|= shiftKey
;
2690 if ( modifiers
& wxMOD_RAW_CONTROL
)
2691 mac_modifiers
|= controlKey
;
2692 if ( modifiers
& wxMOD_CONTROL
)
2693 mac_modifiers
|= cmdKey
;
2695 EventHotKeyRef hotKeyRef
;
2696 EventHotKeyID hotKeyIDmac
;
2698 hotKeyIDmac
.signature
= 'WXMC';
2699 hotKeyIDmac
.id
= hotkeyId
;
2701 if ( RegisterEventHotKey(wxCharCodeWXToOSX((wxKeyCode
)keycode
), mac_modifiers
, hotKeyIDmac
,
2702 GetApplicationEventTarget(), 0, &hotKeyRef
) != noErr
)
2704 wxLogLastError(wxT("RegisterHotKey"));
2715 s_hotkeys
.push_back(v
);
2721 bool wxWindowMac::UnregisterHotKey(int hotkeyId
)
2723 for ( int i
= ((int)s_hotkeys
.size())-1; i
>=0; -- i
)
2725 if ( s_hotkeys
[i
].keyId
== hotkeyId
)
2727 EventHotKeyRef ref
= s_hotkeys
[i
].ref
;
2728 s_hotkeys
.erase(s_hotkeys
.begin() + i
);
2729 if ( UnregisterEventHotKey(ref
) != noErr
)
2731 wxLogLastError(wxT("UnregisterHotKey"));
2743 #endif // wxUSE_HOTKEY
2745 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2747 bool handled
= false;
2749 // moved the ordinary key event sending AFTER the accel evaluation
2752 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2754 wxWindow
*ancestor
= this;
2757 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2760 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2762 wxCommandEvent
command_event( wxEVT_MENU
, command
);
2763 handled
= handler
->ProcessEvent( command_event
);
2767 // accelerators can also be used with buttons, try them too
2768 command_event
.SetEventType(wxEVT_BUTTON
);
2769 handled
= handler
->ProcessEvent( command_event
);
2775 if (ancestor
->IsTopLevel())
2778 ancestor
= ancestor
->GetParent();
2781 #endif // wxUSE_ACCEL
2785 handled
= HandleWindowEvent( event
) ;
2786 if ( handled
&& event
.GetSkipped() )
2797 // we are maintaining a n:1 map from native controls (ControlRef / NSView*) to their wxWidgetImpl
2798 // n:1 because we might have an embedded view eg within a scrollview, both being part of the same impl
2799 // the impl is calling Associate with its newly created native control(s), e.g. in InstallHandler
2801 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2803 static MacControlMap wxWinMacControlList
;
2805 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2807 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2809 return impl
->GetWXPeer();
2814 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2816 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2818 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2821 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2823 // adding NULL ControlRef is (first) surely a result of an error and
2824 // (secondly) breaks native event processing
2825 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2827 wxWinMacControlList
[inControl
] = impl
;
2830 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2832 // iterate over all the elements in the class
2833 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2834 // we should go on...
2840 MacControlMap::iterator it
;
2841 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2843 if ( it
->second
== impl
)
2845 wxWinMacControlList
.erase(it
);
2853 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2855 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
, bool isUserPane
)
2858 m_isRootControl
= isRootControl
;
2859 m_isUserPane
= isUserPane
;
2861 m_shouldSendEvents
= true;
2864 wxWidgetImpl::wxWidgetImpl()
2869 wxWidgetImpl::~wxWidgetImpl()
2873 void wxWidgetImpl::Init()
2875 m_isRootControl
= false;
2877 m_needsFocusRect
= false;
2878 m_needsFrame
= true;
2881 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2883 m_needsFocusRect
= needs
;
2886 bool wxWidgetImpl::NeedsFocusRect() const
2888 return m_needsFocusRect
;
2891 void wxWidgetImpl::SetNeedsFrame( bool needs
)
2893 m_needsFrame
= needs
;
2896 bool wxWidgetImpl::NeedsFrame() const
2898 return m_needsFrame
;
2901 void wxWidgetImpl::SetDrawingEnabled(bool WXUNUSED(enabled
))