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"
46 #if defined(__WXMAC__) && wxUSE_SCROLLBAR
47 #include "wx/scrolbar.h"
51 #include "wx/layout.h"
52 #endif // wxUSE_CONSTRAINTS
56 #if wxUSE_DRAG_AND_DROP
58 #endif // wxUSE_DRAG_AND_DROP
60 #if wxUSE_ACCESSIBILITY
61 #include "wx/access.h"
65 #include "wx/cshelp.h"
69 #include "wx/tooltip.h"
70 #endif // wxUSE_TOOLTIPS
76 #if wxUSE_SYSTEM_OPTIONS
77 #include "wx/sysopt.h"
80 // For reporting compile- and runtime version of GTK+ in the ctrl+alt+mclick dialog.
81 // The gtk includes don't pull any other headers in, at least not on my system - MR
84 #include <gtk/gtkversion.h>
86 #include <gtk/gtkfeatures.h>
88 extern const unsigned int gtk_major_version
;
89 extern const unsigned int gtk_minor_version
;
90 extern const unsigned int gtk_micro_version
;
94 WXDLLIMPEXP_DATA_CORE(wxWindowList
) wxTopLevelWindows
;
96 // ----------------------------------------------------------------------------
98 // ----------------------------------------------------------------------------
100 #if defined(__WXPALMOS__)
101 int wxWindowBase::ms_lastControlId
= 32767;
102 #elif defined(__WXPM__)
103 int wxWindowBase::ms_lastControlId
= 2000;
105 int wxWindowBase::ms_lastControlId
= -200;
108 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
110 // ----------------------------------------------------------------------------
112 // ----------------------------------------------------------------------------
114 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
115 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
116 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
117 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
120 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
125 // ============================================================================
126 // implementation of the common functionality of the wxWindow class
127 // ============================================================================
129 // ----------------------------------------------------------------------------
131 // ----------------------------------------------------------------------------
133 // the default initialization
134 wxWindowBase::wxWindowBase()
136 // no window yet, no parent nor children
137 m_parent
= (wxWindow
*)NULL
;
138 m_windowId
= wxID_ANY
;
140 // no constraints on the minimal window size
142 m_maxWidth
= wxDefaultCoord
;
144 m_maxHeight
= wxDefaultCoord
;
146 // invalidiated cache value
147 m_bestSizeCache
= wxDefaultSize
;
149 // window are created enabled and visible by default
153 // the default event handler is just this window
154 m_eventHandler
= this;
158 m_windowValidator
= (wxValidator
*) NULL
;
159 #endif // wxUSE_VALIDATORS
161 // the colours/fonts are default for now, so leave m_font,
162 // m_backgroundColour and m_foregroundColour uninitialized and set those
168 m_inheritFont
= false;
174 m_backgroundStyle
= wxBG_STYLE_SYSTEM
;
176 #if wxUSE_CONSTRAINTS
177 // no constraints whatsoever
178 m_constraints
= (wxLayoutConstraints
*) NULL
;
179 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
180 #endif // wxUSE_CONSTRAINTS
182 m_windowSizer
= (wxSizer
*) NULL
;
183 m_containingSizer
= (wxSizer
*) NULL
;
184 m_autoLayout
= false;
186 #if wxUSE_DRAG_AND_DROP
187 m_dropTarget
= (wxDropTarget
*)NULL
;
188 #endif // wxUSE_DRAG_AND_DROP
191 m_tooltip
= (wxToolTip
*)NULL
;
192 #endif // wxUSE_TOOLTIPS
195 m_caret
= (wxCaret
*)NULL
;
196 #endif // wxUSE_CARET
199 m_hasCustomPalette
= false;
200 #endif // wxUSE_PALETTE
202 #if wxUSE_ACCESSIBILITY
206 m_virtualSize
= wxDefaultSize
;
209 m_maxVirtualWidth
= wxDefaultCoord
;
211 m_maxVirtualHeight
= wxDefaultCoord
;
213 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
214 #if wxUSE_SYSTEM_OPTIONS
215 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
217 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
221 // Whether we're using the current theme for this window (wxGTK only for now)
222 m_themeEnabled
= false;
224 // VZ: this one shouldn't exist...
225 m_isBeingDeleted
= false;
228 // common part of window creation process
229 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
231 const wxPoint
& WXUNUSED(pos
),
232 const wxSize
& WXUNUSED(size
),
234 const wxValidator
& wxVALIDATOR_PARAM(validator
),
235 const wxString
& name
)
238 // wxGTK doesn't allow to create controls with static box as the parent so
239 // this will result in a crash when the program is ported to wxGTK so warn
242 // if you get this assert, the correct solution is to create the controls
243 // as siblings of the static box
244 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
245 _T("wxStaticBox can't be used as a window parent!") );
246 #endif // wxUSE_STATBOX
248 // ids are limited to 16 bits under MSW so if you care about portability,
249 // it's not a good idea to use ids out of this range (and negative ids are
250 // reserved for wxWidgets own usage)
251 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
252 _T("invalid id value") );
254 // generate a new id if the user doesn't care about it
255 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
258 SetWindowStyleFlag(style
);
262 SetValidator(validator
);
263 #endif // wxUSE_VALIDATORS
265 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
266 // have it too - like this it's possible to set it only in the top level
267 // dialog/frame and all children will inherit it by defult
268 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
270 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
276 // ----------------------------------------------------------------------------
278 // ----------------------------------------------------------------------------
281 wxWindowBase::~wxWindowBase()
283 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
285 // FIXME if these 2 cases result from programming errors in the user code
286 // we should probably assert here instead of silently fixing them
288 // Just in case the window has been Closed, but we're then deleting
289 // immediately: don't leave dangling pointers.
290 wxPendingDelete
.DeleteObject(this);
292 // Just in case we've loaded a top-level window via LoadNativeDialog but
293 // we weren't a dialog class
294 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
296 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
298 // reset the dangling pointer our parent window may keep to us
301 if ( m_parent
->GetDefaultItem() == this )
303 m_parent
->SetDefaultItem(NULL
);
306 m_parent
->RemoveChild(this);
311 #endif // wxUSE_CARET
314 delete m_windowValidator
;
315 #endif // wxUSE_VALIDATORS
317 #if wxUSE_CONSTRAINTS
318 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
319 // at deleted windows as they delete themselves.
320 DeleteRelatedConstraints();
324 // This removes any dangling pointers to this window in other windows'
325 // constraintsInvolvedIn lists.
326 UnsetConstraints(m_constraints
);
327 delete m_constraints
;
328 m_constraints
= NULL
;
330 #endif // wxUSE_CONSTRAINTS
332 if ( m_containingSizer
)
333 m_containingSizer
->Detach( (wxWindow
*)this );
335 delete m_windowSizer
;
337 #if wxUSE_DRAG_AND_DROP
339 #endif // wxUSE_DRAG_AND_DROP
343 #endif // wxUSE_TOOLTIPS
345 #if wxUSE_ACCESSIBILITY
350 bool wxWindowBase::Destroy()
357 bool wxWindowBase::Close(bool force
)
359 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
360 event
.SetEventObject(this);
361 event
.SetCanVeto(!force
);
363 // return false if window wasn't closed because the application vetoed the
365 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
368 bool wxWindowBase::DestroyChildren()
370 wxWindowList::compatibility_iterator node
;
373 // we iterate until the list becomes empty
374 node
= GetChildren().GetFirst();
378 wxWindow
*child
= node
->GetData();
380 // note that we really want to call delete and not ->Destroy() here
381 // because we want to delete the child immediately, before we are
382 // deleted, and delayed deletion would result in problems as our (top
383 // level) child could outlive its parent
386 wxASSERT_MSG( !GetChildren().Find(child
),
387 wxT("child didn't remove itself using RemoveChild()") );
393 // ----------------------------------------------------------------------------
394 // size/position related methods
395 // ----------------------------------------------------------------------------
397 // centre the window with respect to its parent in either (or both) directions
398 void wxWindowBase::DoCentre(int dir
)
400 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
401 _T("this method only implements centering child windows") );
403 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
406 // fits the window around the children
407 void wxWindowBase::Fit()
409 if ( !GetChildren().empty() )
411 SetClientSize(GetBestSize());
413 //else: do nothing if we have no children
416 // fits virtual size (ie. scrolled area etc.) around children
417 void wxWindowBase::FitInside()
419 if ( GetChildren().GetCount() > 0 )
421 SetVirtualSize( GetBestVirtualSize() );
425 // On Mac, scrollbars are explicitly children.
427 static bool wxHasRealChildren(const wxWindowBase
* win
)
429 int realChildCount
= 0;
431 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
433 node
= node
->GetNext() )
435 wxWindow
*win
= node
->GetData();
436 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
439 return (realChildCount
> 0);
443 void wxWindowBase::InvalidateBestSize()
445 m_bestSizeCache
= wxDefaultSize
;
447 // parent's best size calculation may depend on its children's
448 // as long as child window we are in is not top level window itself
449 // (because the TLW size is never resized automatically)
450 // so let's invalidate it as well to be safe:
451 if (m_parent
&& !IsTopLevel())
452 m_parent
->InvalidateBestSize();
455 // return the size best suited for the current window
456 wxSize
wxWindowBase::DoGetBestSize() const
462 best
= GetWindowSizeForVirtualSize(m_windowSizer
->GetMinSize());
464 #if wxUSE_CONSTRAINTS
465 else if ( m_constraints
)
467 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
469 // our minimal acceptable size is such that all our windows fit inside
473 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
475 node
= node
->GetNext() )
477 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
480 // it's not normal that we have an unconstrained child, but
481 // what can we do about it?
485 int x
= c
->right
.GetValue(),
486 y
= c
->bottom
.GetValue();
494 // TODO: we must calculate the overlaps somehow, otherwise we
495 // will never return a size bigger than the current one :-(
498 best
= wxSize(maxX
, maxY
);
500 #endif // wxUSE_CONSTRAINTS
501 else if ( !GetChildren().empty()
503 && wxHasRealChildren(this)
507 // our minimal acceptable size is such that all our visible child windows fit inside
511 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
513 node
= node
->GetNext() )
515 wxWindow
*win
= node
->GetData();
516 if ( win
->IsTopLevel() || ( ! win
->IsShown() )
518 || wxDynamicCast(win
, wxStatusBar
)
519 #endif // wxUSE_STATUSBAR
522 // dialogs and frames lie in different top level windows -
523 // don't deal with them here; as for the status bars, they
524 // don't lie in the client area at all
529 win
->GetPosition(&wx
, &wy
);
531 // if the window hadn't been positioned yet, assume that it is in
533 if ( wx
== wxDefaultCoord
)
535 if ( wy
== wxDefaultCoord
)
538 win
->GetSize(&ww
, &wh
);
539 if ( wx
+ ww
> maxX
)
541 if ( wy
+ wh
> maxY
)
545 // for compatibility with the old versions and because it really looks
546 // slightly more pretty like this, add a pad
550 best
= wxSize(maxX
, maxY
);
552 else // ! has children
554 // for a generic window there is no natural best size so, if the
555 // minimal size is not set, use the current size but take care to
556 // remember it as minimal size for the next time because our best size
557 // should be constant: otherwise we could get into a situation when the
558 // window is initially at some size, then expanded to a larger size and
559 // then, when the containing window is shrunk back (because our initial
560 // best size had been used for computing the parent min size), we can't
561 // be shrunk back any more because our best size is now bigger
562 wxSize size
= GetMinSize();
563 if ( !size
.IsFullySpecified() )
565 size
.SetDefaults(GetSize());
566 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
569 // return as-is, unadjusted by the client size difference.
573 // Add any difference between size and client size
574 wxSize diff
= GetSize() - GetClientSize();
575 best
.x
+= wxMax(0, diff
.x
);
576 best
.y
+= wxMax(0, diff
.y
);
582 wxSize
wxWindowBase::GetBestFittingSize() const
584 // merge the best size with the min size, giving priority to the min size
585 wxSize min
= GetMinSize();
586 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
588 wxSize best
= GetBestSize();
589 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
590 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
596 void wxWindowBase::SetBestFittingSize(const wxSize
& size
)
598 // Set the min size to the size passed in. This will usually either be
599 // wxDefaultSize or the size passed to this window's ctor/Create function.
602 // Merge the size with the best size if needed
603 wxSize best
= GetBestFittingSize();
605 // If the current size doesn't match then change it
606 if (GetSize() != best
)
611 // by default the origin is not shifted
612 wxPoint
wxWindowBase::GetClientAreaOrigin() const
617 // set the min/max size of the window
618 void wxWindowBase::DoSetSizeHints(int minW
, int minH
,
620 int WXUNUSED(incW
), int WXUNUSED(incH
))
622 // setting min width greater than max width leads to infinite loops under
623 // X11 and generally doesn't make any sense, so don't allow it
624 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
625 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
626 _T("min width/height must be less than max width/height!") );
634 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
636 if ( m_windowVariant
!= variant
)
638 m_windowVariant
= variant
;
640 DoSetWindowVariant(variant
);
644 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
646 // adjust the font height to correspond to our new variant (notice that
647 // we're only called if something really changed)
648 wxFont font
= GetFont();
649 int size
= font
.GetPointSize();
652 case wxWINDOW_VARIANT_NORMAL
:
655 case wxWINDOW_VARIANT_SMALL
:
660 case wxWINDOW_VARIANT_MINI
:
665 case wxWINDOW_VARIANT_LARGE
:
671 wxFAIL_MSG(_T("unexpected window variant"));
675 font
.SetPointSize(size
);
679 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
682 m_minVirtualWidth
= minW
;
683 m_maxVirtualWidth
= maxW
;
684 m_minVirtualHeight
= minH
;
685 m_maxVirtualHeight
= maxH
;
688 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
690 if ( m_minVirtualWidth
!= wxDefaultCoord
&& m_minVirtualWidth
> x
)
691 x
= m_minVirtualWidth
;
692 if ( m_maxVirtualWidth
!= wxDefaultCoord
&& m_maxVirtualWidth
< x
)
693 x
= m_maxVirtualWidth
;
694 if ( m_minVirtualHeight
!= wxDefaultCoord
&& m_minVirtualHeight
> y
)
695 y
= m_minVirtualHeight
;
696 if ( m_maxVirtualHeight
!= wxDefaultCoord
&& m_maxVirtualHeight
< y
)
697 y
= m_maxVirtualHeight
;
699 m_virtualSize
= wxSize(x
, y
);
702 wxSize
wxWindowBase::DoGetVirtualSize() const
704 // we should use the entire client area so if it is greater than our
705 // virtual size, expand it to fit (otherwise if the window is big enough we
706 // wouldn't be using parts of it)
707 wxSize size
= GetClientSize();
708 if ( m_virtualSize
.x
> size
.x
)
709 size
.x
= m_virtualSize
.x
;
711 if ( m_virtualSize
.y
>= size
.y
)
712 size
.y
= m_virtualSize
.y
;
717 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
719 // screen position is the same as (0, 0) in client coords for non TLWs (and
720 // TLWs override this method)
726 ClientToScreen(x
, y
);
729 // ----------------------------------------------------------------------------
730 // show/hide/enable/disable the window
731 // ----------------------------------------------------------------------------
733 bool wxWindowBase::Show(bool show
)
735 if ( show
!= m_isShown
)
747 bool wxWindowBase::Enable(bool enable
)
749 if ( enable
!= m_isEnabled
)
751 m_isEnabled
= enable
;
760 // ----------------------------------------------------------------------------
762 // ----------------------------------------------------------------------------
764 bool wxWindowBase::IsTopLevel() const
769 // ----------------------------------------------------------------------------
770 // reparenting the window
771 // ----------------------------------------------------------------------------
773 void wxWindowBase::AddChild(wxWindowBase
*child
)
775 wxCHECK_RET( child
, wxT("can't add a NULL child") );
777 // this should never happen and it will lead to a crash later if it does
778 // because RemoveChild() will remove only one node from the children list
779 // and the other(s) one(s) will be left with dangling pointers in them
780 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
782 GetChildren().Append((wxWindow
*)child
);
783 child
->SetParent(this);
786 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
788 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
790 GetChildren().DeleteObject((wxWindow
*)child
);
791 child
->SetParent(NULL
);
794 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
796 wxWindow
*oldParent
= GetParent();
797 if ( newParent
== oldParent
)
803 // unlink this window from the existing parent.
806 oldParent
->RemoveChild(this);
810 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
813 // add it to the new one
816 newParent
->AddChild(this);
820 wxTopLevelWindows
.Append((wxWindow
*)this);
826 // ----------------------------------------------------------------------------
827 // event handler stuff
828 // ----------------------------------------------------------------------------
830 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
832 wxEvtHandler
*handlerOld
= GetEventHandler();
834 handler
->SetNextHandler(handlerOld
);
837 GetEventHandler()->SetPreviousHandler(handler
);
839 SetEventHandler(handler
);
842 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
844 wxEvtHandler
*handlerA
= GetEventHandler();
847 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
848 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
851 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
852 SetEventHandler(handlerB
);
857 handlerA
= (wxEvtHandler
*)NULL
;
864 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
866 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
868 wxEvtHandler
*handlerPrev
= NULL
,
869 *handlerCur
= GetEventHandler();
872 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
874 if ( handlerCur
== handler
)
878 handlerPrev
->SetNextHandler(handlerNext
);
882 SetEventHandler(handlerNext
);
887 handlerNext
->SetPreviousHandler ( handlerPrev
);
890 handler
->SetNextHandler(NULL
);
891 handler
->SetPreviousHandler(NULL
);
896 handlerPrev
= handlerCur
;
897 handlerCur
= handlerNext
;
900 wxFAIL_MSG( _T("where has the event handler gone?") );
905 // ----------------------------------------------------------------------------
907 // ----------------------------------------------------------------------------
909 void wxWindowBase::InheritAttributes()
911 const wxWindowBase
* const parent
= GetParent();
915 // we only inherit attributes which had been explicitly set for the parent
916 // which ensures that this only happens if the user really wants it and
917 // not by default which wouldn't make any sense in modern GUIs where the
918 // controls don't all use the same fonts (nor colours)
919 if ( parent
->m_inheritFont
&& !m_hasFont
)
920 SetFont(parent
->GetFont());
922 // in addition, there is a possibility to explicitly forbid inheriting
923 // colours at each class level by overriding ShouldInheritColours()
924 if ( ShouldInheritColours() )
926 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
927 SetForegroundColour(parent
->GetForegroundColour());
929 // inheriting (solid) background colour is wrong as it totally breaks
930 // any kind of themed backgrounds
932 // instead, the controls should use the same background as their parent
933 // (ideally by not drawing it at all)
935 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
936 SetBackgroundColour(parent
->GetBackgroundColour());
941 /* static */ wxVisualAttributes
942 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
944 // it is important to return valid values for all attributes from here,
945 // GetXXX() below rely on this
946 wxVisualAttributes attrs
;
947 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
948 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
950 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
951 // the usual background colour than wxSYS_COLOUR_BTNFACE.
952 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
953 // colour on other platforms.
955 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
956 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
958 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
963 wxColour
wxWindowBase::GetBackgroundColour() const
965 if ( !m_backgroundColour
.Ok() )
967 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
969 // get our default background colour
970 wxColour colBg
= GetDefaultAttributes().colBg
;
972 // we must return some valid colour to avoid redoing this every time
973 // and also to avoid surprizing the applications written for older
974 // wxWidgets versions where GetBackgroundColour() always returned
975 // something -- so give them something even if it doesn't make sense
976 // for this window (e.g. it has a themed background)
978 colBg
= GetClassDefaultAttributes().colBg
;
983 return m_backgroundColour
;
986 wxColour
wxWindowBase::GetForegroundColour() const
988 // logic is the same as above
989 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
991 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
993 wxColour colFg
= GetDefaultAttributes().colFg
;
996 colFg
= GetClassDefaultAttributes().colFg
;
1001 return m_foregroundColour
;
1004 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1006 if ( colour
== m_backgroundColour
)
1009 m_hasBgCol
= colour
.Ok();
1010 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1011 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1013 m_inheritBgCol
= m_hasBgCol
;
1014 m_backgroundColour
= colour
;
1015 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1019 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1021 if (colour
== m_foregroundColour
)
1024 m_hasFgCol
= colour
.Ok();
1025 m_inheritFgCol
= m_hasFgCol
;
1026 m_foregroundColour
= colour
;
1027 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1031 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1033 // setting an invalid cursor is ok, it means that we don't have any special
1035 if ( m_cursor
== cursor
)
1046 wxFont
wxWindowBase::GetFont() const
1048 // logic is the same as in GetBackgroundColour()
1051 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1053 wxFont font
= GetDefaultAttributes().font
;
1055 font
= GetClassDefaultAttributes().font
;
1063 bool wxWindowBase::SetFont(const wxFont
& font
)
1065 if ( font
== m_font
)
1072 m_hasFont
= font
.Ok();
1073 m_inheritFont
= m_hasFont
;
1075 InvalidateBestSize();
1082 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1084 m_hasCustomPalette
= true;
1087 // VZ: can anyone explain me what do we do here?
1088 wxWindowDC
d((wxWindow
*) this);
1092 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1094 wxWindow
*win
= (wxWindow
*)this;
1095 while ( win
&& !win
->HasCustomPalette() )
1097 win
= win
->GetParent();
1103 #endif // wxUSE_PALETTE
1106 void wxWindowBase::SetCaret(wxCaret
*caret
)
1117 wxASSERT_MSG( m_caret
->GetWindow() == this,
1118 wxT("caret should be created associated to this window") );
1121 #endif // wxUSE_CARET
1123 #if wxUSE_VALIDATORS
1124 // ----------------------------------------------------------------------------
1126 // ----------------------------------------------------------------------------
1128 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1130 if ( m_windowValidator
)
1131 delete m_windowValidator
;
1133 m_windowValidator
= (wxValidator
*)validator
.Clone();
1135 if ( m_windowValidator
)
1136 m_windowValidator
->SetWindow(this);
1138 #endif // wxUSE_VALIDATORS
1140 // ----------------------------------------------------------------------------
1141 // update region stuff
1142 // ----------------------------------------------------------------------------
1144 wxRect
wxWindowBase::GetUpdateClientRect() const
1146 wxRegion rgnUpdate
= GetUpdateRegion();
1147 rgnUpdate
.Intersect(GetClientRect());
1148 wxRect rectUpdate
= rgnUpdate
.GetBox();
1149 wxPoint ptOrigin
= GetClientAreaOrigin();
1150 rectUpdate
.x
-= ptOrigin
.x
;
1151 rectUpdate
.y
-= ptOrigin
.y
;
1156 bool wxWindowBase::IsExposed(int x
, int y
) const
1158 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1161 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1163 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1166 void wxWindowBase::ClearBackground()
1168 // wxGTK uses its own version, no need to add never used code
1170 wxClientDC
dc((wxWindow
*)this);
1171 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1172 dc
.SetBackground(brush
);
1177 // ----------------------------------------------------------------------------
1178 // find child window by id or name
1179 // ----------------------------------------------------------------------------
1181 wxWindow
*wxWindowBase::FindWindow(long id
) const
1183 if ( id
== m_windowId
)
1184 return (wxWindow
*)this;
1186 wxWindowBase
*res
= (wxWindow
*)NULL
;
1187 wxWindowList::compatibility_iterator node
;
1188 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1190 wxWindowBase
*child
= node
->GetData();
1191 res
= child
->FindWindow( id
);
1194 return (wxWindow
*)res
;
1197 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1199 if ( name
== m_windowName
)
1200 return (wxWindow
*)this;
1202 wxWindowBase
*res
= (wxWindow
*)NULL
;
1203 wxWindowList::compatibility_iterator node
;
1204 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1206 wxWindow
*child
= node
->GetData();
1207 res
= child
->FindWindow(name
);
1210 return (wxWindow
*)res
;
1214 // find any window by id or name or label: If parent is non-NULL, look through
1215 // children for a label or title matching the specified string. If NULL, look
1216 // through all top-level windows.
1218 // to avoid duplicating code we reuse the same helper function but with
1219 // different comparators
1221 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1222 const wxString
& label
, long id
);
1225 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1228 return win
->GetLabel() == label
;
1232 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1235 return win
->GetName() == label
;
1239 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1242 return win
->GetId() == id
;
1245 // recursive helper for the FindWindowByXXX() functions
1247 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1248 const wxString
& label
,
1250 wxFindWindowCmp cmp
)
1254 // see if this is the one we're looking for
1255 if ( (*cmp
)(parent
, label
, id
) )
1256 return (wxWindow
*)parent
;
1258 // It wasn't, so check all its children
1259 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1261 node
= node
->GetNext() )
1263 // recursively check each child
1264 wxWindow
*win
= (wxWindow
*)node
->GetData();
1265 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1275 // helper for FindWindowByXXX()
1277 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1278 const wxString
& label
,
1280 wxFindWindowCmp cmp
)
1284 // just check parent and all its children
1285 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1288 // start at very top of wx's windows
1289 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1291 node
= node
->GetNext() )
1293 // recursively check each window & its children
1294 wxWindow
*win
= node
->GetData();
1295 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1305 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1307 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1312 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1314 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1318 // fall back to the label
1319 win
= FindWindowByLabel(title
, parent
);
1327 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1329 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1332 // ----------------------------------------------------------------------------
1333 // dialog oriented functions
1334 // ----------------------------------------------------------------------------
1336 void wxWindowBase::MakeModal(bool modal
)
1338 // Disable all other windows
1341 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1344 wxWindow
*win
= node
->GetData();
1346 win
->Enable(!modal
);
1348 node
= node
->GetNext();
1353 bool wxWindowBase::Validate()
1355 #if wxUSE_VALIDATORS
1356 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1358 wxWindowList::compatibility_iterator node
;
1359 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1361 wxWindowBase
*child
= node
->GetData();
1362 wxValidator
*validator
= child
->GetValidator();
1363 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1368 if ( recurse
&& !child
->Validate() )
1373 #endif // wxUSE_VALIDATORS
1378 bool wxWindowBase::TransferDataToWindow()
1380 #if wxUSE_VALIDATORS
1381 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1383 wxWindowList::compatibility_iterator node
;
1384 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1386 wxWindowBase
*child
= node
->GetData();
1387 wxValidator
*validator
= child
->GetValidator();
1388 if ( validator
&& !validator
->TransferToWindow() )
1390 wxLogWarning(_("Could not transfer data to window"));
1392 wxLog::FlushActive();
1400 if ( !child
->TransferDataToWindow() )
1402 // warning already given
1407 #endif // wxUSE_VALIDATORS
1412 bool wxWindowBase::TransferDataFromWindow()
1414 #if wxUSE_VALIDATORS
1415 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1417 wxWindowList::compatibility_iterator node
;
1418 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1420 wxWindow
*child
= node
->GetData();
1421 wxValidator
*validator
= child
->GetValidator();
1422 if ( validator
&& !validator
->TransferFromWindow() )
1424 // nop warning here because the application is supposed to give
1425 // one itself - we don't know here what might have gone wrongly
1432 if ( !child
->TransferDataFromWindow() )
1434 // warning already given
1439 #endif // wxUSE_VALIDATORS
1444 void wxWindowBase::InitDialog()
1446 wxInitDialogEvent
event(GetId());
1447 event
.SetEventObject( this );
1448 GetEventHandler()->ProcessEvent(event
);
1451 // ----------------------------------------------------------------------------
1452 // context-sensitive help support
1453 // ----------------------------------------------------------------------------
1457 // associate this help text with this window
1458 void wxWindowBase::SetHelpText(const wxString
& text
)
1460 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1463 helpProvider
->AddHelp(this, text
);
1467 // associate this help text with all windows with the same id as this
1469 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1471 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1474 helpProvider
->AddHelp(GetId(), text
);
1478 // get the help string associated with this window (may be empty)
1479 wxString
wxWindowBase::GetHelpText() const
1482 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1485 text
= helpProvider
->GetHelp(this);
1491 // show help for this window
1492 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1494 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1497 if ( helpProvider
->ShowHelp(this) )
1499 // skip the event.Skip() below
1507 #endif // wxUSE_HELP
1509 // ----------------------------------------------------------------------------
1510 // tooltipsroot.Replace("\\", "/");
1511 // ----------------------------------------------------------------------------
1515 void wxWindowBase::SetToolTip( const wxString
&tip
)
1517 // don't create the new tooltip if we already have one
1520 m_tooltip
->SetTip( tip
);
1524 SetToolTip( new wxToolTip( tip
) );
1527 // setting empty tooltip text does not remove the tooltip any more - use
1528 // SetToolTip((wxToolTip *)NULL) for this
1531 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1533 if ( m_tooltip
!= tooltip
)
1538 m_tooltip
= tooltip
;
1542 #endif // wxUSE_TOOLTIPS
1544 // ----------------------------------------------------------------------------
1545 // constraints and sizers
1546 // ----------------------------------------------------------------------------
1548 #if wxUSE_CONSTRAINTS
1550 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1552 if ( m_constraints
)
1554 UnsetConstraints(m_constraints
);
1555 delete m_constraints
;
1557 m_constraints
= constraints
;
1558 if ( m_constraints
)
1560 // Make sure other windows know they're part of a 'meaningful relationship'
1561 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1562 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1563 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1564 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1565 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1566 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1567 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1568 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1569 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1570 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1571 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1572 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1573 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1574 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1575 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1576 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1580 // This removes any dangling pointers to this window in other windows'
1581 // constraintsInvolvedIn lists.
1582 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1586 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1587 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1588 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1589 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1590 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1591 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1592 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1593 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1594 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1595 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1596 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1597 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1598 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1599 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1600 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1601 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1605 // Back-pointer to other windows we're involved with, so if we delete this
1606 // window, we must delete any constraints we're involved with.
1607 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1609 if ( !m_constraintsInvolvedIn
)
1610 m_constraintsInvolvedIn
= new wxWindowList
;
1611 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1612 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1615 // REMOVE back-pointer to other windows we're involved with.
1616 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1618 if ( m_constraintsInvolvedIn
)
1619 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1622 // Reset any constraints that mention this window
1623 void wxWindowBase::DeleteRelatedConstraints()
1625 if ( m_constraintsInvolvedIn
)
1627 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1630 wxWindow
*win
= node
->GetData();
1631 wxLayoutConstraints
*constr
= win
->GetConstraints();
1633 // Reset any constraints involving this window
1636 constr
->left
.ResetIfWin(this);
1637 constr
->top
.ResetIfWin(this);
1638 constr
->right
.ResetIfWin(this);
1639 constr
->bottom
.ResetIfWin(this);
1640 constr
->width
.ResetIfWin(this);
1641 constr
->height
.ResetIfWin(this);
1642 constr
->centreX
.ResetIfWin(this);
1643 constr
->centreY
.ResetIfWin(this);
1646 wxWindowList::compatibility_iterator next
= node
->GetNext();
1647 m_constraintsInvolvedIn
->Erase(node
);
1651 delete m_constraintsInvolvedIn
;
1652 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1656 #endif // wxUSE_CONSTRAINTS
1658 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1660 if ( sizer
== m_windowSizer
)
1664 delete m_windowSizer
;
1666 m_windowSizer
= sizer
;
1668 SetAutoLayout( sizer
!= NULL
);
1671 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1673 SetSizer( sizer
, deleteOld
);
1674 sizer
->SetSizeHints( (wxWindow
*) this );
1678 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1680 // adding a window to a sizer twice is going to result in fatal and
1681 // hard to debug problems later because when deleting the second
1682 // associated wxSizerItem we're going to dereference a dangling
1683 // pointer; so try to detect this as early as possible
1684 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1685 _T("Adding a window to the same sizer twice?") );
1687 m_containingSizer
= sizer
;
1690 #if wxUSE_CONSTRAINTS
1692 void wxWindowBase::SatisfyConstraints()
1694 wxLayoutConstraints
*constr
= GetConstraints();
1695 bool wasOk
= constr
&& constr
->AreSatisfied();
1697 ResetConstraints(); // Mark all constraints as unevaluated
1701 // if we're a top level panel (i.e. our parent is frame/dialog), our
1702 // own constraints will never be satisfied any more unless we do it
1706 while ( noChanges
> 0 )
1708 LayoutPhase1(&noChanges
);
1712 LayoutPhase2(&noChanges
);
1715 #endif // wxUSE_CONSTRAINTS
1717 bool wxWindowBase::Layout()
1719 // If there is a sizer, use it instead of the constraints
1723 GetVirtualSize(&w
, &h
);
1724 GetSizer()->SetDimension( 0, 0, w
, h
);
1726 #if wxUSE_CONSTRAINTS
1729 SatisfyConstraints(); // Find the right constraints values
1730 SetConstraintSizes(); // Recursively set the real window sizes
1737 #if wxUSE_CONSTRAINTS
1739 // first phase of the constraints evaluation: set our own constraints
1740 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1742 wxLayoutConstraints
*constr
= GetConstraints();
1744 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1747 // second phase: set the constraints for our children
1748 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1755 // Layout grand children
1761 // Do a phase of evaluating child constraints
1762 bool wxWindowBase::DoPhase(int phase
)
1764 // the list containing the children for which the constraints are already
1766 wxWindowList succeeded
;
1768 // the max number of iterations we loop before concluding that we can't set
1770 static const int maxIterations
= 500;
1772 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1776 // loop over all children setting their constraints
1777 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1779 node
= node
->GetNext() )
1781 wxWindow
*child
= node
->GetData();
1782 if ( child
->IsTopLevel() )
1784 // top level children are not inside our client area
1788 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1790 // this one is either already ok or nothing we can do about it
1794 int tempNoChanges
= 0;
1795 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1796 : child
->LayoutPhase2(&tempNoChanges
);
1797 noChanges
+= tempNoChanges
;
1801 succeeded
.Append(child
);
1807 // constraints are set
1815 void wxWindowBase::ResetConstraints()
1817 wxLayoutConstraints
*constr
= GetConstraints();
1820 constr
->left
.SetDone(false);
1821 constr
->top
.SetDone(false);
1822 constr
->right
.SetDone(false);
1823 constr
->bottom
.SetDone(false);
1824 constr
->width
.SetDone(false);
1825 constr
->height
.SetDone(false);
1826 constr
->centreX
.SetDone(false);
1827 constr
->centreY
.SetDone(false);
1830 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1833 wxWindow
*win
= node
->GetData();
1834 if ( !win
->IsTopLevel() )
1835 win
->ResetConstraints();
1836 node
= node
->GetNext();
1840 // Need to distinguish between setting the 'fake' size for windows and sizers,
1841 // and setting the real values.
1842 void wxWindowBase::SetConstraintSizes(bool recurse
)
1844 wxLayoutConstraints
*constr
= GetConstraints();
1845 if ( constr
&& constr
->AreSatisfied() )
1847 int x
= constr
->left
.GetValue();
1848 int y
= constr
->top
.GetValue();
1849 int w
= constr
->width
.GetValue();
1850 int h
= constr
->height
.GetValue();
1852 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1853 (constr
->height
.GetRelationship() != wxAsIs
) )
1855 SetSize(x
, y
, w
, h
);
1859 // If we don't want to resize this window, just move it...
1865 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1866 GetClassInfo()->GetClassName(),
1872 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1875 wxWindow
*win
= node
->GetData();
1876 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1877 win
->SetConstraintSizes();
1878 node
= node
->GetNext();
1883 // Only set the size/position of the constraint (if any)
1884 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1886 wxLayoutConstraints
*constr
= GetConstraints();
1889 if ( x
!= wxDefaultCoord
)
1891 constr
->left
.SetValue(x
);
1892 constr
->left
.SetDone(true);
1894 if ( y
!= wxDefaultCoord
)
1896 constr
->top
.SetValue(y
);
1897 constr
->top
.SetDone(true);
1899 if ( w
!= wxDefaultCoord
)
1901 constr
->width
.SetValue(w
);
1902 constr
->width
.SetDone(true);
1904 if ( h
!= wxDefaultCoord
)
1906 constr
->height
.SetValue(h
);
1907 constr
->height
.SetDone(true);
1912 void wxWindowBase::MoveConstraint(int x
, int y
)
1914 wxLayoutConstraints
*constr
= GetConstraints();
1917 if ( x
!= wxDefaultCoord
)
1919 constr
->left
.SetValue(x
);
1920 constr
->left
.SetDone(true);
1922 if ( y
!= wxDefaultCoord
)
1924 constr
->top
.SetValue(y
);
1925 constr
->top
.SetDone(true);
1930 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1932 wxLayoutConstraints
*constr
= GetConstraints();
1935 *w
= constr
->width
.GetValue();
1936 *h
= constr
->height
.GetValue();
1942 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1944 wxLayoutConstraints
*constr
= GetConstraints();
1947 *w
= constr
->width
.GetValue();
1948 *h
= constr
->height
.GetValue();
1951 GetClientSize(w
, h
);
1954 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1956 wxLayoutConstraints
*constr
= GetConstraints();
1959 *x
= constr
->left
.GetValue();
1960 *y
= constr
->top
.GetValue();
1966 #endif // wxUSE_CONSTRAINTS
1968 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1970 // don't do it for the dialogs/frames - they float independently of their
1972 if ( !IsTopLevel() )
1974 wxWindow
*parent
= GetParent();
1975 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1977 wxPoint
pt(parent
->GetClientAreaOrigin());
1984 // ----------------------------------------------------------------------------
1985 // do Update UI processing for child controls
1986 // ----------------------------------------------------------------------------
1988 void wxWindowBase::UpdateWindowUI(long flags
)
1990 wxUpdateUIEvent
event(GetId());
1991 event
.SetEventObject(this);
1993 if ( GetEventHandler()->ProcessEvent(event
) )
1995 DoUpdateWindowUI(event
);
1998 if (flags
& wxUPDATE_UI_RECURSE
)
2000 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2003 wxWindow
* child
= (wxWindow
*) node
->GetData();
2004 child
->UpdateWindowUI(flags
);
2005 node
= node
->GetNext();
2010 // do the window-specific processing after processing the update event
2011 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2013 if ( event
.GetSetEnabled() )
2014 Enable(event
.GetEnabled());
2016 if ( event
.GetSetShown() )
2017 Show(event
.GetShown());
2021 // call internal idle recursively
2022 // may be obsolete (wait until OnIdle scheme stabilises)
2023 void wxWindowBase::ProcessInternalIdle()
2027 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2030 wxWindow
*child
= node
->GetData();
2031 child
->ProcessInternalIdle();
2032 node
= node
->GetNext();
2037 // ----------------------------------------------------------------------------
2038 // dialog units translations
2039 // ----------------------------------------------------------------------------
2041 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2043 int charWidth
= GetCharWidth();
2044 int charHeight
= GetCharHeight();
2045 wxPoint pt2
= wxDefaultPosition
;
2046 if (pt
.x
!= wxDefaultCoord
)
2047 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2048 if (pt
.y
!= wxDefaultCoord
)
2049 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2054 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2056 int charWidth
= GetCharWidth();
2057 int charHeight
= GetCharHeight();
2058 wxPoint pt2
= wxDefaultPosition
;
2059 if (pt
.x
!= wxDefaultCoord
)
2060 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2061 if (pt
.y
!= wxDefaultCoord
)
2062 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2067 // ----------------------------------------------------------------------------
2069 // ----------------------------------------------------------------------------
2071 // propagate the colour change event to the subwindows
2072 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2074 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2077 // Only propagate to non-top-level windows
2078 wxWindow
*win
= node
->GetData();
2079 if ( !win
->IsTopLevel() )
2081 wxSysColourChangedEvent event2
;
2082 event
.SetEventObject(win
);
2083 win
->GetEventHandler()->ProcessEvent(event2
);
2086 node
= node
->GetNext();
2092 // the default action is to populate dialog with data when it's created,
2093 // and nudge the UI into displaying itself correctly in case
2094 // we've turned the wxUpdateUIEvents frequency down low.
2095 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2097 TransferDataToWindow();
2099 // Update the UI at this point
2100 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2103 // methods for drawing the sizers in a visible way
2106 static void DrawSizers(wxWindowBase
*win
);
2108 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2110 wxClientDC
dc((wxWindow
*)win
);
2111 dc
.SetPen(*wxRED_PEN
);
2112 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2113 dc
.DrawRectangle(rect
.Deflate(1, 1));
2116 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2118 const wxSizerItemList
& items
= sizer
->GetChildren();
2119 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2124 wxSizerItem
*item
= *i
;
2125 if ( item
->IsSizer() )
2127 DrawBorder(win
, item
->GetRect().Deflate(2));
2128 DrawSizer(win
, item
->GetSizer());
2130 else if ( item
->IsSpacer() )
2132 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2134 else if ( item
->IsWindow() )
2136 DrawSizers(item
->GetWindow());
2141 static void DrawSizers(wxWindowBase
*win
)
2143 wxSizer
*sizer
= win
->GetSizer();
2146 DrawBorder(win
, win
->GetClientSize());
2147 DrawSizer(win
, sizer
);
2149 else // no sizer, still recurse into the children
2151 const wxWindowList
& children
= win
->GetChildren();
2152 for ( wxWindowList::const_iterator i
= children
.begin(),
2153 end
= children
.end();
2162 #endif // __WXDEBUG__
2164 // process special middle clicks
2165 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2167 if ( event
.ControlDown() && event
.AltDown() )
2170 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2171 if ( event
.ShiftDown() )
2176 #endif // __WXDEBUG__
2179 // don't translate these strings
2182 #ifdef __WXUNIVERSAL__
2184 #endif // __WXUNIVERSAL__
2186 switch ( wxGetOsVersion() )
2188 case wxMOTIF_X
: port
+= _T("Motif"); break;
2190 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
2191 case wxBEOS
: port
+= _T("BeOS"); break;
2195 case wxGTK_BEOS
: port
+= _T("GTK"); break;
2201 case wxWIN386
: port
+= _T("MS Windows"); break;
2205 case wxMGL_OS2
: port
+= _T("MGL"); break;
2207 case wxOS2_PM
: port
+= _T("OS/2"); break;
2208 case wxPALMOS
: port
+= _T("Palm OS"); break;
2209 case wxWINDOWS_CE
: port
+= _T("Windows CE (generic)"); break;
2210 case wxWINDOWS_POCKETPC
: port
+= _T("Windows CE PocketPC"); break;
2211 case wxWINDOWS_SMARTPHONE
: port
+= _T("Windows CE Smartphone"); break;
2212 default: port
+= _T("unknown"); break;
2215 wxMessageBox(wxString::Format(
2217 " wxWidgets Library (%s port)\nVersion %d.%d.%d%s%s, compiled at %s %s%s\n Copyright (c) 1995-2006 wxWidgets team"
2236 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()
2241 _T("wxWidgets information"),
2242 wxICON_INFORMATION
| wxOK
,
2246 #endif // wxUSE_MSGDLG
2252 // ----------------------------------------------------------------------------
2254 // ----------------------------------------------------------------------------
2256 #if wxUSE_ACCESSIBILITY
2257 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2259 if (m_accessible
&& (accessible
!= m_accessible
))
2260 delete m_accessible
;
2261 m_accessible
= accessible
;
2263 m_accessible
->SetWindow((wxWindow
*) this);
2266 // Returns the accessible object, creating if necessary.
2267 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2270 m_accessible
= CreateAccessible();
2271 return m_accessible
;
2274 // Override to create a specific accessible object.
2275 wxAccessible
* wxWindowBase::CreateAccessible()
2277 return new wxWindowAccessible((wxWindow
*) this);
2282 // ----------------------------------------------------------------------------
2283 // list classes implementation
2284 // ----------------------------------------------------------------------------
2288 #include "wx/listimpl.cpp"
2289 WX_DEFINE_LIST(wxWindowList
)
2293 void wxWindowListNode::DeleteData()
2295 delete (wxWindow
*)GetData();
2300 // ----------------------------------------------------------------------------
2302 // ----------------------------------------------------------------------------
2304 wxBorder
wxWindowBase::GetBorder(long flags
) const
2306 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2307 if ( border
== wxBORDER_DEFAULT
)
2309 border
= GetDefaultBorder();
2315 wxBorder
wxWindowBase::GetDefaultBorder() const
2317 return wxBORDER_NONE
;
2320 // ----------------------------------------------------------------------------
2322 // ----------------------------------------------------------------------------
2324 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2326 // here we just check if the point is inside the window or not
2328 // check the top and left border first
2329 bool outside
= x
< 0 || y
< 0;
2332 // check the right and bottom borders too
2333 wxSize size
= GetSize();
2334 outside
= x
>= size
.x
|| y
>= size
.y
;
2337 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2340 // ----------------------------------------------------------------------------
2342 // ----------------------------------------------------------------------------
2344 struct WXDLLEXPORT wxWindowNext
2348 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2350 void wxWindowBase::CaptureMouse()
2352 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2354 wxWindow
*winOld
= GetCapture();
2357 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2360 wxWindowNext
*item
= new wxWindowNext
;
2362 item
->next
= ms_winCaptureNext
;
2363 ms_winCaptureNext
= item
;
2365 //else: no mouse capture to save
2370 void wxWindowBase::ReleaseMouse()
2372 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2374 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2378 if ( ms_winCaptureNext
)
2380 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2382 wxWindowNext
*item
= ms_winCaptureNext
;
2383 ms_winCaptureNext
= item
->next
;
2386 //else: stack is empty, no previous capture
2388 wxLogTrace(_T("mousecapture"),
2389 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2396 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2397 int WXUNUSED(modifiers
),
2398 int WXUNUSED(keycode
))
2404 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2410 #endif // wxUSE_HOTKEY
2412 void wxWindowBase::SendDestroyEvent()
2414 wxWindowDestroyEvent event
;
2415 event
.SetEventObject(this);
2416 event
.SetId(GetId());
2417 GetEventHandler()->ProcessEvent(event
);
2420 // ----------------------------------------------------------------------------
2422 // ----------------------------------------------------------------------------
2424 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2426 #if wxUSE_VALIDATORS
2427 // Can only use the validator of the window which
2428 // is receiving the event
2429 if ( event
.GetEventObject() == this )
2431 wxValidator
*validator
= GetValidator();
2432 if ( validator
&& validator
->ProcessEvent(event
) )
2437 #endif // wxUSE_VALIDATORS
2442 bool wxWindowBase::TryParent(wxEvent
& event
)
2444 // carry on up the parent-child hierarchy if the propagation count hasn't
2446 if ( event
.ShouldPropagate() )
2448 // honour the requests to stop propagation at this window: this is
2449 // used by the dialogs, for example, to prevent processing the events
2450 // from the dialog controls in the parent frame which rarely, if ever,
2452 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2454 wxWindow
*parent
= GetParent();
2455 if ( parent
&& !parent
->IsBeingDeleted() )
2457 wxPropagateOnce
propagateOnce(event
);
2459 return parent
->GetEventHandler()->ProcessEvent(event
);
2464 return wxEvtHandler::TryParent(event
);
2467 // ----------------------------------------------------------------------------
2468 // keyboard navigation
2469 // ----------------------------------------------------------------------------
2471 // Navigates in the specified direction.
2472 bool wxWindowBase::Navigate(int flags
)
2474 wxNavigationKeyEvent eventNav
;
2475 eventNav
.SetFlags(flags
);
2476 eventNav
.SetEventObject(this);
2477 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2484 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2486 // check that we're not a top level window
2487 wxCHECK_RET( GetParent(),
2488 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2490 // detect the special case when we have nothing to do anyhow and when the
2491 // code below wouldn't work
2495 // find the target window in the siblings list
2496 wxWindowList
& siblings
= GetParent()->GetChildren();
2497 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2498 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2500 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2501 // can't just move the node around
2502 wxWindow
*self
= (wxWindow
*)this;
2503 siblings
.DeleteObject(self
);
2504 if ( move
== MoveAfter
)
2511 siblings
.Insert(i
, self
);
2513 else // MoveAfter and win was the last sibling
2515 siblings
.Append(self
);
2519 // ----------------------------------------------------------------------------
2521 // ----------------------------------------------------------------------------
2523 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2525 wxWindowBase
*win
= DoFindFocus();
2526 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2529 // ----------------------------------------------------------------------------
2531 // ----------------------------------------------------------------------------
2533 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2535 while ( win
&& !win
->IsTopLevel() )
2536 win
= win
->GetParent();
2541 #if wxUSE_ACCESSIBILITY
2542 // ----------------------------------------------------------------------------
2543 // accessible object for windows
2544 // ----------------------------------------------------------------------------
2546 // Can return either a child object, or an integer
2547 // representing the child element, starting from 1.
2548 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2550 wxASSERT( GetWindow() != NULL
);
2554 return wxACC_NOT_IMPLEMENTED
;
2557 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2558 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2560 wxASSERT( GetWindow() != NULL
);
2564 wxWindow
* win
= NULL
;
2571 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2573 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2580 rect
= win
->GetRect();
2581 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2582 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2586 return wxACC_NOT_IMPLEMENTED
;
2589 // Navigates from fromId to toId/toObject.
2590 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2591 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2593 wxASSERT( GetWindow() != NULL
);
2599 case wxNAVDIR_FIRSTCHILD
:
2601 if (GetWindow()->GetChildren().GetCount() == 0)
2603 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2604 *toObject
= childWindow
->GetOrCreateAccessible();
2608 case wxNAVDIR_LASTCHILD
:
2610 if (GetWindow()->GetChildren().GetCount() == 0)
2612 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2613 *toObject
= childWindow
->GetOrCreateAccessible();
2617 case wxNAVDIR_RIGHT
:
2621 wxWindowList::compatibility_iterator node
=
2622 wxWindowList::compatibility_iterator();
2625 // Can't navigate to sibling of this window
2626 // if we're a top-level window.
2627 if (!GetWindow()->GetParent())
2628 return wxACC_NOT_IMPLEMENTED
;
2630 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2634 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2635 node
= GetWindow()->GetChildren().Item(fromId
-1);
2638 if (node
&& node
->GetNext())
2640 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2641 *toObject
= nextWindow
->GetOrCreateAccessible();
2649 case wxNAVDIR_PREVIOUS
:
2651 wxWindowList::compatibility_iterator node
=
2652 wxWindowList::compatibility_iterator();
2655 // Can't navigate to sibling of this window
2656 // if we're a top-level window.
2657 if (!GetWindow()->GetParent())
2658 return wxACC_NOT_IMPLEMENTED
;
2660 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2664 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2665 node
= GetWindow()->GetChildren().Item(fromId
-1);
2668 if (node
&& node
->GetPrevious())
2670 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2671 *toObject
= previousWindow
->GetOrCreateAccessible();
2679 return wxACC_NOT_IMPLEMENTED
;
2682 // Gets the name of the specified object.
2683 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2685 wxASSERT( GetWindow() != NULL
);
2691 // If a child, leave wxWidgets to call the function on the actual
2694 return wxACC_NOT_IMPLEMENTED
;
2696 // This will eventually be replaced by specialised
2697 // accessible classes, one for each kind of wxWidgets
2698 // control or window.
2700 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2701 title
= ((wxButton
*) GetWindow())->GetLabel();
2704 title
= GetWindow()->GetName();
2712 return wxACC_NOT_IMPLEMENTED
;
2715 // Gets the number of children.
2716 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2718 wxASSERT( GetWindow() != NULL
);
2722 *childId
= (int) GetWindow()->GetChildren().GetCount();
2726 // Gets the specified child (starting from 1).
2727 // If *child is NULL and return value is wxACC_OK,
2728 // this means that the child is a simple element and
2729 // not an accessible object.
2730 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2732 wxASSERT( GetWindow() != NULL
);
2742 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2745 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2746 *child
= childWindow
->GetOrCreateAccessible();
2753 // Gets the parent, or NULL.
2754 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2756 wxASSERT( GetWindow() != NULL
);
2760 wxWindow
* parentWindow
= GetWindow()->GetParent();
2768 *parent
= parentWindow
->GetOrCreateAccessible();
2776 // Performs the default action. childId is 0 (the action for this object)
2777 // or > 0 (the action for a child).
2778 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2779 // window (e.g. an edit control).
2780 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2782 wxASSERT( GetWindow() != NULL
);
2786 return wxACC_NOT_IMPLEMENTED
;
2789 // Gets the default action for this object (0) or > 0 (the action for a child).
2790 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2791 // string if there is no action.
2792 // The retrieved string describes the action that is performed on an object,
2793 // not what the object does as a result. For example, a toolbar button that prints
2794 // a document has a default action of "Press" rather than "Prints the current document."
2795 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2797 wxASSERT( GetWindow() != NULL
);
2801 return wxACC_NOT_IMPLEMENTED
;
2804 // Returns the description for this object or a child.
2805 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2807 wxASSERT( GetWindow() != NULL
);
2811 wxString
ht(GetWindow()->GetHelpText());
2817 return wxACC_NOT_IMPLEMENTED
;
2820 // Returns help text for this object or a child, similar to tooltip text.
2821 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2823 wxASSERT( GetWindow() != NULL
);
2827 wxString
ht(GetWindow()->GetHelpText());
2833 return wxACC_NOT_IMPLEMENTED
;
2836 // Returns the keyboard shortcut for this object or child.
2837 // Return e.g. ALT+K
2838 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2840 wxASSERT( GetWindow() != NULL
);
2844 return wxACC_NOT_IMPLEMENTED
;
2847 // Returns a role constant.
2848 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2850 wxASSERT( GetWindow() != NULL
);
2854 // If a child, leave wxWidgets to call the function on the actual
2857 return wxACC_NOT_IMPLEMENTED
;
2859 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2860 return wxACC_NOT_IMPLEMENTED
;
2862 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2863 return wxACC_NOT_IMPLEMENTED
;
2866 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2867 return wxACC_NOT_IMPLEMENTED
;
2870 //*role = wxROLE_SYSTEM_CLIENT;
2871 *role
= wxROLE_SYSTEM_CLIENT
;
2875 return wxACC_NOT_IMPLEMENTED
;
2879 // Returns a state constant.
2880 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2882 wxASSERT( GetWindow() != NULL
);
2886 // If a child, leave wxWidgets to call the function on the actual
2889 return wxACC_NOT_IMPLEMENTED
;
2891 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2892 return wxACC_NOT_IMPLEMENTED
;
2895 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2896 return wxACC_NOT_IMPLEMENTED
;
2899 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2900 return wxACC_NOT_IMPLEMENTED
;
2907 return wxACC_NOT_IMPLEMENTED
;
2911 // Returns a localized string representing the value for the object
2913 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2915 wxASSERT( GetWindow() != NULL
);
2919 return wxACC_NOT_IMPLEMENTED
;
2922 // Selects the object or child.
2923 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2925 wxASSERT( GetWindow() != NULL
);
2929 return wxACC_NOT_IMPLEMENTED
;
2932 // Gets the window with the keyboard focus.
2933 // If childId is 0 and child is NULL, no object in
2934 // this subhierarchy has the focus.
2935 // If this object has the focus, child should be 'this'.
2936 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2938 wxASSERT( GetWindow() != NULL
);
2942 return wxACC_NOT_IMPLEMENTED
;
2945 // Gets a variant representing the selected children
2947 // Acceptable values:
2948 // - a null variant (IsNull() returns true)
2949 // - a list variant (GetType() == wxT("list")
2950 // - an integer representing the selected child element,
2951 // or 0 if this object is selected (GetType() == wxT("long")
2952 // - a "void*" pointer to a wxAccessible child object
2953 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2955 wxASSERT( GetWindow() != NULL
);
2959 return wxACC_NOT_IMPLEMENTED
;
2962 #endif // wxUSE_ACCESSIBILITY