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;
219 // common part of window creation process
220 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
222 const wxPoint
& WXUNUSED(pos
),
223 const wxSize
& WXUNUSED(size
),
225 const wxValidator
& wxVALIDATOR_PARAM(validator
),
226 const wxString
& name
)
229 // wxGTK doesn't allow to create controls with static box as the parent so
230 // this will result in a crash when the program is ported to wxGTK so warn
233 // if you get this assert, the correct solution is to create the controls
234 // as siblings of the static box
235 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
236 _T("wxStaticBox can't be used as a window parent!") );
237 #endif // wxUSE_STATBOX
239 // ids are limited to 16 bits under MSW so if you care about portability,
240 // it's not a good idea to use ids out of this range (and negative ids are
241 // reserved for wxWidgets own usage)
242 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767) ||
243 (id
>= wxID_AUTO_LOWEST
&& id
<= wxID_AUTO_HIGHEST
),
244 _T("invalid id value") );
246 // generate a new id if the user doesn't care about it
247 if ( id
== wxID_ANY
)
249 m_windowId
= NewControlId();
251 // remember to call ReleaseControlId() when this window is destroyed
254 else // valid id specified
259 // don't use SetWindowStyleFlag() here, this function should only be called
260 // to change the flag after creation as it tries to reflect the changes in
261 // flags by updating the window dynamically and we don't need this here
262 m_windowStyle
= style
;
268 SetValidator(validator
);
269 #endif // wxUSE_VALIDATORS
271 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
272 // have it too - like this it's possible to set it only in the top level
273 // dialog/frame and all children will inherit it by defult
274 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
276 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
282 bool wxWindowBase::ToggleWindowStyle(int flag
)
284 wxASSERT_MSG( flag
, _T("flags with 0 value can't be toggled") );
287 long style
= GetWindowStyleFlag();
293 else // currently off
299 SetWindowStyleFlag(style
);
304 // ----------------------------------------------------------------------------
306 // ----------------------------------------------------------------------------
309 wxWindowBase::~wxWindowBase()
311 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
313 // mark the id as unused if we allocated it for this control
315 ReleaseControlId(m_windowId
);
317 // FIXME if these 2 cases result from programming errors in the user code
318 // we should probably assert here instead of silently fixing them
320 // Just in case the window has been Closed, but we're then deleting
321 // immediately: don't leave dangling pointers.
322 wxPendingDelete
.DeleteObject(this);
324 // Just in case we've loaded a top-level window via LoadNativeDialog but
325 // we weren't a dialog class
326 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
328 // The associated popup menu can still be alive, disassociate from it in
330 if ( wxCurrentPopupMenu
&& wxCurrentPopupMenu
->GetInvokingWindow() == this )
331 wxCurrentPopupMenu
->SetInvokingWindow(NULL
);
333 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
335 // notify the parent about this window destruction
337 m_parent
->RemoveChild(this);
341 #endif // wxUSE_CARET
344 delete m_windowValidator
;
345 #endif // wxUSE_VALIDATORS
347 #if wxUSE_CONSTRAINTS
348 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
349 // at deleted windows as they delete themselves.
350 DeleteRelatedConstraints();
354 // This removes any dangling pointers to this window in other windows'
355 // constraintsInvolvedIn lists.
356 UnsetConstraints(m_constraints
);
357 delete m_constraints
;
358 m_constraints
= NULL
;
360 #endif // wxUSE_CONSTRAINTS
362 if ( m_containingSizer
)
363 m_containingSizer
->Detach( (wxWindow
*)this );
365 delete m_windowSizer
;
367 #if wxUSE_DRAG_AND_DROP
369 #endif // wxUSE_DRAG_AND_DROP
373 #endif // wxUSE_TOOLTIPS
375 #if wxUSE_ACCESSIBILITY
380 void wxWindowBase::SendDestroyEvent()
382 wxWindowDestroyEvent event
;
383 event
.SetEventObject(this);
384 event
.SetId(GetId());
385 GetEventHandler()->ProcessEvent(event
);
388 bool wxWindowBase::Destroy()
395 bool wxWindowBase::Close(bool force
)
397 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
398 event
.SetEventObject(this);
399 event
.SetCanVeto(!force
);
401 // return false if window wasn't closed because the application vetoed the
403 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
406 bool wxWindowBase::DestroyChildren()
408 wxWindowList::compatibility_iterator node
;
411 // we iterate until the list becomes empty
412 node
= GetChildren().GetFirst();
416 wxWindow
*child
= node
->GetData();
418 // note that we really want to call delete and not ->Destroy() here
419 // because we want to delete the child immediately, before we are
420 // deleted, and delayed deletion would result in problems as our (top
421 // level) child could outlive its parent
424 wxASSERT_MSG( !GetChildren().Find(child
),
425 wxT("child didn't remove itself using RemoveChild()") );
431 // ----------------------------------------------------------------------------
432 // size/position related methods
433 // ----------------------------------------------------------------------------
435 // centre the window with respect to its parent in either (or both) directions
436 void wxWindowBase::DoCentre(int dir
)
438 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
439 _T("this method only implements centering child windows") );
441 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
444 // fits the window around the children
445 void wxWindowBase::Fit()
447 if ( !GetChildren().empty() )
449 SetSize(GetBestSize());
451 //else: do nothing if we have no children
454 // fits virtual size (ie. scrolled area etc.) around children
455 void wxWindowBase::FitInside()
457 if ( GetChildren().GetCount() > 0 )
459 SetVirtualSize( GetBestVirtualSize() );
463 // On Mac, scrollbars are explicitly children.
465 static bool wxHasRealChildren(const wxWindowBase
* win
)
467 int realChildCount
= 0;
469 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
471 node
= node
->GetNext() )
473 wxWindow
*win
= node
->GetData();
474 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
477 return (realChildCount
> 0);
481 void wxWindowBase::InvalidateBestSize()
483 m_bestSizeCache
= wxDefaultSize
;
485 // parent's best size calculation may depend on its children's
486 // as long as child window we are in is not top level window itself
487 // (because the TLW size is never resized automatically)
488 // so let's invalidate it as well to be safe:
489 if (m_parent
&& !IsTopLevel())
490 m_parent
->InvalidateBestSize();
493 // return the size best suited for the current window
494 wxSize
wxWindowBase::DoGetBestSize() const
500 best
= m_windowSizer
->GetMinSize();
502 #if wxUSE_CONSTRAINTS
503 else if ( m_constraints
)
505 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
507 // our minimal acceptable size is such that all our windows fit inside
511 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
513 node
= node
->GetNext() )
515 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
518 // it's not normal that we have an unconstrained child, but
519 // what can we do about it?
523 int x
= c
->right
.GetValue(),
524 y
= c
->bottom
.GetValue();
532 // TODO: we must calculate the overlaps somehow, otherwise we
533 // will never return a size bigger than the current one :-(
536 best
= wxSize(maxX
, maxY
);
538 #endif // wxUSE_CONSTRAINTS
539 else if ( !GetChildren().empty()
541 && wxHasRealChildren(this)
545 // our minimal acceptable size is such that all our visible child
546 // windows fit inside
550 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
552 node
= node
->GetNext() )
554 wxWindow
*win
= node
->GetData();
555 if ( win
->IsTopLevel()
558 || wxDynamicCast(win
, wxStatusBar
)
559 #endif // wxUSE_STATUSBAR
562 // dialogs and frames lie in different top level windows -
563 // don't deal with them here; as for the status bars, they
564 // don't lie in the client area at all
569 win
->GetPosition(&wx
, &wy
);
571 // if the window hadn't been positioned yet, assume that it is in
573 if ( wx
== wxDefaultCoord
)
575 if ( wy
== wxDefaultCoord
)
578 win
->GetSize(&ww
, &wh
);
579 if ( wx
+ ww
> maxX
)
581 if ( wy
+ wh
> maxY
)
585 best
= wxSize(maxX
, maxY
);
587 else // ! has children
589 // for a generic window there is no natural best size so, if the
590 // minimal size is not set, use the current size but take care to
591 // remember it as minimal size for the next time because our best size
592 // should be constant: otherwise we could get into a situation when the
593 // window is initially at some size, then expanded to a larger size and
594 // then, when the containing window is shrunk back (because our initial
595 // best size had been used for computing the parent min size), we can't
596 // be shrunk back any more because our best size is now bigger
597 wxSize size
= GetMinSize();
598 if ( !size
.IsFullySpecified() )
600 size
.SetDefaults(GetSize());
601 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
604 // return as-is, unadjusted by the client size difference.
608 // Add any difference between size and client size
609 wxSize diff
= GetSize() - GetClientSize();
610 best
.x
+= wxMax(0, diff
.x
);
611 best
.y
+= wxMax(0, diff
.y
);
616 // helper of GetWindowBorderSize(): as many ports don't implement support for
617 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
618 // fallbacks in this case
619 static int wxGetMetricOrDefault(wxSystemMetric what
)
621 int rc
= wxSystemSettings::GetMetric(what
);
628 // 2D border is by default 1 pixel wide
634 // 3D borders are by default 2 pixels
639 wxFAIL_MSG( _T("unexpected wxGetMetricOrDefault() argument") );
647 wxSize
wxWindowBase::GetWindowBorderSize() const
651 switch ( GetBorder() )
654 // nothing to do, size is already (0, 0)
657 case wxBORDER_SIMPLE
:
658 case wxBORDER_STATIC
:
659 size
.x
= wxGetMetricOrDefault(wxSYS_BORDER_X
);
660 size
.y
= wxGetMetricOrDefault(wxSYS_BORDER_Y
);
663 case wxBORDER_SUNKEN
:
664 case wxBORDER_RAISED
:
665 size
.x
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X
),
666 wxGetMetricOrDefault(wxSYS_BORDER_X
));
667 size
.y
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y
),
668 wxGetMetricOrDefault(wxSYS_BORDER_Y
));
671 case wxBORDER_DOUBLE
:
672 size
.x
= wxGetMetricOrDefault(wxSYS_EDGE_X
) +
673 wxGetMetricOrDefault(wxSYS_BORDER_X
);
674 size
.y
= wxGetMetricOrDefault(wxSYS_EDGE_Y
) +
675 wxGetMetricOrDefault(wxSYS_BORDER_Y
);
679 wxFAIL_MSG(_T("Unknown border style."));
683 // we have borders on both sides
687 wxSize
wxWindowBase::GetEffectiveMinSize() const
689 // merge the best size with the min size, giving priority to the min size
690 wxSize min
= GetMinSize();
691 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
693 wxSize best
= GetBestSize();
694 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
695 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
701 void wxWindowBase::SetInitialSize(const wxSize
& size
)
703 // Set the min size to the size passed in. This will usually either be
704 // wxDefaultSize or the size passed to this window's ctor/Create function.
707 // Merge the size with the best size if needed
708 wxSize best
= GetEffectiveMinSize();
710 // If the current size doesn't match then change it
711 if (GetSize() != best
)
716 // by default the origin is not shifted
717 wxPoint
wxWindowBase::GetClientAreaOrigin() const
722 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
724 if ( m_windowVariant
!= variant
)
726 m_windowVariant
= variant
;
728 DoSetWindowVariant(variant
);
732 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
734 // adjust the font height to correspond to our new variant (notice that
735 // we're only called if something really changed)
736 wxFont font
= GetFont();
737 int size
= font
.GetPointSize();
740 case wxWINDOW_VARIANT_NORMAL
:
743 case wxWINDOW_VARIANT_SMALL
:
748 case wxWINDOW_VARIANT_MINI
:
753 case wxWINDOW_VARIANT_LARGE
:
759 wxFAIL_MSG(_T("unexpected window variant"));
763 font
.SetPointSize(size
);
767 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
769 int WXUNUSED(incW
), int WXUNUSED(incH
) )
771 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
772 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
773 _T("min width/height must be less than max width/height!") );
782 #if WXWIN_COMPATIBILITY_2_8
783 void wxWindowBase::SetVirtualSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
),
784 int WXUNUSED(maxW
), int WXUNUSED(maxH
))
788 void wxWindowBase::SetVirtualSizeHints(const wxSize
& WXUNUSED(minsize
),
789 const wxSize
& WXUNUSED(maxsize
))
792 #endif // WXWIN_COMPATIBILITY_2_8
794 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
796 m_virtualSize
= wxSize(x
, y
);
799 wxSize
wxWindowBase::DoGetVirtualSize() const
801 // we should use the entire client area so if it is greater than our
802 // virtual size, expand it to fit (otherwise if the window is big enough we
803 // wouldn't be using parts of it)
804 wxSize size
= GetClientSize();
805 if ( m_virtualSize
.x
> size
.x
)
806 size
.x
= m_virtualSize
.x
;
808 if ( m_virtualSize
.y
>= size
.y
)
809 size
.y
= m_virtualSize
.y
;
814 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
816 // screen position is the same as (0, 0) in client coords for non TLWs (and
817 // TLWs override this method)
823 ClientToScreen(x
, y
);
826 // ----------------------------------------------------------------------------
827 // show/hide/enable/disable the window
828 // ----------------------------------------------------------------------------
830 bool wxWindowBase::Show(bool show
)
832 if ( show
!= m_isShown
)
844 bool wxWindowBase::IsEnabled() const
846 return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
849 void wxWindowBase::NotifyWindowOnEnableChange(bool enabled
)
851 #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
853 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
857 // If we are top-level then the logic doesn't apply - otherwise
858 // showing a modal dialog would result in total greying out (and ungreying
859 // out later) of everything which would be really ugly
863 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
865 node
= node
->GetNext() )
867 wxWindowBase
* const child
= node
->GetData();
868 if ( !child
->IsTopLevel() && child
->IsThisEnabled() )
869 child
->NotifyWindowOnEnableChange(enabled
);
873 bool wxWindowBase::Enable(bool enable
)
875 if ( enable
== IsThisEnabled() )
878 m_isEnabled
= enable
;
880 #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
882 #else // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
883 wxWindowBase
* const parent
= GetParent();
884 if( !IsTopLevel() && parent
&& !parent
->IsEnabled() )
888 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
890 NotifyWindowOnEnableChange(enable
);
895 bool wxWindowBase::IsShownOnScreen() const
897 // A window is shown on screen if it itself is shown and so are all its
898 // parents. But if a window is toplevel one, then its always visible on
899 // screen if IsShown() returns true, even if it has a hidden parent.
901 (IsTopLevel() || GetParent() == NULL
|| GetParent()->IsShownOnScreen());
904 // ----------------------------------------------------------------------------
906 // ----------------------------------------------------------------------------
908 bool wxWindowBase::IsTopLevel() const
913 // ----------------------------------------------------------------------------
914 // reparenting the window
915 // ----------------------------------------------------------------------------
917 void wxWindowBase::AddChild(wxWindowBase
*child
)
919 wxCHECK_RET( child
, wxT("can't add a NULL child") );
921 // this should never happen and it will lead to a crash later if it does
922 // because RemoveChild() will remove only one node from the children list
923 // and the other(s) one(s) will be left with dangling pointers in them
924 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
926 GetChildren().Append((wxWindow
*)child
);
927 child
->SetParent(this);
930 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
932 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
934 GetChildren().DeleteObject((wxWindow
*)child
);
935 child
->SetParent(NULL
);
938 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
940 wxWindow
*oldParent
= GetParent();
941 if ( newParent
== oldParent
)
947 const bool oldEnabledState
= IsEnabled();
949 // unlink this window from the existing parent.
952 oldParent
->RemoveChild(this);
956 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
959 // add it to the new one
962 newParent
->AddChild(this);
966 wxTopLevelWindows
.Append((wxWindow
*)this);
969 // We need to notify window (and its subwindows) if by changing the parent
970 // we also change our enabled/disabled status.
971 const bool newEnabledState
= IsEnabled();
972 if ( newEnabledState
!= oldEnabledState
)
974 NotifyWindowOnEnableChange(newEnabledState
);
980 // ----------------------------------------------------------------------------
981 // event handler stuff
982 // ----------------------------------------------------------------------------
984 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
986 wxEvtHandler
*handlerOld
= GetEventHandler();
988 handler
->SetNextHandler(handlerOld
);
991 GetEventHandler()->SetPreviousHandler(handler
);
993 SetEventHandler(handler
);
996 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
998 wxEvtHandler
*handlerA
= GetEventHandler();
1001 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
1002 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
1005 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
1006 SetEventHandler(handlerB
);
1008 if ( deleteHandler
)
1011 handlerA
= (wxEvtHandler
*)NULL
;
1018 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
1020 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
1022 wxEvtHandler
*handlerPrev
= NULL
,
1023 *handlerCur
= GetEventHandler();
1024 while ( handlerCur
)
1026 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
1028 if ( handlerCur
== handler
)
1032 handlerPrev
->SetNextHandler(handlerNext
);
1036 SetEventHandler(handlerNext
);
1041 handlerNext
->SetPreviousHandler ( handlerPrev
);
1044 handler
->SetNextHandler(NULL
);
1045 handler
->SetPreviousHandler(NULL
);
1050 handlerPrev
= handlerCur
;
1051 handlerCur
= handlerNext
;
1054 wxFAIL_MSG( _T("where has the event handler gone?") );
1059 bool wxWindowBase::HandleWindowEvent(wxEvent
& event
) const
1061 return GetEventHandler()->SafelyProcessEvent(event
);
1064 // ----------------------------------------------------------------------------
1065 // colours, fonts &c
1066 // ----------------------------------------------------------------------------
1068 void wxWindowBase::InheritAttributes()
1070 const wxWindowBase
* const parent
= GetParent();
1074 // we only inherit attributes which had been explicitly set for the parent
1075 // which ensures that this only happens if the user really wants it and
1076 // not by default which wouldn't make any sense in modern GUIs where the
1077 // controls don't all use the same fonts (nor colours)
1078 if ( parent
->m_inheritFont
&& !m_hasFont
)
1079 SetFont(parent
->GetFont());
1081 // in addition, there is a possibility to explicitly forbid inheriting
1082 // colours at each class level by overriding ShouldInheritColours()
1083 if ( ShouldInheritColours() )
1085 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1086 SetForegroundColour(parent
->GetForegroundColour());
1088 // inheriting (solid) background colour is wrong as it totally breaks
1089 // any kind of themed backgrounds
1091 // instead, the controls should use the same background as their parent
1092 // (ideally by not drawing it at all)
1094 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1095 SetBackgroundColour(parent
->GetBackgroundColour());
1100 /* static */ wxVisualAttributes
1101 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1103 // it is important to return valid values for all attributes from here,
1104 // GetXXX() below rely on this
1105 wxVisualAttributes attrs
;
1106 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1107 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1109 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1110 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1111 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1112 // colour on other platforms.
1114 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1115 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1117 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1122 wxColour
wxWindowBase::GetBackgroundColour() const
1124 if ( !m_backgroundColour
.IsOk() )
1126 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
1128 // get our default background colour
1129 wxColour colBg
= GetDefaultAttributes().colBg
;
1131 // we must return some valid colour to avoid redoing this every time
1132 // and also to avoid surprizing the applications written for older
1133 // wxWidgets versions where GetBackgroundColour() always returned
1134 // something -- so give them something even if it doesn't make sense
1135 // for this window (e.g. it has a themed background)
1137 colBg
= GetClassDefaultAttributes().colBg
;
1142 return m_backgroundColour
;
1145 wxColour
wxWindowBase::GetForegroundColour() const
1147 // logic is the same as above
1148 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1150 wxColour colFg
= GetDefaultAttributes().colFg
;
1152 if ( !colFg
.IsOk() )
1153 colFg
= GetClassDefaultAttributes().colFg
;
1158 return m_foregroundColour
;
1161 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1163 if ( colour
== m_backgroundColour
)
1166 m_hasBgCol
= colour
.IsOk();
1167 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1168 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1170 m_inheritBgCol
= m_hasBgCol
;
1171 m_backgroundColour
= colour
;
1172 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1176 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1178 if (colour
== m_foregroundColour
)
1181 m_hasFgCol
= colour
.IsOk();
1182 m_inheritFgCol
= m_hasFgCol
;
1183 m_foregroundColour
= colour
;
1184 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1188 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1190 // setting an invalid cursor is ok, it means that we don't have any special
1192 if ( m_cursor
.IsSameAs(cursor
) )
1203 wxFont
wxWindowBase::GetFont() const
1205 // logic is the same as in GetBackgroundColour()
1206 if ( !m_font
.IsOk() )
1208 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1210 wxFont font
= GetDefaultAttributes().font
;
1212 font
= GetClassDefaultAttributes().font
;
1220 bool wxWindowBase::SetFont(const wxFont
& font
)
1222 if ( font
== m_font
)
1229 m_hasFont
= font
.IsOk();
1230 m_inheritFont
= m_hasFont
;
1232 InvalidateBestSize();
1239 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1241 m_hasCustomPalette
= true;
1244 // VZ: can anyone explain me what do we do here?
1245 wxWindowDC
d((wxWindow
*) this);
1249 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1251 wxWindow
*win
= (wxWindow
*)this;
1252 while ( win
&& !win
->HasCustomPalette() )
1254 win
= win
->GetParent();
1260 #endif // wxUSE_PALETTE
1263 void wxWindowBase::SetCaret(wxCaret
*caret
)
1274 wxASSERT_MSG( m_caret
->GetWindow() == this,
1275 wxT("caret should be created associated to this window") );
1278 #endif // wxUSE_CARET
1280 #if wxUSE_VALIDATORS
1281 // ----------------------------------------------------------------------------
1283 // ----------------------------------------------------------------------------
1285 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1287 if ( m_windowValidator
)
1288 delete m_windowValidator
;
1290 m_windowValidator
= (wxValidator
*)validator
.Clone();
1292 if ( m_windowValidator
)
1293 m_windowValidator
->SetWindow(this);
1295 #endif // wxUSE_VALIDATORS
1297 // ----------------------------------------------------------------------------
1298 // update region stuff
1299 // ----------------------------------------------------------------------------
1301 wxRect
wxWindowBase::GetUpdateClientRect() const
1303 wxRegion rgnUpdate
= GetUpdateRegion();
1304 rgnUpdate
.Intersect(GetClientRect());
1305 wxRect rectUpdate
= rgnUpdate
.GetBox();
1306 wxPoint ptOrigin
= GetClientAreaOrigin();
1307 rectUpdate
.x
-= ptOrigin
.x
;
1308 rectUpdate
.y
-= ptOrigin
.y
;
1313 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1315 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1318 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1320 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1323 void wxWindowBase::ClearBackground()
1325 // wxGTK uses its own version, no need to add never used code
1327 wxClientDC
dc((wxWindow
*)this);
1328 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1329 dc
.SetBackground(brush
);
1334 // ----------------------------------------------------------------------------
1335 // find child window by id or name
1336 // ----------------------------------------------------------------------------
1338 wxWindow
*wxWindowBase::FindWindow(long id
) const
1340 if ( id
== m_windowId
)
1341 return (wxWindow
*)this;
1343 wxWindowBase
*res
= (wxWindow
*)NULL
;
1344 wxWindowList::compatibility_iterator node
;
1345 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1347 wxWindowBase
*child
= node
->GetData();
1348 res
= child
->FindWindow( id
);
1351 return (wxWindow
*)res
;
1354 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1356 if ( name
== m_windowName
)
1357 return (wxWindow
*)this;
1359 wxWindowBase
*res
= (wxWindow
*)NULL
;
1360 wxWindowList::compatibility_iterator node
;
1361 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1363 wxWindow
*child
= node
->GetData();
1364 res
= child
->FindWindow(name
);
1367 return (wxWindow
*)res
;
1371 // find any window by id or name or label: If parent is non-NULL, look through
1372 // children for a label or title matching the specified string. If NULL, look
1373 // through all top-level windows.
1375 // to avoid duplicating code we reuse the same helper function but with
1376 // different comparators
1378 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1379 const wxString
& label
, long id
);
1382 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1385 return win
->GetLabel() == label
;
1389 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1392 return win
->GetName() == label
;
1396 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1399 return win
->GetId() == id
;
1402 // recursive helper for the FindWindowByXXX() functions
1404 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1405 const wxString
& label
,
1407 wxFindWindowCmp cmp
)
1411 // see if this is the one we're looking for
1412 if ( (*cmp
)(parent
, label
, id
) )
1413 return (wxWindow
*)parent
;
1415 // It wasn't, so check all its children
1416 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1418 node
= node
->GetNext() )
1420 // recursively check each child
1421 wxWindow
*win
= (wxWindow
*)node
->GetData();
1422 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1432 // helper for FindWindowByXXX()
1434 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1435 const wxString
& label
,
1437 wxFindWindowCmp cmp
)
1441 // just check parent and all its children
1442 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1445 // start at very top of wx's windows
1446 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1448 node
= node
->GetNext() )
1450 // recursively check each window & its children
1451 wxWindow
*win
= node
->GetData();
1452 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1462 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1464 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1469 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1471 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1475 // fall back to the label
1476 win
= FindWindowByLabel(title
, parent
);
1484 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1486 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1489 // ----------------------------------------------------------------------------
1490 // dialog oriented functions
1491 // ----------------------------------------------------------------------------
1493 void wxWindowBase::MakeModal(bool modal
)
1495 // Disable all other windows
1498 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1501 wxWindow
*win
= node
->GetData();
1503 win
->Enable(!modal
);
1505 node
= node
->GetNext();
1510 bool wxWindowBase::Validate()
1512 #if wxUSE_VALIDATORS
1513 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1515 wxWindowList::compatibility_iterator node
;
1516 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1518 wxWindowBase
*child
= node
->GetData();
1519 wxValidator
*validator
= child
->GetValidator();
1520 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1525 if ( recurse
&& !child
->Validate() )
1530 #endif // wxUSE_VALIDATORS
1535 bool wxWindowBase::TransferDataToWindow()
1537 #if wxUSE_VALIDATORS
1538 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1540 wxWindowList::compatibility_iterator node
;
1541 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1543 wxWindowBase
*child
= node
->GetData();
1544 wxValidator
*validator
= child
->GetValidator();
1545 if ( validator
&& !validator
->TransferToWindow() )
1547 wxLogWarning(_("Could not transfer data to window"));
1549 wxLog::FlushActive();
1557 if ( !child
->TransferDataToWindow() )
1559 // warning already given
1564 #endif // wxUSE_VALIDATORS
1569 bool wxWindowBase::TransferDataFromWindow()
1571 #if wxUSE_VALIDATORS
1572 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1574 wxWindowList::compatibility_iterator node
;
1575 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1577 wxWindow
*child
= node
->GetData();
1578 wxValidator
*validator
= child
->GetValidator();
1579 if ( validator
&& !validator
->TransferFromWindow() )
1581 // nop warning here because the application is supposed to give
1582 // one itself - we don't know here what might have gone wrongly
1589 if ( !child
->TransferDataFromWindow() )
1591 // warning already given
1596 #endif // wxUSE_VALIDATORS
1601 void wxWindowBase::InitDialog()
1603 wxInitDialogEvent
event(GetId());
1604 event
.SetEventObject( this );
1605 GetEventHandler()->ProcessEvent(event
);
1608 // ----------------------------------------------------------------------------
1609 // context-sensitive help support
1610 // ----------------------------------------------------------------------------
1614 // associate this help text with this window
1615 void wxWindowBase::SetHelpText(const wxString
& text
)
1617 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1620 helpProvider
->AddHelp(this, text
);
1624 // associate this help text with all windows with the same id as this
1626 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1628 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1631 helpProvider
->AddHelp(GetId(), text
);
1635 // get the help string associated with this window (may be empty)
1636 // default implementation forwards calls to the help provider
1638 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1639 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1642 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1645 text
= helpProvider
->GetHelp(this);
1651 // show help for this window
1652 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1654 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1657 if ( helpProvider
->ShowHelpAtPoint(this, event
.GetPosition(), event
.GetOrigin()) )
1659 // skip the event.Skip() below
1667 #endif // wxUSE_HELP
1669 // ----------------------------------------------------------------------------
1671 // ----------------------------------------------------------------------------
1675 void wxWindowBase::SetToolTip( const wxString
&tip
)
1677 // don't create the new tooltip if we already have one
1680 m_tooltip
->SetTip( tip
);
1684 SetToolTip( new wxToolTip( tip
) );
1687 // setting empty tooltip text does not remove the tooltip any more - use
1688 // SetToolTip((wxToolTip *)NULL) for this
1691 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1693 if ( m_tooltip
!= tooltip
)
1698 m_tooltip
= tooltip
;
1702 #endif // wxUSE_TOOLTIPS
1704 // ----------------------------------------------------------------------------
1705 // constraints and sizers
1706 // ----------------------------------------------------------------------------
1708 #if wxUSE_CONSTRAINTS
1710 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1712 if ( m_constraints
)
1714 UnsetConstraints(m_constraints
);
1715 delete m_constraints
;
1717 m_constraints
= constraints
;
1718 if ( m_constraints
)
1720 // Make sure other windows know they're part of a 'meaningful relationship'
1721 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1722 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1723 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1724 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1725 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1726 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1727 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1728 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1729 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1730 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1731 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1732 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1733 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1734 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1735 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1736 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1740 // This removes any dangling pointers to this window in other windows'
1741 // constraintsInvolvedIn lists.
1742 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1746 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1747 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1748 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1749 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1750 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1751 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1752 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1753 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1754 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1755 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1756 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1757 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1758 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1759 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1760 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1761 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1765 // Back-pointer to other windows we're involved with, so if we delete this
1766 // window, we must delete any constraints we're involved with.
1767 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1769 if ( !m_constraintsInvolvedIn
)
1770 m_constraintsInvolvedIn
= new wxWindowList
;
1771 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1772 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1775 // REMOVE back-pointer to other windows we're involved with.
1776 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1778 if ( m_constraintsInvolvedIn
)
1779 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1782 // Reset any constraints that mention this window
1783 void wxWindowBase::DeleteRelatedConstraints()
1785 if ( m_constraintsInvolvedIn
)
1787 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1790 wxWindow
*win
= node
->GetData();
1791 wxLayoutConstraints
*constr
= win
->GetConstraints();
1793 // Reset any constraints involving this window
1796 constr
->left
.ResetIfWin(this);
1797 constr
->top
.ResetIfWin(this);
1798 constr
->right
.ResetIfWin(this);
1799 constr
->bottom
.ResetIfWin(this);
1800 constr
->width
.ResetIfWin(this);
1801 constr
->height
.ResetIfWin(this);
1802 constr
->centreX
.ResetIfWin(this);
1803 constr
->centreY
.ResetIfWin(this);
1806 wxWindowList::compatibility_iterator next
= node
->GetNext();
1807 m_constraintsInvolvedIn
->Erase(node
);
1811 delete m_constraintsInvolvedIn
;
1812 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1816 #endif // wxUSE_CONSTRAINTS
1818 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1820 if ( sizer
== m_windowSizer
)
1823 if ( m_windowSizer
)
1825 m_windowSizer
->SetContainingWindow(NULL
);
1828 delete m_windowSizer
;
1831 m_windowSizer
= sizer
;
1832 if ( m_windowSizer
)
1834 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
1837 SetAutoLayout(m_windowSizer
!= NULL
);
1840 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1842 SetSizer( sizer
, deleteOld
);
1843 sizer
->SetSizeHints( (wxWindow
*) this );
1847 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1849 // adding a window to a sizer twice is going to result in fatal and
1850 // hard to debug problems later because when deleting the second
1851 // associated wxSizerItem we're going to dereference a dangling
1852 // pointer; so try to detect this as early as possible
1853 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1854 _T("Adding a window to the same sizer twice?") );
1856 m_containingSizer
= sizer
;
1859 #if wxUSE_CONSTRAINTS
1861 void wxWindowBase::SatisfyConstraints()
1863 wxLayoutConstraints
*constr
= GetConstraints();
1864 bool wasOk
= constr
&& constr
->AreSatisfied();
1866 ResetConstraints(); // Mark all constraints as unevaluated
1870 // if we're a top level panel (i.e. our parent is frame/dialog), our
1871 // own constraints will never be satisfied any more unless we do it
1875 while ( noChanges
> 0 )
1877 LayoutPhase1(&noChanges
);
1881 LayoutPhase2(&noChanges
);
1884 #endif // wxUSE_CONSTRAINTS
1886 bool wxWindowBase::Layout()
1888 // If there is a sizer, use it instead of the constraints
1892 GetVirtualSize(&w
, &h
);
1893 GetSizer()->SetDimension( 0, 0, w
, h
);
1895 #if wxUSE_CONSTRAINTS
1898 SatisfyConstraints(); // Find the right constraints values
1899 SetConstraintSizes(); // Recursively set the real window sizes
1906 #if wxUSE_CONSTRAINTS
1908 // first phase of the constraints evaluation: set our own constraints
1909 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1911 wxLayoutConstraints
*constr
= GetConstraints();
1913 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1916 // second phase: set the constraints for our children
1917 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1924 // Layout grand children
1930 // Do a phase of evaluating child constraints
1931 bool wxWindowBase::DoPhase(int phase
)
1933 // the list containing the children for which the constraints are already
1935 wxWindowList succeeded
;
1937 // the max number of iterations we loop before concluding that we can't set
1939 static const int maxIterations
= 500;
1941 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1945 // loop over all children setting their constraints
1946 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1948 node
= node
->GetNext() )
1950 wxWindow
*child
= node
->GetData();
1951 if ( child
->IsTopLevel() )
1953 // top level children are not inside our client area
1957 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1959 // this one is either already ok or nothing we can do about it
1963 int tempNoChanges
= 0;
1964 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1965 : child
->LayoutPhase2(&tempNoChanges
);
1966 noChanges
+= tempNoChanges
;
1970 succeeded
.Append(child
);
1976 // constraints are set
1984 void wxWindowBase::ResetConstraints()
1986 wxLayoutConstraints
*constr
= GetConstraints();
1989 constr
->left
.SetDone(false);
1990 constr
->top
.SetDone(false);
1991 constr
->right
.SetDone(false);
1992 constr
->bottom
.SetDone(false);
1993 constr
->width
.SetDone(false);
1994 constr
->height
.SetDone(false);
1995 constr
->centreX
.SetDone(false);
1996 constr
->centreY
.SetDone(false);
1999 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2002 wxWindow
*win
= node
->GetData();
2003 if ( !win
->IsTopLevel() )
2004 win
->ResetConstraints();
2005 node
= node
->GetNext();
2009 // Need to distinguish between setting the 'fake' size for windows and sizers,
2010 // and setting the real values.
2011 void wxWindowBase::SetConstraintSizes(bool recurse
)
2013 wxLayoutConstraints
*constr
= GetConstraints();
2014 if ( constr
&& constr
->AreSatisfied() )
2016 int x
= constr
->left
.GetValue();
2017 int y
= constr
->top
.GetValue();
2018 int w
= constr
->width
.GetValue();
2019 int h
= constr
->height
.GetValue();
2021 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
2022 (constr
->height
.GetRelationship() != wxAsIs
) )
2024 SetSize(x
, y
, w
, h
);
2028 // If we don't want to resize this window, just move it...
2034 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
2035 GetClassInfo()->GetClassName(),
2041 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2044 wxWindow
*win
= node
->GetData();
2045 if ( !win
->IsTopLevel() && win
->GetConstraints() )
2046 win
->SetConstraintSizes();
2047 node
= node
->GetNext();
2052 // Only set the size/position of the constraint (if any)
2053 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
2055 wxLayoutConstraints
*constr
= GetConstraints();
2058 if ( x
!= wxDefaultCoord
)
2060 constr
->left
.SetValue(x
);
2061 constr
->left
.SetDone(true);
2063 if ( y
!= wxDefaultCoord
)
2065 constr
->top
.SetValue(y
);
2066 constr
->top
.SetDone(true);
2068 if ( w
!= wxDefaultCoord
)
2070 constr
->width
.SetValue(w
);
2071 constr
->width
.SetDone(true);
2073 if ( h
!= wxDefaultCoord
)
2075 constr
->height
.SetValue(h
);
2076 constr
->height
.SetDone(true);
2081 void wxWindowBase::MoveConstraint(int x
, int y
)
2083 wxLayoutConstraints
*constr
= GetConstraints();
2086 if ( x
!= wxDefaultCoord
)
2088 constr
->left
.SetValue(x
);
2089 constr
->left
.SetDone(true);
2091 if ( y
!= wxDefaultCoord
)
2093 constr
->top
.SetValue(y
);
2094 constr
->top
.SetDone(true);
2099 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2101 wxLayoutConstraints
*constr
= GetConstraints();
2104 *w
= constr
->width
.GetValue();
2105 *h
= constr
->height
.GetValue();
2111 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2113 wxLayoutConstraints
*constr
= GetConstraints();
2116 *w
= constr
->width
.GetValue();
2117 *h
= constr
->height
.GetValue();
2120 GetClientSize(w
, h
);
2123 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2125 wxLayoutConstraints
*constr
= GetConstraints();
2128 *x
= constr
->left
.GetValue();
2129 *y
= constr
->top
.GetValue();
2135 #endif // wxUSE_CONSTRAINTS
2137 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2139 // don't do it for the dialogs/frames - they float independently of their
2141 if ( !IsTopLevel() )
2143 wxWindow
*parent
= GetParent();
2144 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2146 wxPoint
pt(parent
->GetClientAreaOrigin());
2153 // ----------------------------------------------------------------------------
2154 // Update UI processing
2155 // ----------------------------------------------------------------------------
2157 void wxWindowBase::UpdateWindowUI(long flags
)
2159 wxUpdateUIEvent
event(GetId());
2160 event
.SetEventObject(this);
2162 if ( GetEventHandler()->ProcessEvent(event
) )
2164 DoUpdateWindowUI(event
);
2167 if (flags
& wxUPDATE_UI_RECURSE
)
2169 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2172 wxWindow
* child
= (wxWindow
*) node
->GetData();
2173 child
->UpdateWindowUI(flags
);
2174 node
= node
->GetNext();
2179 // do the window-specific processing after processing the update event
2180 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2182 if ( event
.GetSetEnabled() )
2183 Enable(event
.GetEnabled());
2185 if ( event
.GetSetShown() )
2186 Show(event
.GetShown());
2189 // ----------------------------------------------------------------------------
2190 // dialog units translations
2191 // ----------------------------------------------------------------------------
2193 wxPoint
wxWindowBase::ConvertPixelsToDialog(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
* 4) / charWidth
);
2200 if (pt
.y
!= wxDefaultCoord
)
2201 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2206 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2208 int charWidth
= GetCharWidth();
2209 int charHeight
= GetCharHeight();
2210 wxPoint pt2
= wxDefaultPosition
;
2211 if (pt
.x
!= wxDefaultCoord
)
2212 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2213 if (pt
.y
!= wxDefaultCoord
)
2214 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2219 // ----------------------------------------------------------------------------
2221 // ----------------------------------------------------------------------------
2223 // propagate the colour change event to the subwindows
2224 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2226 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2229 // Only propagate to non-top-level windows
2230 wxWindow
*win
= node
->GetData();
2231 if ( !win
->IsTopLevel() )
2233 wxSysColourChangedEvent event2
;
2234 event
.SetEventObject(win
);
2235 win
->GetEventHandler()->ProcessEvent(event2
);
2238 node
= node
->GetNext();
2244 // the default action is to populate dialog with data when it's created,
2245 // and nudge the UI into displaying itself correctly in case
2246 // we've turned the wxUpdateUIEvents frequency down low.
2247 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2249 TransferDataToWindow();
2251 // Update the UI at this point
2252 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2255 // ----------------------------------------------------------------------------
2256 // menu-related functions
2257 // ----------------------------------------------------------------------------
2261 bool wxWindowBase::PopupMenu(wxMenu
*menu
, int x
, int y
)
2263 wxCHECK_MSG( menu
, false, "can't popup NULL menu" );
2265 wxCurrentPopupMenu
= menu
;
2266 const bool rc
= DoPopupMenu(menu
, x
, y
);
2267 wxCurrentPopupMenu
= NULL
;
2272 // this is used to pass the id of the selected item from the menu event handler
2273 // to the main function itself
2275 // it's ok to use a global here as there can be at most one popup menu shown at
2277 static int gs_popupMenuSelection
= wxID_NONE
;
2279 void wxWindowBase::InternalOnPopupMenu(wxCommandEvent
& event
)
2281 // store the id in a global variable where we'll retrieve it from later
2282 gs_popupMenuSelection
= event
.GetId();
2286 wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu
& menu
, int x
, int y
)
2288 gs_popupMenuSelection
= wxID_NONE
;
2290 Connect(wxEVT_COMMAND_MENU_SELECTED
,
2291 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2295 PopupMenu(&menu
, x
, y
);
2297 Disconnect(wxEVT_COMMAND_MENU_SELECTED
,
2298 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2302 return gs_popupMenuSelection
;
2305 #endif // wxUSE_MENUS
2307 // methods for drawing the sizers in a visible way
2310 static void DrawSizers(wxWindowBase
*win
);
2312 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2314 wxClientDC
dc((wxWindow
*)win
);
2315 dc
.SetPen(*wxRED_PEN
);
2316 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2317 dc
.DrawRectangle(rect
.Deflate(1, 1));
2320 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2322 const wxSizerItemList
& items
= sizer
->GetChildren();
2323 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2328 wxSizerItem
*item
= *i
;
2329 if ( item
->IsSizer() )
2331 DrawBorder(win
, item
->GetRect().Deflate(2));
2332 DrawSizer(win
, item
->GetSizer());
2334 else if ( item
->IsSpacer() )
2336 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2338 else if ( item
->IsWindow() )
2340 DrawSizers(item
->GetWindow());
2345 static void DrawSizers(wxWindowBase
*win
)
2347 wxSizer
*sizer
= win
->GetSizer();
2350 DrawBorder(win
, win
->GetClientSize());
2351 DrawSizer(win
, sizer
);
2353 else // no sizer, still recurse into the children
2355 const wxWindowList
& children
= win
->GetChildren();
2356 for ( wxWindowList::const_iterator i
= children
.begin(),
2357 end
= children
.end();
2366 #endif // __WXDEBUG__
2368 // process special middle clicks
2369 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2371 if ( event
.ControlDown() && event
.AltDown() )
2374 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2375 if ( event
.ShiftDown() )
2380 #endif // __WXDEBUG__
2381 ::wxInfoMessageBox((wxWindow
*)this);
2389 // ----------------------------------------------------------------------------
2391 // ----------------------------------------------------------------------------
2393 #if wxUSE_ACCESSIBILITY
2394 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2396 if (m_accessible
&& (accessible
!= m_accessible
))
2397 delete m_accessible
;
2398 m_accessible
= accessible
;
2400 m_accessible
->SetWindow((wxWindow
*) this);
2403 // Returns the accessible object, creating if necessary.
2404 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2407 m_accessible
= CreateAccessible();
2408 return m_accessible
;
2411 // Override to create a specific accessible object.
2412 wxAccessible
* wxWindowBase::CreateAccessible()
2414 return new wxWindowAccessible((wxWindow
*) this);
2419 // ----------------------------------------------------------------------------
2420 // list classes implementation
2421 // ----------------------------------------------------------------------------
2425 #include "wx/listimpl.cpp"
2426 WX_DEFINE_LIST(wxWindowList
)
2430 void wxWindowListNode::DeleteData()
2432 delete (wxWindow
*)GetData();
2435 #endif // wxUSE_STL/!wxUSE_STL
2437 // ----------------------------------------------------------------------------
2439 // ----------------------------------------------------------------------------
2441 wxBorder
wxWindowBase::GetBorder(long flags
) const
2443 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2444 if ( border
== wxBORDER_DEFAULT
)
2446 border
= GetDefaultBorder();
2448 else if ( border
== wxBORDER_THEME
)
2450 border
= GetDefaultBorderForControl();
2456 wxBorder
wxWindowBase::GetDefaultBorder() const
2458 return wxBORDER_NONE
;
2461 // ----------------------------------------------------------------------------
2463 // ----------------------------------------------------------------------------
2465 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2467 // here we just check if the point is inside the window or not
2469 // check the top and left border first
2470 bool outside
= x
< 0 || y
< 0;
2473 // check the right and bottom borders too
2474 wxSize size
= GetSize();
2475 outside
= x
>= size
.x
|| y
>= size
.y
;
2478 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2481 // ----------------------------------------------------------------------------
2483 // ----------------------------------------------------------------------------
2485 struct WXDLLEXPORT wxWindowNext
2489 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2490 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2491 bool wxWindowBase::ms_winCaptureChanging
= false;
2493 void wxWindowBase::CaptureMouse()
2495 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2497 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2499 ms_winCaptureChanging
= true;
2501 wxWindow
*winOld
= GetCapture();
2504 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2507 wxWindowNext
*item
= new wxWindowNext
;
2509 item
->next
= ms_winCaptureNext
;
2510 ms_winCaptureNext
= item
;
2512 //else: no mouse capture to save
2515 ms_winCaptureCurrent
= (wxWindow
*)this;
2517 ms_winCaptureChanging
= false;
2520 void wxWindowBase::ReleaseMouse()
2522 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2524 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2526 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2528 ms_winCaptureChanging
= true;
2531 ms_winCaptureCurrent
= NULL
;
2533 if ( ms_winCaptureNext
)
2535 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2536 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2538 wxWindowNext
*item
= ms_winCaptureNext
;
2539 ms_winCaptureNext
= item
->next
;
2542 //else: stack is empty, no previous capture
2544 ms_winCaptureChanging
= false;
2546 wxLogTrace(_T("mousecapture"),
2547 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2548 wx_static_cast(void*, GetCapture()));
2551 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2553 wxMouseCaptureLostEvent
event(win
->GetId());
2554 event
.SetEventObject(win
);
2555 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2557 // windows must handle this event, otherwise the app wouldn't behave
2558 // correctly if it loses capture unexpectedly; see the discussion here:
2559 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
2560 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
2561 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2566 void wxWindowBase::NotifyCaptureLost()
2568 // don't do anything if capture lost was expected, i.e. resulted from
2569 // a wx call to ReleaseMouse or CaptureMouse:
2570 if ( ms_winCaptureChanging
)
2573 // if the capture was lost unexpectedly, notify every window that has
2574 // capture (on stack or current) about it and clear the stack:
2576 if ( ms_winCaptureCurrent
)
2578 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2579 ms_winCaptureCurrent
= NULL
;
2582 while ( ms_winCaptureNext
)
2584 wxWindowNext
*item
= ms_winCaptureNext
;
2585 ms_winCaptureNext
= item
->next
;
2587 DoNotifyWindowAboutCaptureLost(item
->win
);
2596 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2597 int WXUNUSED(modifiers
),
2598 int WXUNUSED(keycode
))
2604 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2610 #endif // wxUSE_HOTKEY
2612 // ----------------------------------------------------------------------------
2614 // ----------------------------------------------------------------------------
2616 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2618 #if wxUSE_VALIDATORS
2619 // Can only use the validator of the window which
2620 // is receiving the event
2621 if ( event
.GetEventObject() == this )
2623 wxValidator
*validator
= GetValidator();
2624 if ( validator
&& validator
->ProcessEvent(event
) )
2629 #endif // wxUSE_VALIDATORS
2634 bool wxWindowBase::TryParent(wxEvent
& event
)
2636 // carry on up the parent-child hierarchy if the propagation count hasn't
2638 if ( event
.ShouldPropagate() )
2640 // honour the requests to stop propagation at this window: this is
2641 // used by the dialogs, for example, to prevent processing the events
2642 // from the dialog controls in the parent frame which rarely, if ever,
2644 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2646 wxWindow
*parent
= GetParent();
2647 if ( parent
&& !parent
->IsBeingDeleted() )
2649 wxPropagateOnce
propagateOnce(event
);
2651 return parent
->GetEventHandler()->ProcessEvent(event
);
2656 return wxEvtHandler::TryParent(event
);
2659 // ----------------------------------------------------------------------------
2660 // window relationships
2661 // ----------------------------------------------------------------------------
2663 wxWindow
*wxWindowBase::DoGetSibling(WindowOrder order
) const
2665 wxCHECK_MSG( GetParent(), NULL
,
2666 _T("GetPrev/NextSibling() don't work for TLWs!") );
2668 wxWindowList
& siblings
= GetParent()->GetChildren();
2669 wxWindowList::compatibility_iterator i
= siblings
.Find((wxWindow
*)this);
2670 wxCHECK_MSG( i
, NULL
, _T("window not a child of its parent?") );
2672 if ( order
== OrderBefore
)
2673 i
= i
->GetPrevious();
2677 return i
? i
->GetData() : NULL
;
2680 // ----------------------------------------------------------------------------
2681 // keyboard navigation
2682 // ----------------------------------------------------------------------------
2684 // Navigates in the specified direction inside this window
2685 bool wxWindowBase::DoNavigateIn(int flags
)
2687 #ifdef wxHAS_NATIVE_TAB_TRAVERSAL
2688 // native code doesn't process our wxNavigationKeyEvents anyhow
2691 #else // !wxHAS_NATIVE_TAB_TRAVERSAL
2692 wxNavigationKeyEvent eventNav
;
2693 eventNav
.SetFlags(flags
);
2694 eventNav
.SetEventObject(FindFocus());
2695 return GetEventHandler()->ProcessEvent(eventNav
);
2696 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
2699 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, WindowOrder move
)
2701 // check that we're not a top level window
2702 wxCHECK_RET( GetParent(),
2703 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2705 // detect the special case when we have nothing to do anyhow and when the
2706 // code below wouldn't work
2710 // find the target window in the siblings list
2711 wxWindowList
& siblings
= GetParent()->GetChildren();
2712 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2713 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2715 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2716 // can't just move the node around
2717 wxWindow
*self
= (wxWindow
*)this;
2718 siblings
.DeleteObject(self
);
2719 if ( move
== OrderAfter
)
2726 siblings
.Insert(i
, self
);
2728 else // OrderAfter and win was the last sibling
2730 siblings
.Append(self
);
2734 // ----------------------------------------------------------------------------
2736 // ----------------------------------------------------------------------------
2738 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2740 wxWindowBase
*win
= DoFindFocus();
2741 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2744 // ----------------------------------------------------------------------------
2746 // ----------------------------------------------------------------------------
2748 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2750 while ( win
&& !win
->IsTopLevel() )
2751 win
= win
->GetParent();
2756 #if wxUSE_ACCESSIBILITY
2757 // ----------------------------------------------------------------------------
2758 // accessible object for windows
2759 // ----------------------------------------------------------------------------
2761 // Can return either a child object, or an integer
2762 // representing the child element, starting from 1.
2763 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2765 wxASSERT( GetWindow() != NULL
);
2769 return wxACC_NOT_IMPLEMENTED
;
2772 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2773 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2775 wxASSERT( GetWindow() != NULL
);
2779 wxWindow
* win
= NULL
;
2786 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2788 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2795 rect
= win
->GetRect();
2796 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2797 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2801 return wxACC_NOT_IMPLEMENTED
;
2804 // Navigates from fromId to toId/toObject.
2805 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2806 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2808 wxASSERT( GetWindow() != NULL
);
2814 case wxNAVDIR_FIRSTCHILD
:
2816 if (GetWindow()->GetChildren().GetCount() == 0)
2818 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2819 *toObject
= childWindow
->GetOrCreateAccessible();
2823 case wxNAVDIR_LASTCHILD
:
2825 if (GetWindow()->GetChildren().GetCount() == 0)
2827 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2828 *toObject
= childWindow
->GetOrCreateAccessible();
2832 case wxNAVDIR_RIGHT
:
2836 wxWindowList::compatibility_iterator node
=
2837 wxWindowList::compatibility_iterator();
2840 // Can't navigate to sibling of this window
2841 // if we're a top-level window.
2842 if (!GetWindow()->GetParent())
2843 return wxACC_NOT_IMPLEMENTED
;
2845 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2849 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2850 node
= GetWindow()->GetChildren().Item(fromId
-1);
2853 if (node
&& node
->GetNext())
2855 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2856 *toObject
= nextWindow
->GetOrCreateAccessible();
2864 case wxNAVDIR_PREVIOUS
:
2866 wxWindowList::compatibility_iterator node
=
2867 wxWindowList::compatibility_iterator();
2870 // Can't navigate to sibling of this window
2871 // if we're a top-level window.
2872 if (!GetWindow()->GetParent())
2873 return wxACC_NOT_IMPLEMENTED
;
2875 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2879 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2880 node
= GetWindow()->GetChildren().Item(fromId
-1);
2883 if (node
&& node
->GetPrevious())
2885 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2886 *toObject
= previousWindow
->GetOrCreateAccessible();
2894 return wxACC_NOT_IMPLEMENTED
;
2897 // Gets the name of the specified object.
2898 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2900 wxASSERT( GetWindow() != NULL
);
2906 // If a child, leave wxWidgets to call the function on the actual
2909 return wxACC_NOT_IMPLEMENTED
;
2911 // This will eventually be replaced by specialised
2912 // accessible classes, one for each kind of wxWidgets
2913 // control or window.
2915 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2916 title
= ((wxButton
*) GetWindow())->GetLabel();
2919 title
= GetWindow()->GetName();
2927 return wxACC_NOT_IMPLEMENTED
;
2930 // Gets the number of children.
2931 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2933 wxASSERT( GetWindow() != NULL
);
2937 *childId
= (int) GetWindow()->GetChildren().GetCount();
2941 // Gets the specified child (starting from 1).
2942 // If *child is NULL and return value is wxACC_OK,
2943 // this means that the child is a simple element and
2944 // not an accessible object.
2945 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2947 wxASSERT( GetWindow() != NULL
);
2957 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2960 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2961 *child
= childWindow
->GetOrCreateAccessible();
2968 // Gets the parent, or NULL.
2969 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2971 wxASSERT( GetWindow() != NULL
);
2975 wxWindow
* parentWindow
= GetWindow()->GetParent();
2983 *parent
= parentWindow
->GetOrCreateAccessible();
2991 // Performs the default action. childId is 0 (the action for this object)
2992 // or > 0 (the action for a child).
2993 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2994 // window (e.g. an edit control).
2995 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2997 wxASSERT( GetWindow() != NULL
);
3001 return wxACC_NOT_IMPLEMENTED
;
3004 // Gets the default action for this object (0) or > 0 (the action for a child).
3005 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
3006 // string if there is no action.
3007 // The retrieved string describes the action that is performed on an object,
3008 // not what the object does as a result. For example, a toolbar button that prints
3009 // a document has a default action of "Press" rather than "Prints the current document."
3010 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
3012 wxASSERT( GetWindow() != NULL
);
3016 return wxACC_NOT_IMPLEMENTED
;
3019 // Returns the description for this object or a child.
3020 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
3022 wxASSERT( GetWindow() != NULL
);
3026 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3032 return wxACC_NOT_IMPLEMENTED
;
3035 // Returns help text for this object or a child, similar to tooltip text.
3036 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
3038 wxASSERT( GetWindow() != NULL
);
3042 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3048 return wxACC_NOT_IMPLEMENTED
;
3051 // Returns the keyboard shortcut for this object or child.
3052 // Return e.g. ALT+K
3053 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
3055 wxASSERT( GetWindow() != NULL
);
3059 return wxACC_NOT_IMPLEMENTED
;
3062 // Returns a role constant.
3063 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
3065 wxASSERT( GetWindow() != NULL
);
3069 // If a child, leave wxWidgets to call the function on the actual
3072 return wxACC_NOT_IMPLEMENTED
;
3074 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3075 return wxACC_NOT_IMPLEMENTED
;
3077 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3078 return wxACC_NOT_IMPLEMENTED
;
3081 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3082 return wxACC_NOT_IMPLEMENTED
;
3085 //*role = wxROLE_SYSTEM_CLIENT;
3086 *role
= wxROLE_SYSTEM_CLIENT
;
3090 return wxACC_NOT_IMPLEMENTED
;
3094 // Returns a state constant.
3095 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
3097 wxASSERT( GetWindow() != NULL
);
3101 // If a child, leave wxWidgets to call the function on the actual
3104 return wxACC_NOT_IMPLEMENTED
;
3106 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3107 return wxACC_NOT_IMPLEMENTED
;
3110 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3111 return wxACC_NOT_IMPLEMENTED
;
3114 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3115 return wxACC_NOT_IMPLEMENTED
;
3122 return wxACC_NOT_IMPLEMENTED
;
3126 // Returns a localized string representing the value for the object
3128 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3130 wxASSERT( GetWindow() != NULL
);
3134 return wxACC_NOT_IMPLEMENTED
;
3137 // Selects the object or child.
3138 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3140 wxASSERT( GetWindow() != NULL
);
3144 return wxACC_NOT_IMPLEMENTED
;
3147 // Gets the window with the keyboard focus.
3148 // If childId is 0 and child is NULL, no object in
3149 // this subhierarchy has the focus.
3150 // If this object has the focus, child should be 'this'.
3151 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3153 wxASSERT( GetWindow() != NULL
);
3157 return wxACC_NOT_IMPLEMENTED
;
3161 // Gets a variant representing the selected children
3163 // Acceptable values:
3164 // - a null variant (IsNull() returns true)
3165 // - a list variant (GetType() == wxT("list")
3166 // - an integer representing the selected child element,
3167 // or 0 if this object is selected (GetType() == wxT("long")
3168 // - a "void*" pointer to a wxAccessible child object
3169 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3171 wxASSERT( GetWindow() != NULL
);
3175 return wxACC_NOT_IMPLEMENTED
;
3177 #endif // wxUSE_VARIANT
3179 #endif // wxUSE_ACCESSIBILITY
3181 // ----------------------------------------------------------------------------
3183 // ----------------------------------------------------------------------------
3186 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3188 wxCoord widthTotal
) const
3190 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3192 x
= widthTotal
- x
- width
;
3198 // ----------------------------------------------------------------------------
3199 // Window (and menu items) identifiers management
3200 // ----------------------------------------------------------------------------
3205 // this array contains, in packed form, the "in use" flags for the entire
3206 // auto-generated ids range: N-th element of the array contains the flags for
3207 // ids in [wxID_AUTO_LOWEST + 8*N, wxID_AUTO_LOWEST + 8*N + 7] range
3209 // initially no ids are in use and we allocate them consecutively, but after we
3210 // exhaust the entire range, we wrap around and reuse the ids freed in the
3212 wxByte gs_autoIdsInUse
[(wxID_AUTO_HIGHEST
- wxID_AUTO_LOWEST
+ 1)/8 + 1] = { 0 };
3214 // this is an optimization used until we wrap around wxID_AUTO_HIGHEST: if this
3215 // value is < wxID_AUTO_HIGHEST we know that we haven't wrapped yet and so can
3216 // allocate the ids simply by incrementing it
3217 static wxWindowID gs_nextControlId
= wxID_AUTO_LOWEST
;
3219 void MarkAutoIdUsed(wxWindowID id
)
3221 id
-= wxID_AUTO_LOWEST
;
3223 const int theByte
= id
/ 8;
3224 const int theBit
= id
% 8;
3226 gs_autoIdsInUse
[theByte
] |= 1 << theBit
;
3229 void FreeAutoId(wxWindowID id
)
3231 id
-= wxID_AUTO_LOWEST
;
3233 const int theByte
= id
/ 8;
3234 const int theBit
= id
% 8;
3236 gs_autoIdsInUse
[theByte
] &= ~(1 << theBit
);
3239 bool IsAutoIdInUse(wxWindowID id
)
3241 id
-= wxID_AUTO_LOWEST
;
3243 const int theByte
= id
/ 8;
3244 const int theBit
= id
% 8;
3246 return (gs_autoIdsInUse
[theByte
] & (1 << theBit
)) != 0;
3249 } // anonymous namespace
3253 bool wxWindowBase::IsAutoGeneratedId(wxWindowID id
)
3255 if ( id
< wxID_AUTO_LOWEST
|| id
> wxID_AUTO_HIGHEST
)
3258 // we shouldn't have any stray ids in this range
3259 wxASSERT_MSG( IsAutoIdInUse(id
), "unused automatically generated id?" );
3264 wxWindowID
wxWindowBase::NewControlId(int count
)
3266 wxASSERT_MSG( count
> 0, "can't allocate less than 1 id" );
3268 if ( gs_nextControlId
+ count
- 1 <= wxID_AUTO_HIGHEST
)
3270 // we haven't wrapped yet, so we can just grab the next count ids
3271 wxWindowID id
= gs_nextControlId
;
3274 MarkAutoIdUsed(gs_nextControlId
++);
3278 else // we've already wrapped or are now going to
3280 // brute-force search for the id values
3282 // number of consecutive free ids found so far
3285 for ( wxWindowID id
= wxID_AUTO_LOWEST
; id
<= wxID_AUTO_HIGHEST
; id
++ )
3287 if ( !IsAutoIdInUse(id
) )
3289 // found another consecutive available id
3291 if ( found
== count
)
3293 // mark all count consecutive free ids we found as being in
3294 // use now and rewind back to the start of available range
3297 MarkAutoIdUsed(id
--);
3302 else // this id is in use
3304 // reset the number of consecutive free values found
3310 // if we get here, there are not enough consecutive free ids
3314 void wxWindowBase::ReleaseControlId(wxWindowID id
)
3316 wxCHECK_RET( IsAutoGeneratedId(id
), "can't release non auto-generated id" );