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"
50 #if wxUSE_DRAG_AND_DROP
52 #endif // wxUSE_DRAG_AND_DROP
54 #if wxUSE_ACCESSIBILITY
55 #include "wx/access.h"
59 #include "wx/cshelp.h"
63 #include "wx/tooltip.h"
64 #endif // wxUSE_TOOLTIPS
70 #if wxUSE_SYSTEM_OPTIONS
71 #include "wx/sysopt.h"
74 // For reporting compile- and runtime version of GTK+ in the ctrl+alt+mclick dialog.
75 // The gtk includes don't pull any other headers in, at least not on my system - MR
78 #include <gtk/gtkversion.h>
80 #include <gtk/gtkfeatures.h>
84 #include "wx/platinfo.h"
87 WXDLLIMPEXP_DATA_CORE(wxWindowList
) wxTopLevelWindows
;
91 wxMenu
*wxCurrentPopupMenu
= NULL
;
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
99 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
101 // ----------------------------------------------------------------------------
103 // ----------------------------------------------------------------------------
105 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
106 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
107 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
108 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
111 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
116 // ============================================================================
117 // implementation of the common functionality of the wxWindow class
118 // ============================================================================
120 // ----------------------------------------------------------------------------
122 // ----------------------------------------------------------------------------
124 // the default initialization
125 wxWindowBase::wxWindowBase()
127 // no window yet, no parent nor children
128 m_parent
= (wxWindow
*)NULL
;
129 m_windowId
= wxID_ANY
;
131 // no constraints on the minimal window size
133 m_maxWidth
= wxDefaultCoord
;
135 m_maxHeight
= wxDefaultCoord
;
137 // invalidiated cache value
138 m_bestSizeCache
= wxDefaultSize
;
140 // window are created enabled and visible by default
144 // the default event handler is just this window
145 m_eventHandler
= this;
149 m_windowValidator
= (wxValidator
*) NULL
;
150 #endif // wxUSE_VALIDATORS
152 // the colours/fonts are default for now, so leave m_font,
153 // m_backgroundColour and m_foregroundColour uninitialized and set those
159 m_inheritFont
= false;
165 m_backgroundStyle
= wxBG_STYLE_SYSTEM
;
167 #if wxUSE_CONSTRAINTS
168 // no constraints whatsoever
169 m_constraints
= (wxLayoutConstraints
*) NULL
;
170 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
171 #endif // wxUSE_CONSTRAINTS
173 m_windowSizer
= (wxSizer
*) NULL
;
174 m_containingSizer
= (wxSizer
*) NULL
;
175 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
;
202 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
203 #if wxUSE_SYSTEM_OPTIONS
204 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
206 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
210 // Whether we're using the current theme for this window (wxGTK only for now)
211 m_themeEnabled
= false;
213 // VZ: this one shouldn't exist...
214 m_isBeingDeleted
= false;
217 // common part of window creation process
218 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
220 const wxPoint
& WXUNUSED(pos
),
221 const wxSize
& WXUNUSED(size
),
223 const wxValidator
& wxVALIDATOR_PARAM(validator
),
224 const wxString
& name
)
227 // wxGTK doesn't allow to create controls with static box as the parent so
228 // this will result in a crash when the program is ported to wxGTK so warn
231 // if you get this assert, the correct solution is to create the controls
232 // as siblings of the static box
233 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
234 _T("wxStaticBox can't be used as a window parent!") );
235 #endif // wxUSE_STATBOX
237 // ids are limited to 16 bits under MSW so if you care about portability,
238 // it's not a good idea to use ids out of this range (and negative ids are
239 // reserved for wxWidgets own usage)
240 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767) ||
241 (id
>= wxID_AUTO_LOWEST
&& id
<= wxID_AUTO_HIGHEST
),
242 _T("invalid id value") );
244 // generate a new id if the user doesn't care about it
245 if ( id
== wxID_ANY
)
247 m_windowId
= NewControlId();
249 // remember to call ReleaseControlId() when this window is destroyed
252 else // valid id specified
257 // don't use SetWindowStyleFlag() here, this function should only be called
258 // to change the flag after creation as it tries to reflect the changes in
259 // flags by updating the window dynamically and we don't need this here
260 m_windowStyle
= style
;
266 SetValidator(validator
);
267 #endif // wxUSE_VALIDATORS
269 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
270 // have it too - like this it's possible to set it only in the top level
271 // dialog/frame and all children will inherit it by defult
272 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
274 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
280 bool wxWindowBase::ToggleWindowStyle(int flag
)
282 wxASSERT_MSG( flag
, _T("flags with 0 value can't be toggled") );
285 long style
= GetWindowStyleFlag();
291 else // currently off
297 SetWindowStyleFlag(style
);
302 // ----------------------------------------------------------------------------
304 // ----------------------------------------------------------------------------
307 wxWindowBase::~wxWindowBase()
309 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
311 // mark the id as unused if we allocated it for this control
313 ReleaseControlId(m_windowId
);
315 // FIXME if these 2 cases result from programming errors in the user code
316 // we should probably assert here instead of silently fixing them
318 // Just in case the window has been Closed, but we're then deleting
319 // immediately: don't leave dangling pointers.
320 wxPendingDelete
.DeleteObject(this);
322 // Just in case we've loaded a top-level window via LoadNativeDialog but
323 // we weren't a dialog class
324 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
326 // The associated popup menu can still be alive, disassociate from it in
328 if ( wxCurrentPopupMenu
&& wxCurrentPopupMenu
->GetInvokingWindow() == this )
329 wxCurrentPopupMenu
->SetInvokingWindow(NULL
);
331 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
333 // notify the parent about this window destruction
335 m_parent
->RemoveChild(this);
339 #endif // wxUSE_CARET
342 delete m_windowValidator
;
343 #endif // wxUSE_VALIDATORS
345 #if wxUSE_CONSTRAINTS
346 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
347 // at deleted windows as they delete themselves.
348 DeleteRelatedConstraints();
352 // This removes any dangling pointers to this window in other windows'
353 // constraintsInvolvedIn lists.
354 UnsetConstraints(m_constraints
);
355 delete m_constraints
;
356 m_constraints
= NULL
;
358 #endif // wxUSE_CONSTRAINTS
360 if ( m_containingSizer
)
361 m_containingSizer
->Detach( (wxWindow
*)this );
363 delete m_windowSizer
;
365 #if wxUSE_DRAG_AND_DROP
367 #endif // wxUSE_DRAG_AND_DROP
371 #endif // wxUSE_TOOLTIPS
373 #if wxUSE_ACCESSIBILITY
378 void wxWindowBase::SendDestroyEvent()
380 wxWindowDestroyEvent event
;
381 event
.SetEventObject(this);
382 event
.SetId(GetId());
383 GetEventHandler()->ProcessEvent(event
);
386 bool wxWindowBase::Destroy()
393 bool wxWindowBase::Close(bool force
)
395 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
396 event
.SetEventObject(this);
397 event
.SetCanVeto(!force
);
399 // return false if window wasn't closed because the application vetoed the
401 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
404 bool wxWindowBase::DestroyChildren()
406 wxWindowList::compatibility_iterator node
;
409 // we iterate until the list becomes empty
410 node
= GetChildren().GetFirst();
414 wxWindow
*child
= node
->GetData();
416 // note that we really want to call delete and not ->Destroy() here
417 // because we want to delete the child immediately, before we are
418 // deleted, and delayed deletion would result in problems as our (top
419 // level) child could outlive its parent
422 wxASSERT_MSG( !GetChildren().Find(child
),
423 wxT("child didn't remove itself using RemoveChild()") );
429 // ----------------------------------------------------------------------------
430 // size/position related methods
431 // ----------------------------------------------------------------------------
433 // centre the window with respect to its parent in either (or both) directions
434 void wxWindowBase::DoCentre(int dir
)
436 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
437 _T("this method only implements centering child windows") );
439 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
442 // fits the window around the children
443 void wxWindowBase::Fit()
445 if ( !GetChildren().empty() )
447 SetSize(GetBestSize());
449 //else: do nothing if we have no children
452 // fits virtual size (ie. scrolled area etc.) around children
453 void wxWindowBase::FitInside()
455 if ( GetChildren().GetCount() > 0 )
457 SetVirtualSize( GetBestVirtualSize() );
461 // On Mac, scrollbars are explicitly children.
463 static bool wxHasRealChildren(const wxWindowBase
* win
)
465 int realChildCount
= 0;
467 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
469 node
= node
->GetNext() )
471 wxWindow
*win
= node
->GetData();
472 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
475 return (realChildCount
> 0);
479 void wxWindowBase::InvalidateBestSize()
481 m_bestSizeCache
= wxDefaultSize
;
483 // parent's best size calculation may depend on its children's
484 // as long as child window we are in is not top level window itself
485 // (because the TLW size is never resized automatically)
486 // so let's invalidate it as well to be safe:
487 if (m_parent
&& !IsTopLevel())
488 m_parent
->InvalidateBestSize();
491 // return the size best suited for the current window
492 wxSize
wxWindowBase::DoGetBestSize() const
498 best
= m_windowSizer
->GetMinSize();
500 #if wxUSE_CONSTRAINTS
501 else if ( m_constraints
)
503 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
505 // our minimal acceptable size is such that all our windows fit inside
509 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
511 node
= node
->GetNext() )
513 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
516 // it's not normal that we have an unconstrained child, but
517 // what can we do about it?
521 int x
= c
->right
.GetValue(),
522 y
= c
->bottom
.GetValue();
530 // TODO: we must calculate the overlaps somehow, otherwise we
531 // will never return a size bigger than the current one :-(
534 best
= wxSize(maxX
, maxY
);
536 #endif // wxUSE_CONSTRAINTS
537 else if ( !GetChildren().empty()
539 && wxHasRealChildren(this)
543 // our minimal acceptable size is such that all our visible child
544 // windows fit inside
548 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
550 node
= node
->GetNext() )
552 wxWindow
*win
= node
->GetData();
553 if ( win
->IsTopLevel()
556 || wxDynamicCast(win
, wxStatusBar
)
557 #endif // wxUSE_STATUSBAR
560 // dialogs and frames lie in different top level windows -
561 // don't deal with them here; as for the status bars, they
562 // don't lie in the client area at all
567 win
->GetPosition(&wx
, &wy
);
569 // if the window hadn't been positioned yet, assume that it is in
571 if ( wx
== wxDefaultCoord
)
573 if ( wy
== wxDefaultCoord
)
576 win
->GetSize(&ww
, &wh
);
577 if ( wx
+ ww
> maxX
)
579 if ( wy
+ wh
> maxY
)
583 best
= wxSize(maxX
, maxY
);
585 else // ! has children
587 // for a generic window there is no natural best size so, if the
588 // minimal size is not set, use the current size but take care to
589 // remember it as minimal size for the next time because our best size
590 // should be constant: otherwise we could get into a situation when the
591 // window is initially at some size, then expanded to a larger size and
592 // then, when the containing window is shrunk back (because our initial
593 // best size had been used for computing the parent min size), we can't
594 // be shrunk back any more because our best size is now bigger
595 wxSize size
= GetMinSize();
596 if ( !size
.IsFullySpecified() )
598 size
.SetDefaults(GetSize());
599 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
602 // return as-is, unadjusted by the client size difference.
606 // Add any difference between size and client size
607 wxSize diff
= GetSize() - GetClientSize();
608 best
.x
+= wxMax(0, diff
.x
);
609 best
.y
+= wxMax(0, diff
.y
);
614 // helper of GetWindowBorderSize(): as many ports don't implement support for
615 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
616 // fallbacks in this case
617 static int wxGetMetricOrDefault(wxSystemMetric what
)
619 int rc
= wxSystemSettings::GetMetric(what
);
626 // 2D border is by default 1 pixel wide
632 // 3D borders are by default 2 pixels
637 wxFAIL_MSG( _T("unexpected wxGetMetricOrDefault() argument") );
645 wxSize
wxWindowBase::GetWindowBorderSize() const
649 switch ( GetBorder() )
652 // nothing to do, size is already (0, 0)
655 case wxBORDER_SIMPLE
:
656 case wxBORDER_STATIC
:
657 size
.x
= wxGetMetricOrDefault(wxSYS_BORDER_X
);
658 size
.y
= wxGetMetricOrDefault(wxSYS_BORDER_Y
);
661 case wxBORDER_SUNKEN
:
662 case wxBORDER_RAISED
:
663 size
.x
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X
),
664 wxGetMetricOrDefault(wxSYS_BORDER_X
));
665 size
.y
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y
),
666 wxGetMetricOrDefault(wxSYS_BORDER_Y
));
669 case wxBORDER_DOUBLE
:
670 size
.x
= wxGetMetricOrDefault(wxSYS_EDGE_X
) +
671 wxGetMetricOrDefault(wxSYS_BORDER_X
);
672 size
.y
= wxGetMetricOrDefault(wxSYS_EDGE_Y
) +
673 wxGetMetricOrDefault(wxSYS_BORDER_Y
);
677 wxFAIL_MSG(_T("Unknown border style."));
681 // we have borders on both sides
685 wxSize
wxWindowBase::GetEffectiveMinSize() const
687 // merge the best size with the min size, giving priority to the min size
688 wxSize min
= GetMinSize();
689 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
691 wxSize best
= GetBestSize();
692 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
693 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
699 void wxWindowBase::SetInitialSize(const wxSize
& size
)
701 // Set the min size to the size passed in. This will usually either be
702 // wxDefaultSize or the size passed to this window's ctor/Create function.
705 // Merge the size with the best size if needed
706 wxSize best
= GetEffectiveMinSize();
708 // If the current size doesn't match then change it
709 if (GetSize() != best
)
714 // by default the origin is not shifted
715 wxPoint
wxWindowBase::GetClientAreaOrigin() const
720 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
722 if ( m_windowVariant
!= variant
)
724 m_windowVariant
= variant
;
726 DoSetWindowVariant(variant
);
730 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
732 // adjust the font height to correspond to our new variant (notice that
733 // we're only called if something really changed)
734 wxFont font
= GetFont();
735 int size
= font
.GetPointSize();
738 case wxWINDOW_VARIANT_NORMAL
:
741 case wxWINDOW_VARIANT_SMALL
:
746 case wxWINDOW_VARIANT_MINI
:
751 case wxWINDOW_VARIANT_LARGE
:
757 wxFAIL_MSG(_T("unexpected window variant"));
761 font
.SetPointSize(size
);
765 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
767 int WXUNUSED(incW
), int WXUNUSED(incH
) )
769 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
770 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
771 _T("min width/height must be less than max width/height!") );
780 #if WXWIN_COMPATIBILITY_2_8
781 void wxWindowBase::SetVirtualSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
),
782 int WXUNUSED(maxW
), int WXUNUSED(maxH
))
786 void wxWindowBase::SetVirtualSizeHints(const wxSize
& WXUNUSED(minsize
),
787 const wxSize
& WXUNUSED(maxsize
))
790 #endif // WXWIN_COMPATIBILITY_2_8
792 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
794 m_virtualSize
= wxSize(x
, y
);
797 wxSize
wxWindowBase::DoGetVirtualSize() const
799 // we should use the entire client area so if it is greater than our
800 // virtual size, expand it to fit (otherwise if the window is big enough we
801 // wouldn't be using parts of it)
802 wxSize size
= GetClientSize();
803 if ( m_virtualSize
.x
> size
.x
)
804 size
.x
= m_virtualSize
.x
;
806 if ( m_virtualSize
.y
>= size
.y
)
807 size
.y
= m_virtualSize
.y
;
812 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
814 // screen position is the same as (0, 0) in client coords for non TLWs (and
815 // TLWs override this method)
821 ClientToScreen(x
, y
);
824 // ----------------------------------------------------------------------------
825 // show/hide/enable/disable the window
826 // ----------------------------------------------------------------------------
828 bool wxWindowBase::Show(bool show
)
830 if ( show
!= m_isShown
)
842 bool wxWindowBase::IsEnabled() const
844 return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
847 void wxWindowBase::NotifyWindowOnEnableChange(bool enabled
)
849 #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
851 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
855 // If we are top-level then the logic doesn't apply - otherwise
856 // showing a modal dialog would result in total greying out (and ungreying
857 // out later) of everything which would be really ugly
861 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
863 node
= node
->GetNext() )
865 wxWindowBase
* const child
= node
->GetData();
866 if ( !child
->IsTopLevel() && child
->IsThisEnabled() )
867 child
->NotifyWindowOnEnableChange(enabled
);
871 bool wxWindowBase::Enable(bool enable
)
873 if ( enable
== IsThisEnabled() )
876 m_isEnabled
= enable
;
878 #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
880 #else // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
881 wxWindowBase
* const parent
= GetParent();
882 if( !IsTopLevel() && parent
&& !parent
->IsEnabled() )
886 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
888 NotifyWindowOnEnableChange(enable
);
893 bool wxWindowBase::IsShownOnScreen() const
895 // A window is shown on screen if it itself is shown and so are all its
896 // parents. But if a window is toplevel one, then its always visible on
897 // screen if IsShown() returns true, even if it has a hidden parent.
899 (IsTopLevel() || GetParent() == NULL
|| GetParent()->IsShownOnScreen());
902 // ----------------------------------------------------------------------------
904 // ----------------------------------------------------------------------------
906 bool wxWindowBase::IsTopLevel() const
911 // ----------------------------------------------------------------------------
912 // reparenting the window
913 // ----------------------------------------------------------------------------
915 void wxWindowBase::AddChild(wxWindowBase
*child
)
917 wxCHECK_RET( child
, wxT("can't add a NULL child") );
919 // this should never happen and it will lead to a crash later if it does
920 // because RemoveChild() will remove only one node from the children list
921 // and the other(s) one(s) will be left with dangling pointers in them
922 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
924 GetChildren().Append((wxWindow
*)child
);
925 child
->SetParent(this);
928 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
930 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
932 GetChildren().DeleteObject((wxWindow
*)child
);
933 child
->SetParent(NULL
);
936 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
938 wxWindow
*oldParent
= GetParent();
939 if ( newParent
== oldParent
)
945 const bool oldEnabledState
= IsEnabled();
947 // unlink this window from the existing parent.
950 oldParent
->RemoveChild(this);
954 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
957 // add it to the new one
960 newParent
->AddChild(this);
964 wxTopLevelWindows
.Append((wxWindow
*)this);
967 // We need to notify window (and its subwindows) if by changing the parent
968 // we also change our enabled/disabled status.
969 const bool newEnabledState
= IsEnabled();
970 if ( newEnabledState
!= oldEnabledState
)
972 NotifyWindowOnEnableChange(newEnabledState
);
978 // ----------------------------------------------------------------------------
979 // event handler stuff
980 // ----------------------------------------------------------------------------
982 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
984 wxEvtHandler
*handlerOld
= GetEventHandler();
986 handler
->SetNextHandler(handlerOld
);
989 GetEventHandler()->SetPreviousHandler(handler
);
991 SetEventHandler(handler
);
994 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
996 wxEvtHandler
*handlerA
= GetEventHandler();
999 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
1000 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
1003 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
1004 SetEventHandler(handlerB
);
1006 if ( deleteHandler
)
1009 handlerA
= (wxEvtHandler
*)NULL
;
1016 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
1018 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
1020 wxEvtHandler
*handlerPrev
= NULL
,
1021 *handlerCur
= GetEventHandler();
1022 while ( handlerCur
)
1024 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
1026 if ( handlerCur
== handler
)
1030 handlerPrev
->SetNextHandler(handlerNext
);
1034 SetEventHandler(handlerNext
);
1039 handlerNext
->SetPreviousHandler ( handlerPrev
);
1042 handler
->SetNextHandler(NULL
);
1043 handler
->SetPreviousHandler(NULL
);
1048 handlerPrev
= handlerCur
;
1049 handlerCur
= handlerNext
;
1052 wxFAIL_MSG( _T("where has the event handler gone?") );
1057 bool wxWindowBase::HandleWindowEvent(wxEvent
& event
) const
1059 return GetEventHandler()->SafelyProcessEvent(event
);
1062 // ----------------------------------------------------------------------------
1063 // colours, fonts &c
1064 // ----------------------------------------------------------------------------
1066 void wxWindowBase::InheritAttributes()
1068 const wxWindowBase
* const parent
= GetParent();
1072 // we only inherit attributes which had been explicitly set for the parent
1073 // which ensures that this only happens if the user really wants it and
1074 // not by default which wouldn't make any sense in modern GUIs where the
1075 // controls don't all use the same fonts (nor colours)
1076 if ( parent
->m_inheritFont
&& !m_hasFont
)
1077 SetFont(parent
->GetFont());
1079 // in addition, there is a possibility to explicitly forbid inheriting
1080 // colours at each class level by overriding ShouldInheritColours()
1081 if ( ShouldInheritColours() )
1083 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1084 SetForegroundColour(parent
->GetForegroundColour());
1086 // inheriting (solid) background colour is wrong as it totally breaks
1087 // any kind of themed backgrounds
1089 // instead, the controls should use the same background as their parent
1090 // (ideally by not drawing it at all)
1092 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1093 SetBackgroundColour(parent
->GetBackgroundColour());
1098 /* static */ wxVisualAttributes
1099 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1101 // it is important to return valid values for all attributes from here,
1102 // GetXXX() below rely on this
1103 wxVisualAttributes attrs
;
1104 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1105 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1107 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1108 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1109 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1110 // colour on other platforms.
1112 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1113 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1115 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1120 wxColour
wxWindowBase::GetBackgroundColour() const
1122 if ( !m_backgroundColour
.IsOk() )
1124 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
1126 // get our default background colour
1127 wxColour colBg
= GetDefaultAttributes().colBg
;
1129 // we must return some valid colour to avoid redoing this every time
1130 // and also to avoid surprizing the applications written for older
1131 // wxWidgets versions where GetBackgroundColour() always returned
1132 // something -- so give them something even if it doesn't make sense
1133 // for this window (e.g. it has a themed background)
1135 colBg
= GetClassDefaultAttributes().colBg
;
1140 return m_backgroundColour
;
1143 wxColour
wxWindowBase::GetForegroundColour() const
1145 // logic is the same as above
1146 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1148 wxColour colFg
= GetDefaultAttributes().colFg
;
1150 if ( !colFg
.IsOk() )
1151 colFg
= GetClassDefaultAttributes().colFg
;
1156 return m_foregroundColour
;
1159 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1161 if ( colour
== m_backgroundColour
)
1164 m_hasBgCol
= colour
.IsOk();
1165 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1166 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1168 m_inheritBgCol
= m_hasBgCol
;
1169 m_backgroundColour
= colour
;
1170 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1174 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1176 if (colour
== m_foregroundColour
)
1179 m_hasFgCol
= colour
.IsOk();
1180 m_inheritFgCol
= m_hasFgCol
;
1181 m_foregroundColour
= colour
;
1182 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1186 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1188 // setting an invalid cursor is ok, it means that we don't have any special
1190 if ( m_cursor
.IsSameAs(cursor
) )
1201 wxFont
wxWindowBase::GetFont() const
1203 // logic is the same as in GetBackgroundColour()
1204 if ( !m_font
.IsOk() )
1206 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1208 wxFont font
= GetDefaultAttributes().font
;
1210 font
= GetClassDefaultAttributes().font
;
1218 bool wxWindowBase::SetFont(const wxFont
& font
)
1220 if ( font
== m_font
)
1227 m_hasFont
= font
.IsOk();
1228 m_inheritFont
= m_hasFont
;
1230 InvalidateBestSize();
1237 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1239 m_hasCustomPalette
= true;
1242 // VZ: can anyone explain me what do we do here?
1243 wxWindowDC
d((wxWindow
*) this);
1247 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1249 wxWindow
*win
= (wxWindow
*)this;
1250 while ( win
&& !win
->HasCustomPalette() )
1252 win
= win
->GetParent();
1258 #endif // wxUSE_PALETTE
1261 void wxWindowBase::SetCaret(wxCaret
*caret
)
1272 wxASSERT_MSG( m_caret
->GetWindow() == this,
1273 wxT("caret should be created associated to this window") );
1276 #endif // wxUSE_CARET
1278 #if wxUSE_VALIDATORS
1279 // ----------------------------------------------------------------------------
1281 // ----------------------------------------------------------------------------
1283 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1285 if ( m_windowValidator
)
1286 delete m_windowValidator
;
1288 m_windowValidator
= (wxValidator
*)validator
.Clone();
1290 if ( m_windowValidator
)
1291 m_windowValidator
->SetWindow(this);
1293 #endif // wxUSE_VALIDATORS
1295 // ----------------------------------------------------------------------------
1296 // update region stuff
1297 // ----------------------------------------------------------------------------
1299 wxRect
wxWindowBase::GetUpdateClientRect() const
1301 wxRegion rgnUpdate
= GetUpdateRegion();
1302 rgnUpdate
.Intersect(GetClientRect());
1303 wxRect rectUpdate
= rgnUpdate
.GetBox();
1304 wxPoint ptOrigin
= GetClientAreaOrigin();
1305 rectUpdate
.x
-= ptOrigin
.x
;
1306 rectUpdate
.y
-= ptOrigin
.y
;
1311 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1313 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1316 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1318 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1321 void wxWindowBase::ClearBackground()
1323 // wxGTK uses its own version, no need to add never used code
1325 wxClientDC
dc((wxWindow
*)this);
1326 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1327 dc
.SetBackground(brush
);
1332 // ----------------------------------------------------------------------------
1333 // find child window by id or name
1334 // ----------------------------------------------------------------------------
1336 wxWindow
*wxWindowBase::FindWindow(long id
) const
1338 if ( id
== m_windowId
)
1339 return (wxWindow
*)this;
1341 wxWindowBase
*res
= (wxWindow
*)NULL
;
1342 wxWindowList::compatibility_iterator node
;
1343 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1345 wxWindowBase
*child
= node
->GetData();
1346 res
= child
->FindWindow( id
);
1349 return (wxWindow
*)res
;
1352 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1354 if ( name
== m_windowName
)
1355 return (wxWindow
*)this;
1357 wxWindowBase
*res
= (wxWindow
*)NULL
;
1358 wxWindowList::compatibility_iterator node
;
1359 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1361 wxWindow
*child
= node
->GetData();
1362 res
= child
->FindWindow(name
);
1365 return (wxWindow
*)res
;
1369 // find any window by id or name or label: If parent is non-NULL, look through
1370 // children for a label or title matching the specified string. If NULL, look
1371 // through all top-level windows.
1373 // to avoid duplicating code we reuse the same helper function but with
1374 // different comparators
1376 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1377 const wxString
& label
, long id
);
1380 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1383 return win
->GetLabel() == label
;
1387 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1390 return win
->GetName() == label
;
1394 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1397 return win
->GetId() == id
;
1400 // recursive helper for the FindWindowByXXX() functions
1402 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1403 const wxString
& label
,
1405 wxFindWindowCmp cmp
)
1409 // see if this is the one we're looking for
1410 if ( (*cmp
)(parent
, label
, id
) )
1411 return (wxWindow
*)parent
;
1413 // It wasn't, so check all its children
1414 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1416 node
= node
->GetNext() )
1418 // recursively check each child
1419 wxWindow
*win
= (wxWindow
*)node
->GetData();
1420 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1430 // helper for FindWindowByXXX()
1432 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1433 const wxString
& label
,
1435 wxFindWindowCmp cmp
)
1439 // just check parent and all its children
1440 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1443 // start at very top of wx's windows
1444 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1446 node
= node
->GetNext() )
1448 // recursively check each window & its children
1449 wxWindow
*win
= node
->GetData();
1450 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1460 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1462 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1467 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1469 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1473 // fall back to the label
1474 win
= FindWindowByLabel(title
, parent
);
1482 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1484 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1487 // ----------------------------------------------------------------------------
1488 // dialog oriented functions
1489 // ----------------------------------------------------------------------------
1491 void wxWindowBase::MakeModal(bool modal
)
1493 // Disable all other windows
1496 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1499 wxWindow
*win
= node
->GetData();
1501 win
->Enable(!modal
);
1503 node
= node
->GetNext();
1508 bool wxWindowBase::Validate()
1510 #if wxUSE_VALIDATORS
1511 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1513 wxWindowList::compatibility_iterator node
;
1514 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1516 wxWindowBase
*child
= node
->GetData();
1517 wxValidator
*validator
= child
->GetValidator();
1518 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1523 if ( recurse
&& !child
->Validate() )
1528 #endif // wxUSE_VALIDATORS
1533 bool wxWindowBase::TransferDataToWindow()
1535 #if wxUSE_VALIDATORS
1536 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1538 wxWindowList::compatibility_iterator node
;
1539 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1541 wxWindowBase
*child
= node
->GetData();
1542 wxValidator
*validator
= child
->GetValidator();
1543 if ( validator
&& !validator
->TransferToWindow() )
1545 wxLogWarning(_("Could not transfer data to window"));
1547 wxLog::FlushActive();
1555 if ( !child
->TransferDataToWindow() )
1557 // warning already given
1562 #endif // wxUSE_VALIDATORS
1567 bool wxWindowBase::TransferDataFromWindow()
1569 #if wxUSE_VALIDATORS
1570 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1572 wxWindowList::compatibility_iterator node
;
1573 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1575 wxWindow
*child
= node
->GetData();
1576 wxValidator
*validator
= child
->GetValidator();
1577 if ( validator
&& !validator
->TransferFromWindow() )
1579 // nop warning here because the application is supposed to give
1580 // one itself - we don't know here what might have gone wrongly
1587 if ( !child
->TransferDataFromWindow() )
1589 // warning already given
1594 #endif // wxUSE_VALIDATORS
1599 void wxWindowBase::InitDialog()
1601 wxInitDialogEvent
event(GetId());
1602 event
.SetEventObject( this );
1603 GetEventHandler()->ProcessEvent(event
);
1606 // ----------------------------------------------------------------------------
1607 // context-sensitive help support
1608 // ----------------------------------------------------------------------------
1612 // associate this help text with this window
1613 void wxWindowBase::SetHelpText(const wxString
& text
)
1615 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1618 helpProvider
->AddHelp(this, text
);
1622 // associate this help text with all windows with the same id as this
1624 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1626 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1629 helpProvider
->AddHelp(GetId(), text
);
1633 // get the help string associated with this window (may be empty)
1634 // default implementation forwards calls to the help provider
1636 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1637 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1640 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1643 text
= helpProvider
->GetHelp(this);
1649 // show help for this window
1650 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1652 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1655 if ( helpProvider
->ShowHelpAtPoint(this, event
.GetPosition(), event
.GetOrigin()) )
1657 // skip the event.Skip() below
1665 #endif // wxUSE_HELP
1667 // ----------------------------------------------------------------------------
1669 // ----------------------------------------------------------------------------
1673 void wxWindowBase::SetToolTip( const wxString
&tip
)
1675 // don't create the new tooltip if we already have one
1678 m_tooltip
->SetTip( tip
);
1682 SetToolTip( new wxToolTip( tip
) );
1685 // setting empty tooltip text does not remove the tooltip any more - use
1686 // SetToolTip((wxToolTip *)NULL) for this
1689 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1691 if ( m_tooltip
!= tooltip
)
1696 m_tooltip
= tooltip
;
1700 #endif // wxUSE_TOOLTIPS
1702 // ----------------------------------------------------------------------------
1703 // constraints and sizers
1704 // ----------------------------------------------------------------------------
1706 #if wxUSE_CONSTRAINTS
1708 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1710 if ( m_constraints
)
1712 UnsetConstraints(m_constraints
);
1713 delete m_constraints
;
1715 m_constraints
= constraints
;
1716 if ( m_constraints
)
1718 // Make sure other windows know they're part of a 'meaningful relationship'
1719 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1720 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1721 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1722 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1723 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1724 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1725 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1726 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1727 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1728 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1729 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1730 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1731 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1732 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1733 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1734 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1738 // This removes any dangling pointers to this window in other windows'
1739 // constraintsInvolvedIn lists.
1740 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1744 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1745 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1746 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1747 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1748 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1749 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1750 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1751 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1752 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1753 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1754 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1755 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1756 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1757 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1758 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1759 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1763 // Back-pointer to other windows we're involved with, so if we delete this
1764 // window, we must delete any constraints we're involved with.
1765 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1767 if ( !m_constraintsInvolvedIn
)
1768 m_constraintsInvolvedIn
= new wxWindowList
;
1769 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1770 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1773 // REMOVE back-pointer to other windows we're involved with.
1774 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1776 if ( m_constraintsInvolvedIn
)
1777 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1780 // Reset any constraints that mention this window
1781 void wxWindowBase::DeleteRelatedConstraints()
1783 if ( m_constraintsInvolvedIn
)
1785 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1788 wxWindow
*win
= node
->GetData();
1789 wxLayoutConstraints
*constr
= win
->GetConstraints();
1791 // Reset any constraints involving this window
1794 constr
->left
.ResetIfWin(this);
1795 constr
->top
.ResetIfWin(this);
1796 constr
->right
.ResetIfWin(this);
1797 constr
->bottom
.ResetIfWin(this);
1798 constr
->width
.ResetIfWin(this);
1799 constr
->height
.ResetIfWin(this);
1800 constr
->centreX
.ResetIfWin(this);
1801 constr
->centreY
.ResetIfWin(this);
1804 wxWindowList::compatibility_iterator next
= node
->GetNext();
1805 m_constraintsInvolvedIn
->Erase(node
);
1809 delete m_constraintsInvolvedIn
;
1810 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1814 #endif // wxUSE_CONSTRAINTS
1816 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1818 if ( sizer
== m_windowSizer
)
1821 if ( m_windowSizer
)
1823 m_windowSizer
->SetContainingWindow(NULL
);
1826 delete m_windowSizer
;
1829 m_windowSizer
= sizer
;
1830 if ( m_windowSizer
)
1832 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
1835 SetAutoLayout(m_windowSizer
!= NULL
);
1838 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1840 SetSizer( sizer
, deleteOld
);
1841 sizer
->SetSizeHints( (wxWindow
*) this );
1845 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1847 // adding a window to a sizer twice is going to result in fatal and
1848 // hard to debug problems later because when deleting the second
1849 // associated wxSizerItem we're going to dereference a dangling
1850 // pointer; so try to detect this as early as possible
1851 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1852 _T("Adding a window to the same sizer twice?") );
1854 m_containingSizer
= sizer
;
1857 #if wxUSE_CONSTRAINTS
1859 void wxWindowBase::SatisfyConstraints()
1861 wxLayoutConstraints
*constr
= GetConstraints();
1862 bool wasOk
= constr
&& constr
->AreSatisfied();
1864 ResetConstraints(); // Mark all constraints as unevaluated
1868 // if we're a top level panel (i.e. our parent is frame/dialog), our
1869 // own constraints will never be satisfied any more unless we do it
1873 while ( noChanges
> 0 )
1875 LayoutPhase1(&noChanges
);
1879 LayoutPhase2(&noChanges
);
1882 #endif // wxUSE_CONSTRAINTS
1884 bool wxWindowBase::Layout()
1886 // If there is a sizer, use it instead of the constraints
1890 GetVirtualSize(&w
, &h
);
1891 GetSizer()->SetDimension( 0, 0, w
, h
);
1893 #if wxUSE_CONSTRAINTS
1896 SatisfyConstraints(); // Find the right constraints values
1897 SetConstraintSizes(); // Recursively set the real window sizes
1904 #if wxUSE_CONSTRAINTS
1906 // first phase of the constraints evaluation: set our own constraints
1907 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1909 wxLayoutConstraints
*constr
= GetConstraints();
1911 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1914 // second phase: set the constraints for our children
1915 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1922 // Layout grand children
1928 // Do a phase of evaluating child constraints
1929 bool wxWindowBase::DoPhase(int phase
)
1931 // the list containing the children for which the constraints are already
1933 wxWindowList succeeded
;
1935 // the max number of iterations we loop before concluding that we can't set
1937 static const int maxIterations
= 500;
1939 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1943 // loop over all children setting their constraints
1944 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1946 node
= node
->GetNext() )
1948 wxWindow
*child
= node
->GetData();
1949 if ( child
->IsTopLevel() )
1951 // top level children are not inside our client area
1955 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1957 // this one is either already ok or nothing we can do about it
1961 int tempNoChanges
= 0;
1962 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1963 : child
->LayoutPhase2(&tempNoChanges
);
1964 noChanges
+= tempNoChanges
;
1968 succeeded
.Append(child
);
1974 // constraints are set
1982 void wxWindowBase::ResetConstraints()
1984 wxLayoutConstraints
*constr
= GetConstraints();
1987 constr
->left
.SetDone(false);
1988 constr
->top
.SetDone(false);
1989 constr
->right
.SetDone(false);
1990 constr
->bottom
.SetDone(false);
1991 constr
->width
.SetDone(false);
1992 constr
->height
.SetDone(false);
1993 constr
->centreX
.SetDone(false);
1994 constr
->centreY
.SetDone(false);
1997 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2000 wxWindow
*win
= node
->GetData();
2001 if ( !win
->IsTopLevel() )
2002 win
->ResetConstraints();
2003 node
= node
->GetNext();
2007 // Need to distinguish between setting the 'fake' size for windows and sizers,
2008 // and setting the real values.
2009 void wxWindowBase::SetConstraintSizes(bool recurse
)
2011 wxLayoutConstraints
*constr
= GetConstraints();
2012 if ( constr
&& constr
->AreSatisfied() )
2014 int x
= constr
->left
.GetValue();
2015 int y
= constr
->top
.GetValue();
2016 int w
= constr
->width
.GetValue();
2017 int h
= constr
->height
.GetValue();
2019 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
2020 (constr
->height
.GetRelationship() != wxAsIs
) )
2022 SetSize(x
, y
, w
, h
);
2026 // If we don't want to resize this window, just move it...
2032 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
2033 GetClassInfo()->GetClassName(),
2039 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2042 wxWindow
*win
= node
->GetData();
2043 if ( !win
->IsTopLevel() && win
->GetConstraints() )
2044 win
->SetConstraintSizes();
2045 node
= node
->GetNext();
2050 // Only set the size/position of the constraint (if any)
2051 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
2053 wxLayoutConstraints
*constr
= GetConstraints();
2056 if ( x
!= wxDefaultCoord
)
2058 constr
->left
.SetValue(x
);
2059 constr
->left
.SetDone(true);
2061 if ( y
!= wxDefaultCoord
)
2063 constr
->top
.SetValue(y
);
2064 constr
->top
.SetDone(true);
2066 if ( w
!= wxDefaultCoord
)
2068 constr
->width
.SetValue(w
);
2069 constr
->width
.SetDone(true);
2071 if ( h
!= wxDefaultCoord
)
2073 constr
->height
.SetValue(h
);
2074 constr
->height
.SetDone(true);
2079 void wxWindowBase::MoveConstraint(int x
, int y
)
2081 wxLayoutConstraints
*constr
= GetConstraints();
2084 if ( x
!= wxDefaultCoord
)
2086 constr
->left
.SetValue(x
);
2087 constr
->left
.SetDone(true);
2089 if ( y
!= wxDefaultCoord
)
2091 constr
->top
.SetValue(y
);
2092 constr
->top
.SetDone(true);
2097 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2099 wxLayoutConstraints
*constr
= GetConstraints();
2102 *w
= constr
->width
.GetValue();
2103 *h
= constr
->height
.GetValue();
2109 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2111 wxLayoutConstraints
*constr
= GetConstraints();
2114 *w
= constr
->width
.GetValue();
2115 *h
= constr
->height
.GetValue();
2118 GetClientSize(w
, h
);
2121 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2123 wxLayoutConstraints
*constr
= GetConstraints();
2126 *x
= constr
->left
.GetValue();
2127 *y
= constr
->top
.GetValue();
2133 #endif // wxUSE_CONSTRAINTS
2135 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2137 // don't do it for the dialogs/frames - they float independently of their
2139 if ( !IsTopLevel() )
2141 wxWindow
*parent
= GetParent();
2142 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2144 wxPoint
pt(parent
->GetClientAreaOrigin());
2151 // ----------------------------------------------------------------------------
2152 // Update UI processing
2153 // ----------------------------------------------------------------------------
2155 void wxWindowBase::UpdateWindowUI(long flags
)
2157 wxUpdateUIEvent
event(GetId());
2158 event
.SetEventObject(this);
2160 if ( GetEventHandler()->ProcessEvent(event
) )
2162 DoUpdateWindowUI(event
);
2165 if (flags
& wxUPDATE_UI_RECURSE
)
2167 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2170 wxWindow
* child
= (wxWindow
*) node
->GetData();
2171 child
->UpdateWindowUI(flags
);
2172 node
= node
->GetNext();
2177 // do the window-specific processing after processing the update event
2178 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2180 if ( event
.GetSetEnabled() )
2181 Enable(event
.GetEnabled());
2183 if ( event
.GetSetShown() )
2184 Show(event
.GetShown());
2187 // ----------------------------------------------------------------------------
2188 // dialog units translations
2189 // ----------------------------------------------------------------------------
2191 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2193 int charWidth
= GetCharWidth();
2194 int charHeight
= GetCharHeight();
2195 wxPoint pt2
= wxDefaultPosition
;
2196 if (pt
.x
!= wxDefaultCoord
)
2197 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2198 if (pt
.y
!= wxDefaultCoord
)
2199 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2204 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2206 int charWidth
= GetCharWidth();
2207 int charHeight
= GetCharHeight();
2208 wxPoint pt2
= wxDefaultPosition
;
2209 if (pt
.x
!= wxDefaultCoord
)
2210 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2211 if (pt
.y
!= wxDefaultCoord
)
2212 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2217 // ----------------------------------------------------------------------------
2219 // ----------------------------------------------------------------------------
2221 // propagate the colour change event to the subwindows
2222 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2224 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2227 // Only propagate to non-top-level windows
2228 wxWindow
*win
= node
->GetData();
2229 if ( !win
->IsTopLevel() )
2231 wxSysColourChangedEvent event2
;
2232 event
.SetEventObject(win
);
2233 win
->GetEventHandler()->ProcessEvent(event2
);
2236 node
= node
->GetNext();
2242 // the default action is to populate dialog with data when it's created,
2243 // and nudge the UI into displaying itself correctly in case
2244 // we've turned the wxUpdateUIEvents frequency down low.
2245 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2247 TransferDataToWindow();
2249 // Update the UI at this point
2250 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2253 // ----------------------------------------------------------------------------
2254 // menu-related functions
2255 // ----------------------------------------------------------------------------
2259 bool wxWindowBase::PopupMenu(wxMenu
*menu
, int x
, int y
)
2261 wxCHECK_MSG( menu
, false, "can't popup NULL menu" );
2263 wxCurrentPopupMenu
= menu
;
2264 const bool rc
= DoPopupMenu(menu
, x
, y
);
2265 wxCurrentPopupMenu
= NULL
;
2270 // this is used to pass the id of the selected item from the menu event handler
2271 // to the main function itself
2273 // it's ok to use a global here as there can be at most one popup menu shown at
2275 static int gs_popupMenuSelection
= wxID_NONE
;
2277 void wxWindowBase::InternalOnPopupMenu(wxCommandEvent
& event
)
2279 // store the id in a global variable where we'll retrieve it from later
2280 gs_popupMenuSelection
= event
.GetId();
2284 wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu
& menu
, int x
, int y
)
2286 gs_popupMenuSelection
= wxID_NONE
;
2288 Connect(wxEVT_COMMAND_MENU_SELECTED
,
2289 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2293 PopupMenu(&menu
, x
, y
);
2295 Disconnect(wxEVT_COMMAND_MENU_SELECTED
,
2296 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2300 return gs_popupMenuSelection
;
2303 #endif // wxUSE_MENUS
2305 // methods for drawing the sizers in a visible way
2308 static void DrawSizers(wxWindowBase
*win
);
2310 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2312 wxClientDC
dc((wxWindow
*)win
);
2313 dc
.SetPen(*wxRED_PEN
);
2314 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2315 dc
.DrawRectangle(rect
.Deflate(1, 1));
2318 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2320 const wxSizerItemList
& items
= sizer
->GetChildren();
2321 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2326 wxSizerItem
*item
= *i
;
2327 if ( item
->IsSizer() )
2329 DrawBorder(win
, item
->GetRect().Deflate(2));
2330 DrawSizer(win
, item
->GetSizer());
2332 else if ( item
->IsSpacer() )
2334 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2336 else if ( item
->IsWindow() )
2338 DrawSizers(item
->GetWindow());
2343 static void DrawSizers(wxWindowBase
*win
)
2345 wxSizer
*sizer
= win
->GetSizer();
2348 DrawBorder(win
, win
->GetClientSize());
2349 DrawSizer(win
, sizer
);
2351 else // no sizer, still recurse into the children
2353 const wxWindowList
& children
= win
->GetChildren();
2354 for ( wxWindowList::const_iterator i
= children
.begin(),
2355 end
= children
.end();
2364 #endif // __WXDEBUG__
2366 // process special middle clicks
2367 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2369 if ( event
.ControlDown() && event
.AltDown() )
2372 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2373 if ( event
.ShiftDown() )
2378 #endif // __WXDEBUG__
2379 ::wxInfoMessageBox((wxWindow
*)this);
2387 // ----------------------------------------------------------------------------
2389 // ----------------------------------------------------------------------------
2391 #if wxUSE_ACCESSIBILITY
2392 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2394 if (m_accessible
&& (accessible
!= m_accessible
))
2395 delete m_accessible
;
2396 m_accessible
= accessible
;
2398 m_accessible
->SetWindow((wxWindow
*) this);
2401 // Returns the accessible object, creating if necessary.
2402 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2405 m_accessible
= CreateAccessible();
2406 return m_accessible
;
2409 // Override to create a specific accessible object.
2410 wxAccessible
* wxWindowBase::CreateAccessible()
2412 return new wxWindowAccessible((wxWindow
*) this);
2417 // ----------------------------------------------------------------------------
2418 // list classes implementation
2419 // ----------------------------------------------------------------------------
2423 #include "wx/listimpl.cpp"
2424 WX_DEFINE_LIST(wxWindowList
)
2428 void wxWindowListNode::DeleteData()
2430 delete (wxWindow
*)GetData();
2433 #endif // wxUSE_STL/!wxUSE_STL
2435 // ----------------------------------------------------------------------------
2437 // ----------------------------------------------------------------------------
2439 wxBorder
wxWindowBase::GetBorder(long flags
) const
2441 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2442 if ( border
== wxBORDER_DEFAULT
)
2444 border
= GetDefaultBorder();
2446 else if ( border
== wxBORDER_THEME
)
2448 border
= GetDefaultBorderForControl();
2454 wxBorder
wxWindowBase::GetDefaultBorder() const
2456 return wxBORDER_NONE
;
2459 // ----------------------------------------------------------------------------
2461 // ----------------------------------------------------------------------------
2463 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2465 // here we just check if the point is inside the window or not
2467 // check the top and left border first
2468 bool outside
= x
< 0 || y
< 0;
2471 // check the right and bottom borders too
2472 wxSize size
= GetSize();
2473 outside
= x
>= size
.x
|| y
>= size
.y
;
2476 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2479 // ----------------------------------------------------------------------------
2481 // ----------------------------------------------------------------------------
2483 struct WXDLLEXPORT wxWindowNext
2487 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2488 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2489 bool wxWindowBase::ms_winCaptureChanging
= false;
2491 void wxWindowBase::CaptureMouse()
2493 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2495 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2497 ms_winCaptureChanging
= true;
2499 wxWindow
*winOld
= GetCapture();
2502 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2505 wxWindowNext
*item
= new wxWindowNext
;
2507 item
->next
= ms_winCaptureNext
;
2508 ms_winCaptureNext
= item
;
2510 //else: no mouse capture to save
2513 ms_winCaptureCurrent
= (wxWindow
*)this;
2515 ms_winCaptureChanging
= false;
2518 void wxWindowBase::ReleaseMouse()
2520 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2522 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2524 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2526 ms_winCaptureChanging
= true;
2529 ms_winCaptureCurrent
= NULL
;
2531 if ( ms_winCaptureNext
)
2533 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2534 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2536 wxWindowNext
*item
= ms_winCaptureNext
;
2537 ms_winCaptureNext
= item
->next
;
2540 //else: stack is empty, no previous capture
2542 ms_winCaptureChanging
= false;
2544 wxLogTrace(_T("mousecapture"),
2545 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2546 wx_static_cast(void*, GetCapture()));
2549 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2551 wxMouseCaptureLostEvent
event(win
->GetId());
2552 event
.SetEventObject(win
);
2553 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2555 // windows must handle this event, otherwise the app wouldn't behave
2556 // correctly if it loses capture unexpectedly; see the discussion here:
2557 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
2558 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
2559 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2564 void wxWindowBase::NotifyCaptureLost()
2566 // don't do anything if capture lost was expected, i.e. resulted from
2567 // a wx call to ReleaseMouse or CaptureMouse:
2568 if ( ms_winCaptureChanging
)
2571 // if the capture was lost unexpectedly, notify every window that has
2572 // capture (on stack or current) about it and clear the stack:
2574 if ( ms_winCaptureCurrent
)
2576 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2577 ms_winCaptureCurrent
= NULL
;
2580 while ( ms_winCaptureNext
)
2582 wxWindowNext
*item
= ms_winCaptureNext
;
2583 ms_winCaptureNext
= item
->next
;
2585 DoNotifyWindowAboutCaptureLost(item
->win
);
2594 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2595 int WXUNUSED(modifiers
),
2596 int WXUNUSED(keycode
))
2602 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2608 #endif // wxUSE_HOTKEY
2610 // ----------------------------------------------------------------------------
2612 // ----------------------------------------------------------------------------
2614 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2616 #if wxUSE_VALIDATORS
2617 // Can only use the validator of the window which
2618 // is receiving the event
2619 if ( event
.GetEventObject() == this )
2621 wxValidator
*validator
= GetValidator();
2622 if ( validator
&& validator
->ProcessEvent(event
) )
2627 #endif // wxUSE_VALIDATORS
2632 bool wxWindowBase::TryParent(wxEvent
& event
)
2634 // carry on up the parent-child hierarchy if the propagation count hasn't
2636 if ( event
.ShouldPropagate() )
2638 // honour the requests to stop propagation at this window: this is
2639 // used by the dialogs, for example, to prevent processing the events
2640 // from the dialog controls in the parent frame which rarely, if ever,
2642 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2644 wxWindow
*parent
= GetParent();
2645 if ( parent
&& !parent
->IsBeingDeleted() )
2647 wxPropagateOnce
propagateOnce(event
);
2649 return parent
->GetEventHandler()->ProcessEvent(event
);
2654 return wxEvtHandler::TryParent(event
);
2657 // ----------------------------------------------------------------------------
2658 // window relationships
2659 // ----------------------------------------------------------------------------
2661 wxWindow
*wxWindowBase::DoGetSibling(WindowOrder order
) const
2663 wxCHECK_MSG( GetParent(), NULL
,
2664 _T("GetPrev/NextSibling() don't work for TLWs!") );
2666 wxWindowList
& siblings
= GetParent()->GetChildren();
2667 wxWindowList::compatibility_iterator i
= siblings
.Find((wxWindow
*)this);
2668 wxCHECK_MSG( i
, NULL
, _T("window not a child of its parent?") );
2670 if ( order
== OrderBefore
)
2671 i
= i
->GetPrevious();
2675 return i
? i
->GetData() : NULL
;
2678 // ----------------------------------------------------------------------------
2679 // keyboard navigation
2680 // ----------------------------------------------------------------------------
2682 // Navigates in the specified direction inside this window
2683 bool wxWindowBase::DoNavigateIn(int flags
)
2685 #ifdef wxHAS_NATIVE_TAB_TRAVERSAL
2686 // native code doesn't process our wxNavigationKeyEvents anyhow
2689 #else // !wxHAS_NATIVE_TAB_TRAVERSAL
2690 wxNavigationKeyEvent eventNav
;
2691 eventNav
.SetFlags(flags
);
2692 eventNav
.SetEventObject(FindFocus());
2693 return GetEventHandler()->ProcessEvent(eventNav
);
2694 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
2697 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, WindowOrder move
)
2699 // check that we're not a top level window
2700 wxCHECK_RET( GetParent(),
2701 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2703 // detect the special case when we have nothing to do anyhow and when the
2704 // code below wouldn't work
2708 // find the target window in the siblings list
2709 wxWindowList
& siblings
= GetParent()->GetChildren();
2710 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2711 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2713 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2714 // can't just move the node around
2715 wxWindow
*self
= (wxWindow
*)this;
2716 siblings
.DeleteObject(self
);
2717 if ( move
== OrderAfter
)
2724 siblings
.Insert(i
, self
);
2726 else // OrderAfter and win was the last sibling
2728 siblings
.Append(self
);
2732 // ----------------------------------------------------------------------------
2734 // ----------------------------------------------------------------------------
2736 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2738 wxWindowBase
*win
= DoFindFocus();
2739 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2742 // ----------------------------------------------------------------------------
2744 // ----------------------------------------------------------------------------
2746 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2748 while ( win
&& !win
->IsTopLevel() )
2749 win
= win
->GetParent();
2754 #if wxUSE_ACCESSIBILITY
2755 // ----------------------------------------------------------------------------
2756 // accessible object for windows
2757 // ----------------------------------------------------------------------------
2759 // Can return either a child object, or an integer
2760 // representing the child element, starting from 1.
2761 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2763 wxASSERT( GetWindow() != NULL
);
2767 return wxACC_NOT_IMPLEMENTED
;
2770 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2771 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2773 wxASSERT( GetWindow() != NULL
);
2777 wxWindow
* win
= NULL
;
2784 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2786 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2793 rect
= win
->GetRect();
2794 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2795 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2799 return wxACC_NOT_IMPLEMENTED
;
2802 // Navigates from fromId to toId/toObject.
2803 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2804 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2806 wxASSERT( GetWindow() != NULL
);
2812 case wxNAVDIR_FIRSTCHILD
:
2814 if (GetWindow()->GetChildren().GetCount() == 0)
2816 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2817 *toObject
= childWindow
->GetOrCreateAccessible();
2821 case wxNAVDIR_LASTCHILD
:
2823 if (GetWindow()->GetChildren().GetCount() == 0)
2825 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2826 *toObject
= childWindow
->GetOrCreateAccessible();
2830 case wxNAVDIR_RIGHT
:
2834 wxWindowList::compatibility_iterator node
=
2835 wxWindowList::compatibility_iterator();
2838 // Can't navigate to sibling of this window
2839 // if we're a top-level window.
2840 if (!GetWindow()->GetParent())
2841 return wxACC_NOT_IMPLEMENTED
;
2843 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2847 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2848 node
= GetWindow()->GetChildren().Item(fromId
-1);
2851 if (node
&& node
->GetNext())
2853 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2854 *toObject
= nextWindow
->GetOrCreateAccessible();
2862 case wxNAVDIR_PREVIOUS
:
2864 wxWindowList::compatibility_iterator node
=
2865 wxWindowList::compatibility_iterator();
2868 // Can't navigate to sibling of this window
2869 // if we're a top-level window.
2870 if (!GetWindow()->GetParent())
2871 return wxACC_NOT_IMPLEMENTED
;
2873 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2877 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2878 node
= GetWindow()->GetChildren().Item(fromId
-1);
2881 if (node
&& node
->GetPrevious())
2883 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2884 *toObject
= previousWindow
->GetOrCreateAccessible();
2892 return wxACC_NOT_IMPLEMENTED
;
2895 // Gets the name of the specified object.
2896 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2898 wxASSERT( GetWindow() != NULL
);
2904 // If a child, leave wxWidgets to call the function on the actual
2907 return wxACC_NOT_IMPLEMENTED
;
2909 // This will eventually be replaced by specialised
2910 // accessible classes, one for each kind of wxWidgets
2911 // control or window.
2913 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2914 title
= ((wxButton
*) GetWindow())->GetLabel();
2917 title
= GetWindow()->GetName();
2925 return wxACC_NOT_IMPLEMENTED
;
2928 // Gets the number of children.
2929 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2931 wxASSERT( GetWindow() != NULL
);
2935 *childId
= (int) GetWindow()->GetChildren().GetCount();
2939 // Gets the specified child (starting from 1).
2940 // If *child is NULL and return value is wxACC_OK,
2941 // this means that the child is a simple element and
2942 // not an accessible object.
2943 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2945 wxASSERT( GetWindow() != NULL
);
2955 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2958 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2959 *child
= childWindow
->GetOrCreateAccessible();
2966 // Gets the parent, or NULL.
2967 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2969 wxASSERT( GetWindow() != NULL
);
2973 wxWindow
* parentWindow
= GetWindow()->GetParent();
2981 *parent
= parentWindow
->GetOrCreateAccessible();
2989 // Performs the default action. childId is 0 (the action for this object)
2990 // or > 0 (the action for a child).
2991 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2992 // window (e.g. an edit control).
2993 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2995 wxASSERT( GetWindow() != NULL
);
2999 return wxACC_NOT_IMPLEMENTED
;
3002 // Gets the default action for this object (0) or > 0 (the action for a child).
3003 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
3004 // string if there is no action.
3005 // The retrieved string describes the action that is performed on an object,
3006 // not what the object does as a result. For example, a toolbar button that prints
3007 // a document has a default action of "Press" rather than "Prints the current document."
3008 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
3010 wxASSERT( GetWindow() != NULL
);
3014 return wxACC_NOT_IMPLEMENTED
;
3017 // Returns the description for this object or a child.
3018 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
3020 wxASSERT( GetWindow() != NULL
);
3024 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3030 return wxACC_NOT_IMPLEMENTED
;
3033 // Returns help text for this object or a child, similar to tooltip text.
3034 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
3036 wxASSERT( GetWindow() != NULL
);
3040 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3046 return wxACC_NOT_IMPLEMENTED
;
3049 // Returns the keyboard shortcut for this object or child.
3050 // Return e.g. ALT+K
3051 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
3053 wxASSERT( GetWindow() != NULL
);
3057 return wxACC_NOT_IMPLEMENTED
;
3060 // Returns a role constant.
3061 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
3063 wxASSERT( GetWindow() != NULL
);
3067 // If a child, leave wxWidgets to call the function on the actual
3070 return wxACC_NOT_IMPLEMENTED
;
3072 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3073 return wxACC_NOT_IMPLEMENTED
;
3075 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3076 return wxACC_NOT_IMPLEMENTED
;
3079 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3080 return wxACC_NOT_IMPLEMENTED
;
3083 //*role = wxROLE_SYSTEM_CLIENT;
3084 *role
= wxROLE_SYSTEM_CLIENT
;
3088 return wxACC_NOT_IMPLEMENTED
;
3092 // Returns a state constant.
3093 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
3095 wxASSERT( GetWindow() != NULL
);
3099 // If a child, leave wxWidgets to call the function on the actual
3102 return wxACC_NOT_IMPLEMENTED
;
3104 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3105 return wxACC_NOT_IMPLEMENTED
;
3108 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3109 return wxACC_NOT_IMPLEMENTED
;
3112 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3113 return wxACC_NOT_IMPLEMENTED
;
3120 return wxACC_NOT_IMPLEMENTED
;
3124 // Returns a localized string representing the value for the object
3126 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3128 wxASSERT( GetWindow() != NULL
);
3132 return wxACC_NOT_IMPLEMENTED
;
3135 // Selects the object or child.
3136 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3138 wxASSERT( GetWindow() != NULL
);
3142 return wxACC_NOT_IMPLEMENTED
;
3145 // Gets the window with the keyboard focus.
3146 // If childId is 0 and child is NULL, no object in
3147 // this subhierarchy has the focus.
3148 // If this object has the focus, child should be 'this'.
3149 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3151 wxASSERT( GetWindow() != NULL
);
3155 return wxACC_NOT_IMPLEMENTED
;
3159 // Gets a variant representing the selected children
3161 // Acceptable values:
3162 // - a null variant (IsNull() returns true)
3163 // - a list variant (GetType() == wxT("list")
3164 // - an integer representing the selected child element,
3165 // or 0 if this object is selected (GetType() == wxT("long")
3166 // - a "void*" pointer to a wxAccessible child object
3167 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3169 wxASSERT( GetWindow() != NULL
);
3173 return wxACC_NOT_IMPLEMENTED
;
3175 #endif // wxUSE_VARIANT
3177 #endif // wxUSE_ACCESSIBILITY
3179 // ----------------------------------------------------------------------------
3181 // ----------------------------------------------------------------------------
3184 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3186 wxCoord widthTotal
) const
3188 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3190 x
= widthTotal
- x
- width
;
3196 // ----------------------------------------------------------------------------
3197 // Window (and menu items) identifiers management
3198 // ----------------------------------------------------------------------------
3203 // this array contains, in packed form, the "in use" flags for the entire
3204 // auto-generated ids range: N-th element of the array contains the flags for
3205 // ids in [wxID_AUTO_LOWEST + 8*N, wxID_AUTO_LOWEST + 8*N + 7] range
3207 // initially no ids are in use and we allocate them consecutively, but after we
3208 // exhaust the entire range, we wrap around and reuse the ids freed in the
3210 wxByte gs_autoIdsInUse
[(wxID_AUTO_HIGHEST
- wxID_AUTO_LOWEST
+ 1)/8 + 1] = { 0 };
3212 // this is an optimization used until we wrap around wxID_AUTO_HIGHEST: if this
3213 // value is < wxID_AUTO_HIGHEST we know that we haven't wrapped yet and so can
3214 // allocate the ids simply by incrementing it
3215 static wxWindowID gs_nextControlId
= wxID_AUTO_LOWEST
;
3217 void MarkAutoIdUsed(wxWindowID id
)
3219 id
-= wxID_AUTO_LOWEST
;
3221 const int theByte
= id
/ 8;
3222 const int theBit
= id
% 8;
3224 gs_autoIdsInUse
[theByte
] |= 1 << theBit
;
3227 void FreeAutoId(wxWindowID id
)
3229 id
-= wxID_AUTO_LOWEST
;
3231 const int theByte
= id
/ 8;
3232 const int theBit
= id
% 8;
3234 gs_autoIdsInUse
[theByte
] &= ~(1 << theBit
);
3237 bool IsAutoIdInUse(wxWindowID id
)
3239 id
-= wxID_AUTO_LOWEST
;
3241 const int theByte
= id
/ 8;
3242 const int theBit
= id
% 8;
3244 return (gs_autoIdsInUse
[theByte
] & (1 << theBit
)) != 0;
3247 } // anonymous namespace
3251 bool wxWindowBase::IsAutoGeneratedId(wxWindowID id
)
3253 if ( id
< wxID_AUTO_LOWEST
|| id
> wxID_AUTO_HIGHEST
)
3256 // we shouldn't have any stray ids in this range
3257 wxASSERT_MSG( IsAutoIdInUse(id
), "unused automatically generated id?" );
3262 wxWindowID
wxWindowBase::NewControlId(int count
)
3264 wxASSERT_MSG( count
> 0, "can't allocate less than 1 id" );
3266 if ( gs_nextControlId
+ count
- 1 <= wxID_AUTO_HIGHEST
)
3268 // we haven't wrapped yet, so we can just grab the next count ids
3269 wxWindowID id
= gs_nextControlId
;
3272 MarkAutoIdUsed(gs_nextControlId
++);
3276 else // we've already wrapped or are now going to
3278 // brute-force search for the id values
3280 // number of consecutive free ids found so far
3283 for ( wxWindowID id
= wxID_AUTO_LOWEST
; id
<= wxID_AUTO_HIGHEST
; id
++ )
3285 if ( !IsAutoIdInUse(id
) )
3287 // found another consecutive available id
3289 if ( found
== count
)
3291 // mark all count consecutive free ids we found as being in
3292 // use now and rewind back to the start of available range
3295 MarkAutoIdUsed(id
--);
3300 else // this id is in use
3302 // reset the number of consecutive free values found
3308 // if we get here, there are not enough consecutive free ids
3312 void wxWindowBase::ReleaseControlId(wxWindowID id
)
3314 wxCHECK_RET( IsAutoGeneratedId(id
), "can't release non auto-generated id" );