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 void wxWindowBase::SendDestroyEvent()
356 wxWindowDestroyEvent event
;
357 event
.SetEventObject(this);
358 event
.SetId(GetId());
359 GetEventHandler()->ProcessEvent(event
);
362 bool wxWindowBase::Destroy()
369 bool wxWindowBase::Close(bool force
)
371 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
372 event
.SetEventObject(this);
373 event
.SetCanVeto(!force
);
375 // return false if window wasn't closed because the application vetoed the
377 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
380 bool wxWindowBase::DestroyChildren()
382 wxWindowList::compatibility_iterator node
;
385 // we iterate until the list becomes empty
386 node
= GetChildren().GetFirst();
390 wxWindow
*child
= node
->GetData();
392 // note that we really want to call delete and not ->Destroy() here
393 // because we want to delete the child immediately, before we are
394 // deleted, and delayed deletion would result in problems as our (top
395 // level) child could outlive its parent
398 wxASSERT_MSG( !GetChildren().Find(child
),
399 wxT("child didn't remove itself using RemoveChild()") );
405 // ----------------------------------------------------------------------------
406 // size/position related methods
407 // ----------------------------------------------------------------------------
409 // centre the window with respect to its parent in either (or both) directions
410 void wxWindowBase::DoCentre(int dir
)
412 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
413 _T("this method only implements centering child windows") );
415 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
418 // fits the window around the children
419 void wxWindowBase::Fit()
421 if ( !GetChildren().empty() )
423 SetSize(GetBestSize());
425 //else: do nothing if we have no children
428 // fits virtual size (ie. scrolled area etc.) around children
429 void wxWindowBase::FitInside()
431 if ( GetChildren().GetCount() > 0 )
433 SetVirtualSize( GetBestVirtualSize() );
437 // On Mac, scrollbars are explicitly children.
439 static bool wxHasRealChildren(const wxWindowBase
* win
)
441 int realChildCount
= 0;
443 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
445 node
= node
->GetNext() )
447 wxWindow
*win
= node
->GetData();
448 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
451 return (realChildCount
> 0);
455 void wxWindowBase::InvalidateBestSize()
457 m_bestSizeCache
= wxDefaultSize
;
459 // parent's best size calculation may depend on its children's
460 // as long as child window we are in is not top level window itself
461 // (because the TLW size is never resized automatically)
462 // so let's invalidate it as well to be safe:
463 if (m_parent
&& !IsTopLevel())
464 m_parent
->InvalidateBestSize();
467 // return the size best suited for the current window
468 wxSize
wxWindowBase::DoGetBestSize() const
474 best
= GetWindowSizeForVirtualSize(m_windowSizer
->GetMinSize());
476 #if wxUSE_CONSTRAINTS
477 else if ( m_constraints
)
479 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
481 // our minimal acceptable size is such that all our windows fit inside
485 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
487 node
= node
->GetNext() )
489 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
492 // it's not normal that we have an unconstrained child, but
493 // what can we do about it?
497 int x
= c
->right
.GetValue(),
498 y
= c
->bottom
.GetValue();
506 // TODO: we must calculate the overlaps somehow, otherwise we
507 // will never return a size bigger than the current one :-(
510 best
= wxSize(maxX
, maxY
);
512 #endif // wxUSE_CONSTRAINTS
513 else if ( !GetChildren().empty()
515 && wxHasRealChildren(this)
519 // our minimal acceptable size is such that all our visible child
520 // windows fit inside
524 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
526 node
= node
->GetNext() )
528 wxWindow
*win
= node
->GetData();
529 if ( win
->IsTopLevel()
532 || wxDynamicCast(win
, wxStatusBar
)
533 #endif // wxUSE_STATUSBAR
536 // dialogs and frames lie in different top level windows -
537 // don't deal with them here; as for the status bars, they
538 // don't lie in the client area at all
543 win
->GetPosition(&wx
, &wy
);
545 // if the window hadn't been positioned yet, assume that it is in
547 if ( wx
== wxDefaultCoord
)
549 if ( wy
== wxDefaultCoord
)
552 win
->GetSize(&ww
, &wh
);
553 if ( wx
+ ww
> maxX
)
555 if ( wy
+ wh
> maxY
)
559 best
= wxSize(maxX
, maxY
);
561 else // ! has children
563 // for a generic window there is no natural best size so, if the
564 // minimal size is not set, use the current size but take care to
565 // remember it as minimal size for the next time because our best size
566 // should be constant: otherwise we could get into a situation when the
567 // window is initially at some size, then expanded to a larger size and
568 // then, when the containing window is shrunk back (because our initial
569 // best size had been used for computing the parent min size), we can't
570 // be shrunk back any more because our best size is now bigger
571 wxSize size
= GetMinSize();
572 if ( !size
.IsFullySpecified() )
574 size
.SetDefaults(GetSize());
575 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
578 // return as-is, unadjusted by the client size difference.
582 // Add any difference between size and client size
583 wxSize diff
= GetSize() - GetClientSize();
584 best
.x
+= wxMax(0, diff
.x
);
585 best
.y
+= wxMax(0, diff
.y
);
591 wxSize
wxWindowBase::GetEffectiveMinSize() const
593 // merge the best size with the min size, giving priority to the min size
594 wxSize min
= GetMinSize();
595 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
597 wxSize best
= GetBestSize();
598 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
599 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
605 void wxWindowBase::SetInitialSize(const wxSize
& size
)
607 // Set the min size to the size passed in. This will usually either be
608 // wxDefaultSize or the size passed to this window's ctor/Create function.
611 // Merge the size with the best size if needed
612 wxSize best
= GetEffectiveMinSize();
614 // If the current size doesn't match then change it
615 if (GetSize() != best
)
620 // by default the origin is not shifted
621 wxPoint
wxWindowBase::GetClientAreaOrigin() const
626 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
628 if ( m_windowVariant
!= variant
)
630 m_windowVariant
= variant
;
632 DoSetWindowVariant(variant
);
636 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
638 // adjust the font height to correspond to our new variant (notice that
639 // we're only called if something really changed)
640 wxFont font
= GetFont();
641 int size
= font
.GetPointSize();
644 case wxWINDOW_VARIANT_NORMAL
:
647 case wxWINDOW_VARIANT_SMALL
:
652 case wxWINDOW_VARIANT_MINI
:
657 case wxWINDOW_VARIANT_LARGE
:
663 wxFAIL_MSG(_T("unexpected window variant"));
667 font
.SetPointSize(size
);
671 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
673 int WXUNUSED(incW
), int WXUNUSED(incH
) )
675 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
676 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
677 _T("min width/height must be less than max width/height!") );
686 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
689 m_minVirtualWidth
= minW
;
690 m_maxVirtualWidth
= maxW
;
691 m_minVirtualHeight
= minH
;
692 m_maxVirtualHeight
= maxH
;
695 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
697 if ( m_minVirtualWidth
!= wxDefaultCoord
&& m_minVirtualWidth
> x
)
698 x
= m_minVirtualWidth
;
699 if ( m_maxVirtualWidth
!= wxDefaultCoord
&& m_maxVirtualWidth
< x
)
700 x
= m_maxVirtualWidth
;
701 if ( m_minVirtualHeight
!= wxDefaultCoord
&& m_minVirtualHeight
> y
)
702 y
= m_minVirtualHeight
;
703 if ( m_maxVirtualHeight
!= wxDefaultCoord
&& m_maxVirtualHeight
< y
)
704 y
= m_maxVirtualHeight
;
706 m_virtualSize
= wxSize(x
, y
);
709 wxSize
wxWindowBase::DoGetVirtualSize() const
711 // we should use the entire client area so if it is greater than our
712 // virtual size, expand it to fit (otherwise if the window is big enough we
713 // wouldn't be using parts of it)
714 wxSize size
= GetClientSize();
715 if ( m_virtualSize
.x
> size
.x
)
716 size
.x
= m_virtualSize
.x
;
718 if ( m_virtualSize
.y
>= size
.y
)
719 size
.y
= m_virtualSize
.y
;
724 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
726 // screen position is the same as (0, 0) in client coords for non TLWs (and
727 // TLWs override this method)
733 ClientToScreen(x
, y
);
736 // ----------------------------------------------------------------------------
737 // show/hide/enable/disable the window
738 // ----------------------------------------------------------------------------
740 bool wxWindowBase::Show(bool show
)
742 if ( show
!= m_isShown
)
754 bool wxWindowBase::Enable(bool enable
)
756 if ( enable
!= m_isEnabled
)
758 m_isEnabled
= enable
;
768 bool wxWindowBase::IsShownOnScreen() const
771 (GetParent() == NULL
|| GetParent()->IsShownOnScreen());
774 // ----------------------------------------------------------------------------
776 // ----------------------------------------------------------------------------
778 bool wxWindowBase::IsTopLevel() const
783 // ----------------------------------------------------------------------------
784 // reparenting the window
785 // ----------------------------------------------------------------------------
787 void wxWindowBase::AddChild(wxWindowBase
*child
)
789 wxCHECK_RET( child
, wxT("can't add a NULL child") );
791 // this should never happen and it will lead to a crash later if it does
792 // because RemoveChild() will remove only one node from the children list
793 // and the other(s) one(s) will be left with dangling pointers in them
794 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
796 GetChildren().Append((wxWindow
*)child
);
797 child
->SetParent(this);
800 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
802 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
804 GetChildren().DeleteObject((wxWindow
*)child
);
805 child
->SetParent(NULL
);
808 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
810 wxWindow
*oldParent
= GetParent();
811 if ( newParent
== oldParent
)
817 // unlink this window from the existing parent.
820 oldParent
->RemoveChild(this);
824 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
827 // add it to the new one
830 newParent
->AddChild(this);
834 wxTopLevelWindows
.Append((wxWindow
*)this);
840 // ----------------------------------------------------------------------------
841 // event handler stuff
842 // ----------------------------------------------------------------------------
844 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
846 wxEvtHandler
*handlerOld
= GetEventHandler();
848 handler
->SetNextHandler(handlerOld
);
851 GetEventHandler()->SetPreviousHandler(handler
);
853 SetEventHandler(handler
);
856 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
858 wxEvtHandler
*handlerA
= GetEventHandler();
861 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
862 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
865 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
866 SetEventHandler(handlerB
);
871 handlerA
= (wxEvtHandler
*)NULL
;
878 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
880 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
882 wxEvtHandler
*handlerPrev
= NULL
,
883 *handlerCur
= GetEventHandler();
886 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
888 if ( handlerCur
== handler
)
892 handlerPrev
->SetNextHandler(handlerNext
);
896 SetEventHandler(handlerNext
);
901 handlerNext
->SetPreviousHandler ( handlerPrev
);
904 handler
->SetNextHandler(NULL
);
905 handler
->SetPreviousHandler(NULL
);
910 handlerPrev
= handlerCur
;
911 handlerCur
= handlerNext
;
914 wxFAIL_MSG( _T("where has the event handler gone?") );
919 // ----------------------------------------------------------------------------
921 // ----------------------------------------------------------------------------
923 void wxWindowBase::InheritAttributes()
925 const wxWindowBase
* const parent
= GetParent();
929 // we only inherit attributes which had been explicitly set for the parent
930 // which ensures that this only happens if the user really wants it and
931 // not by default which wouldn't make any sense in modern GUIs where the
932 // controls don't all use the same fonts (nor colours)
933 if ( parent
->m_inheritFont
&& !m_hasFont
)
934 SetFont(parent
->GetFont());
936 // in addition, there is a possibility to explicitly forbid inheriting
937 // colours at each class level by overriding ShouldInheritColours()
938 if ( ShouldInheritColours() )
940 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
941 SetForegroundColour(parent
->GetForegroundColour());
943 // inheriting (solid) background colour is wrong as it totally breaks
944 // any kind of themed backgrounds
946 // instead, the controls should use the same background as their parent
947 // (ideally by not drawing it at all)
949 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
950 SetBackgroundColour(parent
->GetBackgroundColour());
955 /* static */ wxVisualAttributes
956 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
958 // it is important to return valid values for all attributes from here,
959 // GetXXX() below rely on this
960 wxVisualAttributes attrs
;
961 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
962 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
964 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
965 // the usual background colour than wxSYS_COLOUR_BTNFACE.
966 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
967 // colour on other platforms.
969 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
970 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
972 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
977 wxColour
wxWindowBase::GetBackgroundColour() const
979 if ( !m_backgroundColour
.Ok() )
981 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
983 // get our default background colour
984 wxColour colBg
= GetDefaultAttributes().colBg
;
986 // we must return some valid colour to avoid redoing this every time
987 // and also to avoid surprizing the applications written for older
988 // wxWidgets versions where GetBackgroundColour() always returned
989 // something -- so give them something even if it doesn't make sense
990 // for this window (e.g. it has a themed background)
992 colBg
= GetClassDefaultAttributes().colBg
;
997 return m_backgroundColour
;
1000 wxColour
wxWindowBase::GetForegroundColour() const
1002 // logic is the same as above
1003 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1005 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
1007 wxColour colFg
= GetDefaultAttributes().colFg
;
1010 colFg
= GetClassDefaultAttributes().colFg
;
1015 return m_foregroundColour
;
1018 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1020 if ( colour
== m_backgroundColour
)
1023 m_hasBgCol
= colour
.Ok();
1024 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1025 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1027 m_inheritBgCol
= m_hasBgCol
;
1028 m_backgroundColour
= colour
;
1029 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1033 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1035 if (colour
== m_foregroundColour
)
1038 m_hasFgCol
= colour
.Ok();
1039 m_inheritFgCol
= m_hasFgCol
;
1040 m_foregroundColour
= colour
;
1041 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1045 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1047 // setting an invalid cursor is ok, it means that we don't have any special
1049 if ( m_cursor
.IsSameAs(cursor
) )
1060 wxFont
wxWindowBase::GetFont() const
1062 // logic is the same as in GetBackgroundColour()
1065 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1067 wxFont font
= GetDefaultAttributes().font
;
1069 font
= GetClassDefaultAttributes().font
;
1077 bool wxWindowBase::SetFont(const wxFont
& font
)
1079 if ( font
== m_font
)
1086 m_hasFont
= font
.Ok();
1087 m_inheritFont
= m_hasFont
;
1089 InvalidateBestSize();
1096 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1098 m_hasCustomPalette
= true;
1101 // VZ: can anyone explain me what do we do here?
1102 wxWindowDC
d((wxWindow
*) this);
1106 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1108 wxWindow
*win
= (wxWindow
*)this;
1109 while ( win
&& !win
->HasCustomPalette() )
1111 win
= win
->GetParent();
1117 #endif // wxUSE_PALETTE
1120 void wxWindowBase::SetCaret(wxCaret
*caret
)
1131 wxASSERT_MSG( m_caret
->GetWindow() == this,
1132 wxT("caret should be created associated to this window") );
1135 #endif // wxUSE_CARET
1137 #if wxUSE_VALIDATORS
1138 // ----------------------------------------------------------------------------
1140 // ----------------------------------------------------------------------------
1142 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1144 if ( m_windowValidator
)
1145 delete m_windowValidator
;
1147 m_windowValidator
= (wxValidator
*)validator
.Clone();
1149 if ( m_windowValidator
)
1150 m_windowValidator
->SetWindow(this);
1152 #endif // wxUSE_VALIDATORS
1154 // ----------------------------------------------------------------------------
1155 // update region stuff
1156 // ----------------------------------------------------------------------------
1158 wxRect
wxWindowBase::GetUpdateClientRect() const
1160 wxRegion rgnUpdate
= GetUpdateRegion();
1161 rgnUpdate
.Intersect(GetClientRect());
1162 wxRect rectUpdate
= rgnUpdate
.GetBox();
1163 wxPoint ptOrigin
= GetClientAreaOrigin();
1164 rectUpdate
.x
-= ptOrigin
.x
;
1165 rectUpdate
.y
-= ptOrigin
.y
;
1170 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1172 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1175 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1177 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1180 void wxWindowBase::ClearBackground()
1182 // wxGTK uses its own version, no need to add never used code
1184 wxClientDC
dc((wxWindow
*)this);
1185 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1186 dc
.SetBackground(brush
);
1191 // ----------------------------------------------------------------------------
1192 // find child window by id or name
1193 // ----------------------------------------------------------------------------
1195 wxWindow
*wxWindowBase::FindWindow(long id
) const
1197 if ( id
== m_windowId
)
1198 return (wxWindow
*)this;
1200 wxWindowBase
*res
= (wxWindow
*)NULL
;
1201 wxWindowList::compatibility_iterator node
;
1202 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1204 wxWindowBase
*child
= node
->GetData();
1205 res
= child
->FindWindow( id
);
1208 return (wxWindow
*)res
;
1211 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1213 if ( name
== m_windowName
)
1214 return (wxWindow
*)this;
1216 wxWindowBase
*res
= (wxWindow
*)NULL
;
1217 wxWindowList::compatibility_iterator node
;
1218 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1220 wxWindow
*child
= node
->GetData();
1221 res
= child
->FindWindow(name
);
1224 return (wxWindow
*)res
;
1228 // find any window by id or name or label: If parent is non-NULL, look through
1229 // children for a label or title matching the specified string. If NULL, look
1230 // through all top-level windows.
1232 // to avoid duplicating code we reuse the same helper function but with
1233 // different comparators
1235 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1236 const wxString
& label
, long id
);
1239 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1242 return win
->GetLabel() == label
;
1246 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1249 return win
->GetName() == label
;
1253 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1256 return win
->GetId() == id
;
1259 // recursive helper for the FindWindowByXXX() functions
1261 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1262 const wxString
& label
,
1264 wxFindWindowCmp cmp
)
1268 // see if this is the one we're looking for
1269 if ( (*cmp
)(parent
, label
, id
) )
1270 return (wxWindow
*)parent
;
1272 // It wasn't, so check all its children
1273 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1275 node
= node
->GetNext() )
1277 // recursively check each child
1278 wxWindow
*win
= (wxWindow
*)node
->GetData();
1279 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1289 // helper for FindWindowByXXX()
1291 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1292 const wxString
& label
,
1294 wxFindWindowCmp cmp
)
1298 // just check parent and all its children
1299 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1302 // start at very top of wx's windows
1303 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1305 node
= node
->GetNext() )
1307 // recursively check each window & its children
1308 wxWindow
*win
= node
->GetData();
1309 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1319 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1321 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1326 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1328 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1332 // fall back to the label
1333 win
= FindWindowByLabel(title
, parent
);
1341 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1343 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1346 // ----------------------------------------------------------------------------
1347 // dialog oriented functions
1348 // ----------------------------------------------------------------------------
1350 void wxWindowBase::MakeModal(bool modal
)
1352 // Disable all other windows
1355 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1358 wxWindow
*win
= node
->GetData();
1360 win
->Enable(!modal
);
1362 node
= node
->GetNext();
1367 bool wxWindowBase::Validate()
1369 #if wxUSE_VALIDATORS
1370 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1372 wxWindowList::compatibility_iterator node
;
1373 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1375 wxWindowBase
*child
= node
->GetData();
1376 wxValidator
*validator
= child
->GetValidator();
1377 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1382 if ( recurse
&& !child
->Validate() )
1387 #endif // wxUSE_VALIDATORS
1392 bool wxWindowBase::TransferDataToWindow()
1394 #if wxUSE_VALIDATORS
1395 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1397 wxWindowList::compatibility_iterator node
;
1398 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1400 wxWindowBase
*child
= node
->GetData();
1401 wxValidator
*validator
= child
->GetValidator();
1402 if ( validator
&& !validator
->TransferToWindow() )
1404 wxLogWarning(_("Could not transfer data to window"));
1406 wxLog::FlushActive();
1414 if ( !child
->TransferDataToWindow() )
1416 // warning already given
1421 #endif // wxUSE_VALIDATORS
1426 bool wxWindowBase::TransferDataFromWindow()
1428 #if wxUSE_VALIDATORS
1429 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1431 wxWindowList::compatibility_iterator node
;
1432 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1434 wxWindow
*child
= node
->GetData();
1435 wxValidator
*validator
= child
->GetValidator();
1436 if ( validator
&& !validator
->TransferFromWindow() )
1438 // nop warning here because the application is supposed to give
1439 // one itself - we don't know here what might have gone wrongly
1446 if ( !child
->TransferDataFromWindow() )
1448 // warning already given
1453 #endif // wxUSE_VALIDATORS
1458 void wxWindowBase::InitDialog()
1460 wxInitDialogEvent
event(GetId());
1461 event
.SetEventObject( this );
1462 GetEventHandler()->ProcessEvent(event
);
1465 // ----------------------------------------------------------------------------
1466 // context-sensitive help support
1467 // ----------------------------------------------------------------------------
1471 // associate this help text with this window
1472 void wxWindowBase::SetHelpText(const wxString
& text
)
1474 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1477 helpProvider
->AddHelp(this, text
);
1481 // associate this help text with all windows with the same id as this
1483 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1485 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1488 helpProvider
->AddHelp(GetId(), text
);
1492 // get the help string associated with this window (may be empty)
1493 // default implementation forwards calls to the help provider
1495 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1496 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1499 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1502 text
= helpProvider
->GetHelp(this);
1508 // show help for this window
1509 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1511 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1514 if ( helpProvider
->ShowHelpAtPoint(this, event
.GetPosition(), event
.GetOrigin()) )
1516 // skip the event.Skip() below
1524 #endif // wxUSE_HELP
1526 // ----------------------------------------------------------------------------
1528 // ----------------------------------------------------------------------------
1532 void wxWindowBase::SetToolTip( const wxString
&tip
)
1534 // don't create the new tooltip if we already have one
1537 m_tooltip
->SetTip( tip
);
1541 SetToolTip( new wxToolTip( tip
) );
1544 // setting empty tooltip text does not remove the tooltip any more - use
1545 // SetToolTip((wxToolTip *)NULL) for this
1548 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1550 if ( m_tooltip
!= tooltip
)
1555 m_tooltip
= tooltip
;
1559 #endif // wxUSE_TOOLTIPS
1561 // ----------------------------------------------------------------------------
1562 // constraints and sizers
1563 // ----------------------------------------------------------------------------
1565 #if wxUSE_CONSTRAINTS
1567 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1569 if ( m_constraints
)
1571 UnsetConstraints(m_constraints
);
1572 delete m_constraints
;
1574 m_constraints
= constraints
;
1575 if ( m_constraints
)
1577 // Make sure other windows know they're part of a 'meaningful relationship'
1578 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1579 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1580 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1581 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1582 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1583 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1584 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1585 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1586 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1587 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1588 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1589 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1590 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1591 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1592 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1593 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1597 // This removes any dangling pointers to this window in other windows'
1598 // constraintsInvolvedIn lists.
1599 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1603 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1604 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1605 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1606 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1607 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1608 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1609 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1610 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1611 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1612 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1613 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1614 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1615 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1616 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1617 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1618 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1622 // Back-pointer to other windows we're involved with, so if we delete this
1623 // window, we must delete any constraints we're involved with.
1624 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1626 if ( !m_constraintsInvolvedIn
)
1627 m_constraintsInvolvedIn
= new wxWindowList
;
1628 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1629 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1632 // REMOVE back-pointer to other windows we're involved with.
1633 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1635 if ( m_constraintsInvolvedIn
)
1636 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1639 // Reset any constraints that mention this window
1640 void wxWindowBase::DeleteRelatedConstraints()
1642 if ( m_constraintsInvolvedIn
)
1644 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1647 wxWindow
*win
= node
->GetData();
1648 wxLayoutConstraints
*constr
= win
->GetConstraints();
1650 // Reset any constraints involving this window
1653 constr
->left
.ResetIfWin(this);
1654 constr
->top
.ResetIfWin(this);
1655 constr
->right
.ResetIfWin(this);
1656 constr
->bottom
.ResetIfWin(this);
1657 constr
->width
.ResetIfWin(this);
1658 constr
->height
.ResetIfWin(this);
1659 constr
->centreX
.ResetIfWin(this);
1660 constr
->centreY
.ResetIfWin(this);
1663 wxWindowList::compatibility_iterator next
= node
->GetNext();
1664 m_constraintsInvolvedIn
->Erase(node
);
1668 delete m_constraintsInvolvedIn
;
1669 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1673 #endif // wxUSE_CONSTRAINTS
1675 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1677 if ( sizer
== m_windowSizer
)
1680 if ( m_windowSizer
)
1682 m_windowSizer
->SetContainingWindow(NULL
);
1685 delete m_windowSizer
;
1688 m_windowSizer
= sizer
;
1689 if ( m_windowSizer
)
1691 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
1694 SetAutoLayout(m_windowSizer
!= NULL
);
1697 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1699 SetSizer( sizer
, deleteOld
);
1700 sizer
->SetSizeHints( (wxWindow
*) this );
1704 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1706 // adding a window to a sizer twice is going to result in fatal and
1707 // hard to debug problems later because when deleting the second
1708 // associated wxSizerItem we're going to dereference a dangling
1709 // pointer; so try to detect this as early as possible
1710 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1711 _T("Adding a window to the same sizer twice?") );
1713 m_containingSizer
= sizer
;
1716 #if wxUSE_CONSTRAINTS
1718 void wxWindowBase::SatisfyConstraints()
1720 wxLayoutConstraints
*constr
= GetConstraints();
1721 bool wasOk
= constr
&& constr
->AreSatisfied();
1723 ResetConstraints(); // Mark all constraints as unevaluated
1727 // if we're a top level panel (i.e. our parent is frame/dialog), our
1728 // own constraints will never be satisfied any more unless we do it
1732 while ( noChanges
> 0 )
1734 LayoutPhase1(&noChanges
);
1738 LayoutPhase2(&noChanges
);
1741 #endif // wxUSE_CONSTRAINTS
1743 bool wxWindowBase::Layout()
1745 // If there is a sizer, use it instead of the constraints
1749 GetVirtualSize(&w
, &h
);
1750 GetSizer()->SetDimension( 0, 0, w
, h
);
1752 #if wxUSE_CONSTRAINTS
1755 SatisfyConstraints(); // Find the right constraints values
1756 SetConstraintSizes(); // Recursively set the real window sizes
1763 #if wxUSE_CONSTRAINTS
1765 // first phase of the constraints evaluation: set our own constraints
1766 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1768 wxLayoutConstraints
*constr
= GetConstraints();
1770 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1773 // second phase: set the constraints for our children
1774 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1781 // Layout grand children
1787 // Do a phase of evaluating child constraints
1788 bool wxWindowBase::DoPhase(int phase
)
1790 // the list containing the children for which the constraints are already
1792 wxWindowList succeeded
;
1794 // the max number of iterations we loop before concluding that we can't set
1796 static const int maxIterations
= 500;
1798 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1802 // loop over all children setting their constraints
1803 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1805 node
= node
->GetNext() )
1807 wxWindow
*child
= node
->GetData();
1808 if ( child
->IsTopLevel() )
1810 // top level children are not inside our client area
1814 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1816 // this one is either already ok or nothing we can do about it
1820 int tempNoChanges
= 0;
1821 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1822 : child
->LayoutPhase2(&tempNoChanges
);
1823 noChanges
+= tempNoChanges
;
1827 succeeded
.Append(child
);
1833 // constraints are set
1841 void wxWindowBase::ResetConstraints()
1843 wxLayoutConstraints
*constr
= GetConstraints();
1846 constr
->left
.SetDone(false);
1847 constr
->top
.SetDone(false);
1848 constr
->right
.SetDone(false);
1849 constr
->bottom
.SetDone(false);
1850 constr
->width
.SetDone(false);
1851 constr
->height
.SetDone(false);
1852 constr
->centreX
.SetDone(false);
1853 constr
->centreY
.SetDone(false);
1856 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1859 wxWindow
*win
= node
->GetData();
1860 if ( !win
->IsTopLevel() )
1861 win
->ResetConstraints();
1862 node
= node
->GetNext();
1866 // Need to distinguish between setting the 'fake' size for windows and sizers,
1867 // and setting the real values.
1868 void wxWindowBase::SetConstraintSizes(bool recurse
)
1870 wxLayoutConstraints
*constr
= GetConstraints();
1871 if ( constr
&& constr
->AreSatisfied() )
1873 int x
= constr
->left
.GetValue();
1874 int y
= constr
->top
.GetValue();
1875 int w
= constr
->width
.GetValue();
1876 int h
= constr
->height
.GetValue();
1878 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1879 (constr
->height
.GetRelationship() != wxAsIs
) )
1881 SetSize(x
, y
, w
, h
);
1885 // If we don't want to resize this window, just move it...
1891 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1892 GetClassInfo()->GetClassName(),
1898 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1901 wxWindow
*win
= node
->GetData();
1902 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1903 win
->SetConstraintSizes();
1904 node
= node
->GetNext();
1909 // Only set the size/position of the constraint (if any)
1910 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1912 wxLayoutConstraints
*constr
= GetConstraints();
1915 if ( x
!= wxDefaultCoord
)
1917 constr
->left
.SetValue(x
);
1918 constr
->left
.SetDone(true);
1920 if ( y
!= wxDefaultCoord
)
1922 constr
->top
.SetValue(y
);
1923 constr
->top
.SetDone(true);
1925 if ( w
!= wxDefaultCoord
)
1927 constr
->width
.SetValue(w
);
1928 constr
->width
.SetDone(true);
1930 if ( h
!= wxDefaultCoord
)
1932 constr
->height
.SetValue(h
);
1933 constr
->height
.SetDone(true);
1938 void wxWindowBase::MoveConstraint(int x
, int y
)
1940 wxLayoutConstraints
*constr
= GetConstraints();
1943 if ( x
!= wxDefaultCoord
)
1945 constr
->left
.SetValue(x
);
1946 constr
->left
.SetDone(true);
1948 if ( y
!= wxDefaultCoord
)
1950 constr
->top
.SetValue(y
);
1951 constr
->top
.SetDone(true);
1956 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1958 wxLayoutConstraints
*constr
= GetConstraints();
1961 *w
= constr
->width
.GetValue();
1962 *h
= constr
->height
.GetValue();
1968 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1970 wxLayoutConstraints
*constr
= GetConstraints();
1973 *w
= constr
->width
.GetValue();
1974 *h
= constr
->height
.GetValue();
1977 GetClientSize(w
, h
);
1980 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1982 wxLayoutConstraints
*constr
= GetConstraints();
1985 *x
= constr
->left
.GetValue();
1986 *y
= constr
->top
.GetValue();
1992 #endif // wxUSE_CONSTRAINTS
1994 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1996 // don't do it for the dialogs/frames - they float independently of their
1998 if ( !IsTopLevel() )
2000 wxWindow
*parent
= GetParent();
2001 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2003 wxPoint
pt(parent
->GetClientAreaOrigin());
2010 // ----------------------------------------------------------------------------
2011 // Update UI processing
2012 // ----------------------------------------------------------------------------
2014 void wxWindowBase::UpdateWindowUI(long flags
)
2016 wxUpdateUIEvent
event(GetId());
2017 event
.SetEventObject(this);
2019 if ( GetEventHandler()->ProcessEvent(event
) )
2021 DoUpdateWindowUI(event
);
2024 if (flags
& wxUPDATE_UI_RECURSE
)
2026 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2029 wxWindow
* child
= (wxWindow
*) node
->GetData();
2030 child
->UpdateWindowUI(flags
);
2031 node
= node
->GetNext();
2036 // do the window-specific processing after processing the update event
2037 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2039 if ( event
.GetSetEnabled() )
2040 Enable(event
.GetEnabled());
2042 if ( event
.GetSetShown() )
2043 Show(event
.GetShown());
2046 // ----------------------------------------------------------------------------
2047 // dialog units translations
2048 // ----------------------------------------------------------------------------
2050 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2052 int charWidth
= GetCharWidth();
2053 int charHeight
= GetCharHeight();
2054 wxPoint pt2
= wxDefaultPosition
;
2055 if (pt
.x
!= wxDefaultCoord
)
2056 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2057 if (pt
.y
!= wxDefaultCoord
)
2058 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2063 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2065 int charWidth
= GetCharWidth();
2066 int charHeight
= GetCharHeight();
2067 wxPoint pt2
= wxDefaultPosition
;
2068 if (pt
.x
!= wxDefaultCoord
)
2069 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2070 if (pt
.y
!= wxDefaultCoord
)
2071 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2076 // ----------------------------------------------------------------------------
2078 // ----------------------------------------------------------------------------
2080 // propagate the colour change event to the subwindows
2081 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2083 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2086 // Only propagate to non-top-level windows
2087 wxWindow
*win
= node
->GetData();
2088 if ( !win
->IsTopLevel() )
2090 wxSysColourChangedEvent event2
;
2091 event
.SetEventObject(win
);
2092 win
->GetEventHandler()->ProcessEvent(event2
);
2095 node
= node
->GetNext();
2101 // the default action is to populate dialog with data when it's created,
2102 // and nudge the UI into displaying itself correctly in case
2103 // we've turned the wxUpdateUIEvents frequency down low.
2104 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2106 TransferDataToWindow();
2108 // Update the UI at this point
2109 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2112 // methods for drawing the sizers in a visible way
2115 static void DrawSizers(wxWindowBase
*win
);
2117 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2119 wxClientDC
dc((wxWindow
*)win
);
2120 dc
.SetPen(*wxRED_PEN
);
2121 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2122 dc
.DrawRectangle(rect
.Deflate(1, 1));
2125 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2127 const wxSizerItemList
& items
= sizer
->GetChildren();
2128 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2133 wxSizerItem
*item
= *i
;
2134 if ( item
->IsSizer() )
2136 DrawBorder(win
, item
->GetRect().Deflate(2));
2137 DrawSizer(win
, item
->GetSizer());
2139 else if ( item
->IsSpacer() )
2141 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2143 else if ( item
->IsWindow() )
2145 DrawSizers(item
->GetWindow());
2150 static void DrawSizers(wxWindowBase
*win
)
2152 wxSizer
*sizer
= win
->GetSizer();
2155 DrawBorder(win
, win
->GetClientSize());
2156 DrawSizer(win
, sizer
);
2158 else // no sizer, still recurse into the children
2160 const wxWindowList
& children
= win
->GetChildren();
2161 for ( wxWindowList::const_iterator i
= children
.begin(),
2162 end
= children
.end();
2171 #endif // __WXDEBUG__
2173 // process special middle clicks
2174 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2176 if ( event
.ControlDown() && event
.AltDown() )
2179 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2180 if ( event
.ShiftDown() )
2185 #endif // __WXDEBUG__
2188 // don't translate these strings, they're for diagnostics purposes only
2190 msg
.Printf(_T("wxWidgets Library (%s port)\n")
2191 _T("Version %d.%d.%d%s%s, compiled at %s %s\n")
2192 _T("Runtime version of toolkit used is %d.%d.%s\n")
2193 _T("Copyright (c) 1995-2006 wxWidgets team"),
2194 wxPlatformInfo::Get().GetPortIdName().c_str(),
2210 wxPlatformInfo::Get().GetToolkitMajorVersion(),
2211 wxPlatformInfo::Get().GetToolkitMinorVersion(),
2213 wxString::Format(_T("\nThe compile-time GTK+ version is %d.%d.%d."), GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
).c_str()
2219 wxMessageBox(msg
, _T("wxWidgets information"),
2220 wxICON_INFORMATION
| wxOK
,
2224 #endif // wxUSE_MSGDLG
2230 // ----------------------------------------------------------------------------
2232 // ----------------------------------------------------------------------------
2234 #if wxUSE_ACCESSIBILITY
2235 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2237 if (m_accessible
&& (accessible
!= m_accessible
))
2238 delete m_accessible
;
2239 m_accessible
= accessible
;
2241 m_accessible
->SetWindow((wxWindow
*) this);
2244 // Returns the accessible object, creating if necessary.
2245 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2248 m_accessible
= CreateAccessible();
2249 return m_accessible
;
2252 // Override to create a specific accessible object.
2253 wxAccessible
* wxWindowBase::CreateAccessible()
2255 return new wxWindowAccessible((wxWindow
*) this);
2260 // ----------------------------------------------------------------------------
2261 // list classes implementation
2262 // ----------------------------------------------------------------------------
2266 #include "wx/listimpl.cpp"
2267 WX_DEFINE_LIST(wxWindowList
)
2271 void wxWindowListNode::DeleteData()
2273 delete (wxWindow
*)GetData();
2276 #endif // wxUSE_STL/!wxUSE_STL
2278 // ----------------------------------------------------------------------------
2280 // ----------------------------------------------------------------------------
2282 wxBorder
wxWindowBase::GetBorder(long flags
) const
2284 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2285 if ( border
== wxBORDER_DEFAULT
)
2287 border
= GetDefaultBorder();
2293 wxBorder
wxWindowBase::GetDefaultBorder() const
2295 return wxBORDER_NONE
;
2298 // ----------------------------------------------------------------------------
2300 // ----------------------------------------------------------------------------
2302 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2304 // here we just check if the point is inside the window or not
2306 // check the top and left border first
2307 bool outside
= x
< 0 || y
< 0;
2310 // check the right and bottom borders too
2311 wxSize size
= GetSize();
2312 outside
= x
>= size
.x
|| y
>= size
.y
;
2315 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2318 // ----------------------------------------------------------------------------
2320 // ----------------------------------------------------------------------------
2322 struct WXDLLEXPORT wxWindowNext
2326 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2327 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2328 bool wxWindowBase::ms_winCaptureChanging
= false;
2330 void wxWindowBase::CaptureMouse()
2332 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2334 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2336 ms_winCaptureChanging
= true;
2338 wxWindow
*winOld
= GetCapture();
2341 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2344 wxWindowNext
*item
= new wxWindowNext
;
2346 item
->next
= ms_winCaptureNext
;
2347 ms_winCaptureNext
= item
;
2349 //else: no mouse capture to save
2352 ms_winCaptureCurrent
= (wxWindow
*)this;
2354 ms_winCaptureChanging
= false;
2357 void wxWindowBase::ReleaseMouse()
2359 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2361 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2363 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2365 ms_winCaptureChanging
= true;
2368 ms_winCaptureCurrent
= NULL
;
2370 if ( ms_winCaptureNext
)
2372 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2373 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2375 wxWindowNext
*item
= ms_winCaptureNext
;
2376 ms_winCaptureNext
= item
->next
;
2379 //else: stack is empty, no previous capture
2381 ms_winCaptureChanging
= false;
2383 wxLogTrace(_T("mousecapture"),
2384 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2385 wx_static_cast(void*, GetCapture()));
2388 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2390 wxMouseCaptureLostEvent
event(win
->GetId());
2391 event
.SetEventObject(win
);
2392 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2394 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2399 void wxWindowBase::NotifyCaptureLost()
2401 // don't do anything if capture lost was expected, i.e. resulted from
2402 // a wx call to ReleaseMouse or CaptureMouse:
2403 if ( ms_winCaptureChanging
)
2406 // if the capture was lost unexpectedly, notify every window that has
2407 // capture (on stack or current) about it and clear the stack:
2409 if ( ms_winCaptureCurrent
)
2411 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2412 ms_winCaptureCurrent
= NULL
;
2415 while ( ms_winCaptureNext
)
2417 wxWindowNext
*item
= ms_winCaptureNext
;
2418 ms_winCaptureNext
= item
->next
;
2420 DoNotifyWindowAboutCaptureLost(item
->win
);
2429 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2430 int WXUNUSED(modifiers
),
2431 int WXUNUSED(keycode
))
2437 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2443 #endif // wxUSE_HOTKEY
2445 // ----------------------------------------------------------------------------
2447 // ----------------------------------------------------------------------------
2449 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2451 #if wxUSE_VALIDATORS
2452 // Can only use the validator of the window which
2453 // is receiving the event
2454 if ( event
.GetEventObject() == this )
2456 wxValidator
*validator
= GetValidator();
2457 if ( validator
&& validator
->ProcessEvent(event
) )
2462 #endif // wxUSE_VALIDATORS
2467 bool wxWindowBase::TryParent(wxEvent
& event
)
2469 // carry on up the parent-child hierarchy if the propagation count hasn't
2471 if ( event
.ShouldPropagate() )
2473 // honour the requests to stop propagation at this window: this is
2474 // used by the dialogs, for example, to prevent processing the events
2475 // from the dialog controls in the parent frame which rarely, if ever,
2477 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2479 wxWindow
*parent
= GetParent();
2480 if ( parent
&& !parent
->IsBeingDeleted() )
2482 wxPropagateOnce
propagateOnce(event
);
2484 return parent
->GetEventHandler()->ProcessEvent(event
);
2489 return wxEvtHandler::TryParent(event
);
2492 // ----------------------------------------------------------------------------
2493 // keyboard navigation
2494 // ----------------------------------------------------------------------------
2496 // Navigates in the specified direction.
2497 bool wxWindowBase::Navigate(int flags
)
2499 wxNavigationKeyEvent eventNav
;
2500 eventNav
.SetFlags(flags
);
2501 eventNav
.SetEventObject(this);
2502 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2509 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2511 // check that we're not a top level window
2512 wxCHECK_RET( GetParent(),
2513 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2515 // detect the special case when we have nothing to do anyhow and when the
2516 // code below wouldn't work
2520 // find the target window in the siblings list
2521 wxWindowList
& siblings
= GetParent()->GetChildren();
2522 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2523 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2525 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2526 // can't just move the node around
2527 wxWindow
*self
= (wxWindow
*)this;
2528 siblings
.DeleteObject(self
);
2529 if ( move
== MoveAfter
)
2536 siblings
.Insert(i
, self
);
2538 else // MoveAfter and win was the last sibling
2540 siblings
.Append(self
);
2544 // ----------------------------------------------------------------------------
2546 // ----------------------------------------------------------------------------
2548 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2550 wxWindowBase
*win
= DoFindFocus();
2551 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2554 // ----------------------------------------------------------------------------
2556 // ----------------------------------------------------------------------------
2558 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2560 while ( win
&& !win
->IsTopLevel() )
2561 win
= win
->GetParent();
2566 #if wxUSE_ACCESSIBILITY
2567 // ----------------------------------------------------------------------------
2568 // accessible object for windows
2569 // ----------------------------------------------------------------------------
2571 // Can return either a child object, or an integer
2572 // representing the child element, starting from 1.
2573 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2575 wxASSERT( GetWindow() != NULL
);
2579 return wxACC_NOT_IMPLEMENTED
;
2582 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2583 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2585 wxASSERT( GetWindow() != NULL
);
2589 wxWindow
* win
= NULL
;
2596 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2598 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2605 rect
= win
->GetRect();
2606 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2607 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2611 return wxACC_NOT_IMPLEMENTED
;
2614 // Navigates from fromId to toId/toObject.
2615 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2616 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2618 wxASSERT( GetWindow() != NULL
);
2624 case wxNAVDIR_FIRSTCHILD
:
2626 if (GetWindow()->GetChildren().GetCount() == 0)
2628 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2629 *toObject
= childWindow
->GetOrCreateAccessible();
2633 case wxNAVDIR_LASTCHILD
:
2635 if (GetWindow()->GetChildren().GetCount() == 0)
2637 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2638 *toObject
= childWindow
->GetOrCreateAccessible();
2642 case wxNAVDIR_RIGHT
:
2646 wxWindowList::compatibility_iterator node
=
2647 wxWindowList::compatibility_iterator();
2650 // Can't navigate to sibling of this window
2651 // if we're a top-level window.
2652 if (!GetWindow()->GetParent())
2653 return wxACC_NOT_IMPLEMENTED
;
2655 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2659 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2660 node
= GetWindow()->GetChildren().Item(fromId
-1);
2663 if (node
&& node
->GetNext())
2665 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2666 *toObject
= nextWindow
->GetOrCreateAccessible();
2674 case wxNAVDIR_PREVIOUS
:
2676 wxWindowList::compatibility_iterator node
=
2677 wxWindowList::compatibility_iterator();
2680 // Can't navigate to sibling of this window
2681 // if we're a top-level window.
2682 if (!GetWindow()->GetParent())
2683 return wxACC_NOT_IMPLEMENTED
;
2685 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2689 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2690 node
= GetWindow()->GetChildren().Item(fromId
-1);
2693 if (node
&& node
->GetPrevious())
2695 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2696 *toObject
= previousWindow
->GetOrCreateAccessible();
2704 return wxACC_NOT_IMPLEMENTED
;
2707 // Gets the name of the specified object.
2708 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2710 wxASSERT( GetWindow() != NULL
);
2716 // If a child, leave wxWidgets to call the function on the actual
2719 return wxACC_NOT_IMPLEMENTED
;
2721 // This will eventually be replaced by specialised
2722 // accessible classes, one for each kind of wxWidgets
2723 // control or window.
2725 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2726 title
= ((wxButton
*) GetWindow())->GetLabel();
2729 title
= GetWindow()->GetName();
2737 return wxACC_NOT_IMPLEMENTED
;
2740 // Gets the number of children.
2741 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2743 wxASSERT( GetWindow() != NULL
);
2747 *childId
= (int) GetWindow()->GetChildren().GetCount();
2751 // Gets the specified child (starting from 1).
2752 // If *child is NULL and return value is wxACC_OK,
2753 // this means that the child is a simple element and
2754 // not an accessible object.
2755 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2757 wxASSERT( GetWindow() != NULL
);
2767 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2770 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2771 *child
= childWindow
->GetOrCreateAccessible();
2778 // Gets the parent, or NULL.
2779 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2781 wxASSERT( GetWindow() != NULL
);
2785 wxWindow
* parentWindow
= GetWindow()->GetParent();
2793 *parent
= parentWindow
->GetOrCreateAccessible();
2801 // Performs the default action. childId is 0 (the action for this object)
2802 // or > 0 (the action for a child).
2803 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2804 // window (e.g. an edit control).
2805 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2807 wxASSERT( GetWindow() != NULL
);
2811 return wxACC_NOT_IMPLEMENTED
;
2814 // Gets the default action for this object (0) or > 0 (the action for a child).
2815 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2816 // string if there is no action.
2817 // The retrieved string describes the action that is performed on an object,
2818 // not what the object does as a result. For example, a toolbar button that prints
2819 // a document has a default action of "Press" rather than "Prints the current document."
2820 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2822 wxASSERT( GetWindow() != NULL
);
2826 return wxACC_NOT_IMPLEMENTED
;
2829 // Returns the description for this object or a child.
2830 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2832 wxASSERT( GetWindow() != NULL
);
2836 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2842 return wxACC_NOT_IMPLEMENTED
;
2845 // Returns help text for this object or a child, similar to tooltip text.
2846 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2848 wxASSERT( GetWindow() != NULL
);
2852 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2858 return wxACC_NOT_IMPLEMENTED
;
2861 // Returns the keyboard shortcut for this object or child.
2862 // Return e.g. ALT+K
2863 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2865 wxASSERT( GetWindow() != NULL
);
2869 return wxACC_NOT_IMPLEMENTED
;
2872 // Returns a role constant.
2873 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2875 wxASSERT( GetWindow() != NULL
);
2879 // If a child, leave wxWidgets to call the function on the actual
2882 return wxACC_NOT_IMPLEMENTED
;
2884 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2885 return wxACC_NOT_IMPLEMENTED
;
2887 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2888 return wxACC_NOT_IMPLEMENTED
;
2891 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2892 return wxACC_NOT_IMPLEMENTED
;
2895 //*role = wxROLE_SYSTEM_CLIENT;
2896 *role
= wxROLE_SYSTEM_CLIENT
;
2900 return wxACC_NOT_IMPLEMENTED
;
2904 // Returns a state constant.
2905 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2907 wxASSERT( GetWindow() != NULL
);
2911 // If a child, leave wxWidgets to call the function on the actual
2914 return wxACC_NOT_IMPLEMENTED
;
2916 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2917 return wxACC_NOT_IMPLEMENTED
;
2920 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2921 return wxACC_NOT_IMPLEMENTED
;
2924 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2925 return wxACC_NOT_IMPLEMENTED
;
2932 return wxACC_NOT_IMPLEMENTED
;
2936 // Returns a localized string representing the value for the object
2938 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2940 wxASSERT( GetWindow() != NULL
);
2944 return wxACC_NOT_IMPLEMENTED
;
2947 // Selects the object or child.
2948 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2950 wxASSERT( GetWindow() != NULL
);
2954 return wxACC_NOT_IMPLEMENTED
;
2957 // Gets the window with the keyboard focus.
2958 // If childId is 0 and child is NULL, no object in
2959 // this subhierarchy has the focus.
2960 // If this object has the focus, child should be 'this'.
2961 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2963 wxASSERT( GetWindow() != NULL
);
2967 return wxACC_NOT_IMPLEMENTED
;
2971 // Gets a variant representing the selected children
2973 // Acceptable values:
2974 // - a null variant (IsNull() returns true)
2975 // - a list variant (GetType() == wxT("list")
2976 // - an integer representing the selected child element,
2977 // or 0 if this object is selected (GetType() == wxT("long")
2978 // - a "void*" pointer to a wxAccessible child object
2979 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2981 wxASSERT( GetWindow() != NULL
);
2985 return wxACC_NOT_IMPLEMENTED
;
2987 #endif // wxUSE_VARIANT
2989 #endif // wxUSE_ACCESSIBILITY
2991 // ----------------------------------------------------------------------------
2993 // ----------------------------------------------------------------------------
2996 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
2998 wxCoord widthTotal
) const
3000 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3002 x
= widthTotal
- x
- width
;