1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/window.cpp
3 // Purpose: common (to all ports) wxWindow functions
4 // Author: Julian Smart, Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/string.h"
32 #include "wx/window.h"
33 #include "wx/control.h"
34 #include "wx/checkbox.h"
35 #include "wx/radiobut.h"
36 #include "wx/statbox.h"
37 #include "wx/textctrl.h"
38 #include "wx/settings.h"
39 #include "wx/dialog.h"
40 #include "wx/msgdlg.h"
41 #include "wx/statusbr.h"
42 #include "wx/toolbar.h"
43 #include "wx/dcclient.h"
44 #include "wx/scrolbar.h"
45 #include "wx/layout.h"
49 #if wxUSE_DRAG_AND_DROP
51 #endif // wxUSE_DRAG_AND_DROP
53 #if wxUSE_ACCESSIBILITY
54 #include "wx/access.h"
58 #include "wx/cshelp.h"
62 #include "wx/tooltip.h"
63 #endif // wxUSE_TOOLTIPS
69 #if wxUSE_SYSTEM_OPTIONS
70 #include "wx/sysopt.h"
73 // For reporting compile- and runtime version of GTK+ in the ctrl+alt+mclick dialog.
74 // The gtk includes don't pull any other headers in, at least not on my system - MR
77 #include <gtk/gtkversion.h>
79 #include <gtk/gtkfeatures.h>
81 extern const unsigned int gtk_major_version
;
82 extern const unsigned int gtk_minor_version
;
83 extern const unsigned int gtk_micro_version
;
86 #include "wx/platinfo.h"
89 WXDLLIMPEXP_DATA_CORE(wxWindowList
) wxTopLevelWindows
;
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
95 #if defined(__WXPALMOS__)
96 int wxWindowBase::ms_lastControlId
= 32767;
97 #elif defined(__WXPM__)
98 int wxWindowBase::ms_lastControlId
= 2000;
100 int wxWindowBase::ms_lastControlId
= -200;
103 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
105 // ----------------------------------------------------------------------------
107 // ----------------------------------------------------------------------------
109 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
110 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
111 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
112 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
115 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
120 // ============================================================================
121 // implementation of the common functionality of the wxWindow class
122 // ============================================================================
124 // ----------------------------------------------------------------------------
126 // ----------------------------------------------------------------------------
128 // the default initialization
129 wxWindowBase::wxWindowBase()
131 // no window yet, no parent nor children
132 m_parent
= (wxWindow
*)NULL
;
133 m_windowId
= wxID_ANY
;
135 // no constraints on the minimal window size
137 m_maxWidth
= wxDefaultCoord
;
139 m_maxHeight
= wxDefaultCoord
;
141 // invalidiated cache value
142 m_bestSizeCache
= wxDefaultSize
;
144 // window are created enabled and visible by default
148 // the default event handler is just this window
149 m_eventHandler
= this;
153 m_windowValidator
= (wxValidator
*) NULL
;
154 #endif // wxUSE_VALIDATORS
156 // the colours/fonts are default for now, so leave m_font,
157 // m_backgroundColour and m_foregroundColour uninitialized and set those
163 m_inheritFont
= false;
169 m_backgroundStyle
= wxBG_STYLE_SYSTEM
;
171 #if wxUSE_CONSTRAINTS
172 // no constraints whatsoever
173 m_constraints
= (wxLayoutConstraints
*) NULL
;
174 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
175 #endif // wxUSE_CONSTRAINTS
177 m_windowSizer
= (wxSizer
*) NULL
;
178 m_containingSizer
= (wxSizer
*) NULL
;
179 m_autoLayout
= false;
181 #if wxUSE_DRAG_AND_DROP
182 m_dropTarget
= (wxDropTarget
*)NULL
;
183 #endif // wxUSE_DRAG_AND_DROP
186 m_tooltip
= (wxToolTip
*)NULL
;
187 #endif // wxUSE_TOOLTIPS
190 m_caret
= (wxCaret
*)NULL
;
191 #endif // wxUSE_CARET
194 m_hasCustomPalette
= false;
195 #endif // wxUSE_PALETTE
197 #if wxUSE_ACCESSIBILITY
201 m_virtualSize
= wxDefaultSize
;
203 m_scrollHelper
= (wxScrollHelper
*) NULL
;
206 m_maxVirtualWidth
= wxDefaultCoord
;
208 m_maxVirtualHeight
= wxDefaultCoord
;
210 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
211 #if wxUSE_SYSTEM_OPTIONS
212 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
214 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
218 // Whether we're using the current theme for this window (wxGTK only for now)
219 m_themeEnabled
= false;
221 // VZ: this one shouldn't exist...
222 m_isBeingDeleted
= false;
225 // common part of window creation process
226 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
228 const wxPoint
& WXUNUSED(pos
),
229 const wxSize
& WXUNUSED(size
),
231 const wxValidator
& wxVALIDATOR_PARAM(validator
),
232 const wxString
& name
)
235 // wxGTK doesn't allow to create controls with static box as the parent so
236 // this will result in a crash when the program is ported to wxGTK so warn
239 // if you get this assert, the correct solution is to create the controls
240 // as siblings of the static box
241 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
242 _T("wxStaticBox can't be used as a window parent!") );
243 #endif // wxUSE_STATBOX
245 // ids are limited to 16 bits under MSW so if you care about portability,
246 // it's not a good idea to use ids out of this range (and negative ids are
247 // reserved for wxWidgets own usage)
248 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
249 _T("invalid id value") );
251 // generate a new id if the user doesn't care about it
252 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
255 SetWindowStyleFlag(style
);
259 SetValidator(validator
);
260 #endif // wxUSE_VALIDATORS
262 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
263 // have it too - like this it's possible to set it only in the top level
264 // dialog/frame and all children will inherit it by defult
265 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
267 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
273 // ----------------------------------------------------------------------------
275 // ----------------------------------------------------------------------------
278 wxWindowBase::~wxWindowBase()
280 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
282 // FIXME if these 2 cases result from programming errors in the user code
283 // we should probably assert here instead of silently fixing them
285 // Just in case the window has been Closed, but we're then deleting
286 // immediately: don't leave dangling pointers.
287 wxPendingDelete
.DeleteObject(this);
289 // Just in case we've loaded a top-level window via LoadNativeDialog but
290 // we weren't a dialog class
291 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
293 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
295 // reset the dangling pointer our parent window may keep to us
298 m_parent
->RemoveChild(this);
303 #endif // wxUSE_CARET
306 delete m_windowValidator
;
307 #endif // wxUSE_VALIDATORS
309 #if wxUSE_CONSTRAINTS
310 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
311 // at deleted windows as they delete themselves.
312 DeleteRelatedConstraints();
316 // This removes any dangling pointers to this window in other windows'
317 // constraintsInvolvedIn lists.
318 UnsetConstraints(m_constraints
);
319 delete m_constraints
;
320 m_constraints
= NULL
;
322 #endif // wxUSE_CONSTRAINTS
324 if ( m_containingSizer
)
325 m_containingSizer
->Detach( (wxWindow
*)this );
327 delete m_windowSizer
;
329 #if wxUSE_DRAG_AND_DROP
331 #endif // wxUSE_DRAG_AND_DROP
335 #endif // wxUSE_TOOLTIPS
337 #if wxUSE_ACCESSIBILITY
342 bool wxWindowBase::Destroy()
349 bool wxWindowBase::Close(bool force
)
351 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
352 event
.SetEventObject(this);
353 event
.SetCanVeto(!force
);
355 // return false if window wasn't closed because the application vetoed the
357 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
360 bool wxWindowBase::DestroyChildren()
362 wxWindowList::compatibility_iterator node
;
365 // we iterate until the list becomes empty
366 node
= GetChildren().GetFirst();
370 wxWindow
*child
= node
->GetData();
372 // note that we really want to call delete and not ->Destroy() here
373 // because we want to delete the child immediately, before we are
374 // deleted, and delayed deletion would result in problems as our (top
375 // level) child could outlive its parent
378 wxASSERT_MSG( !GetChildren().Find(child
),
379 wxT("child didn't remove itself using RemoveChild()") );
385 // ----------------------------------------------------------------------------
386 // size/position related methods
387 // ----------------------------------------------------------------------------
389 // centre the window with respect to its parent in either (or both) directions
390 void wxWindowBase::DoCentre(int dir
)
392 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
393 _T("this method only implements centering child windows") );
395 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
398 // fits the window around the children
399 void wxWindowBase::Fit()
401 if ( !GetChildren().empty() )
403 SetSize(GetBestSize());
405 //else: do nothing if we have no children
408 // fits virtual size (ie. scrolled area etc.) around children
409 void wxWindowBase::FitInside()
411 if ( GetChildren().GetCount() > 0 )
413 SetVirtualSize( GetBestVirtualSize() );
417 // On Mac, scrollbars are explicitly children.
419 static bool wxHasRealChildren(const wxWindowBase
* win
)
421 int realChildCount
= 0;
423 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
425 node
= node
->GetNext() )
427 wxWindow
*win
= node
->GetData();
428 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
431 return (realChildCount
> 0);
435 void wxWindowBase::InvalidateBestSize()
437 m_bestSizeCache
= wxDefaultSize
;
439 // parent's best size calculation may depend on its children's
440 // as long as child window we are in is not top level window itself
441 // (because the TLW size is never resized automatically)
442 // so let's invalidate it as well to be safe:
443 if (m_parent
&& !IsTopLevel())
444 m_parent
->InvalidateBestSize();
447 // return the size best suited for the current window
448 wxSize
wxWindowBase::DoGetBestSize() const
454 best
= GetWindowSizeForVirtualSize(m_windowSizer
->GetMinSize());
456 #if wxUSE_CONSTRAINTS
457 else if ( m_constraints
)
459 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
461 // our minimal acceptable size is such that all our windows fit inside
465 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
467 node
= node
->GetNext() )
469 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
472 // it's not normal that we have an unconstrained child, but
473 // what can we do about it?
477 int x
= c
->right
.GetValue(),
478 y
= c
->bottom
.GetValue();
486 // TODO: we must calculate the overlaps somehow, otherwise we
487 // will never return a size bigger than the current one :-(
490 best
= wxSize(maxX
, maxY
);
492 #endif // wxUSE_CONSTRAINTS
493 else if ( !GetChildren().empty()
495 && wxHasRealChildren(this)
499 // our minimal acceptable size is such that all our visible child
500 // windows fit inside
504 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
506 node
= node
->GetNext() )
508 wxWindow
*win
= node
->GetData();
509 if ( win
->IsTopLevel()
512 || wxDynamicCast(win
, wxStatusBar
)
513 #endif // wxUSE_STATUSBAR
516 // dialogs and frames lie in different top level windows -
517 // don't deal with them here; as for the status bars, they
518 // don't lie in the client area at all
523 win
->GetPosition(&wx
, &wy
);
525 // if the window hadn't been positioned yet, assume that it is in
527 if ( wx
== wxDefaultCoord
)
529 if ( wy
== wxDefaultCoord
)
532 win
->GetSize(&ww
, &wh
);
533 if ( wx
+ ww
> maxX
)
535 if ( wy
+ wh
> maxY
)
539 best
= wxSize(maxX
, maxY
);
541 else // ! has children
543 // for a generic window there is no natural best size so, if the
544 // minimal size is not set, use the current size but take care to
545 // remember it as minimal size for the next time because our best size
546 // should be constant: otherwise we could get into a situation when the
547 // window is initially at some size, then expanded to a larger size and
548 // then, when the containing window is shrunk back (because our initial
549 // best size had been used for computing the parent min size), we can't
550 // be shrunk back any more because our best size is now bigger
551 wxSize size
= GetMinSize();
552 if ( !size
.IsFullySpecified() )
554 size
.SetDefaults(GetSize());
555 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
558 // return as-is, unadjusted by the client size difference.
562 // Add any difference between size and client size
563 wxSize diff
= GetSize() - GetClientSize();
564 best
.x
+= wxMax(0, diff
.x
);
565 best
.y
+= wxMax(0, diff
.y
);
571 wxSize
wxWindowBase::GetBestFittingSize() const
573 // merge the best size with the min size, giving priority to the min size
574 wxSize min
= GetMinSize();
575 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
577 wxSize best
= GetBestSize();
578 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
579 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
585 void wxWindowBase::SetBestFittingSize(const wxSize
& size
)
587 // Set the min size to the size passed in. This will usually either be
588 // wxDefaultSize or the size passed to this window's ctor/Create function.
591 // Merge the size with the best size if needed
592 wxSize best
= GetBestFittingSize();
594 // If the current size doesn't match then change it
595 if (GetSize() != best
)
600 // by default the origin is not shifted
601 wxPoint
wxWindowBase::GetClientAreaOrigin() const
606 // set the min/max size of the window
607 void wxWindowBase::DoSetSizeHints(int minW
, int minH
,
609 int WXUNUSED(incW
), int WXUNUSED(incH
))
611 // setting min width greater than max width leads to infinite loops under
612 // X11 and generally doesn't make any sense, so don't allow it
613 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
614 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
615 _T("min width/height must be less than max width/height!") );
623 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
625 if ( m_windowVariant
!= variant
)
627 m_windowVariant
= variant
;
629 DoSetWindowVariant(variant
);
633 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
635 // adjust the font height to correspond to our new variant (notice that
636 // we're only called if something really changed)
637 wxFont font
= GetFont();
638 int size
= font
.GetPointSize();
641 case wxWINDOW_VARIANT_NORMAL
:
644 case wxWINDOW_VARIANT_SMALL
:
649 case wxWINDOW_VARIANT_MINI
:
654 case wxWINDOW_VARIANT_LARGE
:
660 wxFAIL_MSG(_T("unexpected window variant"));
664 font
.SetPointSize(size
);
668 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
671 m_minVirtualWidth
= minW
;
672 m_maxVirtualWidth
= maxW
;
673 m_minVirtualHeight
= minH
;
674 m_maxVirtualHeight
= maxH
;
677 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
679 if ( m_minVirtualWidth
!= wxDefaultCoord
&& m_minVirtualWidth
> x
)
680 x
= m_minVirtualWidth
;
681 if ( m_maxVirtualWidth
!= wxDefaultCoord
&& m_maxVirtualWidth
< x
)
682 x
= m_maxVirtualWidth
;
683 if ( m_minVirtualHeight
!= wxDefaultCoord
&& m_minVirtualHeight
> y
)
684 y
= m_minVirtualHeight
;
685 if ( m_maxVirtualHeight
!= wxDefaultCoord
&& m_maxVirtualHeight
< y
)
686 y
= m_maxVirtualHeight
;
688 m_virtualSize
= wxSize(x
, y
);
691 wxSize
wxWindowBase::DoGetVirtualSize() const
693 // we should use the entire client area so if it is greater than our
694 // virtual size, expand it to fit (otherwise if the window is big enough we
695 // wouldn't be using parts of it)
696 wxSize size
= GetClientSize();
697 if ( m_virtualSize
.x
> size
.x
)
698 size
.x
= m_virtualSize
.x
;
700 if ( m_virtualSize
.y
>= size
.y
)
701 size
.y
= m_virtualSize
.y
;
706 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
708 // screen position is the same as (0, 0) in client coords for non TLWs (and
709 // TLWs override this method)
715 ClientToScreen(x
, y
);
718 // ----------------------------------------------------------------------------
719 // show/hide/enable/disable the window
720 // ----------------------------------------------------------------------------
722 bool wxWindowBase::Show(bool show
)
724 if ( show
!= m_isShown
)
736 bool wxWindowBase::Enable(bool enable
)
738 if ( enable
!= m_isEnabled
)
740 m_isEnabled
= enable
;
750 bool wxWindowBase::IsShownOnScreen() const
753 (GetParent() == NULL
|| GetParent()->IsShownOnScreen());
756 // ----------------------------------------------------------------------------
758 // ----------------------------------------------------------------------------
760 bool wxWindowBase::IsTopLevel() const
765 // ----------------------------------------------------------------------------
766 // reparenting the window
767 // ----------------------------------------------------------------------------
769 void wxWindowBase::AddChild(wxWindowBase
*child
)
771 wxCHECK_RET( child
, wxT("can't add a NULL child") );
773 // this should never happen and it will lead to a crash later if it does
774 // because RemoveChild() will remove only one node from the children list
775 // and the other(s) one(s) will be left with dangling pointers in them
776 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
778 GetChildren().Append((wxWindow
*)child
);
779 child
->SetParent(this);
782 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
784 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
786 GetChildren().DeleteObject((wxWindow
*)child
);
787 child
->SetParent(NULL
);
790 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
792 wxWindow
*oldParent
= GetParent();
793 if ( newParent
== oldParent
)
799 // unlink this window from the existing parent.
802 oldParent
->RemoveChild(this);
806 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
809 // add it to the new one
812 newParent
->AddChild(this);
816 wxTopLevelWindows
.Append((wxWindow
*)this);
822 // ----------------------------------------------------------------------------
823 // event handler stuff
824 // ----------------------------------------------------------------------------
826 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
828 wxEvtHandler
*handlerOld
= GetEventHandler();
830 handler
->SetNextHandler(handlerOld
);
833 GetEventHandler()->SetPreviousHandler(handler
);
835 SetEventHandler(handler
);
838 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
840 wxEvtHandler
*handlerA
= GetEventHandler();
843 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
844 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
847 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
848 SetEventHandler(handlerB
);
853 handlerA
= (wxEvtHandler
*)NULL
;
860 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
862 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
864 wxEvtHandler
*handlerPrev
= NULL
,
865 *handlerCur
= GetEventHandler();
868 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
870 if ( handlerCur
== handler
)
874 handlerPrev
->SetNextHandler(handlerNext
);
878 SetEventHandler(handlerNext
);
883 handlerNext
->SetPreviousHandler ( handlerPrev
);
886 handler
->SetNextHandler(NULL
);
887 handler
->SetPreviousHandler(NULL
);
892 handlerPrev
= handlerCur
;
893 handlerCur
= handlerNext
;
896 wxFAIL_MSG( _T("where has the event handler gone?") );
901 // ----------------------------------------------------------------------------
903 // ----------------------------------------------------------------------------
905 void wxWindowBase::InheritAttributes()
907 const wxWindowBase
* const parent
= GetParent();
911 // we only inherit attributes which had been explicitly set for the parent
912 // which ensures that this only happens if the user really wants it and
913 // not by default which wouldn't make any sense in modern GUIs where the
914 // controls don't all use the same fonts (nor colours)
915 if ( parent
->m_inheritFont
&& !m_hasFont
)
916 SetFont(parent
->GetFont());
918 // in addition, there is a possibility to explicitly forbid inheriting
919 // colours at each class level by overriding ShouldInheritColours()
920 if ( ShouldInheritColours() )
922 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
923 SetForegroundColour(parent
->GetForegroundColour());
925 // inheriting (solid) background colour is wrong as it totally breaks
926 // any kind of themed backgrounds
928 // instead, the controls should use the same background as their parent
929 // (ideally by not drawing it at all)
931 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
932 SetBackgroundColour(parent
->GetBackgroundColour());
937 /* static */ wxVisualAttributes
938 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
940 // it is important to return valid values for all attributes from here,
941 // GetXXX() below rely on this
942 wxVisualAttributes attrs
;
943 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
944 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
946 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
947 // the usual background colour than wxSYS_COLOUR_BTNFACE.
948 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
949 // colour on other platforms.
951 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
952 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
954 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
959 wxColour
wxWindowBase::GetBackgroundColour() const
961 if ( !m_backgroundColour
.Ok() )
963 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
965 // get our default background colour
966 wxColour colBg
= GetDefaultAttributes().colBg
;
968 // we must return some valid colour to avoid redoing this every time
969 // and also to avoid surprizing the applications written for older
970 // wxWidgets versions where GetBackgroundColour() always returned
971 // something -- so give them something even if it doesn't make sense
972 // for this window (e.g. it has a themed background)
974 colBg
= GetClassDefaultAttributes().colBg
;
979 return m_backgroundColour
;
982 wxColour
wxWindowBase::GetForegroundColour() const
984 // logic is the same as above
985 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
987 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
989 wxColour colFg
= GetDefaultAttributes().colFg
;
992 colFg
= GetClassDefaultAttributes().colFg
;
997 return m_foregroundColour
;
1000 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1002 if ( colour
== m_backgroundColour
)
1005 m_hasBgCol
= colour
.Ok();
1006 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1007 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1009 m_inheritBgCol
= m_hasBgCol
;
1010 m_backgroundColour
= colour
;
1011 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1015 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1017 if (colour
== m_foregroundColour
)
1020 m_hasFgCol
= colour
.Ok();
1021 m_inheritFgCol
= m_hasFgCol
;
1022 m_foregroundColour
= colour
;
1023 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1027 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1029 // setting an invalid cursor is ok, it means that we don't have any special
1031 if ( m_cursor
== cursor
)
1042 wxFont
wxWindowBase::GetFont() const
1044 // logic is the same as in GetBackgroundColour()
1047 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1049 wxFont font
= GetDefaultAttributes().font
;
1051 font
= GetClassDefaultAttributes().font
;
1059 bool wxWindowBase::SetFont(const wxFont
& font
)
1061 if ( font
== m_font
)
1068 m_hasFont
= font
.Ok();
1069 m_inheritFont
= m_hasFont
;
1071 InvalidateBestSize();
1078 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1080 m_hasCustomPalette
= true;
1083 // VZ: can anyone explain me what do we do here?
1084 wxWindowDC
d((wxWindow
*) this);
1088 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1090 wxWindow
*win
= (wxWindow
*)this;
1091 while ( win
&& !win
->HasCustomPalette() )
1093 win
= win
->GetParent();
1099 #endif // wxUSE_PALETTE
1102 void wxWindowBase::SetCaret(wxCaret
*caret
)
1113 wxASSERT_MSG( m_caret
->GetWindow() == this,
1114 wxT("caret should be created associated to this window") );
1117 #endif // wxUSE_CARET
1119 #if wxUSE_VALIDATORS
1120 // ----------------------------------------------------------------------------
1122 // ----------------------------------------------------------------------------
1124 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1126 if ( m_windowValidator
)
1127 delete m_windowValidator
;
1129 m_windowValidator
= (wxValidator
*)validator
.Clone();
1131 if ( m_windowValidator
)
1132 m_windowValidator
->SetWindow(this);
1134 #endif // wxUSE_VALIDATORS
1136 // ----------------------------------------------------------------------------
1137 // update region stuff
1138 // ----------------------------------------------------------------------------
1140 wxRect
wxWindowBase::GetUpdateClientRect() const
1142 wxRegion rgnUpdate
= GetUpdateRegion();
1143 rgnUpdate
.Intersect(GetClientRect());
1144 wxRect rectUpdate
= rgnUpdate
.GetBox();
1145 wxPoint ptOrigin
= GetClientAreaOrigin();
1146 rectUpdate
.x
-= ptOrigin
.x
;
1147 rectUpdate
.y
-= ptOrigin
.y
;
1152 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1154 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1157 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1159 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1162 void wxWindowBase::ClearBackground()
1164 // wxGTK uses its own version, no need to add never used code
1166 wxClientDC
dc((wxWindow
*)this);
1167 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1168 dc
.SetBackground(brush
);
1173 // ----------------------------------------------------------------------------
1174 // find child window by id or name
1175 // ----------------------------------------------------------------------------
1177 wxWindow
*wxWindowBase::FindWindow(long id
) const
1179 if ( id
== m_windowId
)
1180 return (wxWindow
*)this;
1182 wxWindowBase
*res
= (wxWindow
*)NULL
;
1183 wxWindowList::compatibility_iterator node
;
1184 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1186 wxWindowBase
*child
= node
->GetData();
1187 res
= child
->FindWindow( id
);
1190 return (wxWindow
*)res
;
1193 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1195 if ( name
== m_windowName
)
1196 return (wxWindow
*)this;
1198 wxWindowBase
*res
= (wxWindow
*)NULL
;
1199 wxWindowList::compatibility_iterator node
;
1200 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1202 wxWindow
*child
= node
->GetData();
1203 res
= child
->FindWindow(name
);
1206 return (wxWindow
*)res
;
1210 // find any window by id or name or label: If parent is non-NULL, look through
1211 // children for a label or title matching the specified string. If NULL, look
1212 // through all top-level windows.
1214 // to avoid duplicating code we reuse the same helper function but with
1215 // different comparators
1217 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1218 const wxString
& label
, long id
);
1221 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1224 return win
->GetLabel() == label
;
1228 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1231 return win
->GetName() == label
;
1235 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1238 return win
->GetId() == id
;
1241 // recursive helper for the FindWindowByXXX() functions
1243 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1244 const wxString
& label
,
1246 wxFindWindowCmp cmp
)
1250 // see if this is the one we're looking for
1251 if ( (*cmp
)(parent
, label
, id
) )
1252 return (wxWindow
*)parent
;
1254 // It wasn't, so check all its children
1255 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1257 node
= node
->GetNext() )
1259 // recursively check each child
1260 wxWindow
*win
= (wxWindow
*)node
->GetData();
1261 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1271 // helper for FindWindowByXXX()
1273 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1274 const wxString
& label
,
1276 wxFindWindowCmp cmp
)
1280 // just check parent and all its children
1281 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1284 // start at very top of wx's windows
1285 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1287 node
= node
->GetNext() )
1289 // recursively check each window & its children
1290 wxWindow
*win
= node
->GetData();
1291 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1301 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1303 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1308 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1310 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1314 // fall back to the label
1315 win
= FindWindowByLabel(title
, parent
);
1323 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1325 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1328 // ----------------------------------------------------------------------------
1329 // dialog oriented functions
1330 // ----------------------------------------------------------------------------
1332 void wxWindowBase::MakeModal(bool modal
)
1334 // Disable all other windows
1337 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1340 wxWindow
*win
= node
->GetData();
1342 win
->Enable(!modal
);
1344 node
= node
->GetNext();
1349 bool wxWindowBase::Validate()
1351 #if wxUSE_VALIDATORS
1352 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1354 wxWindowList::compatibility_iterator node
;
1355 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1357 wxWindowBase
*child
= node
->GetData();
1358 wxValidator
*validator
= child
->GetValidator();
1359 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1364 if ( recurse
&& !child
->Validate() )
1369 #endif // wxUSE_VALIDATORS
1374 bool wxWindowBase::TransferDataToWindow()
1376 #if wxUSE_VALIDATORS
1377 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1379 wxWindowList::compatibility_iterator node
;
1380 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1382 wxWindowBase
*child
= node
->GetData();
1383 wxValidator
*validator
= child
->GetValidator();
1384 if ( validator
&& !validator
->TransferToWindow() )
1386 wxLogWarning(_("Could not transfer data to window"));
1388 wxLog::FlushActive();
1396 if ( !child
->TransferDataToWindow() )
1398 // warning already given
1403 #endif // wxUSE_VALIDATORS
1408 bool wxWindowBase::TransferDataFromWindow()
1410 #if wxUSE_VALIDATORS
1411 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1413 wxWindowList::compatibility_iterator node
;
1414 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1416 wxWindow
*child
= node
->GetData();
1417 wxValidator
*validator
= child
->GetValidator();
1418 if ( validator
&& !validator
->TransferFromWindow() )
1420 // nop warning here because the application is supposed to give
1421 // one itself - we don't know here what might have gone wrongly
1428 if ( !child
->TransferDataFromWindow() )
1430 // warning already given
1435 #endif // wxUSE_VALIDATORS
1440 void wxWindowBase::InitDialog()
1442 wxInitDialogEvent
event(GetId());
1443 event
.SetEventObject( this );
1444 GetEventHandler()->ProcessEvent(event
);
1447 // ----------------------------------------------------------------------------
1448 // context-sensitive help support
1449 // ----------------------------------------------------------------------------
1453 // associate this help text with this window
1454 void wxWindowBase::SetHelpText(const wxString
& text
)
1456 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1459 helpProvider
->AddHelp(this, text
);
1463 // associate this help text with all windows with the same id as this
1465 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1467 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1470 helpProvider
->AddHelp(GetId(), text
);
1474 // get the help string associated with this window (may be empty)
1475 // default implementation forwards calls to the help provider
1477 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1478 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1481 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1484 text
= helpProvider
->GetHelp(this);
1490 // show help for this window
1491 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1493 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1496 if ( helpProvider
->ShowHelpAtPoint(this, event
.GetPosition(), event
.GetOrigin()) )
1498 // skip the event.Skip() below
1506 #endif // wxUSE_HELP
1508 // ----------------------------------------------------------------------------
1509 // tooltipsroot.Replace("\\", "/");
1510 // ----------------------------------------------------------------------------
1514 void wxWindowBase::SetToolTip( const wxString
&tip
)
1516 // don't create the new tooltip if we already have one
1519 m_tooltip
->SetTip( tip
);
1523 SetToolTip( new wxToolTip( tip
) );
1526 // setting empty tooltip text does not remove the tooltip any more - use
1527 // SetToolTip((wxToolTip *)NULL) for this
1530 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1532 if ( m_tooltip
!= tooltip
)
1537 m_tooltip
= tooltip
;
1541 #endif // wxUSE_TOOLTIPS
1543 // ----------------------------------------------------------------------------
1544 // constraints and sizers
1545 // ----------------------------------------------------------------------------
1547 #if wxUSE_CONSTRAINTS
1549 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1551 if ( m_constraints
)
1553 UnsetConstraints(m_constraints
);
1554 delete m_constraints
;
1556 m_constraints
= constraints
;
1557 if ( m_constraints
)
1559 // Make sure other windows know they're part of a 'meaningful relationship'
1560 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1561 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1562 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1563 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1564 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1565 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1566 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1567 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1568 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1569 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1570 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1571 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1572 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1573 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1574 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1575 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1579 // This removes any dangling pointers to this window in other windows'
1580 // constraintsInvolvedIn lists.
1581 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1585 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1586 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1587 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1588 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1589 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1590 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1591 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1592 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1593 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1594 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1595 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1596 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1597 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1598 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1599 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1600 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1604 // Back-pointer to other windows we're involved with, so if we delete this
1605 // window, we must delete any constraints we're involved with.
1606 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1608 if ( !m_constraintsInvolvedIn
)
1609 m_constraintsInvolvedIn
= new wxWindowList
;
1610 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1611 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1614 // REMOVE back-pointer to other windows we're involved with.
1615 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1617 if ( m_constraintsInvolvedIn
)
1618 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1621 // Reset any constraints that mention this window
1622 void wxWindowBase::DeleteRelatedConstraints()
1624 if ( m_constraintsInvolvedIn
)
1626 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1629 wxWindow
*win
= node
->GetData();
1630 wxLayoutConstraints
*constr
= win
->GetConstraints();
1632 // Reset any constraints involving this window
1635 constr
->left
.ResetIfWin(this);
1636 constr
->top
.ResetIfWin(this);
1637 constr
->right
.ResetIfWin(this);
1638 constr
->bottom
.ResetIfWin(this);
1639 constr
->width
.ResetIfWin(this);
1640 constr
->height
.ResetIfWin(this);
1641 constr
->centreX
.ResetIfWin(this);
1642 constr
->centreY
.ResetIfWin(this);
1645 wxWindowList::compatibility_iterator next
= node
->GetNext();
1646 m_constraintsInvolvedIn
->Erase(node
);
1650 delete m_constraintsInvolvedIn
;
1651 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1655 #endif // wxUSE_CONSTRAINTS
1657 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1659 if ( sizer
== m_windowSizer
)
1662 if ( m_windowSizer
)
1664 m_windowSizer
->SetContainingWindow(NULL
);
1667 delete m_windowSizer
;
1670 m_windowSizer
= sizer
;
1671 if ( m_windowSizer
)
1673 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
1676 SetAutoLayout(m_windowSizer
!= NULL
);
1679 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1681 SetSizer( sizer
, deleteOld
);
1682 sizer
->SetSizeHints( (wxWindow
*) this );
1686 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1688 // adding a window to a sizer twice is going to result in fatal and
1689 // hard to debug problems later because when deleting the second
1690 // associated wxSizerItem we're going to dereference a dangling
1691 // pointer; so try to detect this as early as possible
1692 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1693 _T("Adding a window to the same sizer twice?") );
1695 m_containingSizer
= sizer
;
1698 #if wxUSE_CONSTRAINTS
1700 void wxWindowBase::SatisfyConstraints()
1702 wxLayoutConstraints
*constr
= GetConstraints();
1703 bool wasOk
= constr
&& constr
->AreSatisfied();
1705 ResetConstraints(); // Mark all constraints as unevaluated
1709 // if we're a top level panel (i.e. our parent is frame/dialog), our
1710 // own constraints will never be satisfied any more unless we do it
1714 while ( noChanges
> 0 )
1716 LayoutPhase1(&noChanges
);
1720 LayoutPhase2(&noChanges
);
1723 #endif // wxUSE_CONSTRAINTS
1725 bool wxWindowBase::Layout()
1727 // If there is a sizer, use it instead of the constraints
1731 GetVirtualSize(&w
, &h
);
1732 GetSizer()->SetDimension( 0, 0, w
, h
);
1734 #if wxUSE_CONSTRAINTS
1737 SatisfyConstraints(); // Find the right constraints values
1738 SetConstraintSizes(); // Recursively set the real window sizes
1745 #if wxUSE_CONSTRAINTS
1747 // first phase of the constraints evaluation: set our own constraints
1748 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1750 wxLayoutConstraints
*constr
= GetConstraints();
1752 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1755 // second phase: set the constraints for our children
1756 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1763 // Layout grand children
1769 // Do a phase of evaluating child constraints
1770 bool wxWindowBase::DoPhase(int phase
)
1772 // the list containing the children for which the constraints are already
1774 wxWindowList succeeded
;
1776 // the max number of iterations we loop before concluding that we can't set
1778 static const int maxIterations
= 500;
1780 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1784 // loop over all children setting their constraints
1785 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1787 node
= node
->GetNext() )
1789 wxWindow
*child
= node
->GetData();
1790 if ( child
->IsTopLevel() )
1792 // top level children are not inside our client area
1796 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1798 // this one is either already ok or nothing we can do about it
1802 int tempNoChanges
= 0;
1803 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1804 : child
->LayoutPhase2(&tempNoChanges
);
1805 noChanges
+= tempNoChanges
;
1809 succeeded
.Append(child
);
1815 // constraints are set
1823 void wxWindowBase::ResetConstraints()
1825 wxLayoutConstraints
*constr
= GetConstraints();
1828 constr
->left
.SetDone(false);
1829 constr
->top
.SetDone(false);
1830 constr
->right
.SetDone(false);
1831 constr
->bottom
.SetDone(false);
1832 constr
->width
.SetDone(false);
1833 constr
->height
.SetDone(false);
1834 constr
->centreX
.SetDone(false);
1835 constr
->centreY
.SetDone(false);
1838 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1841 wxWindow
*win
= node
->GetData();
1842 if ( !win
->IsTopLevel() )
1843 win
->ResetConstraints();
1844 node
= node
->GetNext();
1848 // Need to distinguish between setting the 'fake' size for windows and sizers,
1849 // and setting the real values.
1850 void wxWindowBase::SetConstraintSizes(bool recurse
)
1852 wxLayoutConstraints
*constr
= GetConstraints();
1853 if ( constr
&& constr
->AreSatisfied() )
1855 int x
= constr
->left
.GetValue();
1856 int y
= constr
->top
.GetValue();
1857 int w
= constr
->width
.GetValue();
1858 int h
= constr
->height
.GetValue();
1860 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1861 (constr
->height
.GetRelationship() != wxAsIs
) )
1863 SetSize(x
, y
, w
, h
);
1867 // If we don't want to resize this window, just move it...
1873 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1874 GetClassInfo()->GetClassName(),
1880 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1883 wxWindow
*win
= node
->GetData();
1884 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1885 win
->SetConstraintSizes();
1886 node
= node
->GetNext();
1891 // Only set the size/position of the constraint (if any)
1892 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1894 wxLayoutConstraints
*constr
= GetConstraints();
1897 if ( x
!= wxDefaultCoord
)
1899 constr
->left
.SetValue(x
);
1900 constr
->left
.SetDone(true);
1902 if ( y
!= wxDefaultCoord
)
1904 constr
->top
.SetValue(y
);
1905 constr
->top
.SetDone(true);
1907 if ( w
!= wxDefaultCoord
)
1909 constr
->width
.SetValue(w
);
1910 constr
->width
.SetDone(true);
1912 if ( h
!= wxDefaultCoord
)
1914 constr
->height
.SetValue(h
);
1915 constr
->height
.SetDone(true);
1920 void wxWindowBase::MoveConstraint(int x
, int y
)
1922 wxLayoutConstraints
*constr
= GetConstraints();
1925 if ( x
!= wxDefaultCoord
)
1927 constr
->left
.SetValue(x
);
1928 constr
->left
.SetDone(true);
1930 if ( y
!= wxDefaultCoord
)
1932 constr
->top
.SetValue(y
);
1933 constr
->top
.SetDone(true);
1938 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1940 wxLayoutConstraints
*constr
= GetConstraints();
1943 *w
= constr
->width
.GetValue();
1944 *h
= constr
->height
.GetValue();
1950 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1952 wxLayoutConstraints
*constr
= GetConstraints();
1955 *w
= constr
->width
.GetValue();
1956 *h
= constr
->height
.GetValue();
1959 GetClientSize(w
, h
);
1962 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1964 wxLayoutConstraints
*constr
= GetConstraints();
1967 *x
= constr
->left
.GetValue();
1968 *y
= constr
->top
.GetValue();
1974 #endif // wxUSE_CONSTRAINTS
1976 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1978 // don't do it for the dialogs/frames - they float independently of their
1980 if ( !IsTopLevel() )
1982 wxWindow
*parent
= GetParent();
1983 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1985 wxPoint
pt(parent
->GetClientAreaOrigin());
1992 // ----------------------------------------------------------------------------
1993 // do Update UI processing for child controls
1994 // ----------------------------------------------------------------------------
1996 void wxWindowBase::UpdateWindowUI(long flags
)
1998 wxUpdateUIEvent
event(GetId());
1999 event
.SetEventObject(this);
2001 if ( GetEventHandler()->ProcessEvent(event
) )
2003 DoUpdateWindowUI(event
);
2006 if (flags
& wxUPDATE_UI_RECURSE
)
2008 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2011 wxWindow
* child
= (wxWindow
*) node
->GetData();
2012 child
->UpdateWindowUI(flags
);
2013 node
= node
->GetNext();
2018 // do the window-specific processing after processing the update event
2019 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2021 if ( event
.GetSetEnabled() )
2022 Enable(event
.GetEnabled());
2024 if ( event
.GetSetShown() )
2025 Show(event
.GetShown());
2029 // call internal idle recursively
2030 // may be obsolete (wait until OnIdle scheme stabilises)
2031 void wxWindowBase::ProcessInternalIdle()
2035 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2038 wxWindow
*child
= node
->GetData();
2039 child
->ProcessInternalIdle();
2040 node
= node
->GetNext();
2045 // ----------------------------------------------------------------------------
2046 // dialog units translations
2047 // ----------------------------------------------------------------------------
2049 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2051 int charWidth
= GetCharWidth();
2052 int charHeight
= GetCharHeight();
2053 wxPoint pt2
= wxDefaultPosition
;
2054 if (pt
.x
!= wxDefaultCoord
)
2055 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2056 if (pt
.y
!= wxDefaultCoord
)
2057 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2062 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2064 int charWidth
= GetCharWidth();
2065 int charHeight
= GetCharHeight();
2066 wxPoint pt2
= wxDefaultPosition
;
2067 if (pt
.x
!= wxDefaultCoord
)
2068 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2069 if (pt
.y
!= wxDefaultCoord
)
2070 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2075 // ----------------------------------------------------------------------------
2077 // ----------------------------------------------------------------------------
2079 // propagate the colour change event to the subwindows
2080 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2082 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2085 // Only propagate to non-top-level windows
2086 wxWindow
*win
= node
->GetData();
2087 if ( !win
->IsTopLevel() )
2089 wxSysColourChangedEvent event2
;
2090 event
.SetEventObject(win
);
2091 win
->GetEventHandler()->ProcessEvent(event2
);
2094 node
= node
->GetNext();
2100 // the default action is to populate dialog with data when it's created,
2101 // and nudge the UI into displaying itself correctly in case
2102 // we've turned the wxUpdateUIEvents frequency down low.
2103 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2105 TransferDataToWindow();
2107 // Update the UI at this point
2108 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2111 // methods for drawing the sizers in a visible way
2114 static void DrawSizers(wxWindowBase
*win
);
2116 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2118 wxClientDC
dc((wxWindow
*)win
);
2119 dc
.SetPen(*wxRED_PEN
);
2120 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2121 dc
.DrawRectangle(rect
.Deflate(1, 1));
2124 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2126 const wxSizerItemList
& items
= sizer
->GetChildren();
2127 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2132 wxSizerItem
*item
= *i
;
2133 if ( item
->IsSizer() )
2135 DrawBorder(win
, item
->GetRect().Deflate(2));
2136 DrawSizer(win
, item
->GetSizer());
2138 else if ( item
->IsSpacer() )
2140 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2142 else if ( item
->IsWindow() )
2144 DrawSizers(item
->GetWindow());
2149 static void DrawSizers(wxWindowBase
*win
)
2151 wxSizer
*sizer
= win
->GetSizer();
2154 DrawBorder(win
, win
->GetClientSize());
2155 DrawSizer(win
, sizer
);
2157 else // no sizer, still recurse into the children
2159 const wxWindowList
& children
= win
->GetChildren();
2160 for ( wxWindowList::const_iterator i
= children
.begin(),
2161 end
= children
.end();
2170 #endif // __WXDEBUG__
2172 // process special middle clicks
2173 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2175 if ( event
.ControlDown() && event
.AltDown() )
2178 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2179 if ( event
.ShiftDown() )
2184 #endif // __WXDEBUG__
2187 // don't translate these strings, they're for diagnostics purposes only
2189 msg
.Printf(_T("wxWidgets Library (%s port)\n")
2190 _T("Version %d.%d.%d%s%s, compiled at %s %s%s\n")
2191 _T("Copyright (c) 1995-2006 wxWidgets team"),
2192 wxPlatformInfo().GetPortIdName().c_str(),
2209 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()
2215 wxMessageBox(msg
, _T("wxWidgets information"),
2216 wxICON_INFORMATION
| wxOK
,
2220 #endif // wxUSE_MSGDLG
2226 // ----------------------------------------------------------------------------
2228 // ----------------------------------------------------------------------------
2230 #if wxUSE_ACCESSIBILITY
2231 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2233 if (m_accessible
&& (accessible
!= m_accessible
))
2234 delete m_accessible
;
2235 m_accessible
= accessible
;
2237 m_accessible
->SetWindow((wxWindow
*) this);
2240 // Returns the accessible object, creating if necessary.
2241 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2244 m_accessible
= CreateAccessible();
2245 return m_accessible
;
2248 // Override to create a specific accessible object.
2249 wxAccessible
* wxWindowBase::CreateAccessible()
2251 return new wxWindowAccessible((wxWindow
*) this);
2256 // ----------------------------------------------------------------------------
2257 // list classes implementation
2258 // ----------------------------------------------------------------------------
2262 #include "wx/listimpl.cpp"
2263 WX_DEFINE_LIST(wxWindowList
)
2267 void wxWindowListNode::DeleteData()
2269 delete (wxWindow
*)GetData();
2274 // ----------------------------------------------------------------------------
2276 // ----------------------------------------------------------------------------
2278 wxBorder
wxWindowBase::GetBorder(long flags
) const
2280 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2281 if ( border
== wxBORDER_DEFAULT
)
2283 border
= GetDefaultBorder();
2289 wxBorder
wxWindowBase::GetDefaultBorder() const
2291 return wxBORDER_NONE
;
2294 // ----------------------------------------------------------------------------
2296 // ----------------------------------------------------------------------------
2298 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2300 // here we just check if the point is inside the window or not
2302 // check the top and left border first
2303 bool outside
= x
< 0 || y
< 0;
2306 // check the right and bottom borders too
2307 wxSize size
= GetSize();
2308 outside
= x
>= size
.x
|| y
>= size
.y
;
2311 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2314 // ----------------------------------------------------------------------------
2316 // ----------------------------------------------------------------------------
2318 struct WXDLLEXPORT wxWindowNext
2322 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2323 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2324 bool wxWindowBase::ms_winCaptureChanging
= false;
2326 void wxWindowBase::CaptureMouse()
2328 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2330 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2332 ms_winCaptureChanging
= true;
2334 wxWindow
*winOld
= GetCapture();
2337 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2340 wxWindowNext
*item
= new wxWindowNext
;
2342 item
->next
= ms_winCaptureNext
;
2343 ms_winCaptureNext
= item
;
2345 //else: no mouse capture to save
2348 ms_winCaptureCurrent
= (wxWindow
*)this;
2350 ms_winCaptureChanging
= false;
2353 void wxWindowBase::ReleaseMouse()
2355 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2357 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2359 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2361 ms_winCaptureChanging
= true;
2364 ms_winCaptureCurrent
= NULL
;
2366 if ( ms_winCaptureNext
)
2368 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2369 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2371 wxWindowNext
*item
= ms_winCaptureNext
;
2372 ms_winCaptureNext
= item
->next
;
2375 //else: stack is empty, no previous capture
2377 ms_winCaptureChanging
= false;
2379 wxLogTrace(_T("mousecapture"),
2380 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2381 wx_static_cast(void*, GetCapture()));
2384 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2386 wxMouseCaptureLostEvent
event(win
->GetId());
2387 event
.SetEventObject(win
);
2388 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2390 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2395 void wxWindowBase::NotifyCaptureLost()
2397 // don't do anything if capture lost was expected, i.e. resulted from
2398 // a wx call to ReleaseMouse or CaptureMouse:
2399 if ( ms_winCaptureChanging
)
2402 // if the capture was lost unexpectedly, notify every window that has
2403 // capture (on stack or current) about it and clear the stack:
2405 if ( ms_winCaptureCurrent
)
2407 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2408 ms_winCaptureCurrent
= NULL
;
2411 while ( ms_winCaptureNext
)
2413 wxWindowNext
*item
= ms_winCaptureNext
;
2414 ms_winCaptureNext
= item
->next
;
2416 DoNotifyWindowAboutCaptureLost(item
->win
);
2425 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2426 int WXUNUSED(modifiers
),
2427 int WXUNUSED(keycode
))
2433 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2439 #endif // wxUSE_HOTKEY
2441 void wxWindowBase::SendDestroyEvent()
2443 wxWindowDestroyEvent event
;
2444 event
.SetEventObject(this);
2445 event
.SetId(GetId());
2446 GetEventHandler()->ProcessEvent(event
);
2449 // ----------------------------------------------------------------------------
2451 // ----------------------------------------------------------------------------
2453 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2455 #if wxUSE_VALIDATORS
2456 // Can only use the validator of the window which
2457 // is receiving the event
2458 if ( event
.GetEventObject() == this )
2460 wxValidator
*validator
= GetValidator();
2461 if ( validator
&& validator
->ProcessEvent(event
) )
2466 #endif // wxUSE_VALIDATORS
2471 bool wxWindowBase::TryParent(wxEvent
& event
)
2473 // carry on up the parent-child hierarchy if the propagation count hasn't
2475 if ( event
.ShouldPropagate() )
2477 // honour the requests to stop propagation at this window: this is
2478 // used by the dialogs, for example, to prevent processing the events
2479 // from the dialog controls in the parent frame which rarely, if ever,
2481 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2483 wxWindow
*parent
= GetParent();
2484 if ( parent
&& !parent
->IsBeingDeleted() )
2486 wxPropagateOnce
propagateOnce(event
);
2488 return parent
->GetEventHandler()->ProcessEvent(event
);
2493 return wxEvtHandler::TryParent(event
);
2496 // ----------------------------------------------------------------------------
2497 // keyboard navigation
2498 // ----------------------------------------------------------------------------
2500 // Navigates in the specified direction.
2501 bool wxWindowBase::Navigate(int flags
)
2503 wxNavigationKeyEvent eventNav
;
2504 eventNav
.SetFlags(flags
);
2505 eventNav
.SetEventObject(this);
2506 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2513 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2515 // check that we're not a top level window
2516 wxCHECK_RET( GetParent(),
2517 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2519 // detect the special case when we have nothing to do anyhow and when the
2520 // code below wouldn't work
2524 // find the target window in the siblings list
2525 wxWindowList
& siblings
= GetParent()->GetChildren();
2526 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2527 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2529 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2530 // can't just move the node around
2531 wxWindow
*self
= (wxWindow
*)this;
2532 siblings
.DeleteObject(self
);
2533 if ( move
== MoveAfter
)
2540 siblings
.Insert(i
, self
);
2542 else // MoveAfter and win was the last sibling
2544 siblings
.Append(self
);
2548 // ----------------------------------------------------------------------------
2550 // ----------------------------------------------------------------------------
2552 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2554 wxWindowBase
*win
= DoFindFocus();
2555 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2558 // ----------------------------------------------------------------------------
2560 // ----------------------------------------------------------------------------
2562 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2564 while ( win
&& !win
->IsTopLevel() )
2565 win
= win
->GetParent();
2570 #if wxUSE_ACCESSIBILITY
2571 // ----------------------------------------------------------------------------
2572 // accessible object for windows
2573 // ----------------------------------------------------------------------------
2575 // Can return either a child object, or an integer
2576 // representing the child element, starting from 1.
2577 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2579 wxASSERT( GetWindow() != NULL
);
2583 return wxACC_NOT_IMPLEMENTED
;
2586 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2587 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2589 wxASSERT( GetWindow() != NULL
);
2593 wxWindow
* win
= NULL
;
2600 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2602 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2609 rect
= win
->GetRect();
2610 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2611 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2615 return wxACC_NOT_IMPLEMENTED
;
2618 // Navigates from fromId to toId/toObject.
2619 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2620 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2622 wxASSERT( GetWindow() != NULL
);
2628 case wxNAVDIR_FIRSTCHILD
:
2630 if (GetWindow()->GetChildren().GetCount() == 0)
2632 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2633 *toObject
= childWindow
->GetOrCreateAccessible();
2637 case wxNAVDIR_LASTCHILD
:
2639 if (GetWindow()->GetChildren().GetCount() == 0)
2641 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2642 *toObject
= childWindow
->GetOrCreateAccessible();
2646 case wxNAVDIR_RIGHT
:
2650 wxWindowList::compatibility_iterator node
=
2651 wxWindowList::compatibility_iterator();
2654 // Can't navigate to sibling of this window
2655 // if we're a top-level window.
2656 if (!GetWindow()->GetParent())
2657 return wxACC_NOT_IMPLEMENTED
;
2659 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2663 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2664 node
= GetWindow()->GetChildren().Item(fromId
-1);
2667 if (node
&& node
->GetNext())
2669 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2670 *toObject
= nextWindow
->GetOrCreateAccessible();
2678 case wxNAVDIR_PREVIOUS
:
2680 wxWindowList::compatibility_iterator node
=
2681 wxWindowList::compatibility_iterator();
2684 // Can't navigate to sibling of this window
2685 // if we're a top-level window.
2686 if (!GetWindow()->GetParent())
2687 return wxACC_NOT_IMPLEMENTED
;
2689 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2693 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2694 node
= GetWindow()->GetChildren().Item(fromId
-1);
2697 if (node
&& node
->GetPrevious())
2699 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2700 *toObject
= previousWindow
->GetOrCreateAccessible();
2708 return wxACC_NOT_IMPLEMENTED
;
2711 // Gets the name of the specified object.
2712 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2714 wxASSERT( GetWindow() != NULL
);
2720 // If a child, leave wxWidgets to call the function on the actual
2723 return wxACC_NOT_IMPLEMENTED
;
2725 // This will eventually be replaced by specialised
2726 // accessible classes, one for each kind of wxWidgets
2727 // control or window.
2729 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2730 title
= ((wxButton
*) GetWindow())->GetLabel();
2733 title
= GetWindow()->GetName();
2741 return wxACC_NOT_IMPLEMENTED
;
2744 // Gets the number of children.
2745 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2747 wxASSERT( GetWindow() != NULL
);
2751 *childId
= (int) GetWindow()->GetChildren().GetCount();
2755 // Gets the specified child (starting from 1).
2756 // If *child is NULL and return value is wxACC_OK,
2757 // this means that the child is a simple element and
2758 // not an accessible object.
2759 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2761 wxASSERT( GetWindow() != NULL
);
2771 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2774 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2775 *child
= childWindow
->GetOrCreateAccessible();
2782 // Gets the parent, or NULL.
2783 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2785 wxASSERT( GetWindow() != NULL
);
2789 wxWindow
* parentWindow
= GetWindow()->GetParent();
2797 *parent
= parentWindow
->GetOrCreateAccessible();
2805 // Performs the default action. childId is 0 (the action for this object)
2806 // or > 0 (the action for a child).
2807 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2808 // window (e.g. an edit control).
2809 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2811 wxASSERT( GetWindow() != NULL
);
2815 return wxACC_NOT_IMPLEMENTED
;
2818 // Gets the default action for this object (0) or > 0 (the action for a child).
2819 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2820 // string if there is no action.
2821 // The retrieved string describes the action that is performed on an object,
2822 // not what the object does as a result. For example, a toolbar button that prints
2823 // a document has a default action of "Press" rather than "Prints the current document."
2824 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2826 wxASSERT( GetWindow() != NULL
);
2830 return wxACC_NOT_IMPLEMENTED
;
2833 // Returns the description for this object or a child.
2834 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2836 wxASSERT( GetWindow() != NULL
);
2840 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2846 return wxACC_NOT_IMPLEMENTED
;
2849 // Returns help text for this object or a child, similar to tooltip text.
2850 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2852 wxASSERT( GetWindow() != NULL
);
2856 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2862 return wxACC_NOT_IMPLEMENTED
;
2865 // Returns the keyboard shortcut for this object or child.
2866 // Return e.g. ALT+K
2867 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2869 wxASSERT( GetWindow() != NULL
);
2873 return wxACC_NOT_IMPLEMENTED
;
2876 // Returns a role constant.
2877 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2879 wxASSERT( GetWindow() != NULL
);
2883 // If a child, leave wxWidgets to call the function on the actual
2886 return wxACC_NOT_IMPLEMENTED
;
2888 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2889 return wxACC_NOT_IMPLEMENTED
;
2891 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2892 return wxACC_NOT_IMPLEMENTED
;
2895 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2896 return wxACC_NOT_IMPLEMENTED
;
2899 //*role = wxROLE_SYSTEM_CLIENT;
2900 *role
= wxROLE_SYSTEM_CLIENT
;
2904 return wxACC_NOT_IMPLEMENTED
;
2908 // Returns a state constant.
2909 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2911 wxASSERT( GetWindow() != NULL
);
2915 // If a child, leave wxWidgets to call the function on the actual
2918 return wxACC_NOT_IMPLEMENTED
;
2920 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2921 return wxACC_NOT_IMPLEMENTED
;
2924 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2925 return wxACC_NOT_IMPLEMENTED
;
2928 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2929 return wxACC_NOT_IMPLEMENTED
;
2936 return wxACC_NOT_IMPLEMENTED
;
2940 // Returns a localized string representing the value for the object
2942 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2944 wxASSERT( GetWindow() != NULL
);
2948 return wxACC_NOT_IMPLEMENTED
;
2951 // Selects the object or child.
2952 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2954 wxASSERT( GetWindow() != NULL
);
2958 return wxACC_NOT_IMPLEMENTED
;
2961 // Gets the window with the keyboard focus.
2962 // If childId is 0 and child is NULL, no object in
2963 // this subhierarchy has the focus.
2964 // If this object has the focus, child should be 'this'.
2965 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2967 wxASSERT( GetWindow() != NULL
);
2971 return wxACC_NOT_IMPLEMENTED
;
2974 // Gets a variant representing the selected children
2976 // Acceptable values:
2977 // - a null variant (IsNull() returns true)
2978 // - a list variant (GetType() == wxT("list")
2979 // - an integer representing the selected child element,
2980 // or 0 if this object is selected (GetType() == wxT("long")
2981 // - a "void*" pointer to a wxAccessible child object
2982 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2984 wxASSERT( GetWindow() != NULL
);
2988 return wxACC_NOT_IMPLEMENTED
;
2991 #endif // wxUSE_ACCESSIBILITY
2993 // ----------------------------------------------------------------------------
2995 // ----------------------------------------------------------------------------
2998 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3000 wxCoord widthTotal
) const
3002 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3004 x
= widthTotal
- x
- width
;