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
;
254 // don't use SetWindowStyleFlag() here, this function should only be called
255 // to change the flag after creation as it tries to reflect the changes in
256 // flags by updating the window dynamically and we don't need this here
257 m_windowStyle
= style
;
263 SetValidator(validator
);
264 #endif // wxUSE_VALIDATORS
266 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
267 // have it too - like this it's possible to set it only in the top level
268 // dialog/frame and all children will inherit it by defult
269 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
271 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
277 bool wxWindowBase::ToggleWindowStyle(int flag
)
279 wxASSERT_MSG( flag
, _T("flags with 0 value can't be toggled") );
282 long style
= GetWindowStyleFlag();
288 else // currently off
294 SetWindowStyleFlag(style
);
299 // ----------------------------------------------------------------------------
301 // ----------------------------------------------------------------------------
304 wxWindowBase::~wxWindowBase()
306 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
308 // FIXME if these 2 cases result from programming errors in the user code
309 // we should probably assert here instead of silently fixing them
311 // Just in case the window has been Closed, but we're then deleting
312 // immediately: don't leave dangling pointers.
313 wxPendingDelete
.DeleteObject(this);
315 // Just in case we've loaded a top-level window via LoadNativeDialog but
316 // we weren't a dialog class
317 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
319 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
321 // reset the top-level parent's default item if it is this widget
324 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this),
327 if ( tlw
&& tlw
->GetDefaultItem() == this )
328 tlw
->SetDefaultItem(NULL
);
329 if ( tlw
&& tlw
->GetTmpDefaultItem() == this )
330 tlw
->SetTmpDefaultItem(NULL
);
333 // reset the dangling pointer our parent window may keep to us
336 m_parent
->RemoveChild(this);
341 #endif // wxUSE_CARET
344 delete m_windowValidator
;
345 #endif // wxUSE_VALIDATORS
347 #if wxUSE_CONSTRAINTS
348 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
349 // at deleted windows as they delete themselves.
350 DeleteRelatedConstraints();
354 // This removes any dangling pointers to this window in other windows'
355 // constraintsInvolvedIn lists.
356 UnsetConstraints(m_constraints
);
357 delete m_constraints
;
358 m_constraints
= NULL
;
360 #endif // wxUSE_CONSTRAINTS
362 if ( m_containingSizer
)
363 m_containingSizer
->Detach( (wxWindow
*)this );
365 delete m_windowSizer
;
367 #if wxUSE_DRAG_AND_DROP
369 #endif // wxUSE_DRAG_AND_DROP
373 #endif // wxUSE_TOOLTIPS
375 #if wxUSE_ACCESSIBILITY
380 void wxWindowBase::SendDestroyEvent()
382 wxWindowDestroyEvent event
;
383 event
.SetEventObject(this);
384 event
.SetId(GetId());
385 GetEventHandler()->ProcessEvent(event
);
388 bool wxWindowBase::Destroy()
395 bool wxWindowBase::Close(bool force
)
397 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
398 event
.SetEventObject(this);
399 event
.SetCanVeto(!force
);
401 // return false if window wasn't closed because the application vetoed the
403 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
406 bool wxWindowBase::DestroyChildren()
408 wxWindowList::compatibility_iterator node
;
411 // we iterate until the list becomes empty
412 node
= GetChildren().GetFirst();
416 wxWindow
*child
= node
->GetData();
418 // note that we really want to call delete and not ->Destroy() here
419 // because we want to delete the child immediately, before we are
420 // deleted, and delayed deletion would result in problems as our (top
421 // level) child could outlive its parent
424 wxASSERT_MSG( !GetChildren().Find(child
),
425 wxT("child didn't remove itself using RemoveChild()") );
431 // ----------------------------------------------------------------------------
432 // size/position related methods
433 // ----------------------------------------------------------------------------
435 // centre the window with respect to its parent in either (or both) directions
436 void wxWindowBase::DoCentre(int dir
)
438 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
439 _T("this method only implements centering child windows") );
441 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
444 // fits the window around the children
445 void wxWindowBase::Fit()
447 if ( !GetChildren().empty() )
449 SetSize(GetBestSize());
451 //else: do nothing if we have no children
454 // fits virtual size (ie. scrolled area etc.) around children
455 void wxWindowBase::FitInside()
457 if ( GetChildren().GetCount() > 0 )
459 SetVirtualSize( GetBestVirtualSize() );
463 // On Mac, scrollbars are explicitly children.
465 static bool wxHasRealChildren(const wxWindowBase
* win
)
467 int realChildCount
= 0;
469 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
471 node
= node
->GetNext() )
473 wxWindow
*win
= node
->GetData();
474 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
477 return (realChildCount
> 0);
481 void wxWindowBase::InvalidateBestSize()
483 m_bestSizeCache
= wxDefaultSize
;
485 // parent's best size calculation may depend on its children's
486 // as long as child window we are in is not top level window itself
487 // (because the TLW size is never resized automatically)
488 // so let's invalidate it as well to be safe:
489 if (m_parent
&& !IsTopLevel())
490 m_parent
->InvalidateBestSize();
493 // return the size best suited for the current window
494 wxSize
wxWindowBase::DoGetBestSize() const
500 best
= GetWindowSizeForVirtualSize(m_windowSizer
->GetMinSize());
502 #if wxUSE_CONSTRAINTS
503 else if ( m_constraints
)
505 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
507 // our minimal acceptable size is such that all our windows fit inside
511 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
513 node
= node
->GetNext() )
515 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
518 // it's not normal that we have an unconstrained child, but
519 // what can we do about it?
523 int x
= c
->right
.GetValue(),
524 y
= c
->bottom
.GetValue();
532 // TODO: we must calculate the overlaps somehow, otherwise we
533 // will never return a size bigger than the current one :-(
536 best
= wxSize(maxX
, maxY
);
538 #endif // wxUSE_CONSTRAINTS
539 else if ( !GetChildren().empty()
541 && wxHasRealChildren(this)
545 // our minimal acceptable size is such that all our visible child
546 // windows fit inside
550 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
552 node
= node
->GetNext() )
554 wxWindow
*win
= node
->GetData();
555 if ( win
->IsTopLevel()
558 || wxDynamicCast(win
, wxStatusBar
)
559 #endif // wxUSE_STATUSBAR
562 // dialogs and frames lie in different top level windows -
563 // don't deal with them here; as for the status bars, they
564 // don't lie in the client area at all
569 win
->GetPosition(&wx
, &wy
);
571 // if the window hadn't been positioned yet, assume that it is in
573 if ( wx
== wxDefaultCoord
)
575 if ( wy
== wxDefaultCoord
)
578 win
->GetSize(&ww
, &wh
);
579 if ( wx
+ ww
> maxX
)
581 if ( wy
+ wh
> maxY
)
585 best
= wxSize(maxX
, maxY
);
587 else // ! has children
589 // for a generic window there is no natural best size so, if the
590 // minimal size is not set, use the current size but take care to
591 // remember it as minimal size for the next time because our best size
592 // should be constant: otherwise we could get into a situation when the
593 // window is initially at some size, then expanded to a larger size and
594 // then, when the containing window is shrunk back (because our initial
595 // best size had been used for computing the parent min size), we can't
596 // be shrunk back any more because our best size is now bigger
597 wxSize size
= GetMinSize();
598 if ( !size
.IsFullySpecified() )
600 size
.SetDefaults(GetSize());
601 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
604 // return as-is, unadjusted by the client size difference.
608 // Add any difference between size and client size
609 wxSize diff
= GetSize() - GetClientSize();
610 best
.x
+= wxMax(0, diff
.x
);
611 best
.y
+= wxMax(0, diff
.y
);
616 // helper of GetWindowBorderSize(): as many ports don't implement support for
617 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
618 // fallbacks in this case
619 static int wxGetMetricOrDefault(wxSystemMetric what
)
621 int rc
= wxSystemSettings::GetMetric(what
);
628 // 2D border is by default 1 pixel wide
634 // 3D borders are by default 2 pixels
639 wxFAIL_MSG( _T("unexpected wxGetMetricOrDefault() argument") );
647 wxSize
wxWindowBase::GetWindowBorderSize() const
651 switch ( GetBorder() )
654 // nothing to do, size is already (0, 0)
657 case wxBORDER_SIMPLE
:
658 case wxBORDER_STATIC
:
659 size
.x
= wxGetMetricOrDefault(wxSYS_BORDER_X
);
660 size
.y
= wxGetMetricOrDefault(wxSYS_BORDER_Y
);
663 case wxBORDER_SUNKEN
:
664 case wxBORDER_RAISED
:
665 size
.x
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X
),
666 wxGetMetricOrDefault(wxSYS_BORDER_X
));
667 size
.y
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y
),
668 wxGetMetricOrDefault(wxSYS_BORDER_Y
));
671 case wxBORDER_DOUBLE
:
672 size
.x
= wxGetMetricOrDefault(wxSYS_EDGE_X
) +
673 wxGetMetricOrDefault(wxSYS_BORDER_X
);
674 size
.y
= wxGetMetricOrDefault(wxSYS_EDGE_Y
) +
675 wxGetMetricOrDefault(wxSYS_BORDER_Y
);
679 wxFAIL_MSG(_T("Unknown border style."));
683 // we have borders on both sides
687 wxSize
wxWindowBase::GetEffectiveMinSize() const
689 // merge the best size with the min size, giving priority to the min size
690 wxSize min
= GetMinSize();
691 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
693 wxSize best
= GetBestSize();
694 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
695 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
701 void wxWindowBase::SetInitialSize(const wxSize
& size
)
703 // Set the min size to the size passed in. This will usually either be
704 // wxDefaultSize or the size passed to this window's ctor/Create function.
707 // Merge the size with the best size if needed
708 wxSize best
= GetEffectiveMinSize();
710 // If the current size doesn't match then change it
711 if (GetSize() != best
)
716 // by default the origin is not shifted
717 wxPoint
wxWindowBase::GetClientAreaOrigin() const
722 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
724 if ( m_windowVariant
!= variant
)
726 m_windowVariant
= variant
;
728 DoSetWindowVariant(variant
);
732 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
734 // adjust the font height to correspond to our new variant (notice that
735 // we're only called if something really changed)
736 wxFont font
= GetFont();
737 int size
= font
.GetPointSize();
740 case wxWINDOW_VARIANT_NORMAL
:
743 case wxWINDOW_VARIANT_SMALL
:
748 case wxWINDOW_VARIANT_MINI
:
753 case wxWINDOW_VARIANT_LARGE
:
759 wxFAIL_MSG(_T("unexpected window variant"));
763 font
.SetPointSize(size
);
767 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
769 int WXUNUSED(incW
), int WXUNUSED(incH
) )
771 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
772 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
773 _T("min width/height must be less than max width/height!") );
782 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
785 m_minVirtualWidth
= minW
;
786 m_maxVirtualWidth
= maxW
;
787 m_minVirtualHeight
= minH
;
788 m_maxVirtualHeight
= maxH
;
791 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
793 if ( m_minVirtualWidth
!= wxDefaultCoord
&& m_minVirtualWidth
> x
)
794 x
= m_minVirtualWidth
;
795 if ( m_maxVirtualWidth
!= wxDefaultCoord
&& m_maxVirtualWidth
< x
)
796 x
= m_maxVirtualWidth
;
797 if ( m_minVirtualHeight
!= wxDefaultCoord
&& m_minVirtualHeight
> y
)
798 y
= m_minVirtualHeight
;
799 if ( m_maxVirtualHeight
!= wxDefaultCoord
&& m_maxVirtualHeight
< y
)
800 y
= m_maxVirtualHeight
;
802 m_virtualSize
= wxSize(x
, y
);
805 wxSize
wxWindowBase::DoGetVirtualSize() const
807 // we should use the entire client area so if it is greater than our
808 // virtual size, expand it to fit (otherwise if the window is big enough we
809 // wouldn't be using parts of it)
810 wxSize size
= GetClientSize();
811 if ( m_virtualSize
.x
> size
.x
)
812 size
.x
= m_virtualSize
.x
;
814 if ( m_virtualSize
.y
>= size
.y
)
815 size
.y
= m_virtualSize
.y
;
820 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
822 // screen position is the same as (0, 0) in client coords for non TLWs (and
823 // TLWs override this method)
829 ClientToScreen(x
, y
);
832 // ----------------------------------------------------------------------------
833 // show/hide/enable/disable the window
834 // ----------------------------------------------------------------------------
836 bool wxWindowBase::Show(bool show
)
838 if ( show
!= m_isShown
)
850 bool wxWindowBase::Enable(bool enable
)
852 if ( enable
!= m_isEnabled
)
854 m_isEnabled
= enable
;
864 bool wxWindowBase::IsShownOnScreen() const
867 (GetParent() == NULL
|| GetParent()->IsShownOnScreen());
870 // ----------------------------------------------------------------------------
872 // ----------------------------------------------------------------------------
874 bool wxWindowBase::IsTopLevel() const
879 // ----------------------------------------------------------------------------
880 // reparenting the window
881 // ----------------------------------------------------------------------------
883 void wxWindowBase::AddChild(wxWindowBase
*child
)
885 wxCHECK_RET( child
, wxT("can't add a NULL child") );
887 // this should never happen and it will lead to a crash later if it does
888 // because RemoveChild() will remove only one node from the children list
889 // and the other(s) one(s) will be left with dangling pointers in them
890 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
892 GetChildren().Append((wxWindow
*)child
);
893 child
->SetParent(this);
896 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
898 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
900 GetChildren().DeleteObject((wxWindow
*)child
);
901 child
->SetParent(NULL
);
904 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
906 wxWindow
*oldParent
= GetParent();
907 if ( newParent
== oldParent
)
913 // unlink this window from the existing parent.
916 oldParent
->RemoveChild(this);
920 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
923 // add it to the new one
926 newParent
->AddChild(this);
930 wxTopLevelWindows
.Append((wxWindow
*)this);
936 // ----------------------------------------------------------------------------
937 // event handler stuff
938 // ----------------------------------------------------------------------------
940 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
942 wxEvtHandler
*handlerOld
= GetEventHandler();
944 handler
->SetNextHandler(handlerOld
);
947 GetEventHandler()->SetPreviousHandler(handler
);
949 SetEventHandler(handler
);
952 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
954 wxEvtHandler
*handlerA
= GetEventHandler();
957 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
958 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
961 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
962 SetEventHandler(handlerB
);
967 handlerA
= (wxEvtHandler
*)NULL
;
974 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
976 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
978 wxEvtHandler
*handlerPrev
= NULL
,
979 *handlerCur
= GetEventHandler();
982 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
984 if ( handlerCur
== handler
)
988 handlerPrev
->SetNextHandler(handlerNext
);
992 SetEventHandler(handlerNext
);
997 handlerNext
->SetPreviousHandler ( handlerPrev
);
1000 handler
->SetNextHandler(NULL
);
1001 handler
->SetPreviousHandler(NULL
);
1006 handlerPrev
= handlerCur
;
1007 handlerCur
= handlerNext
;
1010 wxFAIL_MSG( _T("where has the event handler gone?") );
1015 // ----------------------------------------------------------------------------
1016 // colours, fonts &c
1017 // ----------------------------------------------------------------------------
1019 void wxWindowBase::InheritAttributes()
1021 const wxWindowBase
* const parent
= GetParent();
1025 // we only inherit attributes which had been explicitly set for the parent
1026 // which ensures that this only happens if the user really wants it and
1027 // not by default which wouldn't make any sense in modern GUIs where the
1028 // controls don't all use the same fonts (nor colours)
1029 if ( parent
->m_inheritFont
&& !m_hasFont
)
1030 SetFont(parent
->GetFont());
1032 // in addition, there is a possibility to explicitly forbid inheriting
1033 // colours at each class level by overriding ShouldInheritColours()
1034 if ( ShouldInheritColours() )
1036 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1037 SetForegroundColour(parent
->GetForegroundColour());
1039 // inheriting (solid) background colour is wrong as it totally breaks
1040 // any kind of themed backgrounds
1042 // instead, the controls should use the same background as their parent
1043 // (ideally by not drawing it at all)
1045 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1046 SetBackgroundColour(parent
->GetBackgroundColour());
1051 /* static */ wxVisualAttributes
1052 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1054 // it is important to return valid values for all attributes from here,
1055 // GetXXX() below rely on this
1056 wxVisualAttributes attrs
;
1057 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1058 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1060 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1061 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1062 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1063 // colour on other platforms.
1065 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1066 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1068 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1073 wxColour
wxWindowBase::GetBackgroundColour() const
1075 if ( !m_backgroundColour
.Ok() )
1077 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
1079 // get our default background colour
1080 wxColour colBg
= GetDefaultAttributes().colBg
;
1082 // we must return some valid colour to avoid redoing this every time
1083 // and also to avoid surprizing the applications written for older
1084 // wxWidgets versions where GetBackgroundColour() always returned
1085 // something -- so give them something even if it doesn't make sense
1086 // for this window (e.g. it has a themed background)
1088 colBg
= GetClassDefaultAttributes().colBg
;
1093 return m_backgroundColour
;
1096 wxColour
wxWindowBase::GetForegroundColour() const
1098 // logic is the same as above
1099 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1101 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
1103 wxColour colFg
= GetDefaultAttributes().colFg
;
1106 colFg
= GetClassDefaultAttributes().colFg
;
1111 return m_foregroundColour
;
1114 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1116 if ( colour
== m_backgroundColour
)
1119 m_hasBgCol
= colour
.Ok();
1120 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1121 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1123 m_inheritBgCol
= m_hasBgCol
;
1124 m_backgroundColour
= colour
;
1125 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1129 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1131 if (colour
== m_foregroundColour
)
1134 m_hasFgCol
= colour
.Ok();
1135 m_inheritFgCol
= m_hasFgCol
;
1136 m_foregroundColour
= colour
;
1137 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1141 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1143 // setting an invalid cursor is ok, it means that we don't have any special
1145 if ( m_cursor
.IsSameAs(cursor
) )
1156 wxFont
wxWindowBase::GetFont() const
1158 // logic is the same as in GetBackgroundColour()
1161 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1163 wxFont font
= GetDefaultAttributes().font
;
1165 font
= GetClassDefaultAttributes().font
;
1173 bool wxWindowBase::SetFont(const wxFont
& font
)
1175 if ( font
== m_font
)
1182 m_hasFont
= font
.Ok();
1183 m_inheritFont
= m_hasFont
;
1185 InvalidateBestSize();
1192 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1194 m_hasCustomPalette
= true;
1197 // VZ: can anyone explain me what do we do here?
1198 wxWindowDC
d((wxWindow
*) this);
1202 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1204 wxWindow
*win
= (wxWindow
*)this;
1205 while ( win
&& !win
->HasCustomPalette() )
1207 win
= win
->GetParent();
1213 #endif // wxUSE_PALETTE
1216 void wxWindowBase::SetCaret(wxCaret
*caret
)
1227 wxASSERT_MSG( m_caret
->GetWindow() == this,
1228 wxT("caret should be created associated to this window") );
1231 #endif // wxUSE_CARET
1233 #if wxUSE_VALIDATORS
1234 // ----------------------------------------------------------------------------
1236 // ----------------------------------------------------------------------------
1238 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1240 if ( m_windowValidator
)
1241 delete m_windowValidator
;
1243 m_windowValidator
= (wxValidator
*)validator
.Clone();
1245 if ( m_windowValidator
)
1246 m_windowValidator
->SetWindow(this);
1248 #endif // wxUSE_VALIDATORS
1250 // ----------------------------------------------------------------------------
1251 // update region stuff
1252 // ----------------------------------------------------------------------------
1254 wxRect
wxWindowBase::GetUpdateClientRect() const
1256 wxRegion rgnUpdate
= GetUpdateRegion();
1257 rgnUpdate
.Intersect(GetClientRect());
1258 wxRect rectUpdate
= rgnUpdate
.GetBox();
1259 wxPoint ptOrigin
= GetClientAreaOrigin();
1260 rectUpdate
.x
-= ptOrigin
.x
;
1261 rectUpdate
.y
-= ptOrigin
.y
;
1266 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1268 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1271 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1273 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1276 void wxWindowBase::ClearBackground()
1278 // wxGTK uses its own version, no need to add never used code
1280 wxClientDC
dc((wxWindow
*)this);
1281 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1282 dc
.SetBackground(brush
);
1287 // ----------------------------------------------------------------------------
1288 // find child window by id or name
1289 // ----------------------------------------------------------------------------
1291 wxWindow
*wxWindowBase::FindWindow(long id
) const
1293 if ( id
== m_windowId
)
1294 return (wxWindow
*)this;
1296 wxWindowBase
*res
= (wxWindow
*)NULL
;
1297 wxWindowList::compatibility_iterator node
;
1298 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1300 wxWindowBase
*child
= node
->GetData();
1301 res
= child
->FindWindow( id
);
1304 return (wxWindow
*)res
;
1307 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1309 if ( name
== m_windowName
)
1310 return (wxWindow
*)this;
1312 wxWindowBase
*res
= (wxWindow
*)NULL
;
1313 wxWindowList::compatibility_iterator node
;
1314 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1316 wxWindow
*child
= node
->GetData();
1317 res
= child
->FindWindow(name
);
1320 return (wxWindow
*)res
;
1324 // find any window by id or name or label: If parent is non-NULL, look through
1325 // children for a label or title matching the specified string. If NULL, look
1326 // through all top-level windows.
1328 // to avoid duplicating code we reuse the same helper function but with
1329 // different comparators
1331 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1332 const wxString
& label
, long id
);
1335 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1338 return win
->GetLabel() == label
;
1342 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1345 return win
->GetName() == label
;
1349 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1352 return win
->GetId() == id
;
1355 // recursive helper for the FindWindowByXXX() functions
1357 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1358 const wxString
& label
,
1360 wxFindWindowCmp cmp
)
1364 // see if this is the one we're looking for
1365 if ( (*cmp
)(parent
, label
, id
) )
1366 return (wxWindow
*)parent
;
1368 // It wasn't, so check all its children
1369 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1371 node
= node
->GetNext() )
1373 // recursively check each child
1374 wxWindow
*win
= (wxWindow
*)node
->GetData();
1375 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1385 // helper for FindWindowByXXX()
1387 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1388 const wxString
& label
,
1390 wxFindWindowCmp cmp
)
1394 // just check parent and all its children
1395 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1398 // start at very top of wx's windows
1399 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1401 node
= node
->GetNext() )
1403 // recursively check each window & its children
1404 wxWindow
*win
= node
->GetData();
1405 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1415 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1417 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1422 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1424 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1428 // fall back to the label
1429 win
= FindWindowByLabel(title
, parent
);
1437 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1439 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1442 // ----------------------------------------------------------------------------
1443 // dialog oriented functions
1444 // ----------------------------------------------------------------------------
1446 void wxWindowBase::MakeModal(bool modal
)
1448 // Disable all other windows
1451 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1454 wxWindow
*win
= node
->GetData();
1456 win
->Enable(!modal
);
1458 node
= node
->GetNext();
1463 bool wxWindowBase::Validate()
1465 #if wxUSE_VALIDATORS
1466 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1468 wxWindowList::compatibility_iterator node
;
1469 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1471 wxWindowBase
*child
= node
->GetData();
1472 wxValidator
*validator
= child
->GetValidator();
1473 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1478 if ( recurse
&& !child
->Validate() )
1483 #endif // wxUSE_VALIDATORS
1488 bool wxWindowBase::TransferDataToWindow()
1490 #if wxUSE_VALIDATORS
1491 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1493 wxWindowList::compatibility_iterator node
;
1494 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1496 wxWindowBase
*child
= node
->GetData();
1497 wxValidator
*validator
= child
->GetValidator();
1498 if ( validator
&& !validator
->TransferToWindow() )
1500 wxLogWarning(_("Could not transfer data to window"));
1502 wxLog::FlushActive();
1510 if ( !child
->TransferDataToWindow() )
1512 // warning already given
1517 #endif // wxUSE_VALIDATORS
1522 bool wxWindowBase::TransferDataFromWindow()
1524 #if wxUSE_VALIDATORS
1525 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1527 wxWindowList::compatibility_iterator node
;
1528 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1530 wxWindow
*child
= node
->GetData();
1531 wxValidator
*validator
= child
->GetValidator();
1532 if ( validator
&& !validator
->TransferFromWindow() )
1534 // nop warning here because the application is supposed to give
1535 // one itself - we don't know here what might have gone wrongly
1542 if ( !child
->TransferDataFromWindow() )
1544 // warning already given
1549 #endif // wxUSE_VALIDATORS
1554 void wxWindowBase::InitDialog()
1556 wxInitDialogEvent
event(GetId());
1557 event
.SetEventObject( this );
1558 GetEventHandler()->ProcessEvent(event
);
1561 // ----------------------------------------------------------------------------
1562 // context-sensitive help support
1563 // ----------------------------------------------------------------------------
1567 // associate this help text with this window
1568 void wxWindowBase::SetHelpText(const wxString
& text
)
1570 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1573 helpProvider
->AddHelp(this, text
);
1577 // associate this help text with all windows with the same id as this
1579 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1581 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1584 helpProvider
->AddHelp(GetId(), text
);
1588 // get the help string associated with this window (may be empty)
1589 // default implementation forwards calls to the help provider
1591 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1592 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1595 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1598 text
= helpProvider
->GetHelp(this);
1604 // show help for this window
1605 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1607 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1610 if ( helpProvider
->ShowHelpAtPoint(this, event
.GetPosition(), event
.GetOrigin()) )
1612 // skip the event.Skip() below
1620 #endif // wxUSE_HELP
1622 // ----------------------------------------------------------------------------
1624 // ----------------------------------------------------------------------------
1628 void wxWindowBase::SetToolTip( const wxString
&tip
)
1630 // don't create the new tooltip if we already have one
1633 m_tooltip
->SetTip( tip
);
1637 SetToolTip( new wxToolTip( tip
) );
1640 // setting empty tooltip text does not remove the tooltip any more - use
1641 // SetToolTip((wxToolTip *)NULL) for this
1644 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1646 if ( m_tooltip
!= tooltip
)
1651 m_tooltip
= tooltip
;
1655 #endif // wxUSE_TOOLTIPS
1657 // ----------------------------------------------------------------------------
1658 // constraints and sizers
1659 // ----------------------------------------------------------------------------
1661 #if wxUSE_CONSTRAINTS
1663 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1665 if ( m_constraints
)
1667 UnsetConstraints(m_constraints
);
1668 delete m_constraints
;
1670 m_constraints
= constraints
;
1671 if ( m_constraints
)
1673 // Make sure other windows know they're part of a 'meaningful relationship'
1674 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1675 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1676 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1677 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1678 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1679 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1680 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1681 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1682 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1683 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1684 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1685 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1686 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1687 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1688 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1689 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1693 // This removes any dangling pointers to this window in other windows'
1694 // constraintsInvolvedIn lists.
1695 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1699 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1700 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1701 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1702 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1703 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1704 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1705 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1706 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1707 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1708 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1709 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1710 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1711 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1712 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1713 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1714 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1718 // Back-pointer to other windows we're involved with, so if we delete this
1719 // window, we must delete any constraints we're involved with.
1720 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1722 if ( !m_constraintsInvolvedIn
)
1723 m_constraintsInvolvedIn
= new wxWindowList
;
1724 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1725 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1728 // REMOVE back-pointer to other windows we're involved with.
1729 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1731 if ( m_constraintsInvolvedIn
)
1732 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1735 // Reset any constraints that mention this window
1736 void wxWindowBase::DeleteRelatedConstraints()
1738 if ( m_constraintsInvolvedIn
)
1740 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1743 wxWindow
*win
= node
->GetData();
1744 wxLayoutConstraints
*constr
= win
->GetConstraints();
1746 // Reset any constraints involving this window
1749 constr
->left
.ResetIfWin(this);
1750 constr
->top
.ResetIfWin(this);
1751 constr
->right
.ResetIfWin(this);
1752 constr
->bottom
.ResetIfWin(this);
1753 constr
->width
.ResetIfWin(this);
1754 constr
->height
.ResetIfWin(this);
1755 constr
->centreX
.ResetIfWin(this);
1756 constr
->centreY
.ResetIfWin(this);
1759 wxWindowList::compatibility_iterator next
= node
->GetNext();
1760 m_constraintsInvolvedIn
->Erase(node
);
1764 delete m_constraintsInvolvedIn
;
1765 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1769 #endif // wxUSE_CONSTRAINTS
1771 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1773 if ( sizer
== m_windowSizer
)
1776 if ( m_windowSizer
)
1778 m_windowSizer
->SetContainingWindow(NULL
);
1781 delete m_windowSizer
;
1784 m_windowSizer
= sizer
;
1785 if ( m_windowSizer
)
1787 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
1790 SetAutoLayout(m_windowSizer
!= NULL
);
1793 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1795 SetSizer( sizer
, deleteOld
);
1796 sizer
->SetSizeHints( (wxWindow
*) this );
1800 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1802 // adding a window to a sizer twice is going to result in fatal and
1803 // hard to debug problems later because when deleting the second
1804 // associated wxSizerItem we're going to dereference a dangling
1805 // pointer; so try to detect this as early as possible
1806 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1807 _T("Adding a window to the same sizer twice?") );
1809 m_containingSizer
= sizer
;
1812 #if wxUSE_CONSTRAINTS
1814 void wxWindowBase::SatisfyConstraints()
1816 wxLayoutConstraints
*constr
= GetConstraints();
1817 bool wasOk
= constr
&& constr
->AreSatisfied();
1819 ResetConstraints(); // Mark all constraints as unevaluated
1823 // if we're a top level panel (i.e. our parent is frame/dialog), our
1824 // own constraints will never be satisfied any more unless we do it
1828 while ( noChanges
> 0 )
1830 LayoutPhase1(&noChanges
);
1834 LayoutPhase2(&noChanges
);
1837 #endif // wxUSE_CONSTRAINTS
1839 bool wxWindowBase::Layout()
1841 // If there is a sizer, use it instead of the constraints
1845 GetVirtualSize(&w
, &h
);
1846 GetSizer()->SetDimension( 0, 0, w
, h
);
1848 #if wxUSE_CONSTRAINTS
1851 SatisfyConstraints(); // Find the right constraints values
1852 SetConstraintSizes(); // Recursively set the real window sizes
1859 #if wxUSE_CONSTRAINTS
1861 // first phase of the constraints evaluation: set our own constraints
1862 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1864 wxLayoutConstraints
*constr
= GetConstraints();
1866 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1869 // second phase: set the constraints for our children
1870 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1877 // Layout grand children
1883 // Do a phase of evaluating child constraints
1884 bool wxWindowBase::DoPhase(int phase
)
1886 // the list containing the children for which the constraints are already
1888 wxWindowList succeeded
;
1890 // the max number of iterations we loop before concluding that we can't set
1892 static const int maxIterations
= 500;
1894 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1898 // loop over all children setting their constraints
1899 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1901 node
= node
->GetNext() )
1903 wxWindow
*child
= node
->GetData();
1904 if ( child
->IsTopLevel() )
1906 // top level children are not inside our client area
1910 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1912 // this one is either already ok or nothing we can do about it
1916 int tempNoChanges
= 0;
1917 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1918 : child
->LayoutPhase2(&tempNoChanges
);
1919 noChanges
+= tempNoChanges
;
1923 succeeded
.Append(child
);
1929 // constraints are set
1937 void wxWindowBase::ResetConstraints()
1939 wxLayoutConstraints
*constr
= GetConstraints();
1942 constr
->left
.SetDone(false);
1943 constr
->top
.SetDone(false);
1944 constr
->right
.SetDone(false);
1945 constr
->bottom
.SetDone(false);
1946 constr
->width
.SetDone(false);
1947 constr
->height
.SetDone(false);
1948 constr
->centreX
.SetDone(false);
1949 constr
->centreY
.SetDone(false);
1952 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1955 wxWindow
*win
= node
->GetData();
1956 if ( !win
->IsTopLevel() )
1957 win
->ResetConstraints();
1958 node
= node
->GetNext();
1962 // Need to distinguish between setting the 'fake' size for windows and sizers,
1963 // and setting the real values.
1964 void wxWindowBase::SetConstraintSizes(bool recurse
)
1966 wxLayoutConstraints
*constr
= GetConstraints();
1967 if ( constr
&& constr
->AreSatisfied() )
1969 int x
= constr
->left
.GetValue();
1970 int y
= constr
->top
.GetValue();
1971 int w
= constr
->width
.GetValue();
1972 int h
= constr
->height
.GetValue();
1974 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1975 (constr
->height
.GetRelationship() != wxAsIs
) )
1977 SetSize(x
, y
, w
, h
);
1981 // If we don't want to resize this window, just move it...
1987 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1988 GetClassInfo()->GetClassName(),
1994 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1997 wxWindow
*win
= node
->GetData();
1998 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1999 win
->SetConstraintSizes();
2000 node
= node
->GetNext();
2005 // Only set the size/position of the constraint (if any)
2006 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
2008 wxLayoutConstraints
*constr
= GetConstraints();
2011 if ( x
!= wxDefaultCoord
)
2013 constr
->left
.SetValue(x
);
2014 constr
->left
.SetDone(true);
2016 if ( y
!= wxDefaultCoord
)
2018 constr
->top
.SetValue(y
);
2019 constr
->top
.SetDone(true);
2021 if ( w
!= wxDefaultCoord
)
2023 constr
->width
.SetValue(w
);
2024 constr
->width
.SetDone(true);
2026 if ( h
!= wxDefaultCoord
)
2028 constr
->height
.SetValue(h
);
2029 constr
->height
.SetDone(true);
2034 void wxWindowBase::MoveConstraint(int x
, int y
)
2036 wxLayoutConstraints
*constr
= GetConstraints();
2039 if ( x
!= wxDefaultCoord
)
2041 constr
->left
.SetValue(x
);
2042 constr
->left
.SetDone(true);
2044 if ( y
!= wxDefaultCoord
)
2046 constr
->top
.SetValue(y
);
2047 constr
->top
.SetDone(true);
2052 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2054 wxLayoutConstraints
*constr
= GetConstraints();
2057 *w
= constr
->width
.GetValue();
2058 *h
= constr
->height
.GetValue();
2064 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2066 wxLayoutConstraints
*constr
= GetConstraints();
2069 *w
= constr
->width
.GetValue();
2070 *h
= constr
->height
.GetValue();
2073 GetClientSize(w
, h
);
2076 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2078 wxLayoutConstraints
*constr
= GetConstraints();
2081 *x
= constr
->left
.GetValue();
2082 *y
= constr
->top
.GetValue();
2088 #endif // wxUSE_CONSTRAINTS
2090 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2092 // don't do it for the dialogs/frames - they float independently of their
2094 if ( !IsTopLevel() )
2096 wxWindow
*parent
= GetParent();
2097 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2099 wxPoint
pt(parent
->GetClientAreaOrigin());
2106 // ----------------------------------------------------------------------------
2107 // Update UI processing
2108 // ----------------------------------------------------------------------------
2110 void wxWindowBase::UpdateWindowUI(long flags
)
2112 wxUpdateUIEvent
event(GetId());
2113 event
.SetEventObject(this);
2115 if ( GetEventHandler()->ProcessEvent(event
) )
2117 DoUpdateWindowUI(event
);
2120 if (flags
& wxUPDATE_UI_RECURSE
)
2122 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2125 wxWindow
* child
= (wxWindow
*) node
->GetData();
2126 child
->UpdateWindowUI(flags
);
2127 node
= node
->GetNext();
2132 // do the window-specific processing after processing the update event
2133 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2135 if ( event
.GetSetEnabled() )
2136 Enable(event
.GetEnabled());
2138 if ( event
.GetSetShown() )
2139 Show(event
.GetShown());
2142 // ----------------------------------------------------------------------------
2143 // dialog units translations
2144 // ----------------------------------------------------------------------------
2146 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2148 int charWidth
= GetCharWidth();
2149 int charHeight
= GetCharHeight();
2150 wxPoint pt2
= wxDefaultPosition
;
2151 if (pt
.x
!= wxDefaultCoord
)
2152 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2153 if (pt
.y
!= wxDefaultCoord
)
2154 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2159 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2161 int charWidth
= GetCharWidth();
2162 int charHeight
= GetCharHeight();
2163 wxPoint pt2
= wxDefaultPosition
;
2164 if (pt
.x
!= wxDefaultCoord
)
2165 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2166 if (pt
.y
!= wxDefaultCoord
)
2167 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2172 // ----------------------------------------------------------------------------
2174 // ----------------------------------------------------------------------------
2176 // propagate the colour change event to the subwindows
2177 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2179 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2182 // Only propagate to non-top-level windows
2183 wxWindow
*win
= node
->GetData();
2184 if ( !win
->IsTopLevel() )
2186 wxSysColourChangedEvent event2
;
2187 event
.SetEventObject(win
);
2188 win
->GetEventHandler()->ProcessEvent(event2
);
2191 node
= node
->GetNext();
2197 // the default action is to populate dialog with data when it's created,
2198 // and nudge the UI into displaying itself correctly in case
2199 // we've turned the wxUpdateUIEvents frequency down low.
2200 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2202 TransferDataToWindow();
2204 // Update the UI at this point
2205 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2208 // methods for drawing the sizers in a visible way
2211 static void DrawSizers(wxWindowBase
*win
);
2213 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2215 wxClientDC
dc((wxWindow
*)win
);
2216 dc
.SetPen(*wxRED_PEN
);
2217 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2218 dc
.DrawRectangle(rect
.Deflate(1, 1));
2221 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2223 const wxSizerItemList
& items
= sizer
->GetChildren();
2224 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2229 wxSizerItem
*item
= *i
;
2230 if ( item
->IsSizer() )
2232 DrawBorder(win
, item
->GetRect().Deflate(2));
2233 DrawSizer(win
, item
->GetSizer());
2235 else if ( item
->IsSpacer() )
2237 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2239 else if ( item
->IsWindow() )
2241 DrawSizers(item
->GetWindow());
2246 static void DrawSizers(wxWindowBase
*win
)
2248 wxSizer
*sizer
= win
->GetSizer();
2251 DrawBorder(win
, win
->GetClientSize());
2252 DrawSizer(win
, sizer
);
2254 else // no sizer, still recurse into the children
2256 const wxWindowList
& children
= win
->GetChildren();
2257 for ( wxWindowList::const_iterator i
= children
.begin(),
2258 end
= children
.end();
2267 #endif // __WXDEBUG__
2269 // process special middle clicks
2270 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2272 if ( event
.ControlDown() && event
.AltDown() )
2275 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2276 if ( event
.ShiftDown() )
2281 #endif // __WXDEBUG__
2284 // don't translate these strings, they're for diagnostics purposes only
2286 msg
.Printf(_T("wxWidgets Library (%s port)\n")
2287 _T("Version %d.%d.%d%s%s, compiled at %s %s\n")
2288 _T("Runtime version of toolkit used is %d.%d.%s\n")
2289 _T("Copyright (c) 1995-2007 wxWidgets team"),
2290 wxPlatformInfo::Get().GetPortIdName().c_str(),
2306 wxPlatformInfo::Get().GetToolkitMajorVersion(),
2307 wxPlatformInfo::Get().GetToolkitMinorVersion(),
2309 wxString::Format(_T("\nThe compile-time GTK+ version is %d.%d.%d."), GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
).c_str()
2315 wxMessageBox(msg
, _T("wxWidgets information"),
2316 wxICON_INFORMATION
| wxOK
,
2320 #endif // wxUSE_MSGDLG
2326 // ----------------------------------------------------------------------------
2328 // ----------------------------------------------------------------------------
2330 #if wxUSE_ACCESSIBILITY
2331 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2333 if (m_accessible
&& (accessible
!= m_accessible
))
2334 delete m_accessible
;
2335 m_accessible
= accessible
;
2337 m_accessible
->SetWindow((wxWindow
*) this);
2340 // Returns the accessible object, creating if necessary.
2341 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2344 m_accessible
= CreateAccessible();
2345 return m_accessible
;
2348 // Override to create a specific accessible object.
2349 wxAccessible
* wxWindowBase::CreateAccessible()
2351 return new wxWindowAccessible((wxWindow
*) this);
2356 // ----------------------------------------------------------------------------
2357 // list classes implementation
2358 // ----------------------------------------------------------------------------
2362 #include "wx/listimpl.cpp"
2363 WX_DEFINE_LIST(wxWindowList
)
2367 void wxWindowListNode::DeleteData()
2369 delete (wxWindow
*)GetData();
2372 #endif // wxUSE_STL/!wxUSE_STL
2374 // ----------------------------------------------------------------------------
2376 // ----------------------------------------------------------------------------
2378 wxBorder
wxWindowBase::GetBorder(long flags
) const
2380 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2381 if ( border
== wxBORDER_DEFAULT
)
2383 border
= GetDefaultBorder();
2389 wxBorder
wxWindowBase::GetDefaultBorder() const
2391 return wxBORDER_NONE
;
2394 // ----------------------------------------------------------------------------
2396 // ----------------------------------------------------------------------------
2398 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2400 // here we just check if the point is inside the window or not
2402 // check the top and left border first
2403 bool outside
= x
< 0 || y
< 0;
2406 // check the right and bottom borders too
2407 wxSize size
= GetSize();
2408 outside
= x
>= size
.x
|| y
>= size
.y
;
2411 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2414 // ----------------------------------------------------------------------------
2416 // ----------------------------------------------------------------------------
2418 struct WXDLLEXPORT wxWindowNext
2422 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2423 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2424 bool wxWindowBase::ms_winCaptureChanging
= false;
2426 void wxWindowBase::CaptureMouse()
2428 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2430 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2432 ms_winCaptureChanging
= true;
2434 wxWindow
*winOld
= GetCapture();
2437 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2440 wxWindowNext
*item
= new wxWindowNext
;
2442 item
->next
= ms_winCaptureNext
;
2443 ms_winCaptureNext
= item
;
2445 //else: no mouse capture to save
2448 ms_winCaptureCurrent
= (wxWindow
*)this;
2450 ms_winCaptureChanging
= false;
2453 void wxWindowBase::ReleaseMouse()
2455 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2457 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2459 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2461 ms_winCaptureChanging
= true;
2464 ms_winCaptureCurrent
= NULL
;
2466 if ( ms_winCaptureNext
)
2468 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2469 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2471 wxWindowNext
*item
= ms_winCaptureNext
;
2472 ms_winCaptureNext
= item
->next
;
2475 //else: stack is empty, no previous capture
2477 ms_winCaptureChanging
= false;
2479 wxLogTrace(_T("mousecapture"),
2480 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2481 wx_static_cast(void*, GetCapture()));
2484 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2486 wxMouseCaptureLostEvent
event(win
->GetId());
2487 event
.SetEventObject(win
);
2488 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2490 // windows must handle this event, otherwise the app wouldn't behave
2491 // correctly if it loses capture unexpectedly; see the discussion here:
2492 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
2493 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
2494 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2499 void wxWindowBase::NotifyCaptureLost()
2501 // don't do anything if capture lost was expected, i.e. resulted from
2502 // a wx call to ReleaseMouse or CaptureMouse:
2503 if ( ms_winCaptureChanging
)
2506 // if the capture was lost unexpectedly, notify every window that has
2507 // capture (on stack or current) about it and clear the stack:
2509 if ( ms_winCaptureCurrent
)
2511 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2512 ms_winCaptureCurrent
= NULL
;
2515 while ( ms_winCaptureNext
)
2517 wxWindowNext
*item
= ms_winCaptureNext
;
2518 ms_winCaptureNext
= item
->next
;
2520 DoNotifyWindowAboutCaptureLost(item
->win
);
2529 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2530 int WXUNUSED(modifiers
),
2531 int WXUNUSED(keycode
))
2537 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2543 #endif // wxUSE_HOTKEY
2545 // ----------------------------------------------------------------------------
2547 // ----------------------------------------------------------------------------
2549 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2551 #if wxUSE_VALIDATORS
2552 // Can only use the validator of the window which
2553 // is receiving the event
2554 if ( event
.GetEventObject() == this )
2556 wxValidator
*validator
= GetValidator();
2557 if ( validator
&& validator
->ProcessEvent(event
) )
2562 #endif // wxUSE_VALIDATORS
2567 bool wxWindowBase::TryParent(wxEvent
& event
)
2569 // carry on up the parent-child hierarchy if the propagation count hasn't
2571 if ( event
.ShouldPropagate() )
2573 // honour the requests to stop propagation at this window: this is
2574 // used by the dialogs, for example, to prevent processing the events
2575 // from the dialog controls in the parent frame which rarely, if ever,
2577 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2579 wxWindow
*parent
= GetParent();
2580 if ( parent
&& !parent
->IsBeingDeleted() )
2582 wxPropagateOnce
propagateOnce(event
);
2584 return parent
->GetEventHandler()->ProcessEvent(event
);
2589 return wxEvtHandler::TryParent(event
);
2592 // ----------------------------------------------------------------------------
2593 // keyboard navigation
2594 // ----------------------------------------------------------------------------
2596 // Navigates in the specified direction.
2597 bool wxWindowBase::Navigate(int flags
)
2599 wxNavigationKeyEvent eventNav
;
2600 eventNav
.SetFlags(flags
);
2601 eventNav
.SetEventObject(this);
2602 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2609 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2611 // check that we're not a top level window
2612 wxCHECK_RET( GetParent(),
2613 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2615 // detect the special case when we have nothing to do anyhow and when the
2616 // code below wouldn't work
2620 // find the target window in the siblings list
2621 wxWindowList
& siblings
= GetParent()->GetChildren();
2622 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2623 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2625 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2626 // can't just move the node around
2627 wxWindow
*self
= (wxWindow
*)this;
2628 siblings
.DeleteObject(self
);
2629 if ( move
== MoveAfter
)
2636 siblings
.Insert(i
, self
);
2638 else // MoveAfter and win was the last sibling
2640 siblings
.Append(self
);
2644 // ----------------------------------------------------------------------------
2646 // ----------------------------------------------------------------------------
2648 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2650 wxWindowBase
*win
= DoFindFocus();
2651 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2654 // ----------------------------------------------------------------------------
2656 // ----------------------------------------------------------------------------
2658 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2660 while ( win
&& !win
->IsTopLevel() )
2661 win
= win
->GetParent();
2666 #if wxUSE_ACCESSIBILITY
2667 // ----------------------------------------------------------------------------
2668 // accessible object for windows
2669 // ----------------------------------------------------------------------------
2671 // Can return either a child object, or an integer
2672 // representing the child element, starting from 1.
2673 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2675 wxASSERT( GetWindow() != NULL
);
2679 return wxACC_NOT_IMPLEMENTED
;
2682 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2683 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2685 wxASSERT( GetWindow() != NULL
);
2689 wxWindow
* win
= NULL
;
2696 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2698 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2705 rect
= win
->GetRect();
2706 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2707 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2711 return wxACC_NOT_IMPLEMENTED
;
2714 // Navigates from fromId to toId/toObject.
2715 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2716 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2718 wxASSERT( GetWindow() != NULL
);
2724 case wxNAVDIR_FIRSTCHILD
:
2726 if (GetWindow()->GetChildren().GetCount() == 0)
2728 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2729 *toObject
= childWindow
->GetOrCreateAccessible();
2733 case wxNAVDIR_LASTCHILD
:
2735 if (GetWindow()->GetChildren().GetCount() == 0)
2737 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2738 *toObject
= childWindow
->GetOrCreateAccessible();
2742 case wxNAVDIR_RIGHT
:
2746 wxWindowList::compatibility_iterator node
=
2747 wxWindowList::compatibility_iterator();
2750 // Can't navigate to sibling of this window
2751 // if we're a top-level window.
2752 if (!GetWindow()->GetParent())
2753 return wxACC_NOT_IMPLEMENTED
;
2755 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2759 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2760 node
= GetWindow()->GetChildren().Item(fromId
-1);
2763 if (node
&& node
->GetNext())
2765 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2766 *toObject
= nextWindow
->GetOrCreateAccessible();
2774 case wxNAVDIR_PREVIOUS
:
2776 wxWindowList::compatibility_iterator node
=
2777 wxWindowList::compatibility_iterator();
2780 // Can't navigate to sibling of this window
2781 // if we're a top-level window.
2782 if (!GetWindow()->GetParent())
2783 return wxACC_NOT_IMPLEMENTED
;
2785 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2789 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2790 node
= GetWindow()->GetChildren().Item(fromId
-1);
2793 if (node
&& node
->GetPrevious())
2795 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2796 *toObject
= previousWindow
->GetOrCreateAccessible();
2804 return wxACC_NOT_IMPLEMENTED
;
2807 // Gets the name of the specified object.
2808 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2810 wxASSERT( GetWindow() != NULL
);
2816 // If a child, leave wxWidgets to call the function on the actual
2819 return wxACC_NOT_IMPLEMENTED
;
2821 // This will eventually be replaced by specialised
2822 // accessible classes, one for each kind of wxWidgets
2823 // control or window.
2825 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2826 title
= ((wxButton
*) GetWindow())->GetLabel();
2829 title
= GetWindow()->GetName();
2837 return wxACC_NOT_IMPLEMENTED
;
2840 // Gets the number of children.
2841 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2843 wxASSERT( GetWindow() != NULL
);
2847 *childId
= (int) GetWindow()->GetChildren().GetCount();
2851 // Gets the specified child (starting from 1).
2852 // If *child is NULL and return value is wxACC_OK,
2853 // this means that the child is a simple element and
2854 // not an accessible object.
2855 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2857 wxASSERT( GetWindow() != NULL
);
2867 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2870 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2871 *child
= childWindow
->GetOrCreateAccessible();
2878 // Gets the parent, or NULL.
2879 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2881 wxASSERT( GetWindow() != NULL
);
2885 wxWindow
* parentWindow
= GetWindow()->GetParent();
2893 *parent
= parentWindow
->GetOrCreateAccessible();
2901 // Performs the default action. childId is 0 (the action for this object)
2902 // or > 0 (the action for a child).
2903 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2904 // window (e.g. an edit control).
2905 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2907 wxASSERT( GetWindow() != NULL
);
2911 return wxACC_NOT_IMPLEMENTED
;
2914 // Gets the default action for this object (0) or > 0 (the action for a child).
2915 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2916 // string if there is no action.
2917 // The retrieved string describes the action that is performed on an object,
2918 // not what the object does as a result. For example, a toolbar button that prints
2919 // a document has a default action of "Press" rather than "Prints the current document."
2920 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2922 wxASSERT( GetWindow() != NULL
);
2926 return wxACC_NOT_IMPLEMENTED
;
2929 // Returns the description for this object or a child.
2930 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2932 wxASSERT( GetWindow() != NULL
);
2936 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2942 return wxACC_NOT_IMPLEMENTED
;
2945 // Returns help text for this object or a child, similar to tooltip text.
2946 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2948 wxASSERT( GetWindow() != NULL
);
2952 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
2958 return wxACC_NOT_IMPLEMENTED
;
2961 // Returns the keyboard shortcut for this object or child.
2962 // Return e.g. ALT+K
2963 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2965 wxASSERT( GetWindow() != NULL
);
2969 return wxACC_NOT_IMPLEMENTED
;
2972 // Returns a role constant.
2973 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2975 wxASSERT( GetWindow() != NULL
);
2979 // If a child, leave wxWidgets to call the function on the actual
2982 return wxACC_NOT_IMPLEMENTED
;
2984 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2985 return wxACC_NOT_IMPLEMENTED
;
2987 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2988 return wxACC_NOT_IMPLEMENTED
;
2991 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2992 return wxACC_NOT_IMPLEMENTED
;
2995 //*role = wxROLE_SYSTEM_CLIENT;
2996 *role
= wxROLE_SYSTEM_CLIENT
;
3000 return wxACC_NOT_IMPLEMENTED
;
3004 // Returns a state constant.
3005 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
3007 wxASSERT( GetWindow() != NULL
);
3011 // If a child, leave wxWidgets to call the function on the actual
3014 return wxACC_NOT_IMPLEMENTED
;
3016 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3017 return wxACC_NOT_IMPLEMENTED
;
3020 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3021 return wxACC_NOT_IMPLEMENTED
;
3024 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3025 return wxACC_NOT_IMPLEMENTED
;
3032 return wxACC_NOT_IMPLEMENTED
;
3036 // Returns a localized string representing the value for the object
3038 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3040 wxASSERT( GetWindow() != NULL
);
3044 return wxACC_NOT_IMPLEMENTED
;
3047 // Selects the object or child.
3048 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3050 wxASSERT( GetWindow() != NULL
);
3054 return wxACC_NOT_IMPLEMENTED
;
3057 // Gets the window with the keyboard focus.
3058 // If childId is 0 and child is NULL, no object in
3059 // this subhierarchy has the focus.
3060 // If this object has the focus, child should be 'this'.
3061 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3063 wxASSERT( GetWindow() != NULL
);
3067 return wxACC_NOT_IMPLEMENTED
;
3071 // Gets a variant representing the selected children
3073 // Acceptable values:
3074 // - a null variant (IsNull() returns true)
3075 // - a list variant (GetType() == wxT("list")
3076 // - an integer representing the selected child element,
3077 // or 0 if this object is selected (GetType() == wxT("long")
3078 // - a "void*" pointer to a wxAccessible child object
3079 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3081 wxASSERT( GetWindow() != NULL
);
3085 return wxACC_NOT_IMPLEMENTED
;
3087 #endif // wxUSE_VARIANT
3089 #endif // wxUSE_ACCESSIBILITY
3091 // ----------------------------------------------------------------------------
3093 // ----------------------------------------------------------------------------
3096 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3098 wxCoord widthTotal
) const
3100 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3102 x
= widthTotal
- x
- width
;