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 // ----------------------------------------------------------------------------
93 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
95 // ----------------------------------------------------------------------------
97 // ----------------------------------------------------------------------------
99 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
100 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
101 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
102 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
105 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
110 // ============================================================================
111 // implementation of the common functionality of the wxWindow class
112 // ============================================================================
114 // ----------------------------------------------------------------------------
116 // ----------------------------------------------------------------------------
118 // the default initialization
119 wxWindowBase::wxWindowBase()
121 // no window yet, no parent nor children
122 m_parent
= (wxWindow
*)NULL
;
123 m_windowId
= wxID_ANY
;
125 // no constraints on the minimal window size
127 m_maxWidth
= wxDefaultCoord
;
129 m_maxHeight
= wxDefaultCoord
;
131 // invalidiated cache value
132 m_bestSizeCache
= wxDefaultSize
;
134 // window are created enabled and visible by default
138 // the default event handler is just this window
139 m_eventHandler
= this;
143 m_windowValidator
= (wxValidator
*) NULL
;
144 #endif // wxUSE_VALIDATORS
146 // the colours/fonts are default for now, so leave m_font,
147 // m_backgroundColour and m_foregroundColour uninitialized and set those
153 m_inheritFont
= false;
159 m_backgroundStyle
= wxBG_STYLE_SYSTEM
;
161 #if wxUSE_CONSTRAINTS
162 // no constraints whatsoever
163 m_constraints
= (wxLayoutConstraints
*) NULL
;
164 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
165 #endif // wxUSE_CONSTRAINTS
167 m_windowSizer
= (wxSizer
*) NULL
;
168 m_containingSizer
= (wxSizer
*) NULL
;
169 m_autoLayout
= false;
172 #if wxUSE_DRAG_AND_DROP
173 m_dropTarget
= (wxDropTarget
*)NULL
;
174 #endif // wxUSE_DRAG_AND_DROP
177 m_tooltip
= (wxToolTip
*)NULL
;
178 #endif // wxUSE_TOOLTIPS
181 m_caret
= (wxCaret
*)NULL
;
182 #endif // wxUSE_CARET
185 m_hasCustomPalette
= false;
186 #endif // wxUSE_PALETTE
188 #if wxUSE_ACCESSIBILITY
192 m_virtualSize
= wxDefaultSize
;
194 m_scrollHelper
= (wxScrollHelper
*) NULL
;
196 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
197 #if wxUSE_SYSTEM_OPTIONS
198 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
200 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
204 // Whether we're using the current theme for this window (wxGTK only for now)
205 m_themeEnabled
= false;
207 // VZ: this one shouldn't exist...
208 m_isBeingDeleted
= false;
211 // common part of window creation process
212 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
214 const wxPoint
& WXUNUSED(pos
),
215 const wxSize
& WXUNUSED(size
),
217 const wxValidator
& wxVALIDATOR_PARAM(validator
),
218 const wxString
& name
)
221 // wxGTK doesn't allow to create controls with static box as the parent so
222 // this will result in a crash when the program is ported to wxGTK so warn
225 // if you get this assert, the correct solution is to create the controls
226 // as siblings of the static box
227 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
228 _T("wxStaticBox can't be used as a window parent!") );
229 #endif // wxUSE_STATBOX
231 // ids are limited to 16 bits under MSW so if you care about portability,
232 // it's not a good idea to use ids out of this range (and negative ids are
233 // reserved for wxWidgets own usage)
234 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767) ||
235 (id
>= wxID_AUTO_LOWEST
&& id
<= wxID_AUTO_HIGHEST
),
236 _T("invalid id value") );
238 // generate a new id if the user doesn't care about it
239 if ( id
== wxID_ANY
)
241 m_windowId
= NewControlId();
243 // remember to call ReleaseControlId() when this window is destroyed
246 else // valid id specified
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 // mark the id as unused if we allocated it for this control
307 ReleaseControlId(m_windowId
);
309 // FIXME if these 2 cases result from programming errors in the user code
310 // we should probably assert here instead of silently fixing them
312 // Just in case the window has been Closed, but we're then deleting
313 // immediately: don't leave dangling pointers.
314 wxPendingDelete
.DeleteObject(this);
316 // Just in case we've loaded a top-level window via LoadNativeDialog but
317 // we weren't a dialog class
318 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
320 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
322 // notify the parent about this window destruction
324 m_parent
->RemoveChild(this);
328 #endif // wxUSE_CARET
331 delete m_windowValidator
;
332 #endif // wxUSE_VALIDATORS
334 #if wxUSE_CONSTRAINTS
335 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
336 // at deleted windows as they delete themselves.
337 DeleteRelatedConstraints();
341 // This removes any dangling pointers to this window in other windows'
342 // constraintsInvolvedIn lists.
343 UnsetConstraints(m_constraints
);
344 delete m_constraints
;
345 m_constraints
= NULL
;
347 #endif // wxUSE_CONSTRAINTS
349 if ( m_containingSizer
)
350 m_containingSizer
->Detach( (wxWindow
*)this );
352 delete m_windowSizer
;
354 #if wxUSE_DRAG_AND_DROP
356 #endif // wxUSE_DRAG_AND_DROP
360 #endif // wxUSE_TOOLTIPS
362 #if wxUSE_ACCESSIBILITY
367 void wxWindowBase::SendDestroyEvent()
369 wxWindowDestroyEvent event
;
370 event
.SetEventObject(this);
371 event
.SetId(GetId());
372 GetEventHandler()->ProcessEvent(event
);
375 bool wxWindowBase::Destroy()
382 bool wxWindowBase::Close(bool force
)
384 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
385 event
.SetEventObject(this);
386 event
.SetCanVeto(!force
);
388 // return false if window wasn't closed because the application vetoed the
390 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
393 bool wxWindowBase::DestroyChildren()
395 wxWindowList::compatibility_iterator node
;
398 // we iterate until the list becomes empty
399 node
= GetChildren().GetFirst();
403 wxWindow
*child
= node
->GetData();
405 // note that we really want to call delete and not ->Destroy() here
406 // because we want to delete the child immediately, before we are
407 // deleted, and delayed deletion would result in problems as our (top
408 // level) child could outlive its parent
411 wxASSERT_MSG( !GetChildren().Find(child
),
412 wxT("child didn't remove itself using RemoveChild()") );
418 // ----------------------------------------------------------------------------
419 // size/position related methods
420 // ----------------------------------------------------------------------------
422 // centre the window with respect to its parent in either (or both) directions
423 void wxWindowBase::DoCentre(int dir
)
425 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
426 _T("this method only implements centering child windows") );
428 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
431 // fits the window around the children
432 void wxWindowBase::Fit()
434 if ( !GetChildren().empty() )
436 SetSize(GetBestSize());
438 //else: do nothing if we have no children
441 // fits virtual size (ie. scrolled area etc.) around children
442 void wxWindowBase::FitInside()
444 if ( GetChildren().GetCount() > 0 )
446 SetVirtualSize( GetBestVirtualSize() );
450 // On Mac, scrollbars are explicitly children.
452 static bool wxHasRealChildren(const wxWindowBase
* win
)
454 int realChildCount
= 0;
456 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
458 node
= node
->GetNext() )
460 wxWindow
*win
= node
->GetData();
461 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
464 return (realChildCount
> 0);
468 void wxWindowBase::InvalidateBestSize()
470 m_bestSizeCache
= wxDefaultSize
;
472 // parent's best size calculation may depend on its children's
473 // as long as child window we are in is not top level window itself
474 // (because the TLW size is never resized automatically)
475 // so let's invalidate it as well to be safe:
476 if (m_parent
&& !IsTopLevel())
477 m_parent
->InvalidateBestSize();
480 // return the size best suited for the current window
481 wxSize
wxWindowBase::DoGetBestSize() const
487 best
= m_windowSizer
->GetMinSize();
489 #if wxUSE_CONSTRAINTS
490 else if ( m_constraints
)
492 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
494 // our minimal acceptable size is such that all our windows fit inside
498 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
500 node
= node
->GetNext() )
502 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
505 // it's not normal that we have an unconstrained child, but
506 // what can we do about it?
510 int x
= c
->right
.GetValue(),
511 y
= c
->bottom
.GetValue();
519 // TODO: we must calculate the overlaps somehow, otherwise we
520 // will never return a size bigger than the current one :-(
523 best
= wxSize(maxX
, maxY
);
525 #endif // wxUSE_CONSTRAINTS
526 else if ( !GetChildren().empty()
528 && wxHasRealChildren(this)
532 // our minimal acceptable size is such that all our visible child
533 // windows fit inside
537 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
539 node
= node
->GetNext() )
541 wxWindow
*win
= node
->GetData();
542 if ( win
->IsTopLevel()
545 || wxDynamicCast(win
, wxStatusBar
)
546 #endif // wxUSE_STATUSBAR
549 // dialogs and frames lie in different top level windows -
550 // don't deal with them here; as for the status bars, they
551 // don't lie in the client area at all
556 win
->GetPosition(&wx
, &wy
);
558 // if the window hadn't been positioned yet, assume that it is in
560 if ( wx
== wxDefaultCoord
)
562 if ( wy
== wxDefaultCoord
)
565 win
->GetSize(&ww
, &wh
);
566 if ( wx
+ ww
> maxX
)
568 if ( wy
+ wh
> maxY
)
572 best
= wxSize(maxX
, maxY
);
574 else // ! has children
576 // for a generic window there is no natural best size so, if the
577 // minimal size is not set, use the current size but take care to
578 // remember it as minimal size for the next time because our best size
579 // should be constant: otherwise we could get into a situation when the
580 // window is initially at some size, then expanded to a larger size and
581 // then, when the containing window is shrunk back (because our initial
582 // best size had been used for computing the parent min size), we can't
583 // be shrunk back any more because our best size is now bigger
584 wxSize size
= GetMinSize();
585 if ( !size
.IsFullySpecified() )
587 size
.SetDefaults(GetSize());
588 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
591 // return as-is, unadjusted by the client size difference.
595 // Add any difference between size and client size
596 wxSize diff
= GetSize() - GetClientSize();
597 best
.x
+= wxMax(0, diff
.x
);
598 best
.y
+= wxMax(0, diff
.y
);
603 // helper of GetWindowBorderSize(): as many ports don't implement support for
604 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
605 // fallbacks in this case
606 static int wxGetMetricOrDefault(wxSystemMetric what
)
608 int rc
= wxSystemSettings::GetMetric(what
);
615 // 2D border is by default 1 pixel wide
621 // 3D borders are by default 2 pixels
626 wxFAIL_MSG( _T("unexpected wxGetMetricOrDefault() argument") );
634 wxSize
wxWindowBase::GetWindowBorderSize() const
638 switch ( GetBorder() )
641 // nothing to do, size is already (0, 0)
644 case wxBORDER_SIMPLE
:
645 case wxBORDER_STATIC
:
646 size
.x
= wxGetMetricOrDefault(wxSYS_BORDER_X
);
647 size
.y
= wxGetMetricOrDefault(wxSYS_BORDER_Y
);
650 case wxBORDER_SUNKEN
:
651 case wxBORDER_RAISED
:
652 size
.x
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X
),
653 wxGetMetricOrDefault(wxSYS_BORDER_X
));
654 size
.y
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y
),
655 wxGetMetricOrDefault(wxSYS_BORDER_Y
));
658 case wxBORDER_DOUBLE
:
659 size
.x
= wxGetMetricOrDefault(wxSYS_EDGE_X
) +
660 wxGetMetricOrDefault(wxSYS_BORDER_X
);
661 size
.y
= wxGetMetricOrDefault(wxSYS_EDGE_Y
) +
662 wxGetMetricOrDefault(wxSYS_BORDER_Y
);
666 wxFAIL_MSG(_T("Unknown border style."));
670 // we have borders on both sides
674 wxSize
wxWindowBase::GetEffectiveMinSize() const
676 // merge the best size with the min size, giving priority to the min size
677 wxSize min
= GetMinSize();
678 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
680 wxSize best
= GetBestSize();
681 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
682 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
688 void wxWindowBase::SetInitialSize(const wxSize
& size
)
690 // Set the min size to the size passed in. This will usually either be
691 // wxDefaultSize or the size passed to this window's ctor/Create function.
694 // Merge the size with the best size if needed
695 wxSize best
= GetEffectiveMinSize();
697 // If the current size doesn't match then change it
698 if (GetSize() != best
)
703 // by default the origin is not shifted
704 wxPoint
wxWindowBase::GetClientAreaOrigin() const
709 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
711 if ( m_windowVariant
!= variant
)
713 m_windowVariant
= variant
;
715 DoSetWindowVariant(variant
);
719 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
721 // adjust the font height to correspond to our new variant (notice that
722 // we're only called if something really changed)
723 wxFont font
= GetFont();
724 int size
= font
.GetPointSize();
727 case wxWINDOW_VARIANT_NORMAL
:
730 case wxWINDOW_VARIANT_SMALL
:
735 case wxWINDOW_VARIANT_MINI
:
740 case wxWINDOW_VARIANT_LARGE
:
746 wxFAIL_MSG(_T("unexpected window variant"));
750 font
.SetPointSize(size
);
754 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
756 int WXUNUSED(incW
), int WXUNUSED(incH
) )
758 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
759 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
760 _T("min width/height must be less than max width/height!") );
769 #if WXWIN_COMPATIBILITY_2_8
770 void wxWindowBase::SetVirtualSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
),
771 int WXUNUSED(maxW
), int WXUNUSED(maxH
))
775 void wxWindowBase::SetVirtualSizeHints(const wxSize
& WXUNUSED(minsize
),
776 const wxSize
& WXUNUSED(maxsize
))
779 #endif // WXWIN_COMPATIBILITY_2_8
781 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
783 m_virtualSize
= wxSize(x
, y
);
786 wxSize
wxWindowBase::DoGetVirtualSize() const
788 // we should use the entire client area so if it is greater than our
789 // virtual size, expand it to fit (otherwise if the window is big enough we
790 // wouldn't be using parts of it)
791 wxSize size
= GetClientSize();
792 if ( m_virtualSize
.x
> size
.x
)
793 size
.x
= m_virtualSize
.x
;
795 if ( m_virtualSize
.y
>= size
.y
)
796 size
.y
= m_virtualSize
.y
;
801 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
803 // screen position is the same as (0, 0) in client coords for non TLWs (and
804 // TLWs override this method)
810 ClientToScreen(x
, y
);
813 // ----------------------------------------------------------------------------
814 // show/hide/enable/disable the window
815 // ----------------------------------------------------------------------------
817 bool wxWindowBase::Show(bool show
)
819 if ( show
!= m_isShown
)
831 bool wxWindowBase::IsEnabled() const
833 return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
836 void wxWindowBase::NotifyWindowOnEnableChange(bool enabled
)
838 #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
840 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
844 // If we are top-level then the logic doesn't apply - otherwise
845 // showing a modal dialog would result in total greying out (and ungreying
846 // out later) of everything which would be really ugly
850 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
852 node
= node
->GetNext() )
854 wxWindowBase
* const child
= node
->GetData();
855 if ( !child
->IsTopLevel() && child
->IsThisEnabled() )
856 child
->NotifyWindowOnEnableChange(enabled
);
860 bool wxWindowBase::Enable(bool enable
)
862 if ( enable
== IsThisEnabled() )
865 m_isEnabled
= enable
;
867 #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
869 #else // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
870 wxWindowBase
* const parent
= GetParent();
871 if( !IsTopLevel() && parent
&& !parent
->IsEnabled() )
875 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
877 NotifyWindowOnEnableChange(enable
);
882 bool wxWindowBase::IsShownOnScreen() const
884 // A window is shown on screen if it itself is shown and so are all its
885 // parents. But if a window is toplevel one, then its always visible on
886 // screen if IsShown() returns true, even if it has a hidden parent.
888 (IsTopLevel() || GetParent() == NULL
|| GetParent()->IsShownOnScreen());
891 // ----------------------------------------------------------------------------
893 // ----------------------------------------------------------------------------
895 bool wxWindowBase::IsTopLevel() const
900 // ----------------------------------------------------------------------------
901 // reparenting the window
902 // ----------------------------------------------------------------------------
904 void wxWindowBase::AddChild(wxWindowBase
*child
)
906 wxCHECK_RET( child
, wxT("can't add a NULL child") );
908 // this should never happen and it will lead to a crash later if it does
909 // because RemoveChild() will remove only one node from the children list
910 // and the other(s) one(s) will be left with dangling pointers in them
911 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
913 GetChildren().Append((wxWindow
*)child
);
914 child
->SetParent(this);
917 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
919 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
921 GetChildren().DeleteObject((wxWindow
*)child
);
922 child
->SetParent(NULL
);
925 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
927 wxWindow
*oldParent
= GetParent();
928 if ( newParent
== oldParent
)
934 const bool oldEnabledState
= IsEnabled();
936 // unlink this window from the existing parent.
939 oldParent
->RemoveChild(this);
943 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
946 // add it to the new one
949 newParent
->AddChild(this);
953 wxTopLevelWindows
.Append((wxWindow
*)this);
956 // We need to notify window (and its subwindows) if by changing the parent
957 // we also change our enabled/disabled status.
958 const bool newEnabledState
= IsEnabled();
959 if ( newEnabledState
!= oldEnabledState
)
961 NotifyWindowOnEnableChange(newEnabledState
);
967 // ----------------------------------------------------------------------------
968 // event handler stuff
969 // ----------------------------------------------------------------------------
971 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
973 wxEvtHandler
*handlerOld
= GetEventHandler();
975 handler
->SetNextHandler(handlerOld
);
978 GetEventHandler()->SetPreviousHandler(handler
);
980 SetEventHandler(handler
);
983 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
985 wxEvtHandler
*handlerA
= GetEventHandler();
988 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
989 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
992 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
993 SetEventHandler(handlerB
);
998 handlerA
= (wxEvtHandler
*)NULL
;
1005 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
1007 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
1009 wxEvtHandler
*handlerPrev
= NULL
,
1010 *handlerCur
= GetEventHandler();
1011 while ( handlerCur
)
1013 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
1015 if ( handlerCur
== handler
)
1019 handlerPrev
->SetNextHandler(handlerNext
);
1023 SetEventHandler(handlerNext
);
1028 handlerNext
->SetPreviousHandler ( handlerPrev
);
1031 handler
->SetNextHandler(NULL
);
1032 handler
->SetPreviousHandler(NULL
);
1037 handlerPrev
= handlerCur
;
1038 handlerCur
= handlerNext
;
1041 wxFAIL_MSG( _T("where has the event handler gone?") );
1046 bool wxWindowBase::HandleWindowEvent(wxEvent
& event
) const
1048 return GetEventHandler()->SafelyProcessEvent(event
);
1051 // ----------------------------------------------------------------------------
1052 // colours, fonts &c
1053 // ----------------------------------------------------------------------------
1055 void wxWindowBase::InheritAttributes()
1057 const wxWindowBase
* const parent
= GetParent();
1061 // we only inherit attributes which had been explicitly set for the parent
1062 // which ensures that this only happens if the user really wants it and
1063 // not by default which wouldn't make any sense in modern GUIs where the
1064 // controls don't all use the same fonts (nor colours)
1065 if ( parent
->m_inheritFont
&& !m_hasFont
)
1066 SetFont(parent
->GetFont());
1068 // in addition, there is a possibility to explicitly forbid inheriting
1069 // colours at each class level by overriding ShouldInheritColours()
1070 if ( ShouldInheritColours() )
1072 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1073 SetForegroundColour(parent
->GetForegroundColour());
1075 // inheriting (solid) background colour is wrong as it totally breaks
1076 // any kind of themed backgrounds
1078 // instead, the controls should use the same background as their parent
1079 // (ideally by not drawing it at all)
1081 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1082 SetBackgroundColour(parent
->GetBackgroundColour());
1087 /* static */ wxVisualAttributes
1088 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1090 // it is important to return valid values for all attributes from here,
1091 // GetXXX() below rely on this
1092 wxVisualAttributes attrs
;
1093 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1094 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1096 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1097 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1098 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1099 // colour on other platforms.
1101 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1102 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1104 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1109 wxColour
wxWindowBase::GetBackgroundColour() const
1111 if ( !m_backgroundColour
.IsOk() )
1113 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
1115 // get our default background colour
1116 wxColour colBg
= GetDefaultAttributes().colBg
;
1118 // we must return some valid colour to avoid redoing this every time
1119 // and also to avoid surprizing the applications written for older
1120 // wxWidgets versions where GetBackgroundColour() always returned
1121 // something -- so give them something even if it doesn't make sense
1122 // for this window (e.g. it has a themed background)
1124 colBg
= GetClassDefaultAttributes().colBg
;
1129 return m_backgroundColour
;
1132 wxColour
wxWindowBase::GetForegroundColour() const
1134 // logic is the same as above
1135 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1137 wxColour colFg
= GetDefaultAttributes().colFg
;
1139 if ( !colFg
.IsOk() )
1140 colFg
= GetClassDefaultAttributes().colFg
;
1145 return m_foregroundColour
;
1148 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1150 if ( colour
== m_backgroundColour
)
1153 m_hasBgCol
= colour
.IsOk();
1154 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1155 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1157 m_inheritBgCol
= m_hasBgCol
;
1158 m_backgroundColour
= colour
;
1159 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1163 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1165 if (colour
== m_foregroundColour
)
1168 m_hasFgCol
= colour
.IsOk();
1169 m_inheritFgCol
= m_hasFgCol
;
1170 m_foregroundColour
= colour
;
1171 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1175 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1177 // setting an invalid cursor is ok, it means that we don't have any special
1179 if ( m_cursor
.IsSameAs(cursor
) )
1190 wxFont
wxWindowBase::GetFont() const
1192 // logic is the same as in GetBackgroundColour()
1193 if ( !m_font
.IsOk() )
1195 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1197 wxFont font
= GetDefaultAttributes().font
;
1199 font
= GetClassDefaultAttributes().font
;
1207 bool wxWindowBase::SetFont(const wxFont
& font
)
1209 if ( font
== m_font
)
1216 m_hasFont
= font
.IsOk();
1217 m_inheritFont
= m_hasFont
;
1219 InvalidateBestSize();
1226 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1228 m_hasCustomPalette
= true;
1231 // VZ: can anyone explain me what do we do here?
1232 wxWindowDC
d((wxWindow
*) this);
1236 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1238 wxWindow
*win
= (wxWindow
*)this;
1239 while ( win
&& !win
->HasCustomPalette() )
1241 win
= win
->GetParent();
1247 #endif // wxUSE_PALETTE
1250 void wxWindowBase::SetCaret(wxCaret
*caret
)
1261 wxASSERT_MSG( m_caret
->GetWindow() == this,
1262 wxT("caret should be created associated to this window") );
1265 #endif // wxUSE_CARET
1267 #if wxUSE_VALIDATORS
1268 // ----------------------------------------------------------------------------
1270 // ----------------------------------------------------------------------------
1272 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1274 if ( m_windowValidator
)
1275 delete m_windowValidator
;
1277 m_windowValidator
= (wxValidator
*)validator
.Clone();
1279 if ( m_windowValidator
)
1280 m_windowValidator
->SetWindow(this);
1282 #endif // wxUSE_VALIDATORS
1284 // ----------------------------------------------------------------------------
1285 // update region stuff
1286 // ----------------------------------------------------------------------------
1288 wxRect
wxWindowBase::GetUpdateClientRect() const
1290 wxRegion rgnUpdate
= GetUpdateRegion();
1291 rgnUpdate
.Intersect(GetClientRect());
1292 wxRect rectUpdate
= rgnUpdate
.GetBox();
1293 wxPoint ptOrigin
= GetClientAreaOrigin();
1294 rectUpdate
.x
-= ptOrigin
.x
;
1295 rectUpdate
.y
-= ptOrigin
.y
;
1300 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1302 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1305 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1307 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1310 void wxWindowBase::ClearBackground()
1312 // wxGTK uses its own version, no need to add never used code
1314 wxClientDC
dc((wxWindow
*)this);
1315 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1316 dc
.SetBackground(brush
);
1321 // ----------------------------------------------------------------------------
1322 // find child window by id or name
1323 // ----------------------------------------------------------------------------
1325 wxWindow
*wxWindowBase::FindWindow(long id
) const
1327 if ( id
== m_windowId
)
1328 return (wxWindow
*)this;
1330 wxWindowBase
*res
= (wxWindow
*)NULL
;
1331 wxWindowList::compatibility_iterator node
;
1332 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1334 wxWindowBase
*child
= node
->GetData();
1335 res
= child
->FindWindow( id
);
1338 return (wxWindow
*)res
;
1341 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1343 if ( name
== m_windowName
)
1344 return (wxWindow
*)this;
1346 wxWindowBase
*res
= (wxWindow
*)NULL
;
1347 wxWindowList::compatibility_iterator node
;
1348 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1350 wxWindow
*child
= node
->GetData();
1351 res
= child
->FindWindow(name
);
1354 return (wxWindow
*)res
;
1358 // find any window by id or name or label: If parent is non-NULL, look through
1359 // children for a label or title matching the specified string. If NULL, look
1360 // through all top-level windows.
1362 // to avoid duplicating code we reuse the same helper function but with
1363 // different comparators
1365 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1366 const wxString
& label
, long id
);
1369 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1372 return win
->GetLabel() == label
;
1376 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1379 return win
->GetName() == label
;
1383 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1386 return win
->GetId() == id
;
1389 // recursive helper for the FindWindowByXXX() functions
1391 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1392 const wxString
& label
,
1394 wxFindWindowCmp cmp
)
1398 // see if this is the one we're looking for
1399 if ( (*cmp
)(parent
, label
, id
) )
1400 return (wxWindow
*)parent
;
1402 // It wasn't, so check all its children
1403 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1405 node
= node
->GetNext() )
1407 // recursively check each child
1408 wxWindow
*win
= (wxWindow
*)node
->GetData();
1409 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1419 // helper for FindWindowByXXX()
1421 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1422 const wxString
& label
,
1424 wxFindWindowCmp cmp
)
1428 // just check parent and all its children
1429 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1432 // start at very top of wx's windows
1433 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1435 node
= node
->GetNext() )
1437 // recursively check each window & its children
1438 wxWindow
*win
= node
->GetData();
1439 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1449 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1451 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1456 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1458 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1462 // fall back to the label
1463 win
= FindWindowByLabel(title
, parent
);
1471 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1473 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1476 // ----------------------------------------------------------------------------
1477 // dialog oriented functions
1478 // ----------------------------------------------------------------------------
1480 void wxWindowBase::MakeModal(bool modal
)
1482 // Disable all other windows
1485 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1488 wxWindow
*win
= node
->GetData();
1490 win
->Enable(!modal
);
1492 node
= node
->GetNext();
1497 bool wxWindowBase::Validate()
1499 #if wxUSE_VALIDATORS
1500 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1502 wxWindowList::compatibility_iterator node
;
1503 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1505 wxWindowBase
*child
= node
->GetData();
1506 wxValidator
*validator
= child
->GetValidator();
1507 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1512 if ( recurse
&& !child
->Validate() )
1517 #endif // wxUSE_VALIDATORS
1522 bool wxWindowBase::TransferDataToWindow()
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 wxWindowBase
*child
= node
->GetData();
1531 wxValidator
*validator
= child
->GetValidator();
1532 if ( validator
&& !validator
->TransferToWindow() )
1534 wxLogWarning(_("Could not transfer data to window"));
1536 wxLog::FlushActive();
1544 if ( !child
->TransferDataToWindow() )
1546 // warning already given
1551 #endif // wxUSE_VALIDATORS
1556 bool wxWindowBase::TransferDataFromWindow()
1558 #if wxUSE_VALIDATORS
1559 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1561 wxWindowList::compatibility_iterator node
;
1562 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1564 wxWindow
*child
= node
->GetData();
1565 wxValidator
*validator
= child
->GetValidator();
1566 if ( validator
&& !validator
->TransferFromWindow() )
1568 // nop warning here because the application is supposed to give
1569 // one itself - we don't know here what might have gone wrongly
1576 if ( !child
->TransferDataFromWindow() )
1578 // warning already given
1583 #endif // wxUSE_VALIDATORS
1588 void wxWindowBase::InitDialog()
1590 wxInitDialogEvent
event(GetId());
1591 event
.SetEventObject( this );
1592 GetEventHandler()->ProcessEvent(event
);
1595 // ----------------------------------------------------------------------------
1596 // context-sensitive help support
1597 // ----------------------------------------------------------------------------
1601 // associate this help text with this window
1602 void wxWindowBase::SetHelpText(const wxString
& text
)
1604 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1607 helpProvider
->AddHelp(this, text
);
1611 // associate this help text with all windows with the same id as this
1613 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1615 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1618 helpProvider
->AddHelp(GetId(), text
);
1622 // get the help string associated with this window (may be empty)
1623 // default implementation forwards calls to the help provider
1625 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1626 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1629 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1632 text
= helpProvider
->GetHelp(this);
1638 // show help for this window
1639 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1641 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1644 if ( helpProvider
->ShowHelpAtPoint(this, event
.GetPosition(), event
.GetOrigin()) )
1646 // skip the event.Skip() below
1654 #endif // wxUSE_HELP
1656 // ----------------------------------------------------------------------------
1658 // ----------------------------------------------------------------------------
1662 void wxWindowBase::SetToolTip( const wxString
&tip
)
1664 // don't create the new tooltip if we already have one
1667 m_tooltip
->SetTip( tip
);
1671 SetToolTip( new wxToolTip( tip
) );
1674 // setting empty tooltip text does not remove the tooltip any more - use
1675 // SetToolTip((wxToolTip *)NULL) for this
1678 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1680 if ( m_tooltip
!= tooltip
)
1685 m_tooltip
= tooltip
;
1689 #endif // wxUSE_TOOLTIPS
1691 // ----------------------------------------------------------------------------
1692 // constraints and sizers
1693 // ----------------------------------------------------------------------------
1695 #if wxUSE_CONSTRAINTS
1697 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1699 if ( m_constraints
)
1701 UnsetConstraints(m_constraints
);
1702 delete m_constraints
;
1704 m_constraints
= constraints
;
1705 if ( m_constraints
)
1707 // Make sure other windows know they're part of a 'meaningful relationship'
1708 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1709 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1710 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1711 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1712 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1713 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1714 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1715 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1716 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1717 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1718 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1719 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1720 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1721 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1722 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1723 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1727 // This removes any dangling pointers to this window in other windows'
1728 // constraintsInvolvedIn lists.
1729 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1733 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1734 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1735 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1736 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1737 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1738 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1739 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1740 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1741 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1742 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1743 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1744 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1745 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1746 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1747 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1748 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1752 // Back-pointer to other windows we're involved with, so if we delete this
1753 // window, we must delete any constraints we're involved with.
1754 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1756 if ( !m_constraintsInvolvedIn
)
1757 m_constraintsInvolvedIn
= new wxWindowList
;
1758 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1759 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1762 // REMOVE back-pointer to other windows we're involved with.
1763 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1765 if ( m_constraintsInvolvedIn
)
1766 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1769 // Reset any constraints that mention this window
1770 void wxWindowBase::DeleteRelatedConstraints()
1772 if ( m_constraintsInvolvedIn
)
1774 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1777 wxWindow
*win
= node
->GetData();
1778 wxLayoutConstraints
*constr
= win
->GetConstraints();
1780 // Reset any constraints involving this window
1783 constr
->left
.ResetIfWin(this);
1784 constr
->top
.ResetIfWin(this);
1785 constr
->right
.ResetIfWin(this);
1786 constr
->bottom
.ResetIfWin(this);
1787 constr
->width
.ResetIfWin(this);
1788 constr
->height
.ResetIfWin(this);
1789 constr
->centreX
.ResetIfWin(this);
1790 constr
->centreY
.ResetIfWin(this);
1793 wxWindowList::compatibility_iterator next
= node
->GetNext();
1794 m_constraintsInvolvedIn
->Erase(node
);
1798 delete m_constraintsInvolvedIn
;
1799 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1803 #endif // wxUSE_CONSTRAINTS
1805 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1807 if ( sizer
== m_windowSizer
)
1810 if ( m_windowSizer
)
1812 m_windowSizer
->SetContainingWindow(NULL
);
1815 delete m_windowSizer
;
1818 m_windowSizer
= sizer
;
1819 if ( m_windowSizer
)
1821 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
1824 SetAutoLayout(m_windowSizer
!= NULL
);
1827 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1829 SetSizer( sizer
, deleteOld
);
1830 sizer
->SetSizeHints( (wxWindow
*) this );
1834 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1836 // adding a window to a sizer twice is going to result in fatal and
1837 // hard to debug problems later because when deleting the second
1838 // associated wxSizerItem we're going to dereference a dangling
1839 // pointer; so try to detect this as early as possible
1840 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1841 _T("Adding a window to the same sizer twice?") );
1843 m_containingSizer
= sizer
;
1846 #if wxUSE_CONSTRAINTS
1848 void wxWindowBase::SatisfyConstraints()
1850 wxLayoutConstraints
*constr
= GetConstraints();
1851 bool wasOk
= constr
&& constr
->AreSatisfied();
1853 ResetConstraints(); // Mark all constraints as unevaluated
1857 // if we're a top level panel (i.e. our parent is frame/dialog), our
1858 // own constraints will never be satisfied any more unless we do it
1862 while ( noChanges
> 0 )
1864 LayoutPhase1(&noChanges
);
1868 LayoutPhase2(&noChanges
);
1871 #endif // wxUSE_CONSTRAINTS
1873 bool wxWindowBase::Layout()
1875 // If there is a sizer, use it instead of the constraints
1879 GetVirtualSize(&w
, &h
);
1880 GetSizer()->SetDimension( 0, 0, w
, h
);
1882 #if wxUSE_CONSTRAINTS
1885 SatisfyConstraints(); // Find the right constraints values
1886 SetConstraintSizes(); // Recursively set the real window sizes
1893 #if wxUSE_CONSTRAINTS
1895 // first phase of the constraints evaluation: set our own constraints
1896 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1898 wxLayoutConstraints
*constr
= GetConstraints();
1900 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1903 // second phase: set the constraints for our children
1904 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1911 // Layout grand children
1917 // Do a phase of evaluating child constraints
1918 bool wxWindowBase::DoPhase(int phase
)
1920 // the list containing the children for which the constraints are already
1922 wxWindowList succeeded
;
1924 // the max number of iterations we loop before concluding that we can't set
1926 static const int maxIterations
= 500;
1928 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1932 // loop over all children setting their constraints
1933 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1935 node
= node
->GetNext() )
1937 wxWindow
*child
= node
->GetData();
1938 if ( child
->IsTopLevel() )
1940 // top level children are not inside our client area
1944 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1946 // this one is either already ok or nothing we can do about it
1950 int tempNoChanges
= 0;
1951 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1952 : child
->LayoutPhase2(&tempNoChanges
);
1953 noChanges
+= tempNoChanges
;
1957 succeeded
.Append(child
);
1963 // constraints are set
1971 void wxWindowBase::ResetConstraints()
1973 wxLayoutConstraints
*constr
= GetConstraints();
1976 constr
->left
.SetDone(false);
1977 constr
->top
.SetDone(false);
1978 constr
->right
.SetDone(false);
1979 constr
->bottom
.SetDone(false);
1980 constr
->width
.SetDone(false);
1981 constr
->height
.SetDone(false);
1982 constr
->centreX
.SetDone(false);
1983 constr
->centreY
.SetDone(false);
1986 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1989 wxWindow
*win
= node
->GetData();
1990 if ( !win
->IsTopLevel() )
1991 win
->ResetConstraints();
1992 node
= node
->GetNext();
1996 // Need to distinguish between setting the 'fake' size for windows and sizers,
1997 // and setting the real values.
1998 void wxWindowBase::SetConstraintSizes(bool recurse
)
2000 wxLayoutConstraints
*constr
= GetConstraints();
2001 if ( constr
&& constr
->AreSatisfied() )
2003 int x
= constr
->left
.GetValue();
2004 int y
= constr
->top
.GetValue();
2005 int w
= constr
->width
.GetValue();
2006 int h
= constr
->height
.GetValue();
2008 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
2009 (constr
->height
.GetRelationship() != wxAsIs
) )
2011 SetSize(x
, y
, w
, h
);
2015 // If we don't want to resize this window, just move it...
2021 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
2022 GetClassInfo()->GetClassName(),
2028 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2031 wxWindow
*win
= node
->GetData();
2032 if ( !win
->IsTopLevel() && win
->GetConstraints() )
2033 win
->SetConstraintSizes();
2034 node
= node
->GetNext();
2039 // Only set the size/position of the constraint (if any)
2040 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
2042 wxLayoutConstraints
*constr
= GetConstraints();
2045 if ( x
!= wxDefaultCoord
)
2047 constr
->left
.SetValue(x
);
2048 constr
->left
.SetDone(true);
2050 if ( y
!= wxDefaultCoord
)
2052 constr
->top
.SetValue(y
);
2053 constr
->top
.SetDone(true);
2055 if ( w
!= wxDefaultCoord
)
2057 constr
->width
.SetValue(w
);
2058 constr
->width
.SetDone(true);
2060 if ( h
!= wxDefaultCoord
)
2062 constr
->height
.SetValue(h
);
2063 constr
->height
.SetDone(true);
2068 void wxWindowBase::MoveConstraint(int x
, int y
)
2070 wxLayoutConstraints
*constr
= GetConstraints();
2073 if ( x
!= wxDefaultCoord
)
2075 constr
->left
.SetValue(x
);
2076 constr
->left
.SetDone(true);
2078 if ( y
!= wxDefaultCoord
)
2080 constr
->top
.SetValue(y
);
2081 constr
->top
.SetDone(true);
2086 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2088 wxLayoutConstraints
*constr
= GetConstraints();
2091 *w
= constr
->width
.GetValue();
2092 *h
= constr
->height
.GetValue();
2098 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2100 wxLayoutConstraints
*constr
= GetConstraints();
2103 *w
= constr
->width
.GetValue();
2104 *h
= constr
->height
.GetValue();
2107 GetClientSize(w
, h
);
2110 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2112 wxLayoutConstraints
*constr
= GetConstraints();
2115 *x
= constr
->left
.GetValue();
2116 *y
= constr
->top
.GetValue();
2122 #endif // wxUSE_CONSTRAINTS
2124 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2126 // don't do it for the dialogs/frames - they float independently of their
2128 if ( !IsTopLevel() )
2130 wxWindow
*parent
= GetParent();
2131 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2133 wxPoint
pt(parent
->GetClientAreaOrigin());
2140 // ----------------------------------------------------------------------------
2141 // Update UI processing
2142 // ----------------------------------------------------------------------------
2144 void wxWindowBase::UpdateWindowUI(long flags
)
2146 wxUpdateUIEvent
event(GetId());
2147 event
.SetEventObject(this);
2149 if ( GetEventHandler()->ProcessEvent(event
) )
2151 DoUpdateWindowUI(event
);
2154 if (flags
& wxUPDATE_UI_RECURSE
)
2156 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2159 wxWindow
* child
= (wxWindow
*) node
->GetData();
2160 child
->UpdateWindowUI(flags
);
2161 node
= node
->GetNext();
2166 // do the window-specific processing after processing the update event
2167 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2169 if ( event
.GetSetEnabled() )
2170 Enable(event
.GetEnabled());
2172 if ( event
.GetSetShown() )
2173 Show(event
.GetShown());
2176 // ----------------------------------------------------------------------------
2177 // dialog units translations
2178 // ----------------------------------------------------------------------------
2180 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2182 int charWidth
= GetCharWidth();
2183 int charHeight
= GetCharHeight();
2184 wxPoint pt2
= wxDefaultPosition
;
2185 if (pt
.x
!= wxDefaultCoord
)
2186 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2187 if (pt
.y
!= wxDefaultCoord
)
2188 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2193 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2195 int charWidth
= GetCharWidth();
2196 int charHeight
= GetCharHeight();
2197 wxPoint pt2
= wxDefaultPosition
;
2198 if (pt
.x
!= wxDefaultCoord
)
2199 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2200 if (pt
.y
!= wxDefaultCoord
)
2201 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2206 // ----------------------------------------------------------------------------
2208 // ----------------------------------------------------------------------------
2210 // propagate the colour change event to the subwindows
2211 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2213 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2216 // Only propagate to non-top-level windows
2217 wxWindow
*win
= node
->GetData();
2218 if ( !win
->IsTopLevel() )
2220 wxSysColourChangedEvent event2
;
2221 event
.SetEventObject(win
);
2222 win
->GetEventHandler()->ProcessEvent(event2
);
2225 node
= node
->GetNext();
2231 // the default action is to populate dialog with data when it's created,
2232 // and nudge the UI into displaying itself correctly in case
2233 // we've turned the wxUpdateUIEvents frequency down low.
2234 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2236 TransferDataToWindow();
2238 // Update the UI at this point
2239 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2242 // ----------------------------------------------------------------------------
2243 // menu-related functions
2244 // ----------------------------------------------------------------------------
2248 // this is used to pass the id of the selected item from the menu event handler
2249 // to the main function itself
2251 // it's ok to use a global here as there can be at most one popup menu shown at
2253 static int gs_popupMenuSelection
= wxID_NONE
;
2255 void wxWindowBase::InternalOnPopupMenu(wxCommandEvent
& event
)
2257 // store the id in a global variable where we'll retrieve it from later
2258 gs_popupMenuSelection
= event
.GetId();
2262 wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu
& menu
, int x
, int y
)
2264 gs_popupMenuSelection
= wxID_NONE
;
2266 Connect(wxEVT_COMMAND_MENU_SELECTED
,
2267 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2271 PopupMenu(&menu
, x
, y
);
2273 Disconnect(wxEVT_COMMAND_MENU_SELECTED
,
2274 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2278 return gs_popupMenuSelection
;
2281 #endif // wxUSE_MENUS
2283 // methods for drawing the sizers in a visible way
2286 static void DrawSizers(wxWindowBase
*win
);
2288 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2290 wxClientDC
dc((wxWindow
*)win
);
2291 dc
.SetPen(*wxRED_PEN
);
2292 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2293 dc
.DrawRectangle(rect
.Deflate(1, 1));
2296 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2298 const wxSizerItemList
& items
= sizer
->GetChildren();
2299 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2304 wxSizerItem
*item
= *i
;
2305 if ( item
->IsSizer() )
2307 DrawBorder(win
, item
->GetRect().Deflate(2));
2308 DrawSizer(win
, item
->GetSizer());
2310 else if ( item
->IsSpacer() )
2312 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2314 else if ( item
->IsWindow() )
2316 DrawSizers(item
->GetWindow());
2321 static void DrawSizers(wxWindowBase
*win
)
2323 wxSizer
*sizer
= win
->GetSizer();
2326 DrawBorder(win
, win
->GetClientSize());
2327 DrawSizer(win
, sizer
);
2329 else // no sizer, still recurse into the children
2331 const wxWindowList
& children
= win
->GetChildren();
2332 for ( wxWindowList::const_iterator i
= children
.begin(),
2333 end
= children
.end();
2342 #endif // __WXDEBUG__
2344 // process special middle clicks
2345 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2347 if ( event
.ControlDown() && event
.AltDown() )
2350 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2351 if ( event
.ShiftDown() )
2356 #endif // __WXDEBUG__
2357 ::wxInfoMessageBox((wxWindow
*)this);
2365 // ----------------------------------------------------------------------------
2367 // ----------------------------------------------------------------------------
2369 #if wxUSE_ACCESSIBILITY
2370 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2372 if (m_accessible
&& (accessible
!= m_accessible
))
2373 delete m_accessible
;
2374 m_accessible
= accessible
;
2376 m_accessible
->SetWindow((wxWindow
*) this);
2379 // Returns the accessible object, creating if necessary.
2380 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2383 m_accessible
= CreateAccessible();
2384 return m_accessible
;
2387 // Override to create a specific accessible object.
2388 wxAccessible
* wxWindowBase::CreateAccessible()
2390 return new wxWindowAccessible((wxWindow
*) this);
2395 // ----------------------------------------------------------------------------
2396 // list classes implementation
2397 // ----------------------------------------------------------------------------
2401 #include "wx/listimpl.cpp"
2402 WX_DEFINE_LIST(wxWindowList
)
2406 void wxWindowListNode::DeleteData()
2408 delete (wxWindow
*)GetData();
2411 #endif // wxUSE_STL/!wxUSE_STL
2413 // ----------------------------------------------------------------------------
2415 // ----------------------------------------------------------------------------
2417 wxBorder
wxWindowBase::GetBorder(long flags
) const
2419 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2420 if ( border
== wxBORDER_DEFAULT
)
2422 border
= GetDefaultBorder();
2424 else if ( border
== wxBORDER_THEME
)
2426 border
= GetDefaultBorderForControl();
2432 wxBorder
wxWindowBase::GetDefaultBorder() const
2434 return wxBORDER_NONE
;
2437 // ----------------------------------------------------------------------------
2439 // ----------------------------------------------------------------------------
2441 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2443 // here we just check if the point is inside the window or not
2445 // check the top and left border first
2446 bool outside
= x
< 0 || y
< 0;
2449 // check the right and bottom borders too
2450 wxSize size
= GetSize();
2451 outside
= x
>= size
.x
|| y
>= size
.y
;
2454 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2457 // ----------------------------------------------------------------------------
2459 // ----------------------------------------------------------------------------
2461 struct WXDLLEXPORT wxWindowNext
2465 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2466 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2467 bool wxWindowBase::ms_winCaptureChanging
= false;
2469 void wxWindowBase::CaptureMouse()
2471 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2473 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2475 ms_winCaptureChanging
= true;
2477 wxWindow
*winOld
= GetCapture();
2480 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2483 wxWindowNext
*item
= new wxWindowNext
;
2485 item
->next
= ms_winCaptureNext
;
2486 ms_winCaptureNext
= item
;
2488 //else: no mouse capture to save
2491 ms_winCaptureCurrent
= (wxWindow
*)this;
2493 ms_winCaptureChanging
= false;
2496 void wxWindowBase::ReleaseMouse()
2498 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2500 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2502 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2504 ms_winCaptureChanging
= true;
2507 ms_winCaptureCurrent
= NULL
;
2509 if ( ms_winCaptureNext
)
2511 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2512 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2514 wxWindowNext
*item
= ms_winCaptureNext
;
2515 ms_winCaptureNext
= item
->next
;
2518 //else: stack is empty, no previous capture
2520 ms_winCaptureChanging
= false;
2522 wxLogTrace(_T("mousecapture"),
2523 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2524 wx_static_cast(void*, GetCapture()));
2527 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2529 wxMouseCaptureLostEvent
event(win
->GetId());
2530 event
.SetEventObject(win
);
2531 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2533 // windows must handle this event, otherwise the app wouldn't behave
2534 // correctly if it loses capture unexpectedly; see the discussion here:
2535 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
2536 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
2537 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2542 void wxWindowBase::NotifyCaptureLost()
2544 // don't do anything if capture lost was expected, i.e. resulted from
2545 // a wx call to ReleaseMouse or CaptureMouse:
2546 if ( ms_winCaptureChanging
)
2549 // if the capture was lost unexpectedly, notify every window that has
2550 // capture (on stack or current) about it and clear the stack:
2552 if ( ms_winCaptureCurrent
)
2554 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2555 ms_winCaptureCurrent
= NULL
;
2558 while ( ms_winCaptureNext
)
2560 wxWindowNext
*item
= ms_winCaptureNext
;
2561 ms_winCaptureNext
= item
->next
;
2563 DoNotifyWindowAboutCaptureLost(item
->win
);
2572 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2573 int WXUNUSED(modifiers
),
2574 int WXUNUSED(keycode
))
2580 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2586 #endif // wxUSE_HOTKEY
2588 // ----------------------------------------------------------------------------
2590 // ----------------------------------------------------------------------------
2592 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2594 #if wxUSE_VALIDATORS
2595 // Can only use the validator of the window which
2596 // is receiving the event
2597 if ( event
.GetEventObject() == this )
2599 wxValidator
*validator
= GetValidator();
2600 if ( validator
&& validator
->ProcessEvent(event
) )
2605 #endif // wxUSE_VALIDATORS
2610 bool wxWindowBase::TryParent(wxEvent
& event
)
2612 // carry on up the parent-child hierarchy if the propagation count hasn't
2614 if ( event
.ShouldPropagate() )
2616 // honour the requests to stop propagation at this window: this is
2617 // used by the dialogs, for example, to prevent processing the events
2618 // from the dialog controls in the parent frame which rarely, if ever,
2620 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2622 wxWindow
*parent
= GetParent();
2623 if ( parent
&& !parent
->IsBeingDeleted() )
2625 wxPropagateOnce
propagateOnce(event
);
2627 return parent
->GetEventHandler()->ProcessEvent(event
);
2632 return wxEvtHandler::TryParent(event
);
2635 // ----------------------------------------------------------------------------
2636 // window relationships
2637 // ----------------------------------------------------------------------------
2639 wxWindow
*wxWindowBase::DoGetSibling(WindowOrder order
) const
2641 wxCHECK_MSG( GetParent(), NULL
,
2642 _T("GetPrev/NextSibling() don't work for TLWs!") );
2644 wxWindowList
& siblings
= GetParent()->GetChildren();
2645 wxWindowList::compatibility_iterator i
= siblings
.Find((wxWindow
*)this);
2646 wxCHECK_MSG( i
, NULL
, _T("window not a child of its parent?") );
2648 if ( order
== OrderBefore
)
2649 i
= i
->GetPrevious();
2653 return i
? i
->GetData() : NULL
;
2656 // ----------------------------------------------------------------------------
2657 // keyboard navigation
2658 // ----------------------------------------------------------------------------
2660 // Navigates in the specified direction inside this window
2661 bool wxWindowBase::DoNavigateIn(int flags
)
2663 #ifdef wxHAS_NATIVE_TAB_TRAVERSAL
2664 // native code doesn't process our wxNavigationKeyEvents anyhow
2667 #else // !wxHAS_NATIVE_TAB_TRAVERSAL
2668 wxNavigationKeyEvent eventNav
;
2669 eventNav
.SetFlags(flags
);
2670 eventNav
.SetEventObject(FindFocus());
2671 return GetEventHandler()->ProcessEvent(eventNav
);
2672 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
2675 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, WindowOrder move
)
2677 // check that we're not a top level window
2678 wxCHECK_RET( GetParent(),
2679 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2681 // detect the special case when we have nothing to do anyhow and when the
2682 // code below wouldn't work
2686 // find the target window in the siblings list
2687 wxWindowList
& siblings
= GetParent()->GetChildren();
2688 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2689 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2691 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2692 // can't just move the node around
2693 wxWindow
*self
= (wxWindow
*)this;
2694 siblings
.DeleteObject(self
);
2695 if ( move
== OrderAfter
)
2702 siblings
.Insert(i
, self
);
2704 else // OrderAfter and win was the last sibling
2706 siblings
.Append(self
);
2710 // ----------------------------------------------------------------------------
2712 // ----------------------------------------------------------------------------
2714 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2716 wxWindowBase
*win
= DoFindFocus();
2717 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2720 // ----------------------------------------------------------------------------
2722 // ----------------------------------------------------------------------------
2724 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2726 while ( win
&& !win
->IsTopLevel() )
2727 win
= win
->GetParent();
2732 #if wxUSE_ACCESSIBILITY
2733 // ----------------------------------------------------------------------------
2734 // accessible object for windows
2735 // ----------------------------------------------------------------------------
2737 // Can return either a child object, or an integer
2738 // representing the child element, starting from 1.
2739 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2741 wxASSERT( GetWindow() != NULL
);
2745 return wxACC_NOT_IMPLEMENTED
;
2748 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2749 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2751 wxASSERT( GetWindow() != NULL
);
2755 wxWindow
* win
= NULL
;
2762 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2764 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2771 rect
= win
->GetRect();
2772 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2773 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2777 return wxACC_NOT_IMPLEMENTED
;
2780 // Navigates from fromId to toId/toObject.
2781 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2782 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2784 wxASSERT( GetWindow() != NULL
);
2790 case wxNAVDIR_FIRSTCHILD
:
2792 if (GetWindow()->GetChildren().GetCount() == 0)
2794 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2795 *toObject
= childWindow
->GetOrCreateAccessible();
2799 case wxNAVDIR_LASTCHILD
:
2801 if (GetWindow()->GetChildren().GetCount() == 0)
2803 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2804 *toObject
= childWindow
->GetOrCreateAccessible();
2808 case wxNAVDIR_RIGHT
:
2812 wxWindowList::compatibility_iterator node
=
2813 wxWindowList::compatibility_iterator();
2816 // Can't navigate to sibling of this window
2817 // if we're a top-level window.
2818 if (!GetWindow()->GetParent())
2819 return wxACC_NOT_IMPLEMENTED
;
2821 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2825 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2826 node
= GetWindow()->GetChildren().Item(fromId
-1);
2829 if (node
&& node
->GetNext())
2831 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2832 *toObject
= nextWindow
->GetOrCreateAccessible();
2840 case wxNAVDIR_PREVIOUS
:
2842 wxWindowList::compatibility_iterator node
=
2843 wxWindowList::compatibility_iterator();
2846 // Can't navigate to sibling of this window
2847 // if we're a top-level window.
2848 if (!GetWindow()->GetParent())
2849 return wxACC_NOT_IMPLEMENTED
;
2851 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2855 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2856 node
= GetWindow()->GetChildren().Item(fromId
-1);
2859 if (node
&& node
->GetPrevious())
2861 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2862 *toObject
= previousWindow
->GetOrCreateAccessible();
2870 return wxACC_NOT_IMPLEMENTED
;
2873 // Gets the name of the specified object.
2874 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2876 wxASSERT( GetWindow() != NULL
);
2882 // If a child, leave wxWidgets to call the function on the actual
2885 return wxACC_NOT_IMPLEMENTED
;
2887 // This will eventually be replaced by specialised
2888 // accessible classes, one for each kind of wxWidgets
2889 // control or window.
2891 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2892 title
= ((wxButton
*) GetWindow())->GetLabel();
2895 title
= GetWindow()->GetName();
2903 return wxACC_NOT_IMPLEMENTED
;
2906 // Gets the number of children.
2907 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2909 wxASSERT( GetWindow() != NULL
);
2913 *childId
= (int) GetWindow()->GetChildren().GetCount();
2917 // Gets the specified child (starting from 1).
2918 // If *child is NULL and return value is wxACC_OK,
2919 // this means that the child is a simple element and
2920 // not an accessible object.
2921 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2923 wxASSERT( GetWindow() != NULL
);
2933 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2936 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2937 *child
= childWindow
->GetOrCreateAccessible();
2944 // Gets the parent, or NULL.
2945 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2947 wxASSERT( GetWindow() != NULL
);
2951 wxWindow
* parentWindow
= GetWindow()->GetParent();
2959 *parent
= parentWindow
->GetOrCreateAccessible();
2967 // Performs the default action. childId is 0 (the action for this object)
2968 // or > 0 (the action for a child).
2969 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2970 // window (e.g. an edit control).
2971 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2973 wxASSERT( GetWindow() != NULL
);
2977 return wxACC_NOT_IMPLEMENTED
;
2980 // Gets the default action for this object (0) or > 0 (the action for a child).
2981 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2982 // string if there is no action.
2983 // The retrieved string describes the action that is performed on an object,
2984 // not what the object does as a result. For example, a toolbar button that prints
2985 // a document has a default action of "Press" rather than "Prints the current document."
2986 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2988 wxASSERT( GetWindow() != NULL
);
2992 return wxACC_NOT_IMPLEMENTED
;
2995 // Returns the description for this object or a child.
2996 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2998 wxASSERT( GetWindow() != NULL
);
3002 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3008 return wxACC_NOT_IMPLEMENTED
;
3011 // Returns help text for this object or a child, similar to tooltip text.
3012 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
3014 wxASSERT( GetWindow() != NULL
);
3018 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3024 return wxACC_NOT_IMPLEMENTED
;
3027 // Returns the keyboard shortcut for this object or child.
3028 // Return e.g. ALT+K
3029 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
3031 wxASSERT( GetWindow() != NULL
);
3035 return wxACC_NOT_IMPLEMENTED
;
3038 // Returns a role constant.
3039 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
3041 wxASSERT( GetWindow() != NULL
);
3045 // If a child, leave wxWidgets to call the function on the actual
3048 return wxACC_NOT_IMPLEMENTED
;
3050 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3051 return wxACC_NOT_IMPLEMENTED
;
3053 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3054 return wxACC_NOT_IMPLEMENTED
;
3057 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3058 return wxACC_NOT_IMPLEMENTED
;
3061 //*role = wxROLE_SYSTEM_CLIENT;
3062 *role
= wxROLE_SYSTEM_CLIENT
;
3066 return wxACC_NOT_IMPLEMENTED
;
3070 // Returns a state constant.
3071 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
3073 wxASSERT( GetWindow() != NULL
);
3077 // If a child, leave wxWidgets to call the function on the actual
3080 return wxACC_NOT_IMPLEMENTED
;
3082 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3083 return wxACC_NOT_IMPLEMENTED
;
3086 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3087 return wxACC_NOT_IMPLEMENTED
;
3090 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3091 return wxACC_NOT_IMPLEMENTED
;
3098 return wxACC_NOT_IMPLEMENTED
;
3102 // Returns a localized string representing the value for the object
3104 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3106 wxASSERT( GetWindow() != NULL
);
3110 return wxACC_NOT_IMPLEMENTED
;
3113 // Selects the object or child.
3114 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3116 wxASSERT( GetWindow() != NULL
);
3120 return wxACC_NOT_IMPLEMENTED
;
3123 // Gets the window with the keyboard focus.
3124 // If childId is 0 and child is NULL, no object in
3125 // this subhierarchy has the focus.
3126 // If this object has the focus, child should be 'this'.
3127 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3129 wxASSERT( GetWindow() != NULL
);
3133 return wxACC_NOT_IMPLEMENTED
;
3137 // Gets a variant representing the selected children
3139 // Acceptable values:
3140 // - a null variant (IsNull() returns true)
3141 // - a list variant (GetType() == wxT("list")
3142 // - an integer representing the selected child element,
3143 // or 0 if this object is selected (GetType() == wxT("long")
3144 // - a "void*" pointer to a wxAccessible child object
3145 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3147 wxASSERT( GetWindow() != NULL
);
3151 return wxACC_NOT_IMPLEMENTED
;
3153 #endif // wxUSE_VARIANT
3155 #endif // wxUSE_ACCESSIBILITY
3157 // ----------------------------------------------------------------------------
3159 // ----------------------------------------------------------------------------
3162 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3164 wxCoord widthTotal
) const
3166 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3168 x
= widthTotal
- x
- width
;
3174 // ----------------------------------------------------------------------------
3175 // Window (and menu items) identifiers management
3176 // ----------------------------------------------------------------------------
3181 // this array contains, in packed form, the "in use" flags for the entire
3182 // auto-generated ids range: N-th element of the array contains the flags for
3183 // ids in [wxID_AUTO_LOWEST + 8*N, wxID_AUTO_LOWEST + 8*N + 7] range
3185 // initially no ids are in use and we allocate them consecutively, but after we
3186 // exhaust the entire range, we wrap around and reuse the ids freed in the
3188 wxByte gs_autoIdsInUse
[(wxID_AUTO_HIGHEST
- wxID_AUTO_LOWEST
+ 1)/8 + 1] = { 0 };
3190 // this is an optimization used until we wrap around wxID_AUTO_HIGHEST: if this
3191 // value is < wxID_AUTO_HIGHEST we know that we haven't wrapped yet and so can
3192 // allocate the ids simply by incrementing it
3193 static wxWindowID gs_nextControlId
= wxID_AUTO_LOWEST
;
3195 void MarkAutoIdUsed(wxWindowID id
)
3197 id
-= wxID_AUTO_LOWEST
;
3199 const int theByte
= id
/ 8;
3200 const int theBit
= id
% 8;
3202 gs_autoIdsInUse
[theByte
] |= 1 << theBit
;
3205 void FreeAutoId(wxWindowID id
)
3207 id
-= wxID_AUTO_LOWEST
;
3209 const int theByte
= id
/ 8;
3210 const int theBit
= id
% 8;
3212 gs_autoIdsInUse
[theByte
] &= ~(1 << theBit
);
3215 bool IsAutoIdInUse(wxWindowID id
)
3217 id
-= wxID_AUTO_LOWEST
;
3219 const int theByte
= id
/ 8;
3220 const int theBit
= id
% 8;
3222 return (gs_autoIdsInUse
[theByte
] & (1 << theBit
)) != 0;
3225 } // anonymous namespace
3229 bool wxWindowBase::IsAutoGeneratedId(wxWindowID id
)
3231 if ( id
< wxID_AUTO_LOWEST
|| id
> wxID_AUTO_HIGHEST
)
3234 // we shouldn't have any stray ids in this range
3235 wxASSERT_MSG( IsAutoIdInUse(id
), "unused automatically generated id?" );
3240 wxWindowID
wxWindowBase::NewControlId(int count
)
3242 wxASSERT_MSG( count
> 0, "can't allocate less than 1 id" );
3244 if ( gs_nextControlId
+ count
- 1 <= wxID_AUTO_HIGHEST
)
3246 // we haven't wrapped yet, so we can just grab the next count ids
3247 wxWindowID id
= gs_nextControlId
;
3250 MarkAutoIdUsed(gs_nextControlId
++);
3254 else // we've already wrapped or are now going to
3256 // brute-force search for the id values
3258 // number of consecutive free ids found so far
3261 for ( wxWindowID id
= wxID_AUTO_LOWEST
; id
<= wxID_AUTO_HIGHEST
; id
++ )
3263 if ( !IsAutoIdInUse(id
) )
3265 // found another consecutive available id
3267 if ( found
== count
)
3269 // mark all count consecutive free ids we found as being in
3270 // use now and rewind back to the start of available range
3273 MarkAutoIdUsed(id
--);
3278 else // this id is in use
3280 // reset the number of consecutive free values found
3286 // if we get here, there are not enough consecutive free ids
3290 void wxWindowBase::ReleaseControlId(wxWindowID id
)
3292 wxCHECK_RET( IsAutoGeneratedId(id
), "can't release non auto-generated id" );