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
;
87 WXDLLIMPEXP_DATA_CORE(wxWindowList
) wxTopLevelWindows
;
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 #if defined(__WXPALMOS__)
94 int wxWindowBase::ms_lastControlId
= 32767;
95 #elif defined(__WXPM__)
96 int wxWindowBase::ms_lastControlId
= 2000;
98 int wxWindowBase::ms_lastControlId
= -200;
101 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
103 // ----------------------------------------------------------------------------
105 // ----------------------------------------------------------------------------
107 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
108 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
109 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
110 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
113 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
118 // ============================================================================
119 // implementation of the common functionality of the wxWindow class
120 // ============================================================================
122 // ----------------------------------------------------------------------------
124 // ----------------------------------------------------------------------------
126 // the default initialization
127 wxWindowBase::wxWindowBase()
129 // no window yet, no parent nor children
130 m_parent
= (wxWindow
*)NULL
;
131 m_windowId
= wxID_ANY
;
133 // no constraints on the minimal window size
135 m_maxWidth
= wxDefaultCoord
;
137 m_maxHeight
= wxDefaultCoord
;
139 // invalidiated cache value
140 m_bestSizeCache
= wxDefaultSize
;
142 // window are created enabled and visible by default
146 // the default event handler is just this window
147 m_eventHandler
= this;
151 m_windowValidator
= (wxValidator
*) NULL
;
152 #endif // wxUSE_VALIDATORS
154 // the colours/fonts are default for now, so leave m_font,
155 // m_backgroundColour and m_foregroundColour uninitialized and set those
161 m_inheritFont
= false;
167 m_backgroundStyle
= wxBG_STYLE_SYSTEM
;
169 #if wxUSE_CONSTRAINTS
170 // no constraints whatsoever
171 m_constraints
= (wxLayoutConstraints
*) NULL
;
172 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
173 #endif // wxUSE_CONSTRAINTS
175 m_windowSizer
= (wxSizer
*) NULL
;
176 m_containingSizer
= (wxSizer
*) NULL
;
177 m_autoLayout
= false;
179 #if wxUSE_DRAG_AND_DROP
180 m_dropTarget
= (wxDropTarget
*)NULL
;
181 #endif // wxUSE_DRAG_AND_DROP
184 m_tooltip
= (wxToolTip
*)NULL
;
185 #endif // wxUSE_TOOLTIPS
188 m_caret
= (wxCaret
*)NULL
;
189 #endif // wxUSE_CARET
192 m_hasCustomPalette
= false;
193 #endif // wxUSE_PALETTE
195 #if wxUSE_ACCESSIBILITY
199 m_virtualSize
= wxDefaultSize
;
202 m_maxVirtualWidth
= wxDefaultCoord
;
204 m_maxVirtualHeight
= wxDefaultCoord
;
206 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
207 #if wxUSE_SYSTEM_OPTIONS
208 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
210 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
214 // Whether we're using the current theme for this window (wxGTK only for now)
215 m_themeEnabled
= false;
217 // VZ: this one shouldn't exist...
218 m_isBeingDeleted
= false;
221 // common part of window creation process
222 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
224 const wxPoint
& WXUNUSED(pos
),
225 const wxSize
& WXUNUSED(size
),
227 const wxValidator
& wxVALIDATOR_PARAM(validator
),
228 const wxString
& name
)
231 // wxGTK doesn't allow to create controls with static box as the parent so
232 // this will result in a crash when the program is ported to wxGTK so warn
235 // if you get this assert, the correct solution is to create the controls
236 // as siblings of the static box
237 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
238 _T("wxStaticBox can't be used as a window parent!") );
239 #endif // wxUSE_STATBOX
241 // ids are limited to 16 bits under MSW so if you care about portability,
242 // it's not a good idea to use ids out of this range (and negative ids are
243 // reserved for wxWidgets own usage)
244 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
245 _T("invalid id value") );
247 // generate a new id if the user doesn't care about it
248 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
251 SetWindowStyleFlag(style
);
255 SetValidator(validator
);
256 #endif // wxUSE_VALIDATORS
258 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
259 // have it too - like this it's possible to set it only in the top level
260 // dialog/frame and all children will inherit it by defult
261 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
263 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
269 // ----------------------------------------------------------------------------
271 // ----------------------------------------------------------------------------
274 wxWindowBase::~wxWindowBase()
276 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
278 // FIXME if these 2 cases result from programming errors in the user code
279 // we should probably assert here instead of silently fixing them
281 // Just in case the window has been Closed, but we're then deleting
282 // immediately: don't leave dangling pointers.
283 wxPendingDelete
.DeleteObject(this);
285 // Just in case we've loaded a top-level window via LoadNativeDialog but
286 // we weren't a dialog class
287 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
289 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
291 // reset the dangling pointer our parent window may keep to us
294 m_parent
->RemoveChild(this);
299 #endif // wxUSE_CARET
302 delete m_windowValidator
;
303 #endif // wxUSE_VALIDATORS
305 #if wxUSE_CONSTRAINTS
306 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
307 // at deleted windows as they delete themselves.
308 DeleteRelatedConstraints();
312 // This removes any dangling pointers to this window in other windows'
313 // constraintsInvolvedIn lists.
314 UnsetConstraints(m_constraints
);
315 delete m_constraints
;
316 m_constraints
= NULL
;
318 #endif // wxUSE_CONSTRAINTS
320 if ( m_containingSizer
)
321 m_containingSizer
->Detach( (wxWindow
*)this );
323 delete m_windowSizer
;
325 #if wxUSE_DRAG_AND_DROP
327 #endif // wxUSE_DRAG_AND_DROP
331 #endif // wxUSE_TOOLTIPS
333 #if wxUSE_ACCESSIBILITY
338 bool wxWindowBase::Destroy()
345 bool wxWindowBase::Close(bool force
)
347 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
348 event
.SetEventObject(this);
349 event
.SetCanVeto(!force
);
351 // return false if window wasn't closed because the application vetoed the
353 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
356 bool wxWindowBase::DestroyChildren()
358 wxWindowList::compatibility_iterator node
;
361 // we iterate until the list becomes empty
362 node
= GetChildren().GetFirst();
366 wxWindow
*child
= node
->GetData();
368 // note that we really want to call delete and not ->Destroy() here
369 // because we want to delete the child immediately, before we are
370 // deleted, and delayed deletion would result in problems as our (top
371 // level) child could outlive its parent
374 wxASSERT_MSG( !GetChildren().Find(child
),
375 wxT("child didn't remove itself using RemoveChild()") );
381 // ----------------------------------------------------------------------------
382 // size/position related methods
383 // ----------------------------------------------------------------------------
385 // centre the window with respect to its parent in either (or both) directions
386 void wxWindowBase::DoCentre(int dir
)
388 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
389 _T("this method only implements centering child windows") );
391 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
394 // fits the window around the children
395 void wxWindowBase::Fit()
397 if ( !GetChildren().empty() )
399 SetSize(GetBestSize());
401 //else: do nothing if we have no children
404 // fits virtual size (ie. scrolled area etc.) around children
405 void wxWindowBase::FitInside()
407 if ( GetChildren().GetCount() > 0 )
409 SetVirtualSize( GetBestVirtualSize() );
413 // On Mac, scrollbars are explicitly children.
415 static bool wxHasRealChildren(const wxWindowBase
* win
)
417 int realChildCount
= 0;
419 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
421 node
= node
->GetNext() )
423 wxWindow
*win
= node
->GetData();
424 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
427 return (realChildCount
> 0);
431 void wxWindowBase::InvalidateBestSize()
433 m_bestSizeCache
= wxDefaultSize
;
435 // parent's best size calculation may depend on its children's
436 // as long as child window we are in is not top level window itself
437 // (because the TLW size is never resized automatically)
438 // so let's invalidate it as well to be safe:
439 if (m_parent
&& !IsTopLevel())
440 m_parent
->InvalidateBestSize();
443 // return the size best suited for the current window
444 wxSize
wxWindowBase::DoGetBestSize() const
450 best
= GetWindowSizeForVirtualSize(m_windowSizer
->GetMinSize());
452 #if wxUSE_CONSTRAINTS
453 else if ( m_constraints
)
455 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
457 // our minimal acceptable size is such that all our windows fit inside
461 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
463 node
= node
->GetNext() )
465 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
468 // it's not normal that we have an unconstrained child, but
469 // what can we do about it?
473 int x
= c
->right
.GetValue(),
474 y
= c
->bottom
.GetValue();
482 // TODO: we must calculate the overlaps somehow, otherwise we
483 // will never return a size bigger than the current one :-(
486 best
= wxSize(maxX
, maxY
);
488 #endif // wxUSE_CONSTRAINTS
489 else if ( !GetChildren().empty()
491 && wxHasRealChildren(this)
495 // our minimal acceptable size is such that all our visible child
496 // windows fit inside
500 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
502 node
= node
->GetNext() )
504 wxWindow
*win
= node
->GetData();
505 if ( win
->IsTopLevel()
508 || wxDynamicCast(win
, wxStatusBar
)
509 #endif // wxUSE_STATUSBAR
512 // dialogs and frames lie in different top level windows -
513 // don't deal with them here; as for the status bars, they
514 // don't lie in the client area at all
519 win
->GetPosition(&wx
, &wy
);
521 // if the window hadn't been positioned yet, assume that it is in
523 if ( wx
== wxDefaultCoord
)
525 if ( wy
== wxDefaultCoord
)
528 win
->GetSize(&ww
, &wh
);
529 if ( wx
+ ww
> maxX
)
531 if ( wy
+ wh
> maxY
)
535 best
= wxSize(maxX
, maxY
);
537 else // ! has children
539 // for a generic window there is no natural best size so, if the
540 // minimal size is not set, use the current size but take care to
541 // remember it as minimal size for the next time because our best size
542 // should be constant: otherwise we could get into a situation when the
543 // window is initially at some size, then expanded to a larger size and
544 // then, when the containing window is shrunk back (because our initial
545 // best size had been used for computing the parent min size), we can't
546 // be shrunk back any more because our best size is now bigger
547 wxSize size
= GetMinSize();
548 if ( !size
.IsFullySpecified() )
550 size
.SetDefaults(GetSize());
551 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
554 // return as-is, unadjusted by the client size difference.
558 // Add any difference between size and client size
559 wxSize diff
= GetSize() - GetClientSize();
560 best
.x
+= wxMax(0, diff
.x
);
561 best
.y
+= wxMax(0, diff
.y
);
567 wxSize
wxWindowBase::GetBestFittingSize() const
569 // merge the best size with the min size, giving priority to the min size
570 wxSize min
= GetMinSize();
571 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
573 wxSize best
= GetBestSize();
574 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
575 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
581 void wxWindowBase::SetBestFittingSize(const wxSize
& size
)
583 // Set the min size to the size passed in. This will usually either be
584 // wxDefaultSize or the size passed to this window's ctor/Create function.
587 // Merge the size with the best size if needed
588 wxSize best
= GetBestFittingSize();
590 // If the current size doesn't match then change it
591 if (GetSize() != best
)
596 // by default the origin is not shifted
597 wxPoint
wxWindowBase::GetClientAreaOrigin() const
602 // set the min/max size of the window
603 void wxWindowBase::DoSetSizeHints(int minW
, int minH
,
605 int WXUNUSED(incW
), int WXUNUSED(incH
))
607 // setting min width greater than max width leads to infinite loops under
608 // X11 and generally doesn't make any sense, so don't allow it
609 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
610 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
611 _T("min width/height must be less than max width/height!") );
619 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
621 if ( m_windowVariant
!= variant
)
623 m_windowVariant
= variant
;
625 DoSetWindowVariant(variant
);
629 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
631 // adjust the font height to correspond to our new variant (notice that
632 // we're only called if something really changed)
633 wxFont font
= GetFont();
634 int size
= font
.GetPointSize();
637 case wxWINDOW_VARIANT_NORMAL
:
640 case wxWINDOW_VARIANT_SMALL
:
645 case wxWINDOW_VARIANT_MINI
:
650 case wxWINDOW_VARIANT_LARGE
:
656 wxFAIL_MSG(_T("unexpected window variant"));
660 font
.SetPointSize(size
);
664 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
667 m_minVirtualWidth
= minW
;
668 m_maxVirtualWidth
= maxW
;
669 m_minVirtualHeight
= minH
;
670 m_maxVirtualHeight
= maxH
;
673 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
675 if ( m_minVirtualWidth
!= wxDefaultCoord
&& m_minVirtualWidth
> x
)
676 x
= m_minVirtualWidth
;
677 if ( m_maxVirtualWidth
!= wxDefaultCoord
&& m_maxVirtualWidth
< x
)
678 x
= m_maxVirtualWidth
;
679 if ( m_minVirtualHeight
!= wxDefaultCoord
&& m_minVirtualHeight
> y
)
680 y
= m_minVirtualHeight
;
681 if ( m_maxVirtualHeight
!= wxDefaultCoord
&& m_maxVirtualHeight
< y
)
682 y
= m_maxVirtualHeight
;
684 m_virtualSize
= wxSize(x
, y
);
687 wxSize
wxWindowBase::DoGetVirtualSize() const
689 // we should use the entire client area so if it is greater than our
690 // virtual size, expand it to fit (otherwise if the window is big enough we
691 // wouldn't be using parts of it)
692 wxSize size
= GetClientSize();
693 if ( m_virtualSize
.x
> size
.x
)
694 size
.x
= m_virtualSize
.x
;
696 if ( m_virtualSize
.y
>= size
.y
)
697 size
.y
= m_virtualSize
.y
;
702 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
704 // screen position is the same as (0, 0) in client coords for non TLWs (and
705 // TLWs override this method)
711 ClientToScreen(x
, y
);
714 // ----------------------------------------------------------------------------
715 // show/hide/enable/disable the window
716 // ----------------------------------------------------------------------------
718 bool wxWindowBase::Show(bool show
)
720 if ( show
!= m_isShown
)
732 bool wxWindowBase::Enable(bool enable
)
734 if ( enable
!= m_isEnabled
)
736 m_isEnabled
= enable
;
745 // ----------------------------------------------------------------------------
747 // ----------------------------------------------------------------------------
749 bool wxWindowBase::IsTopLevel() const
754 // ----------------------------------------------------------------------------
755 // reparenting the window
756 // ----------------------------------------------------------------------------
758 void wxWindowBase::AddChild(wxWindowBase
*child
)
760 wxCHECK_RET( child
, wxT("can't add a NULL child") );
762 // this should never happen and it will lead to a crash later if it does
763 // because RemoveChild() will remove only one node from the children list
764 // and the other(s) one(s) will be left with dangling pointers in them
765 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
767 GetChildren().Append((wxWindow
*)child
);
768 child
->SetParent(this);
771 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
773 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
775 GetChildren().DeleteObject((wxWindow
*)child
);
776 child
->SetParent(NULL
);
779 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
781 wxWindow
*oldParent
= GetParent();
782 if ( newParent
== oldParent
)
788 // unlink this window from the existing parent.
791 oldParent
->RemoveChild(this);
795 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
798 // add it to the new one
801 newParent
->AddChild(this);
805 wxTopLevelWindows
.Append((wxWindow
*)this);
811 // ----------------------------------------------------------------------------
812 // event handler stuff
813 // ----------------------------------------------------------------------------
815 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
817 wxEvtHandler
*handlerOld
= GetEventHandler();
819 handler
->SetNextHandler(handlerOld
);
822 GetEventHandler()->SetPreviousHandler(handler
);
824 SetEventHandler(handler
);
827 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
829 wxEvtHandler
*handlerA
= GetEventHandler();
832 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
833 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
836 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
837 SetEventHandler(handlerB
);
842 handlerA
= (wxEvtHandler
*)NULL
;
849 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
851 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
853 wxEvtHandler
*handlerPrev
= NULL
,
854 *handlerCur
= GetEventHandler();
857 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
859 if ( handlerCur
== handler
)
863 handlerPrev
->SetNextHandler(handlerNext
);
867 SetEventHandler(handlerNext
);
872 handlerNext
->SetPreviousHandler ( handlerPrev
);
875 handler
->SetNextHandler(NULL
);
876 handler
->SetPreviousHandler(NULL
);
881 handlerPrev
= handlerCur
;
882 handlerCur
= handlerNext
;
885 wxFAIL_MSG( _T("where has the event handler gone?") );
890 // ----------------------------------------------------------------------------
892 // ----------------------------------------------------------------------------
894 void wxWindowBase::InheritAttributes()
896 const wxWindowBase
* const parent
= GetParent();
900 // we only inherit attributes which had been explicitly set for the parent
901 // which ensures that this only happens if the user really wants it and
902 // not by default which wouldn't make any sense in modern GUIs where the
903 // controls don't all use the same fonts (nor colours)
904 if ( parent
->m_inheritFont
&& !m_hasFont
)
905 SetFont(parent
->GetFont());
907 // in addition, there is a possibility to explicitly forbid inheriting
908 // colours at each class level by overriding ShouldInheritColours()
909 if ( ShouldInheritColours() )
911 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
912 SetForegroundColour(parent
->GetForegroundColour());
914 // inheriting (solid) background colour is wrong as it totally breaks
915 // any kind of themed backgrounds
917 // instead, the controls should use the same background as their parent
918 // (ideally by not drawing it at all)
920 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
921 SetBackgroundColour(parent
->GetBackgroundColour());
926 /* static */ wxVisualAttributes
927 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
929 // it is important to return valid values for all attributes from here,
930 // GetXXX() below rely on this
931 wxVisualAttributes attrs
;
932 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
933 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
935 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
936 // the usual background colour than wxSYS_COLOUR_BTNFACE.
937 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
938 // colour on other platforms.
940 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
941 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
943 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
948 wxColour
wxWindowBase::GetBackgroundColour() const
950 if ( !m_backgroundColour
.Ok() )
952 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
954 // get our default background colour
955 wxColour colBg
= GetDefaultAttributes().colBg
;
957 // we must return some valid colour to avoid redoing this every time
958 // and also to avoid surprizing the applications written for older
959 // wxWidgets versions where GetBackgroundColour() always returned
960 // something -- so give them something even if it doesn't make sense
961 // for this window (e.g. it has a themed background)
963 colBg
= GetClassDefaultAttributes().colBg
;
968 return m_backgroundColour
;
971 wxColour
wxWindowBase::GetForegroundColour() const
973 // logic is the same as above
974 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
976 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
978 wxColour colFg
= GetDefaultAttributes().colFg
;
981 colFg
= GetClassDefaultAttributes().colFg
;
986 return m_foregroundColour
;
989 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
991 if ( colour
== m_backgroundColour
)
994 m_hasBgCol
= colour
.Ok();
995 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
996 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
998 m_inheritBgCol
= m_hasBgCol
;
999 m_backgroundColour
= colour
;
1000 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1004 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1006 if (colour
== m_foregroundColour
)
1009 m_hasFgCol
= colour
.Ok();
1010 m_inheritFgCol
= m_hasFgCol
;
1011 m_foregroundColour
= colour
;
1012 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1016 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1018 // setting an invalid cursor is ok, it means that we don't have any special
1020 if ( m_cursor
== cursor
)
1031 wxFont
wxWindowBase::GetFont() const
1033 // logic is the same as in GetBackgroundColour()
1036 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1038 wxFont font
= GetDefaultAttributes().font
;
1040 font
= GetClassDefaultAttributes().font
;
1048 bool wxWindowBase::SetFont(const wxFont
& font
)
1050 if ( font
== m_font
)
1057 m_hasFont
= font
.Ok();
1058 m_inheritFont
= m_hasFont
;
1060 InvalidateBestSize();
1067 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1069 m_hasCustomPalette
= true;
1072 // VZ: can anyone explain me what do we do here?
1073 wxWindowDC
d((wxWindow
*) this);
1077 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1079 wxWindow
*win
= (wxWindow
*)this;
1080 while ( win
&& !win
->HasCustomPalette() )
1082 win
= win
->GetParent();
1088 #endif // wxUSE_PALETTE
1091 void wxWindowBase::SetCaret(wxCaret
*caret
)
1102 wxASSERT_MSG( m_caret
->GetWindow() == this,
1103 wxT("caret should be created associated to this window") );
1106 #endif // wxUSE_CARET
1108 #if wxUSE_VALIDATORS
1109 // ----------------------------------------------------------------------------
1111 // ----------------------------------------------------------------------------
1113 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1115 if ( m_windowValidator
)
1116 delete m_windowValidator
;
1118 m_windowValidator
= (wxValidator
*)validator
.Clone();
1120 if ( m_windowValidator
)
1121 m_windowValidator
->SetWindow(this);
1123 #endif // wxUSE_VALIDATORS
1125 // ----------------------------------------------------------------------------
1126 // update region stuff
1127 // ----------------------------------------------------------------------------
1129 wxRect
wxWindowBase::GetUpdateClientRect() const
1131 wxRegion rgnUpdate
= GetUpdateRegion();
1132 rgnUpdate
.Intersect(GetClientRect());
1133 wxRect rectUpdate
= rgnUpdate
.GetBox();
1134 wxPoint ptOrigin
= GetClientAreaOrigin();
1135 rectUpdate
.x
-= ptOrigin
.x
;
1136 rectUpdate
.y
-= ptOrigin
.y
;
1141 bool wxWindowBase::IsExposed(int x
, int y
) const
1143 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1146 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1148 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1151 void wxWindowBase::ClearBackground()
1153 // wxGTK uses its own version, no need to add never used code
1155 wxClientDC
dc((wxWindow
*)this);
1156 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1157 dc
.SetBackground(brush
);
1162 // ----------------------------------------------------------------------------
1163 // find child window by id or name
1164 // ----------------------------------------------------------------------------
1166 wxWindow
*wxWindowBase::FindWindow(long id
) const
1168 if ( id
== m_windowId
)
1169 return (wxWindow
*)this;
1171 wxWindowBase
*res
= (wxWindow
*)NULL
;
1172 wxWindowList::compatibility_iterator node
;
1173 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1175 wxWindowBase
*child
= node
->GetData();
1176 res
= child
->FindWindow( id
);
1179 return (wxWindow
*)res
;
1182 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1184 if ( name
== m_windowName
)
1185 return (wxWindow
*)this;
1187 wxWindowBase
*res
= (wxWindow
*)NULL
;
1188 wxWindowList::compatibility_iterator node
;
1189 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1191 wxWindow
*child
= node
->GetData();
1192 res
= child
->FindWindow(name
);
1195 return (wxWindow
*)res
;
1199 // find any window by id or name or label: If parent is non-NULL, look through
1200 // children for a label or title matching the specified string. If NULL, look
1201 // through all top-level windows.
1203 // to avoid duplicating code we reuse the same helper function but with
1204 // different comparators
1206 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1207 const wxString
& label
, long id
);
1210 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1213 return win
->GetLabel() == label
;
1217 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1220 return win
->GetName() == label
;
1224 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1227 return win
->GetId() == id
;
1230 // recursive helper for the FindWindowByXXX() functions
1232 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1233 const wxString
& label
,
1235 wxFindWindowCmp cmp
)
1239 // see if this is the one we're looking for
1240 if ( (*cmp
)(parent
, label
, id
) )
1241 return (wxWindow
*)parent
;
1243 // It wasn't, so check all its children
1244 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1246 node
= node
->GetNext() )
1248 // recursively check each child
1249 wxWindow
*win
= (wxWindow
*)node
->GetData();
1250 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1260 // helper for FindWindowByXXX()
1262 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1263 const wxString
& label
,
1265 wxFindWindowCmp cmp
)
1269 // just check parent and all its children
1270 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1273 // start at very top of wx's windows
1274 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1276 node
= node
->GetNext() )
1278 // recursively check each window & its children
1279 wxWindow
*win
= node
->GetData();
1280 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1290 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1292 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1297 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1299 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1303 // fall back to the label
1304 win
= FindWindowByLabel(title
, parent
);
1312 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1314 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1317 // ----------------------------------------------------------------------------
1318 // dialog oriented functions
1319 // ----------------------------------------------------------------------------
1321 void wxWindowBase::MakeModal(bool modal
)
1323 // Disable all other windows
1326 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1329 wxWindow
*win
= node
->GetData();
1331 win
->Enable(!modal
);
1333 node
= node
->GetNext();
1338 bool wxWindowBase::Validate()
1340 #if wxUSE_VALIDATORS
1341 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1343 wxWindowList::compatibility_iterator node
;
1344 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1346 wxWindowBase
*child
= node
->GetData();
1347 wxValidator
*validator
= child
->GetValidator();
1348 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1353 if ( recurse
&& !child
->Validate() )
1358 #endif // wxUSE_VALIDATORS
1363 bool wxWindowBase::TransferDataToWindow()
1365 #if wxUSE_VALIDATORS
1366 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1368 wxWindowList::compatibility_iterator node
;
1369 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1371 wxWindowBase
*child
= node
->GetData();
1372 wxValidator
*validator
= child
->GetValidator();
1373 if ( validator
&& !validator
->TransferToWindow() )
1375 wxLogWarning(_("Could not transfer data to window"));
1377 wxLog::FlushActive();
1385 if ( !child
->TransferDataToWindow() )
1387 // warning already given
1392 #endif // wxUSE_VALIDATORS
1397 bool wxWindowBase::TransferDataFromWindow()
1399 #if wxUSE_VALIDATORS
1400 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1402 wxWindowList::compatibility_iterator node
;
1403 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1405 wxWindow
*child
= node
->GetData();
1406 wxValidator
*validator
= child
->GetValidator();
1407 if ( validator
&& !validator
->TransferFromWindow() )
1409 // nop warning here because the application is supposed to give
1410 // one itself - we don't know here what might have gone wrongly
1417 if ( !child
->TransferDataFromWindow() )
1419 // warning already given
1424 #endif // wxUSE_VALIDATORS
1429 void wxWindowBase::InitDialog()
1431 wxInitDialogEvent
event(GetId());
1432 event
.SetEventObject( this );
1433 GetEventHandler()->ProcessEvent(event
);
1436 // ----------------------------------------------------------------------------
1437 // context-sensitive help support
1438 // ----------------------------------------------------------------------------
1442 // associate this help text with this window
1443 void wxWindowBase::SetHelpText(const wxString
& text
)
1445 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1448 helpProvider
->AddHelp(this, text
);
1452 // associate this help text with all windows with the same id as this
1454 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1456 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1459 helpProvider
->AddHelp(GetId(), text
);
1463 // get the help string associated with this window (may be empty)
1464 // default implementation forwards calls to the help provider
1466 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1467 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1470 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1473 text
= helpProvider
->GetHelp(this);
1479 // show help for this window
1480 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1482 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1485 if ( helpProvider
->ShowHelpAtPoint(this, event
.GetPosition(), event
.GetOrigin()) )
1487 // skip the event.Skip() below
1495 #endif // wxUSE_HELP
1497 // ----------------------------------------------------------------------------
1498 // tooltipsroot.Replace("\\", "/");
1499 // ----------------------------------------------------------------------------
1503 void wxWindowBase::SetToolTip( const wxString
&tip
)
1505 // don't create the new tooltip if we already have one
1508 m_tooltip
->SetTip( tip
);
1512 SetToolTip( new wxToolTip( tip
) );
1515 // setting empty tooltip text does not remove the tooltip any more - use
1516 // SetToolTip((wxToolTip *)NULL) for this
1519 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1521 if ( m_tooltip
!= tooltip
)
1526 m_tooltip
= tooltip
;
1530 #endif // wxUSE_TOOLTIPS
1532 // ----------------------------------------------------------------------------
1533 // constraints and sizers
1534 // ----------------------------------------------------------------------------
1536 #if wxUSE_CONSTRAINTS
1538 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1540 if ( m_constraints
)
1542 UnsetConstraints(m_constraints
);
1543 delete m_constraints
;
1545 m_constraints
= constraints
;
1546 if ( m_constraints
)
1548 // Make sure other windows know they're part of a 'meaningful relationship'
1549 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1550 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1551 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1552 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1553 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1554 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1555 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1556 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1557 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1558 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1559 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1560 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1561 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1562 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1563 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1564 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1568 // This removes any dangling pointers to this window in other windows'
1569 // constraintsInvolvedIn lists.
1570 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1574 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1575 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1576 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1577 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1578 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1579 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1580 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1581 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1582 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1583 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1584 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1585 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1586 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1587 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1588 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1589 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1593 // Back-pointer to other windows we're involved with, so if we delete this
1594 // window, we must delete any constraints we're involved with.
1595 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1597 if ( !m_constraintsInvolvedIn
)
1598 m_constraintsInvolvedIn
= new wxWindowList
;
1599 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1600 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1603 // REMOVE back-pointer to other windows we're involved with.
1604 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1606 if ( m_constraintsInvolvedIn
)
1607 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1610 // Reset any constraints that mention this window
1611 void wxWindowBase::DeleteRelatedConstraints()
1613 if ( m_constraintsInvolvedIn
)
1615 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1618 wxWindow
*win
= node
->GetData();
1619 wxLayoutConstraints
*constr
= win
->GetConstraints();
1621 // Reset any constraints involving this window
1624 constr
->left
.ResetIfWin(this);
1625 constr
->top
.ResetIfWin(this);
1626 constr
->right
.ResetIfWin(this);
1627 constr
->bottom
.ResetIfWin(this);
1628 constr
->width
.ResetIfWin(this);
1629 constr
->height
.ResetIfWin(this);
1630 constr
->centreX
.ResetIfWin(this);
1631 constr
->centreY
.ResetIfWin(this);
1634 wxWindowList::compatibility_iterator next
= node
->GetNext();
1635 m_constraintsInvolvedIn
->Erase(node
);
1639 delete m_constraintsInvolvedIn
;
1640 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1644 #endif // wxUSE_CONSTRAINTS
1646 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1648 if ( sizer
== m_windowSizer
)
1652 delete m_windowSizer
;
1654 m_windowSizer
= sizer
;
1656 SetAutoLayout( sizer
!= NULL
);
1659 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1661 SetSizer( sizer
, deleteOld
);
1662 sizer
->SetSizeHints( (wxWindow
*) this );
1666 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1668 // adding a window to a sizer twice is going to result in fatal and
1669 // hard to debug problems later because when deleting the second
1670 // associated wxSizerItem we're going to dereference a dangling
1671 // pointer; so try to detect this as early as possible
1672 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1673 _T("Adding a window to the same sizer twice?") );
1675 m_containingSizer
= sizer
;
1678 #if wxUSE_CONSTRAINTS
1680 void wxWindowBase::SatisfyConstraints()
1682 wxLayoutConstraints
*constr
= GetConstraints();
1683 bool wasOk
= constr
&& constr
->AreSatisfied();
1685 ResetConstraints(); // Mark all constraints as unevaluated
1689 // if we're a top level panel (i.e. our parent is frame/dialog), our
1690 // own constraints will never be satisfied any more unless we do it
1694 while ( noChanges
> 0 )
1696 LayoutPhase1(&noChanges
);
1700 LayoutPhase2(&noChanges
);
1703 #endif // wxUSE_CONSTRAINTS
1705 bool wxWindowBase::Layout()
1707 // If there is a sizer, use it instead of the constraints
1711 GetVirtualSize(&w
, &h
);
1712 GetSizer()->SetDimension( 0, 0, w
, h
);
1714 #if wxUSE_CONSTRAINTS
1717 SatisfyConstraints(); // Find the right constraints values
1718 SetConstraintSizes(); // Recursively set the real window sizes
1725 #if wxUSE_CONSTRAINTS
1727 // first phase of the constraints evaluation: set our own constraints
1728 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1730 wxLayoutConstraints
*constr
= GetConstraints();
1732 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1735 // second phase: set the constraints for our children
1736 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1743 // Layout grand children
1749 // Do a phase of evaluating child constraints
1750 bool wxWindowBase::DoPhase(int phase
)
1752 // the list containing the children for which the constraints are already
1754 wxWindowList succeeded
;
1756 // the max number of iterations we loop before concluding that we can't set
1758 static const int maxIterations
= 500;
1760 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1764 // loop over all children setting their constraints
1765 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1767 node
= node
->GetNext() )
1769 wxWindow
*child
= node
->GetData();
1770 if ( child
->IsTopLevel() )
1772 // top level children are not inside our client area
1776 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1778 // this one is either already ok or nothing we can do about it
1782 int tempNoChanges
= 0;
1783 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1784 : child
->LayoutPhase2(&tempNoChanges
);
1785 noChanges
+= tempNoChanges
;
1789 succeeded
.Append(child
);
1795 // constraints are set
1803 void wxWindowBase::ResetConstraints()
1805 wxLayoutConstraints
*constr
= GetConstraints();
1808 constr
->left
.SetDone(false);
1809 constr
->top
.SetDone(false);
1810 constr
->right
.SetDone(false);
1811 constr
->bottom
.SetDone(false);
1812 constr
->width
.SetDone(false);
1813 constr
->height
.SetDone(false);
1814 constr
->centreX
.SetDone(false);
1815 constr
->centreY
.SetDone(false);
1818 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1821 wxWindow
*win
= node
->GetData();
1822 if ( !win
->IsTopLevel() )
1823 win
->ResetConstraints();
1824 node
= node
->GetNext();
1828 // Need to distinguish between setting the 'fake' size for windows and sizers,
1829 // and setting the real values.
1830 void wxWindowBase::SetConstraintSizes(bool recurse
)
1832 wxLayoutConstraints
*constr
= GetConstraints();
1833 if ( constr
&& constr
->AreSatisfied() )
1835 int x
= constr
->left
.GetValue();
1836 int y
= constr
->top
.GetValue();
1837 int w
= constr
->width
.GetValue();
1838 int h
= constr
->height
.GetValue();
1840 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1841 (constr
->height
.GetRelationship() != wxAsIs
) )
1843 SetSize(x
, y
, w
, h
);
1847 // If we don't want to resize this window, just move it...
1853 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1854 GetClassInfo()->GetClassName(),
1860 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1863 wxWindow
*win
= node
->GetData();
1864 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1865 win
->SetConstraintSizes();
1866 node
= node
->GetNext();
1871 // Only set the size/position of the constraint (if any)
1872 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1874 wxLayoutConstraints
*constr
= GetConstraints();
1877 if ( x
!= wxDefaultCoord
)
1879 constr
->left
.SetValue(x
);
1880 constr
->left
.SetDone(true);
1882 if ( y
!= wxDefaultCoord
)
1884 constr
->top
.SetValue(y
);
1885 constr
->top
.SetDone(true);
1887 if ( w
!= wxDefaultCoord
)
1889 constr
->width
.SetValue(w
);
1890 constr
->width
.SetDone(true);
1892 if ( h
!= wxDefaultCoord
)
1894 constr
->height
.SetValue(h
);
1895 constr
->height
.SetDone(true);
1900 void wxWindowBase::MoveConstraint(int x
, int y
)
1902 wxLayoutConstraints
*constr
= GetConstraints();
1905 if ( x
!= wxDefaultCoord
)
1907 constr
->left
.SetValue(x
);
1908 constr
->left
.SetDone(true);
1910 if ( y
!= wxDefaultCoord
)
1912 constr
->top
.SetValue(y
);
1913 constr
->top
.SetDone(true);
1918 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1920 wxLayoutConstraints
*constr
= GetConstraints();
1923 *w
= constr
->width
.GetValue();
1924 *h
= constr
->height
.GetValue();
1930 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1932 wxLayoutConstraints
*constr
= GetConstraints();
1935 *w
= constr
->width
.GetValue();
1936 *h
= constr
->height
.GetValue();
1939 GetClientSize(w
, h
);
1942 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1944 wxLayoutConstraints
*constr
= GetConstraints();
1947 *x
= constr
->left
.GetValue();
1948 *y
= constr
->top
.GetValue();
1954 #endif // wxUSE_CONSTRAINTS
1956 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1958 // don't do it for the dialogs/frames - they float independently of their
1960 if ( !IsTopLevel() )
1962 wxWindow
*parent
= GetParent();
1963 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1965 wxPoint
pt(parent
->GetClientAreaOrigin());
1972 // ----------------------------------------------------------------------------
1973 // do Update UI processing for child controls
1974 // ----------------------------------------------------------------------------
1976 void wxWindowBase::UpdateWindowUI(long flags
)
1978 wxUpdateUIEvent
event(GetId());
1979 event
.SetEventObject(this);
1981 if ( GetEventHandler()->ProcessEvent(event
) )
1983 DoUpdateWindowUI(event
);
1986 if (flags
& wxUPDATE_UI_RECURSE
)
1988 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1991 wxWindow
* child
= (wxWindow
*) node
->GetData();
1992 child
->UpdateWindowUI(flags
);
1993 node
= node
->GetNext();
1998 // do the window-specific processing after processing the update event
1999 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2001 if ( event
.GetSetEnabled() )
2002 Enable(event
.GetEnabled());
2004 if ( event
.GetSetShown() )
2005 Show(event
.GetShown());
2009 // call internal idle recursively
2010 // may be obsolete (wait until OnIdle scheme stabilises)
2011 void wxWindowBase::ProcessInternalIdle()
2015 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2018 wxWindow
*child
= node
->GetData();
2019 child
->ProcessInternalIdle();
2020 node
= node
->GetNext();
2025 // ----------------------------------------------------------------------------
2026 // dialog units translations
2027 // ----------------------------------------------------------------------------
2029 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2031 int charWidth
= GetCharWidth();
2032 int charHeight
= GetCharHeight();
2033 wxPoint pt2
= wxDefaultPosition
;
2034 if (pt
.x
!= wxDefaultCoord
)
2035 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2036 if (pt
.y
!= wxDefaultCoord
)
2037 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2042 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2044 int charWidth
= GetCharWidth();
2045 int charHeight
= GetCharHeight();
2046 wxPoint pt2
= wxDefaultPosition
;
2047 if (pt
.x
!= wxDefaultCoord
)
2048 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2049 if (pt
.y
!= wxDefaultCoord
)
2050 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2055 // ----------------------------------------------------------------------------
2057 // ----------------------------------------------------------------------------
2059 // propagate the colour change event to the subwindows
2060 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2062 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2065 // Only propagate to non-top-level windows
2066 wxWindow
*win
= node
->GetData();
2067 if ( !win
->IsTopLevel() )
2069 wxSysColourChangedEvent event2
;
2070 event
.SetEventObject(win
);
2071 win
->GetEventHandler()->ProcessEvent(event2
);
2074 node
= node
->GetNext();
2080 // the default action is to populate dialog with data when it's created,
2081 // and nudge the UI into displaying itself correctly in case
2082 // we've turned the wxUpdateUIEvents frequency down low.
2083 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2085 TransferDataToWindow();
2087 // Update the UI at this point
2088 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2091 // methods for drawing the sizers in a visible way
2094 static void DrawSizers(wxWindowBase
*win
);
2096 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2098 wxClientDC
dc((wxWindow
*)win
);
2099 dc
.SetPen(*wxRED_PEN
);
2100 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2101 dc
.DrawRectangle(rect
.Deflate(1, 1));
2104 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2106 const wxSizerItemList
& items
= sizer
->GetChildren();
2107 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2112 wxSizerItem
*item
= *i
;
2113 if ( item
->IsSizer() )
2115 DrawBorder(win
, item
->GetRect().Deflate(2));
2116 DrawSizer(win
, item
->GetSizer());
2118 else if ( item
->IsSpacer() )
2120 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2122 else if ( item
->IsWindow() )
2124 DrawSizers(item
->GetWindow());
2129 static void DrawSizers(wxWindowBase
*win
)
2131 wxSizer
*sizer
= win
->GetSizer();
2134 DrawBorder(win
, win
->GetClientSize());
2135 DrawSizer(win
, sizer
);
2137 else // no sizer, still recurse into the children
2139 const wxWindowList
& children
= win
->GetChildren();
2140 for ( wxWindowList::const_iterator i
= children
.begin(),
2141 end
= children
.end();
2150 #endif // __WXDEBUG__
2152 // process special middle clicks
2153 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2155 if ( event
.ControlDown() && event
.AltDown() )
2158 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2159 if ( event
.ShiftDown() )
2164 #endif // __WXDEBUG__
2167 // don't translate these strings
2170 #ifdef __WXUNIVERSAL__
2172 #endif // __WXUNIVERSAL__
2174 switch ( wxGetOsVersion() )
2176 case wxMOTIF_X
: port
+= _T("Motif"); break;
2178 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
2179 case wxBEOS
: port
+= _T("BeOS"); break;
2183 case wxGTK_BEOS
: port
+= _T("GTK"); break;
2189 case wxWIN386
: port
+= _T("MS Windows"); break;
2193 case wxMGL_OS2
: port
+= _T("MGL"); break;
2195 case wxOS2_PM
: port
+= _T("OS/2"); break;
2196 case wxPALMOS
: port
+= _T("Palm OS"); break;
2197 case wxWINDOWS_CE
: port
+= _T("Windows CE (generic)"); break;
2198 case wxWINDOWS_POCKETPC
: port
+= _T("Windows CE PocketPC"); break;
2199 case wxWINDOWS_SMARTPHONE
: port
+= _T("Windows CE Smartphone"); break;
2200 default: port
+= _T("unknown"); break;
2203 wxMessageBox(wxString::Format(
2205 " wxWidgets Library (%s port)\nVersion %d.%d.%d%s%s, compiled at %s %s%s\n Copyright (c) 1995-2006 wxWidgets team"
2224 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()
2229 _T("wxWidgets information"),
2230 wxICON_INFORMATION
| wxOK
,
2234 #endif // wxUSE_MSGDLG
2240 // ----------------------------------------------------------------------------
2242 // ----------------------------------------------------------------------------
2244 #if wxUSE_ACCESSIBILITY
2245 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2247 if (m_accessible
&& (accessible
!= m_accessible
))
2248 delete m_accessible
;
2249 m_accessible
= accessible
;
2251 m_accessible
->SetWindow((wxWindow
*) this);
2254 // Returns the accessible object, creating if necessary.
2255 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2258 m_accessible
= CreateAccessible();
2259 return m_accessible
;
2262 // Override to create a specific accessible object.
2263 wxAccessible
* wxWindowBase::CreateAccessible()
2265 return new wxWindowAccessible((wxWindow
*) this);
2270 // ----------------------------------------------------------------------------
2271 // list classes implementation
2272 // ----------------------------------------------------------------------------
2276 #include "wx/listimpl.cpp"
2277 WX_DEFINE_LIST(wxWindowList
)
2281 void wxWindowListNode::DeleteData()
2283 delete (wxWindow
*)GetData();
2288 // ----------------------------------------------------------------------------
2290 // ----------------------------------------------------------------------------
2292 wxBorder
wxWindowBase::GetBorder(long flags
) const
2294 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2295 if ( border
== wxBORDER_DEFAULT
)
2297 border
= GetDefaultBorder();
2303 wxBorder
wxWindowBase::GetDefaultBorder() const
2305 return wxBORDER_NONE
;
2308 // ----------------------------------------------------------------------------
2310 // ----------------------------------------------------------------------------
2312 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2314 // here we just check if the point is inside the window or not
2316 // check the top and left border first
2317 bool outside
= x
< 0 || y
< 0;
2320 // check the right and bottom borders too
2321 wxSize size
= GetSize();
2322 outside
= x
>= size
.x
|| y
>= size
.y
;
2325 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2328 // ----------------------------------------------------------------------------
2330 // ----------------------------------------------------------------------------
2332 struct WXDLLEXPORT wxWindowNext
2336 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2337 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2338 bool wxWindowBase::ms_winCaptureChanging
= false;
2340 void wxWindowBase::CaptureMouse()
2342 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2344 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2346 ms_winCaptureChanging
= true;
2348 wxWindow
*winOld
= GetCapture();
2351 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2354 wxWindowNext
*item
= new wxWindowNext
;
2356 item
->next
= ms_winCaptureNext
;
2357 ms_winCaptureNext
= item
;
2359 //else: no mouse capture to save
2362 ms_winCaptureCurrent
= (wxWindow
*)this;
2364 ms_winCaptureChanging
= false;
2367 void wxWindowBase::ReleaseMouse()
2369 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2371 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2373 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2375 ms_winCaptureChanging
= true;
2378 ms_winCaptureCurrent
= NULL
;
2380 if ( ms_winCaptureNext
)
2382 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2383 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2385 wxWindowNext
*item
= ms_winCaptureNext
;
2386 ms_winCaptureNext
= item
->next
;
2389 //else: stack is empty, no previous capture
2391 ms_winCaptureChanging
= false;
2393 wxLogTrace(_T("mousecapture"),
2394 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2395 wx_static_cast(void*, GetCapture()));
2398 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2400 wxMouseCaptureLostEvent
event(win
->GetId());
2401 event
.SetEventObject(win
);
2402 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2404 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2409 void wxWindowBase::NotifyCaptureLost()
2411 // don't do anything if capture lost was expected, i.e. resulted from
2412 // a wx call to ReleaseMouse or CaptureMouse:
2413 if ( ms_winCaptureChanging
)
2416 // if the capture was lost unexpectedly, notify every window that has
2417 // capture (on stack or current) about it and clear the stack:
2419 if ( ms_winCaptureCurrent
)
2421 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2422 ms_winCaptureCurrent
= NULL
;
2425 while ( ms_winCaptureNext
)
2427 wxWindowNext
*item
= ms_winCaptureNext
;
2428 ms_winCaptureNext
= item
->next
;
2430 DoNotifyWindowAboutCaptureLost(item
->win
);
2439 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2440 int WXUNUSED(modifiers
),
2441 int WXUNUSED(keycode
))
2447 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2453 #endif // wxUSE_HOTKEY
2455 void wxWindowBase::SendDestroyEvent()
2457 wxWindowDestroyEvent event
;
2458 event
.SetEventObject(this);
2459 event
.SetId(GetId());
2460 GetEventHandler()->ProcessEvent(event
);
2463 // ----------------------------------------------------------------------------
2465 // ----------------------------------------------------------------------------
2467 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2469 #if wxUSE_VALIDATORS
2470 // Can only use the validator of the window which
2471 // is receiving the event
2472 if ( event
.GetEventObject() == this )
2474 wxValidator
*validator
= GetValidator();
2475 if ( validator
&& validator
->ProcessEvent(event
) )
2480 #endif // wxUSE_VALIDATORS
2485 bool wxWindowBase::TryParent(wxEvent
& event
)
2487 // carry on up the parent-child hierarchy if the propagation count hasn't
2489 if ( event
.ShouldPropagate() )
2491 // honour the requests to stop propagation at this window: this is
2492 // used by the dialogs, for example, to prevent processing the events
2493 // from the dialog controls in the parent frame which rarely, if ever,
2495 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2497 wxWindow
*parent
= GetParent();
2498 if ( parent
&& !parent
->IsBeingDeleted() )
2500 wxPropagateOnce
propagateOnce(event
);
2502 return parent
->GetEventHandler()->ProcessEvent(event
);
2507 return wxEvtHandler::TryParent(event
);
2510 // ----------------------------------------------------------------------------
2511 // keyboard navigation
2512 // ----------------------------------------------------------------------------
2514 // Navigates in the specified direction.
2515 bool wxWindowBase::Navigate(int flags
)
2517 wxNavigationKeyEvent eventNav
;
2518 eventNav
.SetFlags(flags
);
2519 eventNav
.SetEventObject(this);
2520 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2527 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2529 // check that we're not a top level window
2530 wxCHECK_RET( GetParent(),
2531 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2533 // detect the special case when we have nothing to do anyhow and when the
2534 // code below wouldn't work
2538 // find the target window in the siblings list
2539 wxWindowList
& siblings
= GetParent()->GetChildren();
2540 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2541 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2543 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2544 // can't just move the node around
2545 wxWindow
*self
= (wxWindow
*)this;
2546 siblings
.DeleteObject(self
);
2547 if ( move
== MoveAfter
)
2554 siblings
.Insert(i
, self
);
2556 else // MoveAfter and win was the last sibling
2558 siblings
.Append(self
);
2562 // ----------------------------------------------------------------------------
2564 // ----------------------------------------------------------------------------
2566 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2568 wxWindowBase
*win
= DoFindFocus();
2569 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2572 // ----------------------------------------------------------------------------
2574 // ----------------------------------------------------------------------------
2576 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2578 while ( win
&& !win
->IsTopLevel() )
2579 win
= win
->GetParent();
2584 #if wxUSE_ACCESSIBILITY
2585 // ----------------------------------------------------------------------------
2586 // accessible object for windows
2587 // ----------------------------------------------------------------------------
2589 // Can return either a child object, or an integer
2590 // representing the child element, starting from 1.
2591 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2593 wxASSERT( GetWindow() != NULL
);
2597 return wxACC_NOT_IMPLEMENTED
;
2600 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2601 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2603 wxASSERT( GetWindow() != NULL
);
2607 wxWindow
* win
= NULL
;
2614 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2616 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2623 rect
= win
->GetRect();
2624 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2625 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2629 return wxACC_NOT_IMPLEMENTED
;
2632 // Navigates from fromId to toId/toObject.
2633 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2634 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2636 wxASSERT( GetWindow() != NULL
);
2642 case wxNAVDIR_FIRSTCHILD
:
2644 if (GetWindow()->GetChildren().GetCount() == 0)
2646 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2647 *toObject
= childWindow
->GetOrCreateAccessible();
2651 case wxNAVDIR_LASTCHILD
:
2653 if (GetWindow()->GetChildren().GetCount() == 0)
2655 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2656 *toObject
= childWindow
->GetOrCreateAccessible();
2660 case wxNAVDIR_RIGHT
:
2664 wxWindowList::compatibility_iterator node
=
2665 wxWindowList::compatibility_iterator();
2668 // Can't navigate to sibling of this window
2669 // if we're a top-level window.
2670 if (!GetWindow()->GetParent())
2671 return wxACC_NOT_IMPLEMENTED
;
2673 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2677 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2678 node
= GetWindow()->GetChildren().Item(fromId
-1);
2681 if (node
&& node
->GetNext())
2683 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2684 *toObject
= nextWindow
->GetOrCreateAccessible();
2692 case wxNAVDIR_PREVIOUS
:
2694 wxWindowList::compatibility_iterator node
=
2695 wxWindowList::compatibility_iterator();
2698 // Can't navigate to sibling of this window
2699 // if we're a top-level window.
2700 if (!GetWindow()->GetParent())
2701 return wxACC_NOT_IMPLEMENTED
;
2703 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2707 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2708 node
= GetWindow()->GetChildren().Item(fromId
-1);
2711 if (node
&& node
->GetPrevious())
2713 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2714 *toObject
= previousWindow
->GetOrCreateAccessible();
2722 return wxACC_NOT_IMPLEMENTED
;
2725 // Gets the name of the specified object.
2726 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2728 wxASSERT( GetWindow() != NULL
);
2734 // If a child, leave wxWidgets to call the function on the actual
2737 return wxACC_NOT_IMPLEMENTED
;
2739 // This will eventually be replaced by specialised
2740 // accessible classes, one for each kind of wxWidgets
2741 // control or window.
2743 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2744 title
= ((wxButton
*) GetWindow())->GetLabel();
2747 title
= GetWindow()->GetName();
2755 return wxACC_NOT_IMPLEMENTED
;
2758 // Gets the number of children.
2759 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2761 wxASSERT( GetWindow() != NULL
);
2765 *childId
= (int) GetWindow()->GetChildren().GetCount();
2769 // Gets the specified child (starting from 1).
2770 // If *child is NULL and return value is wxACC_OK,
2771 // this means that the child is a simple element and
2772 // not an accessible object.
2773 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2775 wxASSERT( GetWindow() != NULL
);
2785 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2788 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2789 *child
= childWindow
->GetOrCreateAccessible();
2796 // Gets the parent, or NULL.
2797 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2799 wxASSERT( GetWindow() != NULL
);
2803 wxWindow
* parentWindow
= GetWindow()->GetParent();
2811 *parent
= parentWindow
->GetOrCreateAccessible();
2819 // Performs the default action. childId is 0 (the action for this object)
2820 // or > 0 (the action for a child).
2821 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2822 // window (e.g. an edit control).
2823 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2825 wxASSERT( GetWindow() != NULL
);
2829 return wxACC_NOT_IMPLEMENTED
;
2832 // Gets the default action for this object (0) or > 0 (the action for a child).
2833 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2834 // string if there is no action.
2835 // The retrieved string describes the action that is performed on an object,
2836 // not what the object does as a result. For example, a toolbar button that prints
2837 // a document has a default action of "Press" rather than "Prints the current document."
2838 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2840 wxASSERT( GetWindow() != NULL
);
2844 return wxACC_NOT_IMPLEMENTED
;
2847 // Returns the description for this object or a child.
2848 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2850 wxASSERT( GetWindow() != NULL
);
2854 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2860 return wxACC_NOT_IMPLEMENTED
;
2863 // Returns help text for this object or a child, similar to tooltip text.
2864 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2866 wxASSERT( GetWindow() != NULL
);
2870 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2876 return wxACC_NOT_IMPLEMENTED
;
2879 // Returns the keyboard shortcut for this object or child.
2880 // Return e.g. ALT+K
2881 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2883 wxASSERT( GetWindow() != NULL
);
2887 return wxACC_NOT_IMPLEMENTED
;
2890 // Returns a role constant.
2891 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2893 wxASSERT( GetWindow() != NULL
);
2897 // If a child, leave wxWidgets to call the function on the actual
2900 return wxACC_NOT_IMPLEMENTED
;
2902 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2903 return wxACC_NOT_IMPLEMENTED
;
2905 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2906 return wxACC_NOT_IMPLEMENTED
;
2909 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2910 return wxACC_NOT_IMPLEMENTED
;
2913 //*role = wxROLE_SYSTEM_CLIENT;
2914 *role
= wxROLE_SYSTEM_CLIENT
;
2918 return wxACC_NOT_IMPLEMENTED
;
2922 // Returns a state constant.
2923 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2925 wxASSERT( GetWindow() != NULL
);
2929 // If a child, leave wxWidgets to call the function on the actual
2932 return wxACC_NOT_IMPLEMENTED
;
2934 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2935 return wxACC_NOT_IMPLEMENTED
;
2938 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2939 return wxACC_NOT_IMPLEMENTED
;
2942 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2943 return wxACC_NOT_IMPLEMENTED
;
2950 return wxACC_NOT_IMPLEMENTED
;
2954 // Returns a localized string representing the value for the object
2956 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2958 wxASSERT( GetWindow() != NULL
);
2962 return wxACC_NOT_IMPLEMENTED
;
2965 // Selects the object or child.
2966 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2968 wxASSERT( GetWindow() != NULL
);
2972 return wxACC_NOT_IMPLEMENTED
;
2975 // Gets the window with the keyboard focus.
2976 // If childId is 0 and child is NULL, no object in
2977 // this subhierarchy has the focus.
2978 // If this object has the focus, child should be 'this'.
2979 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2981 wxASSERT( GetWindow() != NULL
);
2985 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
;
3005 #endif // wxUSE_ACCESSIBILITY