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"
33 #include "wx/window.h"
34 #include "wx/control.h"
35 #include "wx/checkbox.h"
36 #include "wx/radiobut.h"
37 #include "wx/statbox.h"
38 #include "wx/textctrl.h"
39 #include "wx/settings.h"
40 #include "wx/dialog.h"
41 #include "wx/msgdlg.h"
42 #include "wx/statusbr.h"
43 #include "wx/toolbar.h"
44 #include "wx/dcclient.h"
47 #if defined(__WXMAC__) && wxUSE_SCROLLBAR
48 #include "wx/scrolbar.h"
52 #include "wx/layout.h"
53 #endif // wxUSE_CONSTRAINTS
57 #if wxUSE_DRAG_AND_DROP
59 #endif // wxUSE_DRAG_AND_DROP
61 #if wxUSE_ACCESSIBILITY
62 #include "wx/access.h"
66 #include "wx/cshelp.h"
70 #include "wx/tooltip.h"
71 #endif // wxUSE_TOOLTIPS
77 #if wxUSE_SYSTEM_OPTIONS
78 #include "wx/sysopt.h"
81 // For reporting compile- and runtime version of GTK+ in the ctrl+alt+mclick dialog.
82 // The gtk includes don't pull any other headers in, at least not on my system - MR
85 #include <gtk/gtkversion.h>
87 #include <gtk/gtkfeatures.h>
89 extern const unsigned int gtk_major_version
;
90 extern const unsigned int gtk_minor_version
;
91 extern const unsigned int gtk_micro_version
;
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
98 #if defined(__WXPALMOS__)
99 int wxWindowBase::ms_lastControlId
= 32767;
100 #elif defined(__WXPM__)
101 int wxWindowBase::ms_lastControlId
= 2000;
103 int wxWindowBase::ms_lastControlId
= -200;
106 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
108 // ----------------------------------------------------------------------------
110 // ----------------------------------------------------------------------------
112 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
113 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
114 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
115 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
118 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
123 // ============================================================================
124 // implementation of the common functionality of the wxWindow class
125 // ============================================================================
127 // ----------------------------------------------------------------------------
129 // ----------------------------------------------------------------------------
131 // the default initialization
132 wxWindowBase::wxWindowBase()
134 // no window yet, no parent nor children
135 m_parent
= (wxWindow
*)NULL
;
136 m_windowId
= wxID_ANY
;
138 // no constraints on the minimal window size
140 m_maxWidth
= wxDefaultCoord
;
142 m_maxHeight
= wxDefaultCoord
;
144 // invalidiated cache value
145 m_bestSizeCache
= wxDefaultSize
;
147 // window are created enabled and visible by default
151 // the default event handler is just this window
152 m_eventHandler
= this;
156 m_windowValidator
= (wxValidator
*) NULL
;
157 #endif // wxUSE_VALIDATORS
159 // the colours/fonts are default for now, so leave m_font,
160 // m_backgroundColour and m_foregroundColour uninitialized and set those
166 m_inheritFont
= false;
172 m_backgroundStyle
= wxBG_STYLE_SYSTEM
;
174 #if wxUSE_CONSTRAINTS
175 // no constraints whatsoever
176 m_constraints
= (wxLayoutConstraints
*) NULL
;
177 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
178 #endif // wxUSE_CONSTRAINTS
180 m_windowSizer
= (wxSizer
*) NULL
;
181 m_containingSizer
= (wxSizer
*) NULL
;
182 m_autoLayout
= false;
184 #if wxUSE_DRAG_AND_DROP
185 m_dropTarget
= (wxDropTarget
*)NULL
;
186 #endif // wxUSE_DRAG_AND_DROP
189 m_tooltip
= (wxToolTip
*)NULL
;
190 #endif // wxUSE_TOOLTIPS
193 m_caret
= (wxCaret
*)NULL
;
194 #endif // wxUSE_CARET
197 m_hasCustomPalette
= false;
198 #endif // wxUSE_PALETTE
200 #if wxUSE_ACCESSIBILITY
204 m_virtualSize
= wxDefaultSize
;
207 m_maxVirtualWidth
= wxDefaultCoord
;
209 m_maxVirtualHeight
= wxDefaultCoord
;
211 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
212 #if wxUSE_SYSTEM_OPTIONS
213 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
215 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
219 // Whether we're using the current theme for this window (wxGTK only for now)
220 m_themeEnabled
= false;
222 // VZ: this one shouldn't exist...
223 m_isBeingDeleted
= false;
225 // Reserved for future use
226 m_windowReserved
= NULL
;
229 // common part of window creation process
230 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
232 const wxPoint
& WXUNUSED(pos
),
233 const wxSize
& WXUNUSED(size
),
235 const wxValidator
& wxVALIDATOR_PARAM(validator
),
236 const wxString
& name
)
239 // wxGTK doesn't allow to create controls with static box as the parent so
240 // this will result in a crash when the program is ported to wxGTK so warn
243 // if you get this assert, the correct solution is to create the controls
244 // as siblings of the static box
245 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
246 _T("wxStaticBox can't be used as a window parent!") );
247 #endif // wxUSE_STATBOX
249 // ids are limited to 16 bits under MSW so if you care about portability,
250 // it's not a good idea to use ids out of this range (and negative ids are
251 // reserved for wxWidgets own usage)
252 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
253 _T("invalid id value") );
255 // generate a new id if the user doesn't care about it
256 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
259 SetWindowStyleFlag(style
);
263 SetValidator(validator
);
264 #endif // wxUSE_VALIDATORS
266 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
267 // have it too - like this it's possible to set it only in the top level
268 // dialog/frame and all children will inherit it by defult
269 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
271 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
277 // ----------------------------------------------------------------------------
279 // ----------------------------------------------------------------------------
282 wxWindowBase::~wxWindowBase()
284 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
286 // FIXME if these 2 cases result from programming errors in the user code
287 // we should probably assert here instead of silently fixing them
289 // Just in case the window has been Closed, but we're then deleting
290 // immediately: don't leave dangling pointers.
291 wxPendingDelete
.DeleteObject(this);
293 // Just in case we've loaded a top-level window via LoadNativeDialog but
294 // we weren't a dialog class
295 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
297 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
299 // reset the dangling pointer our parent window may keep to us
302 if ( m_parent
->GetDefaultItem() == this )
304 m_parent
->SetDefaultItem(NULL
);
307 m_parent
->RemoveChild(this);
312 #endif // wxUSE_CARET
315 delete m_windowValidator
;
316 #endif // wxUSE_VALIDATORS
318 #if wxUSE_CONSTRAINTS
319 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
320 // at deleted windows as they delete themselves.
321 DeleteRelatedConstraints();
325 // This removes any dangling pointers to this window in other windows'
326 // constraintsInvolvedIn lists.
327 UnsetConstraints(m_constraints
);
328 delete m_constraints
;
329 m_constraints
= NULL
;
331 #endif // wxUSE_CONSTRAINTS
333 if ( m_containingSizer
)
334 m_containingSizer
->Detach( (wxWindow
*)this );
336 delete m_windowSizer
;
338 #if wxUSE_DRAG_AND_DROP
340 #endif // wxUSE_DRAG_AND_DROP
344 #endif // wxUSE_TOOLTIPS
346 #if wxUSE_ACCESSIBILITY
351 bool wxWindowBase::Destroy()
358 bool wxWindowBase::Close(bool force
)
360 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
361 event
.SetEventObject(this);
362 event
.SetCanVeto(!force
);
364 // return false if window wasn't closed because the application vetoed the
366 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
369 bool wxWindowBase::DestroyChildren()
371 wxWindowList::compatibility_iterator node
;
374 // we iterate until the list becomes empty
375 node
= GetChildren().GetFirst();
379 wxWindow
*child
= node
->GetData();
381 // note that we really want to call delete and not ->Destroy() here
382 // because we want to delete the child immediately, before we are
383 // deleted, and delayed deletion would result in problems as our (top
384 // level) child could outlive its parent
387 wxASSERT_MSG( !GetChildren().Find(child
),
388 wxT("child didn't remove itself using RemoveChild()") );
394 // ----------------------------------------------------------------------------
395 // size/position related methods
396 // ----------------------------------------------------------------------------
398 // centre the window with respect to its parent in either (or both) directions
399 void wxWindowBase::DoCentre(int dir
)
401 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
402 _T("this method only implements centering child windows") );
404 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
407 // fits the window around the children
408 void wxWindowBase::Fit()
410 if ( !GetChildren().empty() )
412 SetClientSize(GetBestSize());
414 //else: do nothing if we have no children
417 // fits virtual size (ie. scrolled area etc.) around children
418 void wxWindowBase::FitInside()
420 if ( GetChildren().GetCount() > 0 )
422 SetVirtualSize( GetBestVirtualSize() );
426 // On Mac, scrollbars are explicitly children.
428 static bool wxHasRealChildren(const wxWindowBase
* win
)
430 int realChildCount
= 0;
432 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
434 node
= node
->GetNext() )
436 wxWindow
*win
= node
->GetData();
437 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
440 return (realChildCount
> 0);
444 void wxWindowBase::InvalidateBestSize()
446 m_bestSizeCache
= wxDefaultSize
;
448 // parent's best size calculation may depend on its children's
449 // best sizes, so let's invalidate it as well to be safe
450 // (but don't influence other wxTLWs)
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 // ----------------------------------------------------------------------------
718 // show/hide/enable/disable the window
719 // ----------------------------------------------------------------------------
721 bool wxWindowBase::Show(bool show
)
723 if ( show
!= m_isShown
)
735 bool wxWindowBase::Enable(bool enable
)
737 if ( enable
!= m_isEnabled
)
739 m_isEnabled
= enable
;
748 // ----------------------------------------------------------------------------
750 // ----------------------------------------------------------------------------
752 bool wxWindowBase::IsTopLevel() const
757 // ----------------------------------------------------------------------------
758 // reparenting the window
759 // ----------------------------------------------------------------------------
761 void wxWindowBase::AddChild(wxWindowBase
*child
)
763 wxCHECK_RET( child
, wxT("can't add a NULL child") );
765 // this should never happen and it will lead to a crash later if it does
766 // because RemoveChild() will remove only one node from the children list
767 // and the other(s) one(s) will be left with dangling pointers in them
768 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
770 GetChildren().Append((wxWindow
*)child
);
771 child
->SetParent(this);
774 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
776 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
778 GetChildren().DeleteObject((wxWindow
*)child
);
779 child
->SetParent(NULL
);
782 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
784 wxWindow
*oldParent
= GetParent();
785 if ( newParent
== oldParent
)
791 // unlink this window from the existing parent.
794 oldParent
->RemoveChild(this);
798 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
801 // add it to the new one
804 newParent
->AddChild(this);
808 wxTopLevelWindows
.Append((wxWindow
*)this);
814 // ----------------------------------------------------------------------------
815 // event handler stuff
816 // ----------------------------------------------------------------------------
818 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
820 wxEvtHandler
*handlerOld
= GetEventHandler();
822 handler
->SetNextHandler(handlerOld
);
825 GetEventHandler()->SetPreviousHandler(handler
);
827 SetEventHandler(handler
);
830 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
832 wxEvtHandler
*handlerA
= GetEventHandler();
835 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
836 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
839 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
840 SetEventHandler(handlerB
);
845 handlerA
= (wxEvtHandler
*)NULL
;
852 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
854 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
856 wxEvtHandler
*handlerPrev
= NULL
,
857 *handlerCur
= GetEventHandler();
860 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
862 if ( handlerCur
== handler
)
866 handlerPrev
->SetNextHandler(handlerNext
);
870 SetEventHandler(handlerNext
);
875 handlerNext
->SetPreviousHandler ( handlerPrev
);
878 handler
->SetNextHandler(NULL
);
879 handler
->SetPreviousHandler(NULL
);
884 handlerPrev
= handlerCur
;
885 handlerCur
= handlerNext
;
888 wxFAIL_MSG( _T("where has the event handler gone?") );
893 // ----------------------------------------------------------------------------
895 // ----------------------------------------------------------------------------
897 void wxWindowBase::InheritAttributes()
899 const wxWindowBase
* const parent
= GetParent();
903 // we only inherit attributes which had been explicitly set for the parent
904 // which ensures that this only happens if the user really wants it and
905 // not by default which wouldn't make any sense in modern GUIs where the
906 // controls don't all use the same fonts (nor colours)
907 if ( parent
->m_inheritFont
&& !m_hasFont
)
908 SetFont(parent
->GetFont());
910 // in addition, there is a possibility to explicitly forbid inheriting
911 // colours at each class level by overriding ShouldInheritColours()
912 if ( ShouldInheritColours() )
914 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
915 SetForegroundColour(parent
->GetForegroundColour());
917 // inheriting (solid) background colour is wrong as it totally breaks
918 // any kind of themed backgrounds
920 // instead, the controls should use the same background as their parent
921 // (ideally by not drawing it at all)
923 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
924 SetBackgroundColour(parent
->GetBackgroundColour());
929 /* static */ wxVisualAttributes
930 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
932 // it is important to return valid values for all attributes from here,
933 // GetXXX() below rely on this
934 wxVisualAttributes attrs
;
935 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
936 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
938 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
939 // the usual background colour than wxSYS_COLOUR_BTNFACE.
940 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
941 // colour on other platforms.
943 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
944 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
946 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
951 wxColour
wxWindowBase::GetBackgroundColour() const
953 if ( !m_backgroundColour
.Ok() )
955 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
957 // get our default background colour
958 wxColour colBg
= GetDefaultAttributes().colBg
;
960 // we must return some valid colour to avoid redoing this every time
961 // and also to avoid surprizing the applications written for older
962 // wxWidgets versions where GetBackgroundColour() always returned
963 // something -- so give them something even if it doesn't make sense
964 // for this window (e.g. it has a themed background)
966 colBg
= GetClassDefaultAttributes().colBg
;
971 return m_backgroundColour
;
974 wxColour
wxWindowBase::GetForegroundColour() const
976 // logic is the same as above
977 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
979 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
981 wxColour colFg
= GetDefaultAttributes().colFg
;
984 colFg
= GetClassDefaultAttributes().colFg
;
989 return m_foregroundColour
;
992 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
994 if ( colour
== m_backgroundColour
)
997 m_hasBgCol
= colour
.Ok();
998 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
999 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1001 m_inheritBgCol
= m_hasBgCol
;
1002 m_backgroundColour
= colour
;
1003 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1007 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1009 if (colour
== m_foregroundColour
)
1012 m_hasFgCol
= colour
.Ok();
1013 m_inheritFgCol
= m_hasFgCol
;
1014 m_foregroundColour
= colour
;
1015 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1019 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1021 // setting an invalid cursor is ok, it means that we don't have any special
1023 if ( m_cursor
== cursor
)
1034 wxFont
wxWindowBase::GetFont() const
1036 // logic is the same as in GetBackgroundColour()
1039 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1041 wxFont font
= GetDefaultAttributes().font
;
1043 font
= GetClassDefaultAttributes().font
;
1051 bool wxWindowBase::SetFont(const wxFont
& font
)
1053 if ( font
== m_font
)
1060 m_hasFont
= font
.Ok();
1061 m_inheritFont
= m_hasFont
;
1063 InvalidateBestSize();
1070 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1072 m_hasCustomPalette
= true;
1075 // VZ: can anyone explain me what do we do here?
1076 wxWindowDC
d((wxWindow
*) this);
1080 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1082 wxWindow
*win
= (wxWindow
*)this;
1083 while ( win
&& !win
->HasCustomPalette() )
1085 win
= win
->GetParent();
1091 #endif // wxUSE_PALETTE
1094 void wxWindowBase::SetCaret(wxCaret
*caret
)
1105 wxASSERT_MSG( m_caret
->GetWindow() == this,
1106 wxT("caret should be created associated to this window") );
1109 #endif // wxUSE_CARET
1111 #if wxUSE_VALIDATORS
1112 // ----------------------------------------------------------------------------
1114 // ----------------------------------------------------------------------------
1116 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1118 if ( m_windowValidator
)
1119 delete m_windowValidator
;
1121 m_windowValidator
= (wxValidator
*)validator
.Clone();
1123 if ( m_windowValidator
)
1124 m_windowValidator
->SetWindow(this);
1126 #endif // wxUSE_VALIDATORS
1128 // ----------------------------------------------------------------------------
1129 // update region stuff
1130 // ----------------------------------------------------------------------------
1132 wxRect
wxWindowBase::GetUpdateClientRect() const
1134 wxRegion rgnUpdate
= GetUpdateRegion();
1135 rgnUpdate
.Intersect(GetClientRect());
1136 wxRect rectUpdate
= rgnUpdate
.GetBox();
1137 wxPoint ptOrigin
= GetClientAreaOrigin();
1138 rectUpdate
.x
-= ptOrigin
.x
;
1139 rectUpdate
.y
-= ptOrigin
.y
;
1144 bool wxWindowBase::IsExposed(int x
, int y
) const
1146 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1149 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1151 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1154 void wxWindowBase::ClearBackground()
1156 // wxGTK uses its own version, no need to add never used code
1158 wxClientDC
dc((wxWindow
*)this);
1159 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1160 dc
.SetBackground(brush
);
1165 // ----------------------------------------------------------------------------
1166 // find child window by id or name
1167 // ----------------------------------------------------------------------------
1169 wxWindow
*wxWindowBase::FindWindow(long id
) const
1171 if ( id
== m_windowId
)
1172 return (wxWindow
*)this;
1174 wxWindowBase
*res
= (wxWindow
*)NULL
;
1175 wxWindowList::compatibility_iterator node
;
1176 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1178 wxWindowBase
*child
= node
->GetData();
1179 res
= child
->FindWindow( id
);
1182 return (wxWindow
*)res
;
1185 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1187 if ( name
== m_windowName
)
1188 return (wxWindow
*)this;
1190 wxWindowBase
*res
= (wxWindow
*)NULL
;
1191 wxWindowList::compatibility_iterator node
;
1192 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1194 wxWindow
*child
= node
->GetData();
1195 res
= child
->FindWindow(name
);
1198 return (wxWindow
*)res
;
1202 // find any window by id or name or label: If parent is non-NULL, look through
1203 // children for a label or title matching the specified string. If NULL, look
1204 // through all top-level windows.
1206 // to avoid duplicating code we reuse the same helper function but with
1207 // different comparators
1209 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1210 const wxString
& label
, long id
);
1213 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1216 return win
->GetLabel() == label
;
1220 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1223 return win
->GetName() == label
;
1227 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1230 return win
->GetId() == id
;
1233 // recursive helper for the FindWindowByXXX() functions
1235 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1236 const wxString
& label
,
1238 wxFindWindowCmp cmp
)
1242 // see if this is the one we're looking for
1243 if ( (*cmp
)(parent
, label
, id
) )
1244 return (wxWindow
*)parent
;
1246 // It wasn't, so check all its children
1247 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1249 node
= node
->GetNext() )
1251 // recursively check each child
1252 wxWindow
*win
= (wxWindow
*)node
->GetData();
1253 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1263 // helper for FindWindowByXXX()
1265 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1266 const wxString
& label
,
1268 wxFindWindowCmp cmp
)
1272 // just check parent and all its children
1273 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1276 // start at very top of wx's windows
1277 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1279 node
= node
->GetNext() )
1281 // recursively check each window & its children
1282 wxWindow
*win
= node
->GetData();
1283 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1293 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1295 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1300 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1302 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1306 // fall back to the label
1307 win
= FindWindowByLabel(title
, parent
);
1315 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1317 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1320 // ----------------------------------------------------------------------------
1321 // dialog oriented functions
1322 // ----------------------------------------------------------------------------
1324 void wxWindowBase::MakeModal(bool modal
)
1326 // Disable all other windows
1329 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1332 wxWindow
*win
= node
->GetData();
1334 win
->Enable(!modal
);
1336 node
= node
->GetNext();
1341 bool wxWindowBase::Validate()
1343 #if wxUSE_VALIDATORS
1344 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1346 wxWindowList::compatibility_iterator node
;
1347 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1349 wxWindowBase
*child
= node
->GetData();
1350 wxValidator
*validator
= child
->GetValidator();
1351 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1356 if ( recurse
&& !child
->Validate() )
1361 #endif // wxUSE_VALIDATORS
1366 bool wxWindowBase::TransferDataToWindow()
1368 #if wxUSE_VALIDATORS
1369 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1371 wxWindowList::compatibility_iterator node
;
1372 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1374 wxWindowBase
*child
= node
->GetData();
1375 wxValidator
*validator
= child
->GetValidator();
1376 if ( validator
&& !validator
->TransferToWindow() )
1378 wxLogWarning(_("Could not transfer data to window"));
1380 wxLog::FlushActive();
1388 if ( !child
->TransferDataToWindow() )
1390 // warning already given
1395 #endif // wxUSE_VALIDATORS
1400 bool wxWindowBase::TransferDataFromWindow()
1402 #if wxUSE_VALIDATORS
1403 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1405 wxWindowList::compatibility_iterator node
;
1406 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1408 wxWindow
*child
= node
->GetData();
1409 wxValidator
*validator
= child
->GetValidator();
1410 if ( validator
&& !validator
->TransferFromWindow() )
1412 // nop warning here because the application is supposed to give
1413 // one itself - we don't know here what might have gone wrongly
1420 if ( !child
->TransferDataFromWindow() )
1422 // warning already given
1427 #endif // wxUSE_VALIDATORS
1432 void wxWindowBase::InitDialog()
1434 wxInitDialogEvent
event(GetId());
1435 event
.SetEventObject( this );
1436 GetEventHandler()->ProcessEvent(event
);
1439 // ----------------------------------------------------------------------------
1440 // context-sensitive help support
1441 // ----------------------------------------------------------------------------
1445 // associate this help text with this window
1446 void wxWindowBase::SetHelpText(const wxString
& text
)
1448 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1451 helpProvider
->AddHelp(this, text
);
1455 // associate this help text with all windows with the same id as this
1457 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1459 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1462 helpProvider
->AddHelp(GetId(), text
);
1466 // get the help string associated with this window (may be empty)
1467 wxString
wxWindowBase::GetHelpText() 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
->ShowHelp(this) )
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
)
1524 m_tooltip
= tooltip
;
1527 #endif // wxUSE_TOOLTIPS
1529 // ----------------------------------------------------------------------------
1530 // constraints and sizers
1531 // ----------------------------------------------------------------------------
1533 #if wxUSE_CONSTRAINTS
1535 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1537 if ( m_constraints
)
1539 UnsetConstraints(m_constraints
);
1540 delete m_constraints
;
1542 m_constraints
= constraints
;
1543 if ( m_constraints
)
1545 // Make sure other windows know they're part of a 'meaningful relationship'
1546 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1547 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1548 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1549 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1550 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1551 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1552 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1553 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1554 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1555 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1556 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1557 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1558 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1559 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1560 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1561 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1565 // This removes any dangling pointers to this window in other windows'
1566 // constraintsInvolvedIn lists.
1567 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1571 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1572 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1573 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1574 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1575 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1576 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1577 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1578 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1579 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1580 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1581 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1582 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1583 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1584 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1585 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1586 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1590 // Back-pointer to other windows we're involved with, so if we delete this
1591 // window, we must delete any constraints we're involved with.
1592 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1594 if ( !m_constraintsInvolvedIn
)
1595 m_constraintsInvolvedIn
= new wxWindowList
;
1596 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1597 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1600 // REMOVE back-pointer to other windows we're involved with.
1601 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1603 if ( m_constraintsInvolvedIn
)
1604 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1607 // Reset any constraints that mention this window
1608 void wxWindowBase::DeleteRelatedConstraints()
1610 if ( m_constraintsInvolvedIn
)
1612 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1615 wxWindow
*win
= node
->GetData();
1616 wxLayoutConstraints
*constr
= win
->GetConstraints();
1618 // Reset any constraints involving this window
1621 constr
->left
.ResetIfWin(this);
1622 constr
->top
.ResetIfWin(this);
1623 constr
->right
.ResetIfWin(this);
1624 constr
->bottom
.ResetIfWin(this);
1625 constr
->width
.ResetIfWin(this);
1626 constr
->height
.ResetIfWin(this);
1627 constr
->centreX
.ResetIfWin(this);
1628 constr
->centreY
.ResetIfWin(this);
1631 wxWindowList::compatibility_iterator next
= node
->GetNext();
1632 m_constraintsInvolvedIn
->Erase(node
);
1636 delete m_constraintsInvolvedIn
;
1637 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1641 #endif // wxUSE_CONSTRAINTS
1643 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1645 if ( sizer
== m_windowSizer
)
1649 delete m_windowSizer
;
1651 m_windowSizer
= sizer
;
1653 SetAutoLayout( sizer
!= NULL
);
1656 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1658 SetSizer( sizer
, deleteOld
);
1659 sizer
->SetSizeHints( (wxWindow
*) this );
1663 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1665 // adding a window to a sizer twice is going to result in fatal and
1666 // hard to debug problems later because when deleting the second
1667 // associated wxSizerItem we're going to dereference a dangling
1668 // pointer; so try to detect this as early as possible
1669 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1670 _T("Adding a window to the same sizer twice?") );
1672 m_containingSizer
= sizer
;
1675 #if wxUSE_CONSTRAINTS
1677 void wxWindowBase::SatisfyConstraints()
1679 wxLayoutConstraints
*constr
= GetConstraints();
1680 bool wasOk
= constr
&& constr
->AreSatisfied();
1682 ResetConstraints(); // Mark all constraints as unevaluated
1686 // if we're a top level panel (i.e. our parent is frame/dialog), our
1687 // own constraints will never be satisfied any more unless we do it
1691 while ( noChanges
> 0 )
1693 LayoutPhase1(&noChanges
);
1697 LayoutPhase2(&noChanges
);
1700 #endif // wxUSE_CONSTRAINTS
1702 bool wxWindowBase::Layout()
1704 // If there is a sizer, use it instead of the constraints
1708 GetVirtualSize(&w
, &h
);
1709 GetSizer()->SetDimension( 0, 0, w
, h
);
1711 #if wxUSE_CONSTRAINTS
1714 SatisfyConstraints(); // Find the right constraints values
1715 SetConstraintSizes(); // Recursively set the real window sizes
1722 #if wxUSE_CONSTRAINTS
1724 // first phase of the constraints evaluation: set our own constraints
1725 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1727 wxLayoutConstraints
*constr
= GetConstraints();
1729 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1732 // second phase: set the constraints for our children
1733 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1740 // Layout grand children
1746 // Do a phase of evaluating child constraints
1747 bool wxWindowBase::DoPhase(int phase
)
1749 // the list containing the children for which the constraints are already
1751 wxWindowList succeeded
;
1753 // the max number of iterations we loop before concluding that we can't set
1755 static const int maxIterations
= 500;
1757 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1761 // loop over all children setting their constraints
1762 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1764 node
= node
->GetNext() )
1766 wxWindow
*child
= node
->GetData();
1767 if ( child
->IsTopLevel() )
1769 // top level children are not inside our client area
1773 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1775 // this one is either already ok or nothing we can do about it
1779 int tempNoChanges
= 0;
1780 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1781 : child
->LayoutPhase2(&tempNoChanges
);
1782 noChanges
+= tempNoChanges
;
1786 succeeded
.Append(child
);
1792 // constraints are set
1800 void wxWindowBase::ResetConstraints()
1802 wxLayoutConstraints
*constr
= GetConstraints();
1805 constr
->left
.SetDone(false);
1806 constr
->top
.SetDone(false);
1807 constr
->right
.SetDone(false);
1808 constr
->bottom
.SetDone(false);
1809 constr
->width
.SetDone(false);
1810 constr
->height
.SetDone(false);
1811 constr
->centreX
.SetDone(false);
1812 constr
->centreY
.SetDone(false);
1815 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1818 wxWindow
*win
= node
->GetData();
1819 if ( !win
->IsTopLevel() )
1820 win
->ResetConstraints();
1821 node
= node
->GetNext();
1825 // Need to distinguish between setting the 'fake' size for windows and sizers,
1826 // and setting the real values.
1827 void wxWindowBase::SetConstraintSizes(bool recurse
)
1829 wxLayoutConstraints
*constr
= GetConstraints();
1830 if ( constr
&& constr
->AreSatisfied() )
1832 int x
= constr
->left
.GetValue();
1833 int y
= constr
->top
.GetValue();
1834 int w
= constr
->width
.GetValue();
1835 int h
= constr
->height
.GetValue();
1837 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1838 (constr
->height
.GetRelationship() != wxAsIs
) )
1840 SetSize(x
, y
, w
, h
);
1844 // If we don't want to resize this window, just move it...
1850 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1851 GetClassInfo()->GetClassName(),
1857 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1860 wxWindow
*win
= node
->GetData();
1861 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1862 win
->SetConstraintSizes();
1863 node
= node
->GetNext();
1868 // Only set the size/position of the constraint (if any)
1869 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1871 wxLayoutConstraints
*constr
= GetConstraints();
1874 if ( x
!= wxDefaultCoord
)
1876 constr
->left
.SetValue(x
);
1877 constr
->left
.SetDone(true);
1879 if ( y
!= wxDefaultCoord
)
1881 constr
->top
.SetValue(y
);
1882 constr
->top
.SetDone(true);
1884 if ( w
!= wxDefaultCoord
)
1886 constr
->width
.SetValue(w
);
1887 constr
->width
.SetDone(true);
1889 if ( h
!= wxDefaultCoord
)
1891 constr
->height
.SetValue(h
);
1892 constr
->height
.SetDone(true);
1897 void wxWindowBase::MoveConstraint(int x
, int y
)
1899 wxLayoutConstraints
*constr
= GetConstraints();
1902 if ( x
!= wxDefaultCoord
)
1904 constr
->left
.SetValue(x
);
1905 constr
->left
.SetDone(true);
1907 if ( y
!= wxDefaultCoord
)
1909 constr
->top
.SetValue(y
);
1910 constr
->top
.SetDone(true);
1915 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1917 wxLayoutConstraints
*constr
= GetConstraints();
1920 *w
= constr
->width
.GetValue();
1921 *h
= constr
->height
.GetValue();
1927 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1929 wxLayoutConstraints
*constr
= GetConstraints();
1932 *w
= constr
->width
.GetValue();
1933 *h
= constr
->height
.GetValue();
1936 GetClientSize(w
, h
);
1939 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1941 wxLayoutConstraints
*constr
= GetConstraints();
1944 *x
= constr
->left
.GetValue();
1945 *y
= constr
->top
.GetValue();
1951 #endif // wxUSE_CONSTRAINTS
1953 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1955 // don't do it for the dialogs/frames - they float independently of their
1957 if ( !IsTopLevel() )
1959 wxWindow
*parent
= GetParent();
1960 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1962 wxPoint
pt(parent
->GetClientAreaOrigin());
1969 // ----------------------------------------------------------------------------
1970 // do Update UI processing for child controls
1971 // ----------------------------------------------------------------------------
1973 void wxWindowBase::UpdateWindowUI(long flags
)
1975 wxUpdateUIEvent
event(GetId());
1976 event
.SetEventObject(this);
1978 if ( GetEventHandler()->ProcessEvent(event
) )
1980 DoUpdateWindowUI(event
);
1983 if (flags
& wxUPDATE_UI_RECURSE
)
1985 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1988 wxWindow
* child
= (wxWindow
*) node
->GetData();
1989 child
->UpdateWindowUI(flags
);
1990 node
= node
->GetNext();
1995 // do the window-specific processing after processing the update event
1996 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
1998 if ( event
.GetSetEnabled() )
1999 Enable(event
.GetEnabled());
2001 if ( event
.GetSetShown() )
2002 Show(event
.GetShown());
2006 // call internal idle recursively
2007 // may be obsolete (wait until OnIdle scheme stabilises)
2008 void wxWindowBase::ProcessInternalIdle()
2012 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2015 wxWindow
*child
= node
->GetData();
2016 child
->ProcessInternalIdle();
2017 node
= node
->GetNext();
2022 // ----------------------------------------------------------------------------
2023 // dialog units translations
2024 // ----------------------------------------------------------------------------
2026 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2028 int charWidth
= GetCharWidth();
2029 int charHeight
= GetCharHeight();
2030 wxPoint pt2
= wxDefaultPosition
;
2031 if (pt
.x
!= wxDefaultCoord
)
2032 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2033 if (pt
.y
!= wxDefaultCoord
)
2034 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2039 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2041 int charWidth
= GetCharWidth();
2042 int charHeight
= GetCharHeight();
2043 wxPoint pt2
= wxDefaultPosition
;
2044 if (pt
.x
!= wxDefaultCoord
)
2045 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2046 if (pt
.y
!= wxDefaultCoord
)
2047 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2052 // ----------------------------------------------------------------------------
2054 // ----------------------------------------------------------------------------
2056 // propagate the colour change event to the subwindows
2057 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2059 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2062 // Only propagate to non-top-level windows
2063 wxWindow
*win
= node
->GetData();
2064 if ( !win
->IsTopLevel() )
2066 wxSysColourChangedEvent event2
;
2067 event
.SetEventObject(win
);
2068 win
->GetEventHandler()->ProcessEvent(event2
);
2071 node
= node
->GetNext();
2077 // the default action is to populate dialog with data when it's created,
2078 // and nudge the UI into displaying itself correctly in case
2079 // we've turned the wxUpdateUIEvents frequency down low.
2080 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2082 TransferDataToWindow();
2084 // Update the UI at this point
2085 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2088 // methods for drawing the sizers in a visible way
2091 static void DrawSizers(wxWindowBase
*win
);
2093 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2095 wxClientDC
dc((wxWindow
*)win
);
2096 dc
.SetPen(*wxRED_PEN
);
2097 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2098 dc
.DrawRectangle(rect
.Deflate(1, 1));
2101 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2103 const wxSizerItemList
& items
= sizer
->GetChildren();
2104 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2109 wxSizerItem
*item
= *i
;
2110 if ( item
->IsSizer() )
2112 DrawBorder(win
, item
->GetRect().Deflate(2));
2113 DrawSizer(win
, item
->GetSizer());
2115 else if ( item
->IsSpacer() )
2117 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2119 else if ( item
->IsWindow() )
2121 DrawSizers(item
->GetWindow());
2126 static void DrawSizers(wxWindowBase
*win
)
2128 wxSizer
*sizer
= win
->GetSizer();
2131 DrawBorder(win
, win
->GetClientSize());
2132 DrawSizer(win
, sizer
);
2134 else // no sizer, still recurse into the children
2136 const wxWindowList
& children
= win
->GetChildren();
2137 for ( wxWindowList::const_iterator i
= children
.begin(),
2138 end
= children
.end();
2147 #endif // __WXDEBUG__
2149 // process special middle clicks
2150 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2152 if ( event
.ControlDown() && event
.AltDown() )
2155 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2156 if ( event
.ShiftDown() )
2161 #endif // __WXDEBUG__
2164 // don't translate these strings
2167 #ifdef __WXUNIVERSAL__
2169 #endif // __WXUNIVERSAL__
2171 switch ( wxGetOsVersion() )
2173 case wxMOTIF_X
: port
+= _T("Motif"); break;
2175 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
2176 case wxBEOS
: port
+= _T("BeOS"); break;
2180 case wxGTK_BEOS
: port
+= _T("GTK"); break;
2186 case wxWIN386
: port
+= _T("MS Windows"); break;
2190 case wxMGL_OS2
: port
+= _T("MGL"); break;
2192 case wxOS2_PM
: port
+= _T("OS/2"); break;
2193 case wxPALMOS
: port
+= _T("Palm OS"); break;
2194 case wxWINDOWS_CE
: port
+= _T("Windows CE (generic)"); break;
2195 case wxWINDOWS_POCKETPC
: port
+= _T("Windows CE PocketPC"); break;
2196 case wxWINDOWS_SMARTPHONE
: port
+= _T("Windows CE Smartphone"); break;
2197 default: port
+= _T("unknown"); break;
2200 wxMessageBox(wxString::Format(
2202 " wxWidgets Library (%s port)\nVersion %d.%d.%d%s%s, compiled at %s %s%s\n Copyright (c) 1995-2006 wxWidgets team"
2221 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()
2226 _T("wxWidgets information"),
2227 wxICON_INFORMATION
| wxOK
,
2231 #endif // wxUSE_MSGDLG
2237 // ----------------------------------------------------------------------------
2239 // ----------------------------------------------------------------------------
2241 #if wxUSE_ACCESSIBILITY
2242 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2244 if (m_accessible
&& (accessible
!= m_accessible
))
2245 delete m_accessible
;
2246 m_accessible
= accessible
;
2248 m_accessible
->SetWindow((wxWindow
*) this);
2251 // Returns the accessible object, creating if necessary.
2252 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2255 m_accessible
= CreateAccessible();
2256 return m_accessible
;
2259 // Override to create a specific accessible object.
2260 wxAccessible
* wxWindowBase::CreateAccessible()
2262 return new wxWindowAccessible((wxWindow
*) this);
2267 // ----------------------------------------------------------------------------
2268 // list classes implementation
2269 // ----------------------------------------------------------------------------
2273 #include "wx/listimpl.cpp"
2274 WX_DEFINE_LIST(wxWindowList
)
2278 void wxWindowListNode::DeleteData()
2280 delete (wxWindow
*)GetData();
2285 // ----------------------------------------------------------------------------
2287 // ----------------------------------------------------------------------------
2289 wxBorder
wxWindowBase::GetBorder(long flags
) const
2291 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2292 if ( border
== wxBORDER_DEFAULT
)
2294 border
= GetDefaultBorder();
2300 wxBorder
wxWindowBase::GetDefaultBorder() const
2302 return wxBORDER_NONE
;
2305 // ----------------------------------------------------------------------------
2307 // ----------------------------------------------------------------------------
2309 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2311 // here we just check if the point is inside the window or not
2313 // check the top and left border first
2314 bool outside
= x
< 0 || y
< 0;
2317 // check the right and bottom borders too
2318 wxSize size
= GetSize();
2319 outside
= x
>= size
.x
|| y
>= size
.y
;
2322 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2325 // ----------------------------------------------------------------------------
2327 // ----------------------------------------------------------------------------
2329 struct WXDLLEXPORT wxWindowNext
2333 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2335 void wxWindowBase::CaptureMouse()
2337 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2339 wxWindow
*winOld
= GetCapture();
2342 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2345 wxWindowNext
*item
= new wxWindowNext
;
2347 item
->next
= ms_winCaptureNext
;
2348 ms_winCaptureNext
= item
;
2350 //else: no mouse capture to save
2355 void wxWindowBase::ReleaseMouse()
2357 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2359 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2363 if ( ms_winCaptureNext
)
2365 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2367 wxWindowNext
*item
= ms_winCaptureNext
;
2368 ms_winCaptureNext
= item
->next
;
2371 //else: stack is empty, no previous capture
2373 wxLogTrace(_T("mousecapture"),
2374 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2381 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2382 int WXUNUSED(modifiers
),
2383 int WXUNUSED(keycode
))
2389 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2395 #endif // wxUSE_HOTKEY
2397 void wxWindowBase::SendDestroyEvent()
2399 wxWindowDestroyEvent event
;
2400 event
.SetEventObject(this);
2401 event
.SetId(GetId());
2402 GetEventHandler()->ProcessEvent(event
);
2405 // ----------------------------------------------------------------------------
2407 // ----------------------------------------------------------------------------
2409 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2411 #if wxUSE_VALIDATORS
2412 // Can only use the validator of the window which
2413 // is receiving the event
2414 if ( event
.GetEventObject() == this )
2416 wxValidator
*validator
= GetValidator();
2417 if ( validator
&& validator
->ProcessEvent(event
) )
2422 #endif // wxUSE_VALIDATORS
2427 bool wxWindowBase::TryParent(wxEvent
& event
)
2429 // carry on up the parent-child hierarchy if the propagation count hasn't
2431 if ( event
.ShouldPropagate() )
2433 // honour the requests to stop propagation at this window: this is
2434 // used by the dialogs, for example, to prevent processing the events
2435 // from the dialog controls in the parent frame which rarely, if ever,
2437 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2439 wxWindow
*parent
= GetParent();
2440 if ( parent
&& !parent
->IsBeingDeleted() )
2442 wxPropagateOnce
propagateOnce(event
);
2444 return parent
->GetEventHandler()->ProcessEvent(event
);
2449 return wxEvtHandler::TryParent(event
);
2452 // ----------------------------------------------------------------------------
2453 // keyboard navigation
2454 // ----------------------------------------------------------------------------
2456 // Navigates in the specified direction.
2457 bool wxWindowBase::Navigate(int flags
)
2459 wxNavigationKeyEvent eventNav
;
2460 eventNav
.SetFlags(flags
);
2461 eventNav
.SetEventObject(this);
2462 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2469 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2471 // check that we're not a top level window
2472 wxCHECK_RET( GetParent(),
2473 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2475 // detect the special case when we have nothing to do anyhow and when the
2476 // code below wouldn't work
2480 // find the target window in the siblings list
2481 wxWindowList
& siblings
= GetParent()->GetChildren();
2482 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2483 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2485 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2486 // can't just move the node around
2487 wxWindow
*self
= (wxWindow
*)this;
2488 siblings
.DeleteObject(self
);
2489 if ( move
== MoveAfter
)
2496 siblings
.Insert(i
, self
);
2498 else // MoveAfter and win was the last sibling
2500 siblings
.Append(self
);
2504 // ----------------------------------------------------------------------------
2506 // ----------------------------------------------------------------------------
2508 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2510 wxWindowBase
*win
= DoFindFocus();
2511 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2514 // ----------------------------------------------------------------------------
2516 // ----------------------------------------------------------------------------
2518 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2520 while ( win
&& !win
->IsTopLevel() )
2521 win
= win
->GetParent();
2526 #if wxUSE_ACCESSIBILITY
2527 // ----------------------------------------------------------------------------
2528 // accessible object for windows
2529 // ----------------------------------------------------------------------------
2531 // Can return either a child object, or an integer
2532 // representing the child element, starting from 1.
2533 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2535 wxASSERT( GetWindow() != NULL
);
2539 return wxACC_NOT_IMPLEMENTED
;
2542 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2543 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2545 wxASSERT( GetWindow() != NULL
);
2549 wxWindow
* win
= NULL
;
2556 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2558 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2565 rect
= win
->GetRect();
2566 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2567 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2571 return wxACC_NOT_IMPLEMENTED
;
2574 // Navigates from fromId to toId/toObject.
2575 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2576 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2578 wxASSERT( GetWindow() != NULL
);
2584 case wxNAVDIR_FIRSTCHILD
:
2586 if (GetWindow()->GetChildren().GetCount() == 0)
2588 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2589 *toObject
= childWindow
->GetOrCreateAccessible();
2593 case wxNAVDIR_LASTCHILD
:
2595 if (GetWindow()->GetChildren().GetCount() == 0)
2597 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2598 *toObject
= childWindow
->GetOrCreateAccessible();
2602 case wxNAVDIR_RIGHT
:
2606 wxWindowList::compatibility_iterator node
=
2607 wxWindowList::compatibility_iterator();
2610 // Can't navigate to sibling of this window
2611 // if we're a top-level window.
2612 if (!GetWindow()->GetParent())
2613 return wxACC_NOT_IMPLEMENTED
;
2615 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2619 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2620 node
= GetWindow()->GetChildren().Item(fromId
-1);
2623 if (node
&& node
->GetNext())
2625 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2626 *toObject
= nextWindow
->GetOrCreateAccessible();
2634 case wxNAVDIR_PREVIOUS
:
2636 wxWindowList::compatibility_iterator node
=
2637 wxWindowList::compatibility_iterator();
2640 // Can't navigate to sibling of this window
2641 // if we're a top-level window.
2642 if (!GetWindow()->GetParent())
2643 return wxACC_NOT_IMPLEMENTED
;
2645 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2649 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2650 node
= GetWindow()->GetChildren().Item(fromId
-1);
2653 if (node
&& node
->GetPrevious())
2655 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2656 *toObject
= previousWindow
->GetOrCreateAccessible();
2664 return wxACC_NOT_IMPLEMENTED
;
2667 // Gets the name of the specified object.
2668 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2670 wxASSERT( GetWindow() != NULL
);
2676 // If a child, leave wxWidgets to call the function on the actual
2679 return wxACC_NOT_IMPLEMENTED
;
2681 // This will eventually be replaced by specialised
2682 // accessible classes, one for each kind of wxWidgets
2683 // control or window.
2685 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2686 title
= ((wxButton
*) GetWindow())->GetLabel();
2689 title
= GetWindow()->GetName();
2697 return wxACC_NOT_IMPLEMENTED
;
2700 // Gets the number of children.
2701 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2703 wxASSERT( GetWindow() != NULL
);
2707 *childId
= (int) GetWindow()->GetChildren().GetCount();
2711 // Gets the specified child (starting from 1).
2712 // If *child is NULL and return value is wxACC_OK,
2713 // this means that the child is a simple element and
2714 // not an accessible object.
2715 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2717 wxASSERT( GetWindow() != NULL
);
2727 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2730 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2731 *child
= childWindow
->GetOrCreateAccessible();
2738 // Gets the parent, or NULL.
2739 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2741 wxASSERT( GetWindow() != NULL
);
2745 wxWindow
* parentWindow
= GetWindow()->GetParent();
2753 *parent
= parentWindow
->GetOrCreateAccessible();
2761 // Performs the default action. childId is 0 (the action for this object)
2762 // or > 0 (the action for a child).
2763 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2764 // window (e.g. an edit control).
2765 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2767 wxASSERT( GetWindow() != NULL
);
2771 return wxACC_NOT_IMPLEMENTED
;
2774 // Gets the default action for this object (0) or > 0 (the action for a child).
2775 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2776 // string if there is no action.
2777 // The retrieved string describes the action that is performed on an object,
2778 // not what the object does as a result. For example, a toolbar button that prints
2779 // a document has a default action of "Press" rather than "Prints the current document."
2780 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2782 wxASSERT( GetWindow() != NULL
);
2786 return wxACC_NOT_IMPLEMENTED
;
2789 // Returns the description for this object or a child.
2790 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2792 wxASSERT( GetWindow() != NULL
);
2796 wxString
ht(GetWindow()->GetHelpText());
2802 return wxACC_NOT_IMPLEMENTED
;
2805 // Returns help text for this object or a child, similar to tooltip text.
2806 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2808 wxASSERT( GetWindow() != NULL
);
2812 wxString
ht(GetWindow()->GetHelpText());
2818 return wxACC_NOT_IMPLEMENTED
;
2821 // Returns the keyboard shortcut for this object or child.
2822 // Return e.g. ALT+K
2823 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2825 wxASSERT( GetWindow() != NULL
);
2829 return wxACC_NOT_IMPLEMENTED
;
2832 // Returns a role constant.
2833 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2835 wxASSERT( GetWindow() != NULL
);
2839 // If a child, leave wxWidgets to call the function on the actual
2842 return wxACC_NOT_IMPLEMENTED
;
2844 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2845 return wxACC_NOT_IMPLEMENTED
;
2847 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2848 return wxACC_NOT_IMPLEMENTED
;
2851 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2852 return wxACC_NOT_IMPLEMENTED
;
2855 //*role = wxROLE_SYSTEM_CLIENT;
2856 *role
= wxROLE_SYSTEM_CLIENT
;
2860 return wxACC_NOT_IMPLEMENTED
;
2864 // Returns a state constant.
2865 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2867 wxASSERT( GetWindow() != NULL
);
2871 // If a child, leave wxWidgets to call the function on the actual
2874 return wxACC_NOT_IMPLEMENTED
;
2876 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2877 return wxACC_NOT_IMPLEMENTED
;
2880 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2881 return wxACC_NOT_IMPLEMENTED
;
2884 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2885 return wxACC_NOT_IMPLEMENTED
;
2892 return wxACC_NOT_IMPLEMENTED
;
2896 // Returns a localized string representing the value for the object
2898 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2900 wxASSERT( GetWindow() != NULL
);
2904 return wxACC_NOT_IMPLEMENTED
;
2907 // Selects the object or child.
2908 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2910 wxASSERT( GetWindow() != NULL
);
2914 return wxACC_NOT_IMPLEMENTED
;
2917 // Gets the window with the keyboard focus.
2918 // If childId is 0 and child is NULL, no object in
2919 // this subhierarchy has the focus.
2920 // If this object has the focus, child should be 'this'.
2921 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2923 wxASSERT( GetWindow() != NULL
);
2927 return wxACC_NOT_IMPLEMENTED
;
2930 // Gets a variant representing the selected children
2932 // Acceptable values:
2933 // - a null variant (IsNull() returns true)
2934 // - a list variant (GetType() == wxT("list")
2935 // - an integer representing the selected child element,
2936 // or 0 if this object is selected (GetType() == wxT("long")
2937 // - a "void*" pointer to a wxAccessible child object
2938 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2940 wxASSERT( GetWindow() != NULL
);
2944 return wxACC_NOT_IMPLEMENTED
;
2947 #endif // wxUSE_ACCESSIBILITY