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 bool wxWindowMac::ShouldCreatePeer() const
306 return m_peer
!= kOSXNoWidgetImpl
;
309 void wxWindowMac::DontCreatePeer()
311 m_peer
= kOSXNoWidgetImpl
;
314 void wxWindowMac::SetWrappingPeer(wxOSXWidgetImpl
* wrapper
)
316 wxOSXWidgetImpl
* inner
= GetPeer();
317 wxASSERT_MSG( inner
!= NULL
&& inner
->IsOk(), "missing or incomplete inner peer" );
318 wxASSERT_MSG( wrapper
!= NULL
&& wrapper
->IsOk(), "missing or incomplete wrapper" );
320 if ( !(inner
!= NULL
&& inner
->IsOk() && wrapper
!= NULL
&& wrapper
->IsOk()) )
323 inner
->RemoveFromParent();
324 wrapper
->InstallEventHandler();
325 wrapper
->Embed(inner
);
329 void wxWindowMac::SetPeer(wxOSXWidgetImpl
* peer
)
333 if ( !GetPeer()->IsRootControl() )
334 GetPeer()->RemoveFromParent();
340 if ( GetPeer() && !GetPeer()->IsRootControl())
342 wxASSERT_MSG( GetPeer()->IsOk() , wxT("The native control must exist already") ) ;
344 if (!GetParent()->GetChildren().Find((wxWindow
*)this))
345 GetParent()->AddChild( this );
347 GetPeer()->InstallEventHandler();
348 GetPeer()->Embed(GetParent()->GetPeer());
350 GetParent()->MacChildAdded() ;
352 // adjust font, controlsize etc
353 DoSetWindowVariant( m_windowVariant
) ;
355 GetPeer()->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
357 // for controls we want to use best size for wxDefaultSize params )
358 if ( !GetPeer()->IsUserPane() )
359 SetInitialSize(GetMinSize());
361 SetCursor( *wxSTANDARD_CURSOR
) ;
365 #if WXWIN_COMPATIBILITY_2_8
367 bool wxWindowMac::MacIsUserPane()
369 return GetPeer() == NULL
|| GetPeer()->IsUserPane();
374 bool wxWindowMac::MacIsUserPane() const
376 return GetPeer() == NULL
|| GetPeer()->IsUserPane();
379 // ---------------------------------------------------------------------------
380 // Utility Routines to move between different coordinate systems
381 // ---------------------------------------------------------------------------
384 * Right now we have the following setup :
385 * a border that is not part of the native control is always outside the
386 * control's border (otherwise we loose all native intelligence, future ways
387 * may be to have a second embedding control responsible for drawing borders
388 * and backgrounds eventually)
389 * so all this border calculations have to be taken into account when calling
390 * native methods or getting native oriented data
391 * so we have three coordinate systems here
392 * wx client coordinates
393 * wx window coordinates (including window frames)
401 bool wxWindowMac::Create(wxWindowMac
*parent
,
406 const wxString
& name
)
408 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
410 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
413 m_windowVariant
= parent
->GetWindowVariant() ;
415 if ( m_peer
!= kOSXNoWidgetImpl
)
417 SetPeer(wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() ));
418 MacPostControlCreate(pos
, size
) ;
421 #ifndef __WXUNIVERSAL__
422 // Don't give scrollbars to wxControls unless they ask for them
423 if ( (! IsKindOf(CLASSINFO(wxControl
))
425 && ! IsKindOf(CLASSINFO(wxStatusBar
))
428 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
430 MacCreateScrollBars( style
) ;
434 wxWindowCreateEvent
event((wxWindow
*)this);
435 GetEventHandler()->AddPendingEvent(event
);
440 void wxWindowMac::MacChildAdded()
444 m_vScrollBar
->Raise() ;
446 m_hScrollBar
->Raise() ;
452 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
),
453 const wxSize
& WXUNUSED(size
))
455 // todo remove if refactoring works correctly
457 wxASSERT_MSG( GetPeer() != NULL
&& GetPeer()->IsOk() , wxT("No valid mac control") ) ;
459 if (!GetParent()->GetChildren().Find((wxWindow
*)this))
460 GetParent()->AddChild( this );
462 GetPeer()->InstallEventHandler();
463 GetPeer()->Embed(GetParent()->GetPeer());
465 GetParent()->MacChildAdded() ;
467 // adjust font, controlsize etc
468 DoSetWindowVariant( m_windowVariant
) ;
470 GetPeer()->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
472 // for controls we want to use best size for wxDefaultSize params )
473 if ( !GetPeer()->IsUserPane() )
474 SetInitialSize(size
);
476 SetCursor( *wxSTANDARD_CURSOR
) ;
480 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
482 // Don't assert, in case we set the window variant before
483 // the window is created
484 // wxASSERT( GetPeer()->IsOk() ) ;
486 m_windowVariant
= variant
;
488 if (GetPeer() == NULL
|| !GetPeer()->IsOk())
491 GetPeer()->SetControlSize( variant
);
495 case wxWINDOW_VARIANT_NORMAL
:
496 static wxFont
sysNormal(wxOSX_SYSTEM_FONT_NORMAL
);
500 case wxWINDOW_VARIANT_SMALL
:
501 static wxFont
sysSmall(wxOSX_SYSTEM_FONT_SMALL
);
505 case wxWINDOW_VARIANT_MINI
:
506 static wxFont
sysMini(wxOSX_SYSTEM_FONT_MINI
);
510 case wxWINDOW_VARIANT_LARGE
:
511 static wxFont
sysLarge(wxOSX_SYSTEM_FONT_NORMAL
);
516 wxFAIL_MSG(wxT("unexpected window variant"));
521 void wxWindowMac::MacUpdateControlFont()
524 GetPeer()->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
526 // do not trigger refreshes upon invisible and possible partly created objects
527 if ( IsShownOnScreen() )
531 bool wxWindowMac::SetFont(const wxFont
& font
)
533 bool retval
= wxWindowBase::SetFont( font
);
535 MacUpdateControlFont() ;
540 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
542 bool retval
= wxWindowBase::SetForegroundColour( col
);
545 MacUpdateControlFont();
550 bool wxWindowMac::SetBackgroundStyle(wxBackgroundStyle style
)
552 if ( !wxWindowBase::SetBackgroundStyle(style
) )
556 GetPeer()->SetBackgroundStyle(style
);
560 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
564 if ( m_backgroundColour
.IsOk() )
565 m_growBox
->SetBackgroundColour(m_backgroundColour
);
567 m_growBox
->SetBackgroundColour(*wxWHITE
);
570 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
574 GetPeer()->SetBackgroundColour( col
) ;
579 static bool wxIsWindowOrParentDisabled(wxWindow
* w
)
581 while (w
&& !w
->IsTopLevel())
590 void wxWindowMac::SetFocus()
592 if ( !AcceptsFocus() )
595 if (wxIsWindowOrParentDisabled((wxWindow
*) this))
598 wxWindow
* former
= FindFocus() ;
599 if ( former
== this )
602 GetPeer()->SetFocus() ;
605 void wxWindowMac::DoCaptureMouse()
607 wxApp::s_captureWindow
= (wxWindow
*) this ;
608 GetPeer()->CaptureMouse() ;
611 wxWindow
* wxWindowBase::GetCapture()
613 return wxApp::s_captureWindow
;
616 void wxWindowMac::DoReleaseMouse()
618 wxApp::s_captureWindow
= NULL
;
620 GetPeer()->ReleaseMouse() ;
623 #if wxUSE_DRAG_AND_DROP
625 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
629 m_dropTarget
= pDropTarget
;
631 GetPeer()->SetDropTarget(m_dropTarget
) ;
636 // Old-style File Manager Drag & Drop
637 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
642 // From a wx position / size calculate the appropriate size of the native control
644 bool wxWindowMac::MacGetBoundsForControl(
648 int& w
, int& h
, bool adjustOrigin
) const
650 // the desired size, minus the border pixels gives the correct size of the control
654 w
= WidthDefault( size
.x
);
655 h
= HeightDefault( size
.y
);
657 x
+= MacGetLeftBorderSize() ;
658 y
+= MacGetTopBorderSize() ;
659 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
660 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
663 AdjustForParentClientOrigin( x
, y
) ;
665 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
666 if ( GetParent() && !GetParent()->IsTopLevel() )
668 x
-= GetParent()->MacGetLeftBorderSize() ;
669 y
-= GetParent()->MacGetTopBorderSize() ;
675 // Get window size (not client size)
676 void wxWindowMac::DoGetSize(int *x
, int *y
) const
679 GetPeer()->GetSize( width
, height
);
682 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
684 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
687 // get the position of the bounds of this window in client coordinates of its parent
688 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
692 GetPeer()->GetPosition( x1
, y1
) ;
694 // get the wx window position from the native one
695 x1
-= MacGetLeftBorderSize() ;
696 y1
-= MacGetTopBorderSize() ;
700 wxWindow
*parent
= GetParent();
703 // we must first adjust it to be in window coordinates of the parent,
704 // as otherwise it gets lost by the ClientAreaOrigin fix
705 x1
+= parent
->MacGetLeftBorderSize() ;
706 y1
+= parent
->MacGetTopBorderSize() ;
708 // and now to client coordinates
709 wxPoint
pt(parent
->GetClientAreaOrigin());
721 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
723 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
724 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
725 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
726 MacRootWindowToWindow( x
, y
) ;
728 wxPoint origin
= GetClientAreaOrigin() ;
735 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
737 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
738 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
740 wxPoint origin
= GetClientAreaOrigin() ;
746 MacWindowToRootWindow( x
, y
) ;
747 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
750 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
752 wxPoint origin
= GetClientAreaOrigin() ;
758 MacWindowToRootWindow( x
, y
) ;
761 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
772 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
775 pt
.x
-= MacGetLeftBorderSize() ;
776 pt
.y
-= MacGetTopBorderSize() ;
777 wxWidgetImpl::Convert( &pt
, GetPeer() , top
->GetPeer() ) ;
787 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
798 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
801 wxWidgetImpl::Convert( &pt
, top
->GetPeer() , GetPeer() ) ;
802 pt
.x
+= MacGetLeftBorderSize() ;
803 pt
.y
+= MacGetTopBorderSize() ;
813 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
815 wxSize sizeTotal
= size
;
817 int innerwidth
, innerheight
;
819 int outerwidth
, outerheight
;
821 GetPeer()->GetContentArea( left
, top
, innerwidth
, innerheight
);
822 GetPeer()->GetSize( outerwidth
, outerheight
);
824 sizeTotal
.x
+= outerwidth
-innerwidth
;
825 sizeTotal
.y
+= outerheight
-innerheight
;
827 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
828 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
833 // Get size *available for subwindows* i.e. excluding menu bar etc.
834 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
840 GetPeer()->GetContentArea( left
, top
, ww
, hh
);
842 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
843 hh
-= m_hScrollBar
->GetSize().y
;
845 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
846 ww
-= m_vScrollBar
->GetSize().x
;
855 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
857 if (m_cursor
.IsSameAs(cursor
))
862 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
867 if ( ! wxWindowBase::SetCursor( cursor
) )
871 wxASSERT_MSG( m_cursor
.IsOk(),
872 wxT("cursor must be valid after call to the base version"));
874 if ( GetPeer() != NULL
)
875 GetPeer()->SetCursor( m_cursor
);
881 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
883 #ifndef __WXUNIVERSAL__
886 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
888 wxPoint mouse
= wxGetMousePosition();
894 ClientToScreen( &x
, &y
) ;
896 menu
->GetPeer()->PopUp(this, x
, y
);
899 // actually this shouldn't be called, because universal is having its own implementation
905 // ----------------------------------------------------------------------------
907 // ----------------------------------------------------------------------------
911 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
913 wxWindowBase::DoSetToolTip(tooltip
);
916 m_tooltip
->SetWindow(this);
919 GetPeer()->SetToolTip(tooltip
);
924 void wxWindowMac::MacInvalidateBorders()
926 if ( GetPeer() == NULL
)
929 bool vis
= IsShownOnScreen() ;
933 int outerBorder
= MacGetLeftBorderSize() ;
935 if ( GetPeer()->NeedsFocusRect() )
938 if ( outerBorder
== 0 )
941 // now we know that we have something to do at all
945 GetPeer()->GetSize( tw
, th
);
946 GetPeer()->GetPosition( tx
, ty
);
948 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
949 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
950 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
951 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
954 GetParent()->GetPeer()->SetNeedsDisplay(&leftupdate
);
955 GetParent()->GetPeer()->SetNeedsDisplay(&rightupdate
);
956 GetParent()->GetPeer()->SetNeedsDisplay(&topupdate
);
957 GetParent()->GetPeer()->SetNeedsDisplay(&bottomupdate
);
961 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
963 // this is never called for a toplevel window, so we know we have a parent
964 int former_x
, former_y
, former_w
, former_h
;
966 // Get true coordinates of former position
967 DoGetPosition( &former_x
, &former_y
) ;
968 DoGetSize( &former_w
, &former_h
) ;
970 wxWindow
*parent
= GetParent();
973 wxPoint
pt(parent
->GetClientAreaOrigin());
978 int actualWidth
= width
;
979 int actualHeight
= height
;
984 // min and max sizes are only for sizers, not for explicit size setting
985 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
986 actualWidth
= m_minWidth
;
987 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
988 actualHeight
= m_minHeight
;
989 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
990 actualWidth
= m_maxWidth
;
991 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
992 actualHeight
= m_maxHeight
;
995 bool doMove
= false, doResize
= false ;
997 if ( actualX
!= former_x
|| actualY
!= former_y
)
1000 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1003 if ( doMove
|| doResize
)
1005 // as the borders are drawn outside the native control, we adjust now
1007 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1008 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1009 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1011 if ( parent
&& !parent
->IsTopLevel() )
1013 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
1016 MacInvalidateBorders() ;
1018 m_cachedClippedRectValid
= false ;
1020 GetPeer()->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
1022 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1024 MacInvalidateBorders() ;
1026 MacRepositionScrollBars() ;
1029 wxPoint
point(actualX
, actualY
);
1030 wxMoveEvent
event(point
, m_windowId
);
1031 event
.SetEventObject(this);
1032 HandleWindowEvent(event
) ;
1037 MacRepositionScrollBars() ;
1038 MacOnInternalSize();
1039 wxSize
size(actualWidth
, actualHeight
);
1040 wxSizeEvent
event(size
, m_windowId
);
1041 event
.SetEventObject(this);
1042 HandleWindowEvent(event
);
1047 wxSize
wxWindowMac::DoGetBestSize() const
1049 if ( GetPeer() == NULL
|| GetPeer()->IsUserPane() || IsTopLevel() )
1051 return wxWindowBase::DoGetBestSize() ;
1057 GetPeer()->GetBestRect(&r
);
1059 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
1067 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1074 if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1081 // return wxWindowBase::DoGetBestSize() ;
1085 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
1086 MacGetRightBorderSize();
1087 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
1088 MacGetBottomBorderSize();
1089 if ( bestHeight
< 10 )
1092 return wxSize(bestWidth
, bestHeight
);
1096 // set the size of the window: if the dimensions are positive, just use them,
1097 // but if any of them is equal to -1, it means that we must find the value for
1098 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1099 // which case -1 is a valid value for x and y)
1101 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1102 // the width/height to best suit our contents, otherwise we reuse the current
1104 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1106 // get the current size and position...
1107 int currentX
, currentY
;
1108 int currentW
, currentH
;
1110 GetPosition(¤tX
, ¤tY
);
1111 GetSize(¤tW
, ¤tH
);
1113 // ... and don't do anything (avoiding flicker) if it's already ok
1114 if ( x
== currentX
&& y
== currentY
&&
1115 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1118 MacRepositionScrollBars() ; // we might have a real position shift
1120 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
1122 MacOnInternalSize();
1123 wxSizeEvent
event( wxSize(width
,height
), GetId() );
1124 event
.SetEventObject( this );
1125 HandleWindowEvent( event
);
1131 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1133 if ( x
== wxDefaultCoord
)
1135 if ( y
== wxDefaultCoord
)
1139 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1141 wxSize size
= wxDefaultSize
;
1142 if ( width
== wxDefaultCoord
)
1144 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1146 size
= DoGetBestSize();
1151 // just take the current one
1156 if ( height
== wxDefaultCoord
)
1158 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1160 if ( size
.x
== wxDefaultCoord
)
1161 size
= DoGetBestSize();
1162 // else: already called DoGetBestSize() above
1168 // just take the current one
1173 DoMoveWindow( x
, y
, width
, height
);
1176 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1178 int left
,top
,width
,height
;
1179 GetPeer()->GetContentArea( left
, top
, width
, height
);
1180 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1183 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1185 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1187 int currentclientwidth
, currentclientheight
;
1188 int currentwidth
, currentheight
;
1190 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1191 GetSize( ¤twidth
, ¤theight
) ;
1193 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1194 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1198 float wxWindowMac::GetContentScaleFactor() const
1200 return GetPeer()->GetContentScaleFactor();
1203 void wxWindowMac::SetLabel(const wxString
& title
)
1205 if ( title
== m_label
)
1210 InvalidateBestSize();
1212 if ( GetPeer() && GetPeer()->IsOk() )
1213 GetPeer()->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1215 // do not trigger refreshes upon invisible and possible partly created objects
1216 if ( IsShownOnScreen() )
1220 wxString
wxWindowMac::GetLabel() const
1225 bool wxWindowMac::Show(bool show
)
1228 MacInvalidateBorders();
1230 if ( !wxWindowBase::Show(show
) )
1234 GetPeer()->SetVisibility( show
) ;
1237 MacInvalidateBorders();
1239 #ifdef __WXOSX_IPHONE__
1240 // only when there's no native event support
1241 if ( !IsTopLevel() )
1244 wxShowEvent
eventShow(GetId(), show
);
1245 eventShow
.SetEventObject(this);
1247 HandleWindowEvent(eventShow
);
1253 bool wxWindowMac::OSXShowWithEffect(bool show
,
1254 wxShowEffect effect
,
1257 if ( effect
== wxSHOW_EFFECT_NONE
||
1258 !GetPeer() || !GetPeer()->ShowWithEffect(show
, effect
, timeout
) )
1264 void wxWindowMac::DoEnable(bool enable
)
1266 GetPeer()->Enable( enable
) ;
1267 MacInvalidateBorders();
1271 // status change notifications
1274 void wxWindowMac::MacVisibilityChanged()
1278 void wxWindowMac::MacHiliteChanged()
1282 void wxWindowMac::MacEnabledStateChanged()
1284 OnEnabled( GetPeer()->IsEnabled() );
1288 // status queries on the inherited window's state
1291 bool wxWindowMac::MacIsReallyEnabled()
1293 return GetPeer()->IsEnabled() ;
1296 bool wxWindowMac::MacIsReallyHilited()
1298 #if wxOSX_USE_CARBON
1299 return GetPeer()->IsActive();
1301 return true; // TODO
1305 int wxWindowMac::GetCharHeight() const
1308 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1313 int wxWindowMac::GetCharWidth() const
1316 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1321 void wxWindowMac::DoGetTextExtent(const wxString
& str
,
1324 int *externalLeading
,
1325 const wxFont
*theFont
) const
1327 const wxFont
*fontToUse
= theFont
;
1331 tempFont
= GetFont();
1332 fontToUse
= &tempFont
;
1335 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1336 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1338 wxDouble h
, d
, e
, w
;
1339 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1343 if ( externalLeading
)
1344 *externalLeading
= (wxCoord
)(e
+0.5);
1346 *descent
= (wxCoord
)(d
+0.5);
1348 *x
= (wxCoord
)(w
+0.5);
1350 *y
= (wxCoord
)(h
+0.5);
1354 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1355 * we always intersect with the entire window, not only with the client area
1358 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1360 if ( GetPeer() == NULL
)
1363 if ( !IsShownOnScreen() )
1369 GetPeer()->SetNeedsDisplay( rect
) ;
1372 void wxWindowMac::DoFreeze()
1374 if ( GetPeer() && GetPeer()->IsOk() )
1375 GetPeer()->SetDrawingEnabled( false ) ;
1378 void wxWindowMac::DoThaw()
1380 if ( GetPeer() && GetPeer()->IsOk() )
1381 GetPeer()->SetDrawingEnabled( true ) ;
1384 wxWindow
*wxGetActiveWindow()
1386 // actually this is a windows-only concept
1390 // Coordinates relative to the window
1391 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
1393 #if wxOSX_USE_COCOA_OR_CARBON
1396 DoClientToScreen(&x
, &y
);
1397 CGPoint cgpoint
= CGPointMake( x
, y
);
1398 CGWarpMouseCursorPosition( cgpoint
);
1400 // At least GTK sends a mouse moved event after WarpMouse
1401 wxMouseEvent
event(wxEVT_MOTION
);
1404 wxMouseState mState
= ::wxGetMouseState();
1406 event
.m_altDown
= mState
.AltDown();
1407 event
.m_controlDown
= mState
.ControlDown();
1408 event
.m_leftDown
= mState
.LeftIsDown();
1409 event
.m_middleDown
= mState
.MiddleIsDown();
1410 event
.m_rightDown
= mState
.RightIsDown();
1411 event
.m_metaDown
= mState
.MetaDown();
1412 event
.m_shiftDown
= mState
.ShiftDown();
1413 event
.SetId(GetId());
1414 event
.SetEventObject(this);
1415 GetEventHandler()->ProcessEvent(event
);
1419 int wxWindowMac::GetScrollPos(int orient
) const
1422 if ( orient
== wxHORIZONTAL
)
1425 return m_hScrollBar
->GetThumbPosition() ;
1430 return m_vScrollBar
->GetThumbPosition() ;
1436 // This now returns the whole range, not just the number
1437 // of positions that we can scroll.
1438 int wxWindowMac::GetScrollRange(int orient
) const
1441 if ( orient
== wxHORIZONTAL
)
1444 return m_hScrollBar
->GetRange() ;
1449 return m_vScrollBar
->GetRange() ;
1455 int wxWindowMac::GetScrollThumb(int orient
) const
1458 if ( orient
== wxHORIZONTAL
)
1461 return m_hScrollBar
->GetThumbSize() ;
1466 return m_vScrollBar
->GetThumbSize() ;
1472 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1475 if ( orient
== wxHORIZONTAL
)
1478 m_hScrollBar
->SetThumbPosition( pos
) ;
1483 m_vScrollBar
->SetThumbPosition( pos
) ;
1489 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1491 bool needVisibilityUpdate
= false;
1493 if ( m_hScrollBarAlwaysShown
!= hflag
)
1495 m_hScrollBarAlwaysShown
= hflag
;
1496 needVisibilityUpdate
= true;
1499 if ( m_vScrollBarAlwaysShown
!= vflag
)
1501 m_vScrollBarAlwaysShown
= vflag
;
1502 needVisibilityUpdate
= true;
1505 if ( needVisibilityUpdate
)
1506 DoUpdateScrollbarVisibility();
1510 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1511 // our own window origin is at leftOrigin/rightOrigin
1514 void wxWindowMac::MacPaintGrowBox()
1520 if ( MacHasScrollBarCorner() )
1523 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1524 wxASSERT( cgContext
) ;
1528 GetPeer()->GetSize( tw
, th
);
1529 GetPeer()->GetPosition( tx
, ty
);
1531 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1534 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1535 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1536 CGContextSaveGState( cgContext
);
1538 if ( m_backgroundColour
.IsOk() )
1540 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1544 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1546 CGContextFillRect( cgContext
, cgrect
);
1547 CGContextRestoreGState( cgContext
);
1551 if ( m_backgroundColour
.IsOk() )
1552 m_growBox
->SetBackgroundColour(m_backgroundColour
);
1554 m_growBox
->SetBackgroundColour(*wxWHITE
);
1562 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1567 bool hasFocus
= GetPeer()->NeedsFocusRect() && HasFocus();
1569 // back to the surrounding frame rectangle
1572 GetPeer()->GetSize( tw
, th
);
1573 GetPeer()->GetPosition( tx
, ty
);
1575 #if wxOSX_USE_COCOA_OR_CARBON
1578 CGRect cgrect
= CGRectMake( tx
-1 , ty
-1 , tw
+2 ,
1581 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1582 wxASSERT( cgContext
) ;
1584 if ( GetPeer()->NeedsFrame() )
1586 HIThemeFrameDrawInfo info
;
1587 memset( &info
, 0 , sizeof(info
) ) ;
1591 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1592 info
.isFocused
= hasFocus
;
1594 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1596 info
.kind
= kHIThemeFrameTextFieldSquare
;
1597 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1599 else if ( HasFlag(wxSIMPLE_BORDER
) )
1601 info
.kind
= kHIThemeFrameListBox
;
1602 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1608 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1611 #endif // wxOSX_USE_COCOA_OR_CARBON
1614 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1617 if ( child
== m_hScrollBar
)
1618 m_hScrollBar
= NULL
;
1619 if ( child
== m_vScrollBar
)
1620 m_vScrollBar
= NULL
;
1621 if ( child
== m_growBox
)
1624 wxWindowBase::RemoveChild( child
) ;
1627 void wxWindowMac::DoUpdateScrollbarVisibility()
1630 bool triggerSizeEvent
= false;
1634 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1636 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1638 m_hScrollBar
->Show( showHScrollBar
);
1639 triggerSizeEvent
= true;
1645 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1647 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1649 m_vScrollBar
->Show( showVScrollBar
) ;
1650 triggerSizeEvent
= true;
1654 MacRepositionScrollBars() ;
1655 if ( triggerSizeEvent
)
1657 MacOnInternalSize();
1658 wxSizeEvent
event(GetSize(), m_windowId
);
1659 event
.SetEventObject(this);
1660 HandleWindowEvent(event
);
1665 // New function that will replace some of the above.
1666 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1667 int range
, bool refresh
)
1670 // Updating scrollbars when window is being deleted is useless and
1671 // currently results in asserts in client-to-screen coordinates conversion
1672 // code which is used by DoUpdateScrollbarVisibility() so just skip it.
1673 if ( m_isBeingDeleted
)
1676 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1677 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1678 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1679 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1681 DoUpdateScrollbarVisibility();
1685 // Does a physical scroll
1686 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1688 if ( dx
== 0 && dy
== 0 )
1691 int width
, height
;
1692 GetClientSize( &width
, &height
) ;
1695 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1697 scrollrect
.Intersect( *rect
) ;
1698 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1699 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1701 GetPeer()->ScrollRect( &scrollrect
, dx
, dy
);
1706 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1708 child
= node
->GetData();
1712 if (child
->IsTopLevel())
1715 if ( !IsClientAreaChild(child
) )
1718 child
->GetPosition( &x
, &y
);
1719 child
->GetSize( &w
, &h
);
1722 wxRect
rc( x
, y
, w
, h
);
1723 if (rect
->Intersects( rc
))
1724 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1728 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1733 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1736 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1738 wxScrollWinEvent wevent
;
1739 wevent
.SetPosition(event
.GetPosition());
1740 wevent
.SetOrientation(event
.GetOrientation());
1741 wevent
.SetEventObject(this);
1743 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1744 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1745 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1746 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1747 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1748 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1749 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1750 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1751 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1752 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1753 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1754 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1755 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1756 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1757 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1758 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1760 HandleWindowEvent(wevent
);
1765 wxWindow
*wxWindowBase::DoFindFocus()
1767 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
1770 // Raise the window to the top of the Z order
1771 void wxWindowMac::Raise()
1776 // Lower the window to the bottom of the Z order
1777 void wxWindowMac::Lower()
1782 // static wxWindow *gs_lastWhich = NULL;
1784 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1786 // first trigger a set cursor event
1788 wxPoint clientorigin
= GetClientAreaOrigin() ;
1789 wxSize clientsize
= GetClientSize() ;
1791 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1793 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1795 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1796 if ( processedEvtSetCursor
&& event
.HasCursor() )
1798 cursor
= event
.GetCursor() ;
1802 // the test for processedEvtSetCursor is here to prevent using m_cursor
1803 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1804 // it - this is a way to say that our cursor shouldn't be used for this
1806 if ( !processedEvtSetCursor
&& m_cursor
.IsOk() )
1809 if ( !wxIsBusy() && !GetParent() )
1810 cursor
= *wxSTANDARD_CURSOR
;
1813 if ( cursor
.IsOk() )
1814 cursor
.MacInstall() ;
1817 return cursor
.IsOk() ;
1820 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1824 return m_tooltip
->GetTip() ;
1827 return wxEmptyString
;
1830 void wxWindowMac::ClearBackground()
1836 void wxWindowMac::Update()
1838 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1843 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1845 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1849 if ( iter
->IsTopLevel() )
1851 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1855 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1860 iter
= iter
->GetParent() ;
1866 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1868 MacUpdateClippedRects() ;
1870 return m_cachedClippedClientRect
;
1873 const wxRect
& wxWindowMac::MacGetClippedRect() const
1875 MacUpdateClippedRects() ;
1877 return m_cachedClippedRect
;
1880 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1882 MacUpdateClippedRects() ;
1884 return m_cachedClippedRectWithOuterStructure
;
1887 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1889 static wxRegion emptyrgn
;
1891 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1893 MacUpdateClippedRects() ;
1894 if ( includeOuterStructures
)
1895 return m_cachedClippedRegionWithOuterStructure
;
1897 return m_cachedClippedRegion
;
1905 void wxWindowMac::MacUpdateClippedRects() const
1907 #if wxOSX_USE_CARBON
1908 if ( m_cachedClippedRectValid
)
1911 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1912 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1913 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1914 // to add focus borders everywhere
1916 Rect rIncludingOuterStructures
;
1920 GetPeer()->GetSize( tw
, th
);
1921 GetPeer()->GetPosition( tx
, ty
);
1923 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1925 r
.left
-= MacGetLeftBorderSize() ;
1926 r
.top
-= MacGetTopBorderSize() ;
1927 r
.bottom
+= MacGetBottomBorderSize() ;
1928 r
.right
+= MacGetRightBorderSize() ;
1935 rIncludingOuterStructures
= r
;
1936 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1938 wxRect cl
= GetClientRect() ;
1939 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1943 const wxWindow
* child
= (wxWindow
*) this ;
1944 const wxWindow
* parent
= NULL
;
1946 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1948 if ( parent
->MacIsChildOfClientArea(child
) )
1950 size
= parent
->GetClientSize() ;
1951 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1957 // this will be true for scrollbars, toolbars etc.
1958 size
= parent
->GetSize() ;
1959 y
= parent
->MacGetTopBorderSize() ;
1960 x
= parent
->MacGetLeftBorderSize() ;
1961 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1962 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1965 parent
->MacWindowToRootWindow( &x
, &y
) ;
1966 MacRootWindowToWindow( &x
, &y
) ;
1968 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1970 // the wxwindow and client rects will always be clipped
1971 SectRect( &r
, &rparent
, &r
) ;
1972 SectRect( &rClient
, &rparent
, &rClient
) ;
1974 // the structure only at 'hard' borders
1975 if ( parent
->MacClipChildren() ||
1976 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1978 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1984 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1985 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1986 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1987 m_cachedClippedRectWithOuterStructure
= wxRect(
1988 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1989 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1990 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1992 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1993 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1994 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1996 m_cachedClippedRectValid
= true ;
2001 This function must not change the updatergn !
2003 bool wxWindowMac::MacDoRedraw( long time
)
2005 bool handled
= false ;
2007 wxRegion formerUpdateRgn
= m_updateRegion
;
2008 wxRegion clientUpdateRgn
= formerUpdateRgn
;
2010 const wxRect clientRect
= GetClientRect();
2012 clientUpdateRgn
.Intersect(clientRect
);
2014 // first send an erase event to the entire update area
2015 const wxBackgroundStyle bgStyle
= GetBackgroundStyle();
2018 case wxBG_STYLE_ERASE
:
2019 case wxBG_STYLE_SYSTEM
:
2020 case wxBG_STYLE_COLOUR
:
2022 // for the toplevel window this really is the entire area for
2023 // all the others only their client area, otherwise they might
2024 // be drawing with full alpha and eg put blue into the grow-box
2025 // area of a scrolled window (scroll sample)
2026 wxWindowDC
dc(this);
2028 dc
.SetDeviceClippingRegion(formerUpdateRgn
);
2030 dc
.SetDeviceClippingRegion(clientUpdateRgn
);
2032 if ( bgStyle
== wxBG_STYLE_ERASE
)
2034 wxEraseEvent
eevent( GetId(), &dc
);
2035 eevent
.SetEventObject( this );
2036 if ( ProcessWindowEvent( eevent
) )
2042 dc
.SetBackground(GetBackgroundColour());
2048 case wxBG_STYLE_PAINT
:
2049 case wxBG_STYLE_TRANSPARENT
:
2050 // nothing to do, user-defined EVT_PAINT handler will overwrite the
2051 // entire window client area
2055 wxFAIL_MSG( "unsupported background style" );
2058 // as this is a full window, shouldn't be necessary anymore
2059 // MacPaintGrowBox();
2061 // calculate a client-origin version of the update rgn and set
2062 // m_updateRegion to that
2063 clientUpdateRgn
.Offset(-clientRect
.GetPosition());
2064 m_updateRegion
= clientUpdateRgn
;
2066 if ( !m_updateRegion
.Empty() )
2068 // paint the window itself
2070 wxPaintEvent
event(GetId());
2071 event
.SetTimestamp(time
);
2072 event
.SetEventObject(this);
2073 handled
= HandleWindowEvent(event
);
2076 m_updateRegion
= formerUpdateRgn
;
2078 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
2080 top
->WindowWasPainted() ;
2085 void wxWindowMac::MacPaintChildrenBorders()
2087 // now we cannot rely on having its borders drawn by a window itself, as it does not
2088 // get the updateRgn wide enough to always do so, so we do it from the parent
2089 // this would also be the place to draw any custom backgrounds for native controls
2090 // in Composited windowing
2091 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2095 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2097 child
= node
->GetData();
2101 if (child
== m_vScrollBar
)
2103 if (child
== m_hScrollBar
)
2105 if (child
== m_growBox
)
2108 if (child
->IsTopLevel())
2110 if (!child
->IsShown())
2113 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2115 child
->GetPosition( &x
, &y
);
2116 child
->GetSize( &w
, &h
);
2118 if ( m_updateRegion
.Contains(clientOrigin
.x
+x
-10, clientOrigin
.y
+y
-10, w
+20, h
+20) )
2120 // paint custom borders
2121 wxNcPaintEvent
eventNc( child
->GetId() );
2122 eventNc
.SetEventObject( child
);
2123 if ( !child
->HandleWindowEvent( eventNc
) )
2125 child
->MacPaintBorders(0, 0) ;
2132 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2134 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
2135 return tlw
? tlw
->GetWXWindow() : NULL
;
2138 bool wxWindowMac::MacHasScrollBarCorner() const
2141 /* Returns whether the scroll bars in a wxScrolledWindow should be
2142 * shortened. Scroll bars should be shortened if either:
2144 * - both scroll bars are visible, or
2146 * - there is a resize box in the parent frame's corner and this
2147 * window shares the bottom and right edge with the parent
2151 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
2154 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
2155 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
2157 // Both scroll bars visible
2162 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
2164 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
2166 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
2169 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
2171 // Parent frame has resize handle
2172 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
2174 // Note: allow for some wiggle room here as wxMac's
2175 // window rect calculations seem to be imprecise
2176 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
2177 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
2179 // Parent frame has resize handle and shares
2180 // right bottom corner
2185 // Parent frame has resize handle but doesn't
2186 // share right bottom corner
2192 // Parent frame doesn't have resize handle
2198 // No parent frame found
2206 void wxWindowMac::MacCreateScrollBars( long style
)
2209 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2211 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2213 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2214 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2216 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2219 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2221 GetClientSize( &width
, &height
) ;
2223 wxPoint
vPoint(width
- scrlsize
, 0) ;
2224 wxSize
vSize(scrlsize
, height
- adjust
) ;
2225 wxPoint
hPoint(0, height
- scrlsize
) ;
2226 wxSize
hSize(width
- adjust
, scrlsize
) ;
2228 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2229 if ( style
& wxVSCROLL
)
2231 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2232 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2235 if ( style
& wxHSCROLL
)
2237 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2238 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2241 wxPoint
gPoint(width
- scrlsize
, height
- scrlsize
);
2242 wxSize
gSize(scrlsize
, scrlsize
);
2243 m_growBox
= new wxBlindPlateWindow((wxWindow
*)this, wxID_ANY
, gPoint
, gSize
, 0);
2246 // because the create does not take into account the client area origin
2247 // we might have a real position shift
2248 MacRepositionScrollBars() ;
2252 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2254 bool result
= ((child
== NULL
)
2256 || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
) && (child
!= m_growBox
))
2263 void wxWindowMac::MacRepositionScrollBars()
2266 if ( !m_hScrollBar
&& !m_vScrollBar
)
2269 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2270 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2272 // get real client area
2274 GetSize( &width
, &height
);
2276 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2277 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2279 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2280 wxSize
vSize( scrlsize
, height
- adjust
) ;
2281 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2282 wxSize
hSize( width
- adjust
, scrlsize
) ;
2285 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2287 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2290 if ( MacHasScrollBarCorner() )
2292 m_growBox
->SetSize( width
- scrlsize
, height
- scrlsize
, wxDefaultCoord
, wxDefaultCoord
, wxSIZE_USE_EXISTING
);
2293 if ( !m_growBox
->IsShown() )
2298 if ( m_growBox
->IsShown() )
2305 bool wxWindowMac::AcceptsFocus() const
2307 if ( GetPeer() == NULL
|| GetPeer()->IsUserPane() )
2308 return wxWindowBase::AcceptsFocus();
2310 return GetPeer()->CanFocus();
2313 void wxWindowMac::MacSuperChangedPosition()
2315 // only window-absolute structures have to be moved i.e. controls
2317 m_cachedClippedRectValid
= false ;
2320 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2323 child
= node
->GetData();
2324 child
->MacSuperChangedPosition() ;
2326 node
= node
->GetNext();
2330 void wxWindowMac::MacTopLevelWindowChangedPosition()
2332 // only screen-absolute structures have to be moved i.e. glcanvas
2335 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2338 child
= node
->GetData();
2339 child
->MacTopLevelWindowChangedPosition() ;
2341 node
= node
->GetNext();
2345 long wxWindowMac::MacGetWXBorderSize() const
2352 if ( GetPeer() && GetPeer()->NeedsFrame() )
2354 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2356 #if wxOSX_USE_COCOA_OR_CARBON
2357 // this metric is only the 'outset' outside the simple frame rect
2358 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2364 else if (HasFlag(wxSIMPLE_BORDER
))
2366 #if wxOSX_USE_COCOA_OR_CARBON
2367 // this metric is only the 'outset' outside the simple frame rect
2368 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2379 long wxWindowMac::MacGetLeftBorderSize() const
2381 // the wx borders are all symmetric in mac themes
2382 long border
= MacGetWXBorderSize() ;
2386 int left
, top
, right
, bottom
;
2387 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2395 long wxWindowMac::MacGetRightBorderSize() const
2397 // the wx borders are all symmetric in mac themes
2398 long border
= MacGetWXBorderSize() ;
2402 int left
, top
, right
, bottom
;
2403 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2410 long wxWindowMac::MacGetTopBorderSize() const
2412 // the wx borders are all symmetric in mac themes
2413 long border
= MacGetWXBorderSize() ;
2417 int left
, top
, right
, bottom
;
2418 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2425 long wxWindowMac::MacGetBottomBorderSize() const
2427 // the wx borders are all symmetric in mac themes
2428 long border
= MacGetWXBorderSize() ;
2432 int left
, top
, right
, bottom
;
2433 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2440 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2442 return style
& ~wxBORDER_MASK
;
2445 // Find the wxWindowMac at the current mouse position, returning the mouse
2447 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2449 pt
= wxGetMousePosition();
2450 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2452 return (wxWindow
*) found
;
2455 // Get the current mouse position.
2456 wxPoint
wxGetMousePosition()
2460 wxGetMousePosition( &x
, &y
);
2462 return wxPoint(x
, y
);
2465 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2467 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2469 // copied from wxGTK : CS
2470 // VZ: shouldn't we move this to base class then?
2472 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2475 // (a) it's a command event and so is propagated to the parent
2476 // (b) under MSW it can be generated from kbd too
2477 // (c) it uses screen coords (because of (a))
2478 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2480 this->ClientToScreen(event
.GetPosition()));
2481 evtCtx
.SetEventObject(this);
2482 if ( ! HandleWindowEvent(evtCtx
) )
2491 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2495 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2499 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2500 Rect bounds
= { static_cast<short>(y
), static_cast<short>(x
), static_cast<short>(y
+ h
), static_cast<short>(x
+ w
) };
2505 bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec
) )
2510 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2512 #if wxOSX_USE_COCOA_OR_CARBON
2513 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2516 return eventNotHandledErr
;
2522 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2524 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2525 if ( !wxWindowBase::Reparent(newParent
) )
2528 GetPeer()->RemoveFromParent();
2529 GetPeer()->Embed( GetParent()->GetPeer() );
2535 bool wxWindowMac::SetTransparent(wxByte alpha
)
2537 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2539 if ( alpha
!= m_macAlpha
)
2541 m_macAlpha
= alpha
;
2548 bool wxWindowMac::CanSetTransparent()
2553 wxByte
wxWindowMac::GetTransparent() const
2558 bool wxWindowMac::IsShownOnScreen() const
2560 if ( GetPeer() && GetPeer()->IsOk() )
2562 bool peerVis
= GetPeer()->IsVisible();
2563 bool wxVis
= wxWindowBase::IsShownOnScreen();
2564 if( peerVis
!= wxVis
)
2566 // CS : put a breakpoint here to investigate differences
2567 // between native an wx visibilities
2568 // the only place where I've encountered them until now
2569 // are the hiding/showing sequences where the vis-changed event is
2570 // first sent to the innermost control, while wx does things
2571 // from the outmost control
2572 wxVis
= wxWindowBase::IsShownOnScreen();
2576 return GetPeer()->IsVisible();
2578 return wxWindowBase::IsShownOnScreen();
2581 #if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
2584 wxHotKeyHandler(EventHandlerCallRef
WXUNUSED(nextHandler
),
2586 void* WXUNUSED(userData
))
2588 EventHotKeyID hotKeyId
;
2590 GetEventParameter( event
, kEventParamDirectObject
, typeEventHotKeyID
, NULL
, sizeof(hotKeyId
), NULL
, &hotKeyId
);
2592 for ( unsigned i
= 0; i
< s_hotkeys
.size(); ++i
)
2594 if ( s_hotkeys
[i
].keyId
== static_cast<int>(hotKeyId
.id
) )
2596 unsigned char charCode
;
2599 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
2601 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
2602 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
2603 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
2605 UInt32 keymessage
= (keyCode
<< 8) + charCode
;
2607 wxKeyEvent
wxevent(wxEVT_HOTKEY
);
2608 wxevent
.SetId(hotKeyId
.id
);
2609 wxTheApp
->MacCreateKeyEvent( wxevent
, s_hotkeys
[i
].window
, keymessage
,
2610 modifiers
, when
, 0 ) ;
2612 s_hotkeys
[i
].window
->HandleWindowEvent(wxevent
);
2619 bool wxWindowMac::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
2621 for ( unsigned i
= 0; i
< s_hotkeys
.size(); ++i
)
2623 if ( s_hotkeys
[i
].keyId
== hotkeyId
)
2625 wxLogLastError(wxT("hotkeyId already registered"));
2631 static bool installed
= false;
2634 EventTypeSpec eventType
;
2635 eventType
.eventClass
=kEventClassKeyboard
;
2636 eventType
.eventKind
=kEventHotKeyPressed
;
2638 InstallApplicationEventHandler(&wxHotKeyHandler
, 1, &eventType
, NULL
, NULL
);
2642 UInt32 mac_modifiers
=0;
2643 if ( modifiers
& wxMOD_ALT
)
2644 mac_modifiers
|= optionKey
;
2645 if ( modifiers
& wxMOD_SHIFT
)
2646 mac_modifiers
|= shiftKey
;
2647 if ( modifiers
& wxMOD_RAW_CONTROL
)
2648 mac_modifiers
|= controlKey
;
2649 if ( modifiers
& wxMOD_CONTROL
)
2650 mac_modifiers
|= cmdKey
;
2652 EventHotKeyRef hotKeyRef
;
2653 EventHotKeyID hotKeyIDmac
;
2655 hotKeyIDmac
.signature
= 'WXMC';
2656 hotKeyIDmac
.id
= hotkeyId
;
2658 if ( RegisterEventHotKey(wxCharCodeWXToOSX((wxKeyCode
)keycode
), mac_modifiers
, hotKeyIDmac
,
2659 GetApplicationEventTarget(), 0, &hotKeyRef
) != noErr
)
2661 wxLogLastError(wxT("RegisterHotKey"));
2672 s_hotkeys
.push_back(v
);
2678 bool wxWindowMac::UnregisterHotKey(int hotkeyId
)
2680 for ( int i
= ((int)s_hotkeys
.size())-1; i
>=0; -- i
)
2682 if ( s_hotkeys
[i
].keyId
== hotkeyId
)
2684 EventHotKeyRef ref
= s_hotkeys
[i
].ref
;
2685 s_hotkeys
.erase(s_hotkeys
.begin() + i
);
2686 if ( UnregisterEventHotKey(ref
) != noErr
)
2688 wxLogLastError(wxT("UnregisterHotKey"));
2700 #endif // wxUSE_HOTKEY
2702 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2704 bool handled
= false;
2706 // moved the ordinary key event sending AFTER the accel evaluation
2709 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2711 wxWindow
*ancestor
= this;
2714 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2717 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2719 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
2720 handled
= handler
->ProcessEvent( command_event
);
2724 // accelerators can also be used with buttons, try them too
2725 command_event
.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED
);
2726 handled
= handler
->ProcessEvent( command_event
);
2732 if (ancestor
->IsTopLevel())
2735 ancestor
= ancestor
->GetParent();
2738 #endif // wxUSE_ACCEL
2742 handled
= HandleWindowEvent( event
) ;
2743 if ( handled
&& event
.GetSkipped() )
2754 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2756 static MacControlMap wxWinMacControlList
;
2758 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2760 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2762 return impl
->GetWXPeer();
2767 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2769 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2771 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2774 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2776 // adding NULL ControlRef is (first) surely a result of an error and
2777 // (secondly) breaks native event processing
2778 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2780 wxWinMacControlList
[inControl
] = impl
;
2783 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2785 // iterate over all the elements in the class
2786 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2787 // we should go on...
2793 MacControlMap::iterator it
;
2794 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2796 if ( it
->second
== impl
)
2798 wxWinMacControlList
.erase(it
);
2806 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2808 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
, bool isUserPane
)
2811 m_isRootControl
= isRootControl
;
2812 m_isUserPane
= isUserPane
;
2814 m_shouldSendEvents
= true;
2817 wxWidgetImpl::wxWidgetImpl()
2822 wxWidgetImpl::~wxWidgetImpl()
2826 void wxWidgetImpl::Init()
2828 m_isRootControl
= false;
2830 m_needsFocusRect
= false;
2831 m_needsFrame
= true;
2834 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2836 m_needsFocusRect
= needs
;
2839 bool wxWidgetImpl::NeedsFocusRect() const
2841 return m_needsFocusRect
;
2844 void wxWidgetImpl::SetNeedsFrame( bool needs
)
2846 m_needsFrame
= needs
;
2849 bool wxWidgetImpl::NeedsFrame() const
2851 return m_needsFrame
;
2854 void wxWidgetImpl::SetDrawingEnabled(bool WXUNUSED(enabled
))