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>
83 #include "wx/platinfo.h"
86 WXDLLIMPEXP_DATA_CORE(wxWindowList
) wxTopLevelWindows
;
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 #if defined(__WXPALMOS__)
93 int wxWindowBase::ms_lastControlId
= 32767;
94 #elif defined(__WXPM__)
95 int wxWindowBase::ms_lastControlId
= 2000;
97 int wxWindowBase::ms_lastControlId
= -200;
100 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
102 // ----------------------------------------------------------------------------
104 // ----------------------------------------------------------------------------
106 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
107 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
108 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
109 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
112 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
117 // ============================================================================
118 // implementation of the common functionality of the wxWindow class
119 // ============================================================================
121 // ----------------------------------------------------------------------------
123 // ----------------------------------------------------------------------------
125 // the default initialization
126 wxWindowBase::wxWindowBase()
128 // no window yet, no parent nor children
129 m_parent
= (wxWindow
*)NULL
;
130 m_windowId
= wxID_ANY
;
132 // no constraints on the minimal window size
134 m_maxWidth
= wxDefaultCoord
;
136 m_maxHeight
= wxDefaultCoord
;
138 // invalidiated cache value
139 m_bestSizeCache
= wxDefaultSize
;
141 // window are created enabled and visible by default
145 // the default event handler is just this window
146 m_eventHandler
= this;
150 m_windowValidator
= (wxValidator
*) NULL
;
151 #endif // wxUSE_VALIDATORS
153 // the colours/fonts are default for now, so leave m_font,
154 // m_backgroundColour and m_foregroundColour uninitialized and set those
160 m_inheritFont
= false;
166 m_backgroundStyle
= wxBG_STYLE_SYSTEM
;
168 #if wxUSE_CONSTRAINTS
169 // no constraints whatsoever
170 m_constraints
= (wxLayoutConstraints
*) NULL
;
171 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
172 #endif // wxUSE_CONSTRAINTS
174 m_windowSizer
= (wxSizer
*) NULL
;
175 m_containingSizer
= (wxSizer
*) NULL
;
176 m_autoLayout
= false;
178 #if wxUSE_DRAG_AND_DROP
179 m_dropTarget
= (wxDropTarget
*)NULL
;
180 #endif // wxUSE_DRAG_AND_DROP
183 m_tooltip
= (wxToolTip
*)NULL
;
184 #endif // wxUSE_TOOLTIPS
187 m_caret
= (wxCaret
*)NULL
;
188 #endif // wxUSE_CARET
191 m_hasCustomPalette
= false;
192 #endif // wxUSE_PALETTE
194 #if wxUSE_ACCESSIBILITY
198 m_virtualSize
= wxDefaultSize
;
200 m_scrollHelper
= (wxScrollHelper
*) NULL
;
203 m_maxVirtualWidth
= wxDefaultCoord
;
205 m_maxVirtualHeight
= wxDefaultCoord
;
207 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
208 #if wxUSE_SYSTEM_OPTIONS
209 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
211 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
215 // Whether we're using the current theme for this window (wxGTK only for now)
216 m_themeEnabled
= false;
218 // VZ: this one shouldn't exist...
219 m_isBeingDeleted
= false;
222 // common part of window creation process
223 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
225 const wxPoint
& WXUNUSED(pos
),
226 const wxSize
& WXUNUSED(size
),
228 const wxValidator
& wxVALIDATOR_PARAM(validator
),
229 const wxString
& name
)
232 // wxGTK doesn't allow to create controls with static box as the parent so
233 // this will result in a crash when the program is ported to wxGTK so warn
236 // if you get this assert, the correct solution is to create the controls
237 // as siblings of the static box
238 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
239 _T("wxStaticBox can't be used as a window parent!") );
240 #endif // wxUSE_STATBOX
242 // ids are limited to 16 bits under MSW so if you care about portability,
243 // it's not a good idea to use ids out of this range (and negative ids are
244 // reserved for wxWidgets own usage)
245 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
246 _T("invalid id value") );
248 // generate a new id if the user doesn't care about it
249 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
251 // don't use SetWindowStyleFlag() here, this function should only be called
252 // to change the flag after creation as it tries to reflect the changes in
253 // flags by updating the window dynamically and we don't need this here
254 m_windowStyle
= style
;
260 SetValidator(validator
);
261 #endif // wxUSE_VALIDATORS
263 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
264 // have it too - like this it's possible to set it only in the top level
265 // dialog/frame and all children will inherit it by defult
266 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
268 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
274 bool wxWindowBase::ToggleWindowStyle(int flag
)
276 wxASSERT_MSG( flag
, _T("flags with 0 value can't be toggled") );
279 long style
= GetWindowStyleFlag();
285 else // currently off
291 SetWindowStyleFlag(style
);
296 // ----------------------------------------------------------------------------
298 // ----------------------------------------------------------------------------
301 wxWindowBase::~wxWindowBase()
303 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
305 // FIXME if these 2 cases result from programming errors in the user code
306 // we should probably assert here instead of silently fixing them
308 // Just in case the window has been Closed, but we're then deleting
309 // immediately: don't leave dangling pointers.
310 wxPendingDelete
.DeleteObject(this);
312 // Just in case we've loaded a top-level window via LoadNativeDialog but
313 // we weren't a dialog class
314 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
316 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
318 // notify the parent about this window destruction
320 m_parent
->RemoveChild(this);
324 #endif // wxUSE_CARET
327 delete m_windowValidator
;
328 #endif // wxUSE_VALIDATORS
330 #if wxUSE_CONSTRAINTS
331 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
332 // at deleted windows as they delete themselves.
333 DeleteRelatedConstraints();
337 // This removes any dangling pointers to this window in other windows'
338 // constraintsInvolvedIn lists.
339 UnsetConstraints(m_constraints
);
340 delete m_constraints
;
341 m_constraints
= NULL
;
343 #endif // wxUSE_CONSTRAINTS
345 if ( m_containingSizer
)
346 m_containingSizer
->Detach( (wxWindow
*)this );
348 delete m_windowSizer
;
350 #if wxUSE_DRAG_AND_DROP
352 #endif // wxUSE_DRAG_AND_DROP
356 #endif // wxUSE_TOOLTIPS
358 #if wxUSE_ACCESSIBILITY
363 void wxWindowBase::SendDestroyEvent()
365 wxWindowDestroyEvent event
;
366 event
.SetEventObject(this);
367 event
.SetId(GetId());
368 GetEventHandler()->ProcessEvent(event
);
371 bool wxWindowBase::Destroy()
378 bool wxWindowBase::Close(bool force
)
380 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
381 event
.SetEventObject(this);
382 event
.SetCanVeto(!force
);
384 // return false if window wasn't closed because the application vetoed the
386 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
389 bool wxWindowBase::DestroyChildren()
391 wxWindowList::compatibility_iterator node
;
394 // we iterate until the list becomes empty
395 node
= GetChildren().GetFirst();
399 wxWindow
*child
= node
->GetData();
401 // note that we really want to call delete and not ->Destroy() here
402 // because we want to delete the child immediately, before we are
403 // deleted, and delayed deletion would result in problems as our (top
404 // level) child could outlive its parent
407 wxASSERT_MSG( !GetChildren().Find(child
),
408 wxT("child didn't remove itself using RemoveChild()") );
414 // ----------------------------------------------------------------------------
415 // size/position related methods
416 // ----------------------------------------------------------------------------
418 // centre the window with respect to its parent in either (or both) directions
419 void wxWindowBase::DoCentre(int dir
)
421 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
422 _T("this method only implements centering child windows") );
424 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
427 // fits the window around the children
428 void wxWindowBase::Fit()
430 if ( !GetChildren().empty() )
432 SetSize(GetBestSize());
434 //else: do nothing if we have no children
437 // fits virtual size (ie. scrolled area etc.) around children
438 void wxWindowBase::FitInside()
440 if ( GetChildren().GetCount() > 0 )
442 SetVirtualSize( GetBestVirtualSize() );
446 // On Mac, scrollbars are explicitly children.
448 static bool wxHasRealChildren(const wxWindowBase
* win
)
450 int realChildCount
= 0;
452 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
454 node
= node
->GetNext() )
456 wxWindow
*win
= node
->GetData();
457 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
460 return (realChildCount
> 0);
464 void wxWindowBase::InvalidateBestSize()
466 m_bestSizeCache
= wxDefaultSize
;
468 // parent's best size calculation may depend on its children's
469 // as long as child window we are in is not top level window itself
470 // (because the TLW size is never resized automatically)
471 // so let's invalidate it as well to be safe:
472 if (m_parent
&& !IsTopLevel())
473 m_parent
->InvalidateBestSize();
476 // return the size best suited for the current window
477 wxSize
wxWindowBase::DoGetBestSize() const
483 best
= m_windowSizer
->GetMinSize();
485 #if wxUSE_CONSTRAINTS
486 else if ( m_constraints
)
488 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
490 // our minimal acceptable size is such that all our windows fit inside
494 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
496 node
= node
->GetNext() )
498 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
501 // it's not normal that we have an unconstrained child, but
502 // what can we do about it?
506 int x
= c
->right
.GetValue(),
507 y
= c
->bottom
.GetValue();
515 // TODO: we must calculate the overlaps somehow, otherwise we
516 // will never return a size bigger than the current one :-(
519 best
= wxSize(maxX
, maxY
);
521 #endif // wxUSE_CONSTRAINTS
522 else if ( !GetChildren().empty()
524 && wxHasRealChildren(this)
528 // our minimal acceptable size is such that all our visible child
529 // windows fit inside
533 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
535 node
= node
->GetNext() )
537 wxWindow
*win
= node
->GetData();
538 if ( win
->IsTopLevel()
541 || wxDynamicCast(win
, wxStatusBar
)
542 #endif // wxUSE_STATUSBAR
545 // dialogs and frames lie in different top level windows -
546 // don't deal with them here; as for the status bars, they
547 // don't lie in the client area at all
552 win
->GetPosition(&wx
, &wy
);
554 // if the window hadn't been positioned yet, assume that it is in
556 if ( wx
== wxDefaultCoord
)
558 if ( wy
== wxDefaultCoord
)
561 win
->GetSize(&ww
, &wh
);
562 if ( wx
+ ww
> maxX
)
564 if ( wy
+ wh
> maxY
)
568 best
= wxSize(maxX
, maxY
);
570 else // ! has children
572 // for a generic window there is no natural best size so, if the
573 // minimal size is not set, use the current size but take care to
574 // remember it as minimal size for the next time because our best size
575 // should be constant: otherwise we could get into a situation when the
576 // window is initially at some size, then expanded to a larger size and
577 // then, when the containing window is shrunk back (because our initial
578 // best size had been used for computing the parent min size), we can't
579 // be shrunk back any more because our best size is now bigger
580 wxSize size
= GetMinSize();
581 if ( !size
.IsFullySpecified() )
583 size
.SetDefaults(GetSize());
584 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
587 // return as-is, unadjusted by the client size difference.
591 // Add any difference between size and client size
592 wxSize diff
= GetSize() - GetClientSize();
593 best
.x
+= wxMax(0, diff
.x
);
594 best
.y
+= wxMax(0, diff
.y
);
599 // helper of GetWindowBorderSize(): as many ports don't implement support for
600 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
601 // fallbacks in this case
602 static int wxGetMetricOrDefault(wxSystemMetric what
)
604 int rc
= wxSystemSettings::GetMetric(what
);
611 // 2D border is by default 1 pixel wide
617 // 3D borders are by default 2 pixels
622 wxFAIL_MSG( _T("unexpected wxGetMetricOrDefault() argument") );
630 wxSize
wxWindowBase::GetWindowBorderSize() const
634 switch ( GetBorder() )
637 // nothing to do, size is already (0, 0)
640 case wxBORDER_SIMPLE
:
641 case wxBORDER_STATIC
:
642 size
.x
= wxGetMetricOrDefault(wxSYS_BORDER_X
);
643 size
.y
= wxGetMetricOrDefault(wxSYS_BORDER_Y
);
646 case wxBORDER_SUNKEN
:
647 case wxBORDER_RAISED
:
648 size
.x
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X
),
649 wxGetMetricOrDefault(wxSYS_BORDER_X
));
650 size
.y
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y
),
651 wxGetMetricOrDefault(wxSYS_BORDER_Y
));
654 case wxBORDER_DOUBLE
:
655 size
.x
= wxGetMetricOrDefault(wxSYS_EDGE_X
) +
656 wxGetMetricOrDefault(wxSYS_BORDER_X
);
657 size
.y
= wxGetMetricOrDefault(wxSYS_EDGE_Y
) +
658 wxGetMetricOrDefault(wxSYS_BORDER_Y
);
662 wxFAIL_MSG(_T("Unknown border style."));
666 // we have borders on both sides
670 wxSize
wxWindowBase::GetEffectiveMinSize() const
672 // merge the best size with the min size, giving priority to the min size
673 wxSize min
= GetMinSize();
674 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
676 wxSize best
= GetBestSize();
677 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
678 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
684 void wxWindowBase::SetInitialSize(const wxSize
& size
)
686 // Set the min size to the size passed in. This will usually either be
687 // wxDefaultSize or the size passed to this window's ctor/Create function.
690 // Merge the size with the best size if needed
691 wxSize best
= GetEffectiveMinSize();
693 // If the current size doesn't match then change it
694 if (GetSize() != best
)
699 // by default the origin is not shifted
700 wxPoint
wxWindowBase::GetClientAreaOrigin() const
705 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
707 if ( m_windowVariant
!= variant
)
709 m_windowVariant
= variant
;
711 DoSetWindowVariant(variant
);
715 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
717 // adjust the font height to correspond to our new variant (notice that
718 // we're only called if something really changed)
719 wxFont font
= GetFont();
720 int size
= font
.GetPointSize();
723 case wxWINDOW_VARIANT_NORMAL
:
726 case wxWINDOW_VARIANT_SMALL
:
731 case wxWINDOW_VARIANT_MINI
:
736 case wxWINDOW_VARIANT_LARGE
:
742 wxFAIL_MSG(_T("unexpected window variant"));
746 font
.SetPointSize(size
);
750 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
752 int WXUNUSED(incW
), int WXUNUSED(incH
) )
754 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
755 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
756 _T("min width/height must be less than max width/height!") );
765 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
768 m_minVirtualWidth
= minW
;
769 m_maxVirtualWidth
= maxW
;
770 m_minVirtualHeight
= minH
;
771 m_maxVirtualHeight
= maxH
;
774 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
776 if ( m_minVirtualWidth
!= wxDefaultCoord
&& m_minVirtualWidth
> x
)
777 x
= m_minVirtualWidth
;
778 if ( m_maxVirtualWidth
!= wxDefaultCoord
&& m_maxVirtualWidth
< x
)
779 x
= m_maxVirtualWidth
;
780 if ( m_minVirtualHeight
!= wxDefaultCoord
&& m_minVirtualHeight
> y
)
781 y
= m_minVirtualHeight
;
782 if ( m_maxVirtualHeight
!= wxDefaultCoord
&& m_maxVirtualHeight
< y
)
783 y
= m_maxVirtualHeight
;
785 m_virtualSize
= wxSize(x
, y
);
788 wxSize
wxWindowBase::DoGetVirtualSize() const
790 // we should use the entire client area so if it is greater than our
791 // virtual size, expand it to fit (otherwise if the window is big enough we
792 // wouldn't be using parts of it)
793 wxSize size
= GetClientSize();
794 if ( m_virtualSize
.x
> size
.x
)
795 size
.x
= m_virtualSize
.x
;
797 if ( m_virtualSize
.y
>= size
.y
)
798 size
.y
= m_virtualSize
.y
;
803 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
805 // screen position is the same as (0, 0) in client coords for non TLWs (and
806 // TLWs override this method)
812 ClientToScreen(x
, y
);
815 // ----------------------------------------------------------------------------
816 // show/hide/enable/disable the window
817 // ----------------------------------------------------------------------------
819 bool wxWindowBase::Show(bool show
)
821 if ( show
!= m_isShown
)
833 bool wxWindowBase::IsEnabled() const
835 return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
838 void wxWindowBase::NotifyWindowOnEnableChange(bool enabled
)
840 #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
842 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
846 // If we are top-level then the logic doesn't apply - otherwise
847 // showing a modal dialog would result in total greying out (and ungreying
848 // out later) of everything which would be really ugly
852 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
854 node
= node
->GetNext() )
856 wxWindowBase
* const child
= node
->GetData();
857 if ( !child
->IsTopLevel() && child
->IsThisEnabled() )
858 child
->NotifyWindowOnEnableChange(enabled
);
862 bool wxWindowBase::Enable(bool enable
)
864 if ( enable
== IsThisEnabled() )
867 m_isEnabled
= enable
;
869 #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
871 #else // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
872 wxWindowBase
* const parent
= GetParent();
873 if( !IsTopLevel() && parent
&& !parent
->IsEnabled() )
877 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
879 NotifyWindowOnEnableChange(enable
);
884 bool wxWindowBase::IsShownOnScreen() const
887 (GetParent() == NULL
|| GetParent()->IsShownOnScreen());
890 // ----------------------------------------------------------------------------
892 // ----------------------------------------------------------------------------
894 bool wxWindowBase::IsTopLevel() const
899 // ----------------------------------------------------------------------------
900 // reparenting the window
901 // ----------------------------------------------------------------------------
903 void wxWindowBase::AddChild(wxWindowBase
*child
)
905 wxCHECK_RET( child
, wxT("can't add a NULL child") );
907 // this should never happen and it will lead to a crash later if it does
908 // because RemoveChild() will remove only one node from the children list
909 // and the other(s) one(s) will be left with dangling pointers in them
910 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
912 GetChildren().Append((wxWindow
*)child
);
913 child
->SetParent(this);
916 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
918 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
920 GetChildren().DeleteObject((wxWindow
*)child
);
921 child
->SetParent(NULL
);
924 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
926 wxWindow
*oldParent
= GetParent();
927 if ( newParent
== oldParent
)
933 const bool oldEnabledState
= IsEnabled();
935 // unlink this window from the existing parent.
938 oldParent
->RemoveChild(this);
942 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
945 // add it to the new one
948 newParent
->AddChild(this);
952 wxTopLevelWindows
.Append((wxWindow
*)this);
955 // We need to notify window (and its subwindows) if by changing the parent
956 // we also change our enabled/disabled status.
957 const bool newEnabledState
= IsEnabled();
958 if ( newEnabledState
!= oldEnabledState
)
960 NotifyWindowOnEnableChange(newEnabledState
);
966 // ----------------------------------------------------------------------------
967 // event handler stuff
968 // ----------------------------------------------------------------------------
970 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
972 wxEvtHandler
*handlerOld
= GetEventHandler();
974 handler
->SetNextHandler(handlerOld
);
977 GetEventHandler()->SetPreviousHandler(handler
);
979 SetEventHandler(handler
);
982 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
984 wxEvtHandler
*handlerA
= GetEventHandler();
987 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
988 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
991 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
992 SetEventHandler(handlerB
);
997 handlerA
= (wxEvtHandler
*)NULL
;
1004 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
1006 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
1008 wxEvtHandler
*handlerPrev
= NULL
,
1009 *handlerCur
= GetEventHandler();
1010 while ( handlerCur
)
1012 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
1014 if ( handlerCur
== handler
)
1018 handlerPrev
->SetNextHandler(handlerNext
);
1022 SetEventHandler(handlerNext
);
1027 handlerNext
->SetPreviousHandler ( handlerPrev
);
1030 handler
->SetNextHandler(NULL
);
1031 handler
->SetPreviousHandler(NULL
);
1036 handlerPrev
= handlerCur
;
1037 handlerCur
= handlerNext
;
1040 wxFAIL_MSG( _T("where has the event handler gone?") );
1045 // ----------------------------------------------------------------------------
1046 // colours, fonts &c
1047 // ----------------------------------------------------------------------------
1049 void wxWindowBase::InheritAttributes()
1051 const wxWindowBase
* const parent
= GetParent();
1055 // we only inherit attributes which had been explicitly set for the parent
1056 // which ensures that this only happens if the user really wants it and
1057 // not by default which wouldn't make any sense in modern GUIs where the
1058 // controls don't all use the same fonts (nor colours)
1059 if ( parent
->m_inheritFont
&& !m_hasFont
)
1060 SetFont(parent
->GetFont());
1062 // in addition, there is a possibility to explicitly forbid inheriting
1063 // colours at each class level by overriding ShouldInheritColours()
1064 if ( ShouldInheritColours() )
1066 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1067 SetForegroundColour(parent
->GetForegroundColour());
1069 // inheriting (solid) background colour is wrong as it totally breaks
1070 // any kind of themed backgrounds
1072 // instead, the controls should use the same background as their parent
1073 // (ideally by not drawing it at all)
1075 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1076 SetBackgroundColour(parent
->GetBackgroundColour());
1081 /* static */ wxVisualAttributes
1082 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1084 // it is important to return valid values for all attributes from here,
1085 // GetXXX() below rely on this
1086 wxVisualAttributes attrs
;
1087 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1088 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1090 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1091 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1092 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1093 // colour on other platforms.
1095 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1096 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1098 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1103 wxColour
wxWindowBase::GetBackgroundColour() const
1105 if ( !m_backgroundColour
.Ok() )
1107 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
1109 // get our default background colour
1110 wxColour colBg
= GetDefaultAttributes().colBg
;
1112 // we must return some valid colour to avoid redoing this every time
1113 // and also to avoid surprizing the applications written for older
1114 // wxWidgets versions where GetBackgroundColour() always returned
1115 // something -- so give them something even if it doesn't make sense
1116 // for this window (e.g. it has a themed background)
1118 colBg
= GetClassDefaultAttributes().colBg
;
1123 return m_backgroundColour
;
1126 wxColour
wxWindowBase::GetForegroundColour() const
1128 // logic is the same as above
1129 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1131 wxColour colFg
= GetDefaultAttributes().colFg
;
1134 colFg
= GetClassDefaultAttributes().colFg
;
1139 return m_foregroundColour
;
1142 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1144 if ( colour
== m_backgroundColour
)
1147 m_hasBgCol
= colour
.Ok();
1148 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1149 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1151 m_inheritBgCol
= m_hasBgCol
;
1152 m_backgroundColour
= colour
;
1153 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1157 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1159 if (colour
== m_foregroundColour
)
1162 m_hasFgCol
= colour
.Ok();
1163 m_inheritFgCol
= m_hasFgCol
;
1164 m_foregroundColour
= colour
;
1165 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1169 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1171 // setting an invalid cursor is ok, it means that we don't have any special
1173 if ( m_cursor
.IsSameAs(cursor
) )
1184 wxFont
wxWindowBase::GetFont() const
1186 // logic is the same as in GetBackgroundColour()
1189 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1191 wxFont font
= GetDefaultAttributes().font
;
1193 font
= GetClassDefaultAttributes().font
;
1201 bool wxWindowBase::SetFont(const wxFont
& font
)
1203 if ( font
== m_font
)
1210 m_hasFont
= font
.Ok();
1211 m_inheritFont
= m_hasFont
;
1213 InvalidateBestSize();
1220 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1222 m_hasCustomPalette
= true;
1225 // VZ: can anyone explain me what do we do here?
1226 wxWindowDC
d((wxWindow
*) this);
1230 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1232 wxWindow
*win
= (wxWindow
*)this;
1233 while ( win
&& !win
->HasCustomPalette() )
1235 win
= win
->GetParent();
1241 #endif // wxUSE_PALETTE
1244 void wxWindowBase::SetCaret(wxCaret
*caret
)
1255 wxASSERT_MSG( m_caret
->GetWindow() == this,
1256 wxT("caret should be created associated to this window") );
1259 #endif // wxUSE_CARET
1261 #if wxUSE_VALIDATORS
1262 // ----------------------------------------------------------------------------
1264 // ----------------------------------------------------------------------------
1266 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1268 if ( m_windowValidator
)
1269 delete m_windowValidator
;
1271 m_windowValidator
= (wxValidator
*)validator
.Clone();
1273 if ( m_windowValidator
)
1274 m_windowValidator
->SetWindow(this);
1276 #endif // wxUSE_VALIDATORS
1278 // ----------------------------------------------------------------------------
1279 // update region stuff
1280 // ----------------------------------------------------------------------------
1282 wxRect
wxWindowBase::GetUpdateClientRect() const
1284 wxRegion rgnUpdate
= GetUpdateRegion();
1285 rgnUpdate
.Intersect(GetClientRect());
1286 wxRect rectUpdate
= rgnUpdate
.GetBox();
1287 wxPoint ptOrigin
= GetClientAreaOrigin();
1288 rectUpdate
.x
-= ptOrigin
.x
;
1289 rectUpdate
.y
-= ptOrigin
.y
;
1294 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1296 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1299 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1301 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1304 void wxWindowBase::ClearBackground()
1306 // wxGTK uses its own version, no need to add never used code
1308 wxClientDC
dc((wxWindow
*)this);
1309 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1310 dc
.SetBackground(brush
);
1315 // ----------------------------------------------------------------------------
1316 // find child window by id or name
1317 // ----------------------------------------------------------------------------
1319 wxWindow
*wxWindowBase::FindWindow(long id
) const
1321 if ( id
== m_windowId
)
1322 return (wxWindow
*)this;
1324 wxWindowBase
*res
= (wxWindow
*)NULL
;
1325 wxWindowList::compatibility_iterator node
;
1326 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1328 wxWindowBase
*child
= node
->GetData();
1329 res
= child
->FindWindow( id
);
1332 return (wxWindow
*)res
;
1335 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1337 if ( name
== m_windowName
)
1338 return (wxWindow
*)this;
1340 wxWindowBase
*res
= (wxWindow
*)NULL
;
1341 wxWindowList::compatibility_iterator node
;
1342 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1344 wxWindow
*child
= node
->GetData();
1345 res
= child
->FindWindow(name
);
1348 return (wxWindow
*)res
;
1352 // find any window by id or name or label: If parent is non-NULL, look through
1353 // children for a label or title matching the specified string. If NULL, look
1354 // through all top-level windows.
1356 // to avoid duplicating code we reuse the same helper function but with
1357 // different comparators
1359 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1360 const wxString
& label
, long id
);
1363 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1366 return win
->GetLabel() == label
;
1370 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1373 return win
->GetName() == label
;
1377 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1380 return win
->GetId() == id
;
1383 // recursive helper for the FindWindowByXXX() functions
1385 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1386 const wxString
& label
,
1388 wxFindWindowCmp cmp
)
1392 // see if this is the one we're looking for
1393 if ( (*cmp
)(parent
, label
, id
) )
1394 return (wxWindow
*)parent
;
1396 // It wasn't, so check all its children
1397 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1399 node
= node
->GetNext() )
1401 // recursively check each child
1402 wxWindow
*win
= (wxWindow
*)node
->GetData();
1403 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1413 // helper for FindWindowByXXX()
1415 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1416 const wxString
& label
,
1418 wxFindWindowCmp cmp
)
1422 // just check parent and all its children
1423 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1426 // start at very top of wx's windows
1427 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1429 node
= node
->GetNext() )
1431 // recursively check each window & its children
1432 wxWindow
*win
= node
->GetData();
1433 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1443 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1445 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1450 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1452 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1456 // fall back to the label
1457 win
= FindWindowByLabel(title
, parent
);
1465 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1467 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1470 // ----------------------------------------------------------------------------
1471 // dialog oriented functions
1472 // ----------------------------------------------------------------------------
1474 void wxWindowBase::MakeModal(bool modal
)
1476 // Disable all other windows
1479 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1482 wxWindow
*win
= node
->GetData();
1484 win
->Enable(!modal
);
1486 node
= node
->GetNext();
1491 bool wxWindowBase::Validate()
1493 #if wxUSE_VALIDATORS
1494 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1496 wxWindowList::compatibility_iterator node
;
1497 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1499 wxWindowBase
*child
= node
->GetData();
1500 wxValidator
*validator
= child
->GetValidator();
1501 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1506 if ( recurse
&& !child
->Validate() )
1511 #endif // wxUSE_VALIDATORS
1516 bool wxWindowBase::TransferDataToWindow()
1518 #if wxUSE_VALIDATORS
1519 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1521 wxWindowList::compatibility_iterator node
;
1522 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1524 wxWindowBase
*child
= node
->GetData();
1525 wxValidator
*validator
= child
->GetValidator();
1526 if ( validator
&& !validator
->TransferToWindow() )
1528 wxLogWarning(_("Could not transfer data to window"));
1530 wxLog::FlushActive();
1538 if ( !child
->TransferDataToWindow() )
1540 // warning already given
1545 #endif // wxUSE_VALIDATORS
1550 bool wxWindowBase::TransferDataFromWindow()
1552 #if wxUSE_VALIDATORS
1553 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1555 wxWindowList::compatibility_iterator node
;
1556 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1558 wxWindow
*child
= node
->GetData();
1559 wxValidator
*validator
= child
->GetValidator();
1560 if ( validator
&& !validator
->TransferFromWindow() )
1562 // nop warning here because the application is supposed to give
1563 // one itself - we don't know here what might have gone wrongly
1570 if ( !child
->TransferDataFromWindow() )
1572 // warning already given
1577 #endif // wxUSE_VALIDATORS
1582 void wxWindowBase::InitDialog()
1584 wxInitDialogEvent
event(GetId());
1585 event
.SetEventObject( this );
1586 GetEventHandler()->ProcessEvent(event
);
1589 // ----------------------------------------------------------------------------
1590 // context-sensitive help support
1591 // ----------------------------------------------------------------------------
1595 // associate this help text with this window
1596 void wxWindowBase::SetHelpText(const wxString
& text
)
1598 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1601 helpProvider
->AddHelp(this, text
);
1605 // associate this help text with all windows with the same id as this
1607 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1609 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1612 helpProvider
->AddHelp(GetId(), text
);
1616 // get the help string associated with this window (may be empty)
1617 // default implementation forwards calls to the help provider
1619 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1620 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1623 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1626 text
= helpProvider
->GetHelp(this);
1632 // show help for this window
1633 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1635 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1638 if ( helpProvider
->ShowHelpAtPoint(this, event
.GetPosition(), event
.GetOrigin()) )
1640 // skip the event.Skip() below
1648 #endif // wxUSE_HELP
1650 // ----------------------------------------------------------------------------
1652 // ----------------------------------------------------------------------------
1656 void wxWindowBase::SetToolTip( const wxString
&tip
)
1658 // don't create the new tooltip if we already have one
1661 m_tooltip
->SetTip( tip
);
1665 SetToolTip( new wxToolTip( tip
) );
1668 // setting empty tooltip text does not remove the tooltip any more - use
1669 // SetToolTip((wxToolTip *)NULL) for this
1672 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1674 if ( m_tooltip
!= tooltip
)
1679 m_tooltip
= tooltip
;
1683 #endif // wxUSE_TOOLTIPS
1685 // ----------------------------------------------------------------------------
1686 // constraints and sizers
1687 // ----------------------------------------------------------------------------
1689 #if wxUSE_CONSTRAINTS
1691 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1693 if ( m_constraints
)
1695 UnsetConstraints(m_constraints
);
1696 delete m_constraints
;
1698 m_constraints
= constraints
;
1699 if ( m_constraints
)
1701 // Make sure other windows know they're part of a 'meaningful relationship'
1702 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1703 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1704 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1705 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1706 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1707 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1708 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1709 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1710 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1711 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1712 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1713 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1714 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1715 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1716 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1717 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1721 // This removes any dangling pointers to this window in other windows'
1722 // constraintsInvolvedIn lists.
1723 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1727 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1728 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1729 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1730 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1731 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1732 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1733 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1734 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1735 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1736 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1737 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1738 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1739 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1740 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1741 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1742 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1746 // Back-pointer to other windows we're involved with, so if we delete this
1747 // window, we must delete any constraints we're involved with.
1748 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1750 if ( !m_constraintsInvolvedIn
)
1751 m_constraintsInvolvedIn
= new wxWindowList
;
1752 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1753 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1756 // REMOVE back-pointer to other windows we're involved with.
1757 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1759 if ( m_constraintsInvolvedIn
)
1760 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1763 // Reset any constraints that mention this window
1764 void wxWindowBase::DeleteRelatedConstraints()
1766 if ( m_constraintsInvolvedIn
)
1768 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1771 wxWindow
*win
= node
->GetData();
1772 wxLayoutConstraints
*constr
= win
->GetConstraints();
1774 // Reset any constraints involving this window
1777 constr
->left
.ResetIfWin(this);
1778 constr
->top
.ResetIfWin(this);
1779 constr
->right
.ResetIfWin(this);
1780 constr
->bottom
.ResetIfWin(this);
1781 constr
->width
.ResetIfWin(this);
1782 constr
->height
.ResetIfWin(this);
1783 constr
->centreX
.ResetIfWin(this);
1784 constr
->centreY
.ResetIfWin(this);
1787 wxWindowList::compatibility_iterator next
= node
->GetNext();
1788 m_constraintsInvolvedIn
->Erase(node
);
1792 delete m_constraintsInvolvedIn
;
1793 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1797 #endif // wxUSE_CONSTRAINTS
1799 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1801 if ( sizer
== m_windowSizer
)
1804 if ( m_windowSizer
)
1806 m_windowSizer
->SetContainingWindow(NULL
);
1809 delete m_windowSizer
;
1812 m_windowSizer
= sizer
;
1813 if ( m_windowSizer
)
1815 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
1818 SetAutoLayout(m_windowSizer
!= NULL
);
1821 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1823 SetSizer( sizer
, deleteOld
);
1824 sizer
->SetSizeHints( (wxWindow
*) this );
1828 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1830 // adding a window to a sizer twice is going to result in fatal and
1831 // hard to debug problems later because when deleting the second
1832 // associated wxSizerItem we're going to dereference a dangling
1833 // pointer; so try to detect this as early as possible
1834 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1835 _T("Adding a window to the same sizer twice?") );
1837 m_containingSizer
= sizer
;
1840 #if wxUSE_CONSTRAINTS
1842 void wxWindowBase::SatisfyConstraints()
1844 wxLayoutConstraints
*constr
= GetConstraints();
1845 bool wasOk
= constr
&& constr
->AreSatisfied();
1847 ResetConstraints(); // Mark all constraints as unevaluated
1851 // if we're a top level panel (i.e. our parent is frame/dialog), our
1852 // own constraints will never be satisfied any more unless we do it
1856 while ( noChanges
> 0 )
1858 LayoutPhase1(&noChanges
);
1862 LayoutPhase2(&noChanges
);
1865 #endif // wxUSE_CONSTRAINTS
1867 bool wxWindowBase::Layout()
1869 // If there is a sizer, use it instead of the constraints
1873 GetVirtualSize(&w
, &h
);
1874 GetSizer()->SetDimension( 0, 0, w
, h
);
1876 #if wxUSE_CONSTRAINTS
1879 SatisfyConstraints(); // Find the right constraints values
1880 SetConstraintSizes(); // Recursively set the real window sizes
1887 #if wxUSE_CONSTRAINTS
1889 // first phase of the constraints evaluation: set our own constraints
1890 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1892 wxLayoutConstraints
*constr
= GetConstraints();
1894 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1897 // second phase: set the constraints for our children
1898 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1905 // Layout grand children
1911 // Do a phase of evaluating child constraints
1912 bool wxWindowBase::DoPhase(int phase
)
1914 // the list containing the children for which the constraints are already
1916 wxWindowList succeeded
;
1918 // the max number of iterations we loop before concluding that we can't set
1920 static const int maxIterations
= 500;
1922 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1926 // loop over all children setting their constraints
1927 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1929 node
= node
->GetNext() )
1931 wxWindow
*child
= node
->GetData();
1932 if ( child
->IsTopLevel() )
1934 // top level children are not inside our client area
1938 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1940 // this one is either already ok or nothing we can do about it
1944 int tempNoChanges
= 0;
1945 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1946 : child
->LayoutPhase2(&tempNoChanges
);
1947 noChanges
+= tempNoChanges
;
1951 succeeded
.Append(child
);
1957 // constraints are set
1965 void wxWindowBase::ResetConstraints()
1967 wxLayoutConstraints
*constr
= GetConstraints();
1970 constr
->left
.SetDone(false);
1971 constr
->top
.SetDone(false);
1972 constr
->right
.SetDone(false);
1973 constr
->bottom
.SetDone(false);
1974 constr
->width
.SetDone(false);
1975 constr
->height
.SetDone(false);
1976 constr
->centreX
.SetDone(false);
1977 constr
->centreY
.SetDone(false);
1980 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1983 wxWindow
*win
= node
->GetData();
1984 if ( !win
->IsTopLevel() )
1985 win
->ResetConstraints();
1986 node
= node
->GetNext();
1990 // Need to distinguish between setting the 'fake' size for windows and sizers,
1991 // and setting the real values.
1992 void wxWindowBase::SetConstraintSizes(bool recurse
)
1994 wxLayoutConstraints
*constr
= GetConstraints();
1995 if ( constr
&& constr
->AreSatisfied() )
1997 int x
= constr
->left
.GetValue();
1998 int y
= constr
->top
.GetValue();
1999 int w
= constr
->width
.GetValue();
2000 int h
= constr
->height
.GetValue();
2002 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
2003 (constr
->height
.GetRelationship() != wxAsIs
) )
2005 SetSize(x
, y
, w
, h
);
2009 // If we don't want to resize this window, just move it...
2015 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
2016 GetClassInfo()->GetClassName(),
2022 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2025 wxWindow
*win
= node
->GetData();
2026 if ( !win
->IsTopLevel() && win
->GetConstraints() )
2027 win
->SetConstraintSizes();
2028 node
= node
->GetNext();
2033 // Only set the size/position of the constraint (if any)
2034 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
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);
2049 if ( w
!= wxDefaultCoord
)
2051 constr
->width
.SetValue(w
);
2052 constr
->width
.SetDone(true);
2054 if ( h
!= wxDefaultCoord
)
2056 constr
->height
.SetValue(h
);
2057 constr
->height
.SetDone(true);
2062 void wxWindowBase::MoveConstraint(int x
, int y
)
2064 wxLayoutConstraints
*constr
= GetConstraints();
2067 if ( x
!= wxDefaultCoord
)
2069 constr
->left
.SetValue(x
);
2070 constr
->left
.SetDone(true);
2072 if ( y
!= wxDefaultCoord
)
2074 constr
->top
.SetValue(y
);
2075 constr
->top
.SetDone(true);
2080 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2082 wxLayoutConstraints
*constr
= GetConstraints();
2085 *w
= constr
->width
.GetValue();
2086 *h
= constr
->height
.GetValue();
2092 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2094 wxLayoutConstraints
*constr
= GetConstraints();
2097 *w
= constr
->width
.GetValue();
2098 *h
= constr
->height
.GetValue();
2101 GetClientSize(w
, h
);
2104 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2106 wxLayoutConstraints
*constr
= GetConstraints();
2109 *x
= constr
->left
.GetValue();
2110 *y
= constr
->top
.GetValue();
2116 #endif // wxUSE_CONSTRAINTS
2118 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2120 // don't do it for the dialogs/frames - they float independently of their
2122 if ( !IsTopLevel() )
2124 wxWindow
*parent
= GetParent();
2125 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2127 wxPoint
pt(parent
->GetClientAreaOrigin());
2134 // ----------------------------------------------------------------------------
2135 // Update UI processing
2136 // ----------------------------------------------------------------------------
2138 void wxWindowBase::UpdateWindowUI(long flags
)
2140 wxUpdateUIEvent
event(GetId());
2141 event
.SetEventObject(this);
2143 if ( GetEventHandler()->ProcessEvent(event
) )
2145 DoUpdateWindowUI(event
);
2148 if (flags
& wxUPDATE_UI_RECURSE
)
2150 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2153 wxWindow
* child
= (wxWindow
*) node
->GetData();
2154 child
->UpdateWindowUI(flags
);
2155 node
= node
->GetNext();
2160 // do the window-specific processing after processing the update event
2161 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2163 if ( event
.GetSetEnabled() )
2164 Enable(event
.GetEnabled());
2166 if ( event
.GetSetShown() )
2167 Show(event
.GetShown());
2170 // ----------------------------------------------------------------------------
2171 // dialog units translations
2172 // ----------------------------------------------------------------------------
2174 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2176 int charWidth
= GetCharWidth();
2177 int charHeight
= GetCharHeight();
2178 wxPoint pt2
= wxDefaultPosition
;
2179 if (pt
.x
!= wxDefaultCoord
)
2180 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2181 if (pt
.y
!= wxDefaultCoord
)
2182 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2187 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2189 int charWidth
= GetCharWidth();
2190 int charHeight
= GetCharHeight();
2191 wxPoint pt2
= wxDefaultPosition
;
2192 if (pt
.x
!= wxDefaultCoord
)
2193 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2194 if (pt
.y
!= wxDefaultCoord
)
2195 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2200 // ----------------------------------------------------------------------------
2202 // ----------------------------------------------------------------------------
2204 // propagate the colour change event to the subwindows
2205 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2207 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2210 // Only propagate to non-top-level windows
2211 wxWindow
*win
= node
->GetData();
2212 if ( !win
->IsTopLevel() )
2214 wxSysColourChangedEvent event2
;
2215 event
.SetEventObject(win
);
2216 win
->GetEventHandler()->ProcessEvent(event2
);
2219 node
= node
->GetNext();
2225 // the default action is to populate dialog with data when it's created,
2226 // and nudge the UI into displaying itself correctly in case
2227 // we've turned the wxUpdateUIEvents frequency down low.
2228 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2230 TransferDataToWindow();
2232 // Update the UI at this point
2233 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2236 // ----------------------------------------------------------------------------
2237 // menu-related functions
2238 // ----------------------------------------------------------------------------
2242 // this is used to pass the id of the selected item from the menu event handler
2243 // to the main function itself
2245 // it's ok to use a global here as there can be at most one popup menu shown at
2247 static int gs_popupMenuSelection
= wxID_NONE
;
2249 void wxWindowBase::InternalOnPopupMenu(wxCommandEvent
& event
)
2251 // store the id in a global variable where we'll retrieve it from later
2252 gs_popupMenuSelection
= event
.GetId();
2256 wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu
& menu
, int x
, int y
)
2258 gs_popupMenuSelection
= wxID_NONE
;
2260 Connect(wxEVT_COMMAND_MENU_SELECTED
,
2261 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2265 PopupMenu(&menu
, x
, y
);
2267 Disconnect(wxEVT_COMMAND_MENU_SELECTED
,
2268 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2272 return gs_popupMenuSelection
;
2275 #endif // wxUSE_MENUS
2277 // methods for drawing the sizers in a visible way
2280 static void DrawSizers(wxWindowBase
*win
);
2282 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2284 wxClientDC
dc((wxWindow
*)win
);
2285 dc
.SetPen(*wxRED_PEN
);
2286 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2287 dc
.DrawRectangle(rect
.Deflate(1, 1));
2290 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2292 const wxSizerItemList
& items
= sizer
->GetChildren();
2293 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2298 wxSizerItem
*item
= *i
;
2299 if ( item
->IsSizer() )
2301 DrawBorder(win
, item
->GetRect().Deflate(2));
2302 DrawSizer(win
, item
->GetSizer());
2304 else if ( item
->IsSpacer() )
2306 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2308 else if ( item
->IsWindow() )
2310 DrawSizers(item
->GetWindow());
2315 static void DrawSizers(wxWindowBase
*win
)
2317 wxSizer
*sizer
= win
->GetSizer();
2320 DrawBorder(win
, win
->GetClientSize());
2321 DrawSizer(win
, sizer
);
2323 else // no sizer, still recurse into the children
2325 const wxWindowList
& children
= win
->GetChildren();
2326 for ( wxWindowList::const_iterator i
= children
.begin(),
2327 end
= children
.end();
2336 #endif // __WXDEBUG__
2338 // process special middle clicks
2339 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2341 if ( event
.ControlDown() && event
.AltDown() )
2344 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2345 if ( event
.ShiftDown() )
2350 #endif // __WXDEBUG__
2353 // don't translate these strings, they're for diagnostics purposes only
2355 msg
.Printf(_T("wxWidgets Library (%s port)\n")
2356 _T("Version %d.%d.%d%s%s, compiled at %s %s\n")
2357 _T("Runtime version of toolkit used is %d.%d.%s\n")
2358 _T("Copyright (c) 1995-2007 wxWidgets team"),
2359 wxPlatformInfo::Get().GetPortIdName().c_str(),
2375 wxPlatformInfo::Get().GetToolkitMajorVersion(),
2376 wxPlatformInfo::Get().GetToolkitMinorVersion(),
2378 wxString::Format(_T("\nThe compile-time GTK+ version is %d.%d.%d."), GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
).c_str()
2384 wxMessageBox(msg
, _T("wxWidgets information"),
2385 wxICON_INFORMATION
| wxOK
,
2387 #endif // wxUSE_MSGDLG
2395 // ----------------------------------------------------------------------------
2397 // ----------------------------------------------------------------------------
2399 #if wxUSE_ACCESSIBILITY
2400 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2402 if (m_accessible
&& (accessible
!= m_accessible
))
2403 delete m_accessible
;
2404 m_accessible
= accessible
;
2406 m_accessible
->SetWindow((wxWindow
*) this);
2409 // Returns the accessible object, creating if necessary.
2410 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2413 m_accessible
= CreateAccessible();
2414 return m_accessible
;
2417 // Override to create a specific accessible object.
2418 wxAccessible
* wxWindowBase::CreateAccessible()
2420 return new wxWindowAccessible((wxWindow
*) this);
2425 // ----------------------------------------------------------------------------
2426 // list classes implementation
2427 // ----------------------------------------------------------------------------
2431 #include "wx/listimpl.cpp"
2432 WX_DEFINE_LIST(wxWindowList
)
2436 void wxWindowListNode::DeleteData()
2438 delete (wxWindow
*)GetData();
2441 #endif // wxUSE_STL/!wxUSE_STL
2443 // ----------------------------------------------------------------------------
2445 // ----------------------------------------------------------------------------
2447 wxBorder
wxWindowBase::GetBorder(long flags
) const
2449 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2450 if ( border
== wxBORDER_DEFAULT
)
2452 border
= GetDefaultBorder();
2454 else if ( border
== wxBORDER_THEME
)
2456 border
= GetDefaultBorderForControl();
2462 wxBorder
wxWindowBase::GetDefaultBorder() const
2464 return wxBORDER_NONE
;
2467 // ----------------------------------------------------------------------------
2469 // ----------------------------------------------------------------------------
2471 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2473 // here we just check if the point is inside the window or not
2475 // check the top and left border first
2476 bool outside
= x
< 0 || y
< 0;
2479 // check the right and bottom borders too
2480 wxSize size
= GetSize();
2481 outside
= x
>= size
.x
|| y
>= size
.y
;
2484 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2487 // ----------------------------------------------------------------------------
2489 // ----------------------------------------------------------------------------
2491 struct WXDLLEXPORT wxWindowNext
2495 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2496 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2497 bool wxWindowBase::ms_winCaptureChanging
= false;
2499 void wxWindowBase::CaptureMouse()
2501 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2503 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2505 ms_winCaptureChanging
= true;
2507 wxWindow
*winOld
= GetCapture();
2510 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2513 wxWindowNext
*item
= new wxWindowNext
;
2515 item
->next
= ms_winCaptureNext
;
2516 ms_winCaptureNext
= item
;
2518 //else: no mouse capture to save
2521 ms_winCaptureCurrent
= (wxWindow
*)this;
2523 ms_winCaptureChanging
= false;
2526 void wxWindowBase::ReleaseMouse()
2528 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2530 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2532 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2534 ms_winCaptureChanging
= true;
2537 ms_winCaptureCurrent
= NULL
;
2539 if ( ms_winCaptureNext
)
2541 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2542 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2544 wxWindowNext
*item
= ms_winCaptureNext
;
2545 ms_winCaptureNext
= item
->next
;
2548 //else: stack is empty, no previous capture
2550 ms_winCaptureChanging
= false;
2552 wxLogTrace(_T("mousecapture"),
2553 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2554 wx_static_cast(void*, GetCapture()));
2557 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2559 wxMouseCaptureLostEvent
event(win
->GetId());
2560 event
.SetEventObject(win
);
2561 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2563 // windows must handle this event, otherwise the app wouldn't behave
2564 // correctly if it loses capture unexpectedly; see the discussion here:
2565 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
2566 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
2567 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2572 void wxWindowBase::NotifyCaptureLost()
2574 // don't do anything if capture lost was expected, i.e. resulted from
2575 // a wx call to ReleaseMouse or CaptureMouse:
2576 if ( ms_winCaptureChanging
)
2579 // if the capture was lost unexpectedly, notify every window that has
2580 // capture (on stack or current) about it and clear the stack:
2582 if ( ms_winCaptureCurrent
)
2584 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2585 ms_winCaptureCurrent
= NULL
;
2588 while ( ms_winCaptureNext
)
2590 wxWindowNext
*item
= ms_winCaptureNext
;
2591 ms_winCaptureNext
= item
->next
;
2593 DoNotifyWindowAboutCaptureLost(item
->win
);
2602 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2603 int WXUNUSED(modifiers
),
2604 int WXUNUSED(keycode
))
2610 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2616 #endif // wxUSE_HOTKEY
2618 // ----------------------------------------------------------------------------
2620 // ----------------------------------------------------------------------------
2622 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2624 #if wxUSE_VALIDATORS
2625 // Can only use the validator of the window which
2626 // is receiving the event
2627 if ( event
.GetEventObject() == this )
2629 wxValidator
*validator
= GetValidator();
2630 if ( validator
&& validator
->ProcessEvent(event
) )
2635 #endif // wxUSE_VALIDATORS
2640 bool wxWindowBase::TryParent(wxEvent
& event
)
2642 // carry on up the parent-child hierarchy if the propagation count hasn't
2644 if ( event
.ShouldPropagate() )
2646 // honour the requests to stop propagation at this window: this is
2647 // used by the dialogs, for example, to prevent processing the events
2648 // from the dialog controls in the parent frame which rarely, if ever,
2650 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2652 wxWindow
*parent
= GetParent();
2653 if ( parent
&& !parent
->IsBeingDeleted() )
2655 wxPropagateOnce
propagateOnce(event
);
2657 return parent
->GetEventHandler()->ProcessEvent(event
);
2662 return wxEvtHandler::TryParent(event
);
2665 // ----------------------------------------------------------------------------
2666 // keyboard navigation
2667 // ----------------------------------------------------------------------------
2669 // Navigates in the specified direction inside this window
2670 bool wxWindowBase::DoNavigateIn(int flags
)
2672 #ifdef wxHAS_NATIVE_TAB_TRAVERSAL
2673 // native code doesn't process our wxNavigationKeyEvents anyhow
2675 #else // !wxHAS_NATIVE_TAB_TRAVERSAL
2676 wxNavigationKeyEvent eventNav
;
2677 eventNav
.SetFlags(flags
);
2678 eventNav
.SetEventObject(FindFocus());
2679 return GetEventHandler()->ProcessEvent(eventNav
);
2680 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
2683 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2685 // check that we're not a top level window
2686 wxCHECK_RET( GetParent(),
2687 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2689 // detect the special case when we have nothing to do anyhow and when the
2690 // code below wouldn't work
2694 // find the target window in the siblings list
2695 wxWindowList
& siblings
= GetParent()->GetChildren();
2696 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2697 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2699 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2700 // can't just move the node around
2701 wxWindow
*self
= (wxWindow
*)this;
2702 siblings
.DeleteObject(self
);
2703 if ( move
== MoveAfter
)
2710 siblings
.Insert(i
, self
);
2712 else // MoveAfter and win was the last sibling
2714 siblings
.Append(self
);
2718 // ----------------------------------------------------------------------------
2720 // ----------------------------------------------------------------------------
2722 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2724 wxWindowBase
*win
= DoFindFocus();
2725 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2728 // ----------------------------------------------------------------------------
2730 // ----------------------------------------------------------------------------
2732 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2734 while ( win
&& !win
->IsTopLevel() )
2735 win
= win
->GetParent();
2740 #if wxUSE_ACCESSIBILITY
2741 // ----------------------------------------------------------------------------
2742 // accessible object for windows
2743 // ----------------------------------------------------------------------------
2745 // Can return either a child object, or an integer
2746 // representing the child element, starting from 1.
2747 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2749 wxASSERT( GetWindow() != NULL
);
2753 return wxACC_NOT_IMPLEMENTED
;
2756 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2757 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2759 wxASSERT( GetWindow() != NULL
);
2763 wxWindow
* win
= NULL
;
2770 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2772 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2779 rect
= win
->GetRect();
2780 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2781 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2785 return wxACC_NOT_IMPLEMENTED
;
2788 // Navigates from fromId to toId/toObject.
2789 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2790 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2792 wxASSERT( GetWindow() != NULL
);
2798 case wxNAVDIR_FIRSTCHILD
:
2800 if (GetWindow()->GetChildren().GetCount() == 0)
2802 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2803 *toObject
= childWindow
->GetOrCreateAccessible();
2807 case wxNAVDIR_LASTCHILD
:
2809 if (GetWindow()->GetChildren().GetCount() == 0)
2811 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2812 *toObject
= childWindow
->GetOrCreateAccessible();
2816 case wxNAVDIR_RIGHT
:
2820 wxWindowList::compatibility_iterator node
=
2821 wxWindowList::compatibility_iterator();
2824 // Can't navigate to sibling of this window
2825 // if we're a top-level window.
2826 if (!GetWindow()->GetParent())
2827 return wxACC_NOT_IMPLEMENTED
;
2829 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2833 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2834 node
= GetWindow()->GetChildren().Item(fromId
-1);
2837 if (node
&& node
->GetNext())
2839 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2840 *toObject
= nextWindow
->GetOrCreateAccessible();
2848 case wxNAVDIR_PREVIOUS
:
2850 wxWindowList::compatibility_iterator node
=
2851 wxWindowList::compatibility_iterator();
2854 // Can't navigate to sibling of this window
2855 // if we're a top-level window.
2856 if (!GetWindow()->GetParent())
2857 return wxACC_NOT_IMPLEMENTED
;
2859 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2863 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2864 node
= GetWindow()->GetChildren().Item(fromId
-1);
2867 if (node
&& node
->GetPrevious())
2869 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2870 *toObject
= previousWindow
->GetOrCreateAccessible();
2878 return wxACC_NOT_IMPLEMENTED
;
2881 // Gets the name of the specified object.
2882 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2884 wxASSERT( GetWindow() != NULL
);
2890 // If a child, leave wxWidgets to call the function on the actual
2893 return wxACC_NOT_IMPLEMENTED
;
2895 // This will eventually be replaced by specialised
2896 // accessible classes, one for each kind of wxWidgets
2897 // control or window.
2899 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2900 title
= ((wxButton
*) GetWindow())->GetLabel();
2903 title
= GetWindow()->GetName();
2911 return wxACC_NOT_IMPLEMENTED
;
2914 // Gets the number of children.
2915 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2917 wxASSERT( GetWindow() != NULL
);
2921 *childId
= (int) GetWindow()->GetChildren().GetCount();
2925 // Gets the specified child (starting from 1).
2926 // If *child is NULL and return value is wxACC_OK,
2927 // this means that the child is a simple element and
2928 // not an accessible object.
2929 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2931 wxASSERT( GetWindow() != NULL
);
2941 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2944 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2945 *child
= childWindow
->GetOrCreateAccessible();
2952 // Gets the parent, or NULL.
2953 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2955 wxASSERT( GetWindow() != NULL
);
2959 wxWindow
* parentWindow
= GetWindow()->GetParent();
2967 *parent
= parentWindow
->GetOrCreateAccessible();
2975 // Performs the default action. childId is 0 (the action for this object)
2976 // or > 0 (the action for a child).
2977 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2978 // window (e.g. an edit control).
2979 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2981 wxASSERT( GetWindow() != NULL
);
2985 return wxACC_NOT_IMPLEMENTED
;
2988 // Gets the default action for this object (0) or > 0 (the action for a child).
2989 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2990 // string if there is no action.
2991 // The retrieved string describes the action that is performed on an object,
2992 // not what the object does as a result. For example, a toolbar button that prints
2993 // a document has a default action of "Press" rather than "Prints the current document."
2994 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2996 wxASSERT( GetWindow() != NULL
);
3000 return wxACC_NOT_IMPLEMENTED
;
3003 // Returns the description for this object or a child.
3004 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
3006 wxASSERT( GetWindow() != NULL
);
3010 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3016 return wxACC_NOT_IMPLEMENTED
;
3019 // Returns help text for this object or a child, similar to tooltip text.
3020 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
3022 wxASSERT( GetWindow() != NULL
);
3026 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3032 return wxACC_NOT_IMPLEMENTED
;
3035 // Returns the keyboard shortcut for this object or child.
3036 // Return e.g. ALT+K
3037 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
3039 wxASSERT( GetWindow() != NULL
);
3043 return wxACC_NOT_IMPLEMENTED
;
3046 // Returns a role constant.
3047 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
3049 wxASSERT( GetWindow() != NULL
);
3053 // If a child, leave wxWidgets to call the function on the actual
3056 return wxACC_NOT_IMPLEMENTED
;
3058 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3059 return wxACC_NOT_IMPLEMENTED
;
3061 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3062 return wxACC_NOT_IMPLEMENTED
;
3065 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3066 return wxACC_NOT_IMPLEMENTED
;
3069 //*role = wxROLE_SYSTEM_CLIENT;
3070 *role
= wxROLE_SYSTEM_CLIENT
;
3074 return wxACC_NOT_IMPLEMENTED
;
3078 // Returns a state constant.
3079 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
3081 wxASSERT( GetWindow() != NULL
);
3085 // If a child, leave wxWidgets to call the function on the actual
3088 return wxACC_NOT_IMPLEMENTED
;
3090 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3091 return wxACC_NOT_IMPLEMENTED
;
3094 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3095 return wxACC_NOT_IMPLEMENTED
;
3098 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3099 return wxACC_NOT_IMPLEMENTED
;
3106 return wxACC_NOT_IMPLEMENTED
;
3110 // Returns a localized string representing the value for the object
3112 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3114 wxASSERT( GetWindow() != NULL
);
3118 return wxACC_NOT_IMPLEMENTED
;
3121 // Selects the object or child.
3122 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3124 wxASSERT( GetWindow() != NULL
);
3128 return wxACC_NOT_IMPLEMENTED
;
3131 // Gets the window with the keyboard focus.
3132 // If childId is 0 and child is NULL, no object in
3133 // this subhierarchy has the focus.
3134 // If this object has the focus, child should be 'this'.
3135 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3137 wxASSERT( GetWindow() != NULL
);
3141 return wxACC_NOT_IMPLEMENTED
;
3145 // Gets a variant representing the selected children
3147 // Acceptable values:
3148 // - a null variant (IsNull() returns true)
3149 // - a list variant (GetType() == wxT("list")
3150 // - an integer representing the selected child element,
3151 // or 0 if this object is selected (GetType() == wxT("long")
3152 // - a "void*" pointer to a wxAccessible child object
3153 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3155 wxASSERT( GetWindow() != NULL
);
3159 return wxACC_NOT_IMPLEMENTED
;
3161 #endif // wxUSE_VARIANT
3163 #endif // wxUSE_ACCESSIBILITY
3165 // ----------------------------------------------------------------------------
3167 // ----------------------------------------------------------------------------
3170 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3172 wxCoord widthTotal
) const
3174 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3176 x
= widthTotal
- x
- width
;