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
;
255 SetWindowStyleFlag(style
);
259 SetValidator(validator
);
260 #endif // wxUSE_VALIDATORS
262 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
263 // have it too - like this it's possible to set it only in the top level
264 // dialog/frame and all children will inherit it by defult
265 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
267 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
273 // ----------------------------------------------------------------------------
275 // ----------------------------------------------------------------------------
278 wxWindowBase::~wxWindowBase()
280 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
282 // FIXME if these 2 cases result from programming errors in the user code
283 // we should probably assert here instead of silently fixing them
285 // Just in case the window has been Closed, but we're then deleting
286 // immediately: don't leave dangling pointers.
287 wxPendingDelete
.DeleteObject(this);
289 // Just in case we've loaded a top-level window via LoadNativeDialog but
290 // we weren't a dialog class
291 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
293 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
295 // reset the top-level parent's default item if it is this widget
298 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this),
301 if ( tlw
&& tlw
->GetDefaultItem() == this )
302 tlw
->SetDefaultItem(NULL
);
303 if ( tlw
&& tlw
->GetTmpDefaultItem() == this )
304 tlw
->SetTmpDefaultItem(NULL
);
307 // reset the dangling pointer our parent window may keep to us
310 m_parent
->RemoveChild(this);
315 #endif // wxUSE_CARET
318 delete m_windowValidator
;
319 #endif // wxUSE_VALIDATORS
321 #if wxUSE_CONSTRAINTS
322 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
323 // at deleted windows as they delete themselves.
324 DeleteRelatedConstraints();
328 // This removes any dangling pointers to this window in other windows'
329 // constraintsInvolvedIn lists.
330 UnsetConstraints(m_constraints
);
331 delete m_constraints
;
332 m_constraints
= NULL
;
334 #endif // wxUSE_CONSTRAINTS
336 if ( m_containingSizer
)
337 m_containingSizer
->Detach( (wxWindow
*)this );
339 delete m_windowSizer
;
341 #if wxUSE_DRAG_AND_DROP
343 #endif // wxUSE_DRAG_AND_DROP
347 #endif // wxUSE_TOOLTIPS
349 #if wxUSE_ACCESSIBILITY
354 bool wxWindowBase::Destroy()
361 bool wxWindowBase::Close(bool force
)
363 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
364 event
.SetEventObject(this);
365 event
.SetCanVeto(!force
);
367 // return false if window wasn't closed because the application vetoed the
369 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
372 bool wxWindowBase::DestroyChildren()
374 wxWindowList::compatibility_iterator node
;
377 // we iterate until the list becomes empty
378 node
= GetChildren().GetFirst();
382 wxWindow
*child
= node
->GetData();
384 // note that we really want to call delete and not ->Destroy() here
385 // because we want to delete the child immediately, before we are
386 // deleted, and delayed deletion would result in problems as our (top
387 // level) child could outlive its parent
390 wxASSERT_MSG( !GetChildren().Find(child
),
391 wxT("child didn't remove itself using RemoveChild()") );
397 // ----------------------------------------------------------------------------
398 // size/position related methods
399 // ----------------------------------------------------------------------------
401 // centre the window with respect to its parent in either (or both) directions
402 void wxWindowBase::DoCentre(int dir
)
404 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
405 _T("this method only implements centering child windows") );
407 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
410 // fits the window around the children
411 void wxWindowBase::Fit()
413 if ( !GetChildren().empty() )
415 SetSize(GetBestSize());
417 //else: do nothing if we have no children
420 // fits virtual size (ie. scrolled area etc.) around children
421 void wxWindowBase::FitInside()
423 if ( GetChildren().GetCount() > 0 )
425 SetVirtualSize( GetBestVirtualSize() );
429 // On Mac, scrollbars are explicitly children.
431 static bool wxHasRealChildren(const wxWindowBase
* win
)
433 int realChildCount
= 0;
435 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
437 node
= node
->GetNext() )
439 wxWindow
*win
= node
->GetData();
440 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
443 return (realChildCount
> 0);
447 void wxWindowBase::InvalidateBestSize()
449 m_bestSizeCache
= wxDefaultSize
;
451 // parent's best size calculation may depend on its children's
452 // as long as child window we are in is not top level window itself
453 // (because the TLW size is never resized automatically)
454 // so let's invalidate it as well to be safe:
455 if (m_parent
&& !IsTopLevel())
456 m_parent
->InvalidateBestSize();
459 // return the size best suited for the current window
460 wxSize
wxWindowBase::DoGetBestSize() const
466 best
= GetWindowSizeForVirtualSize(m_windowSizer
->GetMinSize());
468 #if wxUSE_CONSTRAINTS
469 else if ( m_constraints
)
471 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
473 // our minimal acceptable size is such that all our windows fit inside
477 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
479 node
= node
->GetNext() )
481 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
484 // it's not normal that we have an unconstrained child, but
485 // what can we do about it?
489 int x
= c
->right
.GetValue(),
490 y
= c
->bottom
.GetValue();
498 // TODO: we must calculate the overlaps somehow, otherwise we
499 // will never return a size bigger than the current one :-(
502 best
= wxSize(maxX
, maxY
);
504 #endif // wxUSE_CONSTRAINTS
505 else if ( !GetChildren().empty()
507 && wxHasRealChildren(this)
511 // our minimal acceptable size is such that all our visible child
512 // windows fit inside
516 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
518 node
= node
->GetNext() )
520 wxWindow
*win
= node
->GetData();
521 if ( win
->IsTopLevel()
524 || wxDynamicCast(win
, wxStatusBar
)
525 #endif // wxUSE_STATUSBAR
528 // dialogs and frames lie in different top level windows -
529 // don't deal with them here; as for the status bars, they
530 // don't lie in the client area at all
535 win
->GetPosition(&wx
, &wy
);
537 // if the window hadn't been positioned yet, assume that it is in
539 if ( wx
== wxDefaultCoord
)
541 if ( wy
== wxDefaultCoord
)
544 win
->GetSize(&ww
, &wh
);
545 if ( wx
+ ww
> maxX
)
547 if ( wy
+ wh
> maxY
)
551 best
= wxSize(maxX
, maxY
);
553 else // ! has children
555 // for a generic window there is no natural best size so, if the
556 // minimal size is not set, use the current size but take care to
557 // remember it as minimal size for the next time because our best size
558 // should be constant: otherwise we could get into a situation when the
559 // window is initially at some size, then expanded to a larger size and
560 // then, when the containing window is shrunk back (because our initial
561 // best size had been used for computing the parent min size), we can't
562 // be shrunk back any more because our best size is now bigger
563 wxSize size
= GetMinSize();
564 if ( !size
.IsFullySpecified() )
566 size
.SetDefaults(GetSize());
567 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
570 // return as-is, unadjusted by the client size difference.
574 // Add any difference between size and client size
575 wxSize diff
= GetSize() - GetClientSize();
576 best
.x
+= wxMax(0, diff
.x
);
577 best
.y
+= wxMax(0, diff
.y
);
583 wxSize
wxWindowBase::GetEffectiveMinSize() const
585 // merge the best size with the min size, giving priority to the min size
586 wxSize min
= GetMinSize();
587 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
589 wxSize best
= GetBestSize();
590 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
591 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
597 void wxWindowBase::SetInitialSize(const wxSize
& size
)
599 // Set the min size to the size passed in. This will usually either be
600 // wxDefaultSize or the size passed to this window's ctor/Create function.
603 // Merge the size with the best size if needed
604 wxSize best
= GetEffectiveMinSize();
606 // If the current size doesn't match then change it
607 if (GetSize() != best
)
612 // by default the origin is not shifted
613 wxPoint
wxWindowBase::GetClientAreaOrigin() const
618 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
620 if ( m_windowVariant
!= variant
)
622 m_windowVariant
= variant
;
624 DoSetWindowVariant(variant
);
628 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
630 // adjust the font height to correspond to our new variant (notice that
631 // we're only called if something really changed)
632 wxFont font
= GetFont();
633 int size
= font
.GetPointSize();
636 case wxWINDOW_VARIANT_NORMAL
:
639 case wxWINDOW_VARIANT_SMALL
:
644 case wxWINDOW_VARIANT_MINI
:
649 case wxWINDOW_VARIANT_LARGE
:
655 wxFAIL_MSG(_T("unexpected window variant"));
659 font
.SetPointSize(size
);
663 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
665 int WXUNUSED(incW
), int WXUNUSED(incH
) )
667 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
668 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
669 _T("min width/height must be less than max width/height!") );
678 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
681 m_minVirtualWidth
= minW
;
682 m_maxVirtualWidth
= maxW
;
683 m_minVirtualHeight
= minH
;
684 m_maxVirtualHeight
= maxH
;
687 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
689 if ( m_minVirtualWidth
!= wxDefaultCoord
&& m_minVirtualWidth
> x
)
690 x
= m_minVirtualWidth
;
691 if ( m_maxVirtualWidth
!= wxDefaultCoord
&& m_maxVirtualWidth
< x
)
692 x
= m_maxVirtualWidth
;
693 if ( m_minVirtualHeight
!= wxDefaultCoord
&& m_minVirtualHeight
> y
)
694 y
= m_minVirtualHeight
;
695 if ( m_maxVirtualHeight
!= wxDefaultCoord
&& m_maxVirtualHeight
< y
)
696 y
= m_maxVirtualHeight
;
698 m_virtualSize
= wxSize(x
, y
);
701 wxSize
wxWindowBase::DoGetVirtualSize() const
703 // we should use the entire client area so if it is greater than our
704 // virtual size, expand it to fit (otherwise if the window is big enough we
705 // wouldn't be using parts of it)
706 wxSize size
= GetClientSize();
707 if ( m_virtualSize
.x
> size
.x
)
708 size
.x
= m_virtualSize
.x
;
710 if ( m_virtualSize
.y
>= size
.y
)
711 size
.y
= m_virtualSize
.y
;
716 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
718 // screen position is the same as (0, 0) in client coords for non TLWs (and
719 // TLWs override this method)
725 ClientToScreen(x
, y
);
728 // ----------------------------------------------------------------------------
729 // show/hide/enable/disable the window
730 // ----------------------------------------------------------------------------
732 bool wxWindowBase::Show(bool show
)
734 if ( show
!= m_isShown
)
746 bool wxWindowBase::Enable(bool enable
)
748 if ( enable
!= m_isEnabled
)
750 m_isEnabled
= enable
;
760 bool wxWindowBase::IsShownOnScreen() const
763 (GetParent() == NULL
|| GetParent()->IsShownOnScreen());
766 // ----------------------------------------------------------------------------
768 // ----------------------------------------------------------------------------
770 bool wxWindowBase::IsTopLevel() const
775 // ----------------------------------------------------------------------------
776 // reparenting the window
777 // ----------------------------------------------------------------------------
779 void wxWindowBase::AddChild(wxWindowBase
*child
)
781 wxCHECK_RET( child
, wxT("can't add a NULL child") );
783 // this should never happen and it will lead to a crash later if it does
784 // because RemoveChild() will remove only one node from the children list
785 // and the other(s) one(s) will be left with dangling pointers in them
786 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
788 GetChildren().Append((wxWindow
*)child
);
789 child
->SetParent(this);
792 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
794 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
796 GetChildren().DeleteObject((wxWindow
*)child
);
797 child
->SetParent(NULL
);
800 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
802 wxWindow
*oldParent
= GetParent();
803 if ( newParent
== oldParent
)
809 // unlink this window from the existing parent.
812 oldParent
->RemoveChild(this);
816 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
819 // add it to the new one
822 newParent
->AddChild(this);
826 wxTopLevelWindows
.Append((wxWindow
*)this);
832 // ----------------------------------------------------------------------------
833 // event handler stuff
834 // ----------------------------------------------------------------------------
836 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
838 wxEvtHandler
*handlerOld
= GetEventHandler();
840 handler
->SetNextHandler(handlerOld
);
843 GetEventHandler()->SetPreviousHandler(handler
);
845 SetEventHandler(handler
);
848 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
850 wxEvtHandler
*handlerA
= GetEventHandler();
853 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
854 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
857 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
858 SetEventHandler(handlerB
);
863 handlerA
= (wxEvtHandler
*)NULL
;
870 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
872 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
874 wxEvtHandler
*handlerPrev
= NULL
,
875 *handlerCur
= GetEventHandler();
878 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
880 if ( handlerCur
== handler
)
884 handlerPrev
->SetNextHandler(handlerNext
);
888 SetEventHandler(handlerNext
);
893 handlerNext
->SetPreviousHandler ( handlerPrev
);
896 handler
->SetNextHandler(NULL
);
897 handler
->SetPreviousHandler(NULL
);
902 handlerPrev
= handlerCur
;
903 handlerCur
= handlerNext
;
906 wxFAIL_MSG( _T("where has the event handler gone?") );
911 // ----------------------------------------------------------------------------
913 // ----------------------------------------------------------------------------
915 void wxWindowBase::InheritAttributes()
917 const wxWindowBase
* const parent
= GetParent();
921 // we only inherit attributes which had been explicitly set for the parent
922 // which ensures that this only happens if the user really wants it and
923 // not by default which wouldn't make any sense in modern GUIs where the
924 // controls don't all use the same fonts (nor colours)
925 if ( parent
->m_inheritFont
&& !m_hasFont
)
926 SetFont(parent
->GetFont());
928 // in addition, there is a possibility to explicitly forbid inheriting
929 // colours at each class level by overriding ShouldInheritColours()
930 if ( ShouldInheritColours() )
932 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
933 SetForegroundColour(parent
->GetForegroundColour());
935 // inheriting (solid) background colour is wrong as it totally breaks
936 // any kind of themed backgrounds
938 // instead, the controls should use the same background as their parent
939 // (ideally by not drawing it at all)
941 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
942 SetBackgroundColour(parent
->GetBackgroundColour());
947 /* static */ wxVisualAttributes
948 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
950 // it is important to return valid values for all attributes from here,
951 // GetXXX() below rely on this
952 wxVisualAttributes attrs
;
953 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
954 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
956 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
957 // the usual background colour than wxSYS_COLOUR_BTNFACE.
958 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
959 // colour on other platforms.
961 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
962 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
964 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
969 wxColour
wxWindowBase::GetBackgroundColour() const
971 if ( !m_backgroundColour
.Ok() )
973 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
975 // get our default background colour
976 wxColour colBg
= GetDefaultAttributes().colBg
;
978 // we must return some valid colour to avoid redoing this every time
979 // and also to avoid surprizing the applications written for older
980 // wxWidgets versions where GetBackgroundColour() always returned
981 // something -- so give them something even if it doesn't make sense
982 // for this window (e.g. it has a themed background)
984 colBg
= GetClassDefaultAttributes().colBg
;
989 return m_backgroundColour
;
992 wxColour
wxWindowBase::GetForegroundColour() const
994 // logic is the same as above
995 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
997 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
999 wxColour colFg
= GetDefaultAttributes().colFg
;
1002 colFg
= GetClassDefaultAttributes().colFg
;
1007 return m_foregroundColour
;
1010 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1012 if ( colour
== m_backgroundColour
)
1015 m_hasBgCol
= colour
.Ok();
1016 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1017 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1019 m_inheritBgCol
= m_hasBgCol
;
1020 m_backgroundColour
= colour
;
1021 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1025 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1027 if (colour
== m_foregroundColour
)
1030 m_hasFgCol
= colour
.Ok();
1031 m_inheritFgCol
= m_hasFgCol
;
1032 m_foregroundColour
= colour
;
1033 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1037 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1039 // setting an invalid cursor is ok, it means that we don't have any special
1041 if ( m_cursor
.IsSameAs(cursor
) )
1052 wxFont
wxWindowBase::GetFont() const
1054 // logic is the same as in GetBackgroundColour()
1057 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1059 wxFont font
= GetDefaultAttributes().font
;
1061 font
= GetClassDefaultAttributes().font
;
1069 bool wxWindowBase::SetFont(const wxFont
& font
)
1071 if ( font
== m_font
)
1078 m_hasFont
= font
.Ok();
1079 m_inheritFont
= m_hasFont
;
1081 InvalidateBestSize();
1088 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1090 m_hasCustomPalette
= true;
1093 // VZ: can anyone explain me what do we do here?
1094 wxWindowDC
d((wxWindow
*) this);
1098 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1100 wxWindow
*win
= (wxWindow
*)this;
1101 while ( win
&& !win
->HasCustomPalette() )
1103 win
= win
->GetParent();
1109 #endif // wxUSE_PALETTE
1112 void wxWindowBase::SetCaret(wxCaret
*caret
)
1123 wxASSERT_MSG( m_caret
->GetWindow() == this,
1124 wxT("caret should be created associated to this window") );
1127 #endif // wxUSE_CARET
1129 #if wxUSE_VALIDATORS
1130 // ----------------------------------------------------------------------------
1132 // ----------------------------------------------------------------------------
1134 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1136 if ( m_windowValidator
)
1137 delete m_windowValidator
;
1139 m_windowValidator
= (wxValidator
*)validator
.Clone();
1141 if ( m_windowValidator
)
1142 m_windowValidator
->SetWindow(this);
1144 #endif // wxUSE_VALIDATORS
1146 // ----------------------------------------------------------------------------
1147 // update region stuff
1148 // ----------------------------------------------------------------------------
1150 wxRect
wxWindowBase::GetUpdateClientRect() const
1152 wxRegion rgnUpdate
= GetUpdateRegion();
1153 rgnUpdate
.Intersect(GetClientRect());
1154 wxRect rectUpdate
= rgnUpdate
.GetBox();
1155 wxPoint ptOrigin
= GetClientAreaOrigin();
1156 rectUpdate
.x
-= ptOrigin
.x
;
1157 rectUpdate
.y
-= ptOrigin
.y
;
1162 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1164 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1167 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1169 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1172 void wxWindowBase::ClearBackground()
1174 // wxGTK uses its own version, no need to add never used code
1176 wxClientDC
dc((wxWindow
*)this);
1177 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1178 dc
.SetBackground(brush
);
1183 // ----------------------------------------------------------------------------
1184 // find child window by id or name
1185 // ----------------------------------------------------------------------------
1187 wxWindow
*wxWindowBase::FindWindow(long id
) const
1189 if ( id
== m_windowId
)
1190 return (wxWindow
*)this;
1192 wxWindowBase
*res
= (wxWindow
*)NULL
;
1193 wxWindowList::compatibility_iterator node
;
1194 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1196 wxWindowBase
*child
= node
->GetData();
1197 res
= child
->FindWindow( id
);
1200 return (wxWindow
*)res
;
1203 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1205 if ( name
== m_windowName
)
1206 return (wxWindow
*)this;
1208 wxWindowBase
*res
= (wxWindow
*)NULL
;
1209 wxWindowList::compatibility_iterator node
;
1210 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1212 wxWindow
*child
= node
->GetData();
1213 res
= child
->FindWindow(name
);
1216 return (wxWindow
*)res
;
1220 // find any window by id or name or label: If parent is non-NULL, look through
1221 // children for a label or title matching the specified string. If NULL, look
1222 // through all top-level windows.
1224 // to avoid duplicating code we reuse the same helper function but with
1225 // different comparators
1227 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1228 const wxString
& label
, long id
);
1231 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1234 return win
->GetLabel() == label
;
1238 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1241 return win
->GetName() == label
;
1245 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1248 return win
->GetId() == id
;
1251 // recursive helper for the FindWindowByXXX() functions
1253 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1254 const wxString
& label
,
1256 wxFindWindowCmp cmp
)
1260 // see if this is the one we're looking for
1261 if ( (*cmp
)(parent
, label
, id
) )
1262 return (wxWindow
*)parent
;
1264 // It wasn't, so check all its children
1265 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1267 node
= node
->GetNext() )
1269 // recursively check each child
1270 wxWindow
*win
= (wxWindow
*)node
->GetData();
1271 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1281 // helper for FindWindowByXXX()
1283 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1284 const wxString
& label
,
1286 wxFindWindowCmp cmp
)
1290 // just check parent and all its children
1291 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1294 // start at very top of wx's windows
1295 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1297 node
= node
->GetNext() )
1299 // recursively check each window & its children
1300 wxWindow
*win
= node
->GetData();
1301 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1311 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1313 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1318 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1320 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1324 // fall back to the label
1325 win
= FindWindowByLabel(title
, parent
);
1333 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1335 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1338 // ----------------------------------------------------------------------------
1339 // dialog oriented functions
1340 // ----------------------------------------------------------------------------
1342 void wxWindowBase::MakeModal(bool modal
)
1344 // Disable all other windows
1347 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1350 wxWindow
*win
= node
->GetData();
1352 win
->Enable(!modal
);
1354 node
= node
->GetNext();
1359 bool wxWindowBase::Validate()
1361 #if wxUSE_VALIDATORS
1362 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1364 wxWindowList::compatibility_iterator node
;
1365 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1367 wxWindowBase
*child
= node
->GetData();
1368 wxValidator
*validator
= child
->GetValidator();
1369 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1374 if ( recurse
&& !child
->Validate() )
1379 #endif // wxUSE_VALIDATORS
1384 bool wxWindowBase::TransferDataToWindow()
1386 #if wxUSE_VALIDATORS
1387 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1389 wxWindowList::compatibility_iterator node
;
1390 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1392 wxWindowBase
*child
= node
->GetData();
1393 wxValidator
*validator
= child
->GetValidator();
1394 if ( validator
&& !validator
->TransferToWindow() )
1396 wxLogWarning(_("Could not transfer data to window"));
1398 wxLog::FlushActive();
1406 if ( !child
->TransferDataToWindow() )
1408 // warning already given
1413 #endif // wxUSE_VALIDATORS
1418 bool wxWindowBase::TransferDataFromWindow()
1420 #if wxUSE_VALIDATORS
1421 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1423 wxWindowList::compatibility_iterator node
;
1424 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1426 wxWindow
*child
= node
->GetData();
1427 wxValidator
*validator
= child
->GetValidator();
1428 if ( validator
&& !validator
->TransferFromWindow() )
1430 // nop warning here because the application is supposed to give
1431 // one itself - we don't know here what might have gone wrongly
1438 if ( !child
->TransferDataFromWindow() )
1440 // warning already given
1445 #endif // wxUSE_VALIDATORS
1450 void wxWindowBase::InitDialog()
1452 wxInitDialogEvent
event(GetId());
1453 event
.SetEventObject( this );
1454 GetEventHandler()->ProcessEvent(event
);
1457 // ----------------------------------------------------------------------------
1458 // context-sensitive help support
1459 // ----------------------------------------------------------------------------
1463 // associate this help text with this window
1464 void wxWindowBase::SetHelpText(const wxString
& text
)
1466 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1469 helpProvider
->AddHelp(this, text
);
1473 // associate this help text with all windows with the same id as this
1475 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1477 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1480 helpProvider
->AddHelp(GetId(), text
);
1484 // get the help string associated with this window (may be empty)
1485 // default implementation forwards calls to the help provider
1487 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1488 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1491 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1494 text
= helpProvider
->GetHelp(this);
1500 // show help for this window
1501 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1503 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1506 if ( helpProvider
->ShowHelpAtPoint(this, event
.GetPosition(), event
.GetOrigin()) )
1508 // skip the event.Skip() below
1516 #endif // wxUSE_HELP
1518 // ----------------------------------------------------------------------------
1519 // tooltipsroot.Replace("\\", "/");
1520 // ----------------------------------------------------------------------------
1524 void wxWindowBase::SetToolTip( const wxString
&tip
)
1526 // don't create the new tooltip if we already have one
1529 m_tooltip
->SetTip( tip
);
1533 SetToolTip( new wxToolTip( tip
) );
1536 // setting empty tooltip text does not remove the tooltip any more - use
1537 // SetToolTip((wxToolTip *)NULL) for this
1540 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1542 if ( m_tooltip
!= tooltip
)
1547 m_tooltip
= tooltip
;
1551 #endif // wxUSE_TOOLTIPS
1553 // ----------------------------------------------------------------------------
1554 // constraints and sizers
1555 // ----------------------------------------------------------------------------
1557 #if wxUSE_CONSTRAINTS
1559 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1561 if ( m_constraints
)
1563 UnsetConstraints(m_constraints
);
1564 delete m_constraints
;
1566 m_constraints
= constraints
;
1567 if ( m_constraints
)
1569 // Make sure other windows know they're part of a 'meaningful relationship'
1570 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1571 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1572 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1573 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1574 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1575 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1576 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1577 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1578 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1579 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1580 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1581 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1582 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1583 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1584 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1585 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1589 // This removes any dangling pointers to this window in other windows'
1590 // constraintsInvolvedIn lists.
1591 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1595 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1596 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1597 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1598 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1599 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1600 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1601 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1602 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1603 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1604 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1605 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1606 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1607 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1608 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1609 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1610 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1614 // Back-pointer to other windows we're involved with, so if we delete this
1615 // window, we must delete any constraints we're involved with.
1616 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1618 if ( !m_constraintsInvolvedIn
)
1619 m_constraintsInvolvedIn
= new wxWindowList
;
1620 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1621 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1624 // REMOVE back-pointer to other windows we're involved with.
1625 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1627 if ( m_constraintsInvolvedIn
)
1628 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1631 // Reset any constraints that mention this window
1632 void wxWindowBase::DeleteRelatedConstraints()
1634 if ( m_constraintsInvolvedIn
)
1636 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1639 wxWindow
*win
= node
->GetData();
1640 wxLayoutConstraints
*constr
= win
->GetConstraints();
1642 // Reset any constraints involving this window
1645 constr
->left
.ResetIfWin(this);
1646 constr
->top
.ResetIfWin(this);
1647 constr
->right
.ResetIfWin(this);
1648 constr
->bottom
.ResetIfWin(this);
1649 constr
->width
.ResetIfWin(this);
1650 constr
->height
.ResetIfWin(this);
1651 constr
->centreX
.ResetIfWin(this);
1652 constr
->centreY
.ResetIfWin(this);
1655 wxWindowList::compatibility_iterator next
= node
->GetNext();
1656 m_constraintsInvolvedIn
->Erase(node
);
1660 delete m_constraintsInvolvedIn
;
1661 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1665 #endif // wxUSE_CONSTRAINTS
1667 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1669 if ( sizer
== m_windowSizer
)
1672 if ( m_windowSizer
)
1674 m_windowSizer
->SetContainingWindow(NULL
);
1677 delete m_windowSizer
;
1680 m_windowSizer
= sizer
;
1681 if ( m_windowSizer
)
1683 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
1686 SetAutoLayout(m_windowSizer
!= NULL
);
1689 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1691 SetSizer( sizer
, deleteOld
);
1692 sizer
->SetSizeHints( (wxWindow
*) this );
1696 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1698 // adding a window to a sizer twice is going to result in fatal and
1699 // hard to debug problems later because when deleting the second
1700 // associated wxSizerItem we're going to dereference a dangling
1701 // pointer; so try to detect this as early as possible
1702 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1703 _T("Adding a window to the same sizer twice?") );
1705 m_containingSizer
= sizer
;
1708 #if wxUSE_CONSTRAINTS
1710 void wxWindowBase::SatisfyConstraints()
1712 wxLayoutConstraints
*constr
= GetConstraints();
1713 bool wasOk
= constr
&& constr
->AreSatisfied();
1715 ResetConstraints(); // Mark all constraints as unevaluated
1719 // if we're a top level panel (i.e. our parent is frame/dialog), our
1720 // own constraints will never be satisfied any more unless we do it
1724 while ( noChanges
> 0 )
1726 LayoutPhase1(&noChanges
);
1730 LayoutPhase2(&noChanges
);
1733 #endif // wxUSE_CONSTRAINTS
1735 bool wxWindowBase::Layout()
1737 // If there is a sizer, use it instead of the constraints
1741 GetVirtualSize(&w
, &h
);
1742 GetSizer()->SetDimension( 0, 0, w
, h
);
1744 #if wxUSE_CONSTRAINTS
1747 SatisfyConstraints(); // Find the right constraints values
1748 SetConstraintSizes(); // Recursively set the real window sizes
1755 #if wxUSE_CONSTRAINTS
1757 // first phase of the constraints evaluation: set our own constraints
1758 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1760 wxLayoutConstraints
*constr
= GetConstraints();
1762 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1765 // second phase: set the constraints for our children
1766 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1773 // Layout grand children
1779 // Do a phase of evaluating child constraints
1780 bool wxWindowBase::DoPhase(int phase
)
1782 // the list containing the children for which the constraints are already
1784 wxWindowList succeeded
;
1786 // the max number of iterations we loop before concluding that we can't set
1788 static const int maxIterations
= 500;
1790 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1794 // loop over all children setting their constraints
1795 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1797 node
= node
->GetNext() )
1799 wxWindow
*child
= node
->GetData();
1800 if ( child
->IsTopLevel() )
1802 // top level children are not inside our client area
1806 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1808 // this one is either already ok or nothing we can do about it
1812 int tempNoChanges
= 0;
1813 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1814 : child
->LayoutPhase2(&tempNoChanges
);
1815 noChanges
+= tempNoChanges
;
1819 succeeded
.Append(child
);
1825 // constraints are set
1833 void wxWindowBase::ResetConstraints()
1835 wxLayoutConstraints
*constr
= GetConstraints();
1838 constr
->left
.SetDone(false);
1839 constr
->top
.SetDone(false);
1840 constr
->right
.SetDone(false);
1841 constr
->bottom
.SetDone(false);
1842 constr
->width
.SetDone(false);
1843 constr
->height
.SetDone(false);
1844 constr
->centreX
.SetDone(false);
1845 constr
->centreY
.SetDone(false);
1848 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1851 wxWindow
*win
= node
->GetData();
1852 if ( !win
->IsTopLevel() )
1853 win
->ResetConstraints();
1854 node
= node
->GetNext();
1858 // Need to distinguish between setting the 'fake' size for windows and sizers,
1859 // and setting the real values.
1860 void wxWindowBase::SetConstraintSizes(bool recurse
)
1862 wxLayoutConstraints
*constr
= GetConstraints();
1863 if ( constr
&& constr
->AreSatisfied() )
1865 int x
= constr
->left
.GetValue();
1866 int y
= constr
->top
.GetValue();
1867 int w
= constr
->width
.GetValue();
1868 int h
= constr
->height
.GetValue();
1870 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1871 (constr
->height
.GetRelationship() != wxAsIs
) )
1873 SetSize(x
, y
, w
, h
);
1877 // If we don't want to resize this window, just move it...
1883 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1884 GetClassInfo()->GetClassName(),
1890 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1893 wxWindow
*win
= node
->GetData();
1894 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1895 win
->SetConstraintSizes();
1896 node
= node
->GetNext();
1901 // Only set the size/position of the constraint (if any)
1902 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1904 wxLayoutConstraints
*constr
= GetConstraints();
1907 if ( x
!= wxDefaultCoord
)
1909 constr
->left
.SetValue(x
);
1910 constr
->left
.SetDone(true);
1912 if ( y
!= wxDefaultCoord
)
1914 constr
->top
.SetValue(y
);
1915 constr
->top
.SetDone(true);
1917 if ( w
!= wxDefaultCoord
)
1919 constr
->width
.SetValue(w
);
1920 constr
->width
.SetDone(true);
1922 if ( h
!= wxDefaultCoord
)
1924 constr
->height
.SetValue(h
);
1925 constr
->height
.SetDone(true);
1930 void wxWindowBase::MoveConstraint(int x
, int y
)
1932 wxLayoutConstraints
*constr
= GetConstraints();
1935 if ( x
!= wxDefaultCoord
)
1937 constr
->left
.SetValue(x
);
1938 constr
->left
.SetDone(true);
1940 if ( y
!= wxDefaultCoord
)
1942 constr
->top
.SetValue(y
);
1943 constr
->top
.SetDone(true);
1948 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1950 wxLayoutConstraints
*constr
= GetConstraints();
1953 *w
= constr
->width
.GetValue();
1954 *h
= constr
->height
.GetValue();
1960 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1962 wxLayoutConstraints
*constr
= GetConstraints();
1965 *w
= constr
->width
.GetValue();
1966 *h
= constr
->height
.GetValue();
1969 GetClientSize(w
, h
);
1972 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1974 wxLayoutConstraints
*constr
= GetConstraints();
1977 *x
= constr
->left
.GetValue();
1978 *y
= constr
->top
.GetValue();
1984 #endif // wxUSE_CONSTRAINTS
1986 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1988 // don't do it for the dialogs/frames - they float independently of their
1990 if ( !IsTopLevel() )
1992 wxWindow
*parent
= GetParent();
1993 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1995 wxPoint
pt(parent
->GetClientAreaOrigin());
2002 // ----------------------------------------------------------------------------
2003 // do Update UI processing for child controls
2004 // ----------------------------------------------------------------------------
2006 void wxWindowBase::UpdateWindowUI(long flags
)
2008 wxUpdateUIEvent
event(GetId());
2009 event
.SetEventObject(this);
2011 if ( GetEventHandler()->ProcessEvent(event
) )
2013 DoUpdateWindowUI(event
);
2016 if (flags
& wxUPDATE_UI_RECURSE
)
2018 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2021 wxWindow
* child
= (wxWindow
*) node
->GetData();
2022 child
->UpdateWindowUI(flags
);
2023 node
= node
->GetNext();
2028 // do the window-specific processing after processing the update event
2029 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2031 if ( event
.GetSetEnabled() )
2032 Enable(event
.GetEnabled());
2034 if ( event
.GetSetShown() )
2035 Show(event
.GetShown());
2039 // call internal idle recursively
2040 // may be obsolete (wait until OnIdle scheme stabilises)
2041 void wxWindowBase::ProcessInternalIdle()
2045 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2048 wxWindow
*child
= node
->GetData();
2049 child
->ProcessInternalIdle();
2050 node
= node
->GetNext();
2055 // ----------------------------------------------------------------------------
2056 // dialog units translations
2057 // ----------------------------------------------------------------------------
2059 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2061 int charWidth
= GetCharWidth();
2062 int charHeight
= GetCharHeight();
2063 wxPoint pt2
= wxDefaultPosition
;
2064 if (pt
.x
!= wxDefaultCoord
)
2065 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2066 if (pt
.y
!= wxDefaultCoord
)
2067 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2072 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2074 int charWidth
= GetCharWidth();
2075 int charHeight
= GetCharHeight();
2076 wxPoint pt2
= wxDefaultPosition
;
2077 if (pt
.x
!= wxDefaultCoord
)
2078 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2079 if (pt
.y
!= wxDefaultCoord
)
2080 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2085 // ----------------------------------------------------------------------------
2087 // ----------------------------------------------------------------------------
2089 // propagate the colour change event to the subwindows
2090 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2092 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2095 // Only propagate to non-top-level windows
2096 wxWindow
*win
= node
->GetData();
2097 if ( !win
->IsTopLevel() )
2099 wxSysColourChangedEvent event2
;
2100 event
.SetEventObject(win
);
2101 win
->GetEventHandler()->ProcessEvent(event2
);
2104 node
= node
->GetNext();
2110 // the default action is to populate dialog with data when it's created,
2111 // and nudge the UI into displaying itself correctly in case
2112 // we've turned the wxUpdateUIEvents frequency down low.
2113 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2115 TransferDataToWindow();
2117 // Update the UI at this point
2118 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2121 // methods for drawing the sizers in a visible way
2124 static void DrawSizers(wxWindowBase
*win
);
2126 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2128 wxClientDC
dc((wxWindow
*)win
);
2129 dc
.SetPen(*wxRED_PEN
);
2130 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2131 dc
.DrawRectangle(rect
.Deflate(1, 1));
2134 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2136 const wxSizerItemList
& items
= sizer
->GetChildren();
2137 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2142 wxSizerItem
*item
= *i
;
2143 if ( item
->IsSizer() )
2145 DrawBorder(win
, item
->GetRect().Deflate(2));
2146 DrawSizer(win
, item
->GetSizer());
2148 else if ( item
->IsSpacer() )
2150 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2152 else if ( item
->IsWindow() )
2154 DrawSizers(item
->GetWindow());
2159 static void DrawSizers(wxWindowBase
*win
)
2161 wxSizer
*sizer
= win
->GetSizer();
2164 DrawBorder(win
, win
->GetClientSize());
2165 DrawSizer(win
, sizer
);
2167 else // no sizer, still recurse into the children
2169 const wxWindowList
& children
= win
->GetChildren();
2170 for ( wxWindowList::const_iterator i
= children
.begin(),
2171 end
= children
.end();
2180 #endif // __WXDEBUG__
2182 // process special middle clicks
2183 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2185 if ( event
.ControlDown() && event
.AltDown() )
2188 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2189 if ( event
.ShiftDown() )
2194 #endif // __WXDEBUG__
2197 // don't translate these strings, they're for diagnostics purposes only
2199 msg
.Printf(_T("wxWidgets Library (%s port)\n")
2200 _T("Version %d.%d.%d%s%s, compiled at %s %s\n")
2201 _T("Runtime version of toolkit used is %d.%d.%s\n")
2202 _T("Copyright (c) 1995-2006 wxWidgets team"),
2203 wxPlatformInfo::Get().GetPortIdName().c_str(),
2219 wxPlatformInfo::Get().GetToolkitMajorVersion(),
2220 wxPlatformInfo::Get().GetToolkitMinorVersion(),
2222 wxString::Format(_T("\nThe compile-time GTK+ version is %d.%d.%d."), GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
).c_str()
2228 wxMessageBox(msg
, _T("wxWidgets information"),
2229 wxICON_INFORMATION
| wxOK
,
2233 #endif // wxUSE_MSGDLG
2239 // ----------------------------------------------------------------------------
2241 // ----------------------------------------------------------------------------
2243 #if wxUSE_ACCESSIBILITY
2244 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2246 if (m_accessible
&& (accessible
!= m_accessible
))
2247 delete m_accessible
;
2248 m_accessible
= accessible
;
2250 m_accessible
->SetWindow((wxWindow
*) this);
2253 // Returns the accessible object, creating if necessary.
2254 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2257 m_accessible
= CreateAccessible();
2258 return m_accessible
;
2261 // Override to create a specific accessible object.
2262 wxAccessible
* wxWindowBase::CreateAccessible()
2264 return new wxWindowAccessible((wxWindow
*) this);
2269 // ----------------------------------------------------------------------------
2270 // list classes implementation
2271 // ----------------------------------------------------------------------------
2275 #include "wx/listimpl.cpp"
2276 WX_DEFINE_LIST(wxWindowList
)
2280 void wxWindowListNode::DeleteData()
2282 delete (wxWindow
*)GetData();
2287 // ----------------------------------------------------------------------------
2289 // ----------------------------------------------------------------------------
2291 wxBorder
wxWindowBase::GetBorder(long flags
) const
2293 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2294 if ( border
== wxBORDER_DEFAULT
)
2296 border
= GetDefaultBorder();
2302 wxBorder
wxWindowBase::GetDefaultBorder() const
2304 return wxBORDER_NONE
;
2307 // ----------------------------------------------------------------------------
2309 // ----------------------------------------------------------------------------
2311 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2313 // here we just check if the point is inside the window or not
2315 // check the top and left border first
2316 bool outside
= x
< 0 || y
< 0;
2319 // check the right and bottom borders too
2320 wxSize size
= GetSize();
2321 outside
= x
>= size
.x
|| y
>= size
.y
;
2324 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2327 // ----------------------------------------------------------------------------
2329 // ----------------------------------------------------------------------------
2331 struct WXDLLEXPORT wxWindowNext
2335 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2336 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2337 bool wxWindowBase::ms_winCaptureChanging
= false;
2339 void wxWindowBase::CaptureMouse()
2341 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2343 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2345 ms_winCaptureChanging
= true;
2347 wxWindow
*winOld
= GetCapture();
2350 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2353 wxWindowNext
*item
= new wxWindowNext
;
2355 item
->next
= ms_winCaptureNext
;
2356 ms_winCaptureNext
= item
;
2358 //else: no mouse capture to save
2361 ms_winCaptureCurrent
= (wxWindow
*)this;
2363 ms_winCaptureChanging
= false;
2366 void wxWindowBase::ReleaseMouse()
2368 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2370 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2372 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2374 ms_winCaptureChanging
= true;
2377 ms_winCaptureCurrent
= NULL
;
2379 if ( ms_winCaptureNext
)
2381 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2382 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2384 wxWindowNext
*item
= ms_winCaptureNext
;
2385 ms_winCaptureNext
= item
->next
;
2388 //else: stack is empty, no previous capture
2390 ms_winCaptureChanging
= false;
2392 wxLogTrace(_T("mousecapture"),
2393 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2394 wx_static_cast(void*, GetCapture()));
2397 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2399 wxMouseCaptureLostEvent
event(win
->GetId());
2400 event
.SetEventObject(win
);
2401 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2403 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2408 void wxWindowBase::NotifyCaptureLost()
2410 // don't do anything if capture lost was expected, i.e. resulted from
2411 // a wx call to ReleaseMouse or CaptureMouse:
2412 if ( ms_winCaptureChanging
)
2415 // if the capture was lost unexpectedly, notify every window that has
2416 // capture (on stack or current) about it and clear the stack:
2418 if ( ms_winCaptureCurrent
)
2420 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2421 ms_winCaptureCurrent
= NULL
;
2424 while ( ms_winCaptureNext
)
2426 wxWindowNext
*item
= ms_winCaptureNext
;
2427 ms_winCaptureNext
= item
->next
;
2429 DoNotifyWindowAboutCaptureLost(item
->win
);
2438 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2439 int WXUNUSED(modifiers
),
2440 int WXUNUSED(keycode
))
2446 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2452 #endif // wxUSE_HOTKEY
2454 void wxWindowBase::SendDestroyEvent()
2456 wxWindowDestroyEvent event
;
2457 event
.SetEventObject(this);
2458 event
.SetId(GetId());
2459 GetEventHandler()->ProcessEvent(event
);
2462 // ----------------------------------------------------------------------------
2464 // ----------------------------------------------------------------------------
2466 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2468 #if wxUSE_VALIDATORS
2469 // Can only use the validator of the window which
2470 // is receiving the event
2471 if ( event
.GetEventObject() == this )
2473 wxValidator
*validator
= GetValidator();
2474 if ( validator
&& validator
->ProcessEvent(event
) )
2479 #endif // wxUSE_VALIDATORS
2484 bool wxWindowBase::TryParent(wxEvent
& event
)
2486 // carry on up the parent-child hierarchy if the propagation count hasn't
2488 if ( event
.ShouldPropagate() )
2490 // honour the requests to stop propagation at this window: this is
2491 // used by the dialogs, for example, to prevent processing the events
2492 // from the dialog controls in the parent frame which rarely, if ever,
2494 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2496 wxWindow
*parent
= GetParent();
2497 if ( parent
&& !parent
->IsBeingDeleted() )
2499 wxPropagateOnce
propagateOnce(event
);
2501 return parent
->GetEventHandler()->ProcessEvent(event
);
2506 return wxEvtHandler::TryParent(event
);
2509 // ----------------------------------------------------------------------------
2510 // keyboard navigation
2511 // ----------------------------------------------------------------------------
2513 // Navigates in the specified direction.
2514 bool wxWindowBase::Navigate(int flags
)
2516 wxNavigationKeyEvent eventNav
;
2517 eventNav
.SetFlags(flags
);
2518 eventNav
.SetEventObject(this);
2519 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2526 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2528 // check that we're not a top level window
2529 wxCHECK_RET( GetParent(),
2530 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2532 // detect the special case when we have nothing to do anyhow and when the
2533 // code below wouldn't work
2537 // find the target window in the siblings list
2538 wxWindowList
& siblings
= GetParent()->GetChildren();
2539 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2540 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2542 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2543 // can't just move the node around
2544 wxWindow
*self
= (wxWindow
*)this;
2545 siblings
.DeleteObject(self
);
2546 if ( move
== MoveAfter
)
2553 siblings
.Insert(i
, self
);
2555 else // MoveAfter and win was the last sibling
2557 siblings
.Append(self
);
2561 // ----------------------------------------------------------------------------
2563 // ----------------------------------------------------------------------------
2565 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2567 wxWindowBase
*win
= DoFindFocus();
2568 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2571 // ----------------------------------------------------------------------------
2573 // ----------------------------------------------------------------------------
2575 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2577 while ( win
&& !win
->IsTopLevel() )
2578 win
= win
->GetParent();
2583 #if wxUSE_ACCESSIBILITY
2584 // ----------------------------------------------------------------------------
2585 // accessible object for windows
2586 // ----------------------------------------------------------------------------
2588 // Can return either a child object, or an integer
2589 // representing the child element, starting from 1.
2590 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2592 wxASSERT( GetWindow() != NULL
);
2596 return wxACC_NOT_IMPLEMENTED
;
2599 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2600 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2602 wxASSERT( GetWindow() != NULL
);
2606 wxWindow
* win
= NULL
;
2613 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2615 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2622 rect
= win
->GetRect();
2623 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2624 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2628 return wxACC_NOT_IMPLEMENTED
;
2631 // Navigates from fromId to toId/toObject.
2632 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2633 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2635 wxASSERT( GetWindow() != NULL
);
2641 case wxNAVDIR_FIRSTCHILD
:
2643 if (GetWindow()->GetChildren().GetCount() == 0)
2645 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2646 *toObject
= childWindow
->GetOrCreateAccessible();
2650 case wxNAVDIR_LASTCHILD
:
2652 if (GetWindow()->GetChildren().GetCount() == 0)
2654 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2655 *toObject
= childWindow
->GetOrCreateAccessible();
2659 case wxNAVDIR_RIGHT
:
2663 wxWindowList::compatibility_iterator node
=
2664 wxWindowList::compatibility_iterator();
2667 // Can't navigate to sibling of this window
2668 // if we're a top-level window.
2669 if (!GetWindow()->GetParent())
2670 return wxACC_NOT_IMPLEMENTED
;
2672 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2676 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2677 node
= GetWindow()->GetChildren().Item(fromId
-1);
2680 if (node
&& node
->GetNext())
2682 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2683 *toObject
= nextWindow
->GetOrCreateAccessible();
2691 case wxNAVDIR_PREVIOUS
:
2693 wxWindowList::compatibility_iterator node
=
2694 wxWindowList::compatibility_iterator();
2697 // Can't navigate to sibling of this window
2698 // if we're a top-level window.
2699 if (!GetWindow()->GetParent())
2700 return wxACC_NOT_IMPLEMENTED
;
2702 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2706 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2707 node
= GetWindow()->GetChildren().Item(fromId
-1);
2710 if (node
&& node
->GetPrevious())
2712 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2713 *toObject
= previousWindow
->GetOrCreateAccessible();
2721 return wxACC_NOT_IMPLEMENTED
;
2724 // Gets the name of the specified object.
2725 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2727 wxASSERT( GetWindow() != NULL
);
2733 // If a child, leave wxWidgets to call the function on the actual
2736 return wxACC_NOT_IMPLEMENTED
;
2738 // This will eventually be replaced by specialised
2739 // accessible classes, one for each kind of wxWidgets
2740 // control or window.
2742 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2743 title
= ((wxButton
*) GetWindow())->GetLabel();
2746 title
= GetWindow()->GetName();
2754 return wxACC_NOT_IMPLEMENTED
;
2757 // Gets the number of children.
2758 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2760 wxASSERT( GetWindow() != NULL
);
2764 *childId
= (int) GetWindow()->GetChildren().GetCount();
2768 // Gets the specified child (starting from 1).
2769 // If *child is NULL and return value is wxACC_OK,
2770 // this means that the child is a simple element and
2771 // not an accessible object.
2772 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2774 wxASSERT( GetWindow() != NULL
);
2784 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2787 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2788 *child
= childWindow
->GetOrCreateAccessible();
2795 // Gets the parent, or NULL.
2796 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2798 wxASSERT( GetWindow() != NULL
);
2802 wxWindow
* parentWindow
= GetWindow()->GetParent();
2810 *parent
= parentWindow
->GetOrCreateAccessible();
2818 // Performs the default action. childId is 0 (the action for this object)
2819 // or > 0 (the action for a child).
2820 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2821 // window (e.g. an edit control).
2822 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2824 wxASSERT( GetWindow() != NULL
);
2828 return wxACC_NOT_IMPLEMENTED
;
2831 // Gets the default action for this object (0) or > 0 (the action for a child).
2832 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2833 // string if there is no action.
2834 // The retrieved string describes the action that is performed on an object,
2835 // not what the object does as a result. For example, a toolbar button that prints
2836 // a document has a default action of "Press" rather than "Prints the current document."
2837 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2839 wxASSERT( GetWindow() != NULL
);
2843 return wxACC_NOT_IMPLEMENTED
;
2846 // Returns the description for this object or a child.
2847 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2849 wxASSERT( GetWindow() != NULL
);
2853 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2859 return wxACC_NOT_IMPLEMENTED
;
2862 // Returns help text for this object or a child, similar to tooltip text.
2863 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2865 wxASSERT( GetWindow() != NULL
);
2869 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2875 return wxACC_NOT_IMPLEMENTED
;
2878 // Returns the keyboard shortcut for this object or child.
2879 // Return e.g. ALT+K
2880 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2882 wxASSERT( GetWindow() != NULL
);
2886 return wxACC_NOT_IMPLEMENTED
;
2889 // Returns a role constant.
2890 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2892 wxASSERT( GetWindow() != NULL
);
2896 // If a child, leave wxWidgets to call the function on the actual
2899 return wxACC_NOT_IMPLEMENTED
;
2901 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2902 return wxACC_NOT_IMPLEMENTED
;
2904 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2905 return wxACC_NOT_IMPLEMENTED
;
2908 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2909 return wxACC_NOT_IMPLEMENTED
;
2912 //*role = wxROLE_SYSTEM_CLIENT;
2913 *role
= wxROLE_SYSTEM_CLIENT
;
2917 return wxACC_NOT_IMPLEMENTED
;
2921 // Returns a state constant.
2922 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2924 wxASSERT( GetWindow() != NULL
);
2928 // If a child, leave wxWidgets to call the function on the actual
2931 return wxACC_NOT_IMPLEMENTED
;
2933 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2934 return wxACC_NOT_IMPLEMENTED
;
2937 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2938 return wxACC_NOT_IMPLEMENTED
;
2941 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2942 return wxACC_NOT_IMPLEMENTED
;
2949 return wxACC_NOT_IMPLEMENTED
;
2953 // Returns a localized string representing the value for the object
2955 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2957 wxASSERT( GetWindow() != NULL
);
2961 return wxACC_NOT_IMPLEMENTED
;
2964 // Selects the object or child.
2965 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2967 wxASSERT( GetWindow() != NULL
);
2971 return wxACC_NOT_IMPLEMENTED
;
2974 // Gets the window with the keyboard focus.
2975 // If childId is 0 and child is NULL, no object in
2976 // this subhierarchy has the focus.
2977 // If this object has the focus, child should be 'this'.
2978 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2980 wxASSERT( GetWindow() != NULL
);
2984 return wxACC_NOT_IMPLEMENTED
;
2988 // Gets a variant representing the selected children
2990 // Acceptable values:
2991 // - a null variant (IsNull() returns true)
2992 // - a list variant (GetType() == wxT("list")
2993 // - an integer representing the selected child element,
2994 // or 0 if this object is selected (GetType() == wxT("long")
2995 // - a "void*" pointer to a wxAccessible child object
2996 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2998 wxASSERT( GetWindow() != NULL
);
3002 return wxACC_NOT_IMPLEMENTED
;
3004 #endif // wxUSE_VARIANT
3006 #endif // wxUSE_ACCESSIBILITY
3008 // ----------------------------------------------------------------------------
3010 // ----------------------------------------------------------------------------
3013 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3015 wxCoord widthTotal
) const
3017 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3019 x
= widthTotal
- x
- width
;