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::IsVisible() const
752 return IsShown() && (GetParent() == NULL
|| GetParent()->IsVisible());
755 // ----------------------------------------------------------------------------
757 // ----------------------------------------------------------------------------
759 bool wxWindowBase::IsTopLevel() const
764 // ----------------------------------------------------------------------------
765 // reparenting the window
766 // ----------------------------------------------------------------------------
768 void wxWindowBase::AddChild(wxWindowBase
*child
)
770 wxCHECK_RET( child
, wxT("can't add a NULL child") );
772 // this should never happen and it will lead to a crash later if it does
773 // because RemoveChild() will remove only one node from the children list
774 // and the other(s) one(s) will be left with dangling pointers in them
775 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
777 GetChildren().Append((wxWindow
*)child
);
778 child
->SetParent(this);
781 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
783 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
785 GetChildren().DeleteObject((wxWindow
*)child
);
786 child
->SetParent(NULL
);
789 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
791 wxWindow
*oldParent
= GetParent();
792 if ( newParent
== oldParent
)
798 // unlink this window from the existing parent.
801 oldParent
->RemoveChild(this);
805 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
808 // add it to the new one
811 newParent
->AddChild(this);
815 wxTopLevelWindows
.Append((wxWindow
*)this);
821 // ----------------------------------------------------------------------------
822 // event handler stuff
823 // ----------------------------------------------------------------------------
825 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
827 wxEvtHandler
*handlerOld
= GetEventHandler();
829 handler
->SetNextHandler(handlerOld
);
832 GetEventHandler()->SetPreviousHandler(handler
);
834 SetEventHandler(handler
);
837 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
839 wxEvtHandler
*handlerA
= GetEventHandler();
842 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
843 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
846 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
847 SetEventHandler(handlerB
);
852 handlerA
= (wxEvtHandler
*)NULL
;
859 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
861 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
863 wxEvtHandler
*handlerPrev
= NULL
,
864 *handlerCur
= GetEventHandler();
867 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
869 if ( handlerCur
== handler
)
873 handlerPrev
->SetNextHandler(handlerNext
);
877 SetEventHandler(handlerNext
);
882 handlerNext
->SetPreviousHandler ( handlerPrev
);
885 handler
->SetNextHandler(NULL
);
886 handler
->SetPreviousHandler(NULL
);
891 handlerPrev
= handlerCur
;
892 handlerCur
= handlerNext
;
895 wxFAIL_MSG( _T("where has the event handler gone?") );
900 // ----------------------------------------------------------------------------
902 // ----------------------------------------------------------------------------
904 void wxWindowBase::InheritAttributes()
906 const wxWindowBase
* const parent
= GetParent();
910 // we only inherit attributes which had been explicitly set for the parent
911 // which ensures that this only happens if the user really wants it and
912 // not by default which wouldn't make any sense in modern GUIs where the
913 // controls don't all use the same fonts (nor colours)
914 if ( parent
->m_inheritFont
&& !m_hasFont
)
915 SetFont(parent
->GetFont());
917 // in addition, there is a possibility to explicitly forbid inheriting
918 // colours at each class level by overriding ShouldInheritColours()
919 if ( ShouldInheritColours() )
921 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
922 SetForegroundColour(parent
->GetForegroundColour());
924 // inheriting (solid) background colour is wrong as it totally breaks
925 // any kind of themed backgrounds
927 // instead, the controls should use the same background as their parent
928 // (ideally by not drawing it at all)
930 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
931 SetBackgroundColour(parent
->GetBackgroundColour());
936 /* static */ wxVisualAttributes
937 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
939 // it is important to return valid values for all attributes from here,
940 // GetXXX() below rely on this
941 wxVisualAttributes attrs
;
942 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
943 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
945 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
946 // the usual background colour than wxSYS_COLOUR_BTNFACE.
947 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
948 // colour on other platforms.
950 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
951 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
953 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
958 wxColour
wxWindowBase::GetBackgroundColour() const
960 if ( !m_backgroundColour
.Ok() )
962 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
964 // get our default background colour
965 wxColour colBg
= GetDefaultAttributes().colBg
;
967 // we must return some valid colour to avoid redoing this every time
968 // and also to avoid surprizing the applications written for older
969 // wxWidgets versions where GetBackgroundColour() always returned
970 // something -- so give them something even if it doesn't make sense
971 // for this window (e.g. it has a themed background)
973 colBg
= GetClassDefaultAttributes().colBg
;
978 return m_backgroundColour
;
981 wxColour
wxWindowBase::GetForegroundColour() const
983 // logic is the same as above
984 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
986 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
988 wxColour colFg
= GetDefaultAttributes().colFg
;
991 colFg
= GetClassDefaultAttributes().colFg
;
996 return m_foregroundColour
;
999 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1001 if ( colour
== m_backgroundColour
)
1004 m_hasBgCol
= colour
.Ok();
1005 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1006 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1008 m_inheritBgCol
= m_hasBgCol
;
1009 m_backgroundColour
= colour
;
1010 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1014 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1016 if (colour
== m_foregroundColour
)
1019 m_hasFgCol
= colour
.Ok();
1020 m_inheritFgCol
= m_hasFgCol
;
1021 m_foregroundColour
= colour
;
1022 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1026 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1028 // setting an invalid cursor is ok, it means that we don't have any special
1030 if ( m_cursor
== cursor
)
1041 wxFont
wxWindowBase::GetFont() const
1043 // logic is the same as in GetBackgroundColour()
1046 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1048 wxFont font
= GetDefaultAttributes().font
;
1050 font
= GetClassDefaultAttributes().font
;
1058 bool wxWindowBase::SetFont(const wxFont
& font
)
1060 if ( font
== m_font
)
1067 m_hasFont
= font
.Ok();
1068 m_inheritFont
= m_hasFont
;
1070 InvalidateBestSize();
1077 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1079 m_hasCustomPalette
= true;
1082 // VZ: can anyone explain me what do we do here?
1083 wxWindowDC
d((wxWindow
*) this);
1087 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1089 wxWindow
*win
= (wxWindow
*)this;
1090 while ( win
&& !win
->HasCustomPalette() )
1092 win
= win
->GetParent();
1098 #endif // wxUSE_PALETTE
1101 void wxWindowBase::SetCaret(wxCaret
*caret
)
1112 wxASSERT_MSG( m_caret
->GetWindow() == this,
1113 wxT("caret should be created associated to this window") );
1116 #endif // wxUSE_CARET
1118 #if wxUSE_VALIDATORS
1119 // ----------------------------------------------------------------------------
1121 // ----------------------------------------------------------------------------
1123 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1125 if ( m_windowValidator
)
1126 delete m_windowValidator
;
1128 m_windowValidator
= (wxValidator
*)validator
.Clone();
1130 if ( m_windowValidator
)
1131 m_windowValidator
->SetWindow(this);
1133 #endif // wxUSE_VALIDATORS
1135 // ----------------------------------------------------------------------------
1136 // update region stuff
1137 // ----------------------------------------------------------------------------
1139 wxRect
wxWindowBase::GetUpdateClientRect() const
1141 wxRegion rgnUpdate
= GetUpdateRegion();
1142 rgnUpdate
.Intersect(GetClientRect());
1143 wxRect rectUpdate
= rgnUpdate
.GetBox();
1144 wxPoint ptOrigin
= GetClientAreaOrigin();
1145 rectUpdate
.x
-= ptOrigin
.x
;
1146 rectUpdate
.y
-= ptOrigin
.y
;
1151 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1153 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1156 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1158 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1161 void wxWindowBase::ClearBackground()
1163 // wxGTK uses its own version, no need to add never used code
1165 wxClientDC
dc((wxWindow
*)this);
1166 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1167 dc
.SetBackground(brush
);
1172 // ----------------------------------------------------------------------------
1173 // find child window by id or name
1174 // ----------------------------------------------------------------------------
1176 wxWindow
*wxWindowBase::FindWindow(long id
) const
1178 if ( id
== m_windowId
)
1179 return (wxWindow
*)this;
1181 wxWindowBase
*res
= (wxWindow
*)NULL
;
1182 wxWindowList::compatibility_iterator node
;
1183 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1185 wxWindowBase
*child
= node
->GetData();
1186 res
= child
->FindWindow( id
);
1189 return (wxWindow
*)res
;
1192 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1194 if ( name
== m_windowName
)
1195 return (wxWindow
*)this;
1197 wxWindowBase
*res
= (wxWindow
*)NULL
;
1198 wxWindowList::compatibility_iterator node
;
1199 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1201 wxWindow
*child
= node
->GetData();
1202 res
= child
->FindWindow(name
);
1205 return (wxWindow
*)res
;
1209 // find any window by id or name or label: If parent is non-NULL, look through
1210 // children for a label or title matching the specified string. If NULL, look
1211 // through all top-level windows.
1213 // to avoid duplicating code we reuse the same helper function but with
1214 // different comparators
1216 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1217 const wxString
& label
, long id
);
1220 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1223 return win
->GetLabel() == label
;
1227 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1230 return win
->GetName() == label
;
1234 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1237 return win
->GetId() == id
;
1240 // recursive helper for the FindWindowByXXX() functions
1242 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1243 const wxString
& label
,
1245 wxFindWindowCmp cmp
)
1249 // see if this is the one we're looking for
1250 if ( (*cmp
)(parent
, label
, id
) )
1251 return (wxWindow
*)parent
;
1253 // It wasn't, so check all its children
1254 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1256 node
= node
->GetNext() )
1258 // recursively check each child
1259 wxWindow
*win
= (wxWindow
*)node
->GetData();
1260 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1270 // helper for FindWindowByXXX()
1272 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1273 const wxString
& label
,
1275 wxFindWindowCmp cmp
)
1279 // just check parent and all its children
1280 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1283 // start at very top of wx's windows
1284 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1286 node
= node
->GetNext() )
1288 // recursively check each window & its children
1289 wxWindow
*win
= node
->GetData();
1290 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1300 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1302 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1307 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1309 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1313 // fall back to the label
1314 win
= FindWindowByLabel(title
, parent
);
1322 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1324 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1327 // ----------------------------------------------------------------------------
1328 // dialog oriented functions
1329 // ----------------------------------------------------------------------------
1331 void wxWindowBase::MakeModal(bool modal
)
1333 // Disable all other windows
1336 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1339 wxWindow
*win
= node
->GetData();
1341 win
->Enable(!modal
);
1343 node
= node
->GetNext();
1348 bool wxWindowBase::Validate()
1350 #if wxUSE_VALIDATORS
1351 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1353 wxWindowList::compatibility_iterator node
;
1354 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1356 wxWindowBase
*child
= node
->GetData();
1357 wxValidator
*validator
= child
->GetValidator();
1358 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1363 if ( recurse
&& !child
->Validate() )
1368 #endif // wxUSE_VALIDATORS
1373 bool wxWindowBase::TransferDataToWindow()
1375 #if wxUSE_VALIDATORS
1376 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1378 wxWindowList::compatibility_iterator node
;
1379 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1381 wxWindowBase
*child
= node
->GetData();
1382 wxValidator
*validator
= child
->GetValidator();
1383 if ( validator
&& !validator
->TransferToWindow() )
1385 wxLogWarning(_("Could not transfer data to window"));
1387 wxLog::FlushActive();
1395 if ( !child
->TransferDataToWindow() )
1397 // warning already given
1402 #endif // wxUSE_VALIDATORS
1407 bool wxWindowBase::TransferDataFromWindow()
1409 #if wxUSE_VALIDATORS
1410 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1412 wxWindowList::compatibility_iterator node
;
1413 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1415 wxWindow
*child
= node
->GetData();
1416 wxValidator
*validator
= child
->GetValidator();
1417 if ( validator
&& !validator
->TransferFromWindow() )
1419 // nop warning here because the application is supposed to give
1420 // one itself - we don't know here what might have gone wrongly
1427 if ( !child
->TransferDataFromWindow() )
1429 // warning already given
1434 #endif // wxUSE_VALIDATORS
1439 void wxWindowBase::InitDialog()
1441 wxInitDialogEvent
event(GetId());
1442 event
.SetEventObject( this );
1443 GetEventHandler()->ProcessEvent(event
);
1446 // ----------------------------------------------------------------------------
1447 // context-sensitive help support
1448 // ----------------------------------------------------------------------------
1452 // associate this help text with this window
1453 void wxWindowBase::SetHelpText(const wxString
& text
)
1455 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1458 helpProvider
->AddHelp(this, text
);
1462 // associate this help text with all windows with the same id as this
1464 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1466 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1469 helpProvider
->AddHelp(GetId(), text
);
1473 // get the help string associated with this window (may be empty)
1474 // default implementation forwards calls to the help provider
1476 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1477 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1480 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1483 text
= helpProvider
->GetHelp(this);
1489 // show help for this window
1490 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1492 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1495 if ( helpProvider
->ShowHelpAtPoint(this, event
.GetPosition(), event
.GetOrigin()) )
1497 // skip the event.Skip() below
1505 #endif // wxUSE_HELP
1507 // ----------------------------------------------------------------------------
1508 // tooltipsroot.Replace("\\", "/");
1509 // ----------------------------------------------------------------------------
1513 void wxWindowBase::SetToolTip( const wxString
&tip
)
1515 // don't create the new tooltip if we already have one
1518 m_tooltip
->SetTip( tip
);
1522 SetToolTip( new wxToolTip( tip
) );
1525 // setting empty tooltip text does not remove the tooltip any more - use
1526 // SetToolTip((wxToolTip *)NULL) for this
1529 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1531 if ( m_tooltip
!= tooltip
)
1536 m_tooltip
= tooltip
;
1540 #endif // wxUSE_TOOLTIPS
1542 // ----------------------------------------------------------------------------
1543 // constraints and sizers
1544 // ----------------------------------------------------------------------------
1546 #if wxUSE_CONSTRAINTS
1548 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1550 if ( m_constraints
)
1552 UnsetConstraints(m_constraints
);
1553 delete m_constraints
;
1555 m_constraints
= constraints
;
1556 if ( m_constraints
)
1558 // Make sure other windows know they're part of a 'meaningful relationship'
1559 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1560 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1561 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1562 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1563 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1564 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1565 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1566 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1567 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1568 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1569 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1570 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1571 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1572 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1573 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1574 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1578 // This removes any dangling pointers to this window in other windows'
1579 // constraintsInvolvedIn lists.
1580 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1584 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1585 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1586 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1587 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1588 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1589 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1590 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1591 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1592 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1593 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1594 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1595 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1596 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1597 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1598 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1599 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1603 // Back-pointer to other windows we're involved with, so if we delete this
1604 // window, we must delete any constraints we're involved with.
1605 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1607 if ( !m_constraintsInvolvedIn
)
1608 m_constraintsInvolvedIn
= new wxWindowList
;
1609 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1610 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1613 // REMOVE back-pointer to other windows we're involved with.
1614 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1616 if ( m_constraintsInvolvedIn
)
1617 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1620 // Reset any constraints that mention this window
1621 void wxWindowBase::DeleteRelatedConstraints()
1623 if ( m_constraintsInvolvedIn
)
1625 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1628 wxWindow
*win
= node
->GetData();
1629 wxLayoutConstraints
*constr
= win
->GetConstraints();
1631 // Reset any constraints involving this window
1634 constr
->left
.ResetIfWin(this);
1635 constr
->top
.ResetIfWin(this);
1636 constr
->right
.ResetIfWin(this);
1637 constr
->bottom
.ResetIfWin(this);
1638 constr
->width
.ResetIfWin(this);
1639 constr
->height
.ResetIfWin(this);
1640 constr
->centreX
.ResetIfWin(this);
1641 constr
->centreY
.ResetIfWin(this);
1644 wxWindowList::compatibility_iterator next
= node
->GetNext();
1645 m_constraintsInvolvedIn
->Erase(node
);
1649 delete m_constraintsInvolvedIn
;
1650 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1654 #endif // wxUSE_CONSTRAINTS
1656 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1658 if ( sizer
== m_windowSizer
)
1661 if ( m_windowSizer
)
1663 m_windowSizer
->SetContainingWindow(NULL
);
1666 delete m_windowSizer
;
1669 m_windowSizer
= sizer
;
1670 if ( m_windowSizer
)
1672 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
1675 SetAutoLayout(m_windowSizer
!= NULL
);
1678 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1680 SetSizer( sizer
, deleteOld
);
1681 sizer
->SetSizeHints( (wxWindow
*) this );
1685 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1687 // adding a window to a sizer twice is going to result in fatal and
1688 // hard to debug problems later because when deleting the second
1689 // associated wxSizerItem we're going to dereference a dangling
1690 // pointer; so try to detect this as early as possible
1691 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1692 _T("Adding a window to the same sizer twice?") );
1694 m_containingSizer
= sizer
;
1697 #if wxUSE_CONSTRAINTS
1699 void wxWindowBase::SatisfyConstraints()
1701 wxLayoutConstraints
*constr
= GetConstraints();
1702 bool wasOk
= constr
&& constr
->AreSatisfied();
1704 ResetConstraints(); // Mark all constraints as unevaluated
1708 // if we're a top level panel (i.e. our parent is frame/dialog), our
1709 // own constraints will never be satisfied any more unless we do it
1713 while ( noChanges
> 0 )
1715 LayoutPhase1(&noChanges
);
1719 LayoutPhase2(&noChanges
);
1722 #endif // wxUSE_CONSTRAINTS
1724 bool wxWindowBase::Layout()
1726 // If there is a sizer, use it instead of the constraints
1730 GetVirtualSize(&w
, &h
);
1731 GetSizer()->SetDimension( 0, 0, w
, h
);
1733 #if wxUSE_CONSTRAINTS
1736 SatisfyConstraints(); // Find the right constraints values
1737 SetConstraintSizes(); // Recursively set the real window sizes
1744 #if wxUSE_CONSTRAINTS
1746 // first phase of the constraints evaluation: set our own constraints
1747 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1749 wxLayoutConstraints
*constr
= GetConstraints();
1751 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1754 // second phase: set the constraints for our children
1755 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1762 // Layout grand children
1768 // Do a phase of evaluating child constraints
1769 bool wxWindowBase::DoPhase(int phase
)
1771 // the list containing the children for which the constraints are already
1773 wxWindowList succeeded
;
1775 // the max number of iterations we loop before concluding that we can't set
1777 static const int maxIterations
= 500;
1779 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1783 // loop over all children setting their constraints
1784 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1786 node
= node
->GetNext() )
1788 wxWindow
*child
= node
->GetData();
1789 if ( child
->IsTopLevel() )
1791 // top level children are not inside our client area
1795 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1797 // this one is either already ok or nothing we can do about it
1801 int tempNoChanges
= 0;
1802 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1803 : child
->LayoutPhase2(&tempNoChanges
);
1804 noChanges
+= tempNoChanges
;
1808 succeeded
.Append(child
);
1814 // constraints are set
1822 void wxWindowBase::ResetConstraints()
1824 wxLayoutConstraints
*constr
= GetConstraints();
1827 constr
->left
.SetDone(false);
1828 constr
->top
.SetDone(false);
1829 constr
->right
.SetDone(false);
1830 constr
->bottom
.SetDone(false);
1831 constr
->width
.SetDone(false);
1832 constr
->height
.SetDone(false);
1833 constr
->centreX
.SetDone(false);
1834 constr
->centreY
.SetDone(false);
1837 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1840 wxWindow
*win
= node
->GetData();
1841 if ( !win
->IsTopLevel() )
1842 win
->ResetConstraints();
1843 node
= node
->GetNext();
1847 // Need to distinguish between setting the 'fake' size for windows and sizers,
1848 // and setting the real values.
1849 void wxWindowBase::SetConstraintSizes(bool recurse
)
1851 wxLayoutConstraints
*constr
= GetConstraints();
1852 if ( constr
&& constr
->AreSatisfied() )
1854 int x
= constr
->left
.GetValue();
1855 int y
= constr
->top
.GetValue();
1856 int w
= constr
->width
.GetValue();
1857 int h
= constr
->height
.GetValue();
1859 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1860 (constr
->height
.GetRelationship() != wxAsIs
) )
1862 SetSize(x
, y
, w
, h
);
1866 // If we don't want to resize this window, just move it...
1872 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1873 GetClassInfo()->GetClassName(),
1879 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1882 wxWindow
*win
= node
->GetData();
1883 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1884 win
->SetConstraintSizes();
1885 node
= node
->GetNext();
1890 // Only set the size/position of the constraint (if any)
1891 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1893 wxLayoutConstraints
*constr
= GetConstraints();
1896 if ( x
!= wxDefaultCoord
)
1898 constr
->left
.SetValue(x
);
1899 constr
->left
.SetDone(true);
1901 if ( y
!= wxDefaultCoord
)
1903 constr
->top
.SetValue(y
);
1904 constr
->top
.SetDone(true);
1906 if ( w
!= wxDefaultCoord
)
1908 constr
->width
.SetValue(w
);
1909 constr
->width
.SetDone(true);
1911 if ( h
!= wxDefaultCoord
)
1913 constr
->height
.SetValue(h
);
1914 constr
->height
.SetDone(true);
1919 void wxWindowBase::MoveConstraint(int x
, int y
)
1921 wxLayoutConstraints
*constr
= GetConstraints();
1924 if ( x
!= wxDefaultCoord
)
1926 constr
->left
.SetValue(x
);
1927 constr
->left
.SetDone(true);
1929 if ( y
!= wxDefaultCoord
)
1931 constr
->top
.SetValue(y
);
1932 constr
->top
.SetDone(true);
1937 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1939 wxLayoutConstraints
*constr
= GetConstraints();
1942 *w
= constr
->width
.GetValue();
1943 *h
= constr
->height
.GetValue();
1949 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1951 wxLayoutConstraints
*constr
= GetConstraints();
1954 *w
= constr
->width
.GetValue();
1955 *h
= constr
->height
.GetValue();
1958 GetClientSize(w
, h
);
1961 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1963 wxLayoutConstraints
*constr
= GetConstraints();
1966 *x
= constr
->left
.GetValue();
1967 *y
= constr
->top
.GetValue();
1973 #endif // wxUSE_CONSTRAINTS
1975 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1977 // don't do it for the dialogs/frames - they float independently of their
1979 if ( !IsTopLevel() )
1981 wxWindow
*parent
= GetParent();
1982 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1984 wxPoint
pt(parent
->GetClientAreaOrigin());
1991 // ----------------------------------------------------------------------------
1992 // do Update UI processing for child controls
1993 // ----------------------------------------------------------------------------
1995 void wxWindowBase::UpdateWindowUI(long flags
)
1997 wxUpdateUIEvent
event(GetId());
1998 event
.SetEventObject(this);
2000 if ( GetEventHandler()->ProcessEvent(event
) )
2002 DoUpdateWindowUI(event
);
2005 if (flags
& wxUPDATE_UI_RECURSE
)
2007 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2010 wxWindow
* child
= (wxWindow
*) node
->GetData();
2011 child
->UpdateWindowUI(flags
);
2012 node
= node
->GetNext();
2017 // do the window-specific processing after processing the update event
2018 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2020 if ( event
.GetSetEnabled() )
2021 Enable(event
.GetEnabled());
2023 if ( event
.GetSetShown() )
2024 Show(event
.GetShown());
2028 // call internal idle recursively
2029 // may be obsolete (wait until OnIdle scheme stabilises)
2030 void wxWindowBase::ProcessInternalIdle()
2034 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2037 wxWindow
*child
= node
->GetData();
2038 child
->ProcessInternalIdle();
2039 node
= node
->GetNext();
2044 // ----------------------------------------------------------------------------
2045 // dialog units translations
2046 // ----------------------------------------------------------------------------
2048 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2050 int charWidth
= GetCharWidth();
2051 int charHeight
= GetCharHeight();
2052 wxPoint pt2
= wxDefaultPosition
;
2053 if (pt
.x
!= wxDefaultCoord
)
2054 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2055 if (pt
.y
!= wxDefaultCoord
)
2056 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2061 wxPoint
wxWindowBase::ConvertDialogToPixels(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
* charWidth
) / 4);
2068 if (pt
.y
!= wxDefaultCoord
)
2069 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2074 // ----------------------------------------------------------------------------
2076 // ----------------------------------------------------------------------------
2078 // propagate the colour change event to the subwindows
2079 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2081 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2084 // Only propagate to non-top-level windows
2085 wxWindow
*win
= node
->GetData();
2086 if ( !win
->IsTopLevel() )
2088 wxSysColourChangedEvent event2
;
2089 event
.SetEventObject(win
);
2090 win
->GetEventHandler()->ProcessEvent(event2
);
2093 node
= node
->GetNext();
2099 // the default action is to populate dialog with data when it's created,
2100 // and nudge the UI into displaying itself correctly in case
2101 // we've turned the wxUpdateUIEvents frequency down low.
2102 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2104 TransferDataToWindow();
2106 // Update the UI at this point
2107 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2110 // methods for drawing the sizers in a visible way
2113 static void DrawSizers(wxWindowBase
*win
);
2115 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2117 wxClientDC
dc((wxWindow
*)win
);
2118 dc
.SetPen(*wxRED_PEN
);
2119 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2120 dc
.DrawRectangle(rect
.Deflate(1, 1));
2123 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2125 const wxSizerItemList
& items
= sizer
->GetChildren();
2126 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2131 wxSizerItem
*item
= *i
;
2132 if ( item
->IsSizer() )
2134 DrawBorder(win
, item
->GetRect().Deflate(2));
2135 DrawSizer(win
, item
->GetSizer());
2137 else if ( item
->IsSpacer() )
2139 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2141 else if ( item
->IsWindow() )
2143 DrawSizers(item
->GetWindow());
2148 static void DrawSizers(wxWindowBase
*win
)
2150 wxSizer
*sizer
= win
->GetSizer();
2153 DrawBorder(win
, win
->GetClientSize());
2154 DrawSizer(win
, sizer
);
2156 else // no sizer, still recurse into the children
2158 const wxWindowList
& children
= win
->GetChildren();
2159 for ( wxWindowList::const_iterator i
= children
.begin(),
2160 end
= children
.end();
2169 #endif // __WXDEBUG__
2171 // process special middle clicks
2172 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2174 if ( event
.ControlDown() && event
.AltDown() )
2177 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2178 if ( event
.ShiftDown() )
2183 #endif // __WXDEBUG__
2186 // don't translate these strings, they're for diagnostics purposes only
2188 msg
.Printf(_T("wxWidgets Library (%s port)\n")
2189 _T("Version %d.%d.%d%s%s, compiled at %s %s%s\n")
2190 _T("Copyright (c) 1995-2006 wxWidgets team"),
2191 wxPlatformInfo().GetPortIdName().c_str(),
2208 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()
2214 wxMessageBox(msg
, _T("wxWidgets information"),
2215 wxICON_INFORMATION
| wxOK
,
2219 #endif // wxUSE_MSGDLG
2225 // ----------------------------------------------------------------------------
2227 // ----------------------------------------------------------------------------
2229 #if wxUSE_ACCESSIBILITY
2230 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2232 if (m_accessible
&& (accessible
!= m_accessible
))
2233 delete m_accessible
;
2234 m_accessible
= accessible
;
2236 m_accessible
->SetWindow((wxWindow
*) this);
2239 // Returns the accessible object, creating if necessary.
2240 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2243 m_accessible
= CreateAccessible();
2244 return m_accessible
;
2247 // Override to create a specific accessible object.
2248 wxAccessible
* wxWindowBase::CreateAccessible()
2250 return new wxWindowAccessible((wxWindow
*) this);
2255 // ----------------------------------------------------------------------------
2256 // list classes implementation
2257 // ----------------------------------------------------------------------------
2261 #include "wx/listimpl.cpp"
2262 WX_DEFINE_LIST(wxWindowList
)
2266 void wxWindowListNode::DeleteData()
2268 delete (wxWindow
*)GetData();
2273 // ----------------------------------------------------------------------------
2275 // ----------------------------------------------------------------------------
2277 wxBorder
wxWindowBase::GetBorder(long flags
) const
2279 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2280 if ( border
== wxBORDER_DEFAULT
)
2282 border
= GetDefaultBorder();
2288 wxBorder
wxWindowBase::GetDefaultBorder() const
2290 return wxBORDER_NONE
;
2293 // ----------------------------------------------------------------------------
2295 // ----------------------------------------------------------------------------
2297 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2299 // here we just check if the point is inside the window or not
2301 // check the top and left border first
2302 bool outside
= x
< 0 || y
< 0;
2305 // check the right and bottom borders too
2306 wxSize size
= GetSize();
2307 outside
= x
>= size
.x
|| y
>= size
.y
;
2310 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2313 // ----------------------------------------------------------------------------
2315 // ----------------------------------------------------------------------------
2317 struct WXDLLEXPORT wxWindowNext
2321 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2322 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2323 bool wxWindowBase::ms_winCaptureChanging
= false;
2325 void wxWindowBase::CaptureMouse()
2327 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2329 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2331 ms_winCaptureChanging
= true;
2333 wxWindow
*winOld
= GetCapture();
2336 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2339 wxWindowNext
*item
= new wxWindowNext
;
2341 item
->next
= ms_winCaptureNext
;
2342 ms_winCaptureNext
= item
;
2344 //else: no mouse capture to save
2347 ms_winCaptureCurrent
= (wxWindow
*)this;
2349 ms_winCaptureChanging
= false;
2352 void wxWindowBase::ReleaseMouse()
2354 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2356 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2358 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2360 ms_winCaptureChanging
= true;
2363 ms_winCaptureCurrent
= NULL
;
2365 if ( ms_winCaptureNext
)
2367 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2368 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2370 wxWindowNext
*item
= ms_winCaptureNext
;
2371 ms_winCaptureNext
= item
->next
;
2374 //else: stack is empty, no previous capture
2376 ms_winCaptureChanging
= false;
2378 wxLogTrace(_T("mousecapture"),
2379 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2380 wx_static_cast(void*, GetCapture()));
2383 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2385 wxMouseCaptureLostEvent
event(win
->GetId());
2386 event
.SetEventObject(win
);
2387 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2389 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2394 void wxWindowBase::NotifyCaptureLost()
2396 // don't do anything if capture lost was expected, i.e. resulted from
2397 // a wx call to ReleaseMouse or CaptureMouse:
2398 if ( ms_winCaptureChanging
)
2401 // if the capture was lost unexpectedly, notify every window that has
2402 // capture (on stack or current) about it and clear the stack:
2404 if ( ms_winCaptureCurrent
)
2406 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2407 ms_winCaptureCurrent
= NULL
;
2410 while ( ms_winCaptureNext
)
2412 wxWindowNext
*item
= ms_winCaptureNext
;
2413 ms_winCaptureNext
= item
->next
;
2415 DoNotifyWindowAboutCaptureLost(item
->win
);
2424 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2425 int WXUNUSED(modifiers
),
2426 int WXUNUSED(keycode
))
2432 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2438 #endif // wxUSE_HOTKEY
2440 void wxWindowBase::SendDestroyEvent()
2442 wxWindowDestroyEvent event
;
2443 event
.SetEventObject(this);
2444 event
.SetId(GetId());
2445 GetEventHandler()->ProcessEvent(event
);
2448 // ----------------------------------------------------------------------------
2450 // ----------------------------------------------------------------------------
2452 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2454 #if wxUSE_VALIDATORS
2455 // Can only use the validator of the window which
2456 // is receiving the event
2457 if ( event
.GetEventObject() == this )
2459 wxValidator
*validator
= GetValidator();
2460 if ( validator
&& validator
->ProcessEvent(event
) )
2465 #endif // wxUSE_VALIDATORS
2470 bool wxWindowBase::TryParent(wxEvent
& event
)
2472 // carry on up the parent-child hierarchy if the propagation count hasn't
2474 if ( event
.ShouldPropagate() )
2476 // honour the requests to stop propagation at this window: this is
2477 // used by the dialogs, for example, to prevent processing the events
2478 // from the dialog controls in the parent frame which rarely, if ever,
2480 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2482 wxWindow
*parent
= GetParent();
2483 if ( parent
&& !parent
->IsBeingDeleted() )
2485 wxPropagateOnce
propagateOnce(event
);
2487 return parent
->GetEventHandler()->ProcessEvent(event
);
2492 return wxEvtHandler::TryParent(event
);
2495 // ----------------------------------------------------------------------------
2496 // keyboard navigation
2497 // ----------------------------------------------------------------------------
2499 // Navigates in the specified direction.
2500 bool wxWindowBase::Navigate(int flags
)
2502 wxNavigationKeyEvent eventNav
;
2503 eventNav
.SetFlags(flags
);
2504 eventNav
.SetEventObject(this);
2505 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2512 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2514 // check that we're not a top level window
2515 wxCHECK_RET( GetParent(),
2516 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2518 // detect the special case when we have nothing to do anyhow and when the
2519 // code below wouldn't work
2523 // find the target window in the siblings list
2524 wxWindowList
& siblings
= GetParent()->GetChildren();
2525 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2526 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2528 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2529 // can't just move the node around
2530 wxWindow
*self
= (wxWindow
*)this;
2531 siblings
.DeleteObject(self
);
2532 if ( move
== MoveAfter
)
2539 siblings
.Insert(i
, self
);
2541 else // MoveAfter and win was the last sibling
2543 siblings
.Append(self
);
2547 // ----------------------------------------------------------------------------
2549 // ----------------------------------------------------------------------------
2551 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2553 wxWindowBase
*win
= DoFindFocus();
2554 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2557 // ----------------------------------------------------------------------------
2559 // ----------------------------------------------------------------------------
2561 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2563 while ( win
&& !win
->IsTopLevel() )
2564 win
= win
->GetParent();
2569 #if wxUSE_ACCESSIBILITY
2570 // ----------------------------------------------------------------------------
2571 // accessible object for windows
2572 // ----------------------------------------------------------------------------
2574 // Can return either a child object, or an integer
2575 // representing the child element, starting from 1.
2576 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2578 wxASSERT( GetWindow() != NULL
);
2582 return wxACC_NOT_IMPLEMENTED
;
2585 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2586 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2588 wxASSERT( GetWindow() != NULL
);
2592 wxWindow
* win
= NULL
;
2599 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2601 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2608 rect
= win
->GetRect();
2609 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2610 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2614 return wxACC_NOT_IMPLEMENTED
;
2617 // Navigates from fromId to toId/toObject.
2618 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2619 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2621 wxASSERT( GetWindow() != NULL
);
2627 case wxNAVDIR_FIRSTCHILD
:
2629 if (GetWindow()->GetChildren().GetCount() == 0)
2631 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2632 *toObject
= childWindow
->GetOrCreateAccessible();
2636 case wxNAVDIR_LASTCHILD
:
2638 if (GetWindow()->GetChildren().GetCount() == 0)
2640 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2641 *toObject
= childWindow
->GetOrCreateAccessible();
2645 case wxNAVDIR_RIGHT
:
2649 wxWindowList::compatibility_iterator node
=
2650 wxWindowList::compatibility_iterator();
2653 // Can't navigate to sibling of this window
2654 // if we're a top-level window.
2655 if (!GetWindow()->GetParent())
2656 return wxACC_NOT_IMPLEMENTED
;
2658 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2662 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2663 node
= GetWindow()->GetChildren().Item(fromId
-1);
2666 if (node
&& node
->GetNext())
2668 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2669 *toObject
= nextWindow
->GetOrCreateAccessible();
2677 case wxNAVDIR_PREVIOUS
:
2679 wxWindowList::compatibility_iterator node
=
2680 wxWindowList::compatibility_iterator();
2683 // Can't navigate to sibling of this window
2684 // if we're a top-level window.
2685 if (!GetWindow()->GetParent())
2686 return wxACC_NOT_IMPLEMENTED
;
2688 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2692 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2693 node
= GetWindow()->GetChildren().Item(fromId
-1);
2696 if (node
&& node
->GetPrevious())
2698 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2699 *toObject
= previousWindow
->GetOrCreateAccessible();
2707 return wxACC_NOT_IMPLEMENTED
;
2710 // Gets the name of the specified object.
2711 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2713 wxASSERT( GetWindow() != NULL
);
2719 // If a child, leave wxWidgets to call the function on the actual
2722 return wxACC_NOT_IMPLEMENTED
;
2724 // This will eventually be replaced by specialised
2725 // accessible classes, one for each kind of wxWidgets
2726 // control or window.
2728 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2729 title
= ((wxButton
*) GetWindow())->GetLabel();
2732 title
= GetWindow()->GetName();
2740 return wxACC_NOT_IMPLEMENTED
;
2743 // Gets the number of children.
2744 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2746 wxASSERT( GetWindow() != NULL
);
2750 *childId
= (int) GetWindow()->GetChildren().GetCount();
2754 // Gets the specified child (starting from 1).
2755 // If *child is NULL and return value is wxACC_OK,
2756 // this means that the child is a simple element and
2757 // not an accessible object.
2758 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2760 wxASSERT( GetWindow() != NULL
);
2770 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2773 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2774 *child
= childWindow
->GetOrCreateAccessible();
2781 // Gets the parent, or NULL.
2782 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2784 wxASSERT( GetWindow() != NULL
);
2788 wxWindow
* parentWindow
= GetWindow()->GetParent();
2796 *parent
= parentWindow
->GetOrCreateAccessible();
2804 // Performs the default action. childId is 0 (the action for this object)
2805 // or > 0 (the action for a child).
2806 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2807 // window (e.g. an edit control).
2808 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2810 wxASSERT( GetWindow() != NULL
);
2814 return wxACC_NOT_IMPLEMENTED
;
2817 // Gets the default action for this object (0) or > 0 (the action for a child).
2818 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2819 // string if there is no action.
2820 // The retrieved string describes the action that is performed on an object,
2821 // not what the object does as a result. For example, a toolbar button that prints
2822 // a document has a default action of "Press" rather than "Prints the current document."
2823 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2825 wxASSERT( GetWindow() != NULL
);
2829 return wxACC_NOT_IMPLEMENTED
;
2832 // Returns the description for this object or a child.
2833 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2835 wxASSERT( GetWindow() != NULL
);
2839 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2845 return wxACC_NOT_IMPLEMENTED
;
2848 // Returns help text for this object or a child, similar to tooltip text.
2849 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2851 wxASSERT( GetWindow() != NULL
);
2855 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2861 return wxACC_NOT_IMPLEMENTED
;
2864 // Returns the keyboard shortcut for this object or child.
2865 // Return e.g. ALT+K
2866 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2868 wxASSERT( GetWindow() != NULL
);
2872 return wxACC_NOT_IMPLEMENTED
;
2875 // Returns a role constant.
2876 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2878 wxASSERT( GetWindow() != NULL
);
2882 // If a child, leave wxWidgets to call the function on the actual
2885 return wxACC_NOT_IMPLEMENTED
;
2887 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2888 return wxACC_NOT_IMPLEMENTED
;
2890 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2891 return wxACC_NOT_IMPLEMENTED
;
2894 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2895 return wxACC_NOT_IMPLEMENTED
;
2898 //*role = wxROLE_SYSTEM_CLIENT;
2899 *role
= wxROLE_SYSTEM_CLIENT
;
2903 return wxACC_NOT_IMPLEMENTED
;
2907 // Returns a state constant.
2908 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2910 wxASSERT( GetWindow() != NULL
);
2914 // If a child, leave wxWidgets to call the function on the actual
2917 return wxACC_NOT_IMPLEMENTED
;
2919 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2920 return wxACC_NOT_IMPLEMENTED
;
2923 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2924 return wxACC_NOT_IMPLEMENTED
;
2927 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2928 return wxACC_NOT_IMPLEMENTED
;
2935 return wxACC_NOT_IMPLEMENTED
;
2939 // Returns a localized string representing the value for the object
2941 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2943 wxASSERT( GetWindow() != NULL
);
2947 return wxACC_NOT_IMPLEMENTED
;
2950 // Selects the object or child.
2951 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2953 wxASSERT( GetWindow() != NULL
);
2957 return wxACC_NOT_IMPLEMENTED
;
2960 // Gets the window with the keyboard focus.
2961 // If childId is 0 and child is NULL, no object in
2962 // this subhierarchy has the focus.
2963 // If this object has the focus, child should be 'this'.
2964 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2966 wxASSERT( GetWindow() != NULL
);
2970 return wxACC_NOT_IMPLEMENTED
;
2973 // Gets a variant representing the selected children
2975 // Acceptable values:
2976 // - a null variant (IsNull() returns true)
2977 // - a list variant (GetType() == wxT("list")
2978 // - an integer representing the selected child element,
2979 // or 0 if this object is selected (GetType() == wxT("long")
2980 // - a "void*" pointer to a wxAccessible child object
2981 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2983 wxASSERT( GetWindow() != NULL
);
2987 return wxACC_NOT_IMPLEMENTED
;
2990 #endif // wxUSE_ACCESSIBILITY
2992 // ----------------------------------------------------------------------------
2994 // ----------------------------------------------------------------------------
2997 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
2999 wxCoord widthTotal
) const
3001 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3003 x
= widthTotal
- x
- width
;