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 top-level parent's default item if it is this widget
298 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this),
301 if ( tlw
&& tlw
->GetDefaultItem() == this )
302 tlw
->SetDefaultItem(NULL
);
303 if ( tlw
&& tlw
->GetTmpDefaultItem() == this )
304 tlw
->SetTmpDefaultItem(NULL
);
307 // reset the dangling pointer our parent window may keep to us
310 m_parent
->RemoveChild(this);
315 #endif // wxUSE_CARET
318 delete m_windowValidator
;
319 #endif // wxUSE_VALIDATORS
321 #if wxUSE_CONSTRAINTS
322 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
323 // at deleted windows as they delete themselves.
324 DeleteRelatedConstraints();
328 // This removes any dangling pointers to this window in other windows'
329 // constraintsInvolvedIn lists.
330 UnsetConstraints(m_constraints
);
331 delete m_constraints
;
332 m_constraints
= NULL
;
334 #endif // wxUSE_CONSTRAINTS
336 if ( m_containingSizer
)
337 m_containingSizer
->Detach( (wxWindow
*)this );
339 delete m_windowSizer
;
341 #if wxUSE_DRAG_AND_DROP
343 #endif // wxUSE_DRAG_AND_DROP
347 #endif // wxUSE_TOOLTIPS
349 #if wxUSE_ACCESSIBILITY
354 bool wxWindowBase::Destroy()
361 bool wxWindowBase::Close(bool force
)
363 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
364 event
.SetEventObject(this);
365 event
.SetCanVeto(!force
);
367 // return false if window wasn't closed because the application vetoed the
369 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
372 bool wxWindowBase::DestroyChildren()
374 wxWindowList::compatibility_iterator node
;
377 // we iterate until the list becomes empty
378 node
= GetChildren().GetFirst();
382 wxWindow
*child
= node
->GetData();
384 // note that we really want to call delete and not ->Destroy() here
385 // because we want to delete the child immediately, before we are
386 // deleted, and delayed deletion would result in problems as our (top
387 // level) child could outlive its parent
390 wxASSERT_MSG( !GetChildren().Find(child
),
391 wxT("child didn't remove itself using RemoveChild()") );
397 // ----------------------------------------------------------------------------
398 // size/position related methods
399 // ----------------------------------------------------------------------------
401 // centre the window with respect to its parent in either (or both) directions
402 void wxWindowBase::DoCentre(int dir
)
404 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
405 _T("this method only implements centering child windows") );
407 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
410 // fits the window around the children
411 void wxWindowBase::Fit()
413 if ( !GetChildren().empty() )
415 SetSize(GetBestSize());
417 //else: do nothing if we have no children
420 // fits virtual size (ie. scrolled area etc.) around children
421 void wxWindowBase::FitInside()
423 if ( GetChildren().GetCount() > 0 )
425 SetVirtualSize( GetBestVirtualSize() );
429 // On Mac, scrollbars are explicitly children.
431 static bool wxHasRealChildren(const wxWindowBase
* win
)
433 int realChildCount
= 0;
435 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
437 node
= node
->GetNext() )
439 wxWindow
*win
= node
->GetData();
440 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
443 return (realChildCount
> 0);
447 void wxWindowBase::InvalidateBestSize()
449 m_bestSizeCache
= wxDefaultSize
;
451 // parent's best size calculation may depend on its children's
452 // as long as child window we are in is not top level window itself
453 // (because the TLW size is never resized automatically)
454 // so let's invalidate it as well to be safe:
455 if (m_parent
&& !IsTopLevel())
456 m_parent
->InvalidateBestSize();
459 // return the size best suited for the current window
460 wxSize
wxWindowBase::DoGetBestSize() const
466 best
= GetWindowSizeForVirtualSize(m_windowSizer
->GetMinSize());
468 #if wxUSE_CONSTRAINTS
469 else if ( m_constraints
)
471 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
473 // our minimal acceptable size is such that all our windows fit inside
477 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
479 node
= node
->GetNext() )
481 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
484 // it's not normal that we have an unconstrained child, but
485 // what can we do about it?
489 int x
= c
->right
.GetValue(),
490 y
= c
->bottom
.GetValue();
498 // TODO: we must calculate the overlaps somehow, otherwise we
499 // will never return a size bigger than the current one :-(
502 best
= wxSize(maxX
, maxY
);
504 #endif // wxUSE_CONSTRAINTS
505 else if ( !GetChildren().empty()
507 && wxHasRealChildren(this)
511 // our minimal acceptable size is such that all our visible child
512 // windows fit inside
516 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
518 node
= node
->GetNext() )
520 wxWindow
*win
= node
->GetData();
521 if ( win
->IsTopLevel()
524 || wxDynamicCast(win
, wxStatusBar
)
525 #endif // wxUSE_STATUSBAR
528 // dialogs and frames lie in different top level windows -
529 // don't deal with them here; as for the status bars, they
530 // don't lie in the client area at all
535 win
->GetPosition(&wx
, &wy
);
537 // if the window hadn't been positioned yet, assume that it is in
539 if ( wx
== wxDefaultCoord
)
541 if ( wy
== wxDefaultCoord
)
544 win
->GetSize(&ww
, &wh
);
545 if ( wx
+ ww
> maxX
)
547 if ( wy
+ wh
> maxY
)
551 best
= wxSize(maxX
, maxY
);
553 else // ! has children
555 // for a generic window there is no natural best size so, if the
556 // minimal size is not set, use the current size but take care to
557 // remember it as minimal size for the next time because our best size
558 // should be constant: otherwise we could get into a situation when the
559 // window is initially at some size, then expanded to a larger size and
560 // then, when the containing window is shrunk back (because our initial
561 // best size had been used for computing the parent min size), we can't
562 // be shrunk back any more because our best size is now bigger
563 wxSize size
= GetMinSize();
564 if ( !size
.IsFullySpecified() )
566 size
.SetDefaults(GetSize());
567 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
570 // return as-is, unadjusted by the client size difference.
574 // Add any difference between size and client size
575 wxSize diff
= GetSize() - GetClientSize();
576 best
.x
+= wxMax(0, diff
.x
);
577 best
.y
+= wxMax(0, diff
.y
);
583 wxSize
wxWindowBase::GetBestFittingSize() const
585 // merge the best size with the min size, giving priority to the min size
586 wxSize min
= GetMinSize();
587 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
589 wxSize best
= GetBestSize();
590 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
591 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
597 void wxWindowBase::SetBestFittingSize(const wxSize
& size
)
599 // Set the min size to the size passed in. This will usually either be
600 // wxDefaultSize or the size passed to this window's ctor/Create function.
603 // Merge the size with the best size if needed
604 wxSize best
= GetBestFittingSize();
606 // If the current size doesn't match then change it
607 if (GetSize() != best
)
612 // by default the origin is not shifted
613 wxPoint
wxWindowBase::GetClientAreaOrigin() const
618 // set the min/max size of the window
619 void wxWindowBase::DoSetSizeHints(int minW
, int minH
,
621 int WXUNUSED(incW
), int WXUNUSED(incH
))
623 // setting min width greater than max width leads to infinite loops under
624 // X11 and generally doesn't make any sense, so don't allow it
625 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
626 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
627 _T("min width/height must be less than max width/height!") );
635 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
637 if ( m_windowVariant
!= variant
)
639 m_windowVariant
= variant
;
641 DoSetWindowVariant(variant
);
645 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
647 // adjust the font height to correspond to our new variant (notice that
648 // we're only called if something really changed)
649 wxFont font
= GetFont();
650 int size
= font
.GetPointSize();
653 case wxWINDOW_VARIANT_NORMAL
:
656 case wxWINDOW_VARIANT_SMALL
:
661 case wxWINDOW_VARIANT_MINI
:
666 case wxWINDOW_VARIANT_LARGE
:
672 wxFAIL_MSG(_T("unexpected window variant"));
676 font
.SetPointSize(size
);
680 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
683 m_minVirtualWidth
= minW
;
684 m_maxVirtualWidth
= maxW
;
685 m_minVirtualHeight
= minH
;
686 m_maxVirtualHeight
= maxH
;
689 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
691 if ( m_minVirtualWidth
!= wxDefaultCoord
&& m_minVirtualWidth
> x
)
692 x
= m_minVirtualWidth
;
693 if ( m_maxVirtualWidth
!= wxDefaultCoord
&& m_maxVirtualWidth
< x
)
694 x
= m_maxVirtualWidth
;
695 if ( m_minVirtualHeight
!= wxDefaultCoord
&& m_minVirtualHeight
> y
)
696 y
= m_minVirtualHeight
;
697 if ( m_maxVirtualHeight
!= wxDefaultCoord
&& m_maxVirtualHeight
< y
)
698 y
= m_maxVirtualHeight
;
700 m_virtualSize
= wxSize(x
, y
);
703 wxSize
wxWindowBase::DoGetVirtualSize() const
705 // we should use the entire client area so if it is greater than our
706 // virtual size, expand it to fit (otherwise if the window is big enough we
707 // wouldn't be using parts of it)
708 wxSize size
= GetClientSize();
709 if ( m_virtualSize
.x
> size
.x
)
710 size
.x
= m_virtualSize
.x
;
712 if ( m_virtualSize
.y
>= size
.y
)
713 size
.y
= m_virtualSize
.y
;
718 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
720 // screen position is the same as (0, 0) in client coords for non TLWs (and
721 // TLWs override this method)
727 ClientToScreen(x
, y
);
730 // ----------------------------------------------------------------------------
731 // show/hide/enable/disable the window
732 // ----------------------------------------------------------------------------
734 bool wxWindowBase::Show(bool show
)
736 if ( show
!= m_isShown
)
748 bool wxWindowBase::Enable(bool enable
)
750 if ( enable
!= m_isEnabled
)
752 m_isEnabled
= enable
;
762 bool wxWindowBase::IsShownOnScreen() const
765 (GetParent() == NULL
|| GetParent()->IsShownOnScreen());
768 // ----------------------------------------------------------------------------
770 // ----------------------------------------------------------------------------
772 bool wxWindowBase::IsTopLevel() const
777 // ----------------------------------------------------------------------------
778 // reparenting the window
779 // ----------------------------------------------------------------------------
781 void wxWindowBase::AddChild(wxWindowBase
*child
)
783 wxCHECK_RET( child
, wxT("can't add a NULL child") );
785 // this should never happen and it will lead to a crash later if it does
786 // because RemoveChild() will remove only one node from the children list
787 // and the other(s) one(s) will be left with dangling pointers in them
788 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
790 GetChildren().Append((wxWindow
*)child
);
791 child
->SetParent(this);
794 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
796 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
798 GetChildren().DeleteObject((wxWindow
*)child
);
799 child
->SetParent(NULL
);
802 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
804 wxWindow
*oldParent
= GetParent();
805 if ( newParent
== oldParent
)
811 // unlink this window from the existing parent.
814 oldParent
->RemoveChild(this);
818 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
821 // add it to the new one
824 newParent
->AddChild(this);
828 wxTopLevelWindows
.Append((wxWindow
*)this);
834 // ----------------------------------------------------------------------------
835 // event handler stuff
836 // ----------------------------------------------------------------------------
838 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
840 wxEvtHandler
*handlerOld
= GetEventHandler();
842 handler
->SetNextHandler(handlerOld
);
845 GetEventHandler()->SetPreviousHandler(handler
);
847 SetEventHandler(handler
);
850 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
852 wxEvtHandler
*handlerA
= GetEventHandler();
855 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
856 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
859 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
860 SetEventHandler(handlerB
);
865 handlerA
= (wxEvtHandler
*)NULL
;
872 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
874 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
876 wxEvtHandler
*handlerPrev
= NULL
,
877 *handlerCur
= GetEventHandler();
880 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
882 if ( handlerCur
== handler
)
886 handlerPrev
->SetNextHandler(handlerNext
);
890 SetEventHandler(handlerNext
);
895 handlerNext
->SetPreviousHandler ( handlerPrev
);
898 handler
->SetNextHandler(NULL
);
899 handler
->SetPreviousHandler(NULL
);
904 handlerPrev
= handlerCur
;
905 handlerCur
= handlerNext
;
908 wxFAIL_MSG( _T("where has the event handler gone?") );
913 // ----------------------------------------------------------------------------
915 // ----------------------------------------------------------------------------
917 void wxWindowBase::InheritAttributes()
919 const wxWindowBase
* const parent
= GetParent();
923 // we only inherit attributes which had been explicitly set for the parent
924 // which ensures that this only happens if the user really wants it and
925 // not by default which wouldn't make any sense in modern GUIs where the
926 // controls don't all use the same fonts (nor colours)
927 if ( parent
->m_inheritFont
&& !m_hasFont
)
928 SetFont(parent
->GetFont());
930 // in addition, there is a possibility to explicitly forbid inheriting
931 // colours at each class level by overriding ShouldInheritColours()
932 if ( ShouldInheritColours() )
934 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
935 SetForegroundColour(parent
->GetForegroundColour());
937 // inheriting (solid) background colour is wrong as it totally breaks
938 // any kind of themed backgrounds
940 // instead, the controls should use the same background as their parent
941 // (ideally by not drawing it at all)
943 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
944 SetBackgroundColour(parent
->GetBackgroundColour());
949 /* static */ wxVisualAttributes
950 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
952 // it is important to return valid values for all attributes from here,
953 // GetXXX() below rely on this
954 wxVisualAttributes attrs
;
955 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
956 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
958 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
959 // the usual background colour than wxSYS_COLOUR_BTNFACE.
960 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
961 // colour on other platforms.
963 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
964 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
966 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
971 wxColour
wxWindowBase::GetBackgroundColour() const
973 if ( !m_backgroundColour
.Ok() )
975 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
977 // get our default background colour
978 wxColour colBg
= GetDefaultAttributes().colBg
;
980 // we must return some valid colour to avoid redoing this every time
981 // and also to avoid surprizing the applications written for older
982 // wxWidgets versions where GetBackgroundColour() always returned
983 // something -- so give them something even if it doesn't make sense
984 // for this window (e.g. it has a themed background)
986 colBg
= GetClassDefaultAttributes().colBg
;
991 return m_backgroundColour
;
994 wxColour
wxWindowBase::GetForegroundColour() const
996 // logic is the same as above
997 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
999 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
1001 wxColour colFg
= GetDefaultAttributes().colFg
;
1004 colFg
= GetClassDefaultAttributes().colFg
;
1009 return m_foregroundColour
;
1012 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1014 if ( colour
== m_backgroundColour
)
1017 m_hasBgCol
= colour
.Ok();
1018 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1019 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1021 m_inheritBgCol
= m_hasBgCol
;
1022 m_backgroundColour
= colour
;
1023 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1027 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1029 if (colour
== m_foregroundColour
)
1032 m_hasFgCol
= colour
.Ok();
1033 m_inheritFgCol
= m_hasFgCol
;
1034 m_foregroundColour
= colour
;
1035 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1039 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1041 // setting an invalid cursor is ok, it means that we don't have any special
1043 if ( m_cursor
== cursor
)
1054 wxFont
wxWindowBase::GetFont() const
1056 // logic is the same as in GetBackgroundColour()
1059 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1061 wxFont font
= GetDefaultAttributes().font
;
1063 font
= GetClassDefaultAttributes().font
;
1071 bool wxWindowBase::SetFont(const wxFont
& font
)
1073 if ( font
== m_font
)
1080 m_hasFont
= font
.Ok();
1081 m_inheritFont
= m_hasFont
;
1083 InvalidateBestSize();
1090 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1092 m_hasCustomPalette
= true;
1095 // VZ: can anyone explain me what do we do here?
1096 wxWindowDC
d((wxWindow
*) this);
1100 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1102 wxWindow
*win
= (wxWindow
*)this;
1103 while ( win
&& !win
->HasCustomPalette() )
1105 win
= win
->GetParent();
1111 #endif // wxUSE_PALETTE
1114 void wxWindowBase::SetCaret(wxCaret
*caret
)
1125 wxASSERT_MSG( m_caret
->GetWindow() == this,
1126 wxT("caret should be created associated to this window") );
1129 #endif // wxUSE_CARET
1131 #if wxUSE_VALIDATORS
1132 // ----------------------------------------------------------------------------
1134 // ----------------------------------------------------------------------------
1136 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1138 if ( m_windowValidator
)
1139 delete m_windowValidator
;
1141 m_windowValidator
= (wxValidator
*)validator
.Clone();
1143 if ( m_windowValidator
)
1144 m_windowValidator
->SetWindow(this);
1146 #endif // wxUSE_VALIDATORS
1148 // ----------------------------------------------------------------------------
1149 // update region stuff
1150 // ----------------------------------------------------------------------------
1152 wxRect
wxWindowBase::GetUpdateClientRect() const
1154 wxRegion rgnUpdate
= GetUpdateRegion();
1155 rgnUpdate
.Intersect(GetClientRect());
1156 wxRect rectUpdate
= rgnUpdate
.GetBox();
1157 wxPoint ptOrigin
= GetClientAreaOrigin();
1158 rectUpdate
.x
-= ptOrigin
.x
;
1159 rectUpdate
.y
-= ptOrigin
.y
;
1164 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1166 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1169 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1171 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1174 void wxWindowBase::ClearBackground()
1176 // wxGTK uses its own version, no need to add never used code
1178 wxClientDC
dc((wxWindow
*)this);
1179 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1180 dc
.SetBackground(brush
);
1185 // ----------------------------------------------------------------------------
1186 // find child window by id or name
1187 // ----------------------------------------------------------------------------
1189 wxWindow
*wxWindowBase::FindWindow(long id
) const
1191 if ( id
== m_windowId
)
1192 return (wxWindow
*)this;
1194 wxWindowBase
*res
= (wxWindow
*)NULL
;
1195 wxWindowList::compatibility_iterator node
;
1196 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1198 wxWindowBase
*child
= node
->GetData();
1199 res
= child
->FindWindow( id
);
1202 return (wxWindow
*)res
;
1205 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1207 if ( name
== m_windowName
)
1208 return (wxWindow
*)this;
1210 wxWindowBase
*res
= (wxWindow
*)NULL
;
1211 wxWindowList::compatibility_iterator node
;
1212 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1214 wxWindow
*child
= node
->GetData();
1215 res
= child
->FindWindow(name
);
1218 return (wxWindow
*)res
;
1222 // find any window by id or name or label: If parent is non-NULL, look through
1223 // children for a label or title matching the specified string. If NULL, look
1224 // through all top-level windows.
1226 // to avoid duplicating code we reuse the same helper function but with
1227 // different comparators
1229 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1230 const wxString
& label
, long id
);
1233 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1236 return win
->GetLabel() == label
;
1240 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1243 return win
->GetName() == label
;
1247 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1250 return win
->GetId() == id
;
1253 // recursive helper for the FindWindowByXXX() functions
1255 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1256 const wxString
& label
,
1258 wxFindWindowCmp cmp
)
1262 // see if this is the one we're looking for
1263 if ( (*cmp
)(parent
, label
, id
) )
1264 return (wxWindow
*)parent
;
1266 // It wasn't, so check all its children
1267 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1269 node
= node
->GetNext() )
1271 // recursively check each child
1272 wxWindow
*win
= (wxWindow
*)node
->GetData();
1273 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1283 // helper for FindWindowByXXX()
1285 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1286 const wxString
& label
,
1288 wxFindWindowCmp cmp
)
1292 // just check parent and all its children
1293 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1296 // start at very top of wx's windows
1297 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1299 node
= node
->GetNext() )
1301 // recursively check each window & its children
1302 wxWindow
*win
= node
->GetData();
1303 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1313 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1315 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1320 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1322 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1326 // fall back to the label
1327 win
= FindWindowByLabel(title
, parent
);
1335 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1337 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1340 // ----------------------------------------------------------------------------
1341 // dialog oriented functions
1342 // ----------------------------------------------------------------------------
1344 void wxWindowBase::MakeModal(bool modal
)
1346 // Disable all other windows
1349 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1352 wxWindow
*win
= node
->GetData();
1354 win
->Enable(!modal
);
1356 node
= node
->GetNext();
1361 bool wxWindowBase::Validate()
1363 #if wxUSE_VALIDATORS
1364 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1366 wxWindowList::compatibility_iterator node
;
1367 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1369 wxWindowBase
*child
= node
->GetData();
1370 wxValidator
*validator
= child
->GetValidator();
1371 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1376 if ( recurse
&& !child
->Validate() )
1381 #endif // wxUSE_VALIDATORS
1386 bool wxWindowBase::TransferDataToWindow()
1388 #if wxUSE_VALIDATORS
1389 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1391 wxWindowList::compatibility_iterator node
;
1392 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1394 wxWindowBase
*child
= node
->GetData();
1395 wxValidator
*validator
= child
->GetValidator();
1396 if ( validator
&& !validator
->TransferToWindow() )
1398 wxLogWarning(_("Could not transfer data to window"));
1400 wxLog::FlushActive();
1408 if ( !child
->TransferDataToWindow() )
1410 // warning already given
1415 #endif // wxUSE_VALIDATORS
1420 bool wxWindowBase::TransferDataFromWindow()
1422 #if wxUSE_VALIDATORS
1423 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1425 wxWindowList::compatibility_iterator node
;
1426 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1428 wxWindow
*child
= node
->GetData();
1429 wxValidator
*validator
= child
->GetValidator();
1430 if ( validator
&& !validator
->TransferFromWindow() )
1432 // nop warning here because the application is supposed to give
1433 // one itself - we don't know here what might have gone wrongly
1440 if ( !child
->TransferDataFromWindow() )
1442 // warning already given
1447 #endif // wxUSE_VALIDATORS
1452 void wxWindowBase::InitDialog()
1454 wxInitDialogEvent
event(GetId());
1455 event
.SetEventObject( this );
1456 GetEventHandler()->ProcessEvent(event
);
1459 // ----------------------------------------------------------------------------
1460 // context-sensitive help support
1461 // ----------------------------------------------------------------------------
1465 // associate this help text with this window
1466 void wxWindowBase::SetHelpText(const wxString
& text
)
1468 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1471 helpProvider
->AddHelp(this, text
);
1475 // associate this help text with all windows with the same id as this
1477 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1479 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1482 helpProvider
->AddHelp(GetId(), text
);
1486 // get the help string associated with this window (may be empty)
1487 // default implementation forwards calls to the help provider
1489 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1490 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1493 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1496 text
= helpProvider
->GetHelp(this);
1502 // show help for this window
1503 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1505 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1508 if ( helpProvider
->ShowHelpAtPoint(this, event
.GetPosition(), event
.GetOrigin()) )
1510 // skip the event.Skip() below
1518 #endif // wxUSE_HELP
1520 // ----------------------------------------------------------------------------
1521 // tooltipsroot.Replace("\\", "/");
1522 // ----------------------------------------------------------------------------
1526 void wxWindowBase::SetToolTip( const wxString
&tip
)
1528 // don't create the new tooltip if we already have one
1531 m_tooltip
->SetTip( tip
);
1535 SetToolTip( new wxToolTip( tip
) );
1538 // setting empty tooltip text does not remove the tooltip any more - use
1539 // SetToolTip((wxToolTip *)NULL) for this
1542 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1544 if ( m_tooltip
!= tooltip
)
1549 m_tooltip
= tooltip
;
1553 #endif // wxUSE_TOOLTIPS
1555 // ----------------------------------------------------------------------------
1556 // constraints and sizers
1557 // ----------------------------------------------------------------------------
1559 #if wxUSE_CONSTRAINTS
1561 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1563 if ( m_constraints
)
1565 UnsetConstraints(m_constraints
);
1566 delete m_constraints
;
1568 m_constraints
= constraints
;
1569 if ( m_constraints
)
1571 // Make sure other windows know they're part of a 'meaningful relationship'
1572 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1573 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1574 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1575 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1576 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1577 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1578 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1579 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1580 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1581 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1582 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1583 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1584 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1585 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1586 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1587 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1591 // This removes any dangling pointers to this window in other windows'
1592 // constraintsInvolvedIn lists.
1593 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1597 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1598 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1599 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1600 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1601 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1602 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1603 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1604 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1605 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1606 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1607 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1608 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1609 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1610 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1611 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1612 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1616 // Back-pointer to other windows we're involved with, so if we delete this
1617 // window, we must delete any constraints we're involved with.
1618 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1620 if ( !m_constraintsInvolvedIn
)
1621 m_constraintsInvolvedIn
= new wxWindowList
;
1622 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1623 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1626 // REMOVE back-pointer to other windows we're involved with.
1627 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1629 if ( m_constraintsInvolvedIn
)
1630 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1633 // Reset any constraints that mention this window
1634 void wxWindowBase::DeleteRelatedConstraints()
1636 if ( m_constraintsInvolvedIn
)
1638 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1641 wxWindow
*win
= node
->GetData();
1642 wxLayoutConstraints
*constr
= win
->GetConstraints();
1644 // Reset any constraints involving this window
1647 constr
->left
.ResetIfWin(this);
1648 constr
->top
.ResetIfWin(this);
1649 constr
->right
.ResetIfWin(this);
1650 constr
->bottom
.ResetIfWin(this);
1651 constr
->width
.ResetIfWin(this);
1652 constr
->height
.ResetIfWin(this);
1653 constr
->centreX
.ResetIfWin(this);
1654 constr
->centreY
.ResetIfWin(this);
1657 wxWindowList::compatibility_iterator next
= node
->GetNext();
1658 m_constraintsInvolvedIn
->Erase(node
);
1662 delete m_constraintsInvolvedIn
;
1663 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1667 #endif // wxUSE_CONSTRAINTS
1669 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1671 if ( sizer
== m_windowSizer
)
1674 if ( m_windowSizer
)
1676 m_windowSizer
->SetContainingWindow(NULL
);
1679 delete m_windowSizer
;
1682 m_windowSizer
= sizer
;
1683 if ( m_windowSizer
)
1685 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
1688 SetAutoLayout(m_windowSizer
!= NULL
);
1691 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1693 SetSizer( sizer
, deleteOld
);
1694 sizer
->SetSizeHints( (wxWindow
*) this );
1698 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1700 // adding a window to a sizer twice is going to result in fatal and
1701 // hard to debug problems later because when deleting the second
1702 // associated wxSizerItem we're going to dereference a dangling
1703 // pointer; so try to detect this as early as possible
1704 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1705 _T("Adding a window to the same sizer twice?") );
1707 m_containingSizer
= sizer
;
1710 #if wxUSE_CONSTRAINTS
1712 void wxWindowBase::SatisfyConstraints()
1714 wxLayoutConstraints
*constr
= GetConstraints();
1715 bool wasOk
= constr
&& constr
->AreSatisfied();
1717 ResetConstraints(); // Mark all constraints as unevaluated
1721 // if we're a top level panel (i.e. our parent is frame/dialog), our
1722 // own constraints will never be satisfied any more unless we do it
1726 while ( noChanges
> 0 )
1728 LayoutPhase1(&noChanges
);
1732 LayoutPhase2(&noChanges
);
1735 #endif // wxUSE_CONSTRAINTS
1737 bool wxWindowBase::Layout()
1739 // If there is a sizer, use it instead of the constraints
1743 GetVirtualSize(&w
, &h
);
1744 GetSizer()->SetDimension( 0, 0, w
, h
);
1746 #if wxUSE_CONSTRAINTS
1749 SatisfyConstraints(); // Find the right constraints values
1750 SetConstraintSizes(); // Recursively set the real window sizes
1757 #if wxUSE_CONSTRAINTS
1759 // first phase of the constraints evaluation: set our own constraints
1760 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1762 wxLayoutConstraints
*constr
= GetConstraints();
1764 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1767 // second phase: set the constraints for our children
1768 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1775 // Layout grand children
1781 // Do a phase of evaluating child constraints
1782 bool wxWindowBase::DoPhase(int phase
)
1784 // the list containing the children for which the constraints are already
1786 wxWindowList succeeded
;
1788 // the max number of iterations we loop before concluding that we can't set
1790 static const int maxIterations
= 500;
1792 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1796 // loop over all children setting their constraints
1797 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1799 node
= node
->GetNext() )
1801 wxWindow
*child
= node
->GetData();
1802 if ( child
->IsTopLevel() )
1804 // top level children are not inside our client area
1808 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1810 // this one is either already ok or nothing we can do about it
1814 int tempNoChanges
= 0;
1815 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1816 : child
->LayoutPhase2(&tempNoChanges
);
1817 noChanges
+= tempNoChanges
;
1821 succeeded
.Append(child
);
1827 // constraints are set
1835 void wxWindowBase::ResetConstraints()
1837 wxLayoutConstraints
*constr
= GetConstraints();
1840 constr
->left
.SetDone(false);
1841 constr
->top
.SetDone(false);
1842 constr
->right
.SetDone(false);
1843 constr
->bottom
.SetDone(false);
1844 constr
->width
.SetDone(false);
1845 constr
->height
.SetDone(false);
1846 constr
->centreX
.SetDone(false);
1847 constr
->centreY
.SetDone(false);
1850 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1853 wxWindow
*win
= node
->GetData();
1854 if ( !win
->IsTopLevel() )
1855 win
->ResetConstraints();
1856 node
= node
->GetNext();
1860 // Need to distinguish between setting the 'fake' size for windows and sizers,
1861 // and setting the real values.
1862 void wxWindowBase::SetConstraintSizes(bool recurse
)
1864 wxLayoutConstraints
*constr
= GetConstraints();
1865 if ( constr
&& constr
->AreSatisfied() )
1867 int x
= constr
->left
.GetValue();
1868 int y
= constr
->top
.GetValue();
1869 int w
= constr
->width
.GetValue();
1870 int h
= constr
->height
.GetValue();
1872 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1873 (constr
->height
.GetRelationship() != wxAsIs
) )
1875 SetSize(x
, y
, w
, h
);
1879 // If we don't want to resize this window, just move it...
1885 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1886 GetClassInfo()->GetClassName(),
1892 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1895 wxWindow
*win
= node
->GetData();
1896 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1897 win
->SetConstraintSizes();
1898 node
= node
->GetNext();
1903 // Only set the size/position of the constraint (if any)
1904 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1906 wxLayoutConstraints
*constr
= GetConstraints();
1909 if ( x
!= wxDefaultCoord
)
1911 constr
->left
.SetValue(x
);
1912 constr
->left
.SetDone(true);
1914 if ( y
!= wxDefaultCoord
)
1916 constr
->top
.SetValue(y
);
1917 constr
->top
.SetDone(true);
1919 if ( w
!= wxDefaultCoord
)
1921 constr
->width
.SetValue(w
);
1922 constr
->width
.SetDone(true);
1924 if ( h
!= wxDefaultCoord
)
1926 constr
->height
.SetValue(h
);
1927 constr
->height
.SetDone(true);
1932 void wxWindowBase::MoveConstraint(int x
, int y
)
1934 wxLayoutConstraints
*constr
= GetConstraints();
1937 if ( x
!= wxDefaultCoord
)
1939 constr
->left
.SetValue(x
);
1940 constr
->left
.SetDone(true);
1942 if ( y
!= wxDefaultCoord
)
1944 constr
->top
.SetValue(y
);
1945 constr
->top
.SetDone(true);
1950 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1952 wxLayoutConstraints
*constr
= GetConstraints();
1955 *w
= constr
->width
.GetValue();
1956 *h
= constr
->height
.GetValue();
1962 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1964 wxLayoutConstraints
*constr
= GetConstraints();
1967 *w
= constr
->width
.GetValue();
1968 *h
= constr
->height
.GetValue();
1971 GetClientSize(w
, h
);
1974 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1976 wxLayoutConstraints
*constr
= GetConstraints();
1979 *x
= constr
->left
.GetValue();
1980 *y
= constr
->top
.GetValue();
1986 #endif // wxUSE_CONSTRAINTS
1988 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1990 // don't do it for the dialogs/frames - they float independently of their
1992 if ( !IsTopLevel() )
1994 wxWindow
*parent
= GetParent();
1995 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1997 wxPoint
pt(parent
->GetClientAreaOrigin());
2004 // ----------------------------------------------------------------------------
2005 // do Update UI processing for child controls
2006 // ----------------------------------------------------------------------------
2008 void wxWindowBase::UpdateWindowUI(long flags
)
2010 wxUpdateUIEvent
event(GetId());
2011 event
.SetEventObject(this);
2013 if ( GetEventHandler()->ProcessEvent(event
) )
2015 DoUpdateWindowUI(event
);
2018 if (flags
& wxUPDATE_UI_RECURSE
)
2020 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2023 wxWindow
* child
= (wxWindow
*) node
->GetData();
2024 child
->UpdateWindowUI(flags
);
2025 node
= node
->GetNext();
2030 // do the window-specific processing after processing the update event
2031 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2033 if ( event
.GetSetEnabled() )
2034 Enable(event
.GetEnabled());
2036 if ( event
.GetSetShown() )
2037 Show(event
.GetShown());
2041 // call internal idle recursively
2042 // may be obsolete (wait until OnIdle scheme stabilises)
2043 void wxWindowBase::ProcessInternalIdle()
2047 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2050 wxWindow
*child
= node
->GetData();
2051 child
->ProcessInternalIdle();
2052 node
= node
->GetNext();
2057 // ----------------------------------------------------------------------------
2058 // dialog units translations
2059 // ----------------------------------------------------------------------------
2061 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2063 int charWidth
= GetCharWidth();
2064 int charHeight
= GetCharHeight();
2065 wxPoint pt2
= wxDefaultPosition
;
2066 if (pt
.x
!= wxDefaultCoord
)
2067 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2068 if (pt
.y
!= wxDefaultCoord
)
2069 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2074 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2076 int charWidth
= GetCharWidth();
2077 int charHeight
= GetCharHeight();
2078 wxPoint pt2
= wxDefaultPosition
;
2079 if (pt
.x
!= wxDefaultCoord
)
2080 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2081 if (pt
.y
!= wxDefaultCoord
)
2082 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2087 // ----------------------------------------------------------------------------
2089 // ----------------------------------------------------------------------------
2091 // propagate the colour change event to the subwindows
2092 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2094 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2097 // Only propagate to non-top-level windows
2098 wxWindow
*win
= node
->GetData();
2099 if ( !win
->IsTopLevel() )
2101 wxSysColourChangedEvent event2
;
2102 event
.SetEventObject(win
);
2103 win
->GetEventHandler()->ProcessEvent(event2
);
2106 node
= node
->GetNext();
2112 // the default action is to populate dialog with data when it's created,
2113 // and nudge the UI into displaying itself correctly in case
2114 // we've turned the wxUpdateUIEvents frequency down low.
2115 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2117 TransferDataToWindow();
2119 // Update the UI at this point
2120 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2123 // methods for drawing the sizers in a visible way
2126 static void DrawSizers(wxWindowBase
*win
);
2128 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2130 wxClientDC
dc((wxWindow
*)win
);
2131 dc
.SetPen(*wxRED_PEN
);
2132 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2133 dc
.DrawRectangle(rect
.Deflate(1, 1));
2136 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2138 const wxSizerItemList
& items
= sizer
->GetChildren();
2139 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2144 wxSizerItem
*item
= *i
;
2145 if ( item
->IsSizer() )
2147 DrawBorder(win
, item
->GetRect().Deflate(2));
2148 DrawSizer(win
, item
->GetSizer());
2150 else if ( item
->IsSpacer() )
2152 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2154 else if ( item
->IsWindow() )
2156 DrawSizers(item
->GetWindow());
2161 static void DrawSizers(wxWindowBase
*win
)
2163 wxSizer
*sizer
= win
->GetSizer();
2166 DrawBorder(win
, win
->GetClientSize());
2167 DrawSizer(win
, sizer
);
2169 else // no sizer, still recurse into the children
2171 const wxWindowList
& children
= win
->GetChildren();
2172 for ( wxWindowList::const_iterator i
= children
.begin(),
2173 end
= children
.end();
2182 #endif // __WXDEBUG__
2184 // process special middle clicks
2185 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2187 if ( event
.ControlDown() && event
.AltDown() )
2190 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2191 if ( event
.ShiftDown() )
2196 #endif // __WXDEBUG__
2199 // don't translate these strings, they're for diagnostics purposes only
2201 msg
.Printf(_T("wxWidgets Library (%s port)\n")
2202 _T("Version %d.%d.%d%s%s, compiled at %s %s%s\n")
2203 _T("Copyright (c) 1995-2006 wxWidgets team"),
2204 wxPlatformInfo().GetPortIdName().c_str(),
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()
2227 wxMessageBox(msg
, _T("wxWidgets information"),
2228 wxICON_INFORMATION
| wxOK
,
2232 #endif // wxUSE_MSGDLG
2238 // ----------------------------------------------------------------------------
2240 // ----------------------------------------------------------------------------
2242 #if wxUSE_ACCESSIBILITY
2243 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2245 if (m_accessible
&& (accessible
!= m_accessible
))
2246 delete m_accessible
;
2247 m_accessible
= accessible
;
2249 m_accessible
->SetWindow((wxWindow
*) this);
2252 // Returns the accessible object, creating if necessary.
2253 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2256 m_accessible
= CreateAccessible();
2257 return m_accessible
;
2260 // Override to create a specific accessible object.
2261 wxAccessible
* wxWindowBase::CreateAccessible()
2263 return new wxWindowAccessible((wxWindow
*) this);
2268 // ----------------------------------------------------------------------------
2269 // list classes implementation
2270 // ----------------------------------------------------------------------------
2274 #include "wx/listimpl.cpp"
2275 WX_DEFINE_LIST(wxWindowList
)
2279 void wxWindowListNode::DeleteData()
2281 delete (wxWindow
*)GetData();
2286 // ----------------------------------------------------------------------------
2288 // ----------------------------------------------------------------------------
2290 wxBorder
wxWindowBase::GetBorder(long flags
) const
2292 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2293 if ( border
== wxBORDER_DEFAULT
)
2295 border
= GetDefaultBorder();
2301 wxBorder
wxWindowBase::GetDefaultBorder() const
2303 return wxBORDER_NONE
;
2306 // ----------------------------------------------------------------------------
2308 // ----------------------------------------------------------------------------
2310 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2312 // here we just check if the point is inside the window or not
2314 // check the top and left border first
2315 bool outside
= x
< 0 || y
< 0;
2318 // check the right and bottom borders too
2319 wxSize size
= GetSize();
2320 outside
= x
>= size
.x
|| y
>= size
.y
;
2323 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2326 // ----------------------------------------------------------------------------
2328 // ----------------------------------------------------------------------------
2330 struct WXDLLEXPORT wxWindowNext
2334 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2335 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2336 bool wxWindowBase::ms_winCaptureChanging
= false;
2338 void wxWindowBase::CaptureMouse()
2340 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2342 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2344 ms_winCaptureChanging
= true;
2346 wxWindow
*winOld
= GetCapture();
2349 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2352 wxWindowNext
*item
= new wxWindowNext
;
2354 item
->next
= ms_winCaptureNext
;
2355 ms_winCaptureNext
= item
;
2357 //else: no mouse capture to save
2360 ms_winCaptureCurrent
= (wxWindow
*)this;
2362 ms_winCaptureChanging
= false;
2365 void wxWindowBase::ReleaseMouse()
2367 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2369 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2371 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2373 ms_winCaptureChanging
= true;
2376 ms_winCaptureCurrent
= NULL
;
2378 if ( ms_winCaptureNext
)
2380 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2381 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2383 wxWindowNext
*item
= ms_winCaptureNext
;
2384 ms_winCaptureNext
= item
->next
;
2387 //else: stack is empty, no previous capture
2389 ms_winCaptureChanging
= false;
2391 wxLogTrace(_T("mousecapture"),
2392 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2393 wx_static_cast(void*, GetCapture()));
2396 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2398 wxMouseCaptureLostEvent
event(win
->GetId());
2399 event
.SetEventObject(win
);
2400 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2402 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2407 void wxWindowBase::NotifyCaptureLost()
2409 // don't do anything if capture lost was expected, i.e. resulted from
2410 // a wx call to ReleaseMouse or CaptureMouse:
2411 if ( ms_winCaptureChanging
)
2414 // if the capture was lost unexpectedly, notify every window that has
2415 // capture (on stack or current) about it and clear the stack:
2417 if ( ms_winCaptureCurrent
)
2419 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2420 ms_winCaptureCurrent
= NULL
;
2423 while ( ms_winCaptureNext
)
2425 wxWindowNext
*item
= ms_winCaptureNext
;
2426 ms_winCaptureNext
= item
->next
;
2428 DoNotifyWindowAboutCaptureLost(item
->win
);
2437 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2438 int WXUNUSED(modifiers
),
2439 int WXUNUSED(keycode
))
2445 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2451 #endif // wxUSE_HOTKEY
2453 void wxWindowBase::SendDestroyEvent()
2455 wxWindowDestroyEvent event
;
2456 event
.SetEventObject(this);
2457 event
.SetId(GetId());
2458 GetEventHandler()->ProcessEvent(event
);
2461 // ----------------------------------------------------------------------------
2463 // ----------------------------------------------------------------------------
2465 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2467 #if wxUSE_VALIDATORS
2468 // Can only use the validator of the window which
2469 // is receiving the event
2470 if ( event
.GetEventObject() == this )
2472 wxValidator
*validator
= GetValidator();
2473 if ( validator
&& validator
->ProcessEvent(event
) )
2478 #endif // wxUSE_VALIDATORS
2483 bool wxWindowBase::TryParent(wxEvent
& event
)
2485 // carry on up the parent-child hierarchy if the propagation count hasn't
2487 if ( event
.ShouldPropagate() )
2489 // honour the requests to stop propagation at this window: this is
2490 // used by the dialogs, for example, to prevent processing the events
2491 // from the dialog controls in the parent frame which rarely, if ever,
2493 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2495 wxWindow
*parent
= GetParent();
2496 if ( parent
&& !parent
->IsBeingDeleted() )
2498 wxPropagateOnce
propagateOnce(event
);
2500 return parent
->GetEventHandler()->ProcessEvent(event
);
2505 return wxEvtHandler::TryParent(event
);
2508 // ----------------------------------------------------------------------------
2509 // keyboard navigation
2510 // ----------------------------------------------------------------------------
2512 // Navigates in the specified direction.
2513 bool wxWindowBase::Navigate(int flags
)
2515 wxNavigationKeyEvent eventNav
;
2516 eventNav
.SetFlags(flags
);
2517 eventNav
.SetEventObject(this);
2518 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2525 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2527 // check that we're not a top level window
2528 wxCHECK_RET( GetParent(),
2529 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2531 // detect the special case when we have nothing to do anyhow and when the
2532 // code below wouldn't work
2536 // find the target window in the siblings list
2537 wxWindowList
& siblings
= GetParent()->GetChildren();
2538 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2539 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2541 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2542 // can't just move the node around
2543 wxWindow
*self
= (wxWindow
*)this;
2544 siblings
.DeleteObject(self
);
2545 if ( move
== MoveAfter
)
2552 siblings
.Insert(i
, self
);
2554 else // MoveAfter and win was the last sibling
2556 siblings
.Append(self
);
2560 // ----------------------------------------------------------------------------
2562 // ----------------------------------------------------------------------------
2564 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2566 wxWindowBase
*win
= DoFindFocus();
2567 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2570 // ----------------------------------------------------------------------------
2572 // ----------------------------------------------------------------------------
2574 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2576 while ( win
&& !win
->IsTopLevel() )
2577 win
= win
->GetParent();
2582 #if wxUSE_ACCESSIBILITY
2583 // ----------------------------------------------------------------------------
2584 // accessible object for windows
2585 // ----------------------------------------------------------------------------
2587 // Can return either a child object, or an integer
2588 // representing the child element, starting from 1.
2589 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2591 wxASSERT( GetWindow() != NULL
);
2595 return wxACC_NOT_IMPLEMENTED
;
2598 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2599 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2601 wxASSERT( GetWindow() != NULL
);
2605 wxWindow
* win
= NULL
;
2612 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2614 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2621 rect
= win
->GetRect();
2622 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2623 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2627 return wxACC_NOT_IMPLEMENTED
;
2630 // Navigates from fromId to toId/toObject.
2631 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2632 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2634 wxASSERT( GetWindow() != NULL
);
2640 case wxNAVDIR_FIRSTCHILD
:
2642 if (GetWindow()->GetChildren().GetCount() == 0)
2644 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2645 *toObject
= childWindow
->GetOrCreateAccessible();
2649 case wxNAVDIR_LASTCHILD
:
2651 if (GetWindow()->GetChildren().GetCount() == 0)
2653 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2654 *toObject
= childWindow
->GetOrCreateAccessible();
2658 case wxNAVDIR_RIGHT
:
2662 wxWindowList::compatibility_iterator node
=
2663 wxWindowList::compatibility_iterator();
2666 // Can't navigate to sibling of this window
2667 // if we're a top-level window.
2668 if (!GetWindow()->GetParent())
2669 return wxACC_NOT_IMPLEMENTED
;
2671 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2675 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2676 node
= GetWindow()->GetChildren().Item(fromId
-1);
2679 if (node
&& node
->GetNext())
2681 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2682 *toObject
= nextWindow
->GetOrCreateAccessible();
2690 case wxNAVDIR_PREVIOUS
:
2692 wxWindowList::compatibility_iterator node
=
2693 wxWindowList::compatibility_iterator();
2696 // Can't navigate to sibling of this window
2697 // if we're a top-level window.
2698 if (!GetWindow()->GetParent())
2699 return wxACC_NOT_IMPLEMENTED
;
2701 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2705 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2706 node
= GetWindow()->GetChildren().Item(fromId
-1);
2709 if (node
&& node
->GetPrevious())
2711 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2712 *toObject
= previousWindow
->GetOrCreateAccessible();
2720 return wxACC_NOT_IMPLEMENTED
;
2723 // Gets the name of the specified object.
2724 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2726 wxASSERT( GetWindow() != NULL
);
2732 // If a child, leave wxWidgets to call the function on the actual
2735 return wxACC_NOT_IMPLEMENTED
;
2737 // This will eventually be replaced by specialised
2738 // accessible classes, one for each kind of wxWidgets
2739 // control or window.
2741 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2742 title
= ((wxButton
*) GetWindow())->GetLabel();
2745 title
= GetWindow()->GetName();
2753 return wxACC_NOT_IMPLEMENTED
;
2756 // Gets the number of children.
2757 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2759 wxASSERT( GetWindow() != NULL
);
2763 *childId
= (int) GetWindow()->GetChildren().GetCount();
2767 // Gets the specified child (starting from 1).
2768 // If *child is NULL and return value is wxACC_OK,
2769 // this means that the child is a simple element and
2770 // not an accessible object.
2771 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2773 wxASSERT( GetWindow() != NULL
);
2783 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2786 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2787 *child
= childWindow
->GetOrCreateAccessible();
2794 // Gets the parent, or NULL.
2795 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2797 wxASSERT( GetWindow() != NULL
);
2801 wxWindow
* parentWindow
= GetWindow()->GetParent();
2809 *parent
= parentWindow
->GetOrCreateAccessible();
2817 // Performs the default action. childId is 0 (the action for this object)
2818 // or > 0 (the action for a child).
2819 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2820 // window (e.g. an edit control).
2821 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2823 wxASSERT( GetWindow() != NULL
);
2827 return wxACC_NOT_IMPLEMENTED
;
2830 // Gets the default action for this object (0) or > 0 (the action for a child).
2831 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2832 // string if there is no action.
2833 // The retrieved string describes the action that is performed on an object,
2834 // not what the object does as a result. For example, a toolbar button that prints
2835 // a document has a default action of "Press" rather than "Prints the current document."
2836 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2838 wxASSERT( GetWindow() != NULL
);
2842 return wxACC_NOT_IMPLEMENTED
;
2845 // Returns the description for this object or a child.
2846 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2848 wxASSERT( GetWindow() != NULL
);
2852 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2858 return wxACC_NOT_IMPLEMENTED
;
2861 // Returns help text for this object or a child, similar to tooltip text.
2862 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2864 wxASSERT( GetWindow() != NULL
);
2868 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2874 return wxACC_NOT_IMPLEMENTED
;
2877 // Returns the keyboard shortcut for this object or child.
2878 // Return e.g. ALT+K
2879 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2881 wxASSERT( GetWindow() != NULL
);
2885 return wxACC_NOT_IMPLEMENTED
;
2888 // Returns a role constant.
2889 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2891 wxASSERT( GetWindow() != NULL
);
2895 // If a child, leave wxWidgets to call the function on the actual
2898 return wxACC_NOT_IMPLEMENTED
;
2900 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2901 return wxACC_NOT_IMPLEMENTED
;
2903 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2904 return wxACC_NOT_IMPLEMENTED
;
2907 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2908 return wxACC_NOT_IMPLEMENTED
;
2911 //*role = wxROLE_SYSTEM_CLIENT;
2912 *role
= wxROLE_SYSTEM_CLIENT
;
2916 return wxACC_NOT_IMPLEMENTED
;
2920 // Returns a state constant.
2921 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2923 wxASSERT( GetWindow() != NULL
);
2927 // If a child, leave wxWidgets to call the function on the actual
2930 return wxACC_NOT_IMPLEMENTED
;
2932 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2933 return wxACC_NOT_IMPLEMENTED
;
2936 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2937 return wxACC_NOT_IMPLEMENTED
;
2940 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2941 return wxACC_NOT_IMPLEMENTED
;
2948 return wxACC_NOT_IMPLEMENTED
;
2952 // Returns a localized string representing the value for the object
2954 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2956 wxASSERT( GetWindow() != NULL
);
2960 return wxACC_NOT_IMPLEMENTED
;
2963 // Selects the object or child.
2964 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2966 wxASSERT( GetWindow() != NULL
);
2970 return wxACC_NOT_IMPLEMENTED
;
2973 // Gets the window with the keyboard focus.
2974 // If childId is 0 and child is NULL, no object in
2975 // this subhierarchy has the focus.
2976 // If this object has the focus, child should be 'this'.
2977 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2979 wxASSERT( GetWindow() != NULL
);
2983 return wxACC_NOT_IMPLEMENTED
;
2987 // Gets a variant representing the selected children
2989 // Acceptable values:
2990 // - a null variant (IsNull() returns true)
2991 // - a list variant (GetType() == wxT("list")
2992 // - an integer representing the selected child element,
2993 // or 0 if this object is selected (GetType() == wxT("long")
2994 // - a "void*" pointer to a wxAccessible child object
2995 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2997 wxASSERT( GetWindow() != NULL
);
3001 return wxACC_NOT_IMPLEMENTED
;
3003 #endif // wxUSE_VARIANT
3005 #endif // wxUSE_ACCESSIBILITY
3007 // ----------------------------------------------------------------------------
3009 // ----------------------------------------------------------------------------
3012 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3014 wxCoord widthTotal
) const
3016 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3018 x
= widthTotal
- x
- width
;