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)
247 // note that we can't use IsTopLevel() from ctor
248 if ( size
!= wxDefaultSize
&& !wxTopLevelWindows
.Find((wxWindow
*)this) )
257 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
262 const wxValidator
& wxVALIDATOR_PARAM(validator
),
263 const wxString
& name
)
265 if ( !CreateBase(parent
, id
, pos
, size
, style
, name
) )
269 SetValidator(validator
);
270 #endif // wxUSE_VALIDATORS
272 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
273 // have it too - like this it's possible to set it only in the top level
274 // dialog/frame and all children will inherit it by defult
275 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
277 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
283 bool wxWindowBase::ToggleWindowStyle(int flag
)
285 wxASSERT_MSG( flag
, wxT("flags with 0 value can't be toggled") );
288 long style
= GetWindowStyleFlag();
294 else // currently off
300 SetWindowStyleFlag(style
);
305 // ----------------------------------------------------------------------------
307 // ----------------------------------------------------------------------------
310 wxWindowBase::~wxWindowBase()
312 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
314 // FIXME if these 2 cases result from programming errors in the user code
315 // we should probably assert here instead of silently fixing them
317 // Just in case the window has been Closed, but we're then deleting
318 // immediately: don't leave dangling pointers.
319 wxPendingDelete
.DeleteObject(this);
321 // Just in case we've loaded a top-level window via LoadNativeDialog but
322 // we weren't a dialog class
323 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
325 // Any additional event handlers should be popped before the window is
326 // deleted as otherwise the last handler will be left with a dangling
327 // pointer to this window result in a difficult to diagnose crash later on.
328 wxASSERT_MSG( GetEventHandler() == this,
329 wxT("any pushed event handlers must have been removed") );
332 // The associated popup menu can still be alive, disassociate from it in
334 if ( wxCurrentPopupMenu
&& wxCurrentPopupMenu
->GetInvokingWindow() == this )
335 wxCurrentPopupMenu
->SetInvokingWindow(NULL
);
336 #endif // wxUSE_MENUS
338 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
340 // notify the parent about this window destruction
342 m_parent
->RemoveChild(this);
346 #endif // wxUSE_CARET
349 delete m_windowValidator
;
350 #endif // wxUSE_VALIDATORS
352 #if wxUSE_CONSTRAINTS
353 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
354 // at deleted windows as they delete themselves.
355 DeleteRelatedConstraints();
359 // This removes any dangling pointers to this window in other windows'
360 // constraintsInvolvedIn lists.
361 UnsetConstraints(m_constraints
);
362 delete m_constraints
;
363 m_constraints
= NULL
;
365 #endif // wxUSE_CONSTRAINTS
367 if ( m_containingSizer
)
368 m_containingSizer
->Detach( (wxWindow
*)this );
370 delete m_windowSizer
;
372 #if wxUSE_DRAG_AND_DROP
374 #endif // wxUSE_DRAG_AND_DROP
378 #endif // wxUSE_TOOLTIPS
380 #if wxUSE_ACCESSIBILITY
385 // NB: this has to be called unconditionally, because we don't know
386 // whether this window has associated help text or not
387 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
389 helpProvider
->RemoveHelp(this);
393 bool wxWindowBase::IsBeingDeleted() const
395 return m_isBeingDeleted
||
396 (!IsTopLevel() && m_parent
&& m_parent
->IsBeingDeleted());
399 void wxWindowBase::SendDestroyEvent()
401 if ( m_isBeingDeleted
)
403 // we could have been already called from a more derived class dtor,
404 // e.g. ~wxTLW calls us and so does ~wxWindow and the latter call
405 // should be simply ignored
409 m_isBeingDeleted
= true;
411 wxWindowDestroyEvent event
;
412 event
.SetEventObject(this);
413 event
.SetId(GetId());
414 GetEventHandler()->ProcessEvent(event
);
417 bool wxWindowBase::Destroy()
426 bool wxWindowBase::Close(bool force
)
428 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
429 event
.SetEventObject(this);
430 event
.SetCanVeto(!force
);
432 // return false if window wasn't closed because the application vetoed the
434 return HandleWindowEvent(event
) && !event
.GetVeto();
437 bool wxWindowBase::DestroyChildren()
439 wxWindowList::compatibility_iterator node
;
442 // we iterate until the list becomes empty
443 node
= GetChildren().GetFirst();
447 wxWindow
*child
= node
->GetData();
449 // note that we really want to delete it immediately so don't call the
450 // possible overridden Destroy() version which might not delete the
451 // child immediately resulting in problems with our (top level) child
452 // outliving its parent
453 child
->wxWindowBase::Destroy();
455 wxASSERT_MSG( !GetChildren().Find(child
),
456 wxT("child didn't remove itself using RemoveChild()") );
462 // ----------------------------------------------------------------------------
463 // size/position related methods
464 // ----------------------------------------------------------------------------
466 // centre the window with respect to its parent in either (or both) directions
467 void wxWindowBase::DoCentre(int dir
)
469 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
470 wxT("this method only implements centering child windows") );
472 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
475 // fits the window around the children
476 void wxWindowBase::Fit()
478 if ( !GetChildren().empty() )
480 SetSize(GetBestSize());
482 //else: do nothing if we have no children
485 // fits virtual size (ie. scrolled area etc.) around children
486 void wxWindowBase::FitInside()
488 if ( GetChildren().GetCount() > 0 )
490 SetVirtualSize( GetBestVirtualSize() );
494 // On Mac, scrollbars are explicitly children.
495 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
496 static bool wxHasRealChildren(const wxWindowBase
* win
)
498 int realChildCount
= 0;
500 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
502 node
= node
->GetNext() )
504 wxWindow
*win
= node
->GetData();
505 if ( !win
->IsTopLevel() && win
->IsShown()
507 && !win
->IsKindOf(CLASSINFO(wxScrollBar
))
512 return (realChildCount
> 0);
516 void wxWindowBase::InvalidateBestSize()
518 m_bestSizeCache
= wxDefaultSize
;
520 // parent's best size calculation may depend on its children's
521 // as long as child window we are in is not top level window itself
522 // (because the TLW size is never resized automatically)
523 // so let's invalidate it as well to be safe:
524 if (m_parent
&& !IsTopLevel())
525 m_parent
->InvalidateBestSize();
528 // return the size best suited for the current window
529 wxSize
wxWindowBase::DoGetBestSize() const
535 best
= m_windowSizer
->GetMinSize();
537 #if wxUSE_CONSTRAINTS
538 else if ( m_constraints
)
540 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
542 // our minimal acceptable size is such that all our windows fit inside
546 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
548 node
= node
->GetNext() )
550 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
553 // it's not normal that we have an unconstrained child, but
554 // what can we do about it?
558 int x
= c
->right
.GetValue(),
559 y
= c
->bottom
.GetValue();
567 // TODO: we must calculate the overlaps somehow, otherwise we
568 // will never return a size bigger than the current one :-(
571 best
= wxSize(maxX
, maxY
);
573 #endif // wxUSE_CONSTRAINTS
574 else if ( !GetChildren().empty()
575 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
576 && wxHasRealChildren(this)
580 // our minimal acceptable size is such that all our visible child
581 // windows fit inside
585 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
587 node
= node
->GetNext() )
589 wxWindow
*win
= node
->GetData();
590 if ( win
->IsTopLevel()
593 || wxDynamicCast(win
, wxStatusBar
)
594 #endif // wxUSE_STATUSBAR
597 // dialogs and frames lie in different top level windows -
598 // don't deal with them here; as for the status bars, they
599 // don't lie in the client area at all
604 win
->GetPosition(&wx
, &wy
);
606 // if the window hadn't been positioned yet, assume that it is in
608 if ( wx
== wxDefaultCoord
)
610 if ( wy
== wxDefaultCoord
)
613 win
->GetSize(&ww
, &wh
);
614 if ( wx
+ ww
> maxX
)
616 if ( wy
+ wh
> maxY
)
620 best
= wxSize(maxX
, maxY
);
622 else // ! has children
624 wxSize size
= GetMinSize();
625 if ( !size
.IsFullySpecified() )
627 // if the window doesn't define its best size we assume that it can
628 // be arbitrarily small -- usually this is not the case, of course,
629 // but we have no way to know what the limit is, it should really
630 // override DoGetBestClientSize() itself to tell us
631 size
.SetDefaults(wxSize(1, 1));
634 // return as-is, unadjusted by the client size difference.
638 // Add any difference between size and client size
639 wxSize diff
= GetSize() - GetClientSize();
640 best
.x
+= wxMax(0, diff
.x
);
641 best
.y
+= wxMax(0, diff
.y
);
646 // helper of GetWindowBorderSize(): as many ports don't implement support for
647 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
648 // fallbacks in this case
649 static int wxGetMetricOrDefault(wxSystemMetric what
, const wxWindowBase
* win
)
651 int rc
= wxSystemSettings::GetMetric(
652 what
, static_cast<wxWindow
*>(const_cast<wxWindowBase
*>(win
)));
659 // 2D border is by default 1 pixel wide
665 // 3D borders are by default 2 pixels
670 wxFAIL_MSG( wxT("unexpected wxGetMetricOrDefault() argument") );
678 wxSize
wxWindowBase::GetWindowBorderSize() const
682 switch ( GetBorder() )
685 // nothing to do, size is already (0, 0)
688 case wxBORDER_SIMPLE
:
689 case wxBORDER_STATIC
:
690 size
.x
= wxGetMetricOrDefault(wxSYS_BORDER_X
, this);
691 size
.y
= wxGetMetricOrDefault(wxSYS_BORDER_Y
, this);
694 case wxBORDER_SUNKEN
:
695 case wxBORDER_RAISED
:
696 size
.x
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X
, this),
697 wxGetMetricOrDefault(wxSYS_BORDER_X
, this));
698 size
.y
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y
, this),
699 wxGetMetricOrDefault(wxSYS_BORDER_Y
, this));
702 case wxBORDER_DOUBLE
:
703 size
.x
= wxGetMetricOrDefault(wxSYS_EDGE_X
, this) +
704 wxGetMetricOrDefault(wxSYS_BORDER_X
, this);
705 size
.y
= wxGetMetricOrDefault(wxSYS_EDGE_Y
, this) +
706 wxGetMetricOrDefault(wxSYS_BORDER_Y
, this);
710 wxFAIL_MSG(wxT("Unknown border style."));
714 // we have borders on both sides
718 wxSize
wxWindowBase::GetEffectiveMinSize() const
720 // merge the best size with the min size, giving priority to the min size
721 wxSize min
= GetMinSize();
723 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
725 wxSize best
= GetBestSize();
726 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
727 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
733 wxSize
wxWindowBase::DoGetBorderSize() const
735 // there is one case in which we can implement it for all ports easily:
736 // do it as some classes used by both wxUniv and native ports (e.g.
737 // wxGenericStaticText) do override DoGetBestClientSize() and so this
738 // method must work for them and that ensures that it does, at least in
740 if ( GetBorder() == wxBORDER_NONE
)
743 wxFAIL_MSG( "must be overridden if called" );
745 return wxDefaultSize
;
748 wxSize
wxWindowBase::GetBestSize() const
750 if ( !m_windowSizer
&& m_bestSizeCache
.IsFullySpecified() )
751 return m_bestSizeCache
;
753 // call DoGetBestClientSize() first, if a derived class overrides it wants
755 wxSize size
= DoGetBestClientSize();
756 if ( size
!= wxDefaultSize
)
758 size
+= DoGetBorderSize();
764 return DoGetBestSize();
767 void wxWindowBase::SetMinSize(const wxSize
& minSize
)
769 m_minWidth
= minSize
.x
;
770 m_minHeight
= minSize
.y
;
773 void wxWindowBase::SetMaxSize(const wxSize
& maxSize
)
775 m_maxWidth
= maxSize
.x
;
776 m_maxHeight
= maxSize
.y
;
779 void wxWindowBase::SetInitialSize(const wxSize
& size
)
781 // Set the min size to the size passed in. This will usually either be
782 // wxDefaultSize or the size passed to this window's ctor/Create function.
785 // Merge the size with the best size if needed
786 wxSize best
= GetEffectiveMinSize();
788 // If the current size doesn't match then change it
789 if (GetSize() != best
)
794 // by default the origin is not shifted
795 wxPoint
wxWindowBase::GetClientAreaOrigin() const
800 wxSize
wxWindowBase::ClientToWindowSize(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 wxSize
wxWindowBase::WindowToClientSize(const wxSize
& size
) const
810 const wxSize
diff(GetSize() - GetClientSize());
812 return wxSize(size
.x
== -1 ? -1 : size
.x
- diff
.x
,
813 size
.y
== -1 ? -1 : size
.y
- diff
.y
);
816 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
818 if ( m_windowVariant
!= variant
)
820 m_windowVariant
= variant
;
822 DoSetWindowVariant(variant
);
826 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
828 // adjust the font height to correspond to our new variant (notice that
829 // we're only called if something really changed)
830 wxFont font
= GetFont();
831 int size
= font
.GetPointSize();
834 case wxWINDOW_VARIANT_NORMAL
:
837 case wxWINDOW_VARIANT_SMALL
:
842 case wxWINDOW_VARIANT_MINI
:
847 case wxWINDOW_VARIANT_LARGE
:
853 wxFAIL_MSG(wxT("unexpected window variant"));
857 font
.SetPointSize(size
);
861 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
863 int WXUNUSED(incW
), int WXUNUSED(incH
) )
865 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
866 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
867 wxT("min width/height must be less than max width/height!") );
876 #if WXWIN_COMPATIBILITY_2_8
877 void wxWindowBase::SetVirtualSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
),
878 int WXUNUSED(maxW
), int WXUNUSED(maxH
))
882 void wxWindowBase::SetVirtualSizeHints(const wxSize
& WXUNUSED(minsize
),
883 const wxSize
& WXUNUSED(maxsize
))
886 #endif // WXWIN_COMPATIBILITY_2_8
888 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
890 m_virtualSize
= wxSize(x
, y
);
893 wxSize
wxWindowBase::DoGetVirtualSize() const
895 // we should use the entire client area so if it is greater than our
896 // virtual size, expand it to fit (otherwise if the window is big enough we
897 // wouldn't be using parts of it)
898 wxSize size
= GetClientSize();
899 if ( m_virtualSize
.x
> size
.x
)
900 size
.x
= m_virtualSize
.x
;
902 if ( m_virtualSize
.y
>= size
.y
)
903 size
.y
= m_virtualSize
.y
;
908 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
910 // screen position is the same as (0, 0) in client coords for non TLWs (and
911 // TLWs override this method)
917 ClientToScreen(x
, y
);
920 void wxWindowBase::SendSizeEvent(int flags
)
922 wxSizeEvent
event(GetSize(), GetId());
923 event
.SetEventObject(this);
924 if ( flags
& wxSEND_EVENT_POST
)
925 wxPostEvent(this, event
);
927 HandleWindowEvent(event
);
930 void wxWindowBase::SendSizeEventToParent(int flags
)
932 wxWindow
* const parent
= GetParent();
933 if ( parent
&& !parent
->IsBeingDeleted() )
934 parent
->SendSizeEvent(flags
);
937 bool wxWindowBase::HasScrollbar(int orient
) const
939 // if scrolling in the given direction is disabled, we can't have the
940 // corresponding scrollbar no matter what
941 if ( !CanScroll(orient
) )
944 const wxSize sizeVirt
= GetVirtualSize();
945 const wxSize sizeClient
= GetClientSize();
947 return orient
== wxHORIZONTAL
? sizeVirt
.x
> sizeClient
.x
948 : sizeVirt
.y
> sizeClient
.y
;
951 // ----------------------------------------------------------------------------
952 // show/hide/enable/disable the window
953 // ----------------------------------------------------------------------------
955 bool wxWindowBase::Show(bool show
)
957 if ( show
!= m_isShown
)
969 bool wxWindowBase::IsEnabled() const
971 return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
974 void wxWindowBase::NotifyWindowOnEnableChange(bool enabled
)
976 #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
978 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
982 // If we are top-level then the logic doesn't apply - otherwise
983 // showing a modal dialog would result in total greying out (and ungreying
984 // out later) of everything which would be really ugly
988 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
990 node
= node
->GetNext() )
992 wxWindowBase
* const child
= node
->GetData();
993 if ( !child
->IsTopLevel() && child
->IsThisEnabled() )
994 child
->NotifyWindowOnEnableChange(enabled
);
998 bool wxWindowBase::Enable(bool enable
)
1000 if ( enable
== IsThisEnabled() )
1003 m_isEnabled
= enable
;
1005 #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
1007 #else // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
1008 wxWindowBase
* const parent
= GetParent();
1009 if( !IsTopLevel() && parent
&& !parent
->IsEnabled() )
1013 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
1015 NotifyWindowOnEnableChange(enable
);
1020 bool wxWindowBase::IsShownOnScreen() const
1022 // A window is shown on screen if it itself is shown and so are all its
1023 // parents. But if a window is toplevel one, then its always visible on
1024 // screen if IsShown() returns true, even if it has a hidden parent.
1026 (IsTopLevel() || GetParent() == NULL
|| GetParent()->IsShownOnScreen());
1029 // ----------------------------------------------------------------------------
1031 // ----------------------------------------------------------------------------
1033 bool wxWindowBase::IsTopLevel() const
1038 // ----------------------------------------------------------------------------
1040 // ----------------------------------------------------------------------------
1042 void wxWindowBase::Freeze()
1044 if ( !m_freezeCount
++ )
1046 // physically freeze this window:
1049 // and recursively freeze all children:
1050 for ( wxWindowList::iterator i
= GetChildren().begin();
1051 i
!= GetChildren().end(); ++i
)
1053 wxWindow
*child
= *i
;
1054 if ( child
->IsTopLevel() )
1062 void wxWindowBase::Thaw()
1064 wxASSERT_MSG( m_freezeCount
, "Thaw() without matching Freeze()" );
1066 if ( !--m_freezeCount
)
1068 // recursively thaw all children:
1069 for ( wxWindowList::iterator i
= GetChildren().begin();
1070 i
!= GetChildren().end(); ++i
)
1072 wxWindow
*child
= *i
;
1073 if ( child
->IsTopLevel() )
1079 // physically thaw this window:
1084 // ----------------------------------------------------------------------------
1085 // reparenting the window
1086 // ----------------------------------------------------------------------------
1088 void wxWindowBase::AddChild(wxWindowBase
*child
)
1090 wxCHECK_RET( child
, wxT("can't add a NULL child") );
1092 // this should never happen and it will lead to a crash later if it does
1093 // because RemoveChild() will remove only one node from the children list
1094 // and the other(s) one(s) will be left with dangling pointers in them
1095 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), wxT("AddChild() called twice") );
1097 GetChildren().Append((wxWindow
*)child
);
1098 child
->SetParent(this);
1100 // adding a child while frozen will assert when thawed, so freeze it as if
1101 // it had been already present when we were frozen
1102 if ( IsFrozen() && !child
->IsTopLevel() )
1106 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
1108 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
1110 // removing a child while frozen may result in permanently frozen window
1111 // if used e.g. from Reparent(), so thaw it
1113 // NB: IsTopLevel() doesn't return true any more when a TLW child is being
1114 // removed from its ~wxWindowBase, so check for IsBeingDeleted() too
1115 if ( IsFrozen() && !child
->IsBeingDeleted() && !child
->IsTopLevel() )
1118 GetChildren().DeleteObject((wxWindow
*)child
);
1119 child
->SetParent(NULL
);
1122 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
1124 wxWindow
*oldParent
= GetParent();
1125 if ( newParent
== oldParent
)
1131 const bool oldEnabledState
= IsEnabled();
1133 // unlink this window from the existing parent.
1136 oldParent
->RemoveChild(this);
1140 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
1143 // add it to the new one
1146 newParent
->AddChild(this);
1150 wxTopLevelWindows
.Append((wxWindow
*)this);
1153 // We need to notify window (and its subwindows) if by changing the parent
1154 // we also change our enabled/disabled status.
1155 const bool newEnabledState
= IsEnabled();
1156 if ( newEnabledState
!= oldEnabledState
)
1158 NotifyWindowOnEnableChange(newEnabledState
);
1164 // ----------------------------------------------------------------------------
1165 // event handler stuff
1166 // ----------------------------------------------------------------------------
1168 void wxWindowBase::SetEventHandler(wxEvtHandler
*handler
)
1170 wxCHECK_RET(handler
!= NULL
, "SetEventHandler(NULL) called");
1172 m_eventHandler
= handler
;
1175 void wxWindowBase::SetNextHandler(wxEvtHandler
*WXUNUSED(handler
))
1177 // disable wxEvtHandler chain mechanism for wxWindows:
1178 // wxWindow uses its own stack mechanism which doesn't mix well with wxEvtHandler's one
1180 wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
1182 void wxWindowBase::SetPreviousHandler(wxEvtHandler
*WXUNUSED(handler
))
1184 // we can't simply wxFAIL here as in SetNextHandler: in fact the last
1185 // handler of our stack when is destroyed will be Unlink()ed and thus
1186 // will call this function to update the pointer of this window...
1188 //wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
1191 void wxWindowBase::PushEventHandler(wxEvtHandler
*handlerToPush
)
1193 wxCHECK_RET( handlerToPush
!= NULL
, "PushEventHandler(NULL) called" );
1195 // the new handler is going to be part of the wxWindow stack of event handlers:
1196 // it can't be part also of an event handler double-linked chain:
1197 wxASSERT_MSG(handlerToPush
->IsUnlinked(),
1198 "The handler being pushed in the wxWindow stack shouldn't be part of "
1199 "a wxEvtHandler chain; call Unlink() on it first");
1201 wxEvtHandler
*handlerOld
= GetEventHandler();
1202 wxCHECK_RET( handlerOld
, "an old event handler is NULL?" );
1204 // now use wxEvtHandler double-linked list to implement a stack:
1205 handlerToPush
->SetNextHandler(handlerOld
);
1207 if (handlerOld
!= this)
1208 handlerOld
->SetPreviousHandler(handlerToPush
);
1210 SetEventHandler(handlerToPush
);
1213 // final checks of the operations done above:
1214 wxASSERT_MSG( handlerToPush
->GetPreviousHandler() == NULL
,
1215 "the first handler of the wxWindow stack should "
1216 "have no previous handlers set" );
1217 wxASSERT_MSG( handlerToPush
->GetNextHandler() != NULL
,
1218 "the first handler of the wxWindow stack should "
1219 "have non-NULL next handler" );
1221 wxEvtHandler
* pLast
= handlerToPush
;
1222 while ( pLast
&& pLast
!= this )
1223 pLast
= pLast
->GetNextHandler();
1224 wxASSERT_MSG( pLast
->GetNextHandler() == NULL
,
1225 "the last handler of the wxWindow stack should "
1226 "have this window as next handler" );
1227 #endif // wxDEBUG_LEVEL
1230 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
1232 // we need to pop the wxWindow stack, i.e. we need to remove the first handler
1234 wxEvtHandler
*firstHandler
= GetEventHandler();
1235 wxCHECK_MSG( firstHandler
!= NULL
, NULL
, "wxWindow cannot have a NULL event handler" );
1236 wxCHECK_MSG( firstHandler
!= this, NULL
, "cannot pop the wxWindow itself" );
1237 wxCHECK_MSG( firstHandler
->GetPreviousHandler() == NULL
, NULL
,
1238 "the first handler of the wxWindow stack should have no previous handlers set" );
1240 wxEvtHandler
*secondHandler
= firstHandler
->GetNextHandler();
1241 wxCHECK_MSG( secondHandler
!= NULL
, NULL
,
1242 "the first handler of the wxWindow stack should have non-NULL next handler" );
1244 firstHandler
->SetNextHandler(NULL
);
1245 secondHandler
->SetPreviousHandler(NULL
);
1247 // now firstHandler is completely unlinked; set secondHandler as the new window event handler
1248 SetEventHandler(secondHandler
);
1250 if ( deleteHandler
)
1252 delete firstHandler
;
1253 firstHandler
= NULL
;
1256 return firstHandler
;
1259 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handlerToRemove
)
1261 wxCHECK_MSG( handlerToRemove
!= NULL
, false, "RemoveEventHandler(NULL) called" );
1262 wxCHECK_MSG( handlerToRemove
!= this, false, "Cannot remove the window itself" );
1264 if (handlerToRemove
== GetEventHandler())
1266 // removing the first event handler is equivalent to "popping" the stack
1267 PopEventHandler(false);
1271 // NOTE: the wxWindow event handler list is always terminated with "this" handler
1272 wxEvtHandler
*handlerCur
= GetEventHandler()->GetNextHandler();
1273 while ( handlerCur
!= this )
1275 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
1277 if ( handlerCur
== handlerToRemove
)
1279 handlerCur
->Unlink();
1281 wxASSERT_MSG( handlerCur
!= GetEventHandler(),
1282 "the case Remove == Pop should was already handled" );
1286 handlerCur
= handlerNext
;
1289 wxFAIL_MSG( wxT("where has the event handler gone?") );
1294 bool wxWindowBase::HandleWindowEvent(wxEvent
& event
) const
1296 // SafelyProcessEvent() will handle exceptions nicely
1297 return GetEventHandler()->SafelyProcessEvent(event
);
1300 // ----------------------------------------------------------------------------
1301 // colours, fonts &c
1302 // ----------------------------------------------------------------------------
1304 void wxWindowBase::InheritAttributes()
1306 const wxWindowBase
* const parent
= GetParent();
1310 // we only inherit attributes which had been explicitly set for the parent
1311 // which ensures that this only happens if the user really wants it and
1312 // not by default which wouldn't make any sense in modern GUIs where the
1313 // controls don't all use the same fonts (nor colours)
1314 if ( parent
->m_inheritFont
&& !m_hasFont
)
1315 SetFont(parent
->GetFont());
1317 // in addition, there is a possibility to explicitly forbid inheriting
1318 // colours at each class level by overriding ShouldInheritColours()
1319 if ( ShouldInheritColours() )
1321 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1322 SetForegroundColour(parent
->GetForegroundColour());
1324 // inheriting (solid) background colour is wrong as it totally breaks
1325 // any kind of themed backgrounds
1327 // instead, the controls should use the same background as their parent
1328 // (ideally by not drawing it at all)
1330 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1331 SetBackgroundColour(parent
->GetBackgroundColour());
1336 /* static */ wxVisualAttributes
1337 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1339 // it is important to return valid values for all attributes from here,
1340 // GetXXX() below rely on this
1341 wxVisualAttributes attrs
;
1342 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1343 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1345 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1346 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1347 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1348 // colour on other platforms.
1350 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1351 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1353 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1358 wxColour
wxWindowBase::GetBackgroundColour() const
1360 if ( !m_backgroundColour
.IsOk() )
1362 wxASSERT_MSG( !m_hasBgCol
, wxT("we have invalid explicit bg colour?") );
1364 // get our default background colour
1365 wxColour colBg
= GetDefaultAttributes().colBg
;
1367 // we must return some valid colour to avoid redoing this every time
1368 // and also to avoid surprising the applications written for older
1369 // wxWidgets versions where GetBackgroundColour() always returned
1370 // something -- so give them something even if it doesn't make sense
1371 // for this window (e.g. it has a themed background)
1373 colBg
= GetClassDefaultAttributes().colBg
;
1378 return m_backgroundColour
;
1381 wxColour
wxWindowBase::GetForegroundColour() const
1383 // logic is the same as above
1384 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1386 wxColour colFg
= GetDefaultAttributes().colFg
;
1388 if ( !colFg
.IsOk() )
1389 colFg
= GetClassDefaultAttributes().colFg
;
1394 return m_foregroundColour
;
1397 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1399 if ( colour
== m_backgroundColour
)
1402 m_hasBgCol
= colour
.IsOk();
1404 m_inheritBgCol
= m_hasBgCol
;
1405 m_backgroundColour
= colour
;
1406 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1410 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1412 if (colour
== m_foregroundColour
)
1415 m_hasFgCol
= colour
.IsOk();
1416 m_inheritFgCol
= m_hasFgCol
;
1417 m_foregroundColour
= colour
;
1418 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1422 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1424 // setting an invalid cursor is ok, it means that we don't have any special
1426 if ( m_cursor
.IsSameAs(cursor
) )
1437 wxFont
wxWindowBase::GetFont() const
1439 // logic is the same as in GetBackgroundColour()
1440 if ( !m_font
.IsOk() )
1442 wxASSERT_MSG( !m_hasFont
, wxT("we have invalid explicit font?") );
1444 wxFont font
= GetDefaultAttributes().font
;
1446 font
= GetClassDefaultAttributes().font
;
1454 bool wxWindowBase::SetFont(const wxFont
& font
)
1456 if ( font
== m_font
)
1463 m_hasFont
= font
.IsOk();
1464 m_inheritFont
= m_hasFont
;
1466 InvalidateBestSize();
1473 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1475 m_hasCustomPalette
= true;
1478 // VZ: can anyone explain me what do we do here?
1479 wxWindowDC
d((wxWindow
*) this);
1483 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1485 wxWindow
*win
= (wxWindow
*)this;
1486 while ( win
&& !win
->HasCustomPalette() )
1488 win
= win
->GetParent();
1494 #endif // wxUSE_PALETTE
1497 void wxWindowBase::SetCaret(wxCaret
*caret
)
1508 wxASSERT_MSG( m_caret
->GetWindow() == this,
1509 wxT("caret should be created associated to this window") );
1512 #endif // wxUSE_CARET
1514 #if wxUSE_VALIDATORS
1515 // ----------------------------------------------------------------------------
1517 // ----------------------------------------------------------------------------
1519 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1521 if ( m_windowValidator
)
1522 delete m_windowValidator
;
1524 m_windowValidator
= (wxValidator
*)validator
.Clone();
1526 if ( m_windowValidator
)
1527 m_windowValidator
->SetWindow(this);
1529 #endif // wxUSE_VALIDATORS
1531 // ----------------------------------------------------------------------------
1532 // update region stuff
1533 // ----------------------------------------------------------------------------
1535 wxRect
wxWindowBase::GetUpdateClientRect() const
1537 wxRegion rgnUpdate
= GetUpdateRegion();
1538 rgnUpdate
.Intersect(GetClientRect());
1539 wxRect rectUpdate
= rgnUpdate
.GetBox();
1540 wxPoint ptOrigin
= GetClientAreaOrigin();
1541 rectUpdate
.x
-= ptOrigin
.x
;
1542 rectUpdate
.y
-= ptOrigin
.y
;
1547 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1549 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1552 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1554 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1557 void wxWindowBase::ClearBackground()
1559 // wxGTK uses its own version, no need to add never used code
1561 wxClientDC
dc((wxWindow
*)this);
1562 wxBrush
brush(GetBackgroundColour(), wxBRUSHSTYLE_SOLID
);
1563 dc
.SetBackground(brush
);
1568 // ----------------------------------------------------------------------------
1569 // find child window by id or name
1570 // ----------------------------------------------------------------------------
1572 wxWindow
*wxWindowBase::FindWindow(long id
) const
1574 if ( id
== m_windowId
)
1575 return (wxWindow
*)this;
1577 wxWindowBase
*res
= NULL
;
1578 wxWindowList::compatibility_iterator node
;
1579 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1581 wxWindowBase
*child
= node
->GetData();
1582 res
= child
->FindWindow( id
);
1585 return (wxWindow
*)res
;
1588 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1590 if ( name
== m_windowName
)
1591 return (wxWindow
*)this;
1593 wxWindowBase
*res
= NULL
;
1594 wxWindowList::compatibility_iterator node
;
1595 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1597 wxWindow
*child
= node
->GetData();
1598 res
= child
->FindWindow(name
);
1601 return (wxWindow
*)res
;
1605 // find any window by id or name or label: If parent is non-NULL, look through
1606 // children for a label or title matching the specified string. If NULL, look
1607 // through all top-level windows.
1609 // to avoid duplicating code we reuse the same helper function but with
1610 // different comparators
1612 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1613 const wxString
& label
, long id
);
1616 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1619 return win
->GetLabel() == label
;
1623 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1626 return win
->GetName() == label
;
1630 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1633 return win
->GetId() == id
;
1636 // recursive helper for the FindWindowByXXX() functions
1638 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1639 const wxString
& label
,
1641 wxFindWindowCmp cmp
)
1645 // see if this is the one we're looking for
1646 if ( (*cmp
)(parent
, label
, id
) )
1647 return (wxWindow
*)parent
;
1649 // It wasn't, so check all its children
1650 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1652 node
= node
->GetNext() )
1654 // recursively check each child
1655 wxWindow
*win
= (wxWindow
*)node
->GetData();
1656 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1666 // helper for FindWindowByXXX()
1668 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1669 const wxString
& label
,
1671 wxFindWindowCmp cmp
)
1675 // just check parent and all its children
1676 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1679 // start at very top of wx's windows
1680 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1682 node
= node
->GetNext() )
1684 // recursively check each window & its children
1685 wxWindow
*win
= node
->GetData();
1686 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1696 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1698 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1703 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1705 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1709 // fall back to the label
1710 win
= FindWindowByLabel(title
, parent
);
1718 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1720 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1723 // ----------------------------------------------------------------------------
1724 // dialog oriented functions
1725 // ----------------------------------------------------------------------------
1727 void wxWindowBase::MakeModal(bool modal
)
1729 // Disable all other windows
1732 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1735 wxWindow
*win
= node
->GetData();
1737 win
->Enable(!modal
);
1739 node
= node
->GetNext();
1744 bool wxWindowBase::Validate()
1746 #if wxUSE_VALIDATORS
1747 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1749 wxWindowList::compatibility_iterator node
;
1750 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1752 wxWindowBase
*child
= node
->GetData();
1753 wxValidator
*validator
= child
->GetValidator();
1754 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1759 if ( recurse
&& !child
->Validate() )
1764 #endif // wxUSE_VALIDATORS
1769 bool wxWindowBase::TransferDataToWindow()
1771 #if wxUSE_VALIDATORS
1772 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1774 wxWindowList::compatibility_iterator node
;
1775 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1777 wxWindowBase
*child
= node
->GetData();
1778 wxValidator
*validator
= child
->GetValidator();
1779 if ( validator
&& !validator
->TransferToWindow() )
1781 wxLogWarning(_("Could not transfer data to window"));
1783 wxLog::FlushActive();
1791 if ( !child
->TransferDataToWindow() )
1793 // warning already given
1798 #endif // wxUSE_VALIDATORS
1803 bool wxWindowBase::TransferDataFromWindow()
1805 #if wxUSE_VALIDATORS
1806 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1808 wxWindowList::compatibility_iterator node
;
1809 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1811 wxWindow
*child
= node
->GetData();
1812 wxValidator
*validator
= child
->GetValidator();
1813 if ( validator
&& !validator
->TransferFromWindow() )
1815 // nop warning here because the application is supposed to give
1816 // one itself - we don't know here what might have gone wrongly
1823 if ( !child
->TransferDataFromWindow() )
1825 // warning already given
1830 #endif // wxUSE_VALIDATORS
1835 void wxWindowBase::InitDialog()
1837 wxInitDialogEvent
event(GetId());
1838 event
.SetEventObject( this );
1839 GetEventHandler()->ProcessEvent(event
);
1842 // ----------------------------------------------------------------------------
1843 // context-sensitive help support
1844 // ----------------------------------------------------------------------------
1848 // associate this help text with this window
1849 void wxWindowBase::SetHelpText(const wxString
& text
)
1851 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1854 helpProvider
->AddHelp(this, text
);
1858 #if WXWIN_COMPATIBILITY_2_8
1859 // associate this help text with all windows with the same id as this
1861 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1863 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1866 helpProvider
->AddHelp(GetId(), text
);
1869 #endif // WXWIN_COMPATIBILITY_2_8
1871 // get the help string associated with this window (may be empty)
1872 // default implementation forwards calls to the help provider
1874 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1875 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1878 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1881 text
= helpProvider
->GetHelp(this);
1887 // show help for this window
1888 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1890 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1893 wxPoint pos
= event
.GetPosition();
1894 const wxHelpEvent::Origin origin
= event
.GetOrigin();
1895 if ( origin
== wxHelpEvent::Origin_Keyboard
)
1897 // if the help event was generated from keyboard it shouldn't
1898 // appear at the mouse position (which is still the only position
1899 // associated with help event) if the mouse is far away, although
1900 // we still do use the mouse position if it's over the window
1901 // because we suppose the user looks approximately at the mouse
1902 // already and so it would be more convenient than showing tooltip
1903 // at some arbitrary position which can be quite far from it
1904 const wxRect rectClient
= GetClientRect();
1905 if ( !rectClient
.Contains(ScreenToClient(pos
)) )
1907 // position help slightly under and to the right of this window
1908 pos
= ClientToScreen(wxPoint(
1910 rectClient
.height
+ GetCharHeight()
1915 if ( helpProvider
->ShowHelpAtPoint(this, pos
, origin
) )
1917 // skip the event.Skip() below
1925 #endif // wxUSE_HELP
1927 // ----------------------------------------------------------------------------
1929 // ----------------------------------------------------------------------------
1933 wxString
wxWindowBase::GetToolTipText() const
1935 return m_tooltip
? m_tooltip
->GetTip() : wxString();
1938 void wxWindowBase::SetToolTip( const wxString
&tip
)
1940 // don't create the new tooltip if we already have one
1943 m_tooltip
->SetTip( tip
);
1947 SetToolTip( new wxToolTip( tip
) );
1950 // setting empty tooltip text does not remove the tooltip any more - use
1951 // SetToolTip(NULL) for this
1954 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1956 if ( m_tooltip
!= tooltip
)
1961 m_tooltip
= tooltip
;
1965 #endif // wxUSE_TOOLTIPS
1967 // ----------------------------------------------------------------------------
1968 // constraints and sizers
1969 // ----------------------------------------------------------------------------
1971 #if wxUSE_CONSTRAINTS
1973 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1975 if ( m_constraints
)
1977 UnsetConstraints(m_constraints
);
1978 delete m_constraints
;
1980 m_constraints
= constraints
;
1981 if ( m_constraints
)
1983 // Make sure other windows know they're part of a 'meaningful relationship'
1984 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1985 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1986 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1987 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1988 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1989 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1990 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1991 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1992 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1993 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1994 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1995 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1996 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1997 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1998 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1999 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
2003 // This removes any dangling pointers to this window in other windows'
2004 // constraintsInvolvedIn lists.
2005 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
2009 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
2010 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
2011 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
2012 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
2013 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
2014 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
2015 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
2016 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
2017 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
2018 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
2019 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
2020 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
2021 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
2022 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
2023 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
2024 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
2028 // Back-pointer to other windows we're involved with, so if we delete this
2029 // window, we must delete any constraints we're involved with.
2030 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
2032 if ( !m_constraintsInvolvedIn
)
2033 m_constraintsInvolvedIn
= new wxWindowList
;
2034 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
2035 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
2038 // REMOVE back-pointer to other windows we're involved with.
2039 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
2041 if ( m_constraintsInvolvedIn
)
2042 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
2045 // Reset any constraints that mention this window
2046 void wxWindowBase::DeleteRelatedConstraints()
2048 if ( m_constraintsInvolvedIn
)
2050 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
2053 wxWindow
*win
= node
->GetData();
2054 wxLayoutConstraints
*constr
= win
->GetConstraints();
2056 // Reset any constraints involving this window
2059 constr
->left
.ResetIfWin(this);
2060 constr
->top
.ResetIfWin(this);
2061 constr
->right
.ResetIfWin(this);
2062 constr
->bottom
.ResetIfWin(this);
2063 constr
->width
.ResetIfWin(this);
2064 constr
->height
.ResetIfWin(this);
2065 constr
->centreX
.ResetIfWin(this);
2066 constr
->centreY
.ResetIfWin(this);
2069 wxWindowList::compatibility_iterator next
= node
->GetNext();
2070 m_constraintsInvolvedIn
->Erase(node
);
2074 delete m_constraintsInvolvedIn
;
2075 m_constraintsInvolvedIn
= NULL
;
2079 #endif // wxUSE_CONSTRAINTS
2081 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
2083 if ( sizer
== m_windowSizer
)
2086 if ( m_windowSizer
)
2088 m_windowSizer
->SetContainingWindow(NULL
);
2091 delete m_windowSizer
;
2094 m_windowSizer
= sizer
;
2095 if ( m_windowSizer
)
2097 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
2100 SetAutoLayout(m_windowSizer
!= NULL
);
2103 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
2105 SetSizer( sizer
, deleteOld
);
2106 sizer
->SetSizeHints( (wxWindow
*) this );
2110 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
2112 // adding a window to a sizer twice is going to result in fatal and
2113 // hard to debug problems later because when deleting the second
2114 // associated wxSizerItem we're going to dereference a dangling
2115 // pointer; so try to detect this as early as possible
2116 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
2117 wxT("Adding a window to the same sizer twice?") );
2119 m_containingSizer
= sizer
;
2122 #if wxUSE_CONSTRAINTS
2124 void wxWindowBase::SatisfyConstraints()
2126 wxLayoutConstraints
*constr
= GetConstraints();
2127 bool wasOk
= constr
&& constr
->AreSatisfied();
2129 ResetConstraints(); // Mark all constraints as unevaluated
2133 // if we're a top level panel (i.e. our parent is frame/dialog), our
2134 // own constraints will never be satisfied any more unless we do it
2138 while ( noChanges
> 0 )
2140 LayoutPhase1(&noChanges
);
2144 LayoutPhase2(&noChanges
);
2147 #endif // wxUSE_CONSTRAINTS
2149 bool wxWindowBase::Layout()
2151 // If there is a sizer, use it instead of the constraints
2155 GetVirtualSize(&w
, &h
);
2156 GetSizer()->SetDimension( 0, 0, w
, h
);
2158 #if wxUSE_CONSTRAINTS
2161 SatisfyConstraints(); // Find the right constraints values
2162 SetConstraintSizes(); // Recursively set the real window sizes
2169 void wxWindowBase::InternalOnSize(wxSizeEvent
& event
)
2171 if ( GetAutoLayout() )
2177 #if wxUSE_CONSTRAINTS
2179 // first phase of the constraints evaluation: set our own constraints
2180 bool wxWindowBase::LayoutPhase1(int *noChanges
)
2182 wxLayoutConstraints
*constr
= GetConstraints();
2184 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
2187 // second phase: set the constraints for our children
2188 bool wxWindowBase::LayoutPhase2(int *noChanges
)
2195 // Layout grand children
2201 // Do a phase of evaluating child constraints
2202 bool wxWindowBase::DoPhase(int phase
)
2204 // the list containing the children for which the constraints are already
2206 wxWindowList succeeded
;
2208 // the max number of iterations we loop before concluding that we can't set
2210 static const int maxIterations
= 500;
2212 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
2216 // loop over all children setting their constraints
2217 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2219 node
= node
->GetNext() )
2221 wxWindow
*child
= node
->GetData();
2222 if ( child
->IsTopLevel() )
2224 // top level children are not inside our client area
2228 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
2230 // this one is either already ok or nothing we can do about it
2234 int tempNoChanges
= 0;
2235 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
2236 : child
->LayoutPhase2(&tempNoChanges
);
2237 noChanges
+= tempNoChanges
;
2241 succeeded
.Append(child
);
2247 // constraints are set
2255 void wxWindowBase::ResetConstraints()
2257 wxLayoutConstraints
*constr
= GetConstraints();
2260 constr
->left
.SetDone(false);
2261 constr
->top
.SetDone(false);
2262 constr
->right
.SetDone(false);
2263 constr
->bottom
.SetDone(false);
2264 constr
->width
.SetDone(false);
2265 constr
->height
.SetDone(false);
2266 constr
->centreX
.SetDone(false);
2267 constr
->centreY
.SetDone(false);
2270 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2273 wxWindow
*win
= node
->GetData();
2274 if ( !win
->IsTopLevel() )
2275 win
->ResetConstraints();
2276 node
= node
->GetNext();
2280 // Need to distinguish between setting the 'fake' size for windows and sizers,
2281 // and setting the real values.
2282 void wxWindowBase::SetConstraintSizes(bool recurse
)
2284 wxLayoutConstraints
*constr
= GetConstraints();
2285 if ( constr
&& constr
->AreSatisfied() )
2287 int x
= constr
->left
.GetValue();
2288 int y
= constr
->top
.GetValue();
2289 int w
= constr
->width
.GetValue();
2290 int h
= constr
->height
.GetValue();
2292 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
2293 (constr
->height
.GetRelationship() != wxAsIs
) )
2295 SetSize(x
, y
, w
, h
);
2299 // If we don't want to resize this window, just move it...
2305 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
2306 GetClassInfo()->GetClassName(),
2312 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2315 wxWindow
*win
= node
->GetData();
2316 if ( !win
->IsTopLevel() && win
->GetConstraints() )
2317 win
->SetConstraintSizes();
2318 node
= node
->GetNext();
2323 // Only set the size/position of the constraint (if any)
2324 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
2326 wxLayoutConstraints
*constr
= GetConstraints();
2329 if ( x
!= wxDefaultCoord
)
2331 constr
->left
.SetValue(x
);
2332 constr
->left
.SetDone(true);
2334 if ( y
!= wxDefaultCoord
)
2336 constr
->top
.SetValue(y
);
2337 constr
->top
.SetDone(true);
2339 if ( w
!= wxDefaultCoord
)
2341 constr
->width
.SetValue(w
);
2342 constr
->width
.SetDone(true);
2344 if ( h
!= wxDefaultCoord
)
2346 constr
->height
.SetValue(h
);
2347 constr
->height
.SetDone(true);
2352 void wxWindowBase::MoveConstraint(int x
, int y
)
2354 wxLayoutConstraints
*constr
= GetConstraints();
2357 if ( x
!= wxDefaultCoord
)
2359 constr
->left
.SetValue(x
);
2360 constr
->left
.SetDone(true);
2362 if ( y
!= wxDefaultCoord
)
2364 constr
->top
.SetValue(y
);
2365 constr
->top
.SetDone(true);
2370 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2372 wxLayoutConstraints
*constr
= GetConstraints();
2375 *w
= constr
->width
.GetValue();
2376 *h
= constr
->height
.GetValue();
2382 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2384 wxLayoutConstraints
*constr
= GetConstraints();
2387 *w
= constr
->width
.GetValue();
2388 *h
= constr
->height
.GetValue();
2391 GetClientSize(w
, h
);
2394 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2396 wxLayoutConstraints
*constr
= GetConstraints();
2399 *x
= constr
->left
.GetValue();
2400 *y
= constr
->top
.GetValue();
2406 #endif // wxUSE_CONSTRAINTS
2408 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2410 // don't do it for the dialogs/frames - they float independently of their
2412 if ( !IsTopLevel() )
2414 wxWindow
*parent
= GetParent();
2415 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2417 wxPoint
pt(parent
->GetClientAreaOrigin());
2424 // ----------------------------------------------------------------------------
2425 // Update UI processing
2426 // ----------------------------------------------------------------------------
2428 void wxWindowBase::UpdateWindowUI(long flags
)
2430 wxUpdateUIEvent
event(GetId());
2431 event
.SetEventObject(this);
2433 if ( GetEventHandler()->ProcessEvent(event
) )
2435 DoUpdateWindowUI(event
);
2438 if (flags
& wxUPDATE_UI_RECURSE
)
2440 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2443 wxWindow
* child
= (wxWindow
*) node
->GetData();
2444 child
->UpdateWindowUI(flags
);
2445 node
= node
->GetNext();
2450 // do the window-specific processing after processing the update event
2451 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2453 if ( event
.GetSetEnabled() )
2454 Enable(event
.GetEnabled());
2456 if ( event
.GetSetShown() )
2457 Show(event
.GetShown());
2460 // ----------------------------------------------------------------------------
2461 // dialog units translations
2462 // ----------------------------------------------------------------------------
2464 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
) const
2466 wxPoint pt2
= wxDefaultPosition
;
2467 if (pt
.x
!= wxDefaultCoord
)
2468 pt2
.x
= (int) ((pt
.x
* 4) / GetCharWidth());
2469 if (pt
.y
!= wxDefaultCoord
)
2470 pt2
.y
= (int) ((pt
.y
* 8) / GetCharHeight());
2475 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
) const
2477 wxPoint pt2
= wxDefaultPosition
;
2478 if (pt
.x
!= wxDefaultCoord
)
2479 pt2
.x
= (int) ((pt
.x
* GetCharWidth()) / 4);
2480 if (pt
.y
!= wxDefaultCoord
)
2481 pt2
.y
= (int) ((pt
.y
* GetCharHeight()) / 8);
2486 // ----------------------------------------------------------------------------
2488 // ----------------------------------------------------------------------------
2490 // propagate the colour change event to the subwindows
2491 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
2493 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2496 // Only propagate to non-top-level windows
2497 wxWindow
*win
= node
->GetData();
2498 if ( !win
->IsTopLevel() )
2500 wxSysColourChangedEvent event2
;
2501 event2
.SetEventObject(win
);
2502 win
->GetEventHandler()->ProcessEvent(event2
);
2505 node
= node
->GetNext();
2511 // the default action is to populate dialog with data when it's created,
2512 // and nudge the UI into displaying itself correctly in case
2513 // we've turned the wxUpdateUIEvents frequency down low.
2514 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2516 TransferDataToWindow();
2518 // Update the UI at this point
2519 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2522 // ----------------------------------------------------------------------------
2523 // menu-related functions
2524 // ----------------------------------------------------------------------------
2528 bool wxWindowBase::PopupMenu(wxMenu
*menu
, int x
, int y
)
2530 wxCHECK_MSG( menu
, false, "can't popup NULL menu" );
2532 wxCurrentPopupMenu
= menu
;
2533 const bool rc
= DoPopupMenu(menu
, x
, y
);
2534 wxCurrentPopupMenu
= NULL
;
2539 // this is used to pass the id of the selected item from the menu event handler
2540 // to the main function itself
2542 // it's ok to use a global here as there can be at most one popup menu shown at
2544 static int gs_popupMenuSelection
= wxID_NONE
;
2546 void wxWindowBase::InternalOnPopupMenu(wxCommandEvent
& event
)
2548 // store the id in a global variable where we'll retrieve it from later
2549 gs_popupMenuSelection
= event
.GetId();
2552 void wxWindowBase::InternalOnPopupMenuUpdate(wxUpdateUIEvent
& WXUNUSED(event
))
2554 // nothing to do but do not skip it
2558 wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu
& menu
, int x
, int y
)
2560 gs_popupMenuSelection
= wxID_NONE
;
2562 Connect(wxEVT_COMMAND_MENU_SELECTED
,
2563 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2567 // it is common to construct the menu passed to this function dynamically
2568 // using some fixed range of ids which could clash with the ids used
2569 // elsewhere in the program, which could result in some menu items being
2570 // unintentionally disabled or otherwise modified by update UI handlers
2571 // elsewhere in the program code and this is difficult to avoid in the
2572 // program itself, so instead we just temporarily suspend UI updating while
2573 // this menu is shown
2574 Connect(wxEVT_UPDATE_UI
,
2575 wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate
),
2579 PopupMenu(&menu
, x
, y
);
2581 Disconnect(wxEVT_UPDATE_UI
,
2582 wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate
),
2585 Disconnect(wxEVT_COMMAND_MENU_SELECTED
,
2586 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2590 return gs_popupMenuSelection
;
2593 #endif // wxUSE_MENUS
2595 // methods for drawing the sizers in a visible way: this is currently only
2596 // enabled for "full debug" builds with wxDEBUG_LEVEL==2 as it doesn't work
2597 // that well and also because we don't want to leave it enabled in default
2598 // builds used for production
2599 #if wxDEBUG_LEVEL > 1
2601 static void DrawSizers(wxWindowBase
*win
);
2603 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
, const wxPen
* pen
)
2605 wxClientDC
dc((wxWindow
*)win
);
2607 dc
.SetBrush(fill
? wxBrush(pen
->GetColour(), wxBRUSHSTYLE_CROSSDIAG_HATCH
) :
2608 *wxTRANSPARENT_BRUSH
);
2609 dc
.DrawRectangle(rect
.Deflate(1, 1));
2612 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2614 const wxSizerItemList
& items
= sizer
->GetChildren();
2615 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2620 wxSizerItem
*item
= *i
;
2621 if ( item
->IsSizer() )
2623 DrawBorder(win
, item
->GetRect().Deflate(2), false, wxRED_PEN
);
2624 DrawSizer(win
, item
->GetSizer());
2626 else if ( item
->IsSpacer() )
2628 DrawBorder(win
, item
->GetRect().Deflate(2), true, wxBLUE_PEN
);
2630 else if ( item
->IsWindow() )
2632 DrawSizers(item
->GetWindow());
2635 wxFAIL_MSG("inconsistent wxSizerItem status!");
2639 static void DrawSizers(wxWindowBase
*win
)
2641 DrawBorder(win
, win
->GetClientSize(), false, wxGREEN_PEN
);
2643 wxSizer
*sizer
= win
->GetSizer();
2646 DrawSizer(win
, sizer
);
2648 else // no sizer, still recurse into the children
2650 const wxWindowList
& children
= win
->GetChildren();
2651 for ( wxWindowList::const_iterator i
= children
.begin(),
2652 end
= children
.end();
2659 // show all kind of sizes of this window; see the "window sizing" topic
2660 // overview for more info about the various differences:
2661 wxSize fullSz
= win
->GetSize();
2662 wxSize clientSz
= win
->GetClientSize();
2663 wxSize bestSz
= win
->GetBestSize();
2664 wxSize minSz
= win
->GetMinSize();
2665 wxSize maxSz
= win
->GetMaxSize();
2666 wxSize virtualSz
= win
->GetVirtualSize();
2668 wxMessageOutputDebug dbgout
;
2670 "%-10s => fullsz=%4d;%-4d clientsz=%4d;%-4d bestsz=%4d;%-4d minsz=%4d;%-4d maxsz=%4d;%-4d virtualsz=%4d;%-4d\n",
2673 clientSz
.x
, clientSz
.y
,
2677 virtualSz
.x
, virtualSz
.y
);
2681 #endif // wxDEBUG_LEVEL
2683 // process special middle clicks
2684 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2686 if ( event
.ControlDown() && event
.AltDown() )
2688 #if wxDEBUG_LEVEL > 1
2689 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2690 if ( event
.ShiftDown() )
2695 #endif // __WXDEBUG__
2697 // just Ctrl-Alt-middle click shows information about wx version
2698 ::wxInfoMessageBox((wxWindow
*)this);
2707 // ----------------------------------------------------------------------------
2709 // ----------------------------------------------------------------------------
2711 #if wxUSE_ACCESSIBILITY
2712 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2714 if (m_accessible
&& (accessible
!= m_accessible
))
2715 delete m_accessible
;
2716 m_accessible
= accessible
;
2718 m_accessible
->SetWindow((wxWindow
*) this);
2721 // Returns the accessible object, creating if necessary.
2722 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2725 m_accessible
= CreateAccessible();
2726 return m_accessible
;
2729 // Override to create a specific accessible object.
2730 wxAccessible
* wxWindowBase::CreateAccessible()
2732 return new wxWindowAccessible((wxWindow
*) this);
2737 // ----------------------------------------------------------------------------
2738 // list classes implementation
2739 // ----------------------------------------------------------------------------
2743 #include "wx/listimpl.cpp"
2744 WX_DEFINE_LIST(wxWindowList
)
2748 void wxWindowListNode::DeleteData()
2750 delete (wxWindow
*)GetData();
2753 #endif // wxUSE_STL/!wxUSE_STL
2755 // ----------------------------------------------------------------------------
2757 // ----------------------------------------------------------------------------
2759 wxBorder
wxWindowBase::GetBorder(long flags
) const
2761 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2762 if ( border
== wxBORDER_DEFAULT
)
2764 border
= GetDefaultBorder();
2766 else if ( border
== wxBORDER_THEME
)
2768 border
= GetDefaultBorderForControl();
2774 wxBorder
wxWindowBase::GetDefaultBorder() const
2776 return wxBORDER_NONE
;
2779 // ----------------------------------------------------------------------------
2781 // ----------------------------------------------------------------------------
2783 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2785 // here we just check if the point is inside the window or not
2787 // check the top and left border first
2788 bool outside
= x
< 0 || y
< 0;
2791 // check the right and bottom borders too
2792 wxSize size
= GetSize();
2793 outside
= x
>= size
.x
|| y
>= size
.y
;
2796 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2799 // ----------------------------------------------------------------------------
2801 // ----------------------------------------------------------------------------
2803 struct WXDLLEXPORT wxWindowNext
2807 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2808 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2809 bool wxWindowBase::ms_winCaptureChanging
= false;
2811 void wxWindowBase::CaptureMouse()
2813 wxLogTrace(wxT("mousecapture"), wxT("CaptureMouse(%p)"), static_cast<void*>(this));
2815 wxASSERT_MSG( !ms_winCaptureChanging
, wxT("recursive CaptureMouse call?") );
2817 ms_winCaptureChanging
= true;
2819 wxWindow
*winOld
= GetCapture();
2822 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2825 wxWindowNext
*item
= new wxWindowNext
;
2827 item
->next
= ms_winCaptureNext
;
2828 ms_winCaptureNext
= item
;
2830 //else: no mouse capture to save
2833 ms_winCaptureCurrent
= (wxWindow
*)this;
2835 ms_winCaptureChanging
= false;
2838 void wxWindowBase::ReleaseMouse()
2840 wxLogTrace(wxT("mousecapture"), wxT("ReleaseMouse(%p)"), static_cast<void*>(this));
2842 wxASSERT_MSG( !ms_winCaptureChanging
, wxT("recursive ReleaseMouse call?") );
2844 wxASSERT_MSG( GetCapture() == this,
2845 "attempt to release mouse, but this window hasn't captured it" );
2846 wxASSERT_MSG( ms_winCaptureCurrent
== this,
2847 "attempt to release mouse, but this window hasn't captured it" );
2849 ms_winCaptureChanging
= true;
2852 ms_winCaptureCurrent
= NULL
;
2854 if ( ms_winCaptureNext
)
2856 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2857 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2859 wxWindowNext
*item
= ms_winCaptureNext
;
2860 ms_winCaptureNext
= item
->next
;
2863 //else: stack is empty, no previous capture
2865 ms_winCaptureChanging
= false;
2867 wxLogTrace(wxT("mousecapture"),
2868 (const wxChar
*) wxT("After ReleaseMouse() mouse is captured by %p"),
2869 static_cast<void*>(GetCapture()));
2872 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2874 wxMouseCaptureLostEvent
event(win
->GetId());
2875 event
.SetEventObject(win
);
2876 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2878 // windows must handle this event, otherwise the app wouldn't behave
2879 // correctly if it loses capture unexpectedly; see the discussion here:
2880 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
2881 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
2882 wxFAIL_MSG( wxT("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2887 void wxWindowBase::NotifyCaptureLost()
2889 // don't do anything if capture lost was expected, i.e. resulted from
2890 // a wx call to ReleaseMouse or CaptureMouse:
2891 if ( ms_winCaptureChanging
)
2894 // if the capture was lost unexpectedly, notify every window that has
2895 // capture (on stack or current) about it and clear the stack:
2897 if ( ms_winCaptureCurrent
)
2899 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2900 ms_winCaptureCurrent
= NULL
;
2903 while ( ms_winCaptureNext
)
2905 wxWindowNext
*item
= ms_winCaptureNext
;
2906 ms_winCaptureNext
= item
->next
;
2908 DoNotifyWindowAboutCaptureLost(item
->win
);
2917 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2918 int WXUNUSED(modifiers
),
2919 int WXUNUSED(keycode
))
2925 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2931 #endif // wxUSE_HOTKEY
2933 // ----------------------------------------------------------------------------
2935 // ----------------------------------------------------------------------------
2937 bool wxWindowBase::TryBefore(wxEvent
& event
)
2939 #if wxUSE_VALIDATORS
2940 // Can only use the validator of the window which
2941 // is receiving the event
2942 if ( event
.GetEventObject() == this )
2944 wxValidator
* const validator
= GetValidator();
2945 if ( validator
&& validator
->ProcessEventHere(event
) )
2950 #endif // wxUSE_VALIDATORS
2952 return wxEvtHandler::TryBefore(event
);
2955 bool wxWindowBase::TryAfter(wxEvent
& event
)
2957 // carry on up the parent-child hierarchy if the propagation count hasn't
2959 if ( event
.ShouldPropagate() )
2961 // honour the requests to stop propagation at this window: this is
2962 // used by the dialogs, for example, to prevent processing the events
2963 // from the dialog controls in the parent frame which rarely, if ever,
2965 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2967 wxWindow
*parent
= GetParent();
2968 if ( parent
&& !parent
->IsBeingDeleted() )
2970 wxPropagateOnce
propagateOnce(event
);
2972 return parent
->GetEventHandler()->ProcessEvent(event
);
2977 return wxEvtHandler::TryAfter(event
);
2980 // ----------------------------------------------------------------------------
2981 // window relationships
2982 // ----------------------------------------------------------------------------
2984 wxWindow
*wxWindowBase::DoGetSibling(WindowOrder order
) const
2986 wxCHECK_MSG( GetParent(), NULL
,
2987 wxT("GetPrev/NextSibling() don't work for TLWs!") );
2989 wxWindowList
& siblings
= GetParent()->GetChildren();
2990 wxWindowList::compatibility_iterator i
= siblings
.Find((wxWindow
*)this);
2991 wxCHECK_MSG( i
, NULL
, wxT("window not a child of its parent?") );
2993 if ( order
== OrderBefore
)
2994 i
= i
->GetPrevious();
2998 return i
? i
->GetData() : NULL
;
3001 // ----------------------------------------------------------------------------
3002 // keyboard navigation
3003 // ----------------------------------------------------------------------------
3005 // Navigates in the specified direction inside this window
3006 bool wxWindowBase::DoNavigateIn(int flags
)
3008 #ifdef wxHAS_NATIVE_TAB_TRAVERSAL
3009 // native code doesn't process our wxNavigationKeyEvents anyhow
3012 #else // !wxHAS_NATIVE_TAB_TRAVERSAL
3013 wxNavigationKeyEvent eventNav
;
3014 wxWindow
*focused
= FindFocus();
3015 eventNav
.SetCurrentFocus(focused
);
3016 eventNav
.SetEventObject(focused
);
3017 eventNav
.SetFlags(flags
);
3018 return GetEventHandler()->ProcessEvent(eventNav
);
3019 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
3022 bool wxWindowBase::HandleAsNavigationKey(const wxKeyEvent
& event
)
3024 if ( event
.GetKeyCode() != WXK_TAB
)
3027 int flags
= wxNavigationKeyEvent::FromTab
;
3029 if ( event
.ShiftDown() )
3030 flags
|= wxNavigationKeyEvent::IsBackward
;
3032 flags
|= wxNavigationKeyEvent::IsForward
;
3034 if ( event
.ControlDown() )
3035 flags
|= wxNavigationKeyEvent::WinChange
;
3041 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, WindowOrder move
)
3043 // check that we're not a top level window
3044 wxCHECK_RET( GetParent(),
3045 wxT("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
3047 // detect the special case when we have nothing to do anyhow and when the
3048 // code below wouldn't work
3052 // find the target window in the siblings list
3053 wxWindowList
& siblings
= GetParent()->GetChildren();
3054 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
3055 wxCHECK_RET( i
, wxT("MoveBefore/AfterInTabOrder(): win is not a sibling") );
3057 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
3058 // can't just move the node around
3059 wxWindow
*self
= (wxWindow
*)this;
3060 siblings
.DeleteObject(self
);
3061 if ( move
== OrderAfter
)
3068 siblings
.Insert(i
, self
);
3070 else // OrderAfter and win was the last sibling
3072 siblings
.Append(self
);
3076 // ----------------------------------------------------------------------------
3078 // ----------------------------------------------------------------------------
3080 /*static*/ wxWindow
* wxWindowBase::FindFocus()
3082 wxWindowBase
*win
= DoFindFocus();
3083 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
3086 bool wxWindowBase::HasFocus() const
3088 wxWindowBase
*win
= DoFindFocus();
3089 return win
== this ||
3090 win
== wxConstCast(this, wxWindowBase
)->GetMainWindowOfCompositeControl();
3093 // ----------------------------------------------------------------------------
3095 // ----------------------------------------------------------------------------
3097 #if wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
3102 class DragAcceptFilesTarget
: public wxFileDropTarget
3105 DragAcceptFilesTarget(wxWindowBase
*win
) : m_win(win
) {}
3107 virtual bool OnDropFiles(wxCoord x
, wxCoord y
,
3108 const wxArrayString
& filenames
)
3110 wxDropFilesEvent
event(wxEVT_DROP_FILES
,
3112 wxCArrayString(filenames
).Release());
3113 event
.SetEventObject(m_win
);
3117 return m_win
->HandleWindowEvent(event
);
3121 wxWindowBase
* const m_win
;
3123 wxDECLARE_NO_COPY_CLASS(DragAcceptFilesTarget
);
3127 } // anonymous namespace
3129 // Generic version of DragAcceptFiles(). It works by installing a simple
3130 // wxFileDropTarget-to-EVT_DROP_FILES adaptor and therefore cannot be used
3131 // together with explicit SetDropTarget() calls.
3132 void wxWindowBase::DragAcceptFiles(bool accept
)
3136 wxASSERT_MSG( !GetDropTarget(),
3137 "cannot use DragAcceptFiles() and SetDropTarget() together" );
3138 SetDropTarget(new DragAcceptFilesTarget(this));
3142 SetDropTarget(NULL
);
3146 #endif // wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
3148 // ----------------------------------------------------------------------------
3150 // ----------------------------------------------------------------------------
3152 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
3154 while ( win
&& !win
->IsTopLevel() )
3155 win
= win
->GetParent();
3160 #if wxUSE_ACCESSIBILITY
3161 // ----------------------------------------------------------------------------
3162 // accessible object for windows
3163 // ----------------------------------------------------------------------------
3165 // Can return either a child object, or an integer
3166 // representing the child element, starting from 1.
3167 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
3169 wxASSERT( GetWindow() != NULL
);
3173 return wxACC_NOT_IMPLEMENTED
;
3176 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
3177 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
3179 wxASSERT( GetWindow() != NULL
);
3183 wxWindow
* win
= NULL
;
3190 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
3192 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
3199 rect
= win
->GetRect();
3200 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
3201 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
3205 return wxACC_NOT_IMPLEMENTED
;
3208 // Navigates from fromId to toId/toObject.
3209 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
3210 int* WXUNUSED(toId
), wxAccessible
** toObject
)
3212 wxASSERT( GetWindow() != NULL
);
3218 case wxNAVDIR_FIRSTCHILD
:
3220 if (GetWindow()->GetChildren().GetCount() == 0)
3222 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
3223 *toObject
= childWindow
->GetOrCreateAccessible();
3227 case wxNAVDIR_LASTCHILD
:
3229 if (GetWindow()->GetChildren().GetCount() == 0)
3231 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
3232 *toObject
= childWindow
->GetOrCreateAccessible();
3236 case wxNAVDIR_RIGHT
:
3240 wxWindowList::compatibility_iterator node
=
3241 wxWindowList::compatibility_iterator();
3244 // Can't navigate to sibling of this window
3245 // if we're a top-level window.
3246 if (!GetWindow()->GetParent())
3247 return wxACC_NOT_IMPLEMENTED
;
3249 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3253 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
3254 node
= GetWindow()->GetChildren().Item(fromId
-1);
3257 if (node
&& node
->GetNext())
3259 wxWindow
* nextWindow
= node
->GetNext()->GetData();
3260 *toObject
= nextWindow
->GetOrCreateAccessible();
3268 case wxNAVDIR_PREVIOUS
:
3270 wxWindowList::compatibility_iterator node
=
3271 wxWindowList::compatibility_iterator();
3274 // Can't navigate to sibling of this window
3275 // if we're a top-level window.
3276 if (!GetWindow()->GetParent())
3277 return wxACC_NOT_IMPLEMENTED
;
3279 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3283 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
3284 node
= GetWindow()->GetChildren().Item(fromId
-1);
3287 if (node
&& node
->GetPrevious())
3289 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
3290 *toObject
= previousWindow
->GetOrCreateAccessible();
3298 return wxACC_NOT_IMPLEMENTED
;
3301 // Gets the name of the specified object.
3302 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
3304 wxASSERT( GetWindow() != NULL
);
3310 // If a child, leave wxWidgets to call the function on the actual
3313 return wxACC_NOT_IMPLEMENTED
;
3315 // This will eventually be replaced by specialised
3316 // accessible classes, one for each kind of wxWidgets
3317 // control or window.
3319 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
3320 title
= ((wxButton
*) GetWindow())->GetLabel();
3323 title
= GetWindow()->GetName();
3331 return wxACC_NOT_IMPLEMENTED
;
3334 // Gets the number of children.
3335 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
3337 wxASSERT( GetWindow() != NULL
);
3341 *childId
= (int) GetWindow()->GetChildren().GetCount();
3345 // Gets the specified child (starting from 1).
3346 // If *child is NULL and return value is wxACC_OK,
3347 // this means that the child is a simple element and
3348 // not an accessible object.
3349 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
3351 wxASSERT( GetWindow() != NULL
);
3361 if (childId
> (int) GetWindow()->GetChildren().GetCount())
3364 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
3365 *child
= childWindow
->GetOrCreateAccessible();
3372 // Gets the parent, or NULL.
3373 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
3375 wxASSERT( GetWindow() != NULL
);
3379 wxWindow
* parentWindow
= GetWindow()->GetParent();
3387 *parent
= parentWindow
->GetOrCreateAccessible();
3395 // Performs the default action. childId is 0 (the action for this object)
3396 // or > 0 (the action for a child).
3397 // Return wxACC_NOT_SUPPORTED if there is no default action for this
3398 // window (e.g. an edit control).
3399 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
3401 wxASSERT( GetWindow() != NULL
);
3405 return wxACC_NOT_IMPLEMENTED
;
3408 // Gets the default action for this object (0) or > 0 (the action for a child).
3409 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
3410 // string if there is no action.
3411 // The retrieved string describes the action that is performed on an object,
3412 // not what the object does as a result. For example, a toolbar button that prints
3413 // a document has a default action of "Press" rather than "Prints the current document."
3414 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
3416 wxASSERT( GetWindow() != NULL
);
3420 return wxACC_NOT_IMPLEMENTED
;
3423 // Returns the description for this object or a child.
3424 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
3426 wxASSERT( GetWindow() != NULL
);
3430 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3436 return wxACC_NOT_IMPLEMENTED
;
3439 // Returns help text for this object or a child, similar to tooltip text.
3440 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
3442 wxASSERT( GetWindow() != NULL
);
3446 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3452 return wxACC_NOT_IMPLEMENTED
;
3455 // Returns the keyboard shortcut for this object or child.
3456 // Return e.g. ALT+K
3457 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
3459 wxASSERT( GetWindow() != NULL
);
3463 return wxACC_NOT_IMPLEMENTED
;
3466 // Returns a role constant.
3467 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
3469 wxASSERT( GetWindow() != NULL
);
3473 // If a child, leave wxWidgets to call the function on the actual
3476 return wxACC_NOT_IMPLEMENTED
;
3478 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3479 return wxACC_NOT_IMPLEMENTED
;
3481 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3482 return wxACC_NOT_IMPLEMENTED
;
3485 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3486 return wxACC_NOT_IMPLEMENTED
;
3489 //*role = wxROLE_SYSTEM_CLIENT;
3490 *role
= wxROLE_SYSTEM_CLIENT
;
3494 return wxACC_NOT_IMPLEMENTED
;
3498 // Returns a state constant.
3499 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
3501 wxASSERT( GetWindow() != NULL
);
3505 // If a child, leave wxWidgets to call the function on the actual
3508 return wxACC_NOT_IMPLEMENTED
;
3510 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3511 return wxACC_NOT_IMPLEMENTED
;
3514 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3515 return wxACC_NOT_IMPLEMENTED
;
3518 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3519 return wxACC_NOT_IMPLEMENTED
;
3526 return wxACC_NOT_IMPLEMENTED
;
3530 // Returns a localized string representing the value for the object
3532 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3534 wxASSERT( GetWindow() != NULL
);
3538 return wxACC_NOT_IMPLEMENTED
;
3541 // Selects the object or child.
3542 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3544 wxASSERT( GetWindow() != NULL
);
3548 return wxACC_NOT_IMPLEMENTED
;
3551 // Gets the window with the keyboard focus.
3552 // If childId is 0 and child is NULL, no object in
3553 // this subhierarchy has the focus.
3554 // If this object has the focus, child should be 'this'.
3555 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3557 wxASSERT( GetWindow() != NULL
);
3561 return wxACC_NOT_IMPLEMENTED
;
3565 // Gets a variant representing the selected children
3567 // Acceptable values:
3568 // - a null variant (IsNull() returns true)
3569 // - a list variant (GetType() == wxT("list")
3570 // - an integer representing the selected child element,
3571 // or 0 if this object is selected (GetType() == wxT("long")
3572 // - a "void*" pointer to a wxAccessible child object
3573 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3575 wxASSERT( GetWindow() != NULL
);
3579 return wxACC_NOT_IMPLEMENTED
;
3581 #endif // wxUSE_VARIANT
3583 #endif // wxUSE_ACCESSIBILITY
3585 // ----------------------------------------------------------------------------
3587 // ----------------------------------------------------------------------------
3590 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3592 wxCoord widthTotal
) const
3594 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3596 x
= widthTotal
- x
- width
;