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
;
204 m_maxVirtualWidth
= wxDefaultCoord
;
206 m_maxVirtualHeight
= wxDefaultCoord
;
208 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
209 #if wxUSE_SYSTEM_OPTIONS
210 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
212 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
216 // Whether we're using the current theme for this window (wxGTK only for now)
217 m_themeEnabled
= false;
219 // VZ: this one shouldn't exist...
220 m_isBeingDeleted
= false;
223 // common part of window creation process
224 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
226 const wxPoint
& WXUNUSED(pos
),
227 const wxSize
& WXUNUSED(size
),
229 const wxValidator
& wxVALIDATOR_PARAM(validator
),
230 const wxString
& name
)
233 // wxGTK doesn't allow to create controls with static box as the parent so
234 // this will result in a crash when the program is ported to wxGTK so warn
237 // if you get this assert, the correct solution is to create the controls
238 // as siblings of the static box
239 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
240 _T("wxStaticBox can't be used as a window parent!") );
241 #endif // wxUSE_STATBOX
243 // ids are limited to 16 bits under MSW so if you care about portability,
244 // it's not a good idea to use ids out of this range (and negative ids are
245 // reserved for wxWidgets own usage)
246 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
247 _T("invalid id value") );
249 // generate a new id if the user doesn't care about it
250 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
253 SetWindowStyleFlag(style
);
257 SetValidator(validator
);
258 #endif // wxUSE_VALIDATORS
260 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
261 // have it too - like this it's possible to set it only in the top level
262 // dialog/frame and all children will inherit it by defult
263 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
265 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
271 // ----------------------------------------------------------------------------
273 // ----------------------------------------------------------------------------
276 wxWindowBase::~wxWindowBase()
278 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
280 // FIXME if these 2 cases result from programming errors in the user code
281 // we should probably assert here instead of silently fixing them
283 // Just in case the window has been Closed, but we're then deleting
284 // immediately: don't leave dangling pointers.
285 wxPendingDelete
.DeleteObject(this);
287 // Just in case we've loaded a top-level window via LoadNativeDialog but
288 // we weren't a dialog class
289 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
291 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
293 // reset the dangling pointer our parent window may keep to us
296 m_parent
->RemoveChild(this);
301 #endif // wxUSE_CARET
304 delete m_windowValidator
;
305 #endif // wxUSE_VALIDATORS
307 #if wxUSE_CONSTRAINTS
308 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
309 // at deleted windows as they delete themselves.
310 DeleteRelatedConstraints();
314 // This removes any dangling pointers to this window in other windows'
315 // constraintsInvolvedIn lists.
316 UnsetConstraints(m_constraints
);
317 delete m_constraints
;
318 m_constraints
= NULL
;
320 #endif // wxUSE_CONSTRAINTS
322 if ( m_containingSizer
)
323 m_containingSizer
->Detach( (wxWindow
*)this );
325 delete m_windowSizer
;
327 #if wxUSE_DRAG_AND_DROP
329 #endif // wxUSE_DRAG_AND_DROP
333 #endif // wxUSE_TOOLTIPS
335 #if wxUSE_ACCESSIBILITY
340 bool wxWindowBase::Destroy()
347 bool wxWindowBase::Close(bool force
)
349 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
350 event
.SetEventObject(this);
351 event
.SetCanVeto(!force
);
353 // return false if window wasn't closed because the application vetoed the
355 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
358 bool wxWindowBase::DestroyChildren()
360 wxWindowList::compatibility_iterator node
;
363 // we iterate until the list becomes empty
364 node
= GetChildren().GetFirst();
368 wxWindow
*child
= node
->GetData();
370 // note that we really want to call delete and not ->Destroy() here
371 // because we want to delete the child immediately, before we are
372 // deleted, and delayed deletion would result in problems as our (top
373 // level) child could outlive its parent
376 wxASSERT_MSG( !GetChildren().Find(child
),
377 wxT("child didn't remove itself using RemoveChild()") );
383 // ----------------------------------------------------------------------------
384 // size/position related methods
385 // ----------------------------------------------------------------------------
387 // centre the window with respect to its parent in either (or both) directions
388 void wxWindowBase::DoCentre(int dir
)
390 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
391 _T("this method only implements centering child windows") );
393 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
396 // fits the window around the children
397 void wxWindowBase::Fit()
399 if ( !GetChildren().empty() )
401 SetSize(GetBestSize());
403 //else: do nothing if we have no children
406 // fits virtual size (ie. scrolled area etc.) around children
407 void wxWindowBase::FitInside()
409 if ( GetChildren().GetCount() > 0 )
411 SetVirtualSize( GetBestVirtualSize() );
415 // On Mac, scrollbars are explicitly children.
417 static bool wxHasRealChildren(const wxWindowBase
* win
)
419 int realChildCount
= 0;
421 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
423 node
= node
->GetNext() )
425 wxWindow
*win
= node
->GetData();
426 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
429 return (realChildCount
> 0);
433 void wxWindowBase::InvalidateBestSize()
435 m_bestSizeCache
= wxDefaultSize
;
437 // parent's best size calculation may depend on its children's
438 // as long as child window we are in is not top level window itself
439 // (because the TLW size is never resized automatically)
440 // so let's invalidate it as well to be safe:
441 if (m_parent
&& !IsTopLevel())
442 m_parent
->InvalidateBestSize();
445 // return the size best suited for the current window
446 wxSize
wxWindowBase::DoGetBestSize() const
452 best
= GetWindowSizeForVirtualSize(m_windowSizer
->GetMinSize());
454 #if wxUSE_CONSTRAINTS
455 else if ( m_constraints
)
457 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
459 // our minimal acceptable size is such that all our windows fit inside
463 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
465 node
= node
->GetNext() )
467 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
470 // it's not normal that we have an unconstrained child, but
471 // what can we do about it?
475 int x
= c
->right
.GetValue(),
476 y
= c
->bottom
.GetValue();
484 // TODO: we must calculate the overlaps somehow, otherwise we
485 // will never return a size bigger than the current one :-(
488 best
= wxSize(maxX
, maxY
);
490 #endif // wxUSE_CONSTRAINTS
491 else if ( !GetChildren().empty()
493 && wxHasRealChildren(this)
497 // our minimal acceptable size is such that all our visible child
498 // windows fit inside
502 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
504 node
= node
->GetNext() )
506 wxWindow
*win
= node
->GetData();
507 if ( win
->IsTopLevel()
510 || wxDynamicCast(win
, wxStatusBar
)
511 #endif // wxUSE_STATUSBAR
514 // dialogs and frames lie in different top level windows -
515 // don't deal with them here; as for the status bars, they
516 // don't lie in the client area at all
521 win
->GetPosition(&wx
, &wy
);
523 // if the window hadn't been positioned yet, assume that it is in
525 if ( wx
== wxDefaultCoord
)
527 if ( wy
== wxDefaultCoord
)
530 win
->GetSize(&ww
, &wh
);
531 if ( wx
+ ww
> maxX
)
533 if ( wy
+ wh
> maxY
)
537 best
= wxSize(maxX
, maxY
);
539 else // ! has children
541 // for a generic window there is no natural best size so, if the
542 // minimal size is not set, use the current size but take care to
543 // remember it as minimal size for the next time because our best size
544 // should be constant: otherwise we could get into a situation when the
545 // window is initially at some size, then expanded to a larger size and
546 // then, when the containing window is shrunk back (because our initial
547 // best size had been used for computing the parent min size), we can't
548 // be shrunk back any more because our best size is now bigger
549 wxSize size
= GetMinSize();
550 if ( !size
.IsFullySpecified() )
552 size
.SetDefaults(GetSize());
553 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
556 // return as-is, unadjusted by the client size difference.
560 // Add any difference between size and client size
561 wxSize diff
= GetSize() - GetClientSize();
562 best
.x
+= wxMax(0, diff
.x
);
563 best
.y
+= wxMax(0, diff
.y
);
569 wxSize
wxWindowBase::GetBestFittingSize() const
571 // merge the best size with the min size, giving priority to the min size
572 wxSize min
= GetMinSize();
573 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
575 wxSize best
= GetBestSize();
576 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
577 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
583 void wxWindowBase::SetBestFittingSize(const wxSize
& size
)
585 // Set the min size to the size passed in. This will usually either be
586 // wxDefaultSize or the size passed to this window's ctor/Create function.
589 // Merge the size with the best size if needed
590 wxSize best
= GetBestFittingSize();
592 // If the current size doesn't match then change it
593 if (GetSize() != best
)
598 // by default the origin is not shifted
599 wxPoint
wxWindowBase::GetClientAreaOrigin() const
604 // set the min/max size of the window
605 void wxWindowBase::DoSetSizeHints(int minW
, int minH
,
607 int WXUNUSED(incW
), int WXUNUSED(incH
))
609 // setting min width greater than max width leads to infinite loops under
610 // X11 and generally doesn't make any sense, so don't allow it
611 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
612 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
613 _T("min width/height must be less than max width/height!") );
621 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
623 if ( m_windowVariant
!= variant
)
625 m_windowVariant
= variant
;
627 DoSetWindowVariant(variant
);
631 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
633 // adjust the font height to correspond to our new variant (notice that
634 // we're only called if something really changed)
635 wxFont font
= GetFont();
636 int size
= font
.GetPointSize();
639 case wxWINDOW_VARIANT_NORMAL
:
642 case wxWINDOW_VARIANT_SMALL
:
647 case wxWINDOW_VARIANT_MINI
:
652 case wxWINDOW_VARIANT_LARGE
:
658 wxFAIL_MSG(_T("unexpected window variant"));
662 font
.SetPointSize(size
);
666 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
669 m_minVirtualWidth
= minW
;
670 m_maxVirtualWidth
= maxW
;
671 m_minVirtualHeight
= minH
;
672 m_maxVirtualHeight
= maxH
;
675 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
677 if ( m_minVirtualWidth
!= wxDefaultCoord
&& m_minVirtualWidth
> x
)
678 x
= m_minVirtualWidth
;
679 if ( m_maxVirtualWidth
!= wxDefaultCoord
&& m_maxVirtualWidth
< x
)
680 x
= m_maxVirtualWidth
;
681 if ( m_minVirtualHeight
!= wxDefaultCoord
&& m_minVirtualHeight
> y
)
682 y
= m_minVirtualHeight
;
683 if ( m_maxVirtualHeight
!= wxDefaultCoord
&& m_maxVirtualHeight
< y
)
684 y
= m_maxVirtualHeight
;
686 m_virtualSize
= wxSize(x
, y
);
689 wxSize
wxWindowBase::DoGetVirtualSize() const
691 // we should use the entire client area so if it is greater than our
692 // virtual size, expand it to fit (otherwise if the window is big enough we
693 // wouldn't be using parts of it)
694 wxSize size
= GetClientSize();
695 if ( m_virtualSize
.x
> size
.x
)
696 size
.x
= m_virtualSize
.x
;
698 if ( m_virtualSize
.y
>= size
.y
)
699 size
.y
= m_virtualSize
.y
;
704 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
706 // screen position is the same as (0, 0) in client coords for non TLWs (and
707 // TLWs override this method)
713 ClientToScreen(x
, y
);
716 // ----------------------------------------------------------------------------
717 // show/hide/enable/disable the window
718 // ----------------------------------------------------------------------------
720 bool wxWindowBase::Show(bool show
)
722 if ( show
!= m_isShown
)
734 bool wxWindowBase::Enable(bool enable
)
736 if ( enable
!= m_isEnabled
)
738 m_isEnabled
= enable
;
747 // ----------------------------------------------------------------------------
749 // ----------------------------------------------------------------------------
751 bool wxWindowBase::IsTopLevel() const
756 // ----------------------------------------------------------------------------
757 // reparenting the window
758 // ----------------------------------------------------------------------------
760 void wxWindowBase::AddChild(wxWindowBase
*child
)
762 wxCHECK_RET( child
, wxT("can't add a NULL child") );
764 // this should never happen and it will lead to a crash later if it does
765 // because RemoveChild() will remove only one node from the children list
766 // and the other(s) one(s) will be left with dangling pointers in them
767 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
769 GetChildren().Append((wxWindow
*)child
);
770 child
->SetParent(this);
773 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
775 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
777 GetChildren().DeleteObject((wxWindow
*)child
);
778 child
->SetParent(NULL
);
781 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
783 wxWindow
*oldParent
= GetParent();
784 if ( newParent
== oldParent
)
790 // unlink this window from the existing parent.
793 oldParent
->RemoveChild(this);
797 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
800 // add it to the new one
803 newParent
->AddChild(this);
807 wxTopLevelWindows
.Append((wxWindow
*)this);
813 // ----------------------------------------------------------------------------
814 // event handler stuff
815 // ----------------------------------------------------------------------------
817 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
819 wxEvtHandler
*handlerOld
= GetEventHandler();
821 handler
->SetNextHandler(handlerOld
);
824 GetEventHandler()->SetPreviousHandler(handler
);
826 SetEventHandler(handler
);
829 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
831 wxEvtHandler
*handlerA
= GetEventHandler();
834 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
835 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
838 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
839 SetEventHandler(handlerB
);
844 handlerA
= (wxEvtHandler
*)NULL
;
851 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
853 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
855 wxEvtHandler
*handlerPrev
= NULL
,
856 *handlerCur
= GetEventHandler();
859 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
861 if ( handlerCur
== handler
)
865 handlerPrev
->SetNextHandler(handlerNext
);
869 SetEventHandler(handlerNext
);
874 handlerNext
->SetPreviousHandler ( handlerPrev
);
877 handler
->SetNextHandler(NULL
);
878 handler
->SetPreviousHandler(NULL
);
883 handlerPrev
= handlerCur
;
884 handlerCur
= handlerNext
;
887 wxFAIL_MSG( _T("where has the event handler gone?") );
892 // ----------------------------------------------------------------------------
894 // ----------------------------------------------------------------------------
896 void wxWindowBase::InheritAttributes()
898 const wxWindowBase
* const parent
= GetParent();
902 // we only inherit attributes which had been explicitly set for the parent
903 // which ensures that this only happens if the user really wants it and
904 // not by default which wouldn't make any sense in modern GUIs where the
905 // controls don't all use the same fonts (nor colours)
906 if ( parent
->m_inheritFont
&& !m_hasFont
)
907 SetFont(parent
->GetFont());
909 // in addition, there is a possibility to explicitly forbid inheriting
910 // colours at each class level by overriding ShouldInheritColours()
911 if ( ShouldInheritColours() )
913 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
914 SetForegroundColour(parent
->GetForegroundColour());
916 // inheriting (solid) background colour is wrong as it totally breaks
917 // any kind of themed backgrounds
919 // instead, the controls should use the same background as their parent
920 // (ideally by not drawing it at all)
922 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
923 SetBackgroundColour(parent
->GetBackgroundColour());
928 /* static */ wxVisualAttributes
929 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
931 // it is important to return valid values for all attributes from here,
932 // GetXXX() below rely on this
933 wxVisualAttributes attrs
;
934 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
935 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
937 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
938 // the usual background colour than wxSYS_COLOUR_BTNFACE.
939 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
940 // colour on other platforms.
942 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
943 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
945 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
950 wxColour
wxWindowBase::GetBackgroundColour() const
952 if ( !m_backgroundColour
.Ok() )
954 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
956 // get our default background colour
957 wxColour colBg
= GetDefaultAttributes().colBg
;
959 // we must return some valid colour to avoid redoing this every time
960 // and also to avoid surprizing the applications written for older
961 // wxWidgets versions where GetBackgroundColour() always returned
962 // something -- so give them something even if it doesn't make sense
963 // for this window (e.g. it has a themed background)
965 colBg
= GetClassDefaultAttributes().colBg
;
970 return m_backgroundColour
;
973 wxColour
wxWindowBase::GetForegroundColour() const
975 // logic is the same as above
976 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
978 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
980 wxColour colFg
= GetDefaultAttributes().colFg
;
983 colFg
= GetClassDefaultAttributes().colFg
;
988 return m_foregroundColour
;
991 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
993 if ( colour
== m_backgroundColour
)
996 m_hasBgCol
= colour
.Ok();
997 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
998 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1000 m_inheritBgCol
= m_hasBgCol
;
1001 m_backgroundColour
= colour
;
1002 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1006 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1008 if (colour
== m_foregroundColour
)
1011 m_hasFgCol
= colour
.Ok();
1012 m_inheritFgCol
= m_hasFgCol
;
1013 m_foregroundColour
= colour
;
1014 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1018 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1020 // setting an invalid cursor is ok, it means that we don't have any special
1022 if ( m_cursor
== cursor
)
1033 wxFont
wxWindowBase::GetFont() const
1035 // logic is the same as in GetBackgroundColour()
1038 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1040 wxFont font
= GetDefaultAttributes().font
;
1042 font
= GetClassDefaultAttributes().font
;
1050 bool wxWindowBase::SetFont(const wxFont
& font
)
1052 if ( font
== m_font
)
1059 m_hasFont
= font
.Ok();
1060 m_inheritFont
= m_hasFont
;
1062 InvalidateBestSize();
1069 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1071 m_hasCustomPalette
= true;
1074 // VZ: can anyone explain me what do we do here?
1075 wxWindowDC
d((wxWindow
*) this);
1079 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1081 wxWindow
*win
= (wxWindow
*)this;
1082 while ( win
&& !win
->HasCustomPalette() )
1084 win
= win
->GetParent();
1090 #endif // wxUSE_PALETTE
1093 void wxWindowBase::SetCaret(wxCaret
*caret
)
1104 wxASSERT_MSG( m_caret
->GetWindow() == this,
1105 wxT("caret should be created associated to this window") );
1108 #endif // wxUSE_CARET
1110 #if wxUSE_VALIDATORS
1111 // ----------------------------------------------------------------------------
1113 // ----------------------------------------------------------------------------
1115 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1117 if ( m_windowValidator
)
1118 delete m_windowValidator
;
1120 m_windowValidator
= (wxValidator
*)validator
.Clone();
1122 if ( m_windowValidator
)
1123 m_windowValidator
->SetWindow(this);
1125 #endif // wxUSE_VALIDATORS
1127 // ----------------------------------------------------------------------------
1128 // update region stuff
1129 // ----------------------------------------------------------------------------
1131 wxRect
wxWindowBase::GetUpdateClientRect() const
1133 wxRegion rgnUpdate
= GetUpdateRegion();
1134 rgnUpdate
.Intersect(GetClientRect());
1135 wxRect rectUpdate
= rgnUpdate
.GetBox();
1136 wxPoint ptOrigin
= GetClientAreaOrigin();
1137 rectUpdate
.x
-= ptOrigin
.x
;
1138 rectUpdate
.y
-= ptOrigin
.y
;
1143 bool wxWindowBase::IsExposed(int x
, int y
) const
1145 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1148 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1150 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1153 void wxWindowBase::ClearBackground()
1155 // wxGTK uses its own version, no need to add never used code
1157 wxClientDC
dc((wxWindow
*)this);
1158 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1159 dc
.SetBackground(brush
);
1164 // ----------------------------------------------------------------------------
1165 // find child window by id or name
1166 // ----------------------------------------------------------------------------
1168 wxWindow
*wxWindowBase::FindWindow(long id
) const
1170 if ( id
== m_windowId
)
1171 return (wxWindow
*)this;
1173 wxWindowBase
*res
= (wxWindow
*)NULL
;
1174 wxWindowList::compatibility_iterator node
;
1175 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1177 wxWindowBase
*child
= node
->GetData();
1178 res
= child
->FindWindow( id
);
1181 return (wxWindow
*)res
;
1184 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1186 if ( name
== m_windowName
)
1187 return (wxWindow
*)this;
1189 wxWindowBase
*res
= (wxWindow
*)NULL
;
1190 wxWindowList::compatibility_iterator node
;
1191 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1193 wxWindow
*child
= node
->GetData();
1194 res
= child
->FindWindow(name
);
1197 return (wxWindow
*)res
;
1201 // find any window by id or name or label: If parent is non-NULL, look through
1202 // children for a label or title matching the specified string. If NULL, look
1203 // through all top-level windows.
1205 // to avoid duplicating code we reuse the same helper function but with
1206 // different comparators
1208 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1209 const wxString
& label
, long id
);
1212 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1215 return win
->GetLabel() == label
;
1219 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1222 return win
->GetName() == label
;
1226 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1229 return win
->GetId() == id
;
1232 // recursive helper for the FindWindowByXXX() functions
1234 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1235 const wxString
& label
,
1237 wxFindWindowCmp cmp
)
1241 // see if this is the one we're looking for
1242 if ( (*cmp
)(parent
, label
, id
) )
1243 return (wxWindow
*)parent
;
1245 // It wasn't, so check all its children
1246 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1248 node
= node
->GetNext() )
1250 // recursively check each child
1251 wxWindow
*win
= (wxWindow
*)node
->GetData();
1252 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1262 // helper for FindWindowByXXX()
1264 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1265 const wxString
& label
,
1267 wxFindWindowCmp cmp
)
1271 // just check parent and all its children
1272 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1275 // start at very top of wx's windows
1276 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1278 node
= node
->GetNext() )
1280 // recursively check each window & its children
1281 wxWindow
*win
= node
->GetData();
1282 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1292 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1294 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1299 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1301 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1305 // fall back to the label
1306 win
= FindWindowByLabel(title
, parent
);
1314 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1316 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1319 // ----------------------------------------------------------------------------
1320 // dialog oriented functions
1321 // ----------------------------------------------------------------------------
1323 void wxWindowBase::MakeModal(bool modal
)
1325 // Disable all other windows
1328 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1331 wxWindow
*win
= node
->GetData();
1333 win
->Enable(!modal
);
1335 node
= node
->GetNext();
1340 bool wxWindowBase::Validate()
1342 #if wxUSE_VALIDATORS
1343 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1345 wxWindowList::compatibility_iterator node
;
1346 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1348 wxWindowBase
*child
= node
->GetData();
1349 wxValidator
*validator
= child
->GetValidator();
1350 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1355 if ( recurse
&& !child
->Validate() )
1360 #endif // wxUSE_VALIDATORS
1365 bool wxWindowBase::TransferDataToWindow()
1367 #if wxUSE_VALIDATORS
1368 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1370 wxWindowList::compatibility_iterator node
;
1371 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1373 wxWindowBase
*child
= node
->GetData();
1374 wxValidator
*validator
= child
->GetValidator();
1375 if ( validator
&& !validator
->TransferToWindow() )
1377 wxLogWarning(_("Could not transfer data to window"));
1379 wxLog::FlushActive();
1387 if ( !child
->TransferDataToWindow() )
1389 // warning already given
1394 #endif // wxUSE_VALIDATORS
1399 bool wxWindowBase::TransferDataFromWindow()
1401 #if wxUSE_VALIDATORS
1402 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1404 wxWindowList::compatibility_iterator node
;
1405 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1407 wxWindow
*child
= node
->GetData();
1408 wxValidator
*validator
= child
->GetValidator();
1409 if ( validator
&& !validator
->TransferFromWindow() )
1411 // nop warning here because the application is supposed to give
1412 // one itself - we don't know here what might have gone wrongly
1419 if ( !child
->TransferDataFromWindow() )
1421 // warning already given
1426 #endif // wxUSE_VALIDATORS
1431 void wxWindowBase::InitDialog()
1433 wxInitDialogEvent
event(GetId());
1434 event
.SetEventObject( this );
1435 GetEventHandler()->ProcessEvent(event
);
1438 // ----------------------------------------------------------------------------
1439 // context-sensitive help support
1440 // ----------------------------------------------------------------------------
1444 // associate this help text with this window
1445 void wxWindowBase::SetHelpText(const wxString
& text
)
1447 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1450 helpProvider
->AddHelp(this, text
);
1454 // associate this help text with all windows with the same id as this
1456 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1458 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1461 helpProvider
->AddHelp(GetId(), text
);
1465 // get the help string associated with this window (may be empty)
1466 // default implementation forwards calls to the help provider
1468 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1469 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1472 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1475 text
= helpProvider
->GetHelp(this);
1481 // show help for this window
1482 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1484 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1487 if ( helpProvider
->ShowHelpAtPoint(this, event
.GetPosition(), event
.GetOrigin()) )
1489 // skip the event.Skip() below
1497 #endif // wxUSE_HELP
1499 // ----------------------------------------------------------------------------
1500 // tooltipsroot.Replace("\\", "/");
1501 // ----------------------------------------------------------------------------
1505 void wxWindowBase::SetToolTip( const wxString
&tip
)
1507 // don't create the new tooltip if we already have one
1510 m_tooltip
->SetTip( tip
);
1514 SetToolTip( new wxToolTip( tip
) );
1517 // setting empty tooltip text does not remove the tooltip any more - use
1518 // SetToolTip((wxToolTip *)NULL) for this
1521 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1523 if ( m_tooltip
!= tooltip
)
1528 m_tooltip
= tooltip
;
1532 #endif // wxUSE_TOOLTIPS
1534 // ----------------------------------------------------------------------------
1535 // constraints and sizers
1536 // ----------------------------------------------------------------------------
1538 #if wxUSE_CONSTRAINTS
1540 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1542 if ( m_constraints
)
1544 UnsetConstraints(m_constraints
);
1545 delete m_constraints
;
1547 m_constraints
= constraints
;
1548 if ( m_constraints
)
1550 // Make sure other windows know they're part of a 'meaningful relationship'
1551 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1552 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1553 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1554 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1555 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1556 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1557 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1558 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1559 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1560 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1561 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1562 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1563 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1564 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1565 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1566 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1570 // This removes any dangling pointers to this window in other windows'
1571 // constraintsInvolvedIn lists.
1572 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1576 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1577 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1578 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1579 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1580 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1581 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1582 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1583 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1584 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1585 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1586 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1587 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1588 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1589 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1590 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1591 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1595 // Back-pointer to other windows we're involved with, so if we delete this
1596 // window, we must delete any constraints we're involved with.
1597 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1599 if ( !m_constraintsInvolvedIn
)
1600 m_constraintsInvolvedIn
= new wxWindowList
;
1601 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1602 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1605 // REMOVE back-pointer to other windows we're involved with.
1606 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1608 if ( m_constraintsInvolvedIn
)
1609 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1612 // Reset any constraints that mention this window
1613 void wxWindowBase::DeleteRelatedConstraints()
1615 if ( m_constraintsInvolvedIn
)
1617 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1620 wxWindow
*win
= node
->GetData();
1621 wxLayoutConstraints
*constr
= win
->GetConstraints();
1623 // Reset any constraints involving this window
1626 constr
->left
.ResetIfWin(this);
1627 constr
->top
.ResetIfWin(this);
1628 constr
->right
.ResetIfWin(this);
1629 constr
->bottom
.ResetIfWin(this);
1630 constr
->width
.ResetIfWin(this);
1631 constr
->height
.ResetIfWin(this);
1632 constr
->centreX
.ResetIfWin(this);
1633 constr
->centreY
.ResetIfWin(this);
1636 wxWindowList::compatibility_iterator next
= node
->GetNext();
1637 m_constraintsInvolvedIn
->Erase(node
);
1641 delete m_constraintsInvolvedIn
;
1642 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1646 #endif // wxUSE_CONSTRAINTS
1648 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1650 if ( sizer
== m_windowSizer
)
1653 if ( m_windowSizer
)
1655 m_windowSizer
->SetContainingWindow(NULL
);
1658 delete m_windowSizer
;
1661 m_windowSizer
= sizer
;
1662 if ( m_windowSizer
)
1664 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
1667 SetAutoLayout(m_windowSizer
!= NULL
);
1670 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1672 SetSizer( sizer
, deleteOld
);
1673 sizer
->SetSizeHints( (wxWindow
*) this );
1677 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1679 // adding a window to a sizer twice is going to result in fatal and
1680 // hard to debug problems later because when deleting the second
1681 // associated wxSizerItem we're going to dereference a dangling
1682 // pointer; so try to detect this as early as possible
1683 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1684 _T("Adding a window to the same sizer twice?") );
1686 m_containingSizer
= sizer
;
1689 #if wxUSE_CONSTRAINTS
1691 void wxWindowBase::SatisfyConstraints()
1693 wxLayoutConstraints
*constr
= GetConstraints();
1694 bool wasOk
= constr
&& constr
->AreSatisfied();
1696 ResetConstraints(); // Mark all constraints as unevaluated
1700 // if we're a top level panel (i.e. our parent is frame/dialog), our
1701 // own constraints will never be satisfied any more unless we do it
1705 while ( noChanges
> 0 )
1707 LayoutPhase1(&noChanges
);
1711 LayoutPhase2(&noChanges
);
1714 #endif // wxUSE_CONSTRAINTS
1716 bool wxWindowBase::Layout()
1718 // If there is a sizer, use it instead of the constraints
1722 GetVirtualSize(&w
, &h
);
1723 GetSizer()->SetDimension( 0, 0, w
, h
);
1725 #if wxUSE_CONSTRAINTS
1728 SatisfyConstraints(); // Find the right constraints values
1729 SetConstraintSizes(); // Recursively set the real window sizes
1736 #if wxUSE_CONSTRAINTS
1738 // first phase of the constraints evaluation: set our own constraints
1739 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1741 wxLayoutConstraints
*constr
= GetConstraints();
1743 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1746 // second phase: set the constraints for our children
1747 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1754 // Layout grand children
1760 // Do a phase of evaluating child constraints
1761 bool wxWindowBase::DoPhase(int phase
)
1763 // the list containing the children for which the constraints are already
1765 wxWindowList succeeded
;
1767 // the max number of iterations we loop before concluding that we can't set
1769 static const int maxIterations
= 500;
1771 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1775 // loop over all children setting their constraints
1776 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1778 node
= node
->GetNext() )
1780 wxWindow
*child
= node
->GetData();
1781 if ( child
->IsTopLevel() )
1783 // top level children are not inside our client area
1787 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1789 // this one is either already ok or nothing we can do about it
1793 int tempNoChanges
= 0;
1794 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1795 : child
->LayoutPhase2(&tempNoChanges
);
1796 noChanges
+= tempNoChanges
;
1800 succeeded
.Append(child
);
1806 // constraints are set
1814 void wxWindowBase::ResetConstraints()
1816 wxLayoutConstraints
*constr
= GetConstraints();
1819 constr
->left
.SetDone(false);
1820 constr
->top
.SetDone(false);
1821 constr
->right
.SetDone(false);
1822 constr
->bottom
.SetDone(false);
1823 constr
->width
.SetDone(false);
1824 constr
->height
.SetDone(false);
1825 constr
->centreX
.SetDone(false);
1826 constr
->centreY
.SetDone(false);
1829 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1832 wxWindow
*win
= node
->GetData();
1833 if ( !win
->IsTopLevel() )
1834 win
->ResetConstraints();
1835 node
= node
->GetNext();
1839 // Need to distinguish between setting the 'fake' size for windows and sizers,
1840 // and setting the real values.
1841 void wxWindowBase::SetConstraintSizes(bool recurse
)
1843 wxLayoutConstraints
*constr
= GetConstraints();
1844 if ( constr
&& constr
->AreSatisfied() )
1846 int x
= constr
->left
.GetValue();
1847 int y
= constr
->top
.GetValue();
1848 int w
= constr
->width
.GetValue();
1849 int h
= constr
->height
.GetValue();
1851 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1852 (constr
->height
.GetRelationship() != wxAsIs
) )
1854 SetSize(x
, y
, w
, h
);
1858 // If we don't want to resize this window, just move it...
1864 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1865 GetClassInfo()->GetClassName(),
1871 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1874 wxWindow
*win
= node
->GetData();
1875 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1876 win
->SetConstraintSizes();
1877 node
= node
->GetNext();
1882 // Only set the size/position of the constraint (if any)
1883 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1885 wxLayoutConstraints
*constr
= GetConstraints();
1888 if ( x
!= wxDefaultCoord
)
1890 constr
->left
.SetValue(x
);
1891 constr
->left
.SetDone(true);
1893 if ( y
!= wxDefaultCoord
)
1895 constr
->top
.SetValue(y
);
1896 constr
->top
.SetDone(true);
1898 if ( w
!= wxDefaultCoord
)
1900 constr
->width
.SetValue(w
);
1901 constr
->width
.SetDone(true);
1903 if ( h
!= wxDefaultCoord
)
1905 constr
->height
.SetValue(h
);
1906 constr
->height
.SetDone(true);
1911 void wxWindowBase::MoveConstraint(int x
, int y
)
1913 wxLayoutConstraints
*constr
= GetConstraints();
1916 if ( x
!= wxDefaultCoord
)
1918 constr
->left
.SetValue(x
);
1919 constr
->left
.SetDone(true);
1921 if ( y
!= wxDefaultCoord
)
1923 constr
->top
.SetValue(y
);
1924 constr
->top
.SetDone(true);
1929 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1931 wxLayoutConstraints
*constr
= GetConstraints();
1934 *w
= constr
->width
.GetValue();
1935 *h
= constr
->height
.GetValue();
1941 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1943 wxLayoutConstraints
*constr
= GetConstraints();
1946 *w
= constr
->width
.GetValue();
1947 *h
= constr
->height
.GetValue();
1950 GetClientSize(w
, h
);
1953 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1955 wxLayoutConstraints
*constr
= GetConstraints();
1958 *x
= constr
->left
.GetValue();
1959 *y
= constr
->top
.GetValue();
1965 #endif // wxUSE_CONSTRAINTS
1967 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1969 // don't do it for the dialogs/frames - they float independently of their
1971 if ( !IsTopLevel() )
1973 wxWindow
*parent
= GetParent();
1974 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1976 wxPoint
pt(parent
->GetClientAreaOrigin());
1983 // ----------------------------------------------------------------------------
1984 // do Update UI processing for child controls
1985 // ----------------------------------------------------------------------------
1987 void wxWindowBase::UpdateWindowUI(long flags
)
1989 wxUpdateUIEvent
event(GetId());
1990 event
.SetEventObject(this);
1992 if ( GetEventHandler()->ProcessEvent(event
) )
1994 DoUpdateWindowUI(event
);
1997 if (flags
& wxUPDATE_UI_RECURSE
)
1999 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2002 wxWindow
* child
= (wxWindow
*) node
->GetData();
2003 child
->UpdateWindowUI(flags
);
2004 node
= node
->GetNext();
2009 // do the window-specific processing after processing the update event
2010 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2012 if ( event
.GetSetEnabled() )
2013 Enable(event
.GetEnabled());
2015 if ( event
.GetSetShown() )
2016 Show(event
.GetShown());
2020 // call internal idle recursively
2021 // may be obsolete (wait until OnIdle scheme stabilises)
2022 void wxWindowBase::ProcessInternalIdle()
2026 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2029 wxWindow
*child
= node
->GetData();
2030 child
->ProcessInternalIdle();
2031 node
= node
->GetNext();
2036 // ----------------------------------------------------------------------------
2037 // dialog units translations
2038 // ----------------------------------------------------------------------------
2040 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2042 int charWidth
= GetCharWidth();
2043 int charHeight
= GetCharHeight();
2044 wxPoint pt2
= wxDefaultPosition
;
2045 if (pt
.x
!= wxDefaultCoord
)
2046 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2047 if (pt
.y
!= wxDefaultCoord
)
2048 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2053 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2055 int charWidth
= GetCharWidth();
2056 int charHeight
= GetCharHeight();
2057 wxPoint pt2
= wxDefaultPosition
;
2058 if (pt
.x
!= wxDefaultCoord
)
2059 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2060 if (pt
.y
!= wxDefaultCoord
)
2061 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2066 // ----------------------------------------------------------------------------
2068 // ----------------------------------------------------------------------------
2070 // propagate the colour change event to the subwindows
2071 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2073 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2076 // Only propagate to non-top-level windows
2077 wxWindow
*win
= node
->GetData();
2078 if ( !win
->IsTopLevel() )
2080 wxSysColourChangedEvent event2
;
2081 event
.SetEventObject(win
);
2082 win
->GetEventHandler()->ProcessEvent(event2
);
2085 node
= node
->GetNext();
2091 // the default action is to populate dialog with data when it's created,
2092 // and nudge the UI into displaying itself correctly in case
2093 // we've turned the wxUpdateUIEvents frequency down low.
2094 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2096 TransferDataToWindow();
2098 // Update the UI at this point
2099 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2102 // methods for drawing the sizers in a visible way
2105 static void DrawSizers(wxWindowBase
*win
);
2107 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2109 wxClientDC
dc((wxWindow
*)win
);
2110 dc
.SetPen(*wxRED_PEN
);
2111 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2112 dc
.DrawRectangle(rect
.Deflate(1, 1));
2115 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2117 const wxSizerItemList
& items
= sizer
->GetChildren();
2118 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2123 wxSizerItem
*item
= *i
;
2124 if ( item
->IsSizer() )
2126 DrawBorder(win
, item
->GetRect().Deflate(2));
2127 DrawSizer(win
, item
->GetSizer());
2129 else if ( item
->IsSpacer() )
2131 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2133 else if ( item
->IsWindow() )
2135 DrawSizers(item
->GetWindow());
2140 static void DrawSizers(wxWindowBase
*win
)
2142 wxSizer
*sizer
= win
->GetSizer();
2145 DrawBorder(win
, win
->GetClientSize());
2146 DrawSizer(win
, sizer
);
2148 else // no sizer, still recurse into the children
2150 const wxWindowList
& children
= win
->GetChildren();
2151 for ( wxWindowList::const_iterator i
= children
.begin(),
2152 end
= children
.end();
2161 #endif // __WXDEBUG__
2163 // process special middle clicks
2164 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2166 if ( event
.ControlDown() && event
.AltDown() )
2169 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2170 if ( event
.ShiftDown() )
2175 #endif // __WXDEBUG__
2178 // don't translate these strings, they're for diagnostics purposes only
2180 msg
.Printf(_T("wxWidgets Library (%s port)\n")
2181 _T("Version %d.%d.%d%s%s, compiled at %s %s%s\n")
2182 _T("Copyright (c) 1995-2006 wxWidgets team"),
2183 wxPlatformInfo().GetPortIdName().c_str(),
2200 wxString::Format(_T("\nagainst GTK+ %d.%d.%d. Runtime GTK+ version: %d.%d.%d"), GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
, gtk_major_version
, gtk_minor_version
, gtk_micro_version
).c_str()
2206 wxMessageBox(msg
, _T("wxWidgets information"),
2207 wxICON_INFORMATION
| wxOK
,
2211 #endif // wxUSE_MSGDLG
2217 // ----------------------------------------------------------------------------
2219 // ----------------------------------------------------------------------------
2221 #if wxUSE_ACCESSIBILITY
2222 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2224 if (m_accessible
&& (accessible
!= m_accessible
))
2225 delete m_accessible
;
2226 m_accessible
= accessible
;
2228 m_accessible
->SetWindow((wxWindow
*) this);
2231 // Returns the accessible object, creating if necessary.
2232 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2235 m_accessible
= CreateAccessible();
2236 return m_accessible
;
2239 // Override to create a specific accessible object.
2240 wxAccessible
* wxWindowBase::CreateAccessible()
2242 return new wxWindowAccessible((wxWindow
*) this);
2247 // ----------------------------------------------------------------------------
2248 // list classes implementation
2249 // ----------------------------------------------------------------------------
2253 #include "wx/listimpl.cpp"
2254 WX_DEFINE_LIST(wxWindowList
)
2258 void wxWindowListNode::DeleteData()
2260 delete (wxWindow
*)GetData();
2265 // ----------------------------------------------------------------------------
2267 // ----------------------------------------------------------------------------
2269 wxBorder
wxWindowBase::GetBorder(long flags
) const
2271 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2272 if ( border
== wxBORDER_DEFAULT
)
2274 border
= GetDefaultBorder();
2280 wxBorder
wxWindowBase::GetDefaultBorder() const
2282 return wxBORDER_NONE
;
2285 // ----------------------------------------------------------------------------
2287 // ----------------------------------------------------------------------------
2289 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2291 // here we just check if the point is inside the window or not
2293 // check the top and left border first
2294 bool outside
= x
< 0 || y
< 0;
2297 // check the right and bottom borders too
2298 wxSize size
= GetSize();
2299 outside
= x
>= size
.x
|| y
>= size
.y
;
2302 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2305 // ----------------------------------------------------------------------------
2307 // ----------------------------------------------------------------------------
2309 struct WXDLLEXPORT wxWindowNext
2313 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2314 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2315 bool wxWindowBase::ms_winCaptureChanging
= false;
2317 void wxWindowBase::CaptureMouse()
2319 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2321 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2323 ms_winCaptureChanging
= true;
2325 wxWindow
*winOld
= GetCapture();
2328 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2331 wxWindowNext
*item
= new wxWindowNext
;
2333 item
->next
= ms_winCaptureNext
;
2334 ms_winCaptureNext
= item
;
2336 //else: no mouse capture to save
2339 ms_winCaptureCurrent
= (wxWindow
*)this;
2341 ms_winCaptureChanging
= false;
2344 void wxWindowBase::ReleaseMouse()
2346 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2348 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2350 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2352 ms_winCaptureChanging
= true;
2355 ms_winCaptureCurrent
= NULL
;
2357 if ( ms_winCaptureNext
)
2359 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2360 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2362 wxWindowNext
*item
= ms_winCaptureNext
;
2363 ms_winCaptureNext
= item
->next
;
2366 //else: stack is empty, no previous capture
2368 ms_winCaptureChanging
= false;
2370 wxLogTrace(_T("mousecapture"),
2371 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2372 wx_static_cast(void*, GetCapture()));
2375 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2377 wxMouseCaptureLostEvent
event(win
->GetId());
2378 event
.SetEventObject(win
);
2379 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2381 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2386 void wxWindowBase::NotifyCaptureLost()
2388 // don't do anything if capture lost was expected, i.e. resulted from
2389 // a wx call to ReleaseMouse or CaptureMouse:
2390 if ( ms_winCaptureChanging
)
2393 // if the capture was lost unexpectedly, notify every window that has
2394 // capture (on stack or current) about it and clear the stack:
2396 if ( ms_winCaptureCurrent
)
2398 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2399 ms_winCaptureCurrent
= NULL
;
2402 while ( ms_winCaptureNext
)
2404 wxWindowNext
*item
= ms_winCaptureNext
;
2405 ms_winCaptureNext
= item
->next
;
2407 DoNotifyWindowAboutCaptureLost(item
->win
);
2416 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2417 int WXUNUSED(modifiers
),
2418 int WXUNUSED(keycode
))
2424 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2430 #endif // wxUSE_HOTKEY
2432 void wxWindowBase::SendDestroyEvent()
2434 wxWindowDestroyEvent event
;
2435 event
.SetEventObject(this);
2436 event
.SetId(GetId());
2437 GetEventHandler()->ProcessEvent(event
);
2440 // ----------------------------------------------------------------------------
2442 // ----------------------------------------------------------------------------
2444 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2446 #if wxUSE_VALIDATORS
2447 // Can only use the validator of the window which
2448 // is receiving the event
2449 if ( event
.GetEventObject() == this )
2451 wxValidator
*validator
= GetValidator();
2452 if ( validator
&& validator
->ProcessEvent(event
) )
2457 #endif // wxUSE_VALIDATORS
2462 bool wxWindowBase::TryParent(wxEvent
& event
)
2464 // carry on up the parent-child hierarchy if the propagation count hasn't
2466 if ( event
.ShouldPropagate() )
2468 // honour the requests to stop propagation at this window: this is
2469 // used by the dialogs, for example, to prevent processing the events
2470 // from the dialog controls in the parent frame which rarely, if ever,
2472 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2474 wxWindow
*parent
= GetParent();
2475 if ( parent
&& !parent
->IsBeingDeleted() )
2477 wxPropagateOnce
propagateOnce(event
);
2479 return parent
->GetEventHandler()->ProcessEvent(event
);
2484 return wxEvtHandler::TryParent(event
);
2487 // ----------------------------------------------------------------------------
2488 // keyboard navigation
2489 // ----------------------------------------------------------------------------
2491 // Navigates in the specified direction.
2492 bool wxWindowBase::Navigate(int flags
)
2494 wxNavigationKeyEvent eventNav
;
2495 eventNav
.SetFlags(flags
);
2496 eventNav
.SetEventObject(this);
2497 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2504 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2506 // check that we're not a top level window
2507 wxCHECK_RET( GetParent(),
2508 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2510 // detect the special case when we have nothing to do anyhow and when the
2511 // code below wouldn't work
2515 // find the target window in the siblings list
2516 wxWindowList
& siblings
= GetParent()->GetChildren();
2517 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2518 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2520 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2521 // can't just move the node around
2522 wxWindow
*self
= (wxWindow
*)this;
2523 siblings
.DeleteObject(self
);
2524 if ( move
== MoveAfter
)
2531 siblings
.Insert(i
, self
);
2533 else // MoveAfter and win was the last sibling
2535 siblings
.Append(self
);
2539 // ----------------------------------------------------------------------------
2541 // ----------------------------------------------------------------------------
2543 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2545 wxWindowBase
*win
= DoFindFocus();
2546 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2549 // ----------------------------------------------------------------------------
2551 // ----------------------------------------------------------------------------
2553 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2555 while ( win
&& !win
->IsTopLevel() )
2556 win
= win
->GetParent();
2561 #if wxUSE_ACCESSIBILITY
2562 // ----------------------------------------------------------------------------
2563 // accessible object for windows
2564 // ----------------------------------------------------------------------------
2566 // Can return either a child object, or an integer
2567 // representing the child element, starting from 1.
2568 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2570 wxASSERT( GetWindow() != NULL
);
2574 return wxACC_NOT_IMPLEMENTED
;
2577 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2578 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2580 wxASSERT( GetWindow() != NULL
);
2584 wxWindow
* win
= NULL
;
2591 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2593 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2600 rect
= win
->GetRect();
2601 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2602 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2606 return wxACC_NOT_IMPLEMENTED
;
2609 // Navigates from fromId to toId/toObject.
2610 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2611 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2613 wxASSERT( GetWindow() != NULL
);
2619 case wxNAVDIR_FIRSTCHILD
:
2621 if (GetWindow()->GetChildren().GetCount() == 0)
2623 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2624 *toObject
= childWindow
->GetOrCreateAccessible();
2628 case wxNAVDIR_LASTCHILD
:
2630 if (GetWindow()->GetChildren().GetCount() == 0)
2632 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2633 *toObject
= childWindow
->GetOrCreateAccessible();
2637 case wxNAVDIR_RIGHT
:
2641 wxWindowList::compatibility_iterator node
=
2642 wxWindowList::compatibility_iterator();
2645 // Can't navigate to sibling of this window
2646 // if we're a top-level window.
2647 if (!GetWindow()->GetParent())
2648 return wxACC_NOT_IMPLEMENTED
;
2650 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2654 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2655 node
= GetWindow()->GetChildren().Item(fromId
-1);
2658 if (node
&& node
->GetNext())
2660 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2661 *toObject
= nextWindow
->GetOrCreateAccessible();
2669 case wxNAVDIR_PREVIOUS
:
2671 wxWindowList::compatibility_iterator node
=
2672 wxWindowList::compatibility_iterator();
2675 // Can't navigate to sibling of this window
2676 // if we're a top-level window.
2677 if (!GetWindow()->GetParent())
2678 return wxACC_NOT_IMPLEMENTED
;
2680 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2684 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2685 node
= GetWindow()->GetChildren().Item(fromId
-1);
2688 if (node
&& node
->GetPrevious())
2690 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2691 *toObject
= previousWindow
->GetOrCreateAccessible();
2699 return wxACC_NOT_IMPLEMENTED
;
2702 // Gets the name of the specified object.
2703 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2705 wxASSERT( GetWindow() != NULL
);
2711 // If a child, leave wxWidgets to call the function on the actual
2714 return wxACC_NOT_IMPLEMENTED
;
2716 // This will eventually be replaced by specialised
2717 // accessible classes, one for each kind of wxWidgets
2718 // control or window.
2720 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2721 title
= ((wxButton
*) GetWindow())->GetLabel();
2724 title
= GetWindow()->GetName();
2732 return wxACC_NOT_IMPLEMENTED
;
2735 // Gets the number of children.
2736 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2738 wxASSERT( GetWindow() != NULL
);
2742 *childId
= (int) GetWindow()->GetChildren().GetCount();
2746 // Gets the specified child (starting from 1).
2747 // If *child is NULL and return value is wxACC_OK,
2748 // this means that the child is a simple element and
2749 // not an accessible object.
2750 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2752 wxASSERT( GetWindow() != NULL
);
2762 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2765 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2766 *child
= childWindow
->GetOrCreateAccessible();
2773 // Gets the parent, or NULL.
2774 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2776 wxASSERT( GetWindow() != NULL
);
2780 wxWindow
* parentWindow
= GetWindow()->GetParent();
2788 *parent
= parentWindow
->GetOrCreateAccessible();
2796 // Performs the default action. childId is 0 (the action for this object)
2797 // or > 0 (the action for a child).
2798 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2799 // window (e.g. an edit control).
2800 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2802 wxASSERT( GetWindow() != NULL
);
2806 return wxACC_NOT_IMPLEMENTED
;
2809 // Gets the default action for this object (0) or > 0 (the action for a child).
2810 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2811 // string if there is no action.
2812 // The retrieved string describes the action that is performed on an object,
2813 // not what the object does as a result. For example, a toolbar button that prints
2814 // a document has a default action of "Press" rather than "Prints the current document."
2815 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2817 wxASSERT( GetWindow() != NULL
);
2821 return wxACC_NOT_IMPLEMENTED
;
2824 // Returns the description for this object or a child.
2825 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2827 wxASSERT( GetWindow() != NULL
);
2831 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2837 return wxACC_NOT_IMPLEMENTED
;
2840 // Returns help text for this object or a child, similar to tooltip text.
2841 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2843 wxASSERT( GetWindow() != NULL
);
2847 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2853 return wxACC_NOT_IMPLEMENTED
;
2856 // Returns the keyboard shortcut for this object or child.
2857 // Return e.g. ALT+K
2858 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2860 wxASSERT( GetWindow() != NULL
);
2864 return wxACC_NOT_IMPLEMENTED
;
2867 // Returns a role constant.
2868 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2870 wxASSERT( GetWindow() != NULL
);
2874 // If a child, leave wxWidgets to call the function on the actual
2877 return wxACC_NOT_IMPLEMENTED
;
2879 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2880 return wxACC_NOT_IMPLEMENTED
;
2882 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2883 return wxACC_NOT_IMPLEMENTED
;
2886 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2887 return wxACC_NOT_IMPLEMENTED
;
2890 //*role = wxROLE_SYSTEM_CLIENT;
2891 *role
= wxROLE_SYSTEM_CLIENT
;
2895 return wxACC_NOT_IMPLEMENTED
;
2899 // Returns a state constant.
2900 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2902 wxASSERT( GetWindow() != NULL
);
2906 // If a child, leave wxWidgets to call the function on the actual
2909 return wxACC_NOT_IMPLEMENTED
;
2911 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2912 return wxACC_NOT_IMPLEMENTED
;
2915 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2916 return wxACC_NOT_IMPLEMENTED
;
2919 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2920 return wxACC_NOT_IMPLEMENTED
;
2927 return wxACC_NOT_IMPLEMENTED
;
2931 // Returns a localized string representing the value for the object
2933 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2935 wxASSERT( GetWindow() != NULL
);
2939 return wxACC_NOT_IMPLEMENTED
;
2942 // Selects the object or child.
2943 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2945 wxASSERT( GetWindow() != NULL
);
2949 return wxACC_NOT_IMPLEMENTED
;
2952 // Gets the window with the keyboard focus.
2953 // If childId is 0 and child is NULL, no object in
2954 // this subhierarchy has the focus.
2955 // If this object has the focus, child should be 'this'.
2956 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2958 wxASSERT( GetWindow() != NULL
);
2962 return wxACC_NOT_IMPLEMENTED
;
2965 // Gets a variant representing the selected children
2967 // Acceptable values:
2968 // - a null variant (IsNull() returns true)
2969 // - a list variant (GetType() == wxT("list")
2970 // - an integer representing the selected child element,
2971 // or 0 if this object is selected (GetType() == wxT("long")
2972 // - a "void*" pointer to a wxAccessible child object
2973 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2975 wxASSERT( GetWindow() != NULL
);
2979 return wxACC_NOT_IMPLEMENTED
;
2982 #endif // wxUSE_ACCESSIBILITY