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
),
216 const wxSize
& WXUNUSED(size
),
218 const wxValidator
& wxVALIDATOR_PARAM(validator
),
219 const wxString
& name
)
221 // ids are limited to 16 bits under MSW so if you care about portability,
222 // it's not a good idea to use ids out of this range (and negative ids are
223 // reserved for wxWidgets own usage)
224 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767) ||
225 (id
>= wxID_AUTO_LOWEST
&& id
<= wxID_AUTO_HIGHEST
),
226 wxT("invalid id value") );
228 // generate a new id if the user doesn't care about it
229 if ( id
== wxID_ANY
)
231 m_windowId
= NewControlId();
233 else // valid id specified
238 // don't use SetWindowStyleFlag() here, this function should only be called
239 // to change the flag after creation as it tries to reflect the changes in
240 // flags by updating the window dynamically and we don't need this here
241 m_windowStyle
= style
;
247 SetValidator(validator
);
248 #endif // wxUSE_VALIDATORS
250 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
251 // have it too - like this it's possible to set it only in the top level
252 // dialog/frame and all children will inherit it by defult
253 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
255 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
261 bool wxWindowBase::ToggleWindowStyle(int flag
)
263 wxASSERT_MSG( flag
, wxT("flags with 0 value can't be toggled") );
266 long style
= GetWindowStyleFlag();
272 else // currently off
278 SetWindowStyleFlag(style
);
283 // ----------------------------------------------------------------------------
285 // ----------------------------------------------------------------------------
288 wxWindowBase::~wxWindowBase()
290 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
292 // FIXME if these 2 cases result from programming errors in the user code
293 // we should probably assert here instead of silently fixing them
295 // Just in case the window has been Closed, but we're then deleting
296 // immediately: don't leave dangling pointers.
297 wxPendingDelete
.DeleteObject(this);
299 // Just in case we've loaded a top-level window via LoadNativeDialog but
300 // we weren't a dialog class
301 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
304 // The associated popup menu can still be alive, disassociate from it in
306 if ( wxCurrentPopupMenu
&& wxCurrentPopupMenu
->GetInvokingWindow() == this )
307 wxCurrentPopupMenu
->SetInvokingWindow(NULL
);
308 #endif // wxUSE_MENUS
310 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
312 // notify the parent about this window destruction
314 m_parent
->RemoveChild(this);
318 #endif // wxUSE_CARET
321 delete m_windowValidator
;
322 #endif // wxUSE_VALIDATORS
324 #if wxUSE_CONSTRAINTS
325 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
326 // at deleted windows as they delete themselves.
327 DeleteRelatedConstraints();
331 // This removes any dangling pointers to this window in other windows'
332 // constraintsInvolvedIn lists.
333 UnsetConstraints(m_constraints
);
334 delete m_constraints
;
335 m_constraints
= NULL
;
337 #endif // wxUSE_CONSTRAINTS
339 if ( m_containingSizer
)
340 m_containingSizer
->Detach( (wxWindow
*)this );
342 delete m_windowSizer
;
344 #if wxUSE_DRAG_AND_DROP
346 #endif // wxUSE_DRAG_AND_DROP
350 #endif // wxUSE_TOOLTIPS
352 #if wxUSE_ACCESSIBILITY
357 // NB: this has to be called unconditionally, because we don't know
358 // whether this window has associated help text or not
359 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
361 helpProvider
->RemoveHelp(this);
365 bool wxWindowBase::IsBeingDeleted() const
367 return m_isBeingDeleted
||
368 (!IsTopLevel() && m_parent
&& m_parent
->IsBeingDeleted());
371 void wxWindowBase::SendDestroyEvent()
373 if ( m_isBeingDeleted
)
375 // we could have been already called from a more derived class dtor,
376 // e.g. ~wxTLW calls us and so does ~wxWindow and the latter call
377 // should be simply ignored
381 m_isBeingDeleted
= true;
383 wxWindowDestroyEvent event
;
384 event
.SetEventObject(this);
385 event
.SetId(GetId());
386 GetEventHandler()->ProcessEvent(event
);
389 bool wxWindowBase::Destroy()
398 bool wxWindowBase::Close(bool force
)
400 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
401 event
.SetEventObject(this);
402 event
.SetCanVeto(!force
);
404 // return false if window wasn't closed because the application vetoed the
406 return HandleWindowEvent(event
) && !event
.GetVeto();
409 bool wxWindowBase::DestroyChildren()
411 wxWindowList::compatibility_iterator node
;
414 // we iterate until the list becomes empty
415 node
= GetChildren().GetFirst();
419 wxWindow
*child
= node
->GetData();
421 // note that we really want to delete it immediately so don't call the
422 // possible overridden Destroy() version which might not delete the
423 // child immediately resulting in problems with our (top level) child
424 // outliving its parent
425 child
->wxWindowBase::Destroy();
427 wxASSERT_MSG( !GetChildren().Find(child
),
428 wxT("child didn't remove itself using RemoveChild()") );
434 // ----------------------------------------------------------------------------
435 // size/position related methods
436 // ----------------------------------------------------------------------------
438 // centre the window with respect to its parent in either (or both) directions
439 void wxWindowBase::DoCentre(int dir
)
441 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
442 wxT("this method only implements centering child windows") );
444 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
447 // fits the window around the children
448 void wxWindowBase::Fit()
450 if ( !GetChildren().empty() )
452 SetSize(GetBestSize());
454 //else: do nothing if we have no children
457 // fits virtual size (ie. scrolled area etc.) around children
458 void wxWindowBase::FitInside()
460 if ( GetChildren().GetCount() > 0 )
462 SetVirtualSize( GetBestVirtualSize() );
466 // On Mac, scrollbars are explicitly children.
467 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
468 static bool wxHasRealChildren(const wxWindowBase
* win
)
470 int realChildCount
= 0;
472 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
474 node
= node
->GetNext() )
476 wxWindow
*win
= node
->GetData();
477 if ( !win
->IsTopLevel() && win
->IsShown()
479 && !win
->IsKindOf(CLASSINFO(wxScrollBar
))
484 return (realChildCount
> 0);
488 void wxWindowBase::InvalidateBestSize()
490 m_bestSizeCache
= wxDefaultSize
;
492 // parent's best size calculation may depend on its children's
493 // as long as child window we are in is not top level window itself
494 // (because the TLW size is never resized automatically)
495 // so let's invalidate it as well to be safe:
496 if (m_parent
&& !IsTopLevel())
497 m_parent
->InvalidateBestSize();
500 // return the size best suited for the current window
501 wxSize
wxWindowBase::DoGetBestSize() const
507 best
= m_windowSizer
->GetMinSize();
509 #if wxUSE_CONSTRAINTS
510 else if ( m_constraints
)
512 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
514 // our minimal acceptable size is such that all our windows fit inside
518 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
520 node
= node
->GetNext() )
522 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
525 // it's not normal that we have an unconstrained child, but
526 // what can we do about it?
530 int x
= c
->right
.GetValue(),
531 y
= c
->bottom
.GetValue();
539 // TODO: we must calculate the overlaps somehow, otherwise we
540 // will never return a size bigger than the current one :-(
543 best
= wxSize(maxX
, maxY
);
545 #endif // wxUSE_CONSTRAINTS
546 else if ( !GetChildren().empty()
547 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
548 && wxHasRealChildren(this)
552 // our minimal acceptable size is such that all our visible child
553 // windows fit inside
557 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
559 node
= node
->GetNext() )
561 wxWindow
*win
= node
->GetData();
562 if ( win
->IsTopLevel()
565 || wxDynamicCast(win
, wxStatusBar
)
566 #endif // wxUSE_STATUSBAR
569 // dialogs and frames lie in different top level windows -
570 // don't deal with them here; as for the status bars, they
571 // don't lie in the client area at all
576 win
->GetPosition(&wx
, &wy
);
578 // if the window hadn't been positioned yet, assume that it is in
580 if ( wx
== wxDefaultCoord
)
582 if ( wy
== wxDefaultCoord
)
585 win
->GetSize(&ww
, &wh
);
586 if ( wx
+ ww
> maxX
)
588 if ( wy
+ wh
> maxY
)
592 best
= wxSize(maxX
, maxY
);
594 else // ! has children
596 // for a generic window there is no natural best size so, if the
597 // minimal size is not set, use the current size but take care to
598 // remember it as minimal size for the next time because our best size
599 // should be constant: otherwise we could get into a situation when the
600 // window is initially at some size, then expanded to a larger size and
601 // then, when the containing window is shrunk back (because our initial
602 // best size had been used for computing the parent min size), we can't
603 // be shrunk back any more because our best size is now bigger
604 wxSize size
= GetMinSize();
605 if ( !size
.IsFullySpecified() )
607 size
.SetDefaults(GetSize());
608 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
611 // return as-is, unadjusted by the client size difference.
615 // Add any difference between size and client size
616 wxSize diff
= GetSize() - GetClientSize();
617 best
.x
+= wxMax(0, diff
.x
);
618 best
.y
+= wxMax(0, diff
.y
);
623 // helper of GetWindowBorderSize(): as many ports don't implement support for
624 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
625 // fallbacks in this case
626 static int wxGetMetricOrDefault(wxSystemMetric what
, const wxWindowBase
* win
)
628 int rc
= wxSystemSettings::GetMetric(
629 what
, static_cast<wxWindow
*>(const_cast<wxWindowBase
*>(win
)));
636 // 2D border is by default 1 pixel wide
642 // 3D borders are by default 2 pixels
647 wxFAIL_MSG( wxT("unexpected wxGetMetricOrDefault() argument") );
655 wxSize
wxWindowBase::GetWindowBorderSize() const
659 switch ( GetBorder() )
662 // nothing to do, size is already (0, 0)
665 case wxBORDER_SIMPLE
:
666 case wxBORDER_STATIC
:
667 size
.x
= wxGetMetricOrDefault(wxSYS_BORDER_X
, this);
668 size
.y
= wxGetMetricOrDefault(wxSYS_BORDER_Y
, this);
671 case wxBORDER_SUNKEN
:
672 case wxBORDER_RAISED
:
673 size
.x
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X
, this),
674 wxGetMetricOrDefault(wxSYS_BORDER_X
, this));
675 size
.y
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y
, this),
676 wxGetMetricOrDefault(wxSYS_BORDER_Y
, this));
679 case wxBORDER_DOUBLE
:
680 size
.x
= wxGetMetricOrDefault(wxSYS_EDGE_X
, this) +
681 wxGetMetricOrDefault(wxSYS_BORDER_X
, this);
682 size
.y
= wxGetMetricOrDefault(wxSYS_EDGE_Y
, this) +
683 wxGetMetricOrDefault(wxSYS_BORDER_Y
, this);
687 wxFAIL_MSG(wxT("Unknown border style."));
691 // we have borders on both sides
695 wxSize
wxWindowBase::GetEffectiveMinSize() const
697 // merge the best size with the min size, giving priority to the min size
698 wxSize min
= GetMinSize();
700 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
702 wxSize best
= GetBestSize();
703 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
704 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
710 wxSize
wxWindowBase::GetBestSize() const
712 if ( !m_windowSizer
&& m_bestSizeCache
.IsFullySpecified() )
713 return m_bestSizeCache
;
715 // call DoGetBestClientSize() first, if a derived class overrides it wants
717 wxSize size
= DoGetBestClientSize();
718 if ( size
!= wxDefaultSize
)
720 size
+= DoGetBorderSize();
726 return DoGetBestSize();
729 void wxWindowBase::SetMinSize(const wxSize
& minSize
)
731 m_minWidth
= minSize
.x
;
732 m_minHeight
= minSize
.y
;
735 void wxWindowBase::SetMaxSize(const wxSize
& maxSize
)
737 m_maxWidth
= maxSize
.x
;
738 m_maxHeight
= maxSize
.y
;
741 void wxWindowBase::SetInitialSize(const wxSize
& size
)
743 // Set the min size to the size passed in. This will usually either be
744 // wxDefaultSize or the size passed to this window's ctor/Create function.
747 // Merge the size with the best size if needed
748 wxSize best
= GetEffectiveMinSize();
750 // If the current size doesn't match then change it
751 if (GetSize() != best
)
756 // by default the origin is not shifted
757 wxPoint
wxWindowBase::GetClientAreaOrigin() const
762 wxSize
wxWindowBase::ClientToWindowSize(const wxSize
& size
) const
764 const wxSize
diff(GetSize() - GetClientSize());
766 return wxSize(size
.x
== -1 ? -1 : size
.x
+ diff
.x
,
767 size
.y
== -1 ? -1 : size
.y
+ diff
.y
);
770 wxSize
wxWindowBase::WindowToClientSize(const wxSize
& size
) const
772 const wxSize
diff(GetSize() - GetClientSize());
774 return wxSize(size
.x
== -1 ? -1 : size
.x
- diff
.x
,
775 size
.y
== -1 ? -1 : size
.y
- diff
.y
);
778 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
780 if ( m_windowVariant
!= variant
)
782 m_windowVariant
= variant
;
784 DoSetWindowVariant(variant
);
788 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
790 // adjust the font height to correspond to our new variant (notice that
791 // we're only called if something really changed)
792 wxFont font
= GetFont();
793 int size
= font
.GetPointSize();
796 case wxWINDOW_VARIANT_NORMAL
:
799 case wxWINDOW_VARIANT_SMALL
:
804 case wxWINDOW_VARIANT_MINI
:
809 case wxWINDOW_VARIANT_LARGE
:
815 wxFAIL_MSG(wxT("unexpected window variant"));
819 font
.SetPointSize(size
);
823 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
825 int WXUNUSED(incW
), int WXUNUSED(incH
) )
827 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
828 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
829 wxT("min width/height must be less than max width/height!") );
838 #if WXWIN_COMPATIBILITY_2_8
839 void wxWindowBase::SetVirtualSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
),
840 int WXUNUSED(maxW
), int WXUNUSED(maxH
))
844 void wxWindowBase::SetVirtualSizeHints(const wxSize
& WXUNUSED(minsize
),
845 const wxSize
& WXUNUSED(maxsize
))
848 #endif // WXWIN_COMPATIBILITY_2_8
850 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
852 m_virtualSize
= wxSize(x
, y
);
855 wxSize
wxWindowBase::DoGetVirtualSize() const
857 // we should use the entire client area so if it is greater than our
858 // virtual size, expand it to fit (otherwise if the window is big enough we
859 // wouldn't be using parts of it)
860 wxSize size
= GetClientSize();
861 if ( m_virtualSize
.x
> size
.x
)
862 size
.x
= m_virtualSize
.x
;
864 if ( m_virtualSize
.y
>= size
.y
)
865 size
.y
= m_virtualSize
.y
;
870 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
872 // screen position is the same as (0, 0) in client coords for non TLWs (and
873 // TLWs override this method)
879 ClientToScreen(x
, y
);
882 void wxWindowBase::SendSizeEvent(int flags
)
884 wxSizeEvent
event(GetSize(), GetId());
885 event
.SetEventObject(this);
886 if ( flags
& wxSEND_EVENT_POST
)
887 wxPostEvent(this, event
);
889 HandleWindowEvent(event
);
892 void wxWindowBase::SendSizeEventToParent(int flags
)
894 wxWindow
* const parent
= GetParent();
895 if ( parent
&& !parent
->IsBeingDeleted() )
896 parent
->SendSizeEvent(flags
);
899 bool wxWindowBase::HasScrollbar(int orient
) const
901 // if scrolling in the given direction is disabled, we can't have the
902 // corresponding scrollbar no matter what
903 if ( !CanScroll(orient
) )
906 const wxSize sizeVirt
= GetVirtualSize();
907 const wxSize sizeClient
= GetClientSize();
909 return orient
== wxHORIZONTAL
? sizeVirt
.x
> sizeClient
.x
910 : sizeVirt
.y
> sizeClient
.y
;
913 // ----------------------------------------------------------------------------
914 // show/hide/enable/disable the window
915 // ----------------------------------------------------------------------------
917 bool wxWindowBase::Show(bool show
)
919 if ( show
!= m_isShown
)
931 bool wxWindowBase::IsEnabled() const
933 return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
936 void wxWindowBase::NotifyWindowOnEnableChange(bool enabled
)
938 #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
940 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
944 // If we are top-level then the logic doesn't apply - otherwise
945 // showing a modal dialog would result in total greying out (and ungreying
946 // out later) of everything which would be really ugly
950 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
952 node
= node
->GetNext() )
954 wxWindowBase
* const child
= node
->GetData();
955 if ( !child
->IsTopLevel() && child
->IsThisEnabled() )
956 child
->NotifyWindowOnEnableChange(enabled
);
960 bool wxWindowBase::Enable(bool enable
)
962 if ( enable
== IsThisEnabled() )
965 m_isEnabled
= enable
;
967 #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
969 #else // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
970 wxWindowBase
* const parent
= GetParent();
971 if( !IsTopLevel() && parent
&& !parent
->IsEnabled() )
975 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
977 NotifyWindowOnEnableChange(enable
);
982 bool wxWindowBase::IsShownOnScreen() const
984 // A window is shown on screen if it itself is shown and so are all its
985 // parents. But if a window is toplevel one, then its always visible on
986 // screen if IsShown() returns true, even if it has a hidden parent.
988 (IsTopLevel() || GetParent() == NULL
|| GetParent()->IsShownOnScreen());
991 // ----------------------------------------------------------------------------
993 // ----------------------------------------------------------------------------
995 bool wxWindowBase::IsTopLevel() const
1000 // ----------------------------------------------------------------------------
1002 // ----------------------------------------------------------------------------
1004 void wxWindowBase::Freeze()
1006 if ( !m_freezeCount
++ )
1008 // physically freeze this window:
1011 // and recursively freeze all children:
1012 for ( wxWindowList::iterator i
= GetChildren().begin();
1013 i
!= GetChildren().end(); ++i
)
1015 wxWindow
*child
= *i
;
1016 if ( child
->IsTopLevel() )
1024 void wxWindowBase::Thaw()
1026 wxASSERT_MSG( m_freezeCount
, "Thaw() without matching Freeze()" );
1028 if ( !--m_freezeCount
)
1030 // recursively thaw all children:
1031 for ( wxWindowList::iterator i
= GetChildren().begin();
1032 i
!= GetChildren().end(); ++i
)
1034 wxWindow
*child
= *i
;
1035 if ( child
->IsTopLevel() )
1041 // physically thaw this window:
1046 // ----------------------------------------------------------------------------
1047 // reparenting the window
1048 // ----------------------------------------------------------------------------
1050 void wxWindowBase::AddChild(wxWindowBase
*child
)
1052 wxCHECK_RET( child
, wxT("can't add a NULL child") );
1054 // this should never happen and it will lead to a crash later if it does
1055 // because RemoveChild() will remove only one node from the children list
1056 // and the other(s) one(s) will be left with dangling pointers in them
1057 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), wxT("AddChild() called twice") );
1059 GetChildren().Append((wxWindow
*)child
);
1060 child
->SetParent(this);
1062 // adding a child while frozen will assert when thawed, so freeze it as if
1063 // it had been already present when we were frozen
1064 if ( IsFrozen() && !child
->IsTopLevel() )
1068 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
1070 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
1072 // removing a child while frozen may result in permanently frozen window
1073 // if used e.g. from Reparent(), so thaw it
1075 // NB: IsTopLevel() doesn't return true any more when a TLW child is being
1076 // removed from its ~wxWindowBase, so check for IsBeingDeleted() too
1077 if ( IsFrozen() && !child
->IsBeingDeleted() && !child
->IsTopLevel() )
1080 GetChildren().DeleteObject((wxWindow
*)child
);
1081 child
->SetParent(NULL
);
1084 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
1086 wxWindow
*oldParent
= GetParent();
1087 if ( newParent
== oldParent
)
1093 const bool oldEnabledState
= IsEnabled();
1095 // unlink this window from the existing parent.
1098 oldParent
->RemoveChild(this);
1102 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
1105 // add it to the new one
1108 newParent
->AddChild(this);
1112 wxTopLevelWindows
.Append((wxWindow
*)this);
1115 // We need to notify window (and its subwindows) if by changing the parent
1116 // we also change our enabled/disabled status.
1117 const bool newEnabledState
= IsEnabled();
1118 if ( newEnabledState
!= oldEnabledState
)
1120 NotifyWindowOnEnableChange(newEnabledState
);
1126 // ----------------------------------------------------------------------------
1127 // event handler stuff
1128 // ----------------------------------------------------------------------------
1130 void wxWindowBase::SetEventHandler(wxEvtHandler
*handler
)
1132 wxCHECK_RET(handler
!= NULL
, "SetEventHandler(NULL) called");
1134 m_eventHandler
= handler
;
1137 void wxWindowBase::SetNextHandler(wxEvtHandler
*WXUNUSED(handler
))
1139 // disable wxEvtHandler chain mechanism for wxWindows:
1140 // wxWindow uses its own stack mechanism which doesn't mix well with wxEvtHandler's one
1142 wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
1144 void wxWindowBase::SetPreviousHandler(wxEvtHandler
*WXUNUSED(handler
))
1146 // we can't simply wxFAIL here as in SetNextHandler: in fact the last
1147 // handler of our stack when is destroyed will be Unlink()ed and thus
1148 // will call this function to update the pointer of this window...
1150 //wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
1153 void wxWindowBase::PushEventHandler(wxEvtHandler
*handlerToPush
)
1155 wxCHECK_RET( handlerToPush
!= NULL
, "PushEventHandler(NULL) called" );
1157 // the new handler is going to be part of the wxWindow stack of event handlers:
1158 // it can't be part also of an event handler double-linked chain:
1159 wxASSERT_MSG(handlerToPush
->IsUnlinked(),
1160 "The handler being pushed in the wxWindow stack shouldn't be part of "
1161 "a wxEvtHandler chain; call Unlink() on it first");
1163 wxEvtHandler
*handlerOld
= GetEventHandler();
1164 wxCHECK_RET( handlerOld
, "an old event handler is NULL?" );
1166 // now use wxEvtHandler double-linked list to implement a stack:
1167 handlerToPush
->SetNextHandler(handlerOld
);
1169 if (handlerOld
!= this)
1170 handlerOld
->SetPreviousHandler(handlerToPush
);
1172 SetEventHandler(handlerToPush
);
1175 // final checks of the operations done above:
1176 wxASSERT_MSG( handlerToPush
->GetPreviousHandler() == NULL
,
1177 "the first handler of the wxWindow stack should "
1178 "have no previous handlers set" );
1179 wxASSERT_MSG( handlerToPush
->GetNextHandler() != NULL
,
1180 "the first handler of the wxWindow stack should "
1181 "have non-NULL next handler" );
1183 wxEvtHandler
* pLast
= handlerToPush
;
1184 while ( pLast
&& pLast
!= this )
1185 pLast
= pLast
->GetNextHandler();
1186 wxASSERT_MSG( pLast
->GetNextHandler() == NULL
,
1187 "the last handler of the wxWindow stack should "
1188 "have this window as next handler" );
1189 #endif // wxDEBUG_LEVEL
1192 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
1194 // we need to pop the wxWindow stack, i.e. we need to remove the first handler
1196 wxEvtHandler
*firstHandler
= GetEventHandler();
1197 wxCHECK_MSG( firstHandler
!= NULL
, NULL
, "wxWindow cannot have a NULL event handler" );
1198 wxCHECK_MSG( firstHandler
!= this, NULL
, "cannot pop the wxWindow itself" );
1199 wxCHECK_MSG( firstHandler
->GetPreviousHandler() == NULL
, NULL
,
1200 "the first handler of the wxWindow stack should have no previous handlers set" );
1202 wxEvtHandler
*secondHandler
= firstHandler
->GetNextHandler();
1203 wxCHECK_MSG( secondHandler
!= NULL
, NULL
,
1204 "the first handler of the wxWindow stack should have non-NULL next handler" );
1206 firstHandler
->SetNextHandler(NULL
);
1207 secondHandler
->SetPreviousHandler(NULL
);
1209 // now firstHandler is completely unlinked; set secondHandler as the new window event handler
1210 SetEventHandler(secondHandler
);
1212 if ( deleteHandler
)
1214 delete firstHandler
;
1215 firstHandler
= NULL
;
1218 return firstHandler
;
1221 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handlerToRemove
)
1223 wxCHECK_MSG( handlerToRemove
!= NULL
, false, "RemoveEventHandler(NULL) called" );
1224 wxCHECK_MSG( handlerToRemove
!= this, false, "Cannot remove the window itself" );
1226 if (handlerToRemove
== GetEventHandler())
1228 // removing the first event handler is equivalent to "popping" the stack
1229 PopEventHandler(false);
1233 // NOTE: the wxWindow event handler list is always terminated with "this" handler
1234 wxEvtHandler
*handlerCur
= GetEventHandler()->GetNextHandler();
1235 while ( handlerCur
!= this )
1237 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
1239 if ( handlerCur
== handlerToRemove
)
1241 handlerCur
->Unlink();
1243 wxASSERT_MSG( handlerCur
!= GetEventHandler(),
1244 "the case Remove == Pop should was already handled" );
1248 handlerCur
= handlerNext
;
1251 wxFAIL_MSG( wxT("where has the event handler gone?") );
1256 bool wxWindowBase::HandleWindowEvent(wxEvent
& event
) const
1258 // SafelyProcessEvent() will handle exceptions nicely
1259 return GetEventHandler()->SafelyProcessEvent(event
);
1262 // ----------------------------------------------------------------------------
1263 // colours, fonts &c
1264 // ----------------------------------------------------------------------------
1266 void wxWindowBase::InheritAttributes()
1268 const wxWindowBase
* const parent
= GetParent();
1272 // we only inherit attributes which had been explicitly set for the parent
1273 // which ensures that this only happens if the user really wants it and
1274 // not by default which wouldn't make any sense in modern GUIs where the
1275 // controls don't all use the same fonts (nor colours)
1276 if ( parent
->m_inheritFont
&& !m_hasFont
)
1277 SetFont(parent
->GetFont());
1279 // in addition, there is a possibility to explicitly forbid inheriting
1280 // colours at each class level by overriding ShouldInheritColours()
1281 if ( ShouldInheritColours() )
1283 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1284 SetForegroundColour(parent
->GetForegroundColour());
1286 // inheriting (solid) background colour is wrong as it totally breaks
1287 // any kind of themed backgrounds
1289 // instead, the controls should use the same background as their parent
1290 // (ideally by not drawing it at all)
1292 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1293 SetBackgroundColour(parent
->GetBackgroundColour());
1298 /* static */ wxVisualAttributes
1299 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1301 // it is important to return valid values for all attributes from here,
1302 // GetXXX() below rely on this
1303 wxVisualAttributes attrs
;
1304 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1305 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1307 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1308 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1309 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1310 // colour on other platforms.
1312 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1313 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1315 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1320 wxColour
wxWindowBase::GetBackgroundColour() const
1322 if ( !m_backgroundColour
.IsOk() )
1324 wxASSERT_MSG( !m_hasBgCol
, wxT("we have invalid explicit bg colour?") );
1326 // get our default background colour
1327 wxColour colBg
= GetDefaultAttributes().colBg
;
1329 // we must return some valid colour to avoid redoing this every time
1330 // and also to avoid surprizing the applications written for older
1331 // wxWidgets versions where GetBackgroundColour() always returned
1332 // something -- so give them something even if it doesn't make sense
1333 // for this window (e.g. it has a themed background)
1335 colBg
= GetClassDefaultAttributes().colBg
;
1340 return m_backgroundColour
;
1343 wxColour
wxWindowBase::GetForegroundColour() const
1345 // logic is the same as above
1346 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1348 wxColour colFg
= GetDefaultAttributes().colFg
;
1350 if ( !colFg
.IsOk() )
1351 colFg
= GetClassDefaultAttributes().colFg
;
1356 return m_foregroundColour
;
1359 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1361 if ( colour
== m_backgroundColour
)
1364 m_hasBgCol
= colour
.IsOk();
1366 m_inheritBgCol
= m_hasBgCol
;
1367 m_backgroundColour
= colour
;
1368 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1372 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1374 if (colour
== m_foregroundColour
)
1377 m_hasFgCol
= colour
.IsOk();
1378 m_inheritFgCol
= m_hasFgCol
;
1379 m_foregroundColour
= colour
;
1380 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1384 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1386 // setting an invalid cursor is ok, it means that we don't have any special
1388 if ( m_cursor
.IsSameAs(cursor
) )
1399 wxFont
wxWindowBase::GetFont() const
1401 // logic is the same as in GetBackgroundColour()
1402 if ( !m_font
.IsOk() )
1404 wxASSERT_MSG( !m_hasFont
, wxT("we have invalid explicit font?") );
1406 wxFont font
= GetDefaultAttributes().font
;
1408 font
= GetClassDefaultAttributes().font
;
1416 bool wxWindowBase::SetFont(const wxFont
& font
)
1418 if ( font
== m_font
)
1425 m_hasFont
= font
.IsOk();
1426 m_inheritFont
= m_hasFont
;
1428 InvalidateBestSize();
1435 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1437 m_hasCustomPalette
= true;
1440 // VZ: can anyone explain me what do we do here?
1441 wxWindowDC
d((wxWindow
*) this);
1445 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1447 wxWindow
*win
= (wxWindow
*)this;
1448 while ( win
&& !win
->HasCustomPalette() )
1450 win
= win
->GetParent();
1456 #endif // wxUSE_PALETTE
1459 void wxWindowBase::SetCaret(wxCaret
*caret
)
1470 wxASSERT_MSG( m_caret
->GetWindow() == this,
1471 wxT("caret should be created associated to this window") );
1474 #endif // wxUSE_CARET
1476 #if wxUSE_VALIDATORS
1477 // ----------------------------------------------------------------------------
1479 // ----------------------------------------------------------------------------
1481 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1483 if ( m_windowValidator
)
1484 delete m_windowValidator
;
1486 m_windowValidator
= (wxValidator
*)validator
.Clone();
1488 if ( m_windowValidator
)
1489 m_windowValidator
->SetWindow(this);
1491 #endif // wxUSE_VALIDATORS
1493 // ----------------------------------------------------------------------------
1494 // update region stuff
1495 // ----------------------------------------------------------------------------
1497 wxRect
wxWindowBase::GetUpdateClientRect() const
1499 wxRegion rgnUpdate
= GetUpdateRegion();
1500 rgnUpdate
.Intersect(GetClientRect());
1501 wxRect rectUpdate
= rgnUpdate
.GetBox();
1502 wxPoint ptOrigin
= GetClientAreaOrigin();
1503 rectUpdate
.x
-= ptOrigin
.x
;
1504 rectUpdate
.y
-= ptOrigin
.y
;
1509 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1511 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1514 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1516 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1519 void wxWindowBase::ClearBackground()
1521 // wxGTK uses its own version, no need to add never used code
1523 wxClientDC
dc((wxWindow
*)this);
1524 wxBrush
brush(GetBackgroundColour(), wxBRUSHSTYLE_SOLID
);
1525 dc
.SetBackground(brush
);
1530 // ----------------------------------------------------------------------------
1531 // find child window by id or name
1532 // ----------------------------------------------------------------------------
1534 wxWindow
*wxWindowBase::FindWindow(long id
) const
1536 if ( id
== m_windowId
)
1537 return (wxWindow
*)this;
1539 wxWindowBase
*res
= NULL
;
1540 wxWindowList::compatibility_iterator node
;
1541 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1543 wxWindowBase
*child
= node
->GetData();
1544 res
= child
->FindWindow( id
);
1547 return (wxWindow
*)res
;
1550 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1552 if ( name
== m_windowName
)
1553 return (wxWindow
*)this;
1555 wxWindowBase
*res
= NULL
;
1556 wxWindowList::compatibility_iterator node
;
1557 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1559 wxWindow
*child
= node
->GetData();
1560 res
= child
->FindWindow(name
);
1563 return (wxWindow
*)res
;
1567 // find any window by id or name or label: If parent is non-NULL, look through
1568 // children for a label or title matching the specified string. If NULL, look
1569 // through all top-level windows.
1571 // to avoid duplicating code we reuse the same helper function but with
1572 // different comparators
1574 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1575 const wxString
& label
, long id
);
1578 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1581 return win
->GetLabel() == label
;
1585 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1588 return win
->GetName() == label
;
1592 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1595 return win
->GetId() == id
;
1598 // recursive helper for the FindWindowByXXX() functions
1600 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1601 const wxString
& label
,
1603 wxFindWindowCmp cmp
)
1607 // see if this is the one we're looking for
1608 if ( (*cmp
)(parent
, label
, id
) )
1609 return (wxWindow
*)parent
;
1611 // It wasn't, so check all its children
1612 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1614 node
= node
->GetNext() )
1616 // recursively check each child
1617 wxWindow
*win
= (wxWindow
*)node
->GetData();
1618 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1628 // helper for FindWindowByXXX()
1630 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1631 const wxString
& label
,
1633 wxFindWindowCmp cmp
)
1637 // just check parent and all its children
1638 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1641 // start at very top of wx's windows
1642 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1644 node
= node
->GetNext() )
1646 // recursively check each window & its children
1647 wxWindow
*win
= node
->GetData();
1648 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1658 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1660 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1665 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1667 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1671 // fall back to the label
1672 win
= FindWindowByLabel(title
, parent
);
1680 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1682 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1685 // ----------------------------------------------------------------------------
1686 // dialog oriented functions
1687 // ----------------------------------------------------------------------------
1689 void wxWindowBase::MakeModal(bool modal
)
1691 // Disable all other windows
1694 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1697 wxWindow
*win
= node
->GetData();
1699 win
->Enable(!modal
);
1701 node
= node
->GetNext();
1706 bool wxWindowBase::Validate()
1708 #if wxUSE_VALIDATORS
1709 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1711 wxWindowList::compatibility_iterator node
;
1712 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1714 wxWindowBase
*child
= node
->GetData();
1715 wxValidator
*validator
= child
->GetValidator();
1716 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1721 if ( recurse
&& !child
->Validate() )
1726 #endif // wxUSE_VALIDATORS
1731 bool wxWindowBase::TransferDataToWindow()
1733 #if wxUSE_VALIDATORS
1734 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1736 wxWindowList::compatibility_iterator node
;
1737 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1739 wxWindowBase
*child
= node
->GetData();
1740 wxValidator
*validator
= child
->GetValidator();
1741 if ( validator
&& !validator
->TransferToWindow() )
1743 wxLogWarning(_("Could not transfer data to window"));
1745 wxLog::FlushActive();
1753 if ( !child
->TransferDataToWindow() )
1755 // warning already given
1760 #endif // wxUSE_VALIDATORS
1765 bool wxWindowBase::TransferDataFromWindow()
1767 #if wxUSE_VALIDATORS
1768 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1770 wxWindowList::compatibility_iterator node
;
1771 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1773 wxWindow
*child
= node
->GetData();
1774 wxValidator
*validator
= child
->GetValidator();
1775 if ( validator
&& !validator
->TransferFromWindow() )
1777 // nop warning here because the application is supposed to give
1778 // one itself - we don't know here what might have gone wrongly
1785 if ( !child
->TransferDataFromWindow() )
1787 // warning already given
1792 #endif // wxUSE_VALIDATORS
1797 void wxWindowBase::InitDialog()
1799 wxInitDialogEvent
event(GetId());
1800 event
.SetEventObject( this );
1801 GetEventHandler()->ProcessEvent(event
);
1804 // ----------------------------------------------------------------------------
1805 // context-sensitive help support
1806 // ----------------------------------------------------------------------------
1810 // associate this help text with this window
1811 void wxWindowBase::SetHelpText(const wxString
& text
)
1813 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1816 helpProvider
->AddHelp(this, text
);
1820 #if WXWIN_COMPATIBILITY_2_8
1821 // associate this help text with all windows with the same id as this
1823 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1825 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1828 helpProvider
->AddHelp(GetId(), text
);
1831 #endif // WXWIN_COMPATIBILITY_2_8
1833 // get the help string associated with this window (may be empty)
1834 // default implementation forwards calls to the help provider
1836 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1837 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1840 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1843 text
= helpProvider
->GetHelp(this);
1849 // show help for this window
1850 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1852 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1855 wxPoint pos
= event
.GetPosition();
1856 const wxHelpEvent::Origin origin
= event
.GetOrigin();
1857 if ( origin
== wxHelpEvent::Origin_Keyboard
)
1859 // if the help event was generated from keyboard it shouldn't
1860 // appear at the mouse position (which is still the only position
1861 // associated with help event) if the mouse is far away, although
1862 // we still do use the mouse position if it's over the window
1863 // because we suppose the user looks approximately at the mouse
1864 // already and so it would be more convenient than showing tooltip
1865 // at some arbitrary position which can be quite far from it
1866 const wxRect rectClient
= GetClientRect();
1867 if ( !rectClient
.Contains(ScreenToClient(pos
)) )
1869 // position help slightly under and to the right of this window
1870 pos
= ClientToScreen(wxPoint(
1872 rectClient
.height
+ GetCharHeight()
1877 if ( helpProvider
->ShowHelpAtPoint(this, pos
, origin
) )
1879 // skip the event.Skip() below
1887 #endif // wxUSE_HELP
1889 // ----------------------------------------------------------------------------
1891 // ----------------------------------------------------------------------------
1895 wxString
wxWindowBase::GetToolTipText() const
1897 return m_tooltip
? m_tooltip
->GetTip() : wxString();
1900 void wxWindowBase::SetToolTip( const wxString
&tip
)
1902 // don't create the new tooltip if we already have one
1905 m_tooltip
->SetTip( tip
);
1909 SetToolTip( new wxToolTip( tip
) );
1912 // setting empty tooltip text does not remove the tooltip any more - use
1913 // SetToolTip(NULL) for this
1916 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1918 if ( m_tooltip
!= tooltip
)
1923 m_tooltip
= tooltip
;
1927 #endif // wxUSE_TOOLTIPS
1929 // ----------------------------------------------------------------------------
1930 // constraints and sizers
1931 // ----------------------------------------------------------------------------
1933 #if wxUSE_CONSTRAINTS
1935 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1937 if ( m_constraints
)
1939 UnsetConstraints(m_constraints
);
1940 delete m_constraints
;
1942 m_constraints
= constraints
;
1943 if ( m_constraints
)
1945 // Make sure other windows know they're part of a 'meaningful relationship'
1946 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1947 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1948 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1949 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1950 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1951 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1952 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1953 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1954 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1955 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1956 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1957 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1958 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1959 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1960 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1961 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1965 // This removes any dangling pointers to this window in other windows'
1966 // constraintsInvolvedIn lists.
1967 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1971 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1972 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1973 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1974 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1975 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1976 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1977 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1978 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1979 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1980 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1981 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1982 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1983 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1984 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1985 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1986 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1990 // Back-pointer to other windows we're involved with, so if we delete this
1991 // window, we must delete any constraints we're involved with.
1992 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1994 if ( !m_constraintsInvolvedIn
)
1995 m_constraintsInvolvedIn
= new wxWindowList
;
1996 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1997 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
2000 // REMOVE back-pointer to other windows we're involved with.
2001 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
2003 if ( m_constraintsInvolvedIn
)
2004 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
2007 // Reset any constraints that mention this window
2008 void wxWindowBase::DeleteRelatedConstraints()
2010 if ( m_constraintsInvolvedIn
)
2012 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
2015 wxWindow
*win
= node
->GetData();
2016 wxLayoutConstraints
*constr
= win
->GetConstraints();
2018 // Reset any constraints involving this window
2021 constr
->left
.ResetIfWin(this);
2022 constr
->top
.ResetIfWin(this);
2023 constr
->right
.ResetIfWin(this);
2024 constr
->bottom
.ResetIfWin(this);
2025 constr
->width
.ResetIfWin(this);
2026 constr
->height
.ResetIfWin(this);
2027 constr
->centreX
.ResetIfWin(this);
2028 constr
->centreY
.ResetIfWin(this);
2031 wxWindowList::compatibility_iterator next
= node
->GetNext();
2032 m_constraintsInvolvedIn
->Erase(node
);
2036 delete m_constraintsInvolvedIn
;
2037 m_constraintsInvolvedIn
= NULL
;
2041 #endif // wxUSE_CONSTRAINTS
2043 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
2045 if ( sizer
== m_windowSizer
)
2048 if ( m_windowSizer
)
2050 m_windowSizer
->SetContainingWindow(NULL
);
2053 delete m_windowSizer
;
2056 m_windowSizer
= sizer
;
2057 if ( m_windowSizer
)
2059 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
2062 SetAutoLayout(m_windowSizer
!= NULL
);
2065 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
2067 SetSizer( sizer
, deleteOld
);
2068 sizer
->SetSizeHints( (wxWindow
*) this );
2072 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
2074 // adding a window to a sizer twice is going to result in fatal and
2075 // hard to debug problems later because when deleting the second
2076 // associated wxSizerItem we're going to dereference a dangling
2077 // pointer; so try to detect this as early as possible
2078 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
2079 wxT("Adding a window to the same sizer twice?") );
2081 m_containingSizer
= sizer
;
2084 #if wxUSE_CONSTRAINTS
2086 void wxWindowBase::SatisfyConstraints()
2088 wxLayoutConstraints
*constr
= GetConstraints();
2089 bool wasOk
= constr
&& constr
->AreSatisfied();
2091 ResetConstraints(); // Mark all constraints as unevaluated
2095 // if we're a top level panel (i.e. our parent is frame/dialog), our
2096 // own constraints will never be satisfied any more unless we do it
2100 while ( noChanges
> 0 )
2102 LayoutPhase1(&noChanges
);
2106 LayoutPhase2(&noChanges
);
2109 #endif // wxUSE_CONSTRAINTS
2111 bool wxWindowBase::Layout()
2113 // If there is a sizer, use it instead of the constraints
2117 GetVirtualSize(&w
, &h
);
2118 GetSizer()->SetDimension( 0, 0, w
, h
);
2120 #if wxUSE_CONSTRAINTS
2123 SatisfyConstraints(); // Find the right constraints values
2124 SetConstraintSizes(); // Recursively set the real window sizes
2131 void wxWindowBase::InternalOnSize(wxSizeEvent
& event
)
2133 if ( GetAutoLayout() )
2139 #if wxUSE_CONSTRAINTS
2141 // first phase of the constraints evaluation: set our own constraints
2142 bool wxWindowBase::LayoutPhase1(int *noChanges
)
2144 wxLayoutConstraints
*constr
= GetConstraints();
2146 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
2149 // second phase: set the constraints for our children
2150 bool wxWindowBase::LayoutPhase2(int *noChanges
)
2157 // Layout grand children
2163 // Do a phase of evaluating child constraints
2164 bool wxWindowBase::DoPhase(int phase
)
2166 // the list containing the children for which the constraints are already
2168 wxWindowList succeeded
;
2170 // the max number of iterations we loop before concluding that we can't set
2172 static const int maxIterations
= 500;
2174 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
2178 // loop over all children setting their constraints
2179 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2181 node
= node
->GetNext() )
2183 wxWindow
*child
= node
->GetData();
2184 if ( child
->IsTopLevel() )
2186 // top level children are not inside our client area
2190 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
2192 // this one is either already ok or nothing we can do about it
2196 int tempNoChanges
= 0;
2197 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
2198 : child
->LayoutPhase2(&tempNoChanges
);
2199 noChanges
+= tempNoChanges
;
2203 succeeded
.Append(child
);
2209 // constraints are set
2217 void wxWindowBase::ResetConstraints()
2219 wxLayoutConstraints
*constr
= GetConstraints();
2222 constr
->left
.SetDone(false);
2223 constr
->top
.SetDone(false);
2224 constr
->right
.SetDone(false);
2225 constr
->bottom
.SetDone(false);
2226 constr
->width
.SetDone(false);
2227 constr
->height
.SetDone(false);
2228 constr
->centreX
.SetDone(false);
2229 constr
->centreY
.SetDone(false);
2232 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2235 wxWindow
*win
= node
->GetData();
2236 if ( !win
->IsTopLevel() )
2237 win
->ResetConstraints();
2238 node
= node
->GetNext();
2242 // Need to distinguish between setting the 'fake' size for windows and sizers,
2243 // and setting the real values.
2244 void wxWindowBase::SetConstraintSizes(bool recurse
)
2246 wxLayoutConstraints
*constr
= GetConstraints();
2247 if ( constr
&& constr
->AreSatisfied() )
2249 int x
= constr
->left
.GetValue();
2250 int y
= constr
->top
.GetValue();
2251 int w
= constr
->width
.GetValue();
2252 int h
= constr
->height
.GetValue();
2254 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
2255 (constr
->height
.GetRelationship() != wxAsIs
) )
2257 SetSize(x
, y
, w
, h
);
2261 // If we don't want to resize this window, just move it...
2267 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
2268 GetClassInfo()->GetClassName(),
2274 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2277 wxWindow
*win
= node
->GetData();
2278 if ( !win
->IsTopLevel() && win
->GetConstraints() )
2279 win
->SetConstraintSizes();
2280 node
= node
->GetNext();
2285 // Only set the size/position of the constraint (if any)
2286 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
2288 wxLayoutConstraints
*constr
= GetConstraints();
2291 if ( x
!= wxDefaultCoord
)
2293 constr
->left
.SetValue(x
);
2294 constr
->left
.SetDone(true);
2296 if ( y
!= wxDefaultCoord
)
2298 constr
->top
.SetValue(y
);
2299 constr
->top
.SetDone(true);
2301 if ( w
!= wxDefaultCoord
)
2303 constr
->width
.SetValue(w
);
2304 constr
->width
.SetDone(true);
2306 if ( h
!= wxDefaultCoord
)
2308 constr
->height
.SetValue(h
);
2309 constr
->height
.SetDone(true);
2314 void wxWindowBase::MoveConstraint(int x
, int y
)
2316 wxLayoutConstraints
*constr
= GetConstraints();
2319 if ( x
!= wxDefaultCoord
)
2321 constr
->left
.SetValue(x
);
2322 constr
->left
.SetDone(true);
2324 if ( y
!= wxDefaultCoord
)
2326 constr
->top
.SetValue(y
);
2327 constr
->top
.SetDone(true);
2332 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2334 wxLayoutConstraints
*constr
= GetConstraints();
2337 *w
= constr
->width
.GetValue();
2338 *h
= constr
->height
.GetValue();
2344 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2346 wxLayoutConstraints
*constr
= GetConstraints();
2349 *w
= constr
->width
.GetValue();
2350 *h
= constr
->height
.GetValue();
2353 GetClientSize(w
, h
);
2356 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2358 wxLayoutConstraints
*constr
= GetConstraints();
2361 *x
= constr
->left
.GetValue();
2362 *y
= constr
->top
.GetValue();
2368 #endif // wxUSE_CONSTRAINTS
2370 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2372 // don't do it for the dialogs/frames - they float independently of their
2374 if ( !IsTopLevel() )
2376 wxWindow
*parent
= GetParent();
2377 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2379 wxPoint
pt(parent
->GetClientAreaOrigin());
2386 // ----------------------------------------------------------------------------
2387 // Update UI processing
2388 // ----------------------------------------------------------------------------
2390 void wxWindowBase::UpdateWindowUI(long flags
)
2392 wxUpdateUIEvent
event(GetId());
2393 event
.SetEventObject(this);
2395 if ( GetEventHandler()->ProcessEvent(event
) )
2397 DoUpdateWindowUI(event
);
2400 if (flags
& wxUPDATE_UI_RECURSE
)
2402 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2405 wxWindow
* child
= (wxWindow
*) node
->GetData();
2406 child
->UpdateWindowUI(flags
);
2407 node
= node
->GetNext();
2412 // do the window-specific processing after processing the update event
2413 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2415 if ( event
.GetSetEnabled() )
2416 Enable(event
.GetEnabled());
2418 if ( event
.GetSetShown() )
2419 Show(event
.GetShown());
2422 // ----------------------------------------------------------------------------
2423 // dialog units translations
2424 // ----------------------------------------------------------------------------
2426 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2428 int charWidth
= GetCharWidth();
2429 int charHeight
= GetCharHeight();
2430 wxPoint pt2
= wxDefaultPosition
;
2431 if (pt
.x
!= wxDefaultCoord
)
2432 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2433 if (pt
.y
!= wxDefaultCoord
)
2434 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2439 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2441 int charWidth
= GetCharWidth();
2442 int charHeight
= GetCharHeight();
2443 wxPoint pt2
= wxDefaultPosition
;
2444 if (pt
.x
!= wxDefaultCoord
)
2445 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2446 if (pt
.y
!= wxDefaultCoord
)
2447 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2452 // ----------------------------------------------------------------------------
2454 // ----------------------------------------------------------------------------
2456 // propagate the colour change event to the subwindows
2457 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2459 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2462 // Only propagate to non-top-level windows
2463 wxWindow
*win
= node
->GetData();
2464 if ( !win
->IsTopLevel() )
2466 wxSysColourChangedEvent event2
;
2467 event
.SetEventObject(win
);
2468 win
->GetEventHandler()->ProcessEvent(event2
);
2471 node
= node
->GetNext();
2477 // the default action is to populate dialog with data when it's created,
2478 // and nudge the UI into displaying itself correctly in case
2479 // we've turned the wxUpdateUIEvents frequency down low.
2480 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2482 TransferDataToWindow();
2484 // Update the UI at this point
2485 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2488 // ----------------------------------------------------------------------------
2489 // menu-related functions
2490 // ----------------------------------------------------------------------------
2494 bool wxWindowBase::PopupMenu(wxMenu
*menu
, int x
, int y
)
2496 wxCHECK_MSG( menu
, false, "can't popup NULL menu" );
2498 wxCurrentPopupMenu
= menu
;
2499 const bool rc
= DoPopupMenu(menu
, x
, y
);
2500 wxCurrentPopupMenu
= NULL
;
2505 // this is used to pass the id of the selected item from the menu event handler
2506 // to the main function itself
2508 // it's ok to use a global here as there can be at most one popup menu shown at
2510 static int gs_popupMenuSelection
= wxID_NONE
;
2512 void wxWindowBase::InternalOnPopupMenu(wxCommandEvent
& event
)
2514 // store the id in a global variable where we'll retrieve it from later
2515 gs_popupMenuSelection
= event
.GetId();
2518 void wxWindowBase::InternalOnPopupMenuUpdate(wxUpdateUIEvent
& WXUNUSED(event
))
2520 // nothing to do but do not skip it
2524 wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu
& menu
, int x
, int y
)
2526 gs_popupMenuSelection
= wxID_NONE
;
2528 Connect(wxEVT_COMMAND_MENU_SELECTED
,
2529 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2533 // it is common to construct the menu passed to this function dynamically
2534 // using some fixed range of ids which could clash with the ids used
2535 // elsewhere in the program, which could result in some menu items being
2536 // unintentionally disabled or otherwise modified by update UI handlers
2537 // elsewhere in the program code and this is difficult to avoid in the
2538 // program itself, so instead we just temporarily suspend UI updating while
2539 // this menu is shown
2540 Connect(wxEVT_UPDATE_UI
,
2541 wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate
),
2545 PopupMenu(&menu
, x
, y
);
2547 Disconnect(wxEVT_UPDATE_UI
,
2548 wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate
),
2551 Disconnect(wxEVT_COMMAND_MENU_SELECTED
,
2552 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2556 return gs_popupMenuSelection
;
2559 #endif // wxUSE_MENUS
2561 // methods for drawing the sizers in a visible way: this is currently only
2562 // enabled for "full debug" builds with wxDEBUG_LEVEL==2 as it doesn't work
2563 // that well and also because we don't want to leave it enabled in default
2564 // builds used for production
2565 #if wxDEBUG_LEVEL > 1
2567 static void DrawSizers(wxWindowBase
*win
);
2569 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
, const wxPen
* pen
)
2571 wxClientDC
dc((wxWindow
*)win
);
2573 dc
.SetBrush(fill
? wxBrush(pen
->GetColour(), wxBRUSHSTYLE_CROSSDIAG_HATCH
) :
2574 *wxTRANSPARENT_BRUSH
);
2575 dc
.DrawRectangle(rect
.Deflate(1, 1));
2578 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2580 const wxSizerItemList
& items
= sizer
->GetChildren();
2581 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2586 wxSizerItem
*item
= *i
;
2587 if ( item
->IsSizer() )
2589 DrawBorder(win
, item
->GetRect().Deflate(2), false, wxRED_PEN
);
2590 DrawSizer(win
, item
->GetSizer());
2592 else if ( item
->IsSpacer() )
2594 DrawBorder(win
, item
->GetRect().Deflate(2), true, wxBLUE_PEN
);
2596 else if ( item
->IsWindow() )
2598 DrawSizers(item
->GetWindow());
2601 wxFAIL_MSG("inconsistent wxSizerItem status!");
2605 static void DrawSizers(wxWindowBase
*win
)
2607 DrawBorder(win
, win
->GetClientSize(), false, wxGREEN_PEN
);
2609 wxSizer
*sizer
= win
->GetSizer();
2612 DrawSizer(win
, sizer
);
2614 else // no sizer, still recurse into the children
2616 const wxWindowList
& children
= win
->GetChildren();
2617 for ( wxWindowList::const_iterator i
= children
.begin(),
2618 end
= children
.end();
2625 // show all kind of sizes of this window; see the "window sizing" topic
2626 // overview for more info about the various differences:
2627 wxSize fullSz
= win
->GetSize();
2628 wxSize clientSz
= win
->GetClientSize();
2629 wxSize bestSz
= win
->GetBestSize();
2630 wxSize minSz
= win
->GetMinSize();
2631 wxSize maxSz
= win
->GetMaxSize();
2632 wxSize virtualSz
= win
->GetVirtualSize();
2634 wxMessageOutputDebug dbgout
;
2636 "%-10s => fullsz=%4d;%-4d clientsz=%4d;%-4d bestsz=%4d;%-4d minsz=%4d;%-4d maxsz=%4d;%-4d virtualsz=%4d;%-4d\n",
2639 clientSz
.x
, clientSz
.y
,
2643 virtualSz
.x
, virtualSz
.y
);
2647 #endif // wxDEBUG_LEVEL
2649 // process special middle clicks
2650 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2652 if ( event
.ControlDown() && event
.AltDown() )
2654 #if wxDEBUG_LEVEL > 1
2655 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2656 if ( event
.ShiftDown() )
2661 #endif // __WXDEBUG__
2663 // just Ctrl-Alt-middle click shows information about wx version
2664 ::wxInfoMessageBox((wxWindow
*)this);
2673 // ----------------------------------------------------------------------------
2675 // ----------------------------------------------------------------------------
2677 #if wxUSE_ACCESSIBILITY
2678 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2680 if (m_accessible
&& (accessible
!= m_accessible
))
2681 delete m_accessible
;
2682 m_accessible
= accessible
;
2684 m_accessible
->SetWindow((wxWindow
*) this);
2687 // Returns the accessible object, creating if necessary.
2688 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2691 m_accessible
= CreateAccessible();
2692 return m_accessible
;
2695 // Override to create a specific accessible object.
2696 wxAccessible
* wxWindowBase::CreateAccessible()
2698 return new wxWindowAccessible((wxWindow
*) this);
2703 // ----------------------------------------------------------------------------
2704 // list classes implementation
2705 // ----------------------------------------------------------------------------
2709 #include "wx/listimpl.cpp"
2710 WX_DEFINE_LIST(wxWindowList
)
2714 void wxWindowListNode::DeleteData()
2716 delete (wxWindow
*)GetData();
2719 #endif // wxUSE_STL/!wxUSE_STL
2721 // ----------------------------------------------------------------------------
2723 // ----------------------------------------------------------------------------
2725 wxBorder
wxWindowBase::GetBorder(long flags
) const
2727 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2728 if ( border
== wxBORDER_DEFAULT
)
2730 border
= GetDefaultBorder();
2732 else if ( border
== wxBORDER_THEME
)
2734 border
= GetDefaultBorderForControl();
2740 wxBorder
wxWindowBase::GetDefaultBorder() const
2742 return wxBORDER_NONE
;
2745 // ----------------------------------------------------------------------------
2747 // ----------------------------------------------------------------------------
2749 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2751 // here we just check if the point is inside the window or not
2753 // check the top and left border first
2754 bool outside
= x
< 0 || y
< 0;
2757 // check the right and bottom borders too
2758 wxSize size
= GetSize();
2759 outside
= x
>= size
.x
|| y
>= size
.y
;
2762 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2765 // ----------------------------------------------------------------------------
2767 // ----------------------------------------------------------------------------
2769 struct WXDLLEXPORT wxWindowNext
2773 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2774 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2775 bool wxWindowBase::ms_winCaptureChanging
= false;
2777 void wxWindowBase::CaptureMouse()
2779 wxLogTrace(wxT("mousecapture"), wxT("CaptureMouse(%p)"), static_cast<void*>(this));
2781 wxASSERT_MSG( !ms_winCaptureChanging
, wxT("recursive CaptureMouse call?") );
2783 ms_winCaptureChanging
= true;
2785 wxWindow
*winOld
= GetCapture();
2788 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2791 wxWindowNext
*item
= new wxWindowNext
;
2793 item
->next
= ms_winCaptureNext
;
2794 ms_winCaptureNext
= item
;
2796 //else: no mouse capture to save
2799 ms_winCaptureCurrent
= (wxWindow
*)this;
2801 ms_winCaptureChanging
= false;
2804 void wxWindowBase::ReleaseMouse()
2806 wxLogTrace(wxT("mousecapture"), wxT("ReleaseMouse(%p)"), static_cast<void*>(this));
2808 wxASSERT_MSG( !ms_winCaptureChanging
, wxT("recursive ReleaseMouse call?") );
2810 wxASSERT_MSG( GetCapture() == this,
2811 "attempt to release mouse, but this window hasn't captured it" );
2812 wxASSERT_MSG( ms_winCaptureCurrent
== this,
2813 "attempt to release mouse, but this window hasn't captured it" );
2815 ms_winCaptureChanging
= true;
2818 ms_winCaptureCurrent
= NULL
;
2820 if ( ms_winCaptureNext
)
2822 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2823 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2825 wxWindowNext
*item
= ms_winCaptureNext
;
2826 ms_winCaptureNext
= item
->next
;
2829 //else: stack is empty, no previous capture
2831 ms_winCaptureChanging
= false;
2833 wxLogTrace(wxT("mousecapture"),
2834 (const wxChar
*) wxT("After ReleaseMouse() mouse is captured by %p"),
2835 static_cast<void*>(GetCapture()));
2838 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2840 wxMouseCaptureLostEvent
event(win
->GetId());
2841 event
.SetEventObject(win
);
2842 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2844 // windows must handle this event, otherwise the app wouldn't behave
2845 // correctly if it loses capture unexpectedly; see the discussion here:
2846 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
2847 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
2848 wxFAIL_MSG( wxT("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2853 void wxWindowBase::NotifyCaptureLost()
2855 // don't do anything if capture lost was expected, i.e. resulted from
2856 // a wx call to ReleaseMouse or CaptureMouse:
2857 if ( ms_winCaptureChanging
)
2860 // if the capture was lost unexpectedly, notify every window that has
2861 // capture (on stack or current) about it and clear the stack:
2863 if ( ms_winCaptureCurrent
)
2865 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2866 ms_winCaptureCurrent
= NULL
;
2869 while ( ms_winCaptureNext
)
2871 wxWindowNext
*item
= ms_winCaptureNext
;
2872 ms_winCaptureNext
= item
->next
;
2874 DoNotifyWindowAboutCaptureLost(item
->win
);
2883 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2884 int WXUNUSED(modifiers
),
2885 int WXUNUSED(keycode
))
2891 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2897 #endif // wxUSE_HOTKEY
2899 // ----------------------------------------------------------------------------
2901 // ----------------------------------------------------------------------------
2903 bool wxWindowBase::TryBefore(wxEvent
& event
)
2905 #if wxUSE_VALIDATORS
2906 // Can only use the validator of the window which
2907 // is receiving the event
2908 if ( event
.GetEventObject() == this )
2910 wxValidator
* const validator
= GetValidator();
2911 if ( validator
&& validator
->ProcessEventHere(event
) )
2916 #endif // wxUSE_VALIDATORS
2918 return wxEvtHandler::TryBefore(event
);
2921 bool wxWindowBase::TryAfter(wxEvent
& event
)
2923 // carry on up the parent-child hierarchy if the propagation count hasn't
2925 if ( event
.ShouldPropagate() )
2927 // honour the requests to stop propagation at this window: this is
2928 // used by the dialogs, for example, to prevent processing the events
2929 // from the dialog controls in the parent frame which rarely, if ever,
2931 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2933 wxWindow
*parent
= GetParent();
2934 if ( parent
&& !parent
->IsBeingDeleted() )
2936 wxPropagateOnce
propagateOnce(event
);
2938 return parent
->GetEventHandler()->ProcessEvent(event
);
2943 return wxEvtHandler::TryAfter(event
);
2946 // ----------------------------------------------------------------------------
2947 // window relationships
2948 // ----------------------------------------------------------------------------
2950 wxWindow
*wxWindowBase::DoGetSibling(WindowOrder order
) const
2952 wxCHECK_MSG( GetParent(), NULL
,
2953 wxT("GetPrev/NextSibling() don't work for TLWs!") );
2955 wxWindowList
& siblings
= GetParent()->GetChildren();
2956 wxWindowList::compatibility_iterator i
= siblings
.Find((wxWindow
*)this);
2957 wxCHECK_MSG( i
, NULL
, wxT("window not a child of its parent?") );
2959 if ( order
== OrderBefore
)
2960 i
= i
->GetPrevious();
2964 return i
? i
->GetData() : NULL
;
2967 // ----------------------------------------------------------------------------
2968 // keyboard navigation
2969 // ----------------------------------------------------------------------------
2971 // Navigates in the specified direction inside this window
2972 bool wxWindowBase::DoNavigateIn(int flags
)
2974 #ifdef wxHAS_NATIVE_TAB_TRAVERSAL
2975 // native code doesn't process our wxNavigationKeyEvents anyhow
2978 #else // !wxHAS_NATIVE_TAB_TRAVERSAL
2979 wxNavigationKeyEvent eventNav
;
2980 wxWindow
*focused
= FindFocus();
2981 eventNav
.SetCurrentFocus(focused
);
2982 eventNav
.SetEventObject(focused
);
2983 eventNav
.SetFlags(flags
);
2984 return GetEventHandler()->ProcessEvent(eventNav
);
2985 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
2988 bool wxWindowBase::HandleAsNavigationKey(const wxKeyEvent
& event
)
2990 if ( event
.GetKeyCode() != WXK_TAB
)
2993 int flags
= wxNavigationKeyEvent::FromTab
;
2995 if ( event
.ShiftDown() )
2996 flags
|= wxNavigationKeyEvent::IsBackward
;
2998 flags
|= wxNavigationKeyEvent::IsForward
;
3000 if ( event
.ControlDown() )
3001 flags
|= wxNavigationKeyEvent::WinChange
;
3007 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, WindowOrder move
)
3009 // check that we're not a top level window
3010 wxCHECK_RET( GetParent(),
3011 wxT("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
3013 // detect the special case when we have nothing to do anyhow and when the
3014 // code below wouldn't work
3018 // find the target window in the siblings list
3019 wxWindowList
& siblings
= GetParent()->GetChildren();
3020 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
3021 wxCHECK_RET( i
, wxT("MoveBefore/AfterInTabOrder(): win is not a sibling") );
3023 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
3024 // can't just move the node around
3025 wxWindow
*self
= (wxWindow
*)this;
3026 siblings
.DeleteObject(self
);
3027 if ( move
== OrderAfter
)
3034 siblings
.Insert(i
, self
);
3036 else // OrderAfter and win was the last sibling
3038 siblings
.Append(self
);
3042 // ----------------------------------------------------------------------------
3044 // ----------------------------------------------------------------------------
3046 /*static*/ wxWindow
* wxWindowBase::FindFocus()
3048 wxWindowBase
*win
= DoFindFocus();
3049 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
3052 bool wxWindowBase::HasFocus() const
3054 wxWindowBase
*win
= DoFindFocus();
3055 return win
== this ||
3056 win
== wxConstCast(this, wxWindowBase
)->GetMainWindowOfCompositeControl();
3059 // ----------------------------------------------------------------------------
3061 // ----------------------------------------------------------------------------
3063 #if wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
3068 class DragAcceptFilesTarget
: public wxFileDropTarget
3071 DragAcceptFilesTarget(wxWindowBase
*win
) : m_win(win
) {}
3073 virtual bool OnDropFiles(wxCoord x
, wxCoord y
,
3074 const wxArrayString
& filenames
)
3076 wxDropFilesEvent
event(wxEVT_DROP_FILES
,
3078 wxCArrayString(filenames
).Release());
3079 event
.SetEventObject(m_win
);
3083 return m_win
->HandleWindowEvent(event
);
3087 wxWindowBase
* const m_win
;
3089 wxDECLARE_NO_COPY_CLASS(DragAcceptFilesTarget
);
3093 } // anonymous namespace
3095 // Generic version of DragAcceptFiles(). It works by installing a simple
3096 // wxFileDropTarget-to-EVT_DROP_FILES adaptor and therefore cannot be used
3097 // together with explicit SetDropTarget() calls.
3098 void wxWindowBase::DragAcceptFiles(bool accept
)
3102 wxASSERT_MSG( !GetDropTarget(),
3103 "cannot use DragAcceptFiles() and SetDropTarget() together" );
3104 SetDropTarget(new DragAcceptFilesTarget(this));
3108 SetDropTarget(NULL
);
3112 #endif // wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
3114 // ----------------------------------------------------------------------------
3116 // ----------------------------------------------------------------------------
3118 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
3120 while ( win
&& !win
->IsTopLevel() )
3121 win
= win
->GetParent();
3126 #if wxUSE_ACCESSIBILITY
3127 // ----------------------------------------------------------------------------
3128 // accessible object for windows
3129 // ----------------------------------------------------------------------------
3131 // Can return either a child object, or an integer
3132 // representing the child element, starting from 1.
3133 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
3135 wxASSERT( GetWindow() != NULL
);
3139 return wxACC_NOT_IMPLEMENTED
;
3142 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
3143 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
3145 wxASSERT( GetWindow() != NULL
);
3149 wxWindow
* win
= NULL
;
3156 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
3158 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
3165 rect
= win
->GetRect();
3166 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
3167 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
3171 return wxACC_NOT_IMPLEMENTED
;
3174 // Navigates from fromId to toId/toObject.
3175 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
3176 int* WXUNUSED(toId
), wxAccessible
** toObject
)
3178 wxASSERT( GetWindow() != NULL
);
3184 case wxNAVDIR_FIRSTCHILD
:
3186 if (GetWindow()->GetChildren().GetCount() == 0)
3188 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
3189 *toObject
= childWindow
->GetOrCreateAccessible();
3193 case wxNAVDIR_LASTCHILD
:
3195 if (GetWindow()->GetChildren().GetCount() == 0)
3197 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
3198 *toObject
= childWindow
->GetOrCreateAccessible();
3202 case wxNAVDIR_RIGHT
:
3206 wxWindowList::compatibility_iterator node
=
3207 wxWindowList::compatibility_iterator();
3210 // Can't navigate to sibling of this window
3211 // if we're a top-level window.
3212 if (!GetWindow()->GetParent())
3213 return wxACC_NOT_IMPLEMENTED
;
3215 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3219 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
3220 node
= GetWindow()->GetChildren().Item(fromId
-1);
3223 if (node
&& node
->GetNext())
3225 wxWindow
* nextWindow
= node
->GetNext()->GetData();
3226 *toObject
= nextWindow
->GetOrCreateAccessible();
3234 case wxNAVDIR_PREVIOUS
:
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
->GetPrevious())
3255 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
3256 *toObject
= previousWindow
->GetOrCreateAccessible();
3264 return wxACC_NOT_IMPLEMENTED
;
3267 // Gets the name of the specified object.
3268 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
3270 wxASSERT( GetWindow() != NULL
);
3276 // If a child, leave wxWidgets to call the function on the actual
3279 return wxACC_NOT_IMPLEMENTED
;
3281 // This will eventually be replaced by specialised
3282 // accessible classes, one for each kind of wxWidgets
3283 // control or window.
3285 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
3286 title
= ((wxButton
*) GetWindow())->GetLabel();
3289 title
= GetWindow()->GetName();
3297 return wxACC_NOT_IMPLEMENTED
;
3300 // Gets the number of children.
3301 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
3303 wxASSERT( GetWindow() != NULL
);
3307 *childId
= (int) GetWindow()->GetChildren().GetCount();
3311 // Gets the specified child (starting from 1).
3312 // If *child is NULL and return value is wxACC_OK,
3313 // this means that the child is a simple element and
3314 // not an accessible object.
3315 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
3317 wxASSERT( GetWindow() != NULL
);
3327 if (childId
> (int) GetWindow()->GetChildren().GetCount())
3330 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
3331 *child
= childWindow
->GetOrCreateAccessible();
3338 // Gets the parent, or NULL.
3339 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
3341 wxASSERT( GetWindow() != NULL
);
3345 wxWindow
* parentWindow
= GetWindow()->GetParent();
3353 *parent
= parentWindow
->GetOrCreateAccessible();
3361 // Performs the default action. childId is 0 (the action for this object)
3362 // or > 0 (the action for a child).
3363 // Return wxACC_NOT_SUPPORTED if there is no default action for this
3364 // window (e.g. an edit control).
3365 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
3367 wxASSERT( GetWindow() != NULL
);
3371 return wxACC_NOT_IMPLEMENTED
;
3374 // Gets the default action for this object (0) or > 0 (the action for a child).
3375 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
3376 // string if there is no action.
3377 // The retrieved string describes the action that is performed on an object,
3378 // not what the object does as a result. For example, a toolbar button that prints
3379 // a document has a default action of "Press" rather than "Prints the current document."
3380 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
3382 wxASSERT( GetWindow() != NULL
);
3386 return wxACC_NOT_IMPLEMENTED
;
3389 // Returns the description for this object or a child.
3390 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
3392 wxASSERT( GetWindow() != NULL
);
3396 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3402 return wxACC_NOT_IMPLEMENTED
;
3405 // Returns help text for this object or a child, similar to tooltip text.
3406 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
3408 wxASSERT( GetWindow() != NULL
);
3412 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3418 return wxACC_NOT_IMPLEMENTED
;
3421 // Returns the keyboard shortcut for this object or child.
3422 // Return e.g. ALT+K
3423 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
3425 wxASSERT( GetWindow() != NULL
);
3429 return wxACC_NOT_IMPLEMENTED
;
3432 // Returns a role constant.
3433 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
3435 wxASSERT( GetWindow() != NULL
);
3439 // If a child, leave wxWidgets to call the function on the actual
3442 return wxACC_NOT_IMPLEMENTED
;
3444 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3445 return wxACC_NOT_IMPLEMENTED
;
3447 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3448 return wxACC_NOT_IMPLEMENTED
;
3451 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3452 return wxACC_NOT_IMPLEMENTED
;
3455 //*role = wxROLE_SYSTEM_CLIENT;
3456 *role
= wxROLE_SYSTEM_CLIENT
;
3460 return wxACC_NOT_IMPLEMENTED
;
3464 // Returns a state constant.
3465 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
3467 wxASSERT( GetWindow() != NULL
);
3471 // If a child, leave wxWidgets to call the function on the actual
3474 return wxACC_NOT_IMPLEMENTED
;
3476 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3477 return wxACC_NOT_IMPLEMENTED
;
3480 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3481 return wxACC_NOT_IMPLEMENTED
;
3484 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3485 return wxACC_NOT_IMPLEMENTED
;
3492 return wxACC_NOT_IMPLEMENTED
;
3496 // Returns a localized string representing the value for the object
3498 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3500 wxASSERT( GetWindow() != NULL
);
3504 return wxACC_NOT_IMPLEMENTED
;
3507 // Selects the object or child.
3508 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3510 wxASSERT( GetWindow() != NULL
);
3514 return wxACC_NOT_IMPLEMENTED
;
3517 // Gets the window with the keyboard focus.
3518 // If childId is 0 and child is NULL, no object in
3519 // this subhierarchy has the focus.
3520 // If this object has the focus, child should be 'this'.
3521 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3523 wxASSERT( GetWindow() != NULL
);
3527 return wxACC_NOT_IMPLEMENTED
;
3531 // Gets a variant representing the selected children
3533 // Acceptable values:
3534 // - a null variant (IsNull() returns true)
3535 // - a list variant (GetType() == wxT("list")
3536 // - an integer representing the selected child element,
3537 // or 0 if this object is selected (GetType() == wxT("long")
3538 // - a "void*" pointer to a wxAccessible child object
3539 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3541 wxASSERT( GetWindow() != NULL
);
3545 return wxACC_NOT_IMPLEMENTED
;
3547 #endif // wxUSE_VARIANT
3549 #endif // wxUSE_ACCESSIBILITY
3551 // ----------------------------------------------------------------------------
3553 // ----------------------------------------------------------------------------
3556 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3558 wxCoord widthTotal
) const
3560 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3562 x
= widthTotal
- x
- width
;