1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/window.cpp
3 // Purpose: common (to all ports) wxWindow functions
4 // Author: Julian Smart, Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/string.h"
32 #include "wx/window.h"
33 #include "wx/control.h"
34 #include "wx/checkbox.h"
35 #include "wx/radiobut.h"
36 #include "wx/statbox.h"
37 #include "wx/textctrl.h"
38 #include "wx/settings.h"
39 #include "wx/dialog.h"
40 #include "wx/msgdlg.h"
41 #include "wx/statusbr.h"
42 #include "wx/toolbar.h"
43 #include "wx/dcclient.h"
44 #include "wx/scrolbar.h"
45 #include "wx/layout.h"
50 #include "wx/collpane.h"
52 #if wxUSE_DRAG_AND_DROP
54 #endif // wxUSE_DRAG_AND_DROP
56 #if wxUSE_ACCESSIBILITY
57 #include "wx/access.h"
61 #include "wx/cshelp.h"
65 #include "wx/tooltip.h"
66 #endif // wxUSE_TOOLTIPS
72 #if wxUSE_SYSTEM_OPTIONS
73 #include "wx/sysopt.h"
76 // For reporting compile- and runtime version of GTK+ in the ctrl+alt+mclick dialog.
77 // The gtk includes don't pull any other headers in, at least not on my system - MR
80 #include <gtk/gtkversion.h>
82 #include <gtk/gtkfeatures.h>
86 #include "wx/platinfo.h"
89 WXDLLIMPEXP_DATA_CORE(wxWindowList
) wxTopLevelWindows
;
93 wxMenu
*wxCurrentPopupMenu
= NULL
;
96 // ----------------------------------------------------------------------------
98 // ----------------------------------------------------------------------------
101 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
103 // ----------------------------------------------------------------------------
105 // ----------------------------------------------------------------------------
107 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
108 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
109 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
110 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
113 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
118 // ============================================================================
119 // implementation of the common functionality of the wxWindow class
120 // ============================================================================
122 // ----------------------------------------------------------------------------
124 // ----------------------------------------------------------------------------
126 // the default initialization
127 wxWindowBase::wxWindowBase()
129 // no window yet, no parent nor children
131 m_windowId
= wxID_ANY
;
133 // no constraints on the minimal window size
135 m_maxWidth
= wxDefaultCoord
;
137 m_maxHeight
= wxDefaultCoord
;
139 // invalidiated cache value
140 m_bestSizeCache
= wxDefaultSize
;
142 // window are created enabled and visible by default
146 // the default event handler is just this window
147 m_eventHandler
= this;
151 m_windowValidator
= NULL
;
152 #endif // wxUSE_VALIDATORS
154 // the colours/fonts are default for now, so leave m_font,
155 // m_backgroundColour and m_foregroundColour uninitialized and set those
161 m_inheritFont
= false;
167 m_backgroundStyle
= wxBG_STYLE_SYSTEM
;
169 #if wxUSE_CONSTRAINTS
170 // no constraints whatsoever
171 m_constraints
= NULL
;
172 m_constraintsInvolvedIn
= NULL
;
173 #endif // wxUSE_CONSTRAINTS
175 m_windowSizer
= NULL
;
176 m_containingSizer
= NULL
;
177 m_autoLayout
= false;
179 #if wxUSE_DRAG_AND_DROP
181 #endif // wxUSE_DRAG_AND_DROP
185 #endif // wxUSE_TOOLTIPS
189 #endif // wxUSE_CARET
192 m_hasCustomPalette
= false;
193 #endif // wxUSE_PALETTE
195 #if wxUSE_ACCESSIBILITY
199 m_virtualSize
= wxDefaultSize
;
201 m_scrollHelper
= NULL
;
203 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
204 #if wxUSE_SYSTEM_OPTIONS
205 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
207 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
211 // Whether we're using the current theme for this window (wxGTK only for now)
212 m_themeEnabled
= false;
214 // This is set to true by SendDestroyEvent() which should be called by the
215 // most derived class to ensure that the destruction event is sent as soon
216 // as possible to allow its handlers to still see the undestroyed window
217 m_isBeingDeleted
= false;
222 // common part of window creation process
223 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
225 const wxPoint
& WXUNUSED(pos
),
226 const wxSize
& WXUNUSED(size
),
228 const wxValidator
& wxVALIDATOR_PARAM(validator
),
229 const wxString
& name
)
232 // wxGTK doesn't allow to create controls with static box as the parent so
233 // this will result in a crash when the program is ported to wxGTK so warn
236 // if you get this assert, the correct solution is to create the controls
237 // as siblings of the static box
238 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
239 _T("wxStaticBox can't be used as a window parent!") );
240 #endif // wxUSE_STATBOX
242 // ids are limited to 16 bits under MSW so if you care about portability,
243 // it's not a good idea to use ids out of this range (and negative ids are
244 // reserved for wxWidgets own usage)
245 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767) ||
246 (id
>= wxID_AUTO_LOWEST
&& id
<= wxID_AUTO_HIGHEST
),
247 _T("invalid id value") );
249 // generate a new id if the user doesn't care about it
250 if ( id
== wxID_ANY
)
252 m_windowId
= NewControlId();
254 else // valid id specified
259 // don't use SetWindowStyleFlag() here, this function should only be called
260 // to change the flag after creation as it tries to reflect the changes in
261 // flags by updating the window dynamically and we don't need this here
262 m_windowStyle
= style
;
268 SetValidator(validator
);
269 #endif // wxUSE_VALIDATORS
271 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
272 // have it too - like this it's possible to set it only in the top level
273 // dialog/frame and all children will inherit it by defult
274 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
276 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
282 bool wxWindowBase::ToggleWindowStyle(int flag
)
284 wxASSERT_MSG( flag
, _T("flags with 0 value can't be toggled") );
287 long style
= GetWindowStyleFlag();
293 else // currently off
299 SetWindowStyleFlag(style
);
304 // ----------------------------------------------------------------------------
306 // ----------------------------------------------------------------------------
309 wxWindowBase::~wxWindowBase()
311 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
313 // FIXME if these 2 cases result from programming errors in the user code
314 // we should probably assert here instead of silently fixing them
316 // Just in case the window has been Closed, but we're then deleting
317 // immediately: don't leave dangling pointers.
318 wxPendingDelete
.DeleteObject(this);
320 // Just in case we've loaded a top-level window via LoadNativeDialog but
321 // we weren't a dialog class
322 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
325 // The associated popup menu can still be alive, disassociate from it in
327 if ( wxCurrentPopupMenu
&& wxCurrentPopupMenu
->GetInvokingWindow() == this )
328 wxCurrentPopupMenu
->SetInvokingWindow(NULL
);
329 #endif // wxUSE_MENUS
331 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
333 // notify the parent about this window destruction
335 m_parent
->RemoveChild(this);
339 #endif // wxUSE_CARET
342 delete m_windowValidator
;
343 #endif // wxUSE_VALIDATORS
345 #if wxUSE_CONSTRAINTS
346 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
347 // at deleted windows as they delete themselves.
348 DeleteRelatedConstraints();
352 // This removes any dangling pointers to this window in other windows'
353 // constraintsInvolvedIn lists.
354 UnsetConstraints(m_constraints
);
355 delete m_constraints
;
356 m_constraints
= NULL
;
358 #endif // wxUSE_CONSTRAINTS
360 if ( m_containingSizer
)
361 m_containingSizer
->Detach( (wxWindow
*)this );
363 delete m_windowSizer
;
365 #if wxUSE_DRAG_AND_DROP
367 #endif // wxUSE_DRAG_AND_DROP
371 #endif // wxUSE_TOOLTIPS
373 #if wxUSE_ACCESSIBILITY
378 // NB: this has to be called unconditionally, because we don't know
379 // whether this window has associated help text or not
380 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
382 helpProvider
->RemoveHelp(this);
386 bool wxWindowBase::IsBeingDeleted() const
388 return m_isBeingDeleted
||
389 (!IsTopLevel() && m_parent
&& m_parent
->IsBeingDeleted());
392 void wxWindowBase::SendDestroyEvent()
394 if ( m_isBeingDeleted
)
396 // we could have been already called from a more derived class dtor,
397 // e.g. ~wxTLW calls us and so does ~wxWindow and the latter call
398 // should be simply ignored
402 m_isBeingDeleted
= true;
404 wxWindowDestroyEvent event
;
405 event
.SetEventObject(this);
406 event
.SetId(GetId());
407 GetEventHandler()->ProcessEvent(event
);
410 bool wxWindowBase::Destroy()
419 bool wxWindowBase::Close(bool force
)
421 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
422 event
.SetEventObject(this);
423 event
.SetCanVeto(!force
);
425 // return false if window wasn't closed because the application vetoed the
427 return HandleWindowEvent(event
) && !event
.GetVeto();
430 bool wxWindowBase::DestroyChildren()
432 wxWindowList::compatibility_iterator node
;
435 // we iterate until the list becomes empty
436 node
= GetChildren().GetFirst();
440 wxWindow
*child
= node
->GetData();
442 // note that we really want to delete it immediately so don't call the
443 // possible overridden Destroy() version which might not delete the
444 // child immediately resulting in problems with our (top level) child
445 // outliving its parent
446 child
->wxWindowBase::Destroy();
448 wxASSERT_MSG( !GetChildren().Find(child
),
449 wxT("child didn't remove itself using RemoveChild()") );
455 // ----------------------------------------------------------------------------
456 // size/position related methods
457 // ----------------------------------------------------------------------------
459 // centre the window with respect to its parent in either (or both) directions
460 void wxWindowBase::DoCentre(int dir
)
462 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
463 _T("this method only implements centering child windows") );
465 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
468 // fits the window around the children
469 void wxWindowBase::Fit()
471 if ( !GetChildren().empty() )
473 SetSize(GetBestSize());
475 //else: do nothing if we have no children
478 // fits virtual size (ie. scrolled area etc.) around children
479 void wxWindowBase::FitInside()
481 if ( GetChildren().GetCount() > 0 )
483 SetVirtualSize( GetBestVirtualSize() );
487 // On Mac, scrollbars are explicitly children.
489 static bool wxHasRealChildren(const wxWindowBase
* win
)
491 int realChildCount
= 0;
493 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
495 node
= node
->GetNext() )
497 wxWindow
*win
= node
->GetData();
498 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
501 return (realChildCount
> 0);
505 void wxWindowBase::InvalidateBestSize()
507 m_bestSizeCache
= wxDefaultSize
;
509 // parent's best size calculation may depend on its children's
510 // as long as child window we are in is not top level window itself
511 // (because the TLW size is never resized automatically)
512 // so let's invalidate it as well to be safe:
513 if (m_parent
&& !IsTopLevel())
514 m_parent
->InvalidateBestSize();
517 // return the size best suited for the current window
518 wxSize
wxWindowBase::DoGetBestSize() const
524 best
= m_windowSizer
->GetMinSize();
526 #if wxUSE_CONSTRAINTS
527 else if ( m_constraints
)
529 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
531 // our minimal acceptable size is such that all our windows fit inside
535 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
537 node
= node
->GetNext() )
539 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
542 // it's not normal that we have an unconstrained child, but
543 // what can we do about it?
547 int x
= c
->right
.GetValue(),
548 y
= c
->bottom
.GetValue();
556 // TODO: we must calculate the overlaps somehow, otherwise we
557 // will never return a size bigger than the current one :-(
560 best
= wxSize(maxX
, maxY
);
562 #endif // wxUSE_CONSTRAINTS
563 else if ( !GetChildren().empty()
565 && wxHasRealChildren(this)
569 // our minimal acceptable size is such that all our visible child
570 // windows fit inside
574 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
576 node
= node
->GetNext() )
578 wxWindow
*win
= node
->GetData();
579 if ( win
->IsTopLevel()
582 || wxDynamicCast(win
, wxStatusBar
)
583 #endif // wxUSE_STATUSBAR
586 // dialogs and frames lie in different top level windows -
587 // don't deal with them here; as for the status bars, they
588 // don't lie in the client area at all
593 win
->GetPosition(&wx
, &wy
);
595 // if the window hadn't been positioned yet, assume that it is in
597 if ( wx
== wxDefaultCoord
)
599 if ( wy
== wxDefaultCoord
)
602 win
->GetSize(&ww
, &wh
);
603 if ( wx
+ ww
> maxX
)
605 if ( wy
+ wh
> maxY
)
609 best
= wxSize(maxX
, maxY
);
611 else // ! has children
613 // for a generic window there is no natural best size so, if the
614 // minimal size is not set, use the current size but take care to
615 // remember it as minimal size for the next time because our best size
616 // should be constant: otherwise we could get into a situation when the
617 // window is initially at some size, then expanded to a larger size and
618 // then, when the containing window is shrunk back (because our initial
619 // best size had been used for computing the parent min size), we can't
620 // be shrunk back any more because our best size is now bigger
621 wxSize size
= GetMinSize();
622 if ( !size
.IsFullySpecified() )
624 size
.SetDefaults(GetSize());
625 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
628 // return as-is, unadjusted by the client size difference.
632 // Add any difference between size and client size
633 wxSize diff
= GetSize() - GetClientSize();
634 best
.x
+= wxMax(0, diff
.x
);
635 best
.y
+= wxMax(0, diff
.y
);
640 // helper of GetWindowBorderSize(): as many ports don't implement support for
641 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
642 // fallbacks in this case
643 static int wxGetMetricOrDefault(wxSystemMetric what
, const wxWindowBase
* win
)
645 int rc
= wxSystemSettings::GetMetric(
646 what
, static_cast<wxWindow
*>(const_cast<wxWindowBase
*>(win
)));
653 // 2D border is by default 1 pixel wide
659 // 3D borders are by default 2 pixels
664 wxFAIL_MSG( _T("unexpected wxGetMetricOrDefault() argument") );
672 wxSize
wxWindowBase::GetWindowBorderSize() const
676 switch ( GetBorder() )
679 // nothing to do, size is already (0, 0)
682 case wxBORDER_SIMPLE
:
683 case wxBORDER_STATIC
:
684 size
.x
= wxGetMetricOrDefault(wxSYS_BORDER_X
, this);
685 size
.y
= wxGetMetricOrDefault(wxSYS_BORDER_Y
, this);
688 case wxBORDER_SUNKEN
:
689 case wxBORDER_RAISED
:
690 size
.x
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X
, this),
691 wxGetMetricOrDefault(wxSYS_BORDER_X
, this));
692 size
.y
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y
, this),
693 wxGetMetricOrDefault(wxSYS_BORDER_Y
, this));
696 case wxBORDER_DOUBLE
:
697 size
.x
= wxGetMetricOrDefault(wxSYS_EDGE_X
, this) +
698 wxGetMetricOrDefault(wxSYS_BORDER_X
, this);
699 size
.y
= wxGetMetricOrDefault(wxSYS_EDGE_Y
, this) +
700 wxGetMetricOrDefault(wxSYS_BORDER_Y
, this);
704 wxFAIL_MSG(_T("Unknown border style."));
708 // we have borders on both sides
712 wxSize
wxWindowBase::GetEffectiveMinSize() const
714 // merge the best size with the min size, giving priority to the min size
715 wxSize min
= GetMinSize();
716 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
718 wxSize best
= GetBestSize();
719 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
720 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
725 wxSize
wxWindowBase::GetBestSize() const
727 if ((!m_windowSizer
) && (m_bestSizeCache
.IsFullySpecified()))
728 return m_bestSizeCache
;
730 return DoGetBestSize();
733 void wxWindowBase::SetMinSize(const wxSize
& minSize
)
735 m_minWidth
= minSize
.x
;
736 m_minHeight
= minSize
.y
;
739 void wxWindowBase::SetMaxSize(const wxSize
& maxSize
)
741 m_maxWidth
= maxSize
.x
;
742 m_maxHeight
= maxSize
.y
;
745 void wxWindowBase::SetInitialSize(const wxSize
& size
)
747 // Set the min size to the size passed in. This will usually either be
748 // wxDefaultSize or the size passed to this window's ctor/Create function.
751 // Merge the size with the best size if needed
752 wxSize best
= GetEffectiveMinSize();
754 // If the current size doesn't match then change it
755 if (GetSize() != best
)
760 // by default the origin is not shifted
761 wxPoint
wxWindowBase::GetClientAreaOrigin() const
766 wxSize
wxWindowBase::ClientToWindowSize(const wxSize
& size
) const
768 const wxSize
diff(GetSize() - GetClientSize());
770 return wxSize(size
.x
== -1 ? -1 : size
.x
+ diff
.x
,
771 size
.y
== -1 ? -1 : size
.y
+ diff
.y
);
774 wxSize
wxWindowBase::WindowToClientSize(const wxSize
& size
) const
776 const wxSize
diff(GetSize() - GetClientSize());
778 return wxSize(size
.x
== -1 ? -1 : size
.x
- diff
.x
,
779 size
.y
== -1 ? -1 : size
.y
- diff
.y
);
782 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
784 if ( m_windowVariant
!= variant
)
786 m_windowVariant
= variant
;
788 DoSetWindowVariant(variant
);
792 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
794 // adjust the font height to correspond to our new variant (notice that
795 // we're only called if something really changed)
796 wxFont font
= GetFont();
797 int size
= font
.GetPointSize();
800 case wxWINDOW_VARIANT_NORMAL
:
803 case wxWINDOW_VARIANT_SMALL
:
808 case wxWINDOW_VARIANT_MINI
:
813 case wxWINDOW_VARIANT_LARGE
:
819 wxFAIL_MSG(_T("unexpected window variant"));
823 font
.SetPointSize(size
);
827 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
829 int WXUNUSED(incW
), int WXUNUSED(incH
) )
831 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
832 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
833 _T("min width/height must be less than max width/height!") );
842 #if WXWIN_COMPATIBILITY_2_8
843 void wxWindowBase::SetVirtualSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
),
844 int WXUNUSED(maxW
), int WXUNUSED(maxH
))
848 void wxWindowBase::SetVirtualSizeHints(const wxSize
& WXUNUSED(minsize
),
849 const wxSize
& WXUNUSED(maxsize
))
852 #endif // WXWIN_COMPATIBILITY_2_8
854 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
856 m_virtualSize
= wxSize(x
, y
);
859 wxSize
wxWindowBase::DoGetVirtualSize() const
861 // we should use the entire client area so if it is greater than our
862 // virtual size, expand it to fit (otherwise if the window is big enough we
863 // wouldn't be using parts of it)
864 wxSize size
= GetClientSize();
865 if ( m_virtualSize
.x
> size
.x
)
866 size
.x
= m_virtualSize
.x
;
868 if ( m_virtualSize
.y
>= size
.y
)
869 size
.y
= m_virtualSize
.y
;
874 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
876 // screen position is the same as (0, 0) in client coords for non TLWs (and
877 // TLWs override this method)
883 ClientToScreen(x
, y
);
886 void wxWindowBase::SendSizeEvent(int flags
)
888 wxSizeEvent
event(GetSize(), GetId());
889 event
.SetEventObject(this);
890 if ( flags
& wxSEND_EVENT_POST
)
891 wxPostEvent(this, event
);
893 HandleWindowEvent(event
);
896 void wxWindowBase::SendSizeEventToParent(int flags
)
898 wxWindow
* const parent
= GetParent();
899 if ( parent
&& !parent
->IsBeingDeleted() )
900 parent
->SendSizeEvent(flags
);
903 // ----------------------------------------------------------------------------
904 // show/hide/enable/disable the window
905 // ----------------------------------------------------------------------------
907 bool wxWindowBase::Show(bool show
)
909 if ( show
!= m_isShown
)
921 bool wxWindowBase::IsEnabled() const
923 return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
926 void wxWindowBase::NotifyWindowOnEnableChange(bool enabled
)
928 #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
930 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
934 // If we are top-level then the logic doesn't apply - otherwise
935 // showing a modal dialog would result in total greying out (and ungreying
936 // out later) of everything which would be really ugly
940 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
942 node
= node
->GetNext() )
944 wxWindowBase
* const child
= node
->GetData();
945 if ( !child
->IsTopLevel() && child
->IsThisEnabled() )
946 child
->NotifyWindowOnEnableChange(enabled
);
950 bool wxWindowBase::Enable(bool enable
)
952 if ( enable
== IsThisEnabled() )
955 m_isEnabled
= enable
;
957 #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
959 #else // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
960 wxWindowBase
* const parent
= GetParent();
961 if( !IsTopLevel() && parent
&& !parent
->IsEnabled() )
965 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
967 NotifyWindowOnEnableChange(enable
);
972 bool wxWindowBase::IsShownOnScreen() const
974 // A window is shown on screen if it itself is shown and so are all its
975 // parents. But if a window is toplevel one, then its always visible on
976 // screen if IsShown() returns true, even if it has a hidden parent.
978 (IsTopLevel() || GetParent() == NULL
|| GetParent()->IsShownOnScreen());
981 // ----------------------------------------------------------------------------
983 // ----------------------------------------------------------------------------
985 bool wxWindowBase::IsTopLevel() const
990 // ----------------------------------------------------------------------------
992 // ----------------------------------------------------------------------------
994 void wxWindowBase::Freeze()
996 if ( !m_freezeCount
++ )
998 // physically freeze this window:
1001 // and recursively freeze all children:
1002 for ( wxWindowList::iterator i
= GetChildren().begin();
1003 i
!= GetChildren().end(); ++i
)
1005 wxWindow
*child
= *i
;
1006 if ( child
->IsTopLevel() )
1014 void wxWindowBase::Thaw()
1016 wxASSERT_MSG( m_freezeCount
, "Thaw() without matching Freeze()" );
1018 if ( !--m_freezeCount
)
1020 // recursively thaw all children:
1021 for ( wxWindowList::iterator i
= GetChildren().begin();
1022 i
!= GetChildren().end(); ++i
)
1024 wxWindow
*child
= *i
;
1025 if ( child
->IsTopLevel() )
1031 // physically thaw this window:
1036 // ----------------------------------------------------------------------------
1037 // reparenting the window
1038 // ----------------------------------------------------------------------------
1040 void wxWindowBase::AddChild(wxWindowBase
*child
)
1042 wxCHECK_RET( child
, wxT("can't add a NULL child") );
1044 // this should never happen and it will lead to a crash later if it does
1045 // because RemoveChild() will remove only one node from the children list
1046 // and the other(s) one(s) will be left with dangling pointers in them
1047 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
1049 GetChildren().Append((wxWindow
*)child
);
1050 child
->SetParent(this);
1052 // adding a child while frozen will assert when thawed, so freeze it as if
1053 // it had been already present when we were frozen
1054 if ( IsFrozen() && !child
->IsTopLevel() )
1058 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
1060 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
1062 // removing a child while frozen may result in permanently frozen window
1063 // if used e.g. from Reparent(), so thaw it
1065 // NB: IsTopLevel() doesn't return true any more when a TLW child is being
1066 // removed from its ~wxWindowBase, so check for IsBeingDeleted() too
1067 if ( IsFrozen() && !child
->IsBeingDeleted() && !child
->IsTopLevel() )
1070 GetChildren().DeleteObject((wxWindow
*)child
);
1071 child
->SetParent(NULL
);
1074 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
1076 wxWindow
*oldParent
= GetParent();
1077 if ( newParent
== oldParent
)
1083 const bool oldEnabledState
= IsEnabled();
1085 // unlink this window from the existing parent.
1088 oldParent
->RemoveChild(this);
1092 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
1095 // add it to the new one
1098 newParent
->AddChild(this);
1102 wxTopLevelWindows
.Append((wxWindow
*)this);
1105 // We need to notify window (and its subwindows) if by changing the parent
1106 // we also change our enabled/disabled status.
1107 const bool newEnabledState
= IsEnabled();
1108 if ( newEnabledState
!= oldEnabledState
)
1110 NotifyWindowOnEnableChange(newEnabledState
);
1116 // ----------------------------------------------------------------------------
1117 // event handler stuff
1118 // ----------------------------------------------------------------------------
1120 void wxWindowBase::SetEventHandler(wxEvtHandler
*handler
)
1122 wxCHECK_RET(handler
!= NULL
, "SetEventHandler(NULL) called");
1124 m_eventHandler
= handler
;
1127 void wxWindowBase::SetNextHandler(wxEvtHandler
*WXUNUSED(handler
))
1129 // disable wxEvtHandler chain mechanism for wxWindows:
1130 // wxWindow uses its own stack mechanism which doesn't mix well with wxEvtHandler's one
1132 wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
1134 void wxWindowBase::SetPreviousHandler(wxEvtHandler
*WXUNUSED(handler
))
1136 // we can't simply wxFAIL here as in SetNextHandler: in fact the last
1137 // handler of our stack when is destroyed will be Unlink()ed and thus
1138 // will call this function to update the pointer of this window...
1140 //wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
1143 void wxWindowBase::PushEventHandler(wxEvtHandler
*handlerToPush
)
1145 wxCHECK_RET( handlerToPush
!= NULL
, "PushEventHandler(NULL) called" );
1147 // the new handler is going to be part of the wxWindow stack of event handlers:
1148 // it can't be part also of an event handler double-linked chain:
1149 wxASSERT_MSG(handlerToPush
->IsUnlinked(),
1150 "The handler being pushed in the wxWindow stack shouldn't be part of "
1151 "a wxEvtHandler chain; call Unlink() on it first");
1153 wxEvtHandler
*handlerOld
= GetEventHandler();
1154 wxCHECK_RET( handlerOld
, "an old event handler is NULL?" );
1156 // now use wxEvtHandler double-linked list to implement a stack:
1157 handlerToPush
->SetNextHandler(handlerOld
);
1159 if (handlerOld
!= this)
1160 handlerOld
->SetPreviousHandler(handlerToPush
);
1162 SetEventHandler(handlerToPush
);
1165 // final checks of the operations done above:
1166 wxASSERT_MSG( handlerToPush
->GetPreviousHandler() == NULL
,
1167 "the first handler of the wxWindow stack should have no previous handlers set" );
1168 wxASSERT_MSG( handlerToPush
->GetNextHandler() != NULL
,
1169 "the first handler of the wxWindow stack should have non-NULL next handler" );
1171 wxEvtHandler
* pLast
= handlerToPush
;
1172 while (pLast
&& pLast
!= this)
1173 pLast
= pLast
->GetNextHandler();
1174 wxASSERT_MSG( pLast
->GetNextHandler() == NULL
,
1175 "the last handler of the wxWindow stack should have this window as next handler" );
1179 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
1181 // we need to pop the wxWindow stack, i.e. we need to remove the first handler
1183 wxEvtHandler
*firstHandler
= GetEventHandler();
1184 wxCHECK_MSG( firstHandler
!= NULL
, NULL
, "wxWindow cannot have a NULL event handler" );
1185 wxCHECK_MSG( firstHandler
!= this, NULL
, "cannot pop the wxWindow itself" );
1186 wxCHECK_MSG( firstHandler
->GetPreviousHandler() == NULL
, NULL
,
1187 "the first handler of the wxWindow stack should have no previous handlers set" );
1189 wxEvtHandler
*secondHandler
= firstHandler
->GetNextHandler();
1190 wxCHECK_MSG( secondHandler
!= NULL
, NULL
,
1191 "the first handler of the wxWindow stack should have non-NULL next handler" );
1193 firstHandler
->SetNextHandler(NULL
);
1194 secondHandler
->SetPreviousHandler(NULL
);
1196 // now firstHandler is completely unlinked; set secondHandler as the new window event handler
1197 SetEventHandler(secondHandler
);
1199 if ( deleteHandler
)
1201 delete firstHandler
;
1202 firstHandler
= NULL
;
1205 return firstHandler
;
1208 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handlerToRemove
)
1210 wxCHECK_MSG( handlerToRemove
!= NULL
, false, "RemoveEventHandler(NULL) called" );
1211 wxCHECK_MSG( handlerToRemove
!= this, false, "Cannot remove the window itself" );
1213 if (handlerToRemove
== GetEventHandler())
1215 // removing the first event handler is equivalent to "popping" the stack
1216 PopEventHandler(false);
1220 // NOTE: the wxWindow event handler list is always terminated with "this" handler
1221 wxEvtHandler
*handlerCur
= GetEventHandler()->GetNextHandler();
1222 while ( handlerCur
!= this )
1224 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
1226 if ( handlerCur
== handlerToRemove
)
1228 handlerCur
->Unlink();
1230 wxASSERT_MSG( handlerCur
!= GetEventHandler(),
1231 "the case Remove == Pop should was already handled" );
1235 handlerCur
= handlerNext
;
1238 wxFAIL_MSG( _T("where has the event handler gone?") );
1243 bool wxWindowBase::HandleWindowEvent(wxEvent
& event
) const
1245 // SafelyProcessEvent() will handle exceptions nicely
1246 return GetEventHandler()->SafelyProcessEvent(event
);
1249 // ----------------------------------------------------------------------------
1250 // colours, fonts &c
1251 // ----------------------------------------------------------------------------
1253 void wxWindowBase::InheritAttributes()
1255 const wxWindowBase
* const parent
= GetParent();
1259 // we only inherit attributes which had been explicitly set for the parent
1260 // which ensures that this only happens if the user really wants it and
1261 // not by default which wouldn't make any sense in modern GUIs where the
1262 // controls don't all use the same fonts (nor colours)
1263 if ( parent
->m_inheritFont
&& !m_hasFont
)
1264 SetFont(parent
->GetFont());
1266 // in addition, there is a possibility to explicitly forbid inheriting
1267 // colours at each class level by overriding ShouldInheritColours()
1268 if ( ShouldInheritColours() )
1270 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1271 SetForegroundColour(parent
->GetForegroundColour());
1273 // inheriting (solid) background colour is wrong as it totally breaks
1274 // any kind of themed backgrounds
1276 // instead, the controls should use the same background as their parent
1277 // (ideally by not drawing it at all)
1279 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1280 SetBackgroundColour(parent
->GetBackgroundColour());
1285 /* static */ wxVisualAttributes
1286 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1288 // it is important to return valid values for all attributes from here,
1289 // GetXXX() below rely on this
1290 wxVisualAttributes attrs
;
1291 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1292 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1294 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1295 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1296 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1297 // colour on other platforms.
1299 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1300 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1302 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1307 wxColour
wxWindowBase::GetBackgroundColour() const
1309 if ( !m_backgroundColour
.IsOk() )
1311 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
1313 // get our default background colour
1314 wxColour colBg
= GetDefaultAttributes().colBg
;
1316 // we must return some valid colour to avoid redoing this every time
1317 // and also to avoid surprizing the applications written for older
1318 // wxWidgets versions where GetBackgroundColour() always returned
1319 // something -- so give them something even if it doesn't make sense
1320 // for this window (e.g. it has a themed background)
1322 colBg
= GetClassDefaultAttributes().colBg
;
1327 return m_backgroundColour
;
1330 wxColour
wxWindowBase::GetForegroundColour() const
1332 // logic is the same as above
1333 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1335 wxColour colFg
= GetDefaultAttributes().colFg
;
1337 if ( !colFg
.IsOk() )
1338 colFg
= GetClassDefaultAttributes().colFg
;
1343 return m_foregroundColour
;
1346 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1348 if ( colour
== m_backgroundColour
)
1351 m_hasBgCol
= colour
.IsOk();
1352 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1353 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1355 m_inheritBgCol
= m_hasBgCol
;
1356 m_backgroundColour
= colour
;
1357 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1361 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1363 if (colour
== m_foregroundColour
)
1366 m_hasFgCol
= colour
.IsOk();
1367 m_inheritFgCol
= m_hasFgCol
;
1368 m_foregroundColour
= colour
;
1369 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1373 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1375 // setting an invalid cursor is ok, it means that we don't have any special
1377 if ( m_cursor
.IsSameAs(cursor
) )
1388 wxFont
wxWindowBase::GetFont() const
1390 // logic is the same as in GetBackgroundColour()
1391 if ( !m_font
.IsOk() )
1393 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1395 wxFont font
= GetDefaultAttributes().font
;
1397 font
= GetClassDefaultAttributes().font
;
1405 bool wxWindowBase::SetFont(const wxFont
& font
)
1407 if ( font
== m_font
)
1414 m_hasFont
= font
.IsOk();
1415 m_inheritFont
= m_hasFont
;
1417 InvalidateBestSize();
1424 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1426 m_hasCustomPalette
= true;
1429 // VZ: can anyone explain me what do we do here?
1430 wxWindowDC
d((wxWindow
*) this);
1434 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1436 wxWindow
*win
= (wxWindow
*)this;
1437 while ( win
&& !win
->HasCustomPalette() )
1439 win
= win
->GetParent();
1445 #endif // wxUSE_PALETTE
1448 void wxWindowBase::SetCaret(wxCaret
*caret
)
1459 wxASSERT_MSG( m_caret
->GetWindow() == this,
1460 wxT("caret should be created associated to this window") );
1463 #endif // wxUSE_CARET
1465 #if wxUSE_VALIDATORS
1466 // ----------------------------------------------------------------------------
1468 // ----------------------------------------------------------------------------
1470 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1472 if ( m_windowValidator
)
1473 delete m_windowValidator
;
1475 m_windowValidator
= (wxValidator
*)validator
.Clone();
1477 if ( m_windowValidator
)
1478 m_windowValidator
->SetWindow(this);
1480 #endif // wxUSE_VALIDATORS
1482 // ----------------------------------------------------------------------------
1483 // update region stuff
1484 // ----------------------------------------------------------------------------
1486 wxRect
wxWindowBase::GetUpdateClientRect() const
1488 wxRegion rgnUpdate
= GetUpdateRegion();
1489 rgnUpdate
.Intersect(GetClientRect());
1490 wxRect rectUpdate
= rgnUpdate
.GetBox();
1491 wxPoint ptOrigin
= GetClientAreaOrigin();
1492 rectUpdate
.x
-= ptOrigin
.x
;
1493 rectUpdate
.y
-= ptOrigin
.y
;
1498 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1500 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1503 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1505 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1508 void wxWindowBase::ClearBackground()
1510 // wxGTK uses its own version, no need to add never used code
1512 wxClientDC
dc((wxWindow
*)this);
1513 wxBrush
brush(GetBackgroundColour(), wxBRUSHSTYLE_SOLID
);
1514 dc
.SetBackground(brush
);
1519 // ----------------------------------------------------------------------------
1520 // find child window by id or name
1521 // ----------------------------------------------------------------------------
1523 wxWindow
*wxWindowBase::FindWindow(long id
) const
1525 if ( id
== m_windowId
)
1526 return (wxWindow
*)this;
1528 wxWindowBase
*res
= NULL
;
1529 wxWindowList::compatibility_iterator node
;
1530 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1532 wxWindowBase
*child
= node
->GetData();
1533 res
= child
->FindWindow( id
);
1536 return (wxWindow
*)res
;
1539 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1541 if ( name
== m_windowName
)
1542 return (wxWindow
*)this;
1544 wxWindowBase
*res
= NULL
;
1545 wxWindowList::compatibility_iterator node
;
1546 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1548 wxWindow
*child
= node
->GetData();
1549 res
= child
->FindWindow(name
);
1552 return (wxWindow
*)res
;
1556 // find any window by id or name or label: If parent is non-NULL, look through
1557 // children for a label or title matching the specified string. If NULL, look
1558 // through all top-level windows.
1560 // to avoid duplicating code we reuse the same helper function but with
1561 // different comparators
1563 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1564 const wxString
& label
, long id
);
1567 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1570 return win
->GetLabel() == label
;
1574 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1577 return win
->GetName() == label
;
1581 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1584 return win
->GetId() == id
;
1587 // recursive helper for the FindWindowByXXX() functions
1589 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1590 const wxString
& label
,
1592 wxFindWindowCmp cmp
)
1596 // see if this is the one we're looking for
1597 if ( (*cmp
)(parent
, label
, id
) )
1598 return (wxWindow
*)parent
;
1600 // It wasn't, so check all its children
1601 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1603 node
= node
->GetNext() )
1605 // recursively check each child
1606 wxWindow
*win
= (wxWindow
*)node
->GetData();
1607 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1617 // helper for FindWindowByXXX()
1619 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1620 const wxString
& label
,
1622 wxFindWindowCmp cmp
)
1626 // just check parent and all its children
1627 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1630 // start at very top of wx's windows
1631 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1633 node
= node
->GetNext() )
1635 // recursively check each window & its children
1636 wxWindow
*win
= node
->GetData();
1637 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1647 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1649 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1654 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1656 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1660 // fall back to the label
1661 win
= FindWindowByLabel(title
, parent
);
1669 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1671 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1674 // ----------------------------------------------------------------------------
1675 // dialog oriented functions
1676 // ----------------------------------------------------------------------------
1678 void wxWindowBase::MakeModal(bool modal
)
1680 // Disable all other windows
1683 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1686 wxWindow
*win
= node
->GetData();
1688 win
->Enable(!modal
);
1690 node
= node
->GetNext();
1695 bool wxWindowBase::Validate()
1697 #if wxUSE_VALIDATORS
1698 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1700 wxWindowList::compatibility_iterator node
;
1701 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1703 wxWindowBase
*child
= node
->GetData();
1704 wxValidator
*validator
= child
->GetValidator();
1705 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1710 if ( recurse
&& !child
->Validate() )
1715 #endif // wxUSE_VALIDATORS
1720 bool wxWindowBase::TransferDataToWindow()
1722 #if wxUSE_VALIDATORS
1723 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1725 wxWindowList::compatibility_iterator node
;
1726 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1728 wxWindowBase
*child
= node
->GetData();
1729 wxValidator
*validator
= child
->GetValidator();
1730 if ( validator
&& !validator
->TransferToWindow() )
1732 wxLogWarning(_("Could not transfer data to window"));
1734 wxLog::FlushActive();
1742 if ( !child
->TransferDataToWindow() )
1744 // warning already given
1749 #endif // wxUSE_VALIDATORS
1754 bool wxWindowBase::TransferDataFromWindow()
1756 #if wxUSE_VALIDATORS
1757 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1759 wxWindowList::compatibility_iterator node
;
1760 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1762 wxWindow
*child
= node
->GetData();
1763 wxValidator
*validator
= child
->GetValidator();
1764 if ( validator
&& !validator
->TransferFromWindow() )
1766 // nop warning here because the application is supposed to give
1767 // one itself - we don't know here what might have gone wrongly
1774 if ( !child
->TransferDataFromWindow() )
1776 // warning already given
1781 #endif // wxUSE_VALIDATORS
1786 void wxWindowBase::InitDialog()
1788 wxInitDialogEvent
event(GetId());
1789 event
.SetEventObject( this );
1790 GetEventHandler()->ProcessEvent(event
);
1793 // ----------------------------------------------------------------------------
1794 // context-sensitive help support
1795 // ----------------------------------------------------------------------------
1799 // associate this help text with this window
1800 void wxWindowBase::SetHelpText(const wxString
& text
)
1802 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1805 helpProvider
->AddHelp(this, text
);
1809 #if WXWIN_COMPATIBILITY_2_8
1810 // associate this help text with all windows with the same id as this
1812 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1814 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1817 helpProvider
->AddHelp(GetId(), text
);
1820 #endif // WXWIN_COMPATIBILITY_2_8
1822 // get the help string associated with this window (may be empty)
1823 // default implementation forwards calls to the help provider
1825 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1826 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1829 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1832 text
= helpProvider
->GetHelp(this);
1838 // show help for this window
1839 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1841 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1844 wxPoint pos
= event
.GetPosition();
1845 const wxHelpEvent::Origin origin
= event
.GetOrigin();
1846 if ( origin
== wxHelpEvent::Origin_Keyboard
)
1848 // if the help event was generated from keyboard it shouldn't
1849 // appear at the mouse position (which is still the only position
1850 // associated with help event) if the mouse is far away, although
1851 // we still do use the mouse position if it's over the window
1852 // because we suppose the user looks approximately at the mouse
1853 // already and so it would be more convenient than showing tooltip
1854 // at some arbitrary position which can be quite far from it
1855 const wxRect rectClient
= GetClientRect();
1856 if ( !rectClient
.Contains(ScreenToClient(pos
)) )
1858 // position help slightly under and to the right of this window
1859 pos
= ClientToScreen(wxPoint(
1861 rectClient
.height
+ GetCharHeight()
1866 if ( helpProvider
->ShowHelpAtPoint(this, pos
, origin
) )
1868 // skip the event.Skip() below
1876 #endif // wxUSE_HELP
1878 // ----------------------------------------------------------------------------
1880 // ----------------------------------------------------------------------------
1884 void wxWindowBase::SetToolTip( const wxString
&tip
)
1886 // don't create the new tooltip if we already have one
1889 m_tooltip
->SetTip( tip
);
1893 SetToolTip( new wxToolTip( tip
) );
1896 // setting empty tooltip text does not remove the tooltip any more - use
1897 // SetToolTip(NULL) for this
1900 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1902 if ( m_tooltip
!= tooltip
)
1907 m_tooltip
= tooltip
;
1911 #endif // wxUSE_TOOLTIPS
1913 // ----------------------------------------------------------------------------
1914 // constraints and sizers
1915 // ----------------------------------------------------------------------------
1917 #if wxUSE_CONSTRAINTS
1919 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1921 if ( m_constraints
)
1923 UnsetConstraints(m_constraints
);
1924 delete m_constraints
;
1926 m_constraints
= constraints
;
1927 if ( m_constraints
)
1929 // Make sure other windows know they're part of a 'meaningful relationship'
1930 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1931 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1932 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1933 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1934 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1935 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1936 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1937 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1938 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1939 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1940 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1941 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1942 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1943 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1944 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1945 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1949 // This removes any dangling pointers to this window in other windows'
1950 // constraintsInvolvedIn lists.
1951 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1955 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1956 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1957 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1958 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1959 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1960 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1961 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1962 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1963 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1964 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1965 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1966 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1967 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1968 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1969 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1970 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1974 // Back-pointer to other windows we're involved with, so if we delete this
1975 // window, we must delete any constraints we're involved with.
1976 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1978 if ( !m_constraintsInvolvedIn
)
1979 m_constraintsInvolvedIn
= new wxWindowList
;
1980 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1981 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1984 // REMOVE back-pointer to other windows we're involved with.
1985 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1987 if ( m_constraintsInvolvedIn
)
1988 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1991 // Reset any constraints that mention this window
1992 void wxWindowBase::DeleteRelatedConstraints()
1994 if ( m_constraintsInvolvedIn
)
1996 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1999 wxWindow
*win
= node
->GetData();
2000 wxLayoutConstraints
*constr
= win
->GetConstraints();
2002 // Reset any constraints involving this window
2005 constr
->left
.ResetIfWin(this);
2006 constr
->top
.ResetIfWin(this);
2007 constr
->right
.ResetIfWin(this);
2008 constr
->bottom
.ResetIfWin(this);
2009 constr
->width
.ResetIfWin(this);
2010 constr
->height
.ResetIfWin(this);
2011 constr
->centreX
.ResetIfWin(this);
2012 constr
->centreY
.ResetIfWin(this);
2015 wxWindowList::compatibility_iterator next
= node
->GetNext();
2016 m_constraintsInvolvedIn
->Erase(node
);
2020 delete m_constraintsInvolvedIn
;
2021 m_constraintsInvolvedIn
= NULL
;
2025 #endif // wxUSE_CONSTRAINTS
2027 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
2029 if ( sizer
== m_windowSizer
)
2032 if ( m_windowSizer
)
2034 m_windowSizer
->SetContainingWindow(NULL
);
2037 delete m_windowSizer
;
2040 m_windowSizer
= sizer
;
2041 if ( m_windowSizer
)
2043 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
2046 SetAutoLayout(m_windowSizer
!= NULL
);
2049 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
2051 SetSizer( sizer
, deleteOld
);
2052 sizer
->SetSizeHints( (wxWindow
*) this );
2056 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
2058 // adding a window to a sizer twice is going to result in fatal and
2059 // hard to debug problems later because when deleting the second
2060 // associated wxSizerItem we're going to dereference a dangling
2061 // pointer; so try to detect this as early as possible
2062 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
2063 _T("Adding a window to the same sizer twice?") );
2065 m_containingSizer
= sizer
;
2068 #if wxUSE_CONSTRAINTS
2070 void wxWindowBase::SatisfyConstraints()
2072 wxLayoutConstraints
*constr
= GetConstraints();
2073 bool wasOk
= constr
&& constr
->AreSatisfied();
2075 ResetConstraints(); // Mark all constraints as unevaluated
2079 // if we're a top level panel (i.e. our parent is frame/dialog), our
2080 // own constraints will never be satisfied any more unless we do it
2084 while ( noChanges
> 0 )
2086 LayoutPhase1(&noChanges
);
2090 LayoutPhase2(&noChanges
);
2093 #endif // wxUSE_CONSTRAINTS
2095 bool wxWindowBase::Layout()
2097 // If there is a sizer, use it instead of the constraints
2101 GetVirtualSize(&w
, &h
);
2102 GetSizer()->SetDimension( 0, 0, w
, h
);
2104 #if wxUSE_CONSTRAINTS
2107 SatisfyConstraints(); // Find the right constraints values
2108 SetConstraintSizes(); // Recursively set the real window sizes
2115 #if wxUSE_CONSTRAINTS
2117 // first phase of the constraints evaluation: set our own constraints
2118 bool wxWindowBase::LayoutPhase1(int *noChanges
)
2120 wxLayoutConstraints
*constr
= GetConstraints();
2122 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
2125 // second phase: set the constraints for our children
2126 bool wxWindowBase::LayoutPhase2(int *noChanges
)
2133 // Layout grand children
2139 // Do a phase of evaluating child constraints
2140 bool wxWindowBase::DoPhase(int phase
)
2142 // the list containing the children for which the constraints are already
2144 wxWindowList succeeded
;
2146 // the max number of iterations we loop before concluding that we can't set
2148 static const int maxIterations
= 500;
2150 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
2154 // loop over all children setting their constraints
2155 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2157 node
= node
->GetNext() )
2159 wxWindow
*child
= node
->GetData();
2160 if ( child
->IsTopLevel() )
2162 // top level children are not inside our client area
2166 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
2168 // this one is either already ok or nothing we can do about it
2172 int tempNoChanges
= 0;
2173 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
2174 : child
->LayoutPhase2(&tempNoChanges
);
2175 noChanges
+= tempNoChanges
;
2179 succeeded
.Append(child
);
2185 // constraints are set
2193 void wxWindowBase::ResetConstraints()
2195 wxLayoutConstraints
*constr
= GetConstraints();
2198 constr
->left
.SetDone(false);
2199 constr
->top
.SetDone(false);
2200 constr
->right
.SetDone(false);
2201 constr
->bottom
.SetDone(false);
2202 constr
->width
.SetDone(false);
2203 constr
->height
.SetDone(false);
2204 constr
->centreX
.SetDone(false);
2205 constr
->centreY
.SetDone(false);
2208 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2211 wxWindow
*win
= node
->GetData();
2212 if ( !win
->IsTopLevel() )
2213 win
->ResetConstraints();
2214 node
= node
->GetNext();
2218 // Need to distinguish between setting the 'fake' size for windows and sizers,
2219 // and setting the real values.
2220 void wxWindowBase::SetConstraintSizes(bool recurse
)
2222 wxLayoutConstraints
*constr
= GetConstraints();
2223 if ( constr
&& constr
->AreSatisfied() )
2225 int x
= constr
->left
.GetValue();
2226 int y
= constr
->top
.GetValue();
2227 int w
= constr
->width
.GetValue();
2228 int h
= constr
->height
.GetValue();
2230 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
2231 (constr
->height
.GetRelationship() != wxAsIs
) )
2233 SetSize(x
, y
, w
, h
);
2237 // If we don't want to resize this window, just move it...
2243 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
2244 GetClassInfo()->GetClassName(),
2250 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2253 wxWindow
*win
= node
->GetData();
2254 if ( !win
->IsTopLevel() && win
->GetConstraints() )
2255 win
->SetConstraintSizes();
2256 node
= node
->GetNext();
2261 // Only set the size/position of the constraint (if any)
2262 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
2264 wxLayoutConstraints
*constr
= GetConstraints();
2267 if ( x
!= wxDefaultCoord
)
2269 constr
->left
.SetValue(x
);
2270 constr
->left
.SetDone(true);
2272 if ( y
!= wxDefaultCoord
)
2274 constr
->top
.SetValue(y
);
2275 constr
->top
.SetDone(true);
2277 if ( w
!= wxDefaultCoord
)
2279 constr
->width
.SetValue(w
);
2280 constr
->width
.SetDone(true);
2282 if ( h
!= wxDefaultCoord
)
2284 constr
->height
.SetValue(h
);
2285 constr
->height
.SetDone(true);
2290 void wxWindowBase::MoveConstraint(int x
, int y
)
2292 wxLayoutConstraints
*constr
= GetConstraints();
2295 if ( x
!= wxDefaultCoord
)
2297 constr
->left
.SetValue(x
);
2298 constr
->left
.SetDone(true);
2300 if ( y
!= wxDefaultCoord
)
2302 constr
->top
.SetValue(y
);
2303 constr
->top
.SetDone(true);
2308 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2310 wxLayoutConstraints
*constr
= GetConstraints();
2313 *w
= constr
->width
.GetValue();
2314 *h
= constr
->height
.GetValue();
2320 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2322 wxLayoutConstraints
*constr
= GetConstraints();
2325 *w
= constr
->width
.GetValue();
2326 *h
= constr
->height
.GetValue();
2329 GetClientSize(w
, h
);
2332 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2334 wxLayoutConstraints
*constr
= GetConstraints();
2337 *x
= constr
->left
.GetValue();
2338 *y
= constr
->top
.GetValue();
2344 #endif // wxUSE_CONSTRAINTS
2346 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2348 // don't do it for the dialogs/frames - they float independently of their
2350 if ( !IsTopLevel() )
2352 wxWindow
*parent
= GetParent();
2353 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2355 wxPoint
pt(parent
->GetClientAreaOrigin());
2362 // ----------------------------------------------------------------------------
2363 // Update UI processing
2364 // ----------------------------------------------------------------------------
2366 void wxWindowBase::UpdateWindowUI(long flags
)
2368 wxUpdateUIEvent
event(GetId());
2369 event
.SetEventObject(this);
2371 if ( GetEventHandler()->ProcessEvent(event
) )
2373 DoUpdateWindowUI(event
);
2376 if (flags
& wxUPDATE_UI_RECURSE
)
2378 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2381 wxWindow
* child
= (wxWindow
*) node
->GetData();
2382 child
->UpdateWindowUI(flags
);
2383 node
= node
->GetNext();
2388 // do the window-specific processing after processing the update event
2389 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2391 if ( event
.GetSetEnabled() )
2392 Enable(event
.GetEnabled());
2394 if ( event
.GetSetShown() )
2395 Show(event
.GetShown());
2398 // ----------------------------------------------------------------------------
2399 // dialog units translations
2400 // ----------------------------------------------------------------------------
2402 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2404 int charWidth
= GetCharWidth();
2405 int charHeight
= GetCharHeight();
2406 wxPoint pt2
= wxDefaultPosition
;
2407 if (pt
.x
!= wxDefaultCoord
)
2408 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2409 if (pt
.y
!= wxDefaultCoord
)
2410 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2415 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2417 int charWidth
= GetCharWidth();
2418 int charHeight
= GetCharHeight();
2419 wxPoint pt2
= wxDefaultPosition
;
2420 if (pt
.x
!= wxDefaultCoord
)
2421 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2422 if (pt
.y
!= wxDefaultCoord
)
2423 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2428 // ----------------------------------------------------------------------------
2430 // ----------------------------------------------------------------------------
2432 // propagate the colour change event to the subwindows
2433 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2435 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2438 // Only propagate to non-top-level windows
2439 wxWindow
*win
= node
->GetData();
2440 if ( !win
->IsTopLevel() )
2442 wxSysColourChangedEvent event2
;
2443 event
.SetEventObject(win
);
2444 win
->GetEventHandler()->ProcessEvent(event2
);
2447 node
= node
->GetNext();
2453 // the default action is to populate dialog with data when it's created,
2454 // and nudge the UI into displaying itself correctly in case
2455 // we've turned the wxUpdateUIEvents frequency down low.
2456 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2458 TransferDataToWindow();
2460 // Update the UI at this point
2461 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2464 // ----------------------------------------------------------------------------
2465 // menu-related functions
2466 // ----------------------------------------------------------------------------
2470 bool wxWindowBase::PopupMenu(wxMenu
*menu
, int x
, int y
)
2472 wxCHECK_MSG( menu
, false, "can't popup NULL menu" );
2474 wxCurrentPopupMenu
= menu
;
2475 const bool rc
= DoPopupMenu(menu
, x
, y
);
2476 wxCurrentPopupMenu
= NULL
;
2481 // this is used to pass the id of the selected item from the menu event handler
2482 // to the main function itself
2484 // it's ok to use a global here as there can be at most one popup menu shown at
2486 static int gs_popupMenuSelection
= wxID_NONE
;
2488 void wxWindowBase::InternalOnPopupMenu(wxCommandEvent
& event
)
2490 // store the id in a global variable where we'll retrieve it from later
2491 gs_popupMenuSelection
= event
.GetId();
2494 void wxWindowBase::InternalOnPopupMenuUpdate(wxUpdateUIEvent
& WXUNUSED(event
))
2496 // nothing to do but do not skip it
2500 wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu
& menu
, int x
, int y
)
2502 gs_popupMenuSelection
= wxID_NONE
;
2504 Connect(wxEVT_COMMAND_MENU_SELECTED
,
2505 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2509 // it is common to construct the menu passed to this function dynamically
2510 // using some fixed range of ids which could clash with the ids used
2511 // elsewhere in the program, which could result in some menu items being
2512 // unintentionally disabled or otherwise modified by update UI handlers
2513 // elsewhere in the program code and this is difficult to avoid in the
2514 // program itself, so instead we just temporarily suspend UI updating while
2515 // this menu is shown
2516 Connect(wxEVT_UPDATE_UI
,
2517 wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate
),
2521 PopupMenu(&menu
, x
, y
);
2523 Disconnect(wxEVT_UPDATE_UI
,
2524 wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate
),
2527 Disconnect(wxEVT_COMMAND_MENU_SELECTED
,
2528 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2532 return gs_popupMenuSelection
;
2535 #endif // wxUSE_MENUS
2537 // methods for drawing the sizers in a visible way
2540 static void DrawSizers(wxWindowBase
*win
);
2542 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2544 wxClientDC
dc((wxWindow
*)win
);
2545 dc
.SetPen(*wxRED_PEN
);
2546 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxBRUSHSTYLE_CROSSDIAG_HATCH
) : *wxTRANSPARENT_BRUSH
);
2547 dc
.DrawRectangle(rect
.Deflate(1, 1));
2550 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2552 const wxSizerItemList
& items
= sizer
->GetChildren();
2553 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2558 wxSizerItem
*item
= *i
;
2559 if ( item
->IsSizer() )
2561 DrawBorder(win
, item
->GetRect().Deflate(2));
2562 DrawSizer(win
, item
->GetSizer());
2564 else if ( item
->IsSpacer() )
2566 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2568 else if ( item
->IsWindow() )
2570 DrawSizers(item
->GetWindow());
2575 static void DrawSizers(wxWindowBase
*win
)
2577 wxSizer
*sizer
= win
->GetSizer();
2580 DrawBorder(win
, win
->GetClientSize());
2581 DrawSizer(win
, sizer
);
2583 else // no sizer, still recurse into the children
2585 const wxWindowList
& children
= win
->GetChildren();
2586 for ( wxWindowList::const_iterator i
= children
.begin(),
2587 end
= children
.end();
2596 #endif // __WXDEBUG__
2598 // process special middle clicks
2599 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2601 if ( event
.ControlDown() && event
.AltDown() )
2604 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2605 if ( event
.ShiftDown() )
2610 #endif // __WXDEBUG__
2611 ::wxInfoMessageBox((wxWindow
*)this);
2619 // ----------------------------------------------------------------------------
2621 // ----------------------------------------------------------------------------
2623 #if wxUSE_ACCESSIBILITY
2624 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2626 if (m_accessible
&& (accessible
!= m_accessible
))
2627 delete m_accessible
;
2628 m_accessible
= accessible
;
2630 m_accessible
->SetWindow((wxWindow
*) this);
2633 // Returns the accessible object, creating if necessary.
2634 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2637 m_accessible
= CreateAccessible();
2638 return m_accessible
;
2641 // Override to create a specific accessible object.
2642 wxAccessible
* wxWindowBase::CreateAccessible()
2644 return new wxWindowAccessible((wxWindow
*) this);
2649 // ----------------------------------------------------------------------------
2650 // list classes implementation
2651 // ----------------------------------------------------------------------------
2655 #include "wx/listimpl.cpp"
2656 WX_DEFINE_LIST(wxWindowList
)
2660 void wxWindowListNode::DeleteData()
2662 delete (wxWindow
*)GetData();
2665 #endif // wxUSE_STL/!wxUSE_STL
2667 // ----------------------------------------------------------------------------
2669 // ----------------------------------------------------------------------------
2671 wxBorder
wxWindowBase::GetBorder(long flags
) const
2673 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2674 if ( border
== wxBORDER_DEFAULT
)
2676 border
= GetDefaultBorder();
2678 else if ( border
== wxBORDER_THEME
)
2680 border
= GetDefaultBorderForControl();
2686 wxBorder
wxWindowBase::GetDefaultBorder() const
2688 return wxBORDER_NONE
;
2691 // ----------------------------------------------------------------------------
2693 // ----------------------------------------------------------------------------
2695 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2697 // here we just check if the point is inside the window or not
2699 // check the top and left border first
2700 bool outside
= x
< 0 || y
< 0;
2703 // check the right and bottom borders too
2704 wxSize size
= GetSize();
2705 outside
= x
>= size
.x
|| y
>= size
.y
;
2708 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2711 // ----------------------------------------------------------------------------
2713 // ----------------------------------------------------------------------------
2715 struct WXDLLEXPORT wxWindowNext
2719 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2720 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2721 bool wxWindowBase::ms_winCaptureChanging
= false;
2723 void wxWindowBase::CaptureMouse()
2725 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), static_cast<void*>(this));
2727 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2729 ms_winCaptureChanging
= true;
2731 wxWindow
*winOld
= GetCapture();
2734 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2737 wxWindowNext
*item
= new wxWindowNext
;
2739 item
->next
= ms_winCaptureNext
;
2740 ms_winCaptureNext
= item
;
2742 //else: no mouse capture to save
2745 ms_winCaptureCurrent
= (wxWindow
*)this;
2747 ms_winCaptureChanging
= false;
2750 void wxWindowBase::ReleaseMouse()
2752 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), static_cast<void*>(this));
2754 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2756 wxASSERT_MSG( GetCapture() == this,
2757 "attempt to release mouse, but this window hasn't captured it" );
2758 wxASSERT_MSG( ms_winCaptureCurrent
== this,
2759 "attempt to release mouse, but this window hasn't captured it" );
2761 ms_winCaptureChanging
= true;
2764 ms_winCaptureCurrent
= NULL
;
2766 if ( ms_winCaptureNext
)
2768 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2769 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2771 wxWindowNext
*item
= ms_winCaptureNext
;
2772 ms_winCaptureNext
= item
->next
;
2775 //else: stack is empty, no previous capture
2777 ms_winCaptureChanging
= false;
2779 wxLogTrace(_T("mousecapture"),
2780 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2781 static_cast<void*>(GetCapture()));
2784 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2786 wxMouseCaptureLostEvent
event(win
->GetId());
2787 event
.SetEventObject(win
);
2788 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2790 // windows must handle this event, otherwise the app wouldn't behave
2791 // correctly if it loses capture unexpectedly; see the discussion here:
2792 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
2793 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
2794 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2799 void wxWindowBase::NotifyCaptureLost()
2801 // don't do anything if capture lost was expected, i.e. resulted from
2802 // a wx call to ReleaseMouse or CaptureMouse:
2803 if ( ms_winCaptureChanging
)
2806 // if the capture was lost unexpectedly, notify every window that has
2807 // capture (on stack or current) about it and clear the stack:
2809 if ( ms_winCaptureCurrent
)
2811 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2812 ms_winCaptureCurrent
= NULL
;
2815 while ( ms_winCaptureNext
)
2817 wxWindowNext
*item
= ms_winCaptureNext
;
2818 ms_winCaptureNext
= item
->next
;
2820 DoNotifyWindowAboutCaptureLost(item
->win
);
2829 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2830 int WXUNUSED(modifiers
),
2831 int WXUNUSED(keycode
))
2837 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2843 #endif // wxUSE_HOTKEY
2845 // ----------------------------------------------------------------------------
2847 // ----------------------------------------------------------------------------
2849 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2851 #if wxUSE_VALIDATORS
2852 // Can only use the validator of the window which
2853 // is receiving the event
2854 if ( event
.GetEventObject() == this )
2856 wxValidator
* const validator
= GetValidator();
2857 if ( validator
&& validator
->ProcessEventHere(event
) )
2862 #endif // wxUSE_VALIDATORS
2867 bool wxWindowBase::TryParent(wxEvent
& event
)
2869 // carry on up the parent-child hierarchy if the propagation count hasn't
2871 if ( event
.ShouldPropagate() )
2873 // honour the requests to stop propagation at this window: this is
2874 // used by the dialogs, for example, to prevent processing the events
2875 // from the dialog controls in the parent frame which rarely, if ever,
2877 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2879 wxWindow
*parent
= GetParent();
2880 if ( parent
&& !parent
->IsBeingDeleted() )
2882 wxPropagateOnce
propagateOnce(event
);
2884 return parent
->GetEventHandler()->ProcessEvent(event
);
2889 return wxEvtHandler::TryParent(event
);
2892 // ----------------------------------------------------------------------------
2893 // window relationships
2894 // ----------------------------------------------------------------------------
2896 wxWindow
*wxWindowBase::DoGetSibling(WindowOrder order
) const
2898 wxCHECK_MSG( GetParent(), NULL
,
2899 _T("GetPrev/NextSibling() don't work for TLWs!") );
2901 wxWindowList
& siblings
= GetParent()->GetChildren();
2902 wxWindowList::compatibility_iterator i
= siblings
.Find((wxWindow
*)this);
2903 wxCHECK_MSG( i
, NULL
, _T("window not a child of its parent?") );
2905 if ( order
== OrderBefore
)
2906 i
= i
->GetPrevious();
2910 return i
? i
->GetData() : NULL
;
2913 // ----------------------------------------------------------------------------
2914 // keyboard navigation
2915 // ----------------------------------------------------------------------------
2917 // Navigates in the specified direction inside this window
2918 bool wxWindowBase::DoNavigateIn(int flags
)
2920 #ifdef wxHAS_NATIVE_TAB_TRAVERSAL
2921 // native code doesn't process our wxNavigationKeyEvents anyhow
2924 #else // !wxHAS_NATIVE_TAB_TRAVERSAL
2925 wxNavigationKeyEvent eventNav
;
2926 wxWindow
*focused
= FindFocus();
2927 eventNav
.SetCurrentFocus(focused
);
2928 eventNav
.SetEventObject(focused
);
2929 eventNav
.SetFlags(flags
);
2930 return GetEventHandler()->ProcessEvent(eventNav
);
2931 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
2934 bool wxWindowBase::HandleAsNavigationKey(const wxKeyEvent
& event
)
2936 if ( event
.GetKeyCode() != WXK_TAB
)
2939 int flags
= wxNavigationKeyEvent::FromTab
;
2941 if ( event
.ShiftDown() )
2942 flags
|= wxNavigationKeyEvent::IsBackward
;
2944 flags
|= wxNavigationKeyEvent::IsForward
;
2946 if ( event
.ControlDown() )
2947 flags
|= wxNavigationKeyEvent::WinChange
;
2953 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, WindowOrder move
)
2955 // check that we're not a top level window
2956 wxCHECK_RET( GetParent(),
2957 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2959 // detect the special case when we have nothing to do anyhow and when the
2960 // code below wouldn't work
2964 // find the target window in the siblings list
2965 wxWindowList
& siblings
= GetParent()->GetChildren();
2966 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2967 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2969 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2970 // can't just move the node around
2971 wxWindow
*self
= (wxWindow
*)this;
2972 siblings
.DeleteObject(self
);
2973 if ( move
== OrderAfter
)
2980 siblings
.Insert(i
, self
);
2982 else // OrderAfter and win was the last sibling
2984 siblings
.Append(self
);
2988 // ----------------------------------------------------------------------------
2990 // ----------------------------------------------------------------------------
2992 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2994 wxWindowBase
*win
= DoFindFocus();
2995 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2998 bool wxWindowBase::HasFocus() const
3000 wxWindowBase
*win
= DoFindFocus();
3001 return win
== this ||
3002 win
== wxConstCast(this, wxWindowBase
)->GetMainWindowOfCompositeControl();
3005 // ----------------------------------------------------------------------------
3007 // ----------------------------------------------------------------------------
3009 #if wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
3014 class DragAcceptFilesTarget
: public wxFileDropTarget
3017 DragAcceptFilesTarget(wxWindowBase
*win
) : m_win(win
) {}
3019 virtual bool OnDropFiles(wxCoord x
, wxCoord y
,
3020 const wxArrayString
& filenames
)
3022 wxDropFilesEvent
event(wxEVT_DROP_FILES
,
3024 wxCArrayString(filenames
).Release());
3025 event
.SetEventObject(m_win
);
3029 return m_win
->HandleWindowEvent(event
);
3033 wxWindowBase
* const m_win
;
3035 DECLARE_NO_COPY_CLASS(DragAcceptFilesTarget
)
3039 } // anonymous namespace
3041 // Generic version of DragAcceptFiles(). It works by installing a simple
3042 // wxFileDropTarget-to-EVT_DROP_FILES adaptor and therefore cannot be used
3043 // together with explicit SetDropTarget() calls.
3044 void wxWindowBase::DragAcceptFiles(bool accept
)
3048 wxASSERT_MSG( !GetDropTarget(),
3049 "cannot use DragAcceptFiles() and SetDropTarget() together" );
3050 SetDropTarget(new DragAcceptFilesTarget(this));
3054 SetDropTarget(NULL
);
3058 #endif // wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
3060 // ----------------------------------------------------------------------------
3062 // ----------------------------------------------------------------------------
3064 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
3066 while ( win
&& !win
->IsTopLevel() )
3067 win
= win
->GetParent();
3072 #if wxUSE_ACCESSIBILITY
3073 // ----------------------------------------------------------------------------
3074 // accessible object for windows
3075 // ----------------------------------------------------------------------------
3077 // Can return either a child object, or an integer
3078 // representing the child element, starting from 1.
3079 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
3081 wxASSERT( GetWindow() != NULL
);
3085 return wxACC_NOT_IMPLEMENTED
;
3088 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
3089 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
3091 wxASSERT( GetWindow() != NULL
);
3095 wxWindow
* win
= NULL
;
3102 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
3104 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
3111 rect
= win
->GetRect();
3112 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
3113 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
3117 return wxACC_NOT_IMPLEMENTED
;
3120 // Navigates from fromId to toId/toObject.
3121 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
3122 int* WXUNUSED(toId
), wxAccessible
** toObject
)
3124 wxASSERT( GetWindow() != NULL
);
3130 case wxNAVDIR_FIRSTCHILD
:
3132 if (GetWindow()->GetChildren().GetCount() == 0)
3134 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
3135 *toObject
= childWindow
->GetOrCreateAccessible();
3139 case wxNAVDIR_LASTCHILD
:
3141 if (GetWindow()->GetChildren().GetCount() == 0)
3143 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
3144 *toObject
= childWindow
->GetOrCreateAccessible();
3148 case wxNAVDIR_RIGHT
:
3152 wxWindowList::compatibility_iterator node
=
3153 wxWindowList::compatibility_iterator();
3156 // Can't navigate to sibling of this window
3157 // if we're a top-level window.
3158 if (!GetWindow()->GetParent())
3159 return wxACC_NOT_IMPLEMENTED
;
3161 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3165 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
3166 node
= GetWindow()->GetChildren().Item(fromId
-1);
3169 if (node
&& node
->GetNext())
3171 wxWindow
* nextWindow
= node
->GetNext()->GetData();
3172 *toObject
= nextWindow
->GetOrCreateAccessible();
3180 case wxNAVDIR_PREVIOUS
:
3182 wxWindowList::compatibility_iterator node
=
3183 wxWindowList::compatibility_iterator();
3186 // Can't navigate to sibling of this window
3187 // if we're a top-level window.
3188 if (!GetWindow()->GetParent())
3189 return wxACC_NOT_IMPLEMENTED
;
3191 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3195 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
3196 node
= GetWindow()->GetChildren().Item(fromId
-1);
3199 if (node
&& node
->GetPrevious())
3201 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
3202 *toObject
= previousWindow
->GetOrCreateAccessible();
3210 return wxACC_NOT_IMPLEMENTED
;
3213 // Gets the name of the specified object.
3214 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
3216 wxASSERT( GetWindow() != NULL
);
3222 // If a child, leave wxWidgets to call the function on the actual
3225 return wxACC_NOT_IMPLEMENTED
;
3227 // This will eventually be replaced by specialised
3228 // accessible classes, one for each kind of wxWidgets
3229 // control or window.
3231 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
3232 title
= ((wxButton
*) GetWindow())->GetLabel();
3235 title
= GetWindow()->GetName();
3243 return wxACC_NOT_IMPLEMENTED
;
3246 // Gets the number of children.
3247 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
3249 wxASSERT( GetWindow() != NULL
);
3253 *childId
= (int) GetWindow()->GetChildren().GetCount();
3257 // Gets the specified child (starting from 1).
3258 // If *child is NULL and return value is wxACC_OK,
3259 // this means that the child is a simple element and
3260 // not an accessible object.
3261 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
3263 wxASSERT( GetWindow() != NULL
);
3273 if (childId
> (int) GetWindow()->GetChildren().GetCount())
3276 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
3277 *child
= childWindow
->GetOrCreateAccessible();
3284 // Gets the parent, or NULL.
3285 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
3287 wxASSERT( GetWindow() != NULL
);
3291 wxWindow
* parentWindow
= GetWindow()->GetParent();
3299 *parent
= parentWindow
->GetOrCreateAccessible();
3307 // Performs the default action. childId is 0 (the action for this object)
3308 // or > 0 (the action for a child).
3309 // Return wxACC_NOT_SUPPORTED if there is no default action for this
3310 // window (e.g. an edit control).
3311 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
3313 wxASSERT( GetWindow() != NULL
);
3317 return wxACC_NOT_IMPLEMENTED
;
3320 // Gets the default action for this object (0) or > 0 (the action for a child).
3321 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
3322 // string if there is no action.
3323 // The retrieved string describes the action that is performed on an object,
3324 // not what the object does as a result. For example, a toolbar button that prints
3325 // a document has a default action of "Press" rather than "Prints the current document."
3326 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
3328 wxASSERT( GetWindow() != NULL
);
3332 return wxACC_NOT_IMPLEMENTED
;
3335 // Returns the description for this object or a child.
3336 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
3338 wxASSERT( GetWindow() != NULL
);
3342 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3348 return wxACC_NOT_IMPLEMENTED
;
3351 // Returns help text for this object or a child, similar to tooltip text.
3352 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
3354 wxASSERT( GetWindow() != NULL
);
3358 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3364 return wxACC_NOT_IMPLEMENTED
;
3367 // Returns the keyboard shortcut for this object or child.
3368 // Return e.g. ALT+K
3369 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
3371 wxASSERT( GetWindow() != NULL
);
3375 return wxACC_NOT_IMPLEMENTED
;
3378 // Returns a role constant.
3379 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
3381 wxASSERT( GetWindow() != NULL
);
3385 // If a child, leave wxWidgets to call the function on the actual
3388 return wxACC_NOT_IMPLEMENTED
;
3390 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3391 return wxACC_NOT_IMPLEMENTED
;
3393 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3394 return wxACC_NOT_IMPLEMENTED
;
3397 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3398 return wxACC_NOT_IMPLEMENTED
;
3401 //*role = wxROLE_SYSTEM_CLIENT;
3402 *role
= wxROLE_SYSTEM_CLIENT
;
3406 return wxACC_NOT_IMPLEMENTED
;
3410 // Returns a state constant.
3411 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
3413 wxASSERT( GetWindow() != NULL
);
3417 // If a child, leave wxWidgets to call the function on the actual
3420 return wxACC_NOT_IMPLEMENTED
;
3422 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3423 return wxACC_NOT_IMPLEMENTED
;
3426 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3427 return wxACC_NOT_IMPLEMENTED
;
3430 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3431 return wxACC_NOT_IMPLEMENTED
;
3438 return wxACC_NOT_IMPLEMENTED
;
3442 // Returns a localized string representing the value for the object
3444 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3446 wxASSERT( GetWindow() != NULL
);
3450 return wxACC_NOT_IMPLEMENTED
;
3453 // Selects the object or child.
3454 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3456 wxASSERT( GetWindow() != NULL
);
3460 return wxACC_NOT_IMPLEMENTED
;
3463 // Gets the window with the keyboard focus.
3464 // If childId is 0 and child is NULL, no object in
3465 // this subhierarchy has the focus.
3466 // If this object has the focus, child should be 'this'.
3467 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3469 wxASSERT( GetWindow() != NULL
);
3473 return wxACC_NOT_IMPLEMENTED
;
3477 // Gets a variant representing the selected children
3479 // Acceptable values:
3480 // - a null variant (IsNull() returns true)
3481 // - a list variant (GetType() == wxT("list")
3482 // - an integer representing the selected child element,
3483 // or 0 if this object is selected (GetType() == wxT("long")
3484 // - a "void*" pointer to a wxAccessible child object
3485 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3487 wxASSERT( GetWindow() != NULL
);
3491 return wxACC_NOT_IMPLEMENTED
;
3493 #endif // wxUSE_VARIANT
3495 #endif // wxUSE_ACCESSIBILITY
3497 // ----------------------------------------------------------------------------
3499 // ----------------------------------------------------------------------------
3502 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3504 wxCoord widthTotal
) const
3506 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3508 x
= widthTotal
- x
- width
;