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/msgout.h"
42 #include "wx/statusbr.h"
43 #include "wx/toolbar.h"
44 #include "wx/dcclient.h"
45 #include "wx/scrolbar.h"
46 #include "wx/layout.h"
51 #if wxUSE_DRAG_AND_DROP
53 #endif // wxUSE_DRAG_AND_DROP
55 #if wxUSE_ACCESSIBILITY
56 #include "wx/access.h"
60 #include "wx/cshelp.h"
64 #include "wx/tooltip.h"
65 #endif // wxUSE_TOOLTIPS
71 #if wxUSE_SYSTEM_OPTIONS
72 #include "wx/sysopt.h"
75 #include "wx/platinfo.h"
78 WXDLLIMPEXP_DATA_CORE(wxWindowList
) wxTopLevelWindows
;
82 wxMenu
*wxCurrentPopupMenu
= NULL
;
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
90 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
96 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
97 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
98 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
99 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
102 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
105 EVT_SIZE(wxWindowBase::InternalOnSize
)
108 // ============================================================================
109 // implementation of the common functionality of the wxWindow class
110 // ============================================================================
112 // ----------------------------------------------------------------------------
114 // ----------------------------------------------------------------------------
116 // the default initialization
117 wxWindowBase::wxWindowBase()
119 // no window yet, no parent nor children
121 m_windowId
= wxID_ANY
;
123 // no constraints on the minimal window size
125 m_maxWidth
= wxDefaultCoord
;
127 m_maxHeight
= wxDefaultCoord
;
129 // invalidiated cache value
130 m_bestSizeCache
= wxDefaultSize
;
132 // window are created enabled and visible by default
136 // the default event handler is just this window
137 m_eventHandler
= this;
141 m_windowValidator
= NULL
;
142 #endif // wxUSE_VALIDATORS
144 // the colours/fonts are default for now, so leave m_font,
145 // m_backgroundColour and m_foregroundColour uninitialized and set those
151 m_inheritFont
= false;
157 m_backgroundStyle
= wxBG_STYLE_ERASE
;
159 #if wxUSE_CONSTRAINTS
160 // no constraints whatsoever
161 m_constraints
= NULL
;
162 m_constraintsInvolvedIn
= NULL
;
163 #endif // wxUSE_CONSTRAINTS
165 m_windowSizer
= NULL
;
166 m_containingSizer
= NULL
;
167 m_autoLayout
= false;
169 #if wxUSE_DRAG_AND_DROP
171 #endif // wxUSE_DRAG_AND_DROP
175 #endif // wxUSE_TOOLTIPS
179 #endif // wxUSE_CARET
182 m_hasCustomPalette
= false;
183 #endif // wxUSE_PALETTE
185 #if wxUSE_ACCESSIBILITY
189 m_virtualSize
= wxDefaultSize
;
191 m_scrollHelper
= NULL
;
193 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
194 #if wxUSE_SYSTEM_OPTIONS
195 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
197 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
201 // Whether we're using the current theme for this window (wxGTK only for now)
202 m_themeEnabled
= false;
204 // This is set to true by SendDestroyEvent() which should be called by the
205 // most derived class to ensure that the destruction event is sent as soon
206 // as possible to allow its handlers to still see the undestroyed window
207 m_isBeingDeleted
= false;
212 // common part of window creation process
213 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
215 const wxPoint
& WXUNUSED(pos
),
218 const wxString
& name
)
220 // ids are limited to 16 bits under MSW so if you care about portability,
221 // it's not a good idea to use ids out of this range (and negative ids are
222 // reserved for wxWidgets own usage)
223 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767) ||
224 (id
>= wxID_AUTO_LOWEST
&& id
<= wxID_AUTO_HIGHEST
),
225 wxT("invalid id value") );
227 // generate a new id if the user doesn't care about it
228 if ( id
== wxID_ANY
)
230 m_windowId
= NewControlId();
232 else // valid id specified
237 // don't use SetWindowStyleFlag() here, this function should only be called
238 // to change the flag after creation as it tries to reflect the changes in
239 // flags by updating the window dynamically and we don't need this here
240 m_windowStyle
= style
;
242 // assume the user doesn't want this window to shrink beneath its initial
243 // size, this worked like this in wxWidgets 2.8 and before and generally
244 // often makes sense for child windows (for top level ones it definitely
245 // does not as the user should be able to resize the window)
246 if ( !wxTopLevelWindows
.Find(this) ) // can't use IsTopLevel() from ctor
255 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
260 const wxValidator
& wxVALIDATOR_PARAM(validator
),
261 const wxString
& name
)
263 if ( !CreateBase(parent
, id
, pos
, size
, style
, name
) )
267 SetValidator(validator
);
268 #endif // wxUSE_VALIDATORS
270 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
271 // have it too - like this it's possible to set it only in the top level
272 // dialog/frame and all children will inherit it by defult
273 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
275 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
281 bool wxWindowBase::ToggleWindowStyle(int flag
)
283 wxASSERT_MSG( flag
, wxT("flags with 0 value can't be toggled") );
286 long style
= GetWindowStyleFlag();
292 else // currently off
298 SetWindowStyleFlag(style
);
303 // ----------------------------------------------------------------------------
305 // ----------------------------------------------------------------------------
308 wxWindowBase::~wxWindowBase()
310 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
312 // FIXME if these 2 cases result from programming errors in the user code
313 // we should probably assert here instead of silently fixing them
315 // Just in case the window has been Closed, but we're then deleting
316 // immediately: don't leave dangling pointers.
317 wxPendingDelete
.DeleteObject(this);
319 // Just in case we've loaded a top-level window via LoadNativeDialog but
320 // we weren't a dialog class
321 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
324 // The associated popup menu can still be alive, disassociate from it in
326 if ( wxCurrentPopupMenu
&& wxCurrentPopupMenu
->GetInvokingWindow() == this )
327 wxCurrentPopupMenu
->SetInvokingWindow(NULL
);
328 #endif // wxUSE_MENUS
330 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
332 // notify the parent about this window destruction
334 m_parent
->RemoveChild(this);
338 #endif // wxUSE_CARET
341 delete m_windowValidator
;
342 #endif // wxUSE_VALIDATORS
344 #if wxUSE_CONSTRAINTS
345 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
346 // at deleted windows as they delete themselves.
347 DeleteRelatedConstraints();
351 // This removes any dangling pointers to this window in other windows'
352 // constraintsInvolvedIn lists.
353 UnsetConstraints(m_constraints
);
354 delete m_constraints
;
355 m_constraints
= NULL
;
357 #endif // wxUSE_CONSTRAINTS
359 if ( m_containingSizer
)
360 m_containingSizer
->Detach( (wxWindow
*)this );
362 delete m_windowSizer
;
364 #if wxUSE_DRAG_AND_DROP
366 #endif // wxUSE_DRAG_AND_DROP
370 #endif // wxUSE_TOOLTIPS
372 #if wxUSE_ACCESSIBILITY
377 // NB: this has to be called unconditionally, because we don't know
378 // whether this window has associated help text or not
379 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
381 helpProvider
->RemoveHelp(this);
385 bool wxWindowBase::IsBeingDeleted() const
387 return m_isBeingDeleted
||
388 (!IsTopLevel() && m_parent
&& m_parent
->IsBeingDeleted());
391 void wxWindowBase::SendDestroyEvent()
393 if ( m_isBeingDeleted
)
395 // we could have been already called from a more derived class dtor,
396 // e.g. ~wxTLW calls us and so does ~wxWindow and the latter call
397 // should be simply ignored
401 m_isBeingDeleted
= true;
403 wxWindowDestroyEvent event
;
404 event
.SetEventObject(this);
405 event
.SetId(GetId());
406 GetEventHandler()->ProcessEvent(event
);
409 bool wxWindowBase::Destroy()
418 bool wxWindowBase::Close(bool force
)
420 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
421 event
.SetEventObject(this);
422 event
.SetCanVeto(!force
);
424 // return false if window wasn't closed because the application vetoed the
426 return HandleWindowEvent(event
) && !event
.GetVeto();
429 bool wxWindowBase::DestroyChildren()
431 wxWindowList::compatibility_iterator node
;
434 // we iterate until the list becomes empty
435 node
= GetChildren().GetFirst();
439 wxWindow
*child
= node
->GetData();
441 // note that we really want to delete it immediately so don't call the
442 // possible overridden Destroy() version which might not delete the
443 // child immediately resulting in problems with our (top level) child
444 // outliving its parent
445 child
->wxWindowBase::Destroy();
447 wxASSERT_MSG( !GetChildren().Find(child
),
448 wxT("child didn't remove itself using RemoveChild()") );
454 // ----------------------------------------------------------------------------
455 // size/position related methods
456 // ----------------------------------------------------------------------------
458 // centre the window with respect to its parent in either (or both) directions
459 void wxWindowBase::DoCentre(int dir
)
461 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
462 wxT("this method only implements centering child windows") );
464 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
467 // fits the window around the children
468 void wxWindowBase::Fit()
470 if ( !GetChildren().empty() )
472 SetSize(GetBestSize());
474 //else: do nothing if we have no children
477 // fits virtual size (ie. scrolled area etc.) around children
478 void wxWindowBase::FitInside()
480 if ( GetChildren().GetCount() > 0 )
482 SetVirtualSize( GetBestVirtualSize() );
486 // On Mac, scrollbars are explicitly children.
487 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
488 static bool wxHasRealChildren(const wxWindowBase
* win
)
490 int realChildCount
= 0;
492 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
494 node
= node
->GetNext() )
496 wxWindow
*win
= node
->GetData();
497 if ( !win
->IsTopLevel() && win
->IsShown()
499 && !win
->IsKindOf(CLASSINFO(wxScrollBar
))
504 return (realChildCount
> 0);
508 void wxWindowBase::InvalidateBestSize()
510 m_bestSizeCache
= wxDefaultSize
;
512 // parent's best size calculation may depend on its children's
513 // as long as child window we are in is not top level window itself
514 // (because the TLW size is never resized automatically)
515 // so let's invalidate it as well to be safe:
516 if (m_parent
&& !IsTopLevel())
517 m_parent
->InvalidateBestSize();
520 // return the size best suited for the current window
521 wxSize
wxWindowBase::DoGetBestSize() const
527 best
= m_windowSizer
->GetMinSize();
529 #if wxUSE_CONSTRAINTS
530 else if ( m_constraints
)
532 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
534 // our minimal acceptable size is such that all our windows fit inside
538 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
540 node
= node
->GetNext() )
542 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
545 // it's not normal that we have an unconstrained child, but
546 // what can we do about it?
550 int x
= c
->right
.GetValue(),
551 y
= c
->bottom
.GetValue();
559 // TODO: we must calculate the overlaps somehow, otherwise we
560 // will never return a size bigger than the current one :-(
563 best
= wxSize(maxX
, maxY
);
565 #endif // wxUSE_CONSTRAINTS
566 else if ( !GetChildren().empty()
567 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
568 && wxHasRealChildren(this)
572 // our minimal acceptable size is such that all our visible child
573 // windows fit inside
577 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
579 node
= node
->GetNext() )
581 wxWindow
*win
= node
->GetData();
582 if ( win
->IsTopLevel()
585 || wxDynamicCast(win
, wxStatusBar
)
586 #endif // wxUSE_STATUSBAR
589 // dialogs and frames lie in different top level windows -
590 // don't deal with them here; as for the status bars, they
591 // don't lie in the client area at all
596 win
->GetPosition(&wx
, &wy
);
598 // if the window hadn't been positioned yet, assume that it is in
600 if ( wx
== wxDefaultCoord
)
602 if ( wy
== wxDefaultCoord
)
605 win
->GetSize(&ww
, &wh
);
606 if ( wx
+ ww
> maxX
)
608 if ( wy
+ wh
> maxY
)
612 best
= wxSize(maxX
, maxY
);
614 else // ! has children
616 wxSize size
= GetMinSize();
617 if ( !size
.IsFullySpecified() )
619 // if the window doesn't define its best size we assume that it can
620 // be arbitrarily small -- usually this is not the case, of course,
621 // but we have no way to know what the limit is, it should really
622 // override DoGetBestClientSize() itself to tell us
623 size
.SetDefaults(wxSize(1, 1));
626 // return as-is, unadjusted by the client size difference.
630 // Add any difference between size and client size
631 wxSize diff
= GetSize() - GetClientSize();
632 best
.x
+= wxMax(0, diff
.x
);
633 best
.y
+= wxMax(0, diff
.y
);
638 // helper of GetWindowBorderSize(): as many ports don't implement support for
639 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
640 // fallbacks in this case
641 static int wxGetMetricOrDefault(wxSystemMetric what
, const wxWindowBase
* win
)
643 int rc
= wxSystemSettings::GetMetric(
644 what
, static_cast<wxWindow
*>(const_cast<wxWindowBase
*>(win
)));
651 // 2D border is by default 1 pixel wide
657 // 3D borders are by default 2 pixels
662 wxFAIL_MSG( wxT("unexpected wxGetMetricOrDefault() argument") );
670 wxSize
wxWindowBase::GetWindowBorderSize() const
674 switch ( GetBorder() )
677 // nothing to do, size is already (0, 0)
680 case wxBORDER_SIMPLE
:
681 case wxBORDER_STATIC
:
682 size
.x
= wxGetMetricOrDefault(wxSYS_BORDER_X
, this);
683 size
.y
= wxGetMetricOrDefault(wxSYS_BORDER_Y
, this);
686 case wxBORDER_SUNKEN
:
687 case wxBORDER_RAISED
:
688 size
.x
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X
, this),
689 wxGetMetricOrDefault(wxSYS_BORDER_X
, this));
690 size
.y
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y
, this),
691 wxGetMetricOrDefault(wxSYS_BORDER_Y
, this));
694 case wxBORDER_DOUBLE
:
695 size
.x
= wxGetMetricOrDefault(wxSYS_EDGE_X
, this) +
696 wxGetMetricOrDefault(wxSYS_BORDER_X
, this);
697 size
.y
= wxGetMetricOrDefault(wxSYS_EDGE_Y
, this) +
698 wxGetMetricOrDefault(wxSYS_BORDER_Y
, this);
702 wxFAIL_MSG(wxT("Unknown border style."));
706 // we have borders on both sides
710 wxSize
wxWindowBase::GetEffectiveMinSize() const
712 // merge the best size with the min size, giving priority to the min size
713 wxSize min
= GetMinSize();
715 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
717 wxSize best
= GetBestSize();
718 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
719 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
725 wxSize
wxWindowBase::DoGetBorderSize() const
727 // there is one case in which we can implement it for all ports easily:
728 // do it as some classes used by both wxUniv and native ports (e.g.
729 // wxGenericStaticText) do override DoGetBestClientSize() and so this
730 // method must work for them and that ensures that it does, at least in
732 if ( GetBorder() == wxBORDER_NONE
)
735 wxFAIL_MSG( "must be overridden if called" );
737 return wxDefaultSize
;
740 wxSize
wxWindowBase::GetBestSize() const
742 if ( !m_windowSizer
&& m_bestSizeCache
.IsFullySpecified() )
743 return m_bestSizeCache
;
745 // call DoGetBestClientSize() first, if a derived class overrides it wants
747 wxSize size
= DoGetBestClientSize();
748 if ( size
!= wxDefaultSize
)
750 size
+= DoGetBorderSize();
756 return DoGetBestSize();
759 void wxWindowBase::SetMinSize(const wxSize
& minSize
)
761 m_minWidth
= minSize
.x
;
762 m_minHeight
= minSize
.y
;
765 void wxWindowBase::SetMaxSize(const wxSize
& maxSize
)
767 m_maxWidth
= maxSize
.x
;
768 m_maxHeight
= maxSize
.y
;
771 void wxWindowBase::SetInitialSize(const wxSize
& size
)
773 // Set the min size to the size passed in. This will usually either be
774 // wxDefaultSize or the size passed to this window's ctor/Create function.
777 // Merge the size with the best size if needed
778 wxSize best
= GetEffectiveMinSize();
780 // If the current size doesn't match then change it
781 if (GetSize() != best
)
786 // by default the origin is not shifted
787 wxPoint
wxWindowBase::GetClientAreaOrigin() const
792 wxSize
wxWindowBase::ClientToWindowSize(const wxSize
& size
) const
794 const wxSize
diff(GetSize() - GetClientSize());
796 return wxSize(size
.x
== -1 ? -1 : size
.x
+ diff
.x
,
797 size
.y
== -1 ? -1 : size
.y
+ diff
.y
);
800 wxSize
wxWindowBase::WindowToClientSize(const wxSize
& size
) const
802 const wxSize
diff(GetSize() - GetClientSize());
804 return wxSize(size
.x
== -1 ? -1 : size
.x
- diff
.x
,
805 size
.y
== -1 ? -1 : size
.y
- diff
.y
);
808 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
810 if ( m_windowVariant
!= variant
)
812 m_windowVariant
= variant
;
814 DoSetWindowVariant(variant
);
818 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
820 // adjust the font height to correspond to our new variant (notice that
821 // we're only called if something really changed)
822 wxFont font
= GetFont();
823 int size
= font
.GetPointSize();
826 case wxWINDOW_VARIANT_NORMAL
:
829 case wxWINDOW_VARIANT_SMALL
:
834 case wxWINDOW_VARIANT_MINI
:
839 case wxWINDOW_VARIANT_LARGE
:
845 wxFAIL_MSG(wxT("unexpected window variant"));
849 font
.SetPointSize(size
);
853 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
855 int WXUNUSED(incW
), int WXUNUSED(incH
) )
857 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
858 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
859 wxT("min width/height must be less than max width/height!") );
868 #if WXWIN_COMPATIBILITY_2_8
869 void wxWindowBase::SetVirtualSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
),
870 int WXUNUSED(maxW
), int WXUNUSED(maxH
))
874 void wxWindowBase::SetVirtualSizeHints(const wxSize
& WXUNUSED(minsize
),
875 const wxSize
& WXUNUSED(maxsize
))
878 #endif // WXWIN_COMPATIBILITY_2_8
880 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
882 m_virtualSize
= wxSize(x
, y
);
885 wxSize
wxWindowBase::DoGetVirtualSize() const
887 // we should use the entire client area so if it is greater than our
888 // virtual size, expand it to fit (otherwise if the window is big enough we
889 // wouldn't be using parts of it)
890 wxSize size
= GetClientSize();
891 if ( m_virtualSize
.x
> size
.x
)
892 size
.x
= m_virtualSize
.x
;
894 if ( m_virtualSize
.y
>= size
.y
)
895 size
.y
= m_virtualSize
.y
;
900 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
902 // screen position is the same as (0, 0) in client coords for non TLWs (and
903 // TLWs override this method)
909 ClientToScreen(x
, y
);
912 void wxWindowBase::SendSizeEvent(int flags
)
914 wxSizeEvent
event(GetSize(), GetId());
915 event
.SetEventObject(this);
916 if ( flags
& wxSEND_EVENT_POST
)
917 wxPostEvent(this, event
);
919 HandleWindowEvent(event
);
922 void wxWindowBase::SendSizeEventToParent(int flags
)
924 wxWindow
* const parent
= GetParent();
925 if ( parent
&& !parent
->IsBeingDeleted() )
926 parent
->SendSizeEvent(flags
);
929 bool wxWindowBase::HasScrollbar(int orient
) const
931 // if scrolling in the given direction is disabled, we can't have the
932 // corresponding scrollbar no matter what
933 if ( !CanScroll(orient
) )
936 const wxSize sizeVirt
= GetVirtualSize();
937 const wxSize sizeClient
= GetClientSize();
939 return orient
== wxHORIZONTAL
? sizeVirt
.x
> sizeClient
.x
940 : sizeVirt
.y
> sizeClient
.y
;
943 // ----------------------------------------------------------------------------
944 // show/hide/enable/disable the window
945 // ----------------------------------------------------------------------------
947 bool wxWindowBase::Show(bool show
)
949 if ( show
!= m_isShown
)
961 bool wxWindowBase::IsEnabled() const
963 return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
966 void wxWindowBase::NotifyWindowOnEnableChange(bool enabled
)
968 #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
970 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
974 // If we are top-level then the logic doesn't apply - otherwise
975 // showing a modal dialog would result in total greying out (and ungreying
976 // out later) of everything which would be really ugly
980 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
982 node
= node
->GetNext() )
984 wxWindowBase
* const child
= node
->GetData();
985 if ( !child
->IsTopLevel() && child
->IsThisEnabled() )
986 child
->NotifyWindowOnEnableChange(enabled
);
990 bool wxWindowBase::Enable(bool enable
)
992 if ( enable
== IsThisEnabled() )
995 m_isEnabled
= enable
;
997 #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
999 #else // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
1000 wxWindowBase
* const parent
= GetParent();
1001 if( !IsTopLevel() && parent
&& !parent
->IsEnabled() )
1005 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
1007 NotifyWindowOnEnableChange(enable
);
1012 bool wxWindowBase::IsShownOnScreen() const
1014 // A window is shown on screen if it itself is shown and so are all its
1015 // parents. But if a window is toplevel one, then its always visible on
1016 // screen if IsShown() returns true, even if it has a hidden parent.
1018 (IsTopLevel() || GetParent() == NULL
|| GetParent()->IsShownOnScreen());
1021 // ----------------------------------------------------------------------------
1023 // ----------------------------------------------------------------------------
1025 bool wxWindowBase::IsTopLevel() const
1030 // ----------------------------------------------------------------------------
1032 // ----------------------------------------------------------------------------
1034 void wxWindowBase::Freeze()
1036 if ( !m_freezeCount
++ )
1038 // physically freeze this window:
1041 // and recursively freeze all children:
1042 for ( wxWindowList::iterator i
= GetChildren().begin();
1043 i
!= GetChildren().end(); ++i
)
1045 wxWindow
*child
= *i
;
1046 if ( child
->IsTopLevel() )
1054 void wxWindowBase::Thaw()
1056 wxASSERT_MSG( m_freezeCount
, "Thaw() without matching Freeze()" );
1058 if ( !--m_freezeCount
)
1060 // recursively thaw all children:
1061 for ( wxWindowList::iterator i
= GetChildren().begin();
1062 i
!= GetChildren().end(); ++i
)
1064 wxWindow
*child
= *i
;
1065 if ( child
->IsTopLevel() )
1071 // physically thaw this window:
1076 // ----------------------------------------------------------------------------
1077 // reparenting the window
1078 // ----------------------------------------------------------------------------
1080 void wxWindowBase::AddChild(wxWindowBase
*child
)
1082 wxCHECK_RET( child
, wxT("can't add a NULL child") );
1084 // this should never happen and it will lead to a crash later if it does
1085 // because RemoveChild() will remove only one node from the children list
1086 // and the other(s) one(s) will be left with dangling pointers in them
1087 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), wxT("AddChild() called twice") );
1089 GetChildren().Append((wxWindow
*)child
);
1090 child
->SetParent(this);
1092 // adding a child while frozen will assert when thawed, so freeze it as if
1093 // it had been already present when we were frozen
1094 if ( IsFrozen() && !child
->IsTopLevel() )
1098 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
1100 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
1102 // removing a child while frozen may result in permanently frozen window
1103 // if used e.g. from Reparent(), so thaw it
1105 // NB: IsTopLevel() doesn't return true any more when a TLW child is being
1106 // removed from its ~wxWindowBase, so check for IsBeingDeleted() too
1107 if ( IsFrozen() && !child
->IsBeingDeleted() && !child
->IsTopLevel() )
1110 GetChildren().DeleteObject((wxWindow
*)child
);
1111 child
->SetParent(NULL
);
1114 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
1116 wxWindow
*oldParent
= GetParent();
1117 if ( newParent
== oldParent
)
1123 const bool oldEnabledState
= IsEnabled();
1125 // unlink this window from the existing parent.
1128 oldParent
->RemoveChild(this);
1132 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
1135 // add it to the new one
1138 newParent
->AddChild(this);
1142 wxTopLevelWindows
.Append((wxWindow
*)this);
1145 // We need to notify window (and its subwindows) if by changing the parent
1146 // we also change our enabled/disabled status.
1147 const bool newEnabledState
= IsEnabled();
1148 if ( newEnabledState
!= oldEnabledState
)
1150 NotifyWindowOnEnableChange(newEnabledState
);
1156 // ----------------------------------------------------------------------------
1157 // event handler stuff
1158 // ----------------------------------------------------------------------------
1160 void wxWindowBase::SetEventHandler(wxEvtHandler
*handler
)
1162 wxCHECK_RET(handler
!= NULL
, "SetEventHandler(NULL) called");
1164 m_eventHandler
= handler
;
1167 void wxWindowBase::SetNextHandler(wxEvtHandler
*WXUNUSED(handler
))
1169 // disable wxEvtHandler chain mechanism for wxWindows:
1170 // wxWindow uses its own stack mechanism which doesn't mix well with wxEvtHandler's one
1172 wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
1174 void wxWindowBase::SetPreviousHandler(wxEvtHandler
*WXUNUSED(handler
))
1176 // we can't simply wxFAIL here as in SetNextHandler: in fact the last
1177 // handler of our stack when is destroyed will be Unlink()ed and thus
1178 // will call this function to update the pointer of this window...
1180 //wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
1183 void wxWindowBase::PushEventHandler(wxEvtHandler
*handlerToPush
)
1185 wxCHECK_RET( handlerToPush
!= NULL
, "PushEventHandler(NULL) called" );
1187 // the new handler is going to be part of the wxWindow stack of event handlers:
1188 // it can't be part also of an event handler double-linked chain:
1189 wxASSERT_MSG(handlerToPush
->IsUnlinked(),
1190 "The handler being pushed in the wxWindow stack shouldn't be part of "
1191 "a wxEvtHandler chain; call Unlink() on it first");
1193 wxEvtHandler
*handlerOld
= GetEventHandler();
1194 wxCHECK_RET( handlerOld
, "an old event handler is NULL?" );
1196 // now use wxEvtHandler double-linked list to implement a stack:
1197 handlerToPush
->SetNextHandler(handlerOld
);
1199 if (handlerOld
!= this)
1200 handlerOld
->SetPreviousHandler(handlerToPush
);
1202 SetEventHandler(handlerToPush
);
1205 // final checks of the operations done above:
1206 wxASSERT_MSG( handlerToPush
->GetPreviousHandler() == NULL
,
1207 "the first handler of the wxWindow stack should "
1208 "have no previous handlers set" );
1209 wxASSERT_MSG( handlerToPush
->GetNextHandler() != NULL
,
1210 "the first handler of the wxWindow stack should "
1211 "have non-NULL next handler" );
1213 wxEvtHandler
* pLast
= handlerToPush
;
1214 while ( pLast
&& pLast
!= this )
1215 pLast
= pLast
->GetNextHandler();
1216 wxASSERT_MSG( pLast
->GetNextHandler() == NULL
,
1217 "the last handler of the wxWindow stack should "
1218 "have this window as next handler" );
1219 #endif // wxDEBUG_LEVEL
1222 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
1224 // we need to pop the wxWindow stack, i.e. we need to remove the first handler
1226 wxEvtHandler
*firstHandler
= GetEventHandler();
1227 wxCHECK_MSG( firstHandler
!= NULL
, NULL
, "wxWindow cannot have a NULL event handler" );
1228 wxCHECK_MSG( firstHandler
!= this, NULL
, "cannot pop the wxWindow itself" );
1229 wxCHECK_MSG( firstHandler
->GetPreviousHandler() == NULL
, NULL
,
1230 "the first handler of the wxWindow stack should have no previous handlers set" );
1232 wxEvtHandler
*secondHandler
= firstHandler
->GetNextHandler();
1233 wxCHECK_MSG( secondHandler
!= NULL
, NULL
,
1234 "the first handler of the wxWindow stack should have non-NULL next handler" );
1236 firstHandler
->SetNextHandler(NULL
);
1237 secondHandler
->SetPreviousHandler(NULL
);
1239 // now firstHandler is completely unlinked; set secondHandler as the new window event handler
1240 SetEventHandler(secondHandler
);
1242 if ( deleteHandler
)
1244 delete firstHandler
;
1245 firstHandler
= NULL
;
1248 return firstHandler
;
1251 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handlerToRemove
)
1253 wxCHECK_MSG( handlerToRemove
!= NULL
, false, "RemoveEventHandler(NULL) called" );
1254 wxCHECK_MSG( handlerToRemove
!= this, false, "Cannot remove the window itself" );
1256 if (handlerToRemove
== GetEventHandler())
1258 // removing the first event handler is equivalent to "popping" the stack
1259 PopEventHandler(false);
1263 // NOTE: the wxWindow event handler list is always terminated with "this" handler
1264 wxEvtHandler
*handlerCur
= GetEventHandler()->GetNextHandler();
1265 while ( handlerCur
!= this )
1267 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
1269 if ( handlerCur
== handlerToRemove
)
1271 handlerCur
->Unlink();
1273 wxASSERT_MSG( handlerCur
!= GetEventHandler(),
1274 "the case Remove == Pop should was already handled" );
1278 handlerCur
= handlerNext
;
1281 wxFAIL_MSG( wxT("where has the event handler gone?") );
1286 bool wxWindowBase::HandleWindowEvent(wxEvent
& event
) const
1288 // SafelyProcessEvent() will handle exceptions nicely
1289 return GetEventHandler()->SafelyProcessEvent(event
);
1292 // ----------------------------------------------------------------------------
1293 // colours, fonts &c
1294 // ----------------------------------------------------------------------------
1296 void wxWindowBase::InheritAttributes()
1298 const wxWindowBase
* const parent
= GetParent();
1302 // we only inherit attributes which had been explicitly set for the parent
1303 // which ensures that this only happens if the user really wants it and
1304 // not by default which wouldn't make any sense in modern GUIs where the
1305 // controls don't all use the same fonts (nor colours)
1306 if ( parent
->m_inheritFont
&& !m_hasFont
)
1307 SetFont(parent
->GetFont());
1309 // in addition, there is a possibility to explicitly forbid inheriting
1310 // colours at each class level by overriding ShouldInheritColours()
1311 if ( ShouldInheritColours() )
1313 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1314 SetForegroundColour(parent
->GetForegroundColour());
1316 // inheriting (solid) background colour is wrong as it totally breaks
1317 // any kind of themed backgrounds
1319 // instead, the controls should use the same background as their parent
1320 // (ideally by not drawing it at all)
1322 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1323 SetBackgroundColour(parent
->GetBackgroundColour());
1328 /* static */ wxVisualAttributes
1329 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1331 // it is important to return valid values for all attributes from here,
1332 // GetXXX() below rely on this
1333 wxVisualAttributes attrs
;
1334 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1335 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1337 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1338 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1339 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1340 // colour on other platforms.
1342 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1343 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1345 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1350 wxColour
wxWindowBase::GetBackgroundColour() const
1352 if ( !m_backgroundColour
.IsOk() )
1354 wxASSERT_MSG( !m_hasBgCol
, wxT("we have invalid explicit bg colour?") );
1356 // get our default background colour
1357 wxColour colBg
= GetDefaultAttributes().colBg
;
1359 // we must return some valid colour to avoid redoing this every time
1360 // and also to avoid surprizing the applications written for older
1361 // wxWidgets versions where GetBackgroundColour() always returned
1362 // something -- so give them something even if it doesn't make sense
1363 // for this window (e.g. it has a themed background)
1365 colBg
= GetClassDefaultAttributes().colBg
;
1370 return m_backgroundColour
;
1373 wxColour
wxWindowBase::GetForegroundColour() const
1375 // logic is the same as above
1376 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1378 wxColour colFg
= GetDefaultAttributes().colFg
;
1380 if ( !colFg
.IsOk() )
1381 colFg
= GetClassDefaultAttributes().colFg
;
1386 return m_foregroundColour
;
1389 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1391 if ( colour
== m_backgroundColour
)
1394 m_hasBgCol
= colour
.IsOk();
1396 m_inheritBgCol
= m_hasBgCol
;
1397 m_backgroundColour
= colour
;
1398 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1402 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1404 if (colour
== m_foregroundColour
)
1407 m_hasFgCol
= colour
.IsOk();
1408 m_inheritFgCol
= m_hasFgCol
;
1409 m_foregroundColour
= colour
;
1410 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1414 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1416 // setting an invalid cursor is ok, it means that we don't have any special
1418 if ( m_cursor
.IsSameAs(cursor
) )
1429 wxFont
wxWindowBase::GetFont() const
1431 // logic is the same as in GetBackgroundColour()
1432 if ( !m_font
.IsOk() )
1434 wxASSERT_MSG( !m_hasFont
, wxT("we have invalid explicit font?") );
1436 wxFont font
= GetDefaultAttributes().font
;
1438 font
= GetClassDefaultAttributes().font
;
1446 bool wxWindowBase::SetFont(const wxFont
& font
)
1448 if ( font
== m_font
)
1455 m_hasFont
= font
.IsOk();
1456 m_inheritFont
= m_hasFont
;
1458 InvalidateBestSize();
1465 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1467 m_hasCustomPalette
= true;
1470 // VZ: can anyone explain me what do we do here?
1471 wxWindowDC
d((wxWindow
*) this);
1475 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1477 wxWindow
*win
= (wxWindow
*)this;
1478 while ( win
&& !win
->HasCustomPalette() )
1480 win
= win
->GetParent();
1486 #endif // wxUSE_PALETTE
1489 void wxWindowBase::SetCaret(wxCaret
*caret
)
1500 wxASSERT_MSG( m_caret
->GetWindow() == this,
1501 wxT("caret should be created associated to this window") );
1504 #endif // wxUSE_CARET
1506 #if wxUSE_VALIDATORS
1507 // ----------------------------------------------------------------------------
1509 // ----------------------------------------------------------------------------
1511 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1513 if ( m_windowValidator
)
1514 delete m_windowValidator
;
1516 m_windowValidator
= (wxValidator
*)validator
.Clone();
1518 if ( m_windowValidator
)
1519 m_windowValidator
->SetWindow(this);
1521 #endif // wxUSE_VALIDATORS
1523 // ----------------------------------------------------------------------------
1524 // update region stuff
1525 // ----------------------------------------------------------------------------
1527 wxRect
wxWindowBase::GetUpdateClientRect() const
1529 wxRegion rgnUpdate
= GetUpdateRegion();
1530 rgnUpdate
.Intersect(GetClientRect());
1531 wxRect rectUpdate
= rgnUpdate
.GetBox();
1532 wxPoint ptOrigin
= GetClientAreaOrigin();
1533 rectUpdate
.x
-= ptOrigin
.x
;
1534 rectUpdate
.y
-= ptOrigin
.y
;
1539 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1541 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1544 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1546 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1549 void wxWindowBase::ClearBackground()
1551 // wxGTK uses its own version, no need to add never used code
1553 wxClientDC
dc((wxWindow
*)this);
1554 wxBrush
brush(GetBackgroundColour(), wxBRUSHSTYLE_SOLID
);
1555 dc
.SetBackground(brush
);
1560 // ----------------------------------------------------------------------------
1561 // find child window by id or name
1562 // ----------------------------------------------------------------------------
1564 wxWindow
*wxWindowBase::FindWindow(long id
) const
1566 if ( id
== m_windowId
)
1567 return (wxWindow
*)this;
1569 wxWindowBase
*res
= NULL
;
1570 wxWindowList::compatibility_iterator node
;
1571 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1573 wxWindowBase
*child
= node
->GetData();
1574 res
= child
->FindWindow( id
);
1577 return (wxWindow
*)res
;
1580 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1582 if ( name
== m_windowName
)
1583 return (wxWindow
*)this;
1585 wxWindowBase
*res
= NULL
;
1586 wxWindowList::compatibility_iterator node
;
1587 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1589 wxWindow
*child
= node
->GetData();
1590 res
= child
->FindWindow(name
);
1593 return (wxWindow
*)res
;
1597 // find any window by id or name or label: If parent is non-NULL, look through
1598 // children for a label or title matching the specified string. If NULL, look
1599 // through all top-level windows.
1601 // to avoid duplicating code we reuse the same helper function but with
1602 // different comparators
1604 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1605 const wxString
& label
, long id
);
1608 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1611 return win
->GetLabel() == label
;
1615 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1618 return win
->GetName() == label
;
1622 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1625 return win
->GetId() == id
;
1628 // recursive helper for the FindWindowByXXX() functions
1630 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1631 const wxString
& label
,
1633 wxFindWindowCmp cmp
)
1637 // see if this is the one we're looking for
1638 if ( (*cmp
)(parent
, label
, id
) )
1639 return (wxWindow
*)parent
;
1641 // It wasn't, so check all its children
1642 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1644 node
= node
->GetNext() )
1646 // recursively check each child
1647 wxWindow
*win
= (wxWindow
*)node
->GetData();
1648 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1658 // helper for FindWindowByXXX()
1660 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1661 const wxString
& label
,
1663 wxFindWindowCmp cmp
)
1667 // just check parent and all its children
1668 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1671 // start at very top of wx's windows
1672 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1674 node
= node
->GetNext() )
1676 // recursively check each window & its children
1677 wxWindow
*win
= node
->GetData();
1678 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1688 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1690 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1695 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1697 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1701 // fall back to the label
1702 win
= FindWindowByLabel(title
, parent
);
1710 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1712 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1715 // ----------------------------------------------------------------------------
1716 // dialog oriented functions
1717 // ----------------------------------------------------------------------------
1719 void wxWindowBase::MakeModal(bool modal
)
1721 // Disable all other windows
1724 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1727 wxWindow
*win
= node
->GetData();
1729 win
->Enable(!modal
);
1731 node
= node
->GetNext();
1736 bool wxWindowBase::Validate()
1738 #if wxUSE_VALIDATORS
1739 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1741 wxWindowList::compatibility_iterator node
;
1742 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1744 wxWindowBase
*child
= node
->GetData();
1745 wxValidator
*validator
= child
->GetValidator();
1746 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1751 if ( recurse
&& !child
->Validate() )
1756 #endif // wxUSE_VALIDATORS
1761 bool wxWindowBase::TransferDataToWindow()
1763 #if wxUSE_VALIDATORS
1764 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1766 wxWindowList::compatibility_iterator node
;
1767 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1769 wxWindowBase
*child
= node
->GetData();
1770 wxValidator
*validator
= child
->GetValidator();
1771 if ( validator
&& !validator
->TransferToWindow() )
1773 wxLogWarning(_("Could not transfer data to window"));
1775 wxLog::FlushActive();
1783 if ( !child
->TransferDataToWindow() )
1785 // warning already given
1790 #endif // wxUSE_VALIDATORS
1795 bool wxWindowBase::TransferDataFromWindow()
1797 #if wxUSE_VALIDATORS
1798 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1800 wxWindowList::compatibility_iterator node
;
1801 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1803 wxWindow
*child
= node
->GetData();
1804 wxValidator
*validator
= child
->GetValidator();
1805 if ( validator
&& !validator
->TransferFromWindow() )
1807 // nop warning here because the application is supposed to give
1808 // one itself - we don't know here what might have gone wrongly
1815 if ( !child
->TransferDataFromWindow() )
1817 // warning already given
1822 #endif // wxUSE_VALIDATORS
1827 void wxWindowBase::InitDialog()
1829 wxInitDialogEvent
event(GetId());
1830 event
.SetEventObject( this );
1831 GetEventHandler()->ProcessEvent(event
);
1834 // ----------------------------------------------------------------------------
1835 // context-sensitive help support
1836 // ----------------------------------------------------------------------------
1840 // associate this help text with this window
1841 void wxWindowBase::SetHelpText(const wxString
& text
)
1843 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1846 helpProvider
->AddHelp(this, text
);
1850 #if WXWIN_COMPATIBILITY_2_8
1851 // associate this help text with all windows with the same id as this
1853 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1855 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1858 helpProvider
->AddHelp(GetId(), text
);
1861 #endif // WXWIN_COMPATIBILITY_2_8
1863 // get the help string associated with this window (may be empty)
1864 // default implementation forwards calls to the help provider
1866 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1867 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1870 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1873 text
= helpProvider
->GetHelp(this);
1879 // show help for this window
1880 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1882 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1885 wxPoint pos
= event
.GetPosition();
1886 const wxHelpEvent::Origin origin
= event
.GetOrigin();
1887 if ( origin
== wxHelpEvent::Origin_Keyboard
)
1889 // if the help event was generated from keyboard it shouldn't
1890 // appear at the mouse position (which is still the only position
1891 // associated with help event) if the mouse is far away, although
1892 // we still do use the mouse position if it's over the window
1893 // because we suppose the user looks approximately at the mouse
1894 // already and so it would be more convenient than showing tooltip
1895 // at some arbitrary position which can be quite far from it
1896 const wxRect rectClient
= GetClientRect();
1897 if ( !rectClient
.Contains(ScreenToClient(pos
)) )
1899 // position help slightly under and to the right of this window
1900 pos
= ClientToScreen(wxPoint(
1902 rectClient
.height
+ GetCharHeight()
1907 if ( helpProvider
->ShowHelpAtPoint(this, pos
, origin
) )
1909 // skip the event.Skip() below
1917 #endif // wxUSE_HELP
1919 // ----------------------------------------------------------------------------
1921 // ----------------------------------------------------------------------------
1925 wxString
wxWindowBase::GetToolTipText() const
1927 return m_tooltip
? m_tooltip
->GetTip() : wxString();
1930 void wxWindowBase::SetToolTip( const wxString
&tip
)
1932 // don't create the new tooltip if we already have one
1935 m_tooltip
->SetTip( tip
);
1939 SetToolTip( new wxToolTip( tip
) );
1942 // setting empty tooltip text does not remove the tooltip any more - use
1943 // SetToolTip(NULL) for this
1946 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1948 if ( m_tooltip
!= tooltip
)
1953 m_tooltip
= tooltip
;
1957 #endif // wxUSE_TOOLTIPS
1959 // ----------------------------------------------------------------------------
1960 // constraints and sizers
1961 // ----------------------------------------------------------------------------
1963 #if wxUSE_CONSTRAINTS
1965 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1967 if ( m_constraints
)
1969 UnsetConstraints(m_constraints
);
1970 delete m_constraints
;
1972 m_constraints
= constraints
;
1973 if ( m_constraints
)
1975 // Make sure other windows know they're part of a 'meaningful relationship'
1976 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1977 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1978 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1979 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1980 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1981 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1982 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1983 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1984 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1985 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1986 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1987 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1988 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1989 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1990 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1991 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1995 // This removes any dangling pointers to this window in other windows'
1996 // constraintsInvolvedIn lists.
1997 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
2001 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
2002 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
2003 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
2004 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
2005 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
2006 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
2007 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
2008 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
2009 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
2010 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
2011 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
2012 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
2013 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
2014 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
2015 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
2016 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
2020 // Back-pointer to other windows we're involved with, so if we delete this
2021 // window, we must delete any constraints we're involved with.
2022 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
2024 if ( !m_constraintsInvolvedIn
)
2025 m_constraintsInvolvedIn
= new wxWindowList
;
2026 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
2027 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
2030 // REMOVE back-pointer to other windows we're involved with.
2031 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
2033 if ( m_constraintsInvolvedIn
)
2034 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
2037 // Reset any constraints that mention this window
2038 void wxWindowBase::DeleteRelatedConstraints()
2040 if ( m_constraintsInvolvedIn
)
2042 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
2045 wxWindow
*win
= node
->GetData();
2046 wxLayoutConstraints
*constr
= win
->GetConstraints();
2048 // Reset any constraints involving this window
2051 constr
->left
.ResetIfWin(this);
2052 constr
->top
.ResetIfWin(this);
2053 constr
->right
.ResetIfWin(this);
2054 constr
->bottom
.ResetIfWin(this);
2055 constr
->width
.ResetIfWin(this);
2056 constr
->height
.ResetIfWin(this);
2057 constr
->centreX
.ResetIfWin(this);
2058 constr
->centreY
.ResetIfWin(this);
2061 wxWindowList::compatibility_iterator next
= node
->GetNext();
2062 m_constraintsInvolvedIn
->Erase(node
);
2066 delete m_constraintsInvolvedIn
;
2067 m_constraintsInvolvedIn
= NULL
;
2071 #endif // wxUSE_CONSTRAINTS
2073 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
2075 if ( sizer
== m_windowSizer
)
2078 if ( m_windowSizer
)
2080 m_windowSizer
->SetContainingWindow(NULL
);
2083 delete m_windowSizer
;
2086 m_windowSizer
= sizer
;
2087 if ( m_windowSizer
)
2089 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
2092 SetAutoLayout(m_windowSizer
!= NULL
);
2095 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
2097 SetSizer( sizer
, deleteOld
);
2098 sizer
->SetSizeHints( (wxWindow
*) this );
2102 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
2104 // adding a window to a sizer twice is going to result in fatal and
2105 // hard to debug problems later because when deleting the second
2106 // associated wxSizerItem we're going to dereference a dangling
2107 // pointer; so try to detect this as early as possible
2108 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
2109 wxT("Adding a window to the same sizer twice?") );
2111 m_containingSizer
= sizer
;
2114 #if wxUSE_CONSTRAINTS
2116 void wxWindowBase::SatisfyConstraints()
2118 wxLayoutConstraints
*constr
= GetConstraints();
2119 bool wasOk
= constr
&& constr
->AreSatisfied();
2121 ResetConstraints(); // Mark all constraints as unevaluated
2125 // if we're a top level panel (i.e. our parent is frame/dialog), our
2126 // own constraints will never be satisfied any more unless we do it
2130 while ( noChanges
> 0 )
2132 LayoutPhase1(&noChanges
);
2136 LayoutPhase2(&noChanges
);
2139 #endif // wxUSE_CONSTRAINTS
2141 bool wxWindowBase::Layout()
2143 // If there is a sizer, use it instead of the constraints
2147 GetVirtualSize(&w
, &h
);
2148 GetSizer()->SetDimension( 0, 0, w
, h
);
2150 #if wxUSE_CONSTRAINTS
2153 SatisfyConstraints(); // Find the right constraints values
2154 SetConstraintSizes(); // Recursively set the real window sizes
2161 void wxWindowBase::InternalOnSize(wxSizeEvent
& event
)
2163 if ( GetAutoLayout() )
2169 #if wxUSE_CONSTRAINTS
2171 // first phase of the constraints evaluation: set our own constraints
2172 bool wxWindowBase::LayoutPhase1(int *noChanges
)
2174 wxLayoutConstraints
*constr
= GetConstraints();
2176 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
2179 // second phase: set the constraints for our children
2180 bool wxWindowBase::LayoutPhase2(int *noChanges
)
2187 // Layout grand children
2193 // Do a phase of evaluating child constraints
2194 bool wxWindowBase::DoPhase(int phase
)
2196 // the list containing the children for which the constraints are already
2198 wxWindowList succeeded
;
2200 // the max number of iterations we loop before concluding that we can't set
2202 static const int maxIterations
= 500;
2204 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
2208 // loop over all children setting their constraints
2209 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2211 node
= node
->GetNext() )
2213 wxWindow
*child
= node
->GetData();
2214 if ( child
->IsTopLevel() )
2216 // top level children are not inside our client area
2220 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
2222 // this one is either already ok or nothing we can do about it
2226 int tempNoChanges
= 0;
2227 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
2228 : child
->LayoutPhase2(&tempNoChanges
);
2229 noChanges
+= tempNoChanges
;
2233 succeeded
.Append(child
);
2239 // constraints are set
2247 void wxWindowBase::ResetConstraints()
2249 wxLayoutConstraints
*constr
= GetConstraints();
2252 constr
->left
.SetDone(false);
2253 constr
->top
.SetDone(false);
2254 constr
->right
.SetDone(false);
2255 constr
->bottom
.SetDone(false);
2256 constr
->width
.SetDone(false);
2257 constr
->height
.SetDone(false);
2258 constr
->centreX
.SetDone(false);
2259 constr
->centreY
.SetDone(false);
2262 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2265 wxWindow
*win
= node
->GetData();
2266 if ( !win
->IsTopLevel() )
2267 win
->ResetConstraints();
2268 node
= node
->GetNext();
2272 // Need to distinguish between setting the 'fake' size for windows and sizers,
2273 // and setting the real values.
2274 void wxWindowBase::SetConstraintSizes(bool recurse
)
2276 wxLayoutConstraints
*constr
= GetConstraints();
2277 if ( constr
&& constr
->AreSatisfied() )
2279 int x
= constr
->left
.GetValue();
2280 int y
= constr
->top
.GetValue();
2281 int w
= constr
->width
.GetValue();
2282 int h
= constr
->height
.GetValue();
2284 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
2285 (constr
->height
.GetRelationship() != wxAsIs
) )
2287 SetSize(x
, y
, w
, h
);
2291 // If we don't want to resize this window, just move it...
2297 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
2298 GetClassInfo()->GetClassName(),
2304 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2307 wxWindow
*win
= node
->GetData();
2308 if ( !win
->IsTopLevel() && win
->GetConstraints() )
2309 win
->SetConstraintSizes();
2310 node
= node
->GetNext();
2315 // Only set the size/position of the constraint (if any)
2316 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
2318 wxLayoutConstraints
*constr
= GetConstraints();
2321 if ( x
!= wxDefaultCoord
)
2323 constr
->left
.SetValue(x
);
2324 constr
->left
.SetDone(true);
2326 if ( y
!= wxDefaultCoord
)
2328 constr
->top
.SetValue(y
);
2329 constr
->top
.SetDone(true);
2331 if ( w
!= wxDefaultCoord
)
2333 constr
->width
.SetValue(w
);
2334 constr
->width
.SetDone(true);
2336 if ( h
!= wxDefaultCoord
)
2338 constr
->height
.SetValue(h
);
2339 constr
->height
.SetDone(true);
2344 void wxWindowBase::MoveConstraint(int x
, int y
)
2346 wxLayoutConstraints
*constr
= GetConstraints();
2349 if ( x
!= wxDefaultCoord
)
2351 constr
->left
.SetValue(x
);
2352 constr
->left
.SetDone(true);
2354 if ( y
!= wxDefaultCoord
)
2356 constr
->top
.SetValue(y
);
2357 constr
->top
.SetDone(true);
2362 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2364 wxLayoutConstraints
*constr
= GetConstraints();
2367 *w
= constr
->width
.GetValue();
2368 *h
= constr
->height
.GetValue();
2374 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2376 wxLayoutConstraints
*constr
= GetConstraints();
2379 *w
= constr
->width
.GetValue();
2380 *h
= constr
->height
.GetValue();
2383 GetClientSize(w
, h
);
2386 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2388 wxLayoutConstraints
*constr
= GetConstraints();
2391 *x
= constr
->left
.GetValue();
2392 *y
= constr
->top
.GetValue();
2398 #endif // wxUSE_CONSTRAINTS
2400 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2402 // don't do it for the dialogs/frames - they float independently of their
2404 if ( !IsTopLevel() )
2406 wxWindow
*parent
= GetParent();
2407 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2409 wxPoint
pt(parent
->GetClientAreaOrigin());
2416 // ----------------------------------------------------------------------------
2417 // Update UI processing
2418 // ----------------------------------------------------------------------------
2420 void wxWindowBase::UpdateWindowUI(long flags
)
2422 wxUpdateUIEvent
event(GetId());
2423 event
.SetEventObject(this);
2425 if ( GetEventHandler()->ProcessEvent(event
) )
2427 DoUpdateWindowUI(event
);
2430 if (flags
& wxUPDATE_UI_RECURSE
)
2432 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2435 wxWindow
* child
= (wxWindow
*) node
->GetData();
2436 child
->UpdateWindowUI(flags
);
2437 node
= node
->GetNext();
2442 // do the window-specific processing after processing the update event
2443 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2445 if ( event
.GetSetEnabled() )
2446 Enable(event
.GetEnabled());
2448 if ( event
.GetSetShown() )
2449 Show(event
.GetShown());
2452 // ----------------------------------------------------------------------------
2453 // dialog units translations
2454 // ----------------------------------------------------------------------------
2456 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2458 int charWidth
= GetCharWidth();
2459 int charHeight
= GetCharHeight();
2460 wxPoint pt2
= wxDefaultPosition
;
2461 if (pt
.x
!= wxDefaultCoord
)
2462 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2463 if (pt
.y
!= wxDefaultCoord
)
2464 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2469 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2471 int charWidth
= GetCharWidth();
2472 int charHeight
= GetCharHeight();
2473 wxPoint pt2
= wxDefaultPosition
;
2474 if (pt
.x
!= wxDefaultCoord
)
2475 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2476 if (pt
.y
!= wxDefaultCoord
)
2477 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2482 // ----------------------------------------------------------------------------
2484 // ----------------------------------------------------------------------------
2486 // propagate the colour change event to the subwindows
2487 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
2489 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2492 // Only propagate to non-top-level windows
2493 wxWindow
*win
= node
->GetData();
2494 if ( !win
->IsTopLevel() )
2496 wxSysColourChangedEvent event2
;
2497 event2
.SetEventObject(win
);
2498 win
->GetEventHandler()->ProcessEvent(event2
);
2501 node
= node
->GetNext();
2507 // the default action is to populate dialog with data when it's created,
2508 // and nudge the UI into displaying itself correctly in case
2509 // we've turned the wxUpdateUIEvents frequency down low.
2510 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2512 TransferDataToWindow();
2514 // Update the UI at this point
2515 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2518 // ----------------------------------------------------------------------------
2519 // menu-related functions
2520 // ----------------------------------------------------------------------------
2524 bool wxWindowBase::PopupMenu(wxMenu
*menu
, int x
, int y
)
2526 wxCHECK_MSG( menu
, false, "can't popup NULL menu" );
2528 wxCurrentPopupMenu
= menu
;
2529 const bool rc
= DoPopupMenu(menu
, x
, y
);
2530 wxCurrentPopupMenu
= NULL
;
2535 // this is used to pass the id of the selected item from the menu event handler
2536 // to the main function itself
2538 // it's ok to use a global here as there can be at most one popup menu shown at
2540 static int gs_popupMenuSelection
= wxID_NONE
;
2542 void wxWindowBase::InternalOnPopupMenu(wxCommandEvent
& event
)
2544 // store the id in a global variable where we'll retrieve it from later
2545 gs_popupMenuSelection
= event
.GetId();
2548 void wxWindowBase::InternalOnPopupMenuUpdate(wxUpdateUIEvent
& WXUNUSED(event
))
2550 // nothing to do but do not skip it
2554 wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu
& menu
, int x
, int y
)
2556 gs_popupMenuSelection
= wxID_NONE
;
2558 Connect(wxEVT_COMMAND_MENU_SELECTED
,
2559 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2563 // it is common to construct the menu passed to this function dynamically
2564 // using some fixed range of ids which could clash with the ids used
2565 // elsewhere in the program, which could result in some menu items being
2566 // unintentionally disabled or otherwise modified by update UI handlers
2567 // elsewhere in the program code and this is difficult to avoid in the
2568 // program itself, so instead we just temporarily suspend UI updating while
2569 // this menu is shown
2570 Connect(wxEVT_UPDATE_UI
,
2571 wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate
),
2575 PopupMenu(&menu
, x
, y
);
2577 Disconnect(wxEVT_UPDATE_UI
,
2578 wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate
),
2581 Disconnect(wxEVT_COMMAND_MENU_SELECTED
,
2582 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2586 return gs_popupMenuSelection
;
2589 #endif // wxUSE_MENUS
2591 // methods for drawing the sizers in a visible way: this is currently only
2592 // enabled for "full debug" builds with wxDEBUG_LEVEL==2 as it doesn't work
2593 // that well and also because we don't want to leave it enabled in default
2594 // builds used for production
2595 #if wxDEBUG_LEVEL > 1
2597 static void DrawSizers(wxWindowBase
*win
);
2599 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
, const wxPen
* pen
)
2601 wxClientDC
dc((wxWindow
*)win
);
2603 dc
.SetBrush(fill
? wxBrush(pen
->GetColour(), wxBRUSHSTYLE_CROSSDIAG_HATCH
) :
2604 *wxTRANSPARENT_BRUSH
);
2605 dc
.DrawRectangle(rect
.Deflate(1, 1));
2608 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2610 const wxSizerItemList
& items
= sizer
->GetChildren();
2611 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2616 wxSizerItem
*item
= *i
;
2617 if ( item
->IsSizer() )
2619 DrawBorder(win
, item
->GetRect().Deflate(2), false, wxRED_PEN
);
2620 DrawSizer(win
, item
->GetSizer());
2622 else if ( item
->IsSpacer() )
2624 DrawBorder(win
, item
->GetRect().Deflate(2), true, wxBLUE_PEN
);
2626 else if ( item
->IsWindow() )
2628 DrawSizers(item
->GetWindow());
2631 wxFAIL_MSG("inconsistent wxSizerItem status!");
2635 static void DrawSizers(wxWindowBase
*win
)
2637 DrawBorder(win
, win
->GetClientSize(), false, wxGREEN_PEN
);
2639 wxSizer
*sizer
= win
->GetSizer();
2642 DrawSizer(win
, sizer
);
2644 else // no sizer, still recurse into the children
2646 const wxWindowList
& children
= win
->GetChildren();
2647 for ( wxWindowList::const_iterator i
= children
.begin(),
2648 end
= children
.end();
2655 // show all kind of sizes of this window; see the "window sizing" topic
2656 // overview for more info about the various differences:
2657 wxSize fullSz
= win
->GetSize();
2658 wxSize clientSz
= win
->GetClientSize();
2659 wxSize bestSz
= win
->GetBestSize();
2660 wxSize minSz
= win
->GetMinSize();
2661 wxSize maxSz
= win
->GetMaxSize();
2662 wxSize virtualSz
= win
->GetVirtualSize();
2664 wxMessageOutputDebug dbgout
;
2666 "%-10s => fullsz=%4d;%-4d clientsz=%4d;%-4d bestsz=%4d;%-4d minsz=%4d;%-4d maxsz=%4d;%-4d virtualsz=%4d;%-4d\n",
2669 clientSz
.x
, clientSz
.y
,
2673 virtualSz
.x
, virtualSz
.y
);
2677 #endif // wxDEBUG_LEVEL
2679 // process special middle clicks
2680 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2682 if ( event
.ControlDown() && event
.AltDown() )
2684 #if wxDEBUG_LEVEL > 1
2685 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2686 if ( event
.ShiftDown() )
2691 #endif // __WXDEBUG__
2693 // just Ctrl-Alt-middle click shows information about wx version
2694 ::wxInfoMessageBox((wxWindow
*)this);
2703 // ----------------------------------------------------------------------------
2705 // ----------------------------------------------------------------------------
2707 #if wxUSE_ACCESSIBILITY
2708 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2710 if (m_accessible
&& (accessible
!= m_accessible
))
2711 delete m_accessible
;
2712 m_accessible
= accessible
;
2714 m_accessible
->SetWindow((wxWindow
*) this);
2717 // Returns the accessible object, creating if necessary.
2718 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2721 m_accessible
= CreateAccessible();
2722 return m_accessible
;
2725 // Override to create a specific accessible object.
2726 wxAccessible
* wxWindowBase::CreateAccessible()
2728 return new wxWindowAccessible((wxWindow
*) this);
2733 // ----------------------------------------------------------------------------
2734 // list classes implementation
2735 // ----------------------------------------------------------------------------
2739 #include "wx/listimpl.cpp"
2740 WX_DEFINE_LIST(wxWindowList
)
2744 void wxWindowListNode::DeleteData()
2746 delete (wxWindow
*)GetData();
2749 #endif // wxUSE_STL/!wxUSE_STL
2751 // ----------------------------------------------------------------------------
2753 // ----------------------------------------------------------------------------
2755 wxBorder
wxWindowBase::GetBorder(long flags
) const
2757 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2758 if ( border
== wxBORDER_DEFAULT
)
2760 border
= GetDefaultBorder();
2762 else if ( border
== wxBORDER_THEME
)
2764 border
= GetDefaultBorderForControl();
2770 wxBorder
wxWindowBase::GetDefaultBorder() const
2772 return wxBORDER_NONE
;
2775 // ----------------------------------------------------------------------------
2777 // ----------------------------------------------------------------------------
2779 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2781 // here we just check if the point is inside the window or not
2783 // check the top and left border first
2784 bool outside
= x
< 0 || y
< 0;
2787 // check the right and bottom borders too
2788 wxSize size
= GetSize();
2789 outside
= x
>= size
.x
|| y
>= size
.y
;
2792 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2795 // ----------------------------------------------------------------------------
2797 // ----------------------------------------------------------------------------
2799 struct WXDLLEXPORT wxWindowNext
2803 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2804 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2805 bool wxWindowBase::ms_winCaptureChanging
= false;
2807 void wxWindowBase::CaptureMouse()
2809 wxLogTrace(wxT("mousecapture"), wxT("CaptureMouse(%p)"), static_cast<void*>(this));
2811 wxASSERT_MSG( !ms_winCaptureChanging
, wxT("recursive CaptureMouse call?") );
2813 ms_winCaptureChanging
= true;
2815 wxWindow
*winOld
= GetCapture();
2818 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2821 wxWindowNext
*item
= new wxWindowNext
;
2823 item
->next
= ms_winCaptureNext
;
2824 ms_winCaptureNext
= item
;
2826 //else: no mouse capture to save
2829 ms_winCaptureCurrent
= (wxWindow
*)this;
2831 ms_winCaptureChanging
= false;
2834 void wxWindowBase::ReleaseMouse()
2836 wxLogTrace(wxT("mousecapture"), wxT("ReleaseMouse(%p)"), static_cast<void*>(this));
2838 wxASSERT_MSG( !ms_winCaptureChanging
, wxT("recursive ReleaseMouse call?") );
2840 wxASSERT_MSG( GetCapture() == this,
2841 "attempt to release mouse, but this window hasn't captured it" );
2842 wxASSERT_MSG( ms_winCaptureCurrent
== this,
2843 "attempt to release mouse, but this window hasn't captured it" );
2845 ms_winCaptureChanging
= true;
2848 ms_winCaptureCurrent
= NULL
;
2850 if ( ms_winCaptureNext
)
2852 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2853 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2855 wxWindowNext
*item
= ms_winCaptureNext
;
2856 ms_winCaptureNext
= item
->next
;
2859 //else: stack is empty, no previous capture
2861 ms_winCaptureChanging
= false;
2863 wxLogTrace(wxT("mousecapture"),
2864 (const wxChar
*) wxT("After ReleaseMouse() mouse is captured by %p"),
2865 static_cast<void*>(GetCapture()));
2868 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2870 wxMouseCaptureLostEvent
event(win
->GetId());
2871 event
.SetEventObject(win
);
2872 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2874 // windows must handle this event, otherwise the app wouldn't behave
2875 // correctly if it loses capture unexpectedly; see the discussion here:
2876 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
2877 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
2878 wxFAIL_MSG( wxT("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2883 void wxWindowBase::NotifyCaptureLost()
2885 // don't do anything if capture lost was expected, i.e. resulted from
2886 // a wx call to ReleaseMouse or CaptureMouse:
2887 if ( ms_winCaptureChanging
)
2890 // if the capture was lost unexpectedly, notify every window that has
2891 // capture (on stack or current) about it and clear the stack:
2893 if ( ms_winCaptureCurrent
)
2895 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2896 ms_winCaptureCurrent
= NULL
;
2899 while ( ms_winCaptureNext
)
2901 wxWindowNext
*item
= ms_winCaptureNext
;
2902 ms_winCaptureNext
= item
->next
;
2904 DoNotifyWindowAboutCaptureLost(item
->win
);
2913 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2914 int WXUNUSED(modifiers
),
2915 int WXUNUSED(keycode
))
2921 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2927 #endif // wxUSE_HOTKEY
2929 // ----------------------------------------------------------------------------
2931 // ----------------------------------------------------------------------------
2933 bool wxWindowBase::TryBefore(wxEvent
& event
)
2935 #if wxUSE_VALIDATORS
2936 // Can only use the validator of the window which
2937 // is receiving the event
2938 if ( event
.GetEventObject() == this )
2940 wxValidator
* const validator
= GetValidator();
2941 if ( validator
&& validator
->ProcessEventHere(event
) )
2946 #endif // wxUSE_VALIDATORS
2948 return wxEvtHandler::TryBefore(event
);
2951 bool wxWindowBase::TryAfter(wxEvent
& event
)
2953 // carry on up the parent-child hierarchy if the propagation count hasn't
2955 if ( event
.ShouldPropagate() )
2957 // honour the requests to stop propagation at this window: this is
2958 // used by the dialogs, for example, to prevent processing the events
2959 // from the dialog controls in the parent frame which rarely, if ever,
2961 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2963 wxWindow
*parent
= GetParent();
2964 if ( parent
&& !parent
->IsBeingDeleted() )
2966 wxPropagateOnce
propagateOnce(event
);
2968 return parent
->GetEventHandler()->ProcessEvent(event
);
2973 return wxEvtHandler::TryAfter(event
);
2976 // ----------------------------------------------------------------------------
2977 // window relationships
2978 // ----------------------------------------------------------------------------
2980 wxWindow
*wxWindowBase::DoGetSibling(WindowOrder order
) const
2982 wxCHECK_MSG( GetParent(), NULL
,
2983 wxT("GetPrev/NextSibling() don't work for TLWs!") );
2985 wxWindowList
& siblings
= GetParent()->GetChildren();
2986 wxWindowList::compatibility_iterator i
= siblings
.Find((wxWindow
*)this);
2987 wxCHECK_MSG( i
, NULL
, wxT("window not a child of its parent?") );
2989 if ( order
== OrderBefore
)
2990 i
= i
->GetPrevious();
2994 return i
? i
->GetData() : NULL
;
2997 // ----------------------------------------------------------------------------
2998 // keyboard navigation
2999 // ----------------------------------------------------------------------------
3001 // Navigates in the specified direction inside this window
3002 bool wxWindowBase::DoNavigateIn(int flags
)
3004 #ifdef wxHAS_NATIVE_TAB_TRAVERSAL
3005 // native code doesn't process our wxNavigationKeyEvents anyhow
3008 #else // !wxHAS_NATIVE_TAB_TRAVERSAL
3009 wxNavigationKeyEvent eventNav
;
3010 wxWindow
*focused
= FindFocus();
3011 eventNav
.SetCurrentFocus(focused
);
3012 eventNav
.SetEventObject(focused
);
3013 eventNav
.SetFlags(flags
);
3014 return GetEventHandler()->ProcessEvent(eventNav
);
3015 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
3018 bool wxWindowBase::HandleAsNavigationKey(const wxKeyEvent
& event
)
3020 if ( event
.GetKeyCode() != WXK_TAB
)
3023 int flags
= wxNavigationKeyEvent::FromTab
;
3025 if ( event
.ShiftDown() )
3026 flags
|= wxNavigationKeyEvent::IsBackward
;
3028 flags
|= wxNavigationKeyEvent::IsForward
;
3030 if ( event
.ControlDown() )
3031 flags
|= wxNavigationKeyEvent::WinChange
;
3037 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, WindowOrder move
)
3039 // check that we're not a top level window
3040 wxCHECK_RET( GetParent(),
3041 wxT("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
3043 // detect the special case when we have nothing to do anyhow and when the
3044 // code below wouldn't work
3048 // find the target window in the siblings list
3049 wxWindowList
& siblings
= GetParent()->GetChildren();
3050 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
3051 wxCHECK_RET( i
, wxT("MoveBefore/AfterInTabOrder(): win is not a sibling") );
3053 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
3054 // can't just move the node around
3055 wxWindow
*self
= (wxWindow
*)this;
3056 siblings
.DeleteObject(self
);
3057 if ( move
== OrderAfter
)
3064 siblings
.Insert(i
, self
);
3066 else // OrderAfter and win was the last sibling
3068 siblings
.Append(self
);
3072 // ----------------------------------------------------------------------------
3074 // ----------------------------------------------------------------------------
3076 /*static*/ wxWindow
* wxWindowBase::FindFocus()
3078 wxWindowBase
*win
= DoFindFocus();
3079 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
3082 bool wxWindowBase::HasFocus() const
3084 wxWindowBase
*win
= DoFindFocus();
3085 return win
== this ||
3086 win
== wxConstCast(this, wxWindowBase
)->GetMainWindowOfCompositeControl();
3089 // ----------------------------------------------------------------------------
3091 // ----------------------------------------------------------------------------
3093 #if wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
3098 class DragAcceptFilesTarget
: public wxFileDropTarget
3101 DragAcceptFilesTarget(wxWindowBase
*win
) : m_win(win
) {}
3103 virtual bool OnDropFiles(wxCoord x
, wxCoord y
,
3104 const wxArrayString
& filenames
)
3106 wxDropFilesEvent
event(wxEVT_DROP_FILES
,
3108 wxCArrayString(filenames
).Release());
3109 event
.SetEventObject(m_win
);
3113 return m_win
->HandleWindowEvent(event
);
3117 wxWindowBase
* const m_win
;
3119 wxDECLARE_NO_COPY_CLASS(DragAcceptFilesTarget
);
3123 } // anonymous namespace
3125 // Generic version of DragAcceptFiles(). It works by installing a simple
3126 // wxFileDropTarget-to-EVT_DROP_FILES adaptor and therefore cannot be used
3127 // together with explicit SetDropTarget() calls.
3128 void wxWindowBase::DragAcceptFiles(bool accept
)
3132 wxASSERT_MSG( !GetDropTarget(),
3133 "cannot use DragAcceptFiles() and SetDropTarget() together" );
3134 SetDropTarget(new DragAcceptFilesTarget(this));
3138 SetDropTarget(NULL
);
3142 #endif // wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
3144 // ----------------------------------------------------------------------------
3146 // ----------------------------------------------------------------------------
3148 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
3150 while ( win
&& !win
->IsTopLevel() )
3151 win
= win
->GetParent();
3156 #if wxUSE_ACCESSIBILITY
3157 // ----------------------------------------------------------------------------
3158 // accessible object for windows
3159 // ----------------------------------------------------------------------------
3161 // Can return either a child object, or an integer
3162 // representing the child element, starting from 1.
3163 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
3165 wxASSERT( GetWindow() != NULL
);
3169 return wxACC_NOT_IMPLEMENTED
;
3172 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
3173 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
3175 wxASSERT( GetWindow() != NULL
);
3179 wxWindow
* win
= NULL
;
3186 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
3188 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
3195 rect
= win
->GetRect();
3196 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
3197 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
3201 return wxACC_NOT_IMPLEMENTED
;
3204 // Navigates from fromId to toId/toObject.
3205 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
3206 int* WXUNUSED(toId
), wxAccessible
** toObject
)
3208 wxASSERT( GetWindow() != NULL
);
3214 case wxNAVDIR_FIRSTCHILD
:
3216 if (GetWindow()->GetChildren().GetCount() == 0)
3218 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
3219 *toObject
= childWindow
->GetOrCreateAccessible();
3223 case wxNAVDIR_LASTCHILD
:
3225 if (GetWindow()->GetChildren().GetCount() == 0)
3227 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
3228 *toObject
= childWindow
->GetOrCreateAccessible();
3232 case wxNAVDIR_RIGHT
:
3236 wxWindowList::compatibility_iterator node
=
3237 wxWindowList::compatibility_iterator();
3240 // Can't navigate to sibling of this window
3241 // if we're a top-level window.
3242 if (!GetWindow()->GetParent())
3243 return wxACC_NOT_IMPLEMENTED
;
3245 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3249 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
3250 node
= GetWindow()->GetChildren().Item(fromId
-1);
3253 if (node
&& node
->GetNext())
3255 wxWindow
* nextWindow
= node
->GetNext()->GetData();
3256 *toObject
= nextWindow
->GetOrCreateAccessible();
3264 case wxNAVDIR_PREVIOUS
:
3266 wxWindowList::compatibility_iterator node
=
3267 wxWindowList::compatibility_iterator();
3270 // Can't navigate to sibling of this window
3271 // if we're a top-level window.
3272 if (!GetWindow()->GetParent())
3273 return wxACC_NOT_IMPLEMENTED
;
3275 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3279 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
3280 node
= GetWindow()->GetChildren().Item(fromId
-1);
3283 if (node
&& node
->GetPrevious())
3285 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
3286 *toObject
= previousWindow
->GetOrCreateAccessible();
3294 return wxACC_NOT_IMPLEMENTED
;
3297 // Gets the name of the specified object.
3298 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
3300 wxASSERT( GetWindow() != NULL
);
3306 // If a child, leave wxWidgets to call the function on the actual
3309 return wxACC_NOT_IMPLEMENTED
;
3311 // This will eventually be replaced by specialised
3312 // accessible classes, one for each kind of wxWidgets
3313 // control or window.
3315 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
3316 title
= ((wxButton
*) GetWindow())->GetLabel();
3319 title
= GetWindow()->GetName();
3327 return wxACC_NOT_IMPLEMENTED
;
3330 // Gets the number of children.
3331 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
3333 wxASSERT( GetWindow() != NULL
);
3337 *childId
= (int) GetWindow()->GetChildren().GetCount();
3341 // Gets the specified child (starting from 1).
3342 // If *child is NULL and return value is wxACC_OK,
3343 // this means that the child is a simple element and
3344 // not an accessible object.
3345 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
3347 wxASSERT( GetWindow() != NULL
);
3357 if (childId
> (int) GetWindow()->GetChildren().GetCount())
3360 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
3361 *child
= childWindow
->GetOrCreateAccessible();
3368 // Gets the parent, or NULL.
3369 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
3371 wxASSERT( GetWindow() != NULL
);
3375 wxWindow
* parentWindow
= GetWindow()->GetParent();
3383 *parent
= parentWindow
->GetOrCreateAccessible();
3391 // Performs the default action. childId is 0 (the action for this object)
3392 // or > 0 (the action for a child).
3393 // Return wxACC_NOT_SUPPORTED if there is no default action for this
3394 // window (e.g. an edit control).
3395 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
3397 wxASSERT( GetWindow() != NULL
);
3401 return wxACC_NOT_IMPLEMENTED
;
3404 // Gets the default action for this object (0) or > 0 (the action for a child).
3405 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
3406 // string if there is no action.
3407 // The retrieved string describes the action that is performed on an object,
3408 // not what the object does as a result. For example, a toolbar button that prints
3409 // a document has a default action of "Press" rather than "Prints the current document."
3410 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
3412 wxASSERT( GetWindow() != NULL
);
3416 return wxACC_NOT_IMPLEMENTED
;
3419 // Returns the description for this object or a child.
3420 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
3422 wxASSERT( GetWindow() != NULL
);
3426 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3432 return wxACC_NOT_IMPLEMENTED
;
3435 // Returns help text for this object or a child, similar to tooltip text.
3436 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
3438 wxASSERT( GetWindow() != NULL
);
3442 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3448 return wxACC_NOT_IMPLEMENTED
;
3451 // Returns the keyboard shortcut for this object or child.
3452 // Return e.g. ALT+K
3453 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
3455 wxASSERT( GetWindow() != NULL
);
3459 return wxACC_NOT_IMPLEMENTED
;
3462 // Returns a role constant.
3463 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
3465 wxASSERT( GetWindow() != NULL
);
3469 // If a child, leave wxWidgets to call the function on the actual
3472 return wxACC_NOT_IMPLEMENTED
;
3474 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3475 return wxACC_NOT_IMPLEMENTED
;
3477 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3478 return wxACC_NOT_IMPLEMENTED
;
3481 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3482 return wxACC_NOT_IMPLEMENTED
;
3485 //*role = wxROLE_SYSTEM_CLIENT;
3486 *role
= wxROLE_SYSTEM_CLIENT
;
3490 return wxACC_NOT_IMPLEMENTED
;
3494 // Returns a state constant.
3495 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
3497 wxASSERT( GetWindow() != NULL
);
3501 // If a child, leave wxWidgets to call the function on the actual
3504 return wxACC_NOT_IMPLEMENTED
;
3506 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3507 return wxACC_NOT_IMPLEMENTED
;
3510 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3511 return wxACC_NOT_IMPLEMENTED
;
3514 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3515 return wxACC_NOT_IMPLEMENTED
;
3522 return wxACC_NOT_IMPLEMENTED
;
3526 // Returns a localized string representing the value for the object
3528 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3530 wxASSERT( GetWindow() != NULL
);
3534 return wxACC_NOT_IMPLEMENTED
;
3537 // Selects the object or child.
3538 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3540 wxASSERT( GetWindow() != NULL
);
3544 return wxACC_NOT_IMPLEMENTED
;
3547 // Gets the window with the keyboard focus.
3548 // If childId is 0 and child is NULL, no object in
3549 // this subhierarchy has the focus.
3550 // If this object has the focus, child should be 'this'.
3551 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3553 wxASSERT( GetWindow() != NULL
);
3557 return wxACC_NOT_IMPLEMENTED
;
3561 // Gets a variant representing the selected children
3563 // Acceptable values:
3564 // - a null variant (IsNull() returns true)
3565 // - a list variant (GetType() == wxT("list")
3566 // - an integer representing the selected child element,
3567 // or 0 if this object is selected (GetType() == wxT("long")
3568 // - a "void*" pointer to a wxAccessible child object
3569 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3571 wxASSERT( GetWindow() != NULL
);
3575 return wxACC_NOT_IMPLEMENTED
;
3577 #endif // wxUSE_VARIANT
3579 #endif // wxUSE_ACCESSIBILITY
3581 // ----------------------------------------------------------------------------
3583 // ----------------------------------------------------------------------------
3586 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3588 wxCoord widthTotal
) const
3590 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3592 x
= widthTotal
- x
- width
;