1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/window.cpp
3 // Purpose: common (to all ports) wxWindow functions
4 // Author: Julian Smart, Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/string.h"
32 #include "wx/window.h"
33 #include "wx/control.h"
34 #include "wx/checkbox.h"
35 #include "wx/radiobut.h"
36 #include "wx/statbox.h"
37 #include "wx/textctrl.h"
38 #include "wx/settings.h"
39 #include "wx/dialog.h"
40 #include "wx/msgdlg.h"
41 #include "wx/statusbr.h"
42 #include "wx/toolbar.h"
43 #include "wx/dcclient.h"
44 #include "wx/scrolbar.h"
45 #include "wx/layout.h"
49 #if wxUSE_DRAG_AND_DROP
51 #endif // wxUSE_DRAG_AND_DROP
53 #if wxUSE_ACCESSIBILITY
54 #include "wx/access.h"
58 #include "wx/cshelp.h"
62 #include "wx/tooltip.h"
63 #endif // wxUSE_TOOLTIPS
69 #if wxUSE_SYSTEM_OPTIONS
70 #include "wx/sysopt.h"
73 // For reporting compile- and runtime version of GTK+ in the ctrl+alt+mclick dialog.
74 // The gtk includes don't pull any other headers in, at least not on my system - MR
77 #include <gtk/gtkversion.h>
79 #include <gtk/gtkfeatures.h>
81 extern const unsigned int gtk_major_version
;
82 extern const unsigned int gtk_minor_version
;
83 extern const unsigned int gtk_micro_version
;
86 #include "wx/platinfo.h"
89 WXDLLIMPEXP_DATA_CORE(wxWindowList
) wxTopLevelWindows
;
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
95 #if defined(__WXPALMOS__)
96 int wxWindowBase::ms_lastControlId
= 32767;
97 #elif defined(__WXPM__)
98 int wxWindowBase::ms_lastControlId
= 2000;
100 int wxWindowBase::ms_lastControlId
= -200;
103 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
105 // ----------------------------------------------------------------------------
107 // ----------------------------------------------------------------------------
109 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
110 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
111 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
112 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
115 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
120 // ============================================================================
121 // implementation of the common functionality of the wxWindow class
122 // ============================================================================
124 // ----------------------------------------------------------------------------
126 // ----------------------------------------------------------------------------
128 // the default initialization
129 wxWindowBase::wxWindowBase()
131 // no window yet, no parent nor children
132 m_parent
= (wxWindow
*)NULL
;
133 m_windowId
= wxID_ANY
;
135 // no constraints on the minimal window size
137 m_maxWidth
= wxDefaultCoord
;
139 m_maxHeight
= wxDefaultCoord
;
141 // invalidiated cache value
142 m_bestSizeCache
= wxDefaultSize
;
144 // window are created enabled and visible by default
148 // the default event handler is just this window
149 m_eventHandler
= this;
153 m_windowValidator
= (wxValidator
*) NULL
;
154 #endif // wxUSE_VALIDATORS
156 // the colours/fonts are default for now, so leave m_font,
157 // m_backgroundColour and m_foregroundColour uninitialized and set those
163 m_inheritFont
= false;
169 m_backgroundStyle
= wxBG_STYLE_SYSTEM
;
171 #if wxUSE_CONSTRAINTS
172 // no constraints whatsoever
173 m_constraints
= (wxLayoutConstraints
*) NULL
;
174 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
175 #endif // wxUSE_CONSTRAINTS
177 m_windowSizer
= (wxSizer
*) NULL
;
178 m_containingSizer
= (wxSizer
*) NULL
;
179 m_autoLayout
= false;
181 #if wxUSE_DRAG_AND_DROP
182 m_dropTarget
= (wxDropTarget
*)NULL
;
183 #endif // wxUSE_DRAG_AND_DROP
186 m_tooltip
= (wxToolTip
*)NULL
;
187 #endif // wxUSE_TOOLTIPS
190 m_caret
= (wxCaret
*)NULL
;
191 #endif // wxUSE_CARET
194 m_hasCustomPalette
= false;
195 #endif // wxUSE_PALETTE
197 #if wxUSE_ACCESSIBILITY
201 m_virtualSize
= wxDefaultSize
;
203 m_scrollHelper
= (wxScrollHelper
*) NULL
;
206 m_maxVirtualWidth
= wxDefaultCoord
;
208 m_maxVirtualHeight
= wxDefaultCoord
;
210 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
211 #if wxUSE_SYSTEM_OPTIONS
212 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
214 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
218 // Whether we're using the current theme for this window (wxGTK only for now)
219 m_themeEnabled
= false;
221 // VZ: this one shouldn't exist...
222 m_isBeingDeleted
= false;
225 // common part of window creation process
226 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
228 const wxPoint
& WXUNUSED(pos
),
229 const wxSize
& WXUNUSED(size
),
231 const wxValidator
& wxVALIDATOR_PARAM(validator
),
232 const wxString
& name
)
235 // wxGTK doesn't allow to create controls with static box as the parent so
236 // this will result in a crash when the program is ported to wxGTK so warn
239 // if you get this assert, the correct solution is to create the controls
240 // as siblings of the static box
241 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
242 _T("wxStaticBox can't be used as a window parent!") );
243 #endif // wxUSE_STATBOX
245 // ids are limited to 16 bits under MSW so if you care about portability,
246 // it's not a good idea to use ids out of this range (and negative ids are
247 // reserved for wxWidgets own usage)
248 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
249 _T("invalid id value") );
251 // generate a new id if the user doesn't care about it
252 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
254 // don't use SetWindowStyleFlag() here, this function should only be called
255 // to change the flag after creation as it tries to reflect the changes in
256 // flags by updating the window dynamically and we don't need this here
257 m_windowStyle
= style
;
263 SetValidator(validator
);
264 #endif // wxUSE_VALIDATORS
266 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
267 // have it too - like this it's possible to set it only in the top level
268 // dialog/frame and all children will inherit it by defult
269 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
271 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
277 bool wxWindowBase::ToggleWindowStyle(int flag
)
279 wxASSERT_MSG( flag
, _T("flags with 0 value can't be toggled") );
282 long style
= GetWindowStyleFlag();
288 else // currently off
294 SetWindowStyleFlag(style
);
299 // ----------------------------------------------------------------------------
301 // ----------------------------------------------------------------------------
304 wxWindowBase::~wxWindowBase()
306 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
308 // FIXME if these 2 cases result from programming errors in the user code
309 // we should probably assert here instead of silently fixing them
311 // Just in case the window has been Closed, but we're then deleting
312 // immediately: don't leave dangling pointers.
313 wxPendingDelete
.DeleteObject(this);
315 // Just in case we've loaded a top-level window via LoadNativeDialog but
316 // we weren't a dialog class
317 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
319 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
321 // notify the parent about this window destruction
323 m_parent
->RemoveChild(this);
327 #endif // wxUSE_CARET
330 delete m_windowValidator
;
331 #endif // wxUSE_VALIDATORS
333 #if wxUSE_CONSTRAINTS
334 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
335 // at deleted windows as they delete themselves.
336 DeleteRelatedConstraints();
340 // This removes any dangling pointers to this window in other windows'
341 // constraintsInvolvedIn lists.
342 UnsetConstraints(m_constraints
);
343 delete m_constraints
;
344 m_constraints
= NULL
;
346 #endif // wxUSE_CONSTRAINTS
348 if ( m_containingSizer
)
349 m_containingSizer
->Detach( (wxWindow
*)this );
351 delete m_windowSizer
;
353 #if wxUSE_DRAG_AND_DROP
355 #endif // wxUSE_DRAG_AND_DROP
359 #endif // wxUSE_TOOLTIPS
361 #if wxUSE_ACCESSIBILITY
366 void wxWindowBase::SendDestroyEvent()
368 wxWindowDestroyEvent event
;
369 event
.SetEventObject(this);
370 event
.SetId(GetId());
371 GetEventHandler()->ProcessEvent(event
);
374 bool wxWindowBase::Destroy()
381 bool wxWindowBase::Close(bool force
)
383 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
384 event
.SetEventObject(this);
385 event
.SetCanVeto(!force
);
387 // return false if window wasn't closed because the application vetoed the
389 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
392 bool wxWindowBase::DestroyChildren()
394 wxWindowList::compatibility_iterator node
;
397 // we iterate until the list becomes empty
398 node
= GetChildren().GetFirst();
402 wxWindow
*child
= node
->GetData();
404 // note that we really want to call delete and not ->Destroy() here
405 // because we want to delete the child immediately, before we are
406 // deleted, and delayed deletion would result in problems as our (top
407 // level) child could outlive its parent
410 wxASSERT_MSG( !GetChildren().Find(child
),
411 wxT("child didn't remove itself using RemoveChild()") );
417 // ----------------------------------------------------------------------------
418 // size/position related methods
419 // ----------------------------------------------------------------------------
421 // centre the window with respect to its parent in either (or both) directions
422 void wxWindowBase::DoCentre(int dir
)
424 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
425 _T("this method only implements centering child windows") );
427 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
430 // fits the window around the children
431 void wxWindowBase::Fit()
433 if ( !GetChildren().empty() )
435 SetSize(GetBestSize());
437 //else: do nothing if we have no children
440 // fits virtual size (ie. scrolled area etc.) around children
441 void wxWindowBase::FitInside()
443 if ( GetChildren().GetCount() > 0 )
445 SetVirtualSize( GetBestVirtualSize() );
449 // On Mac, scrollbars are explicitly children.
451 static bool wxHasRealChildren(const wxWindowBase
* win
)
453 int realChildCount
= 0;
455 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
457 node
= node
->GetNext() )
459 wxWindow
*win
= node
->GetData();
460 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
463 return (realChildCount
> 0);
467 void wxWindowBase::InvalidateBestSize()
469 m_bestSizeCache
= wxDefaultSize
;
471 // parent's best size calculation may depend on its children's
472 // as long as child window we are in is not top level window itself
473 // (because the TLW size is never resized automatically)
474 // so let's invalidate it as well to be safe:
475 if (m_parent
&& !IsTopLevel())
476 m_parent
->InvalidateBestSize();
479 // return the size best suited for the current window
480 wxSize
wxWindowBase::DoGetBestSize() const
486 best
= m_windowSizer
->GetMinSize();
488 #if wxUSE_CONSTRAINTS
489 else if ( m_constraints
)
491 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
493 // our minimal acceptable size is such that all our windows fit inside
497 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
499 node
= node
->GetNext() )
501 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
504 // it's not normal that we have an unconstrained child, but
505 // what can we do about it?
509 int x
= c
->right
.GetValue(),
510 y
= c
->bottom
.GetValue();
518 // TODO: we must calculate the overlaps somehow, otherwise we
519 // will never return a size bigger than the current one :-(
522 best
= wxSize(maxX
, maxY
);
524 #endif // wxUSE_CONSTRAINTS
525 else if ( !GetChildren().empty()
527 && wxHasRealChildren(this)
531 // our minimal acceptable size is such that all our visible child
532 // windows fit inside
536 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
538 node
= node
->GetNext() )
540 wxWindow
*win
= node
->GetData();
541 if ( win
->IsTopLevel()
544 || wxDynamicCast(win
, wxStatusBar
)
545 #endif // wxUSE_STATUSBAR
548 // dialogs and frames lie in different top level windows -
549 // don't deal with them here; as for the status bars, they
550 // don't lie in the client area at all
555 win
->GetPosition(&wx
, &wy
);
557 // if the window hadn't been positioned yet, assume that it is in
559 if ( wx
== wxDefaultCoord
)
561 if ( wy
== wxDefaultCoord
)
564 win
->GetSize(&ww
, &wh
);
565 if ( wx
+ ww
> maxX
)
567 if ( wy
+ wh
> maxY
)
571 best
= wxSize(maxX
, maxY
);
573 else // ! has children
575 // for a generic window there is no natural best size so, if the
576 // minimal size is not set, use the current size but take care to
577 // remember it as minimal size for the next time because our best size
578 // should be constant: otherwise we could get into a situation when the
579 // window is initially at some size, then expanded to a larger size and
580 // then, when the containing window is shrunk back (because our initial
581 // best size had been used for computing the parent min size), we can't
582 // be shrunk back any more because our best size is now bigger
583 wxSize size
= GetMinSize();
584 if ( !size
.IsFullySpecified() )
586 size
.SetDefaults(GetSize());
587 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
590 // return as-is, unadjusted by the client size difference.
594 // Add any difference between size and client size
595 wxSize diff
= GetSize() - GetClientSize();
596 best
.x
+= wxMax(0, diff
.x
);
597 best
.y
+= wxMax(0, diff
.y
);
602 // helper of GetWindowBorderSize(): as many ports don't implement support for
603 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
604 // fallbacks in this case
605 static int wxGetMetricOrDefault(wxSystemMetric what
)
607 int rc
= wxSystemSettings::GetMetric(what
);
614 // 2D border is by default 1 pixel wide
620 // 3D borders are by default 2 pixels
625 wxFAIL_MSG( _T("unexpected wxGetMetricOrDefault() argument") );
633 wxSize
wxWindowBase::GetWindowBorderSize() const
637 switch ( GetBorder() )
640 // nothing to do, size is already (0, 0)
643 case wxBORDER_SIMPLE
:
644 case wxBORDER_STATIC
:
645 size
.x
= wxGetMetricOrDefault(wxSYS_BORDER_X
);
646 size
.y
= wxGetMetricOrDefault(wxSYS_BORDER_Y
);
649 case wxBORDER_SUNKEN
:
650 case wxBORDER_RAISED
:
651 size
.x
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X
),
652 wxGetMetricOrDefault(wxSYS_BORDER_X
));
653 size
.y
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y
),
654 wxGetMetricOrDefault(wxSYS_BORDER_Y
));
657 case wxBORDER_DOUBLE
:
658 size
.x
= wxGetMetricOrDefault(wxSYS_EDGE_X
) +
659 wxGetMetricOrDefault(wxSYS_BORDER_X
);
660 size
.y
= wxGetMetricOrDefault(wxSYS_EDGE_Y
) +
661 wxGetMetricOrDefault(wxSYS_BORDER_Y
);
665 wxFAIL_MSG(_T("Unknown border style."));
669 // we have borders on both sides
673 wxSize
wxWindowBase::GetEffectiveMinSize() const
675 // merge the best size with the min size, giving priority to the min size
676 wxSize min
= GetMinSize();
677 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
679 wxSize best
= GetBestSize();
680 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
681 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
687 void wxWindowBase::SetInitialSize(const wxSize
& size
)
689 // Set the min size to the size passed in. This will usually either be
690 // wxDefaultSize or the size passed to this window's ctor/Create function.
693 // Merge the size with the best size if needed
694 wxSize best
= GetEffectiveMinSize();
696 // If the current size doesn't match then change it
697 if (GetSize() != best
)
702 // by default the origin is not shifted
703 wxPoint
wxWindowBase::GetClientAreaOrigin() const
708 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
710 if ( m_windowVariant
!= variant
)
712 m_windowVariant
= variant
;
714 DoSetWindowVariant(variant
);
718 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
720 // adjust the font height to correspond to our new variant (notice that
721 // we're only called if something really changed)
722 wxFont font
= GetFont();
723 int size
= font
.GetPointSize();
726 case wxWINDOW_VARIANT_NORMAL
:
729 case wxWINDOW_VARIANT_SMALL
:
734 case wxWINDOW_VARIANT_MINI
:
739 case wxWINDOW_VARIANT_LARGE
:
745 wxFAIL_MSG(_T("unexpected window variant"));
749 font
.SetPointSize(size
);
753 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
755 int WXUNUSED(incW
), int WXUNUSED(incH
) )
757 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
758 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
759 _T("min width/height must be less than max width/height!") );
768 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
771 m_minVirtualWidth
= minW
;
772 m_maxVirtualWidth
= maxW
;
773 m_minVirtualHeight
= minH
;
774 m_maxVirtualHeight
= maxH
;
777 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
779 if ( m_minVirtualWidth
!= wxDefaultCoord
&& m_minVirtualWidth
> x
)
780 x
= m_minVirtualWidth
;
781 if ( m_maxVirtualWidth
!= wxDefaultCoord
&& m_maxVirtualWidth
< x
)
782 x
= m_maxVirtualWidth
;
783 if ( m_minVirtualHeight
!= wxDefaultCoord
&& m_minVirtualHeight
> y
)
784 y
= m_minVirtualHeight
;
785 if ( m_maxVirtualHeight
!= wxDefaultCoord
&& m_maxVirtualHeight
< y
)
786 y
= m_maxVirtualHeight
;
788 m_virtualSize
= wxSize(x
, y
);
791 wxSize
wxWindowBase::DoGetVirtualSize() const
793 // we should use the entire client area so if it is greater than our
794 // virtual size, expand it to fit (otherwise if the window is big enough we
795 // wouldn't be using parts of it)
796 wxSize size
= GetClientSize();
797 if ( m_virtualSize
.x
> size
.x
)
798 size
.x
= m_virtualSize
.x
;
800 if ( m_virtualSize
.y
>= size
.y
)
801 size
.y
= m_virtualSize
.y
;
806 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
808 // screen position is the same as (0, 0) in client coords for non TLWs (and
809 // TLWs override this method)
815 ClientToScreen(x
, y
);
818 // ----------------------------------------------------------------------------
819 // show/hide/enable/disable the window
820 // ----------------------------------------------------------------------------
822 bool wxWindowBase::Show(bool show
)
824 if ( show
!= m_isShown
)
836 bool wxWindowBase::IsEnabled() const
838 return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
841 void wxWindowBase::NotifyWindowOnEnableChange(bool enabled
)
843 #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
845 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
849 // If we are top-level then the logic doesn't apply - otherwise
850 // showing a modal dialog would result in total greying out (and ungreying
851 // out later) of everything which would be really ugly
855 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
857 node
= node
->GetNext() )
859 wxWindowBase
* const child
= node
->GetData();
860 if ( !child
->IsTopLevel() && child
->IsThisEnabled() )
861 child
->NotifyWindowOnEnableChange(enabled
);
865 bool wxWindowBase::Enable(bool enable
)
867 if ( enable
== IsThisEnabled() )
870 m_isEnabled
= enable
;
872 #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
874 #else // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
875 wxWindowBase
* const parent
= GetParent();
876 if( !IsTopLevel() && parent
&& !parent
->IsEnabled() )
880 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
882 NotifyWindowOnEnableChange(enable
);
887 bool wxWindowBase::IsShownOnScreen() const
890 (GetParent() == NULL
|| GetParent()->IsShownOnScreen());
893 // ----------------------------------------------------------------------------
895 // ----------------------------------------------------------------------------
897 bool wxWindowBase::IsTopLevel() const
902 // ----------------------------------------------------------------------------
903 // reparenting the window
904 // ----------------------------------------------------------------------------
906 void wxWindowBase::AddChild(wxWindowBase
*child
)
908 wxCHECK_RET( child
, wxT("can't add a NULL child") );
910 // this should never happen and it will lead to a crash later if it does
911 // because RemoveChild() will remove only one node from the children list
912 // and the other(s) one(s) will be left with dangling pointers in them
913 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
915 GetChildren().Append((wxWindow
*)child
);
916 child
->SetParent(this);
919 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
921 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
923 GetChildren().DeleteObject((wxWindow
*)child
);
924 child
->SetParent(NULL
);
927 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
929 wxWindow
*oldParent
= GetParent();
930 if ( newParent
== oldParent
)
936 const bool oldEnabledState
= IsEnabled();
938 // unlink this window from the existing parent.
941 oldParent
->RemoveChild(this);
945 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
948 // add it to the new one
951 newParent
->AddChild(this);
955 wxTopLevelWindows
.Append((wxWindow
*)this);
958 // We need to notify window (and its subwindows) if by changing the parent
959 // we also change our enabled/disabled status.
960 const bool newEnabledState
= IsEnabled();
961 if ( newEnabledState
!= oldEnabledState
)
963 NotifyWindowOnEnableChange(newEnabledState
);
969 // ----------------------------------------------------------------------------
970 // event handler stuff
971 // ----------------------------------------------------------------------------
973 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
975 wxEvtHandler
*handlerOld
= GetEventHandler();
977 handler
->SetNextHandler(handlerOld
);
980 GetEventHandler()->SetPreviousHandler(handler
);
982 SetEventHandler(handler
);
985 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
987 wxEvtHandler
*handlerA
= GetEventHandler();
990 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
991 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
994 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
995 SetEventHandler(handlerB
);
1000 handlerA
= (wxEvtHandler
*)NULL
;
1007 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
1009 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
1011 wxEvtHandler
*handlerPrev
= NULL
,
1012 *handlerCur
= GetEventHandler();
1013 while ( handlerCur
)
1015 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
1017 if ( handlerCur
== handler
)
1021 handlerPrev
->SetNextHandler(handlerNext
);
1025 SetEventHandler(handlerNext
);
1030 handlerNext
->SetPreviousHandler ( handlerPrev
);
1033 handler
->SetNextHandler(NULL
);
1034 handler
->SetPreviousHandler(NULL
);
1039 handlerPrev
= handlerCur
;
1040 handlerCur
= handlerNext
;
1043 wxFAIL_MSG( _T("where has the event handler gone?") );
1048 // ----------------------------------------------------------------------------
1049 // colours, fonts &c
1050 // ----------------------------------------------------------------------------
1052 void wxWindowBase::InheritAttributes()
1054 const wxWindowBase
* const parent
= GetParent();
1058 // we only inherit attributes which had been explicitly set for the parent
1059 // which ensures that this only happens if the user really wants it and
1060 // not by default which wouldn't make any sense in modern GUIs where the
1061 // controls don't all use the same fonts (nor colours)
1062 if ( parent
->m_inheritFont
&& !m_hasFont
)
1063 SetFont(parent
->GetFont());
1065 // in addition, there is a possibility to explicitly forbid inheriting
1066 // colours at each class level by overriding ShouldInheritColours()
1067 if ( ShouldInheritColours() )
1069 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1070 SetForegroundColour(parent
->GetForegroundColour());
1072 // inheriting (solid) background colour is wrong as it totally breaks
1073 // any kind of themed backgrounds
1075 // instead, the controls should use the same background as their parent
1076 // (ideally by not drawing it at all)
1078 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1079 SetBackgroundColour(parent
->GetBackgroundColour());
1084 /* static */ wxVisualAttributes
1085 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1087 // it is important to return valid values for all attributes from here,
1088 // GetXXX() below rely on this
1089 wxVisualAttributes attrs
;
1090 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1091 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1093 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1094 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1095 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1096 // colour on other platforms.
1098 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1099 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1101 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1106 wxColour
wxWindowBase::GetBackgroundColour() const
1108 if ( !m_backgroundColour
.Ok() )
1110 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
1112 // get our default background colour
1113 wxColour colBg
= GetDefaultAttributes().colBg
;
1115 // we must return some valid colour to avoid redoing this every time
1116 // and also to avoid surprizing the applications written for older
1117 // wxWidgets versions where GetBackgroundColour() always returned
1118 // something -- so give them something even if it doesn't make sense
1119 // for this window (e.g. it has a themed background)
1121 colBg
= GetClassDefaultAttributes().colBg
;
1126 return m_backgroundColour
;
1129 wxColour
wxWindowBase::GetForegroundColour() const
1131 // logic is the same as above
1132 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1134 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
1136 wxColour colFg
= GetDefaultAttributes().colFg
;
1139 colFg
= GetClassDefaultAttributes().colFg
;
1144 return m_foregroundColour
;
1147 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1149 if ( colour
== m_backgroundColour
)
1152 m_hasBgCol
= colour
.Ok();
1153 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1154 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1156 m_inheritBgCol
= m_hasBgCol
;
1157 m_backgroundColour
= colour
;
1158 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1162 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1164 if (colour
== m_foregroundColour
)
1167 m_hasFgCol
= colour
.Ok();
1168 m_inheritFgCol
= m_hasFgCol
;
1169 m_foregroundColour
= colour
;
1170 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1174 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1176 // setting an invalid cursor is ok, it means that we don't have any special
1178 if ( m_cursor
.IsSameAs(cursor
) )
1189 wxFont
wxWindowBase::GetFont() const
1191 // logic is the same as in GetBackgroundColour()
1194 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1196 wxFont font
= GetDefaultAttributes().font
;
1198 font
= GetClassDefaultAttributes().font
;
1206 bool wxWindowBase::SetFont(const wxFont
& font
)
1208 if ( font
== m_font
)
1215 m_hasFont
= font
.Ok();
1216 m_inheritFont
= m_hasFont
;
1218 InvalidateBestSize();
1225 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1227 m_hasCustomPalette
= true;
1230 // VZ: can anyone explain me what do we do here?
1231 wxWindowDC
d((wxWindow
*) this);
1235 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1237 wxWindow
*win
= (wxWindow
*)this;
1238 while ( win
&& !win
->HasCustomPalette() )
1240 win
= win
->GetParent();
1246 #endif // wxUSE_PALETTE
1249 void wxWindowBase::SetCaret(wxCaret
*caret
)
1260 wxASSERT_MSG( m_caret
->GetWindow() == this,
1261 wxT("caret should be created associated to this window") );
1264 #endif // wxUSE_CARET
1266 #if wxUSE_VALIDATORS
1267 // ----------------------------------------------------------------------------
1269 // ----------------------------------------------------------------------------
1271 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1273 if ( m_windowValidator
)
1274 delete m_windowValidator
;
1276 m_windowValidator
= (wxValidator
*)validator
.Clone();
1278 if ( m_windowValidator
)
1279 m_windowValidator
->SetWindow(this);
1281 #endif // wxUSE_VALIDATORS
1283 // ----------------------------------------------------------------------------
1284 // update region stuff
1285 // ----------------------------------------------------------------------------
1287 wxRect
wxWindowBase::GetUpdateClientRect() const
1289 wxRegion rgnUpdate
= GetUpdateRegion();
1290 rgnUpdate
.Intersect(GetClientRect());
1291 wxRect rectUpdate
= rgnUpdate
.GetBox();
1292 wxPoint ptOrigin
= GetClientAreaOrigin();
1293 rectUpdate
.x
-= ptOrigin
.x
;
1294 rectUpdate
.y
-= ptOrigin
.y
;
1299 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1301 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1304 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1306 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1309 void wxWindowBase::ClearBackground()
1311 // wxGTK uses its own version, no need to add never used code
1313 wxClientDC
dc((wxWindow
*)this);
1314 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1315 dc
.SetBackground(brush
);
1320 // ----------------------------------------------------------------------------
1321 // find child window by id or name
1322 // ----------------------------------------------------------------------------
1324 wxWindow
*wxWindowBase::FindWindow(long id
) const
1326 if ( id
== m_windowId
)
1327 return (wxWindow
*)this;
1329 wxWindowBase
*res
= (wxWindow
*)NULL
;
1330 wxWindowList::compatibility_iterator node
;
1331 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1333 wxWindowBase
*child
= node
->GetData();
1334 res
= child
->FindWindow( id
);
1337 return (wxWindow
*)res
;
1340 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1342 if ( name
== m_windowName
)
1343 return (wxWindow
*)this;
1345 wxWindowBase
*res
= (wxWindow
*)NULL
;
1346 wxWindowList::compatibility_iterator node
;
1347 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1349 wxWindow
*child
= node
->GetData();
1350 res
= child
->FindWindow(name
);
1353 return (wxWindow
*)res
;
1357 // find any window by id or name or label: If parent is non-NULL, look through
1358 // children for a label or title matching the specified string. If NULL, look
1359 // through all top-level windows.
1361 // to avoid duplicating code we reuse the same helper function but with
1362 // different comparators
1364 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1365 const wxString
& label
, long id
);
1368 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1371 return win
->GetLabel() == label
;
1375 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1378 return win
->GetName() == label
;
1382 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1385 return win
->GetId() == id
;
1388 // recursive helper for the FindWindowByXXX() functions
1390 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1391 const wxString
& label
,
1393 wxFindWindowCmp cmp
)
1397 // see if this is the one we're looking for
1398 if ( (*cmp
)(parent
, label
, id
) )
1399 return (wxWindow
*)parent
;
1401 // It wasn't, so check all its children
1402 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1404 node
= node
->GetNext() )
1406 // recursively check each child
1407 wxWindow
*win
= (wxWindow
*)node
->GetData();
1408 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1418 // helper for FindWindowByXXX()
1420 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1421 const wxString
& label
,
1423 wxFindWindowCmp cmp
)
1427 // just check parent and all its children
1428 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1431 // start at very top of wx's windows
1432 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1434 node
= node
->GetNext() )
1436 // recursively check each window & its children
1437 wxWindow
*win
= node
->GetData();
1438 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1448 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1450 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1455 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1457 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1461 // fall back to the label
1462 win
= FindWindowByLabel(title
, parent
);
1470 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1472 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1475 // ----------------------------------------------------------------------------
1476 // dialog oriented functions
1477 // ----------------------------------------------------------------------------
1479 void wxWindowBase::MakeModal(bool modal
)
1481 // Disable all other windows
1484 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1487 wxWindow
*win
= node
->GetData();
1489 win
->Enable(!modal
);
1491 node
= node
->GetNext();
1496 bool wxWindowBase::Validate()
1498 #if wxUSE_VALIDATORS
1499 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1501 wxWindowList::compatibility_iterator node
;
1502 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1504 wxWindowBase
*child
= node
->GetData();
1505 wxValidator
*validator
= child
->GetValidator();
1506 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1511 if ( recurse
&& !child
->Validate() )
1516 #endif // wxUSE_VALIDATORS
1521 bool wxWindowBase::TransferDataToWindow()
1523 #if wxUSE_VALIDATORS
1524 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1526 wxWindowList::compatibility_iterator node
;
1527 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1529 wxWindowBase
*child
= node
->GetData();
1530 wxValidator
*validator
= child
->GetValidator();
1531 if ( validator
&& !validator
->TransferToWindow() )
1533 wxLogWarning(_("Could not transfer data to window"));
1535 wxLog::FlushActive();
1543 if ( !child
->TransferDataToWindow() )
1545 // warning already given
1550 #endif // wxUSE_VALIDATORS
1555 bool wxWindowBase::TransferDataFromWindow()
1557 #if wxUSE_VALIDATORS
1558 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1560 wxWindowList::compatibility_iterator node
;
1561 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1563 wxWindow
*child
= node
->GetData();
1564 wxValidator
*validator
= child
->GetValidator();
1565 if ( validator
&& !validator
->TransferFromWindow() )
1567 // nop warning here because the application is supposed to give
1568 // one itself - we don't know here what might have gone wrongly
1575 if ( !child
->TransferDataFromWindow() )
1577 // warning already given
1582 #endif // wxUSE_VALIDATORS
1587 void wxWindowBase::InitDialog()
1589 wxInitDialogEvent
event(GetId());
1590 event
.SetEventObject( this );
1591 GetEventHandler()->ProcessEvent(event
);
1594 // ----------------------------------------------------------------------------
1595 // context-sensitive help support
1596 // ----------------------------------------------------------------------------
1600 // associate this help text with this window
1601 void wxWindowBase::SetHelpText(const wxString
& text
)
1603 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1606 helpProvider
->AddHelp(this, text
);
1610 // associate this help text with all windows with the same id as this
1612 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1614 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1617 helpProvider
->AddHelp(GetId(), text
);
1621 // get the help string associated with this window (may be empty)
1622 // default implementation forwards calls to the help provider
1624 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1625 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1628 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1631 text
= helpProvider
->GetHelp(this);
1637 // show help for this window
1638 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1640 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1643 if ( helpProvider
->ShowHelpAtPoint(this, event
.GetPosition(), event
.GetOrigin()) )
1645 // skip the event.Skip() below
1653 #endif // wxUSE_HELP
1655 // ----------------------------------------------------------------------------
1657 // ----------------------------------------------------------------------------
1661 void wxWindowBase::SetToolTip( const wxString
&tip
)
1663 // don't create the new tooltip if we already have one
1666 m_tooltip
->SetTip( tip
);
1670 SetToolTip( new wxToolTip( tip
) );
1673 // setting empty tooltip text does not remove the tooltip any more - use
1674 // SetToolTip((wxToolTip *)NULL) for this
1677 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1679 if ( m_tooltip
!= tooltip
)
1684 m_tooltip
= tooltip
;
1688 #endif // wxUSE_TOOLTIPS
1690 // ----------------------------------------------------------------------------
1691 // constraints and sizers
1692 // ----------------------------------------------------------------------------
1694 #if wxUSE_CONSTRAINTS
1696 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1698 if ( m_constraints
)
1700 UnsetConstraints(m_constraints
);
1701 delete m_constraints
;
1703 m_constraints
= constraints
;
1704 if ( m_constraints
)
1706 // Make sure other windows know they're part of a 'meaningful relationship'
1707 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1708 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1709 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1710 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1711 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1712 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1713 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1714 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1715 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1716 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1717 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1718 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1719 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1720 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1721 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1722 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1726 // This removes any dangling pointers to this window in other windows'
1727 // constraintsInvolvedIn lists.
1728 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1732 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1733 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1734 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1735 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1736 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1737 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1738 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1739 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1740 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1741 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1742 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1743 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1744 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1745 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1746 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1747 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1751 // Back-pointer to other windows we're involved with, so if we delete this
1752 // window, we must delete any constraints we're involved with.
1753 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1755 if ( !m_constraintsInvolvedIn
)
1756 m_constraintsInvolvedIn
= new wxWindowList
;
1757 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1758 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1761 // REMOVE back-pointer to other windows we're involved with.
1762 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1764 if ( m_constraintsInvolvedIn
)
1765 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1768 // Reset any constraints that mention this window
1769 void wxWindowBase::DeleteRelatedConstraints()
1771 if ( m_constraintsInvolvedIn
)
1773 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1776 wxWindow
*win
= node
->GetData();
1777 wxLayoutConstraints
*constr
= win
->GetConstraints();
1779 // Reset any constraints involving this window
1782 constr
->left
.ResetIfWin(this);
1783 constr
->top
.ResetIfWin(this);
1784 constr
->right
.ResetIfWin(this);
1785 constr
->bottom
.ResetIfWin(this);
1786 constr
->width
.ResetIfWin(this);
1787 constr
->height
.ResetIfWin(this);
1788 constr
->centreX
.ResetIfWin(this);
1789 constr
->centreY
.ResetIfWin(this);
1792 wxWindowList::compatibility_iterator next
= node
->GetNext();
1793 m_constraintsInvolvedIn
->Erase(node
);
1797 delete m_constraintsInvolvedIn
;
1798 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1802 #endif // wxUSE_CONSTRAINTS
1804 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1806 if ( sizer
== m_windowSizer
)
1809 if ( m_windowSizer
)
1811 m_windowSizer
->SetContainingWindow(NULL
);
1814 delete m_windowSizer
;
1817 m_windowSizer
= sizer
;
1818 if ( m_windowSizer
)
1820 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
1823 SetAutoLayout(m_windowSizer
!= NULL
);
1826 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1828 SetSizer( sizer
, deleteOld
);
1829 sizer
->SetSizeHints( (wxWindow
*) this );
1833 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1835 // adding a window to a sizer twice is going to result in fatal and
1836 // hard to debug problems later because when deleting the second
1837 // associated wxSizerItem we're going to dereference a dangling
1838 // pointer; so try to detect this as early as possible
1839 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1840 _T("Adding a window to the same sizer twice?") );
1842 m_containingSizer
= sizer
;
1845 #if wxUSE_CONSTRAINTS
1847 void wxWindowBase::SatisfyConstraints()
1849 wxLayoutConstraints
*constr
= GetConstraints();
1850 bool wasOk
= constr
&& constr
->AreSatisfied();
1852 ResetConstraints(); // Mark all constraints as unevaluated
1856 // if we're a top level panel (i.e. our parent is frame/dialog), our
1857 // own constraints will never be satisfied any more unless we do it
1861 while ( noChanges
> 0 )
1863 LayoutPhase1(&noChanges
);
1867 LayoutPhase2(&noChanges
);
1870 #endif // wxUSE_CONSTRAINTS
1872 bool wxWindowBase::Layout()
1874 // If there is a sizer, use it instead of the constraints
1878 GetVirtualSize(&w
, &h
);
1879 GetSizer()->SetDimension( 0, 0, w
, h
);
1881 #if wxUSE_CONSTRAINTS
1884 SatisfyConstraints(); // Find the right constraints values
1885 SetConstraintSizes(); // Recursively set the real window sizes
1892 #if wxUSE_CONSTRAINTS
1894 // first phase of the constraints evaluation: set our own constraints
1895 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1897 wxLayoutConstraints
*constr
= GetConstraints();
1899 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1902 // second phase: set the constraints for our children
1903 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1910 // Layout grand children
1916 // Do a phase of evaluating child constraints
1917 bool wxWindowBase::DoPhase(int phase
)
1919 // the list containing the children for which the constraints are already
1921 wxWindowList succeeded
;
1923 // the max number of iterations we loop before concluding that we can't set
1925 static const int maxIterations
= 500;
1927 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1931 // loop over all children setting their constraints
1932 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1934 node
= node
->GetNext() )
1936 wxWindow
*child
= node
->GetData();
1937 if ( child
->IsTopLevel() )
1939 // top level children are not inside our client area
1943 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1945 // this one is either already ok or nothing we can do about it
1949 int tempNoChanges
= 0;
1950 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1951 : child
->LayoutPhase2(&tempNoChanges
);
1952 noChanges
+= tempNoChanges
;
1956 succeeded
.Append(child
);
1962 // constraints are set
1970 void wxWindowBase::ResetConstraints()
1972 wxLayoutConstraints
*constr
= GetConstraints();
1975 constr
->left
.SetDone(false);
1976 constr
->top
.SetDone(false);
1977 constr
->right
.SetDone(false);
1978 constr
->bottom
.SetDone(false);
1979 constr
->width
.SetDone(false);
1980 constr
->height
.SetDone(false);
1981 constr
->centreX
.SetDone(false);
1982 constr
->centreY
.SetDone(false);
1985 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1988 wxWindow
*win
= node
->GetData();
1989 if ( !win
->IsTopLevel() )
1990 win
->ResetConstraints();
1991 node
= node
->GetNext();
1995 // Need to distinguish between setting the 'fake' size for windows and sizers,
1996 // and setting the real values.
1997 void wxWindowBase::SetConstraintSizes(bool recurse
)
1999 wxLayoutConstraints
*constr
= GetConstraints();
2000 if ( constr
&& constr
->AreSatisfied() )
2002 int x
= constr
->left
.GetValue();
2003 int y
= constr
->top
.GetValue();
2004 int w
= constr
->width
.GetValue();
2005 int h
= constr
->height
.GetValue();
2007 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
2008 (constr
->height
.GetRelationship() != wxAsIs
) )
2010 SetSize(x
, y
, w
, h
);
2014 // If we don't want to resize this window, just move it...
2020 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
2021 GetClassInfo()->GetClassName(),
2027 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2030 wxWindow
*win
= node
->GetData();
2031 if ( !win
->IsTopLevel() && win
->GetConstraints() )
2032 win
->SetConstraintSizes();
2033 node
= node
->GetNext();
2038 // Only set the size/position of the constraint (if any)
2039 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
2041 wxLayoutConstraints
*constr
= GetConstraints();
2044 if ( x
!= wxDefaultCoord
)
2046 constr
->left
.SetValue(x
);
2047 constr
->left
.SetDone(true);
2049 if ( y
!= wxDefaultCoord
)
2051 constr
->top
.SetValue(y
);
2052 constr
->top
.SetDone(true);
2054 if ( w
!= wxDefaultCoord
)
2056 constr
->width
.SetValue(w
);
2057 constr
->width
.SetDone(true);
2059 if ( h
!= wxDefaultCoord
)
2061 constr
->height
.SetValue(h
);
2062 constr
->height
.SetDone(true);
2067 void wxWindowBase::MoveConstraint(int x
, int y
)
2069 wxLayoutConstraints
*constr
= GetConstraints();
2072 if ( x
!= wxDefaultCoord
)
2074 constr
->left
.SetValue(x
);
2075 constr
->left
.SetDone(true);
2077 if ( y
!= wxDefaultCoord
)
2079 constr
->top
.SetValue(y
);
2080 constr
->top
.SetDone(true);
2085 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2087 wxLayoutConstraints
*constr
= GetConstraints();
2090 *w
= constr
->width
.GetValue();
2091 *h
= constr
->height
.GetValue();
2097 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2099 wxLayoutConstraints
*constr
= GetConstraints();
2102 *w
= constr
->width
.GetValue();
2103 *h
= constr
->height
.GetValue();
2106 GetClientSize(w
, h
);
2109 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2111 wxLayoutConstraints
*constr
= GetConstraints();
2114 *x
= constr
->left
.GetValue();
2115 *y
= constr
->top
.GetValue();
2121 #endif // wxUSE_CONSTRAINTS
2123 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2125 // don't do it for the dialogs/frames - they float independently of their
2127 if ( !IsTopLevel() )
2129 wxWindow
*parent
= GetParent();
2130 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2132 wxPoint
pt(parent
->GetClientAreaOrigin());
2139 // ----------------------------------------------------------------------------
2140 // Update UI processing
2141 // ----------------------------------------------------------------------------
2143 void wxWindowBase::UpdateWindowUI(long flags
)
2145 wxUpdateUIEvent
event(GetId());
2146 event
.SetEventObject(this);
2148 if ( GetEventHandler()->ProcessEvent(event
) )
2150 DoUpdateWindowUI(event
);
2153 if (flags
& wxUPDATE_UI_RECURSE
)
2155 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2158 wxWindow
* child
= (wxWindow
*) node
->GetData();
2159 child
->UpdateWindowUI(flags
);
2160 node
= node
->GetNext();
2165 // do the window-specific processing after processing the update event
2166 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2168 if ( event
.GetSetEnabled() )
2169 Enable(event
.GetEnabled());
2171 if ( event
.GetSetShown() )
2172 Show(event
.GetShown());
2175 // ----------------------------------------------------------------------------
2176 // dialog units translations
2177 // ----------------------------------------------------------------------------
2179 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2181 int charWidth
= GetCharWidth();
2182 int charHeight
= GetCharHeight();
2183 wxPoint pt2
= wxDefaultPosition
;
2184 if (pt
.x
!= wxDefaultCoord
)
2185 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2186 if (pt
.y
!= wxDefaultCoord
)
2187 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2192 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2194 int charWidth
= GetCharWidth();
2195 int charHeight
= GetCharHeight();
2196 wxPoint pt2
= wxDefaultPosition
;
2197 if (pt
.x
!= wxDefaultCoord
)
2198 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2199 if (pt
.y
!= wxDefaultCoord
)
2200 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2205 // ----------------------------------------------------------------------------
2207 // ----------------------------------------------------------------------------
2209 // propagate the colour change event to the subwindows
2210 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2212 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2215 // Only propagate to non-top-level windows
2216 wxWindow
*win
= node
->GetData();
2217 if ( !win
->IsTopLevel() )
2219 wxSysColourChangedEvent event2
;
2220 event
.SetEventObject(win
);
2221 win
->GetEventHandler()->ProcessEvent(event2
);
2224 node
= node
->GetNext();
2230 // the default action is to populate dialog with data when it's created,
2231 // and nudge the UI into displaying itself correctly in case
2232 // we've turned the wxUpdateUIEvents frequency down low.
2233 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2235 TransferDataToWindow();
2237 // Update the UI at this point
2238 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2241 // methods for drawing the sizers in a visible way
2244 static void DrawSizers(wxWindowBase
*win
);
2246 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2248 wxClientDC
dc((wxWindow
*)win
);
2249 dc
.SetPen(*wxRED_PEN
);
2250 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2251 dc
.DrawRectangle(rect
.Deflate(1, 1));
2254 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2256 const wxSizerItemList
& items
= sizer
->GetChildren();
2257 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2262 wxSizerItem
*item
= *i
;
2263 if ( item
->IsSizer() )
2265 DrawBorder(win
, item
->GetRect().Deflate(2));
2266 DrawSizer(win
, item
->GetSizer());
2268 else if ( item
->IsSpacer() )
2270 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2272 else if ( item
->IsWindow() )
2274 DrawSizers(item
->GetWindow());
2279 static void DrawSizers(wxWindowBase
*win
)
2281 wxSizer
*sizer
= win
->GetSizer();
2284 DrawBorder(win
, win
->GetClientSize());
2285 DrawSizer(win
, sizer
);
2287 else // no sizer, still recurse into the children
2289 const wxWindowList
& children
= win
->GetChildren();
2290 for ( wxWindowList::const_iterator i
= children
.begin(),
2291 end
= children
.end();
2300 #endif // __WXDEBUG__
2302 // process special middle clicks
2303 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2305 if ( event
.ControlDown() && event
.AltDown() )
2308 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2309 if ( event
.ShiftDown() )
2314 #endif // __WXDEBUG__
2317 // don't translate these strings, they're for diagnostics purposes only
2319 msg
.Printf(_T("wxWidgets Library (%s port)\n")
2320 _T("Version %d.%d.%d%s%s, compiled at %s %s\n")
2321 _T("Runtime version of toolkit used is %d.%d.%s\n")
2322 _T("Copyright (c) 1995-2007 wxWidgets team"),
2323 wxPlatformInfo::Get().GetPortIdName().c_str(),
2339 wxPlatformInfo::Get().GetToolkitMajorVersion(),
2340 wxPlatformInfo::Get().GetToolkitMinorVersion(),
2342 wxString::Format(_T("\nThe compile-time GTK+ version is %d.%d.%d."), GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
).c_str()
2348 wxMessageBox(msg
, _T("wxWidgets information"),
2349 wxICON_INFORMATION
| wxOK
,
2351 #endif // wxUSE_MSGDLG
2359 // ----------------------------------------------------------------------------
2361 // ----------------------------------------------------------------------------
2363 #if wxUSE_ACCESSIBILITY
2364 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2366 if (m_accessible
&& (accessible
!= m_accessible
))
2367 delete m_accessible
;
2368 m_accessible
= accessible
;
2370 m_accessible
->SetWindow((wxWindow
*) this);
2373 // Returns the accessible object, creating if necessary.
2374 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2377 m_accessible
= CreateAccessible();
2378 return m_accessible
;
2381 // Override to create a specific accessible object.
2382 wxAccessible
* wxWindowBase::CreateAccessible()
2384 return new wxWindowAccessible((wxWindow
*) this);
2389 // ----------------------------------------------------------------------------
2390 // list classes implementation
2391 // ----------------------------------------------------------------------------
2395 #include "wx/listimpl.cpp"
2396 WX_DEFINE_LIST(wxWindowList
)
2400 void wxWindowListNode::DeleteData()
2402 delete (wxWindow
*)GetData();
2405 #endif // wxUSE_STL/!wxUSE_STL
2407 // ----------------------------------------------------------------------------
2409 // ----------------------------------------------------------------------------
2411 wxBorder
wxWindowBase::GetBorder(long flags
) const
2413 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2414 if ( border
== wxBORDER_DEFAULT
)
2416 border
= GetDefaultBorder();
2422 wxBorder
wxWindowBase::GetDefaultBorder() const
2424 return wxBORDER_NONE
;
2427 // ----------------------------------------------------------------------------
2429 // ----------------------------------------------------------------------------
2431 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2433 // here we just check if the point is inside the window or not
2435 // check the top and left border first
2436 bool outside
= x
< 0 || y
< 0;
2439 // check the right and bottom borders too
2440 wxSize size
= GetSize();
2441 outside
= x
>= size
.x
|| y
>= size
.y
;
2444 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2447 // ----------------------------------------------------------------------------
2449 // ----------------------------------------------------------------------------
2451 struct WXDLLEXPORT wxWindowNext
2455 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2456 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2457 bool wxWindowBase::ms_winCaptureChanging
= false;
2459 void wxWindowBase::CaptureMouse()
2461 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2463 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2465 ms_winCaptureChanging
= true;
2467 wxWindow
*winOld
= GetCapture();
2470 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2473 wxWindowNext
*item
= new wxWindowNext
;
2475 item
->next
= ms_winCaptureNext
;
2476 ms_winCaptureNext
= item
;
2478 //else: no mouse capture to save
2481 ms_winCaptureCurrent
= (wxWindow
*)this;
2483 ms_winCaptureChanging
= false;
2486 void wxWindowBase::ReleaseMouse()
2488 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2490 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2492 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2494 ms_winCaptureChanging
= true;
2497 ms_winCaptureCurrent
= NULL
;
2499 if ( ms_winCaptureNext
)
2501 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2502 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2504 wxWindowNext
*item
= ms_winCaptureNext
;
2505 ms_winCaptureNext
= item
->next
;
2508 //else: stack is empty, no previous capture
2510 ms_winCaptureChanging
= false;
2512 wxLogTrace(_T("mousecapture"),
2513 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2514 wx_static_cast(void*, GetCapture()));
2517 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2519 wxMouseCaptureLostEvent
event(win
->GetId());
2520 event
.SetEventObject(win
);
2521 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2523 // windows must handle this event, otherwise the app wouldn't behave
2524 // correctly if it loses capture unexpectedly; see the discussion here:
2525 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
2526 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
2527 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2532 void wxWindowBase::NotifyCaptureLost()
2534 // don't do anything if capture lost was expected, i.e. resulted from
2535 // a wx call to ReleaseMouse or CaptureMouse:
2536 if ( ms_winCaptureChanging
)
2539 // if the capture was lost unexpectedly, notify every window that has
2540 // capture (on stack or current) about it and clear the stack:
2542 if ( ms_winCaptureCurrent
)
2544 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2545 ms_winCaptureCurrent
= NULL
;
2548 while ( ms_winCaptureNext
)
2550 wxWindowNext
*item
= ms_winCaptureNext
;
2551 ms_winCaptureNext
= item
->next
;
2553 DoNotifyWindowAboutCaptureLost(item
->win
);
2562 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2563 int WXUNUSED(modifiers
),
2564 int WXUNUSED(keycode
))
2570 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2576 #endif // wxUSE_HOTKEY
2578 // ----------------------------------------------------------------------------
2580 // ----------------------------------------------------------------------------
2582 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2584 #if wxUSE_VALIDATORS
2585 // Can only use the validator of the window which
2586 // is receiving the event
2587 if ( event
.GetEventObject() == this )
2589 wxValidator
*validator
= GetValidator();
2590 if ( validator
&& validator
->ProcessEvent(event
) )
2595 #endif // wxUSE_VALIDATORS
2600 bool wxWindowBase::TryParent(wxEvent
& event
)
2602 // carry on up the parent-child hierarchy if the propagation count hasn't
2604 if ( event
.ShouldPropagate() )
2606 // honour the requests to stop propagation at this window: this is
2607 // used by the dialogs, for example, to prevent processing the events
2608 // from the dialog controls in the parent frame which rarely, if ever,
2610 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2612 wxWindow
*parent
= GetParent();
2613 if ( parent
&& !parent
->IsBeingDeleted() )
2615 wxPropagateOnce
propagateOnce(event
);
2617 return parent
->GetEventHandler()->ProcessEvent(event
);
2622 return wxEvtHandler::TryParent(event
);
2625 // ----------------------------------------------------------------------------
2626 // keyboard navigation
2627 // ----------------------------------------------------------------------------
2629 // Navigates in the specified direction inside this window
2630 bool wxWindowBase::DoNavigateIn(int flags
)
2632 #ifdef wxHAS_NATIVE_TAB_TRAVERSAL
2633 // native code doesn't process our wxNavigationKeyEvents anyhow
2635 #else // !wxHAS_NATIVE_TAB_TRAVERSAL
2636 wxNavigationKeyEvent eventNav
;
2637 eventNav
.SetFlags(flags
);
2638 eventNav
.SetEventObject(FindFocus());
2639 return GetEventHandler()->ProcessEvent(eventNav
);
2640 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
2643 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2645 // check that we're not a top level window
2646 wxCHECK_RET( GetParent(),
2647 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2649 // detect the special case when we have nothing to do anyhow and when the
2650 // code below wouldn't work
2654 // find the target window in the siblings list
2655 wxWindowList
& siblings
= GetParent()->GetChildren();
2656 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2657 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2659 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2660 // can't just move the node around
2661 wxWindow
*self
= (wxWindow
*)this;
2662 siblings
.DeleteObject(self
);
2663 if ( move
== MoveAfter
)
2670 siblings
.Insert(i
, self
);
2672 else // MoveAfter and win was the last sibling
2674 siblings
.Append(self
);
2678 // ----------------------------------------------------------------------------
2680 // ----------------------------------------------------------------------------
2682 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2684 wxWindowBase
*win
= DoFindFocus();
2685 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2688 // ----------------------------------------------------------------------------
2690 // ----------------------------------------------------------------------------
2692 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2694 while ( win
&& !win
->IsTopLevel() )
2695 win
= win
->GetParent();
2700 #if wxUSE_ACCESSIBILITY
2701 // ----------------------------------------------------------------------------
2702 // accessible object for windows
2703 // ----------------------------------------------------------------------------
2705 // Can return either a child object, or an integer
2706 // representing the child element, starting from 1.
2707 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2709 wxASSERT( GetWindow() != NULL
);
2713 return wxACC_NOT_IMPLEMENTED
;
2716 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2717 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2719 wxASSERT( GetWindow() != NULL
);
2723 wxWindow
* win
= NULL
;
2730 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2732 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2739 rect
= win
->GetRect();
2740 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2741 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2745 return wxACC_NOT_IMPLEMENTED
;
2748 // Navigates from fromId to toId/toObject.
2749 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2750 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2752 wxASSERT( GetWindow() != NULL
);
2758 case wxNAVDIR_FIRSTCHILD
:
2760 if (GetWindow()->GetChildren().GetCount() == 0)
2762 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2763 *toObject
= childWindow
->GetOrCreateAccessible();
2767 case wxNAVDIR_LASTCHILD
:
2769 if (GetWindow()->GetChildren().GetCount() == 0)
2771 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2772 *toObject
= childWindow
->GetOrCreateAccessible();
2776 case wxNAVDIR_RIGHT
:
2780 wxWindowList::compatibility_iterator node
=
2781 wxWindowList::compatibility_iterator();
2784 // Can't navigate to sibling of this window
2785 // if we're a top-level window.
2786 if (!GetWindow()->GetParent())
2787 return wxACC_NOT_IMPLEMENTED
;
2789 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2793 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2794 node
= GetWindow()->GetChildren().Item(fromId
-1);
2797 if (node
&& node
->GetNext())
2799 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2800 *toObject
= nextWindow
->GetOrCreateAccessible();
2808 case wxNAVDIR_PREVIOUS
:
2810 wxWindowList::compatibility_iterator node
=
2811 wxWindowList::compatibility_iterator();
2814 // Can't navigate to sibling of this window
2815 // if we're a top-level window.
2816 if (!GetWindow()->GetParent())
2817 return wxACC_NOT_IMPLEMENTED
;
2819 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2823 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2824 node
= GetWindow()->GetChildren().Item(fromId
-1);
2827 if (node
&& node
->GetPrevious())
2829 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2830 *toObject
= previousWindow
->GetOrCreateAccessible();
2838 return wxACC_NOT_IMPLEMENTED
;
2841 // Gets the name of the specified object.
2842 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2844 wxASSERT( GetWindow() != NULL
);
2850 // If a child, leave wxWidgets to call the function on the actual
2853 return wxACC_NOT_IMPLEMENTED
;
2855 // This will eventually be replaced by specialised
2856 // accessible classes, one for each kind of wxWidgets
2857 // control or window.
2859 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2860 title
= ((wxButton
*) GetWindow())->GetLabel();
2863 title
= GetWindow()->GetName();
2871 return wxACC_NOT_IMPLEMENTED
;
2874 // Gets the number of children.
2875 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2877 wxASSERT( GetWindow() != NULL
);
2881 *childId
= (int) GetWindow()->GetChildren().GetCount();
2885 // Gets the specified child (starting from 1).
2886 // If *child is NULL and return value is wxACC_OK,
2887 // this means that the child is a simple element and
2888 // not an accessible object.
2889 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2891 wxASSERT( GetWindow() != NULL
);
2901 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2904 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2905 *child
= childWindow
->GetOrCreateAccessible();
2912 // Gets the parent, or NULL.
2913 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2915 wxASSERT( GetWindow() != NULL
);
2919 wxWindow
* parentWindow
= GetWindow()->GetParent();
2927 *parent
= parentWindow
->GetOrCreateAccessible();
2935 // Performs the default action. childId is 0 (the action for this object)
2936 // or > 0 (the action for a child).
2937 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2938 // window (e.g. an edit control).
2939 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2941 wxASSERT( GetWindow() != NULL
);
2945 return wxACC_NOT_IMPLEMENTED
;
2948 // Gets the default action for this object (0) or > 0 (the action for a child).
2949 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2950 // string if there is no action.
2951 // The retrieved string describes the action that is performed on an object,
2952 // not what the object does as a result. For example, a toolbar button that prints
2953 // a document has a default action of "Press" rather than "Prints the current document."
2954 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2956 wxASSERT( GetWindow() != NULL
);
2960 return wxACC_NOT_IMPLEMENTED
;
2963 // Returns the description for this object or a child.
2964 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2966 wxASSERT( GetWindow() != NULL
);
2970 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2976 return wxACC_NOT_IMPLEMENTED
;
2979 // Returns help text for this object or a child, similar to tooltip text.
2980 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2982 wxASSERT( GetWindow() != NULL
);
2986 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2992 return wxACC_NOT_IMPLEMENTED
;
2995 // Returns the keyboard shortcut for this object or child.
2996 // Return e.g. ALT+K
2997 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2999 wxASSERT( GetWindow() != NULL
);
3003 return wxACC_NOT_IMPLEMENTED
;
3006 // Returns a role constant.
3007 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
3009 wxASSERT( GetWindow() != NULL
);
3013 // If a child, leave wxWidgets to call the function on the actual
3016 return wxACC_NOT_IMPLEMENTED
;
3018 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3019 return wxACC_NOT_IMPLEMENTED
;
3021 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3022 return wxACC_NOT_IMPLEMENTED
;
3025 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3026 return wxACC_NOT_IMPLEMENTED
;
3029 //*role = wxROLE_SYSTEM_CLIENT;
3030 *role
= wxROLE_SYSTEM_CLIENT
;
3034 return wxACC_NOT_IMPLEMENTED
;
3038 // Returns a state constant.
3039 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
3041 wxASSERT( GetWindow() != NULL
);
3045 // If a child, leave wxWidgets to call the function on the actual
3048 return wxACC_NOT_IMPLEMENTED
;
3050 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3051 return wxACC_NOT_IMPLEMENTED
;
3054 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3055 return wxACC_NOT_IMPLEMENTED
;
3058 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3059 return wxACC_NOT_IMPLEMENTED
;
3066 return wxACC_NOT_IMPLEMENTED
;
3070 // Returns a localized string representing the value for the object
3072 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3074 wxASSERT( GetWindow() != NULL
);
3078 return wxACC_NOT_IMPLEMENTED
;
3081 // Selects the object or child.
3082 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3084 wxASSERT( GetWindow() != NULL
);
3088 return wxACC_NOT_IMPLEMENTED
;
3091 // Gets the window with the keyboard focus.
3092 // If childId is 0 and child is NULL, no object in
3093 // this subhierarchy has the focus.
3094 // If this object has the focus, child should be 'this'.
3095 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3097 wxASSERT( GetWindow() != NULL
);
3101 return wxACC_NOT_IMPLEMENTED
;
3105 // Gets a variant representing the selected children
3107 // Acceptable values:
3108 // - a null variant (IsNull() returns true)
3109 // - a list variant (GetType() == wxT("list")
3110 // - an integer representing the selected child element,
3111 // or 0 if this object is selected (GetType() == wxT("long")
3112 // - a "void*" pointer to a wxAccessible child object
3113 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3115 wxASSERT( GetWindow() != NULL
);
3119 return wxACC_NOT_IMPLEMENTED
;
3121 #endif // wxUSE_VARIANT
3123 #endif // wxUSE_ACCESSIBILITY
3125 // ----------------------------------------------------------------------------
3127 // ----------------------------------------------------------------------------
3130 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3132 wxCoord widthTotal
) const
3134 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3136 x
= widthTotal
- x
- width
;