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 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
620 if ( m_windowVariant
!= variant
)
622 m_windowVariant
= variant
;
624 DoSetWindowVariant(variant
);
628 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
630 // adjust the font height to correspond to our new variant (notice that
631 // we're only called if something really changed)
632 wxFont font
= GetFont();
633 int size
= font
.GetPointSize();
636 case wxWINDOW_VARIANT_NORMAL
:
639 case wxWINDOW_VARIANT_SMALL
:
644 case wxWINDOW_VARIANT_MINI
:
649 case wxWINDOW_VARIANT_LARGE
:
655 wxFAIL_MSG(_T("unexpected window variant"));
659 font
.SetPointSize(size
);
663 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
666 m_minVirtualWidth
= minW
;
667 m_maxVirtualWidth
= maxW
;
668 m_minVirtualHeight
= minH
;
669 m_maxVirtualHeight
= maxH
;
672 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
674 if ( m_minVirtualWidth
!= wxDefaultCoord
&& m_minVirtualWidth
> x
)
675 x
= m_minVirtualWidth
;
676 if ( m_maxVirtualWidth
!= wxDefaultCoord
&& m_maxVirtualWidth
< x
)
677 x
= m_maxVirtualWidth
;
678 if ( m_minVirtualHeight
!= wxDefaultCoord
&& m_minVirtualHeight
> y
)
679 y
= m_minVirtualHeight
;
680 if ( m_maxVirtualHeight
!= wxDefaultCoord
&& m_maxVirtualHeight
< y
)
681 y
= m_maxVirtualHeight
;
683 m_virtualSize
= wxSize(x
, y
);
686 wxSize
wxWindowBase::DoGetVirtualSize() const
688 // we should use the entire client area so if it is greater than our
689 // virtual size, expand it to fit (otherwise if the window is big enough we
690 // wouldn't be using parts of it)
691 wxSize size
= GetClientSize();
692 if ( m_virtualSize
.x
> size
.x
)
693 size
.x
= m_virtualSize
.x
;
695 if ( m_virtualSize
.y
>= size
.y
)
696 size
.y
= m_virtualSize
.y
;
701 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
703 // screen position is the same as (0, 0) in client coords for non TLWs (and
704 // TLWs override this method)
710 ClientToScreen(x
, y
);
713 // ----------------------------------------------------------------------------
714 // show/hide/enable/disable the window
715 // ----------------------------------------------------------------------------
717 bool wxWindowBase::Show(bool show
)
719 if ( show
!= m_isShown
)
731 bool wxWindowBase::Enable(bool enable
)
733 if ( enable
!= m_isEnabled
)
735 m_isEnabled
= enable
;
745 bool wxWindowBase::IsShownOnScreen() const
748 (GetParent() == NULL
|| GetParent()->IsShownOnScreen());
751 // ----------------------------------------------------------------------------
753 // ----------------------------------------------------------------------------
755 bool wxWindowBase::IsTopLevel() const
760 // ----------------------------------------------------------------------------
761 // reparenting the window
762 // ----------------------------------------------------------------------------
764 void wxWindowBase::AddChild(wxWindowBase
*child
)
766 wxCHECK_RET( child
, wxT("can't add a NULL child") );
768 // this should never happen and it will lead to a crash later if it does
769 // because RemoveChild() will remove only one node from the children list
770 // and the other(s) one(s) will be left with dangling pointers in them
771 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
773 GetChildren().Append((wxWindow
*)child
);
774 child
->SetParent(this);
777 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
779 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
781 GetChildren().DeleteObject((wxWindow
*)child
);
782 child
->SetParent(NULL
);
785 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
787 wxWindow
*oldParent
= GetParent();
788 if ( newParent
== oldParent
)
794 // unlink this window from the existing parent.
797 oldParent
->RemoveChild(this);
801 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
804 // add it to the new one
807 newParent
->AddChild(this);
811 wxTopLevelWindows
.Append((wxWindow
*)this);
817 // ----------------------------------------------------------------------------
818 // event handler stuff
819 // ----------------------------------------------------------------------------
821 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
823 wxEvtHandler
*handlerOld
= GetEventHandler();
825 handler
->SetNextHandler(handlerOld
);
828 GetEventHandler()->SetPreviousHandler(handler
);
830 SetEventHandler(handler
);
833 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
835 wxEvtHandler
*handlerA
= GetEventHandler();
838 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
839 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
842 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
843 SetEventHandler(handlerB
);
848 handlerA
= (wxEvtHandler
*)NULL
;
855 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
857 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
859 wxEvtHandler
*handlerPrev
= NULL
,
860 *handlerCur
= GetEventHandler();
863 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
865 if ( handlerCur
== handler
)
869 handlerPrev
->SetNextHandler(handlerNext
);
873 SetEventHandler(handlerNext
);
878 handlerNext
->SetPreviousHandler ( handlerPrev
);
881 handler
->SetNextHandler(NULL
);
882 handler
->SetPreviousHandler(NULL
);
887 handlerPrev
= handlerCur
;
888 handlerCur
= handlerNext
;
891 wxFAIL_MSG( _T("where has the event handler gone?") );
896 // ----------------------------------------------------------------------------
898 // ----------------------------------------------------------------------------
900 void wxWindowBase::InheritAttributes()
902 const wxWindowBase
* const parent
= GetParent();
906 // we only inherit attributes which had been explicitly set for the parent
907 // which ensures that this only happens if the user really wants it and
908 // not by default which wouldn't make any sense in modern GUIs where the
909 // controls don't all use the same fonts (nor colours)
910 if ( parent
->m_inheritFont
&& !m_hasFont
)
911 SetFont(parent
->GetFont());
913 // in addition, there is a possibility to explicitly forbid inheriting
914 // colours at each class level by overriding ShouldInheritColours()
915 if ( ShouldInheritColours() )
917 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
918 SetForegroundColour(parent
->GetForegroundColour());
920 // inheriting (solid) background colour is wrong as it totally breaks
921 // any kind of themed backgrounds
923 // instead, the controls should use the same background as their parent
924 // (ideally by not drawing it at all)
926 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
927 SetBackgroundColour(parent
->GetBackgroundColour());
932 /* static */ wxVisualAttributes
933 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
935 // it is important to return valid values for all attributes from here,
936 // GetXXX() below rely on this
937 wxVisualAttributes attrs
;
938 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
939 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
941 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
942 // the usual background colour than wxSYS_COLOUR_BTNFACE.
943 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
944 // colour on other platforms.
946 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
947 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
949 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
954 wxColour
wxWindowBase::GetBackgroundColour() const
956 if ( !m_backgroundColour
.Ok() )
958 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
960 // get our default background colour
961 wxColour colBg
= GetDefaultAttributes().colBg
;
963 // we must return some valid colour to avoid redoing this every time
964 // and also to avoid surprizing the applications written for older
965 // wxWidgets versions where GetBackgroundColour() always returned
966 // something -- so give them something even if it doesn't make sense
967 // for this window (e.g. it has a themed background)
969 colBg
= GetClassDefaultAttributes().colBg
;
974 return m_backgroundColour
;
977 wxColour
wxWindowBase::GetForegroundColour() const
979 // logic is the same as above
980 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
982 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
984 wxColour colFg
= GetDefaultAttributes().colFg
;
987 colFg
= GetClassDefaultAttributes().colFg
;
992 return m_foregroundColour
;
995 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
997 if ( colour
== m_backgroundColour
)
1000 m_hasBgCol
= colour
.Ok();
1001 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1002 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1004 m_inheritBgCol
= m_hasBgCol
;
1005 m_backgroundColour
= colour
;
1006 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1010 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1012 if (colour
== m_foregroundColour
)
1015 m_hasFgCol
= colour
.Ok();
1016 m_inheritFgCol
= m_hasFgCol
;
1017 m_foregroundColour
= colour
;
1018 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1022 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1024 // setting an invalid cursor is ok, it means that we don't have any special
1026 if ( m_cursor
== cursor
)
1037 wxFont
wxWindowBase::GetFont() const
1039 // logic is the same as in GetBackgroundColour()
1042 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1044 wxFont font
= GetDefaultAttributes().font
;
1046 font
= GetClassDefaultAttributes().font
;
1054 bool wxWindowBase::SetFont(const wxFont
& font
)
1056 if ( font
== m_font
)
1063 m_hasFont
= font
.Ok();
1064 m_inheritFont
= m_hasFont
;
1066 InvalidateBestSize();
1073 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1075 m_hasCustomPalette
= true;
1078 // VZ: can anyone explain me what do we do here?
1079 wxWindowDC
d((wxWindow
*) this);
1083 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1085 wxWindow
*win
= (wxWindow
*)this;
1086 while ( win
&& !win
->HasCustomPalette() )
1088 win
= win
->GetParent();
1094 #endif // wxUSE_PALETTE
1097 void wxWindowBase::SetCaret(wxCaret
*caret
)
1108 wxASSERT_MSG( m_caret
->GetWindow() == this,
1109 wxT("caret should be created associated to this window") );
1112 #endif // wxUSE_CARET
1114 #if wxUSE_VALIDATORS
1115 // ----------------------------------------------------------------------------
1117 // ----------------------------------------------------------------------------
1119 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1121 if ( m_windowValidator
)
1122 delete m_windowValidator
;
1124 m_windowValidator
= (wxValidator
*)validator
.Clone();
1126 if ( m_windowValidator
)
1127 m_windowValidator
->SetWindow(this);
1129 #endif // wxUSE_VALIDATORS
1131 // ----------------------------------------------------------------------------
1132 // update region stuff
1133 // ----------------------------------------------------------------------------
1135 wxRect
wxWindowBase::GetUpdateClientRect() const
1137 wxRegion rgnUpdate
= GetUpdateRegion();
1138 rgnUpdate
.Intersect(GetClientRect());
1139 wxRect rectUpdate
= rgnUpdate
.GetBox();
1140 wxPoint ptOrigin
= GetClientAreaOrigin();
1141 rectUpdate
.x
-= ptOrigin
.x
;
1142 rectUpdate
.y
-= ptOrigin
.y
;
1147 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1149 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1152 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1154 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1157 void wxWindowBase::ClearBackground()
1159 // wxGTK uses its own version, no need to add never used code
1161 wxClientDC
dc((wxWindow
*)this);
1162 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1163 dc
.SetBackground(brush
);
1168 // ----------------------------------------------------------------------------
1169 // find child window by id or name
1170 // ----------------------------------------------------------------------------
1172 wxWindow
*wxWindowBase::FindWindow(long id
) const
1174 if ( id
== m_windowId
)
1175 return (wxWindow
*)this;
1177 wxWindowBase
*res
= (wxWindow
*)NULL
;
1178 wxWindowList::compatibility_iterator node
;
1179 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1181 wxWindowBase
*child
= node
->GetData();
1182 res
= child
->FindWindow( id
);
1185 return (wxWindow
*)res
;
1188 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1190 if ( name
== m_windowName
)
1191 return (wxWindow
*)this;
1193 wxWindowBase
*res
= (wxWindow
*)NULL
;
1194 wxWindowList::compatibility_iterator node
;
1195 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1197 wxWindow
*child
= node
->GetData();
1198 res
= child
->FindWindow(name
);
1201 return (wxWindow
*)res
;
1205 // find any window by id or name or label: If parent is non-NULL, look through
1206 // children for a label or title matching the specified string. If NULL, look
1207 // through all top-level windows.
1209 // to avoid duplicating code we reuse the same helper function but with
1210 // different comparators
1212 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1213 const wxString
& label
, long id
);
1216 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1219 return win
->GetLabel() == label
;
1223 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1226 return win
->GetName() == label
;
1230 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1233 return win
->GetId() == id
;
1236 // recursive helper for the FindWindowByXXX() functions
1238 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1239 const wxString
& label
,
1241 wxFindWindowCmp cmp
)
1245 // see if this is the one we're looking for
1246 if ( (*cmp
)(parent
, label
, id
) )
1247 return (wxWindow
*)parent
;
1249 // It wasn't, so check all its children
1250 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1252 node
= node
->GetNext() )
1254 // recursively check each child
1255 wxWindow
*win
= (wxWindow
*)node
->GetData();
1256 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1266 // helper for FindWindowByXXX()
1268 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1269 const wxString
& label
,
1271 wxFindWindowCmp cmp
)
1275 // just check parent and all its children
1276 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1279 // start at very top of wx's windows
1280 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1282 node
= node
->GetNext() )
1284 // recursively check each window & its children
1285 wxWindow
*win
= node
->GetData();
1286 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1296 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1298 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1303 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1305 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1309 // fall back to the label
1310 win
= FindWindowByLabel(title
, parent
);
1318 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1320 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1323 // ----------------------------------------------------------------------------
1324 // dialog oriented functions
1325 // ----------------------------------------------------------------------------
1327 void wxWindowBase::MakeModal(bool modal
)
1329 // Disable all other windows
1332 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1335 wxWindow
*win
= node
->GetData();
1337 win
->Enable(!modal
);
1339 node
= node
->GetNext();
1344 bool wxWindowBase::Validate()
1346 #if wxUSE_VALIDATORS
1347 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1349 wxWindowList::compatibility_iterator node
;
1350 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1352 wxWindowBase
*child
= node
->GetData();
1353 wxValidator
*validator
= child
->GetValidator();
1354 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1359 if ( recurse
&& !child
->Validate() )
1364 #endif // wxUSE_VALIDATORS
1369 bool wxWindowBase::TransferDataToWindow()
1371 #if wxUSE_VALIDATORS
1372 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1374 wxWindowList::compatibility_iterator node
;
1375 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1377 wxWindowBase
*child
= node
->GetData();
1378 wxValidator
*validator
= child
->GetValidator();
1379 if ( validator
&& !validator
->TransferToWindow() )
1381 wxLogWarning(_("Could not transfer data to window"));
1383 wxLog::FlushActive();
1391 if ( !child
->TransferDataToWindow() )
1393 // warning already given
1398 #endif // wxUSE_VALIDATORS
1403 bool wxWindowBase::TransferDataFromWindow()
1405 #if wxUSE_VALIDATORS
1406 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1408 wxWindowList::compatibility_iterator node
;
1409 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1411 wxWindow
*child
= node
->GetData();
1412 wxValidator
*validator
= child
->GetValidator();
1413 if ( validator
&& !validator
->TransferFromWindow() )
1415 // nop warning here because the application is supposed to give
1416 // one itself - we don't know here what might have gone wrongly
1423 if ( !child
->TransferDataFromWindow() )
1425 // warning already given
1430 #endif // wxUSE_VALIDATORS
1435 void wxWindowBase::InitDialog()
1437 wxInitDialogEvent
event(GetId());
1438 event
.SetEventObject( this );
1439 GetEventHandler()->ProcessEvent(event
);
1442 // ----------------------------------------------------------------------------
1443 // context-sensitive help support
1444 // ----------------------------------------------------------------------------
1448 // associate this help text with this window
1449 void wxWindowBase::SetHelpText(const wxString
& text
)
1451 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1454 helpProvider
->AddHelp(this, text
);
1458 // associate this help text with all windows with the same id as this
1460 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1462 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1465 helpProvider
->AddHelp(GetId(), text
);
1469 // get the help string associated with this window (may be empty)
1470 // default implementation forwards calls to the help provider
1472 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1473 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1476 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1479 text
= helpProvider
->GetHelp(this);
1485 // show help for this window
1486 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1488 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1491 if ( helpProvider
->ShowHelpAtPoint(this, event
.GetPosition(), event
.GetOrigin()) )
1493 // skip the event.Skip() below
1501 #endif // wxUSE_HELP
1503 // ----------------------------------------------------------------------------
1504 // tooltipsroot.Replace("\\", "/");
1505 // ----------------------------------------------------------------------------
1509 void wxWindowBase::SetToolTip( const wxString
&tip
)
1511 // don't create the new tooltip if we already have one
1514 m_tooltip
->SetTip( tip
);
1518 SetToolTip( new wxToolTip( tip
) );
1521 // setting empty tooltip text does not remove the tooltip any more - use
1522 // SetToolTip((wxToolTip *)NULL) for this
1525 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1527 if ( m_tooltip
!= tooltip
)
1532 m_tooltip
= tooltip
;
1536 #endif // wxUSE_TOOLTIPS
1538 // ----------------------------------------------------------------------------
1539 // constraints and sizers
1540 // ----------------------------------------------------------------------------
1542 #if wxUSE_CONSTRAINTS
1544 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1546 if ( m_constraints
)
1548 UnsetConstraints(m_constraints
);
1549 delete m_constraints
;
1551 m_constraints
= constraints
;
1552 if ( m_constraints
)
1554 // Make sure other windows know they're part of a 'meaningful relationship'
1555 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1556 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1557 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1558 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1559 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1560 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1561 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1562 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1563 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1564 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1565 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1566 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1567 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1568 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1569 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1570 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1574 // This removes any dangling pointers to this window in other windows'
1575 // constraintsInvolvedIn lists.
1576 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1580 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1581 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1582 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1583 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1584 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1585 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1586 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1587 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1588 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1589 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1590 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1591 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1592 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1593 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1594 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1595 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1599 // Back-pointer to other windows we're involved with, so if we delete this
1600 // window, we must delete any constraints we're involved with.
1601 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1603 if ( !m_constraintsInvolvedIn
)
1604 m_constraintsInvolvedIn
= new wxWindowList
;
1605 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1606 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1609 // REMOVE back-pointer to other windows we're involved with.
1610 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1612 if ( m_constraintsInvolvedIn
)
1613 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1616 // Reset any constraints that mention this window
1617 void wxWindowBase::DeleteRelatedConstraints()
1619 if ( m_constraintsInvolvedIn
)
1621 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1624 wxWindow
*win
= node
->GetData();
1625 wxLayoutConstraints
*constr
= win
->GetConstraints();
1627 // Reset any constraints involving this window
1630 constr
->left
.ResetIfWin(this);
1631 constr
->top
.ResetIfWin(this);
1632 constr
->right
.ResetIfWin(this);
1633 constr
->bottom
.ResetIfWin(this);
1634 constr
->width
.ResetIfWin(this);
1635 constr
->height
.ResetIfWin(this);
1636 constr
->centreX
.ResetIfWin(this);
1637 constr
->centreY
.ResetIfWin(this);
1640 wxWindowList::compatibility_iterator next
= node
->GetNext();
1641 m_constraintsInvolvedIn
->Erase(node
);
1645 delete m_constraintsInvolvedIn
;
1646 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1650 #endif // wxUSE_CONSTRAINTS
1652 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1654 if ( sizer
== m_windowSizer
)
1657 if ( m_windowSizer
)
1659 m_windowSizer
->SetContainingWindow(NULL
);
1662 delete m_windowSizer
;
1665 m_windowSizer
= sizer
;
1666 if ( m_windowSizer
)
1668 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
1671 SetAutoLayout(m_windowSizer
!= NULL
);
1674 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1676 SetSizer( sizer
, deleteOld
);
1677 sizer
->SetSizeHints( (wxWindow
*) this );
1681 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1683 // adding a window to a sizer twice is going to result in fatal and
1684 // hard to debug problems later because when deleting the second
1685 // associated wxSizerItem we're going to dereference a dangling
1686 // pointer; so try to detect this as early as possible
1687 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1688 _T("Adding a window to the same sizer twice?") );
1690 m_containingSizer
= sizer
;
1693 #if wxUSE_CONSTRAINTS
1695 void wxWindowBase::SatisfyConstraints()
1697 wxLayoutConstraints
*constr
= GetConstraints();
1698 bool wasOk
= constr
&& constr
->AreSatisfied();
1700 ResetConstraints(); // Mark all constraints as unevaluated
1704 // if we're a top level panel (i.e. our parent is frame/dialog), our
1705 // own constraints will never be satisfied any more unless we do it
1709 while ( noChanges
> 0 )
1711 LayoutPhase1(&noChanges
);
1715 LayoutPhase2(&noChanges
);
1718 #endif // wxUSE_CONSTRAINTS
1720 bool wxWindowBase::Layout()
1722 // If there is a sizer, use it instead of the constraints
1726 GetVirtualSize(&w
, &h
);
1727 GetSizer()->SetDimension( 0, 0, w
, h
);
1729 #if wxUSE_CONSTRAINTS
1732 SatisfyConstraints(); // Find the right constraints values
1733 SetConstraintSizes(); // Recursively set the real window sizes
1740 #if wxUSE_CONSTRAINTS
1742 // first phase of the constraints evaluation: set our own constraints
1743 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1745 wxLayoutConstraints
*constr
= GetConstraints();
1747 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1750 // second phase: set the constraints for our children
1751 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1758 // Layout grand children
1764 // Do a phase of evaluating child constraints
1765 bool wxWindowBase::DoPhase(int phase
)
1767 // the list containing the children for which the constraints are already
1769 wxWindowList succeeded
;
1771 // the max number of iterations we loop before concluding that we can't set
1773 static const int maxIterations
= 500;
1775 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1779 // loop over all children setting their constraints
1780 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1782 node
= node
->GetNext() )
1784 wxWindow
*child
= node
->GetData();
1785 if ( child
->IsTopLevel() )
1787 // top level children are not inside our client area
1791 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1793 // this one is either already ok or nothing we can do about it
1797 int tempNoChanges
= 0;
1798 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1799 : child
->LayoutPhase2(&tempNoChanges
);
1800 noChanges
+= tempNoChanges
;
1804 succeeded
.Append(child
);
1810 // constraints are set
1818 void wxWindowBase::ResetConstraints()
1820 wxLayoutConstraints
*constr
= GetConstraints();
1823 constr
->left
.SetDone(false);
1824 constr
->top
.SetDone(false);
1825 constr
->right
.SetDone(false);
1826 constr
->bottom
.SetDone(false);
1827 constr
->width
.SetDone(false);
1828 constr
->height
.SetDone(false);
1829 constr
->centreX
.SetDone(false);
1830 constr
->centreY
.SetDone(false);
1833 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1836 wxWindow
*win
= node
->GetData();
1837 if ( !win
->IsTopLevel() )
1838 win
->ResetConstraints();
1839 node
= node
->GetNext();
1843 // Need to distinguish between setting the 'fake' size for windows and sizers,
1844 // and setting the real values.
1845 void wxWindowBase::SetConstraintSizes(bool recurse
)
1847 wxLayoutConstraints
*constr
= GetConstraints();
1848 if ( constr
&& constr
->AreSatisfied() )
1850 int x
= constr
->left
.GetValue();
1851 int y
= constr
->top
.GetValue();
1852 int w
= constr
->width
.GetValue();
1853 int h
= constr
->height
.GetValue();
1855 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1856 (constr
->height
.GetRelationship() != wxAsIs
) )
1858 SetSize(x
, y
, w
, h
);
1862 // If we don't want to resize this window, just move it...
1868 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1869 GetClassInfo()->GetClassName(),
1875 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1878 wxWindow
*win
= node
->GetData();
1879 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1880 win
->SetConstraintSizes();
1881 node
= node
->GetNext();
1886 // Only set the size/position of the constraint (if any)
1887 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1889 wxLayoutConstraints
*constr
= GetConstraints();
1892 if ( x
!= wxDefaultCoord
)
1894 constr
->left
.SetValue(x
);
1895 constr
->left
.SetDone(true);
1897 if ( y
!= wxDefaultCoord
)
1899 constr
->top
.SetValue(y
);
1900 constr
->top
.SetDone(true);
1902 if ( w
!= wxDefaultCoord
)
1904 constr
->width
.SetValue(w
);
1905 constr
->width
.SetDone(true);
1907 if ( h
!= wxDefaultCoord
)
1909 constr
->height
.SetValue(h
);
1910 constr
->height
.SetDone(true);
1915 void wxWindowBase::MoveConstraint(int x
, int y
)
1917 wxLayoutConstraints
*constr
= GetConstraints();
1920 if ( x
!= wxDefaultCoord
)
1922 constr
->left
.SetValue(x
);
1923 constr
->left
.SetDone(true);
1925 if ( y
!= wxDefaultCoord
)
1927 constr
->top
.SetValue(y
);
1928 constr
->top
.SetDone(true);
1933 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1935 wxLayoutConstraints
*constr
= GetConstraints();
1938 *w
= constr
->width
.GetValue();
1939 *h
= constr
->height
.GetValue();
1945 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1947 wxLayoutConstraints
*constr
= GetConstraints();
1950 *w
= constr
->width
.GetValue();
1951 *h
= constr
->height
.GetValue();
1954 GetClientSize(w
, h
);
1957 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1959 wxLayoutConstraints
*constr
= GetConstraints();
1962 *x
= constr
->left
.GetValue();
1963 *y
= constr
->top
.GetValue();
1969 #endif // wxUSE_CONSTRAINTS
1971 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1973 // don't do it for the dialogs/frames - they float independently of their
1975 if ( !IsTopLevel() )
1977 wxWindow
*parent
= GetParent();
1978 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1980 wxPoint
pt(parent
->GetClientAreaOrigin());
1987 // ----------------------------------------------------------------------------
1988 // do Update UI processing for child controls
1989 // ----------------------------------------------------------------------------
1991 void wxWindowBase::UpdateWindowUI(long flags
)
1993 wxUpdateUIEvent
event(GetId());
1994 event
.SetEventObject(this);
1996 if ( GetEventHandler()->ProcessEvent(event
) )
1998 DoUpdateWindowUI(event
);
2001 if (flags
& wxUPDATE_UI_RECURSE
)
2003 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2006 wxWindow
* child
= (wxWindow
*) node
->GetData();
2007 child
->UpdateWindowUI(flags
);
2008 node
= node
->GetNext();
2013 // do the window-specific processing after processing the update event
2014 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2016 if ( event
.GetSetEnabled() )
2017 Enable(event
.GetEnabled());
2019 if ( event
.GetSetShown() )
2020 Show(event
.GetShown());
2024 // call internal idle recursively
2025 // may be obsolete (wait until OnIdle scheme stabilises)
2026 void wxWindowBase::ProcessInternalIdle()
2030 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2033 wxWindow
*child
= node
->GetData();
2034 child
->ProcessInternalIdle();
2035 node
= node
->GetNext();
2040 // ----------------------------------------------------------------------------
2041 // dialog units translations
2042 // ----------------------------------------------------------------------------
2044 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2046 int charWidth
= GetCharWidth();
2047 int charHeight
= GetCharHeight();
2048 wxPoint pt2
= wxDefaultPosition
;
2049 if (pt
.x
!= wxDefaultCoord
)
2050 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2051 if (pt
.y
!= wxDefaultCoord
)
2052 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2057 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2059 int charWidth
= GetCharWidth();
2060 int charHeight
= GetCharHeight();
2061 wxPoint pt2
= wxDefaultPosition
;
2062 if (pt
.x
!= wxDefaultCoord
)
2063 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2064 if (pt
.y
!= wxDefaultCoord
)
2065 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2070 // ----------------------------------------------------------------------------
2072 // ----------------------------------------------------------------------------
2074 // propagate the colour change event to the subwindows
2075 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2077 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2080 // Only propagate to non-top-level windows
2081 wxWindow
*win
= node
->GetData();
2082 if ( !win
->IsTopLevel() )
2084 wxSysColourChangedEvent event2
;
2085 event
.SetEventObject(win
);
2086 win
->GetEventHandler()->ProcessEvent(event2
);
2089 node
= node
->GetNext();
2095 // the default action is to populate dialog with data when it's created,
2096 // and nudge the UI into displaying itself correctly in case
2097 // we've turned the wxUpdateUIEvents frequency down low.
2098 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2100 TransferDataToWindow();
2102 // Update the UI at this point
2103 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2106 // methods for drawing the sizers in a visible way
2109 static void DrawSizers(wxWindowBase
*win
);
2111 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2113 wxClientDC
dc((wxWindow
*)win
);
2114 dc
.SetPen(*wxRED_PEN
);
2115 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2116 dc
.DrawRectangle(rect
.Deflate(1, 1));
2119 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2121 const wxSizerItemList
& items
= sizer
->GetChildren();
2122 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2127 wxSizerItem
*item
= *i
;
2128 if ( item
->IsSizer() )
2130 DrawBorder(win
, item
->GetRect().Deflate(2));
2131 DrawSizer(win
, item
->GetSizer());
2133 else if ( item
->IsSpacer() )
2135 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2137 else if ( item
->IsWindow() )
2139 DrawSizers(item
->GetWindow());
2144 static void DrawSizers(wxWindowBase
*win
)
2146 wxSizer
*sizer
= win
->GetSizer();
2149 DrawBorder(win
, win
->GetClientSize());
2150 DrawSizer(win
, sizer
);
2152 else // no sizer, still recurse into the children
2154 const wxWindowList
& children
= win
->GetChildren();
2155 for ( wxWindowList::const_iterator i
= children
.begin(),
2156 end
= children
.end();
2165 #endif // __WXDEBUG__
2167 // process special middle clicks
2168 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2170 if ( event
.ControlDown() && event
.AltDown() )
2173 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2174 if ( event
.ShiftDown() )
2179 #endif // __WXDEBUG__
2182 // don't translate these strings, they're for diagnostics purposes only
2184 msg
.Printf(_T("wxWidgets Library (%s port)\n")
2185 _T("Version %d.%d.%d%s%s, compiled at %s %s\n")
2186 _T("Runtime version of toolkit used is %d.%d.%s\n")
2187 _T("Copyright (c) 1995-2006 wxWidgets team"),
2188 wxPlatformInfo::Get().GetPortIdName().c_str(),
2204 wxPlatformInfo::Get().GetToolkitMajorVersion(),
2205 wxPlatformInfo::Get().GetToolkitMinorVersion(),
2207 wxString::Format(_T("\nThe compile-time GTK+ version is %d.%d.%d."), GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
).c_str()
2213 wxMessageBox(msg
, _T("wxWidgets information"),
2214 wxICON_INFORMATION
| wxOK
,
2218 #endif // wxUSE_MSGDLG
2224 // ----------------------------------------------------------------------------
2226 // ----------------------------------------------------------------------------
2228 #if wxUSE_ACCESSIBILITY
2229 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2231 if (m_accessible
&& (accessible
!= m_accessible
))
2232 delete m_accessible
;
2233 m_accessible
= accessible
;
2235 m_accessible
->SetWindow((wxWindow
*) this);
2238 // Returns the accessible object, creating if necessary.
2239 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2242 m_accessible
= CreateAccessible();
2243 return m_accessible
;
2246 // Override to create a specific accessible object.
2247 wxAccessible
* wxWindowBase::CreateAccessible()
2249 return new wxWindowAccessible((wxWindow
*) this);
2254 // ----------------------------------------------------------------------------
2255 // list classes implementation
2256 // ----------------------------------------------------------------------------
2260 #include "wx/listimpl.cpp"
2261 WX_DEFINE_LIST(wxWindowList
)
2265 void wxWindowListNode::DeleteData()
2267 delete (wxWindow
*)GetData();
2272 // ----------------------------------------------------------------------------
2274 // ----------------------------------------------------------------------------
2276 wxBorder
wxWindowBase::GetBorder(long flags
) const
2278 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2279 if ( border
== wxBORDER_DEFAULT
)
2281 border
= GetDefaultBorder();
2287 wxBorder
wxWindowBase::GetDefaultBorder() const
2289 return wxBORDER_NONE
;
2292 // ----------------------------------------------------------------------------
2294 // ----------------------------------------------------------------------------
2296 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2298 // here we just check if the point is inside the window or not
2300 // check the top and left border first
2301 bool outside
= x
< 0 || y
< 0;
2304 // check the right and bottom borders too
2305 wxSize size
= GetSize();
2306 outside
= x
>= size
.x
|| y
>= size
.y
;
2309 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2312 // ----------------------------------------------------------------------------
2314 // ----------------------------------------------------------------------------
2316 struct WXDLLEXPORT wxWindowNext
2320 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2321 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2322 bool wxWindowBase::ms_winCaptureChanging
= false;
2324 void wxWindowBase::CaptureMouse()
2326 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2328 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2330 ms_winCaptureChanging
= true;
2332 wxWindow
*winOld
= GetCapture();
2335 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2338 wxWindowNext
*item
= new wxWindowNext
;
2340 item
->next
= ms_winCaptureNext
;
2341 ms_winCaptureNext
= item
;
2343 //else: no mouse capture to save
2346 ms_winCaptureCurrent
= (wxWindow
*)this;
2348 ms_winCaptureChanging
= false;
2351 void wxWindowBase::ReleaseMouse()
2353 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2355 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2357 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2359 ms_winCaptureChanging
= true;
2362 ms_winCaptureCurrent
= NULL
;
2364 if ( ms_winCaptureNext
)
2366 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2367 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2369 wxWindowNext
*item
= ms_winCaptureNext
;
2370 ms_winCaptureNext
= item
->next
;
2373 //else: stack is empty, no previous capture
2375 ms_winCaptureChanging
= false;
2377 wxLogTrace(_T("mousecapture"),
2378 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2379 wx_static_cast(void*, GetCapture()));
2382 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2384 wxMouseCaptureLostEvent
event(win
->GetId());
2385 event
.SetEventObject(win
);
2386 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2388 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2393 void wxWindowBase::NotifyCaptureLost()
2395 // don't do anything if capture lost was expected, i.e. resulted from
2396 // a wx call to ReleaseMouse or CaptureMouse:
2397 if ( ms_winCaptureChanging
)
2400 // if the capture was lost unexpectedly, notify every window that has
2401 // capture (on stack or current) about it and clear the stack:
2403 if ( ms_winCaptureCurrent
)
2405 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2406 ms_winCaptureCurrent
= NULL
;
2409 while ( ms_winCaptureNext
)
2411 wxWindowNext
*item
= ms_winCaptureNext
;
2412 ms_winCaptureNext
= item
->next
;
2414 DoNotifyWindowAboutCaptureLost(item
->win
);
2423 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2424 int WXUNUSED(modifiers
),
2425 int WXUNUSED(keycode
))
2431 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2437 #endif // wxUSE_HOTKEY
2439 void wxWindowBase::SendDestroyEvent()
2441 wxWindowDestroyEvent event
;
2442 event
.SetEventObject(this);
2443 event
.SetId(GetId());
2444 GetEventHandler()->ProcessEvent(event
);
2447 // ----------------------------------------------------------------------------
2449 // ----------------------------------------------------------------------------
2451 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2453 #if wxUSE_VALIDATORS
2454 // Can only use the validator of the window which
2455 // is receiving the event
2456 if ( event
.GetEventObject() == this )
2458 wxValidator
*validator
= GetValidator();
2459 if ( validator
&& validator
->ProcessEvent(event
) )
2464 #endif // wxUSE_VALIDATORS
2469 bool wxWindowBase::TryParent(wxEvent
& event
)
2471 // carry on up the parent-child hierarchy if the propagation count hasn't
2473 if ( event
.ShouldPropagate() )
2475 // honour the requests to stop propagation at this window: this is
2476 // used by the dialogs, for example, to prevent processing the events
2477 // from the dialog controls in the parent frame which rarely, if ever,
2479 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2481 wxWindow
*parent
= GetParent();
2482 if ( parent
&& !parent
->IsBeingDeleted() )
2484 wxPropagateOnce
propagateOnce(event
);
2486 return parent
->GetEventHandler()->ProcessEvent(event
);
2491 return wxEvtHandler::TryParent(event
);
2494 // ----------------------------------------------------------------------------
2495 // keyboard navigation
2496 // ----------------------------------------------------------------------------
2498 // Navigates in the specified direction.
2499 bool wxWindowBase::Navigate(int flags
)
2501 wxNavigationKeyEvent eventNav
;
2502 eventNav
.SetFlags(flags
);
2503 eventNav
.SetEventObject(this);
2504 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2511 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2513 // check that we're not a top level window
2514 wxCHECK_RET( GetParent(),
2515 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2517 // detect the special case when we have nothing to do anyhow and when the
2518 // code below wouldn't work
2522 // find the target window in the siblings list
2523 wxWindowList
& siblings
= GetParent()->GetChildren();
2524 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2525 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2527 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2528 // can't just move the node around
2529 wxWindow
*self
= (wxWindow
*)this;
2530 siblings
.DeleteObject(self
);
2531 if ( move
== MoveAfter
)
2538 siblings
.Insert(i
, self
);
2540 else // MoveAfter and win was the last sibling
2542 siblings
.Append(self
);
2546 // ----------------------------------------------------------------------------
2548 // ----------------------------------------------------------------------------
2550 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2552 wxWindowBase
*win
= DoFindFocus();
2553 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2556 // ----------------------------------------------------------------------------
2558 // ----------------------------------------------------------------------------
2560 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2562 while ( win
&& !win
->IsTopLevel() )
2563 win
= win
->GetParent();
2568 #if wxUSE_ACCESSIBILITY
2569 // ----------------------------------------------------------------------------
2570 // accessible object for windows
2571 // ----------------------------------------------------------------------------
2573 // Can return either a child object, or an integer
2574 // representing the child element, starting from 1.
2575 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2577 wxASSERT( GetWindow() != NULL
);
2581 return wxACC_NOT_IMPLEMENTED
;
2584 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2585 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2587 wxASSERT( GetWindow() != NULL
);
2591 wxWindow
* win
= NULL
;
2598 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2600 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2607 rect
= win
->GetRect();
2608 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2609 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2613 return wxACC_NOT_IMPLEMENTED
;
2616 // Navigates from fromId to toId/toObject.
2617 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2618 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2620 wxASSERT( GetWindow() != NULL
);
2626 case wxNAVDIR_FIRSTCHILD
:
2628 if (GetWindow()->GetChildren().GetCount() == 0)
2630 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2631 *toObject
= childWindow
->GetOrCreateAccessible();
2635 case wxNAVDIR_LASTCHILD
:
2637 if (GetWindow()->GetChildren().GetCount() == 0)
2639 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2640 *toObject
= childWindow
->GetOrCreateAccessible();
2644 case wxNAVDIR_RIGHT
:
2648 wxWindowList::compatibility_iterator node
=
2649 wxWindowList::compatibility_iterator();
2652 // Can't navigate to sibling of this window
2653 // if we're a top-level window.
2654 if (!GetWindow()->GetParent())
2655 return wxACC_NOT_IMPLEMENTED
;
2657 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2661 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2662 node
= GetWindow()->GetChildren().Item(fromId
-1);
2665 if (node
&& node
->GetNext())
2667 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2668 *toObject
= nextWindow
->GetOrCreateAccessible();
2676 case wxNAVDIR_PREVIOUS
:
2678 wxWindowList::compatibility_iterator node
=
2679 wxWindowList::compatibility_iterator();
2682 // Can't navigate to sibling of this window
2683 // if we're a top-level window.
2684 if (!GetWindow()->GetParent())
2685 return wxACC_NOT_IMPLEMENTED
;
2687 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2691 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2692 node
= GetWindow()->GetChildren().Item(fromId
-1);
2695 if (node
&& node
->GetPrevious())
2697 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2698 *toObject
= previousWindow
->GetOrCreateAccessible();
2706 return wxACC_NOT_IMPLEMENTED
;
2709 // Gets the name of the specified object.
2710 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2712 wxASSERT( GetWindow() != NULL
);
2718 // If a child, leave wxWidgets to call the function on the actual
2721 return wxACC_NOT_IMPLEMENTED
;
2723 // This will eventually be replaced by specialised
2724 // accessible classes, one for each kind of wxWidgets
2725 // control or window.
2727 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2728 title
= ((wxButton
*) GetWindow())->GetLabel();
2731 title
= GetWindow()->GetName();
2739 return wxACC_NOT_IMPLEMENTED
;
2742 // Gets the number of children.
2743 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2745 wxASSERT( GetWindow() != NULL
);
2749 *childId
= (int) GetWindow()->GetChildren().GetCount();
2753 // Gets the specified child (starting from 1).
2754 // If *child is NULL and return value is wxACC_OK,
2755 // this means that the child is a simple element and
2756 // not an accessible object.
2757 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2759 wxASSERT( GetWindow() != NULL
);
2769 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2772 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2773 *child
= childWindow
->GetOrCreateAccessible();
2780 // Gets the parent, or NULL.
2781 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2783 wxASSERT( GetWindow() != NULL
);
2787 wxWindow
* parentWindow
= GetWindow()->GetParent();
2795 *parent
= parentWindow
->GetOrCreateAccessible();
2803 // Performs the default action. childId is 0 (the action for this object)
2804 // or > 0 (the action for a child).
2805 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2806 // window (e.g. an edit control).
2807 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2809 wxASSERT( GetWindow() != NULL
);
2813 return wxACC_NOT_IMPLEMENTED
;
2816 // Gets the default action for this object (0) or > 0 (the action for a child).
2817 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2818 // string if there is no action.
2819 // The retrieved string describes the action that is performed on an object,
2820 // not what the object does as a result. For example, a toolbar button that prints
2821 // a document has a default action of "Press" rather than "Prints the current document."
2822 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2824 wxASSERT( GetWindow() != NULL
);
2828 return wxACC_NOT_IMPLEMENTED
;
2831 // Returns the description for this object or a child.
2832 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2834 wxASSERT( GetWindow() != NULL
);
2838 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2844 return wxACC_NOT_IMPLEMENTED
;
2847 // Returns help text for this object or a child, similar to tooltip text.
2848 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2850 wxASSERT( GetWindow() != NULL
);
2854 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2860 return wxACC_NOT_IMPLEMENTED
;
2863 // Returns the keyboard shortcut for this object or child.
2864 // Return e.g. ALT+K
2865 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2867 wxASSERT( GetWindow() != NULL
);
2871 return wxACC_NOT_IMPLEMENTED
;
2874 // Returns a role constant.
2875 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2877 wxASSERT( GetWindow() != NULL
);
2881 // If a child, leave wxWidgets to call the function on the actual
2884 return wxACC_NOT_IMPLEMENTED
;
2886 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2887 return wxACC_NOT_IMPLEMENTED
;
2889 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2890 return wxACC_NOT_IMPLEMENTED
;
2893 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2894 return wxACC_NOT_IMPLEMENTED
;
2897 //*role = wxROLE_SYSTEM_CLIENT;
2898 *role
= wxROLE_SYSTEM_CLIENT
;
2902 return wxACC_NOT_IMPLEMENTED
;
2906 // Returns a state constant.
2907 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2909 wxASSERT( GetWindow() != NULL
);
2913 // If a child, leave wxWidgets to call the function on the actual
2916 return wxACC_NOT_IMPLEMENTED
;
2918 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2919 return wxACC_NOT_IMPLEMENTED
;
2922 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2923 return wxACC_NOT_IMPLEMENTED
;
2926 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2927 return wxACC_NOT_IMPLEMENTED
;
2934 return wxACC_NOT_IMPLEMENTED
;
2938 // Returns a localized string representing the value for the object
2940 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2942 wxASSERT( GetWindow() != NULL
);
2946 return wxACC_NOT_IMPLEMENTED
;
2949 // Selects the object or child.
2950 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2952 wxASSERT( GetWindow() != NULL
);
2956 return wxACC_NOT_IMPLEMENTED
;
2959 // Gets the window with the keyboard focus.
2960 // If childId is 0 and child is NULL, no object in
2961 // this subhierarchy has the focus.
2962 // If this object has the focus, child should be 'this'.
2963 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2965 wxASSERT( GetWindow() != NULL
);
2969 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
;
2989 #endif // wxUSE_VARIANT
2991 #endif // wxUSE_ACCESSIBILITY
2993 // ----------------------------------------------------------------------------
2995 // ----------------------------------------------------------------------------
2998 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3000 wxCoord widthTotal
) const
3002 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3004 x
= widthTotal
- x
- width
;