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;
177 #if wxUSE_DRAG_AND_DROP
178 m_dropTarget
= (wxDropTarget
*)NULL
;
179 #endif // wxUSE_DRAG_AND_DROP
182 m_tooltip
= (wxToolTip
*)NULL
;
183 #endif // wxUSE_TOOLTIPS
186 m_caret
= (wxCaret
*)NULL
;
187 #endif // wxUSE_CARET
190 m_hasCustomPalette
= false;
191 #endif // wxUSE_PALETTE
193 #if wxUSE_ACCESSIBILITY
197 m_virtualSize
= wxDefaultSize
;
199 m_scrollHelper
= (wxScrollHelper
*) NULL
;
201 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
202 #if wxUSE_SYSTEM_OPTIONS
203 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
205 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
209 // Whether we're using the current theme for this window (wxGTK only for now)
210 m_themeEnabled
= false;
212 // VZ: this one shouldn't exist...
213 m_isBeingDeleted
= false;
218 // common part of window creation process
219 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
221 const wxPoint
& WXUNUSED(pos
),
222 const wxSize
& WXUNUSED(size
),
224 const wxValidator
& wxVALIDATOR_PARAM(validator
),
225 const wxString
& name
)
228 // wxGTK doesn't allow to create controls with static box as the parent so
229 // this will result in a crash when the program is ported to wxGTK so warn
232 // if you get this assert, the correct solution is to create the controls
233 // as siblings of the static box
234 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
235 _T("wxStaticBox can't be used as a window parent!") );
236 #endif // wxUSE_STATBOX
238 // ids are limited to 16 bits under MSW so if you care about portability,
239 // it's not a good idea to use ids out of this range (and negative ids are
240 // reserved for wxWidgets own usage)
241 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767) ||
242 (id
>= wxID_AUTO_LOWEST
&& id
<= wxID_AUTO_HIGHEST
),
243 _T("invalid id value") );
245 // generate a new id if the user doesn't care about it
246 if ( id
== wxID_ANY
)
248 m_windowId
= NewControlId();
250 else // valid id specified
255 // don't use SetWindowStyleFlag() here, this function should only be called
256 // to change the flag after creation as it tries to reflect the changes in
257 // flags by updating the window dynamically and we don't need this here
258 m_windowStyle
= style
;
264 SetValidator(validator
);
265 #endif // wxUSE_VALIDATORS
267 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
268 // have it too - like this it's possible to set it only in the top level
269 // dialog/frame and all children will inherit it by defult
270 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
272 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
278 bool wxWindowBase::ToggleWindowStyle(int flag
)
280 wxASSERT_MSG( flag
, _T("flags with 0 value can't be toggled") );
283 long style
= GetWindowStyleFlag();
289 else // currently off
295 SetWindowStyleFlag(style
);
300 // ----------------------------------------------------------------------------
302 // ----------------------------------------------------------------------------
305 wxWindowBase::~wxWindowBase()
307 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
309 // FIXME if these 2 cases result from programming errors in the user code
310 // we should probably assert here instead of silently fixing them
312 // Just in case the window has been Closed, but we're then deleting
313 // immediately: don't leave dangling pointers.
314 wxPendingDelete
.DeleteObject(this);
316 // Just in case we've loaded a top-level window via LoadNativeDialog but
317 // we weren't a dialog class
318 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
321 // The associated popup menu can still be alive, disassociate from it in
323 if ( wxCurrentPopupMenu
&& wxCurrentPopupMenu
->GetInvokingWindow() == this )
324 wxCurrentPopupMenu
->SetInvokingWindow(NULL
);
325 #endif // wxUSE_MENUS
327 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
329 // notify the parent about this window destruction
331 m_parent
->RemoveChild(this);
335 #endif // wxUSE_CARET
338 delete m_windowValidator
;
339 #endif // wxUSE_VALIDATORS
341 #if wxUSE_CONSTRAINTS
342 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
343 // at deleted windows as they delete themselves.
344 DeleteRelatedConstraints();
348 // This removes any dangling pointers to this window in other windows'
349 // constraintsInvolvedIn lists.
350 UnsetConstraints(m_constraints
);
351 delete m_constraints
;
352 m_constraints
= NULL
;
354 #endif // wxUSE_CONSTRAINTS
356 if ( m_containingSizer
)
357 m_containingSizer
->Detach( (wxWindow
*)this );
359 delete m_windowSizer
;
361 #if wxUSE_DRAG_AND_DROP
363 #endif // wxUSE_DRAG_AND_DROP
367 #endif // wxUSE_TOOLTIPS
369 #if wxUSE_ACCESSIBILITY
374 // NB: this has to be called unconditionally, because we don't know
375 // whether this window has associated help text or not
376 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
378 helpProvider
->RemoveHelp(this);
382 void wxWindowBase::SendDestroyEvent()
384 wxWindowDestroyEvent event
;
385 event
.SetEventObject(this);
386 event
.SetId(GetId());
387 GetEventHandler()->ProcessEvent(event
);
390 bool wxWindowBase::Destroy()
397 bool wxWindowBase::Close(bool force
)
399 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
400 event
.SetEventObject(this);
401 event
.SetCanVeto(!force
);
403 // return false if window wasn't closed because the application vetoed the
405 return HandleWindowEvent(event
) && !event
.GetVeto();
408 bool wxWindowBase::DestroyChildren()
410 wxWindowList::compatibility_iterator node
;
413 // we iterate until the list becomes empty
414 node
= GetChildren().GetFirst();
418 wxWindow
*child
= node
->GetData();
420 // note that we really want to call delete and not ->Destroy() here
421 // because we want to delete the child immediately, before we are
422 // deleted, and delayed deletion would result in problems as our (top
423 // level) child could outlive its parent
426 wxASSERT_MSG( !GetChildren().Find(child
),
427 wxT("child didn't remove itself using RemoveChild()") );
433 // ----------------------------------------------------------------------------
434 // size/position related methods
435 // ----------------------------------------------------------------------------
437 // centre the window with respect to its parent in either (or both) directions
438 void wxWindowBase::DoCentre(int dir
)
440 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
441 _T("this method only implements centering child windows") );
443 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
446 // fits the window around the children
447 void wxWindowBase::Fit()
449 if ( !GetChildren().empty() )
451 SetSize(GetBestSize());
453 //else: do nothing if we have no children
456 // fits virtual size (ie. scrolled area etc.) around children
457 void wxWindowBase::FitInside()
459 if ( GetChildren().GetCount() > 0 )
461 SetVirtualSize( GetBestVirtualSize() );
465 // On Mac, scrollbars are explicitly children.
467 static bool wxHasRealChildren(const wxWindowBase
* win
)
469 int realChildCount
= 0;
471 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
473 node
= node
->GetNext() )
475 wxWindow
*win
= node
->GetData();
476 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
479 return (realChildCount
> 0);
483 void wxWindowBase::InvalidateBestSize()
485 m_bestSizeCache
= wxDefaultSize
;
487 // parent's best size calculation may depend on its children's
488 // as long as child window we are in is not top level window itself
489 // (because the TLW size is never resized automatically)
490 // so let's invalidate it as well to be safe:
491 if (m_parent
&& !IsTopLevel())
492 m_parent
->InvalidateBestSize();
495 // return the size best suited for the current window
496 wxSize
wxWindowBase::DoGetBestSize() const
502 best
= m_windowSizer
->GetMinSize();
504 #if wxUSE_CONSTRAINTS
505 else if ( m_constraints
)
507 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
509 // our minimal acceptable size is such that all our windows fit inside
513 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
515 node
= node
->GetNext() )
517 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
520 // it's not normal that we have an unconstrained child, but
521 // what can we do about it?
525 int x
= c
->right
.GetValue(),
526 y
= c
->bottom
.GetValue();
534 // TODO: we must calculate the overlaps somehow, otherwise we
535 // will never return a size bigger than the current one :-(
538 best
= wxSize(maxX
, maxY
);
540 #endif // wxUSE_CONSTRAINTS
541 else if ( !GetChildren().empty()
543 && wxHasRealChildren(this)
547 // our minimal acceptable size is such that all our visible child
548 // windows fit inside
552 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
554 node
= node
->GetNext() )
556 wxWindow
*win
= node
->GetData();
557 if ( win
->IsTopLevel()
560 || wxDynamicCast(win
, wxStatusBar
)
561 #endif // wxUSE_STATUSBAR
564 // dialogs and frames lie in different top level windows -
565 // don't deal with them here; as for the status bars, they
566 // don't lie in the client area at all
571 win
->GetPosition(&wx
, &wy
);
573 // if the window hadn't been positioned yet, assume that it is in
575 if ( wx
== wxDefaultCoord
)
577 if ( wy
== wxDefaultCoord
)
580 win
->GetSize(&ww
, &wh
);
581 if ( wx
+ ww
> maxX
)
583 if ( wy
+ wh
> maxY
)
587 best
= wxSize(maxX
, maxY
);
589 else // ! has children
591 // for a generic window there is no natural best size so, if the
592 // minimal size is not set, use the current size but take care to
593 // remember it as minimal size for the next time because our best size
594 // should be constant: otherwise we could get into a situation when the
595 // window is initially at some size, then expanded to a larger size and
596 // then, when the containing window is shrunk back (because our initial
597 // best size had been used for computing the parent min size), we can't
598 // be shrunk back any more because our best size is now bigger
599 wxSize size
= GetMinSize();
600 if ( !size
.IsFullySpecified() )
602 size
.SetDefaults(GetSize());
603 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
606 // return as-is, unadjusted by the client size difference.
610 // Add any difference between size and client size
611 wxSize diff
= GetSize() - GetClientSize();
612 best
.x
+= wxMax(0, diff
.x
);
613 best
.y
+= wxMax(0, diff
.y
);
618 // helper of GetWindowBorderSize(): as many ports don't implement support for
619 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
620 // fallbacks in this case
621 static int wxGetMetricOrDefault(wxSystemMetric what
)
623 int rc
= wxSystemSettings::GetMetric(what
);
630 // 2D border is by default 1 pixel wide
636 // 3D borders are by default 2 pixels
641 wxFAIL_MSG( _T("unexpected wxGetMetricOrDefault() argument") );
649 wxSize
wxWindowBase::GetWindowBorderSize() const
653 switch ( GetBorder() )
656 // nothing to do, size is already (0, 0)
659 case wxBORDER_SIMPLE
:
660 case wxBORDER_STATIC
:
661 size
.x
= wxGetMetricOrDefault(wxSYS_BORDER_X
);
662 size
.y
= wxGetMetricOrDefault(wxSYS_BORDER_Y
);
665 case wxBORDER_SUNKEN
:
666 case wxBORDER_RAISED
:
667 size
.x
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X
),
668 wxGetMetricOrDefault(wxSYS_BORDER_X
));
669 size
.y
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y
),
670 wxGetMetricOrDefault(wxSYS_BORDER_Y
));
673 case wxBORDER_DOUBLE
:
674 size
.x
= wxGetMetricOrDefault(wxSYS_EDGE_X
) +
675 wxGetMetricOrDefault(wxSYS_BORDER_X
);
676 size
.y
= wxGetMetricOrDefault(wxSYS_EDGE_Y
) +
677 wxGetMetricOrDefault(wxSYS_BORDER_Y
);
681 wxFAIL_MSG(_T("Unknown border style."));
685 // we have borders on both sides
689 wxSize
wxWindowBase::GetEffectiveMinSize() const
691 // merge the best size with the min size, giving priority to the min size
692 wxSize min
= GetMinSize();
693 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
695 wxSize best
= GetBestSize();
696 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
697 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
703 void wxWindowBase::SetInitialSize(const wxSize
& size
)
705 // Set the min size to the size passed in. This will usually either be
706 // wxDefaultSize or the size passed to this window's ctor/Create function.
709 // Merge the size with the best size if needed
710 wxSize best
= GetEffectiveMinSize();
712 // If the current size doesn't match then change it
713 if (GetSize() != best
)
718 // by default the origin is not shifted
719 wxPoint
wxWindowBase::GetClientAreaOrigin() const
724 wxSize
wxWindowBase::ClientToWindowSize(const wxSize
& size
) const
726 const wxSize
diff(GetSize() - GetClientSize());
728 return wxSize(size
.x
== -1 ? -1 : size
.x
+ diff
.x
,
729 size
.y
== -1 ? -1 : size
.y
+ diff
.y
);
732 wxSize
wxWindowBase::WindowToClientSize(const wxSize
& size
) const
734 const wxSize
diff(GetSize() - GetClientSize());
736 return wxSize(size
.x
== -1 ? -1 : size
.x
- diff
.x
,
737 size
.y
== -1 ? -1 : size
.y
- diff
.y
);
740 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
742 if ( m_windowVariant
!= variant
)
744 m_windowVariant
= variant
;
746 DoSetWindowVariant(variant
);
750 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
752 // adjust the font height to correspond to our new variant (notice that
753 // we're only called if something really changed)
754 wxFont font
= GetFont();
755 int size
= font
.GetPointSize();
758 case wxWINDOW_VARIANT_NORMAL
:
761 case wxWINDOW_VARIANT_SMALL
:
766 case wxWINDOW_VARIANT_MINI
:
771 case wxWINDOW_VARIANT_LARGE
:
777 wxFAIL_MSG(_T("unexpected window variant"));
781 font
.SetPointSize(size
);
785 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
787 int WXUNUSED(incW
), int WXUNUSED(incH
) )
789 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
790 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
791 _T("min width/height must be less than max width/height!") );
800 #if WXWIN_COMPATIBILITY_2_8
801 void wxWindowBase::SetVirtualSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
),
802 int WXUNUSED(maxW
), int WXUNUSED(maxH
))
806 void wxWindowBase::SetVirtualSizeHints(const wxSize
& WXUNUSED(minsize
),
807 const wxSize
& WXUNUSED(maxsize
))
810 #endif // WXWIN_COMPATIBILITY_2_8
812 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
814 m_virtualSize
= wxSize(x
, y
);
817 wxSize
wxWindowBase::DoGetVirtualSize() const
819 // we should use the entire client area so if it is greater than our
820 // virtual size, expand it to fit (otherwise if the window is big enough we
821 // wouldn't be using parts of it)
822 wxSize size
= GetClientSize();
823 if ( m_virtualSize
.x
> size
.x
)
824 size
.x
= m_virtualSize
.x
;
826 if ( m_virtualSize
.y
>= size
.y
)
827 size
.y
= m_virtualSize
.y
;
832 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
834 // screen position is the same as (0, 0) in client coords for non TLWs (and
835 // TLWs override this method)
841 ClientToScreen(x
, y
);
844 void wxWindowBase::SendSizeEvent(int flags
)
846 wxSizeEvent
event(GetSize(), GetId());
847 event
.SetEventObject(this);
848 if ( flags
& wxSEND_EVENT_POST
)
849 wxPostEvent(this, event
);
851 HandleWindowEvent(event
);
854 void wxWindowBase::SendSizeEventToParent(int flags
)
856 wxWindow
* const parent
= GetParent();
857 if ( parent
&& !parent
->IsBeingDeleted() )
858 parent
->SendSizeEvent(flags
);
861 // ----------------------------------------------------------------------------
862 // show/hide/enable/disable the window
863 // ----------------------------------------------------------------------------
865 bool wxWindowBase::Show(bool show
)
867 if ( show
!= m_isShown
)
879 bool wxWindowBase::IsEnabled() const
881 return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
884 void wxWindowBase::NotifyWindowOnEnableChange(bool enabled
)
886 #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
888 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
892 // If we are top-level then the logic doesn't apply - otherwise
893 // showing a modal dialog would result in total greying out (and ungreying
894 // out later) of everything which would be really ugly
898 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
900 node
= node
->GetNext() )
902 wxWindowBase
* const child
= node
->GetData();
903 if ( !child
->IsTopLevel() && child
->IsThisEnabled() )
904 child
->NotifyWindowOnEnableChange(enabled
);
908 bool wxWindowBase::Enable(bool enable
)
910 if ( enable
== IsThisEnabled() )
913 m_isEnabled
= enable
;
915 #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
917 #else // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
918 wxWindowBase
* const parent
= GetParent();
919 if( !IsTopLevel() && parent
&& !parent
->IsEnabled() )
923 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
925 NotifyWindowOnEnableChange(enable
);
930 bool wxWindowBase::IsShownOnScreen() const
932 // A window is shown on screen if it itself is shown and so are all its
933 // parents. But if a window is toplevel one, then its always visible on
934 // screen if IsShown() returns true, even if it has a hidden parent.
936 (IsTopLevel() || GetParent() == NULL
|| GetParent()->IsShownOnScreen());
939 // ----------------------------------------------------------------------------
941 // ----------------------------------------------------------------------------
943 bool wxWindowBase::IsTopLevel() const
948 // ----------------------------------------------------------------------------
950 // ----------------------------------------------------------------------------
952 void wxWindowBase::Freeze()
954 if ( !m_freezeCount
++ )
956 // physically freeze this window:
959 // and recursively freeze all children:
960 for ( wxWindowList::iterator i
= GetChildren().begin();
961 i
!= GetChildren().end(); ++i
)
963 wxWindow
*child
= *i
;
964 if ( child
->IsTopLevel() )
972 void wxWindowBase::Thaw()
974 wxASSERT_MSG( m_freezeCount
, "Thaw() without matching Freeze()" );
976 if ( !--m_freezeCount
)
978 // recursively thaw all children:
979 for ( wxWindowList::iterator i
= GetChildren().begin();
980 i
!= GetChildren().end(); ++i
)
982 wxWindow
*child
= *i
;
983 if ( child
->IsTopLevel() )
989 // physically thaw this window:
994 // ----------------------------------------------------------------------------
995 // reparenting the window
996 // ----------------------------------------------------------------------------
998 void wxWindowBase::AddChild(wxWindowBase
*child
)
1000 wxCHECK_RET( child
, wxT("can't add a NULL child") );
1002 // this should never happen and it will lead to a crash later if it does
1003 // because RemoveChild() will remove only one node from the children list
1004 // and the other(s) one(s) will be left with dangling pointers in them
1005 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
1007 GetChildren().Append((wxWindow
*)child
);
1008 child
->SetParent(this);
1010 // adding a child while frozen will assert when thawn, so freeze it as if
1011 // it had been already present when we were frozen
1012 if ( IsFrozen() && !child
->IsTopLevel() )
1016 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
1018 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
1020 // removing a child while frozen may result in permanently frozen window
1021 // if used e.g. from Reparent(), so thaw it
1022 if ( IsFrozen() && !child
->IsTopLevel() )
1025 GetChildren().DeleteObject((wxWindow
*)child
);
1026 child
->SetParent(NULL
);
1029 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
1031 wxWindow
*oldParent
= GetParent();
1032 if ( newParent
== oldParent
)
1038 const bool oldEnabledState
= IsEnabled();
1040 // unlink this window from the existing parent.
1043 oldParent
->RemoveChild(this);
1047 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
1050 // add it to the new one
1053 newParent
->AddChild(this);
1057 wxTopLevelWindows
.Append((wxWindow
*)this);
1060 // We need to notify window (and its subwindows) if by changing the parent
1061 // we also change our enabled/disabled status.
1062 const bool newEnabledState
= IsEnabled();
1063 if ( newEnabledState
!= oldEnabledState
)
1065 NotifyWindowOnEnableChange(newEnabledState
);
1071 // ----------------------------------------------------------------------------
1072 // event handler stuff
1073 // ----------------------------------------------------------------------------
1075 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
1077 wxEvtHandler
*handlerOld
= GetEventHandler();
1079 handler
->SetNextHandler(handlerOld
);
1082 GetEventHandler()->SetPreviousHandler(handler
);
1084 SetEventHandler(handler
);
1087 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
1089 wxEvtHandler
*handlerA
= GetEventHandler();
1092 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
1093 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
1096 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
1097 SetEventHandler(handlerB
);
1099 if ( deleteHandler
)
1102 handlerA
= (wxEvtHandler
*)NULL
;
1109 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
1111 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
1113 wxEvtHandler
*handlerPrev
= NULL
,
1114 *handlerCur
= GetEventHandler();
1115 while ( handlerCur
)
1117 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
1119 if ( handlerCur
== handler
)
1123 handlerPrev
->SetNextHandler(handlerNext
);
1127 SetEventHandler(handlerNext
);
1132 handlerNext
->SetPreviousHandler ( handlerPrev
);
1135 handler
->SetNextHandler(NULL
);
1136 handler
->SetPreviousHandler(NULL
);
1141 handlerPrev
= handlerCur
;
1142 handlerCur
= handlerNext
;
1145 wxFAIL_MSG( _T("where has the event handler gone?") );
1150 bool wxWindowBase::HandleWindowEvent(wxEvent
& event
) const
1152 return GetEventHandler()->SafelyProcessEvent(event
);
1155 // ----------------------------------------------------------------------------
1156 // colours, fonts &c
1157 // ----------------------------------------------------------------------------
1159 void wxWindowBase::InheritAttributes()
1161 const wxWindowBase
* const parent
= GetParent();
1165 // we only inherit attributes which had been explicitly set for the parent
1166 // which ensures that this only happens if the user really wants it and
1167 // not by default which wouldn't make any sense in modern GUIs where the
1168 // controls don't all use the same fonts (nor colours)
1169 if ( parent
->m_inheritFont
&& !m_hasFont
)
1170 SetFont(parent
->GetFont());
1172 // in addition, there is a possibility to explicitly forbid inheriting
1173 // colours at each class level by overriding ShouldInheritColours()
1174 if ( ShouldInheritColours() )
1176 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1177 SetForegroundColour(parent
->GetForegroundColour());
1179 // inheriting (solid) background colour is wrong as it totally breaks
1180 // any kind of themed backgrounds
1182 // instead, the controls should use the same background as their parent
1183 // (ideally by not drawing it at all)
1185 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1186 SetBackgroundColour(parent
->GetBackgroundColour());
1191 /* static */ wxVisualAttributes
1192 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1194 // it is important to return valid values for all attributes from here,
1195 // GetXXX() below rely on this
1196 wxVisualAttributes attrs
;
1197 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1198 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1200 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1201 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1202 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1203 // colour on other platforms.
1205 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1206 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1208 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1213 wxColour
wxWindowBase::GetBackgroundColour() const
1215 if ( !m_backgroundColour
.IsOk() )
1217 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
1219 // get our default background colour
1220 wxColour colBg
= GetDefaultAttributes().colBg
;
1222 // we must return some valid colour to avoid redoing this every time
1223 // and also to avoid surprizing the applications written for older
1224 // wxWidgets versions where GetBackgroundColour() always returned
1225 // something -- so give them something even if it doesn't make sense
1226 // for this window (e.g. it has a themed background)
1228 colBg
= GetClassDefaultAttributes().colBg
;
1233 return m_backgroundColour
;
1236 wxColour
wxWindowBase::GetForegroundColour() const
1238 // logic is the same as above
1239 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1241 wxColour colFg
= GetDefaultAttributes().colFg
;
1243 if ( !colFg
.IsOk() )
1244 colFg
= GetClassDefaultAttributes().colFg
;
1249 return m_foregroundColour
;
1252 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1254 if ( colour
== m_backgroundColour
)
1257 m_hasBgCol
= colour
.IsOk();
1258 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1259 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1261 m_inheritBgCol
= m_hasBgCol
;
1262 m_backgroundColour
= colour
;
1263 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1267 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1269 if (colour
== m_foregroundColour
)
1272 m_hasFgCol
= colour
.IsOk();
1273 m_inheritFgCol
= m_hasFgCol
;
1274 m_foregroundColour
= colour
;
1275 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1279 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1281 // setting an invalid cursor is ok, it means that we don't have any special
1283 if ( m_cursor
.IsSameAs(cursor
) )
1294 wxFont
wxWindowBase::GetFont() const
1296 // logic is the same as in GetBackgroundColour()
1297 if ( !m_font
.IsOk() )
1299 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1301 wxFont font
= GetDefaultAttributes().font
;
1303 font
= GetClassDefaultAttributes().font
;
1311 bool wxWindowBase::SetFont(const wxFont
& font
)
1313 if ( font
== m_font
)
1320 m_hasFont
= font
.IsOk();
1321 m_inheritFont
= m_hasFont
;
1323 InvalidateBestSize();
1330 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1332 m_hasCustomPalette
= true;
1335 // VZ: can anyone explain me what do we do here?
1336 wxWindowDC
d((wxWindow
*) this);
1340 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1342 wxWindow
*win
= (wxWindow
*)this;
1343 while ( win
&& !win
->HasCustomPalette() )
1345 win
= win
->GetParent();
1351 #endif // wxUSE_PALETTE
1354 void wxWindowBase::SetCaret(wxCaret
*caret
)
1365 wxASSERT_MSG( m_caret
->GetWindow() == this,
1366 wxT("caret should be created associated to this window") );
1369 #endif // wxUSE_CARET
1371 #if wxUSE_VALIDATORS
1372 // ----------------------------------------------------------------------------
1374 // ----------------------------------------------------------------------------
1376 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1378 if ( m_windowValidator
)
1379 delete m_windowValidator
;
1381 m_windowValidator
= (wxValidator
*)validator
.Clone();
1383 if ( m_windowValidator
)
1384 m_windowValidator
->SetWindow(this);
1386 #endif // wxUSE_VALIDATORS
1388 // ----------------------------------------------------------------------------
1389 // update region stuff
1390 // ----------------------------------------------------------------------------
1392 wxRect
wxWindowBase::GetUpdateClientRect() const
1394 wxRegion rgnUpdate
= GetUpdateRegion();
1395 rgnUpdate
.Intersect(GetClientRect());
1396 wxRect rectUpdate
= rgnUpdate
.GetBox();
1397 wxPoint ptOrigin
= GetClientAreaOrigin();
1398 rectUpdate
.x
-= ptOrigin
.x
;
1399 rectUpdate
.y
-= ptOrigin
.y
;
1404 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1406 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1409 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1411 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1414 void wxWindowBase::ClearBackground()
1416 // wxGTK uses its own version, no need to add never used code
1418 wxClientDC
dc((wxWindow
*)this);
1419 wxBrush
brush(GetBackgroundColour(), wxBRUSHSTYLE_SOLID
);
1420 dc
.SetBackground(brush
);
1425 // ----------------------------------------------------------------------------
1426 // find child window by id or name
1427 // ----------------------------------------------------------------------------
1429 wxWindow
*wxWindowBase::FindWindow(long id
) const
1431 if ( id
== m_windowId
)
1432 return (wxWindow
*)this;
1434 wxWindowBase
*res
= (wxWindow
*)NULL
;
1435 wxWindowList::compatibility_iterator node
;
1436 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1438 wxWindowBase
*child
= node
->GetData();
1439 res
= child
->FindWindow( id
);
1442 return (wxWindow
*)res
;
1445 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1447 if ( name
== m_windowName
)
1448 return (wxWindow
*)this;
1450 wxWindowBase
*res
= (wxWindow
*)NULL
;
1451 wxWindowList::compatibility_iterator node
;
1452 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1454 wxWindow
*child
= node
->GetData();
1455 res
= child
->FindWindow(name
);
1458 return (wxWindow
*)res
;
1462 // find any window by id or name or label: If parent is non-NULL, look through
1463 // children for a label or title matching the specified string. If NULL, look
1464 // through all top-level windows.
1466 // to avoid duplicating code we reuse the same helper function but with
1467 // different comparators
1469 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1470 const wxString
& label
, long id
);
1473 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1476 return win
->GetLabel() == label
;
1480 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1483 return win
->GetName() == label
;
1487 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1490 return win
->GetId() == id
;
1493 // recursive helper for the FindWindowByXXX() functions
1495 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1496 const wxString
& label
,
1498 wxFindWindowCmp cmp
)
1502 // see if this is the one we're looking for
1503 if ( (*cmp
)(parent
, label
, id
) )
1504 return (wxWindow
*)parent
;
1506 // It wasn't, so check all its children
1507 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1509 node
= node
->GetNext() )
1511 // recursively check each child
1512 wxWindow
*win
= (wxWindow
*)node
->GetData();
1513 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1523 // helper for FindWindowByXXX()
1525 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1526 const wxString
& label
,
1528 wxFindWindowCmp cmp
)
1532 // just check parent and all its children
1533 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1536 // start at very top of wx's windows
1537 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1539 node
= node
->GetNext() )
1541 // recursively check each window & its children
1542 wxWindow
*win
= node
->GetData();
1543 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1553 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1555 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1560 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1562 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1566 // fall back to the label
1567 win
= FindWindowByLabel(title
, parent
);
1575 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1577 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1580 // ----------------------------------------------------------------------------
1581 // dialog oriented functions
1582 // ----------------------------------------------------------------------------
1584 void wxWindowBase::MakeModal(bool modal
)
1586 // Disable all other windows
1589 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1592 wxWindow
*win
= node
->GetData();
1594 win
->Enable(!modal
);
1596 node
= node
->GetNext();
1601 bool wxWindowBase::Validate()
1603 #if wxUSE_VALIDATORS
1604 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1606 wxWindowList::compatibility_iterator node
;
1607 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1609 wxWindowBase
*child
= node
->GetData();
1610 wxValidator
*validator
= child
->GetValidator();
1611 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1616 if ( recurse
&& !child
->Validate() )
1621 #endif // wxUSE_VALIDATORS
1626 bool wxWindowBase::TransferDataToWindow()
1628 #if wxUSE_VALIDATORS
1629 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1631 wxWindowList::compatibility_iterator node
;
1632 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1634 wxWindowBase
*child
= node
->GetData();
1635 wxValidator
*validator
= child
->GetValidator();
1636 if ( validator
&& !validator
->TransferToWindow() )
1638 wxLogWarning(_("Could not transfer data to window"));
1640 wxLog::FlushActive();
1648 if ( !child
->TransferDataToWindow() )
1650 // warning already given
1655 #endif // wxUSE_VALIDATORS
1660 bool wxWindowBase::TransferDataFromWindow()
1662 #if wxUSE_VALIDATORS
1663 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1665 wxWindowList::compatibility_iterator node
;
1666 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1668 wxWindow
*child
= node
->GetData();
1669 wxValidator
*validator
= child
->GetValidator();
1670 if ( validator
&& !validator
->TransferFromWindow() )
1672 // nop warning here because the application is supposed to give
1673 // one itself - we don't know here what might have gone wrongly
1680 if ( !child
->TransferDataFromWindow() )
1682 // warning already given
1687 #endif // wxUSE_VALIDATORS
1692 void wxWindowBase::InitDialog()
1694 wxInitDialogEvent
event(GetId());
1695 event
.SetEventObject( this );
1696 GetEventHandler()->ProcessEvent(event
);
1699 // ----------------------------------------------------------------------------
1700 // context-sensitive help support
1701 // ----------------------------------------------------------------------------
1705 // associate this help text with this window
1706 void wxWindowBase::SetHelpText(const wxString
& text
)
1708 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1711 helpProvider
->AddHelp(this, text
);
1715 #if WXWIN_COMPATIBILITY_2_8
1716 // associate this help text with all windows with the same id as this
1718 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1720 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1723 helpProvider
->AddHelp(GetId(), text
);
1726 #endif // WXWIN_COMPATIBILITY_2_8
1728 // get the help string associated with this window (may be empty)
1729 // default implementation forwards calls to the help provider
1731 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1732 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1735 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1738 text
= helpProvider
->GetHelp(this);
1744 // show help for this window
1745 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1747 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1750 wxPoint pos
= event
.GetPosition();
1751 const wxHelpEvent::Origin origin
= event
.GetOrigin();
1752 if ( origin
== wxHelpEvent::Origin_Keyboard
)
1754 // if the help event was generated from keyboard it shouldn't
1755 // appear at the mouse position (which is still the only position
1756 // associated with help event) if the mouse is far away, although
1757 // we still do use the mouse position if it's over the window
1758 // because we suppose the user looks approximately at the mouse
1759 // already and so it would be more convenient than showing tooltip
1760 // at some arbitrary position which can be quite far from it
1761 const wxRect rectClient
= GetClientRect();
1762 if ( !rectClient
.Contains(ScreenToClient(pos
)) )
1764 // position help slightly under and to the right of this window
1765 pos
= ClientToScreen(wxPoint(
1767 rectClient
.height
+ GetCharHeight()
1772 if ( helpProvider
->ShowHelpAtPoint(this, pos
, origin
) )
1774 // skip the event.Skip() below
1782 #endif // wxUSE_HELP
1784 // ----------------------------------------------------------------------------
1786 // ----------------------------------------------------------------------------
1790 void wxWindowBase::SetToolTip( const wxString
&tip
)
1792 // don't create the new tooltip if we already have one
1795 m_tooltip
->SetTip( tip
);
1799 SetToolTip( new wxToolTip( tip
) );
1802 // setting empty tooltip text does not remove the tooltip any more - use
1803 // SetToolTip((wxToolTip *)NULL) for this
1806 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1808 if ( m_tooltip
!= tooltip
)
1813 m_tooltip
= tooltip
;
1817 #endif // wxUSE_TOOLTIPS
1819 // ----------------------------------------------------------------------------
1820 // constraints and sizers
1821 // ----------------------------------------------------------------------------
1823 #if wxUSE_CONSTRAINTS
1825 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1827 if ( m_constraints
)
1829 UnsetConstraints(m_constraints
);
1830 delete m_constraints
;
1832 m_constraints
= constraints
;
1833 if ( m_constraints
)
1835 // Make sure other windows know they're part of a 'meaningful relationship'
1836 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1837 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1838 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1839 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1840 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1841 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1842 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1843 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1844 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1845 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1846 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1847 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1848 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1849 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1850 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1851 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1855 // This removes any dangling pointers to this window in other windows'
1856 // constraintsInvolvedIn lists.
1857 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1861 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1862 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1863 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1864 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1865 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1866 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1867 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1868 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1869 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1870 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1871 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1872 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1873 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1874 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1875 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1876 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1880 // Back-pointer to other windows we're involved with, so if we delete this
1881 // window, we must delete any constraints we're involved with.
1882 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1884 if ( !m_constraintsInvolvedIn
)
1885 m_constraintsInvolvedIn
= new wxWindowList
;
1886 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1887 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1890 // REMOVE back-pointer to other windows we're involved with.
1891 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1893 if ( m_constraintsInvolvedIn
)
1894 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1897 // Reset any constraints that mention this window
1898 void wxWindowBase::DeleteRelatedConstraints()
1900 if ( m_constraintsInvolvedIn
)
1902 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1905 wxWindow
*win
= node
->GetData();
1906 wxLayoutConstraints
*constr
= win
->GetConstraints();
1908 // Reset any constraints involving this window
1911 constr
->left
.ResetIfWin(this);
1912 constr
->top
.ResetIfWin(this);
1913 constr
->right
.ResetIfWin(this);
1914 constr
->bottom
.ResetIfWin(this);
1915 constr
->width
.ResetIfWin(this);
1916 constr
->height
.ResetIfWin(this);
1917 constr
->centreX
.ResetIfWin(this);
1918 constr
->centreY
.ResetIfWin(this);
1921 wxWindowList::compatibility_iterator next
= node
->GetNext();
1922 m_constraintsInvolvedIn
->Erase(node
);
1926 delete m_constraintsInvolvedIn
;
1927 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1931 #endif // wxUSE_CONSTRAINTS
1933 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1935 if ( sizer
== m_windowSizer
)
1938 if ( m_windowSizer
)
1940 m_windowSizer
->SetContainingWindow(NULL
);
1943 delete m_windowSizer
;
1946 m_windowSizer
= sizer
;
1947 if ( m_windowSizer
)
1949 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
1952 SetAutoLayout(m_windowSizer
!= NULL
);
1955 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1957 SetSizer( sizer
, deleteOld
);
1958 sizer
->SetSizeHints( (wxWindow
*) this );
1962 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1964 // adding a window to a sizer twice is going to result in fatal and
1965 // hard to debug problems later because when deleting the second
1966 // associated wxSizerItem we're going to dereference a dangling
1967 // pointer; so try to detect this as early as possible
1968 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1969 _T("Adding a window to the same sizer twice?") );
1971 m_containingSizer
= sizer
;
1974 #if wxUSE_CONSTRAINTS
1976 void wxWindowBase::SatisfyConstraints()
1978 wxLayoutConstraints
*constr
= GetConstraints();
1979 bool wasOk
= constr
&& constr
->AreSatisfied();
1981 ResetConstraints(); // Mark all constraints as unevaluated
1985 // if we're a top level panel (i.e. our parent is frame/dialog), our
1986 // own constraints will never be satisfied any more unless we do it
1990 while ( noChanges
> 0 )
1992 LayoutPhase1(&noChanges
);
1996 LayoutPhase2(&noChanges
);
1999 #endif // wxUSE_CONSTRAINTS
2001 bool wxWindowBase::Layout()
2003 // If there is a sizer, use it instead of the constraints
2007 GetVirtualSize(&w
, &h
);
2008 GetSizer()->SetDimension( 0, 0, w
, h
);
2010 #if wxUSE_CONSTRAINTS
2013 SatisfyConstraints(); // Find the right constraints values
2014 SetConstraintSizes(); // Recursively set the real window sizes
2021 #if wxUSE_CONSTRAINTS
2023 // first phase of the constraints evaluation: set our own constraints
2024 bool wxWindowBase::LayoutPhase1(int *noChanges
)
2026 wxLayoutConstraints
*constr
= GetConstraints();
2028 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
2031 // second phase: set the constraints for our children
2032 bool wxWindowBase::LayoutPhase2(int *noChanges
)
2039 // Layout grand children
2045 // Do a phase of evaluating child constraints
2046 bool wxWindowBase::DoPhase(int phase
)
2048 // the list containing the children for which the constraints are already
2050 wxWindowList succeeded
;
2052 // the max number of iterations we loop before concluding that we can't set
2054 static const int maxIterations
= 500;
2056 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
2060 // loop over all children setting their constraints
2061 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2063 node
= node
->GetNext() )
2065 wxWindow
*child
= node
->GetData();
2066 if ( child
->IsTopLevel() )
2068 // top level children are not inside our client area
2072 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
2074 // this one is either already ok or nothing we can do about it
2078 int tempNoChanges
= 0;
2079 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
2080 : child
->LayoutPhase2(&tempNoChanges
);
2081 noChanges
+= tempNoChanges
;
2085 succeeded
.Append(child
);
2091 // constraints are set
2099 void wxWindowBase::ResetConstraints()
2101 wxLayoutConstraints
*constr
= GetConstraints();
2104 constr
->left
.SetDone(false);
2105 constr
->top
.SetDone(false);
2106 constr
->right
.SetDone(false);
2107 constr
->bottom
.SetDone(false);
2108 constr
->width
.SetDone(false);
2109 constr
->height
.SetDone(false);
2110 constr
->centreX
.SetDone(false);
2111 constr
->centreY
.SetDone(false);
2114 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2117 wxWindow
*win
= node
->GetData();
2118 if ( !win
->IsTopLevel() )
2119 win
->ResetConstraints();
2120 node
= node
->GetNext();
2124 // Need to distinguish between setting the 'fake' size for windows and sizers,
2125 // and setting the real values.
2126 void wxWindowBase::SetConstraintSizes(bool recurse
)
2128 wxLayoutConstraints
*constr
= GetConstraints();
2129 if ( constr
&& constr
->AreSatisfied() )
2131 int x
= constr
->left
.GetValue();
2132 int y
= constr
->top
.GetValue();
2133 int w
= constr
->width
.GetValue();
2134 int h
= constr
->height
.GetValue();
2136 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
2137 (constr
->height
.GetRelationship() != wxAsIs
) )
2139 SetSize(x
, y
, w
, h
);
2143 // If we don't want to resize this window, just move it...
2149 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
2150 GetClassInfo()->GetClassName(),
2156 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2159 wxWindow
*win
= node
->GetData();
2160 if ( !win
->IsTopLevel() && win
->GetConstraints() )
2161 win
->SetConstraintSizes();
2162 node
= node
->GetNext();
2167 // Only set the size/position of the constraint (if any)
2168 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
2170 wxLayoutConstraints
*constr
= GetConstraints();
2173 if ( x
!= wxDefaultCoord
)
2175 constr
->left
.SetValue(x
);
2176 constr
->left
.SetDone(true);
2178 if ( y
!= wxDefaultCoord
)
2180 constr
->top
.SetValue(y
);
2181 constr
->top
.SetDone(true);
2183 if ( w
!= wxDefaultCoord
)
2185 constr
->width
.SetValue(w
);
2186 constr
->width
.SetDone(true);
2188 if ( h
!= wxDefaultCoord
)
2190 constr
->height
.SetValue(h
);
2191 constr
->height
.SetDone(true);
2196 void wxWindowBase::MoveConstraint(int x
, int y
)
2198 wxLayoutConstraints
*constr
= GetConstraints();
2201 if ( x
!= wxDefaultCoord
)
2203 constr
->left
.SetValue(x
);
2204 constr
->left
.SetDone(true);
2206 if ( y
!= wxDefaultCoord
)
2208 constr
->top
.SetValue(y
);
2209 constr
->top
.SetDone(true);
2214 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2216 wxLayoutConstraints
*constr
= GetConstraints();
2219 *w
= constr
->width
.GetValue();
2220 *h
= constr
->height
.GetValue();
2226 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2228 wxLayoutConstraints
*constr
= GetConstraints();
2231 *w
= constr
->width
.GetValue();
2232 *h
= constr
->height
.GetValue();
2235 GetClientSize(w
, h
);
2238 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2240 wxLayoutConstraints
*constr
= GetConstraints();
2243 *x
= constr
->left
.GetValue();
2244 *y
= constr
->top
.GetValue();
2250 #endif // wxUSE_CONSTRAINTS
2252 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2254 // don't do it for the dialogs/frames - they float independently of their
2256 if ( !IsTopLevel() )
2258 wxWindow
*parent
= GetParent();
2259 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2261 wxPoint
pt(parent
->GetClientAreaOrigin());
2268 // ----------------------------------------------------------------------------
2269 // Update UI processing
2270 // ----------------------------------------------------------------------------
2272 void wxWindowBase::UpdateWindowUI(long flags
)
2274 wxUpdateUIEvent
event(GetId());
2275 event
.SetEventObject(this);
2277 if ( GetEventHandler()->ProcessEvent(event
) )
2279 DoUpdateWindowUI(event
);
2282 if (flags
& wxUPDATE_UI_RECURSE
)
2284 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2287 wxWindow
* child
= (wxWindow
*) node
->GetData();
2288 child
->UpdateWindowUI(flags
);
2289 node
= node
->GetNext();
2294 // do the window-specific processing after processing the update event
2295 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2297 if ( event
.GetSetEnabled() )
2298 Enable(event
.GetEnabled());
2300 if ( event
.GetSetShown() )
2301 Show(event
.GetShown());
2304 // ----------------------------------------------------------------------------
2305 // dialog units translations
2306 // ----------------------------------------------------------------------------
2308 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2310 int charWidth
= GetCharWidth();
2311 int charHeight
= GetCharHeight();
2312 wxPoint pt2
= wxDefaultPosition
;
2313 if (pt
.x
!= wxDefaultCoord
)
2314 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2315 if (pt
.y
!= wxDefaultCoord
)
2316 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2321 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2323 int charWidth
= GetCharWidth();
2324 int charHeight
= GetCharHeight();
2325 wxPoint pt2
= wxDefaultPosition
;
2326 if (pt
.x
!= wxDefaultCoord
)
2327 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2328 if (pt
.y
!= wxDefaultCoord
)
2329 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2334 // ----------------------------------------------------------------------------
2336 // ----------------------------------------------------------------------------
2338 // propagate the colour change event to the subwindows
2339 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2341 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2344 // Only propagate to non-top-level windows
2345 wxWindow
*win
= node
->GetData();
2346 if ( !win
->IsTopLevel() )
2348 wxSysColourChangedEvent event2
;
2349 event
.SetEventObject(win
);
2350 win
->GetEventHandler()->ProcessEvent(event2
);
2353 node
= node
->GetNext();
2359 // the default action is to populate dialog with data when it's created,
2360 // and nudge the UI into displaying itself correctly in case
2361 // we've turned the wxUpdateUIEvents frequency down low.
2362 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2364 TransferDataToWindow();
2366 // Update the UI at this point
2367 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2370 // ----------------------------------------------------------------------------
2371 // menu-related functions
2372 // ----------------------------------------------------------------------------
2376 bool wxWindowBase::PopupMenu(wxMenu
*menu
, int x
, int y
)
2378 wxCHECK_MSG( menu
, false, "can't popup NULL menu" );
2380 wxCurrentPopupMenu
= menu
;
2381 const bool rc
= DoPopupMenu(menu
, x
, y
);
2382 wxCurrentPopupMenu
= NULL
;
2387 // this is used to pass the id of the selected item from the menu event handler
2388 // to the main function itself
2390 // it's ok to use a global here as there can be at most one popup menu shown at
2392 static int gs_popupMenuSelection
= wxID_NONE
;
2394 void wxWindowBase::InternalOnPopupMenu(wxCommandEvent
& event
)
2396 // store the id in a global variable where we'll retrieve it from later
2397 gs_popupMenuSelection
= event
.GetId();
2401 wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu
& menu
, int x
, int y
)
2403 gs_popupMenuSelection
= wxID_NONE
;
2405 Connect(wxEVT_COMMAND_MENU_SELECTED
,
2406 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2410 PopupMenu(&menu
, x
, y
);
2412 Disconnect(wxEVT_COMMAND_MENU_SELECTED
,
2413 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2417 return gs_popupMenuSelection
;
2420 #endif // wxUSE_MENUS
2422 // methods for drawing the sizers in a visible way
2425 static void DrawSizers(wxWindowBase
*win
);
2427 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2429 wxClientDC
dc((wxWindow
*)win
);
2430 dc
.SetPen(*wxRED_PEN
);
2431 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxBRUSHSTYLE_CROSSDIAG_HATCH
) : *wxTRANSPARENT_BRUSH
);
2432 dc
.DrawRectangle(rect
.Deflate(1, 1));
2435 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2437 const wxSizerItemList
& items
= sizer
->GetChildren();
2438 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2443 wxSizerItem
*item
= *i
;
2444 if ( item
->IsSizer() )
2446 DrawBorder(win
, item
->GetRect().Deflate(2));
2447 DrawSizer(win
, item
->GetSizer());
2449 else if ( item
->IsSpacer() )
2451 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2453 else if ( item
->IsWindow() )
2455 DrawSizers(item
->GetWindow());
2460 static void DrawSizers(wxWindowBase
*win
)
2462 wxSizer
*sizer
= win
->GetSizer();
2465 DrawBorder(win
, win
->GetClientSize());
2466 DrawSizer(win
, sizer
);
2468 else // no sizer, still recurse into the children
2470 const wxWindowList
& children
= win
->GetChildren();
2471 for ( wxWindowList::const_iterator i
= children
.begin(),
2472 end
= children
.end();
2481 #endif // __WXDEBUG__
2483 // process special middle clicks
2484 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2486 if ( event
.ControlDown() && event
.AltDown() )
2489 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2490 if ( event
.ShiftDown() )
2495 #endif // __WXDEBUG__
2496 ::wxInfoMessageBox((wxWindow
*)this);
2504 // ----------------------------------------------------------------------------
2506 // ----------------------------------------------------------------------------
2508 #if wxUSE_ACCESSIBILITY
2509 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2511 if (m_accessible
&& (accessible
!= m_accessible
))
2512 delete m_accessible
;
2513 m_accessible
= accessible
;
2515 m_accessible
->SetWindow((wxWindow
*) this);
2518 // Returns the accessible object, creating if necessary.
2519 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2522 m_accessible
= CreateAccessible();
2523 return m_accessible
;
2526 // Override to create a specific accessible object.
2527 wxAccessible
* wxWindowBase::CreateAccessible()
2529 return new wxWindowAccessible((wxWindow
*) this);
2534 // ----------------------------------------------------------------------------
2535 // list classes implementation
2536 // ----------------------------------------------------------------------------
2540 #include "wx/listimpl.cpp"
2541 WX_DEFINE_LIST(wxWindowList
)
2545 void wxWindowListNode::DeleteData()
2547 delete (wxWindow
*)GetData();
2550 #endif // wxUSE_STL/!wxUSE_STL
2552 // ----------------------------------------------------------------------------
2554 // ----------------------------------------------------------------------------
2556 wxBorder
wxWindowBase::GetBorder(long flags
) const
2558 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2559 if ( border
== wxBORDER_DEFAULT
)
2561 border
= GetDefaultBorder();
2563 else if ( border
== wxBORDER_THEME
)
2565 border
= GetDefaultBorderForControl();
2571 wxBorder
wxWindowBase::GetDefaultBorder() const
2573 return wxBORDER_NONE
;
2576 // ----------------------------------------------------------------------------
2578 // ----------------------------------------------------------------------------
2580 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2582 // here we just check if the point is inside the window or not
2584 // check the top and left border first
2585 bool outside
= x
< 0 || y
< 0;
2588 // check the right and bottom borders too
2589 wxSize size
= GetSize();
2590 outside
= x
>= size
.x
|| y
>= size
.y
;
2593 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2596 // ----------------------------------------------------------------------------
2598 // ----------------------------------------------------------------------------
2600 struct WXDLLEXPORT wxWindowNext
2604 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2605 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2606 bool wxWindowBase::ms_winCaptureChanging
= false;
2608 void wxWindowBase::CaptureMouse()
2610 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2612 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2614 ms_winCaptureChanging
= true;
2616 wxWindow
*winOld
= GetCapture();
2619 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2622 wxWindowNext
*item
= new wxWindowNext
;
2624 item
->next
= ms_winCaptureNext
;
2625 ms_winCaptureNext
= item
;
2627 //else: no mouse capture to save
2630 ms_winCaptureCurrent
= (wxWindow
*)this;
2632 ms_winCaptureChanging
= false;
2635 void wxWindowBase::ReleaseMouse()
2637 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2639 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2641 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2643 ms_winCaptureChanging
= true;
2646 ms_winCaptureCurrent
= NULL
;
2648 if ( ms_winCaptureNext
)
2650 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2651 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2653 wxWindowNext
*item
= ms_winCaptureNext
;
2654 ms_winCaptureNext
= item
->next
;
2657 //else: stack is empty, no previous capture
2659 ms_winCaptureChanging
= false;
2661 wxLogTrace(_T("mousecapture"),
2662 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2663 wx_static_cast(void*, GetCapture()));
2666 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2668 wxMouseCaptureLostEvent
event(win
->GetId());
2669 event
.SetEventObject(win
);
2670 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2672 // windows must handle this event, otherwise the app wouldn't behave
2673 // correctly if it loses capture unexpectedly; see the discussion here:
2674 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
2675 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
2676 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2681 void wxWindowBase::NotifyCaptureLost()
2683 // don't do anything if capture lost was expected, i.e. resulted from
2684 // a wx call to ReleaseMouse or CaptureMouse:
2685 if ( ms_winCaptureChanging
)
2688 // if the capture was lost unexpectedly, notify every window that has
2689 // capture (on stack or current) about it and clear the stack:
2691 if ( ms_winCaptureCurrent
)
2693 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2694 ms_winCaptureCurrent
= NULL
;
2697 while ( ms_winCaptureNext
)
2699 wxWindowNext
*item
= ms_winCaptureNext
;
2700 ms_winCaptureNext
= item
->next
;
2702 DoNotifyWindowAboutCaptureLost(item
->win
);
2711 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2712 int WXUNUSED(modifiers
),
2713 int WXUNUSED(keycode
))
2719 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2725 #endif // wxUSE_HOTKEY
2727 // ----------------------------------------------------------------------------
2729 // ----------------------------------------------------------------------------
2731 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2733 #if wxUSE_VALIDATORS
2734 // Can only use the validator of the window which
2735 // is receiving the event
2736 if ( event
.GetEventObject() == this )
2738 wxValidator
*validator
= GetValidator();
2739 if ( validator
&& validator
->ProcessEvent(event
) )
2744 #endif // wxUSE_VALIDATORS
2749 bool wxWindowBase::TryParent(wxEvent
& event
)
2751 // carry on up the parent-child hierarchy if the propagation count hasn't
2753 if ( event
.ShouldPropagate() )
2755 // honour the requests to stop propagation at this window: this is
2756 // used by the dialogs, for example, to prevent processing the events
2757 // from the dialog controls in the parent frame which rarely, if ever,
2759 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2761 wxWindow
*parent
= GetParent();
2762 if ( parent
&& !parent
->IsBeingDeleted() )
2764 wxPropagateOnce
propagateOnce(event
);
2766 return parent
->GetEventHandler()->ProcessEvent(event
);
2771 return wxEvtHandler::TryParent(event
);
2774 // ----------------------------------------------------------------------------
2775 // window relationships
2776 // ----------------------------------------------------------------------------
2778 wxWindow
*wxWindowBase::DoGetSibling(WindowOrder order
) const
2780 wxCHECK_MSG( GetParent(), NULL
,
2781 _T("GetPrev/NextSibling() don't work for TLWs!") );
2783 wxWindowList
& siblings
= GetParent()->GetChildren();
2784 wxWindowList::compatibility_iterator i
= siblings
.Find((wxWindow
*)this);
2785 wxCHECK_MSG( i
, NULL
, _T("window not a child of its parent?") );
2787 if ( order
== OrderBefore
)
2788 i
= i
->GetPrevious();
2792 return i
? i
->GetData() : NULL
;
2795 // ----------------------------------------------------------------------------
2796 // keyboard navigation
2797 // ----------------------------------------------------------------------------
2799 // Navigates in the specified direction inside this window
2800 bool wxWindowBase::DoNavigateIn(int flags
)
2802 #ifdef wxHAS_NATIVE_TAB_TRAVERSAL
2803 // native code doesn't process our wxNavigationKeyEvents anyhow
2806 #else // !wxHAS_NATIVE_TAB_TRAVERSAL
2807 wxNavigationKeyEvent eventNav
;
2808 wxWindow
*focused
= FindFocus();
2809 eventNav
.SetCurrentFocus(focused
);
2810 eventNav
.SetEventObject(focused
);
2811 eventNav
.SetFlags(flags
);
2812 return GetEventHandler()->ProcessEvent(eventNav
);
2813 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
2816 bool wxWindowBase::HandleAsNavigationKey(const wxKeyEvent
& event
)
2818 if ( event
.GetKeyCode() != WXK_TAB
)
2821 int flags
= wxNavigationKeyEvent::FromTab
;
2823 if ( event
.ShiftDown() )
2824 flags
|= wxNavigationKeyEvent::IsBackward
;
2826 flags
|= wxNavigationKeyEvent::IsForward
;
2828 if ( event
.ControlDown() )
2829 flags
|= wxNavigationKeyEvent::WinChange
;
2835 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, WindowOrder move
)
2837 // check that we're not a top level window
2838 wxCHECK_RET( GetParent(),
2839 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2841 // detect the special case when we have nothing to do anyhow and when the
2842 // code below wouldn't work
2846 // find the target window in the siblings list
2847 wxWindowList
& siblings
= GetParent()->GetChildren();
2848 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2849 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2851 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2852 // can't just move the node around
2853 wxWindow
*self
= (wxWindow
*)this;
2854 siblings
.DeleteObject(self
);
2855 if ( move
== OrderAfter
)
2862 siblings
.Insert(i
, self
);
2864 else // OrderAfter and win was the last sibling
2866 siblings
.Append(self
);
2870 // ----------------------------------------------------------------------------
2872 // ----------------------------------------------------------------------------
2874 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2876 wxWindowBase
*win
= DoFindFocus();
2877 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2880 bool wxWindowBase::HasFocus() const
2882 wxWindowBase
*win
= DoFindFocus();
2883 return win
== this ||
2884 win
== wxConstCast(this, wxWindowBase
)->GetMainWindowOfCompositeControl();
2887 // ----------------------------------------------------------------------------
2889 // ----------------------------------------------------------------------------
2891 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2893 while ( win
&& !win
->IsTopLevel() )
2894 win
= win
->GetParent();
2899 #if wxUSE_ACCESSIBILITY
2900 // ----------------------------------------------------------------------------
2901 // accessible object for windows
2902 // ----------------------------------------------------------------------------
2904 // Can return either a child object, or an integer
2905 // representing the child element, starting from 1.
2906 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2908 wxASSERT( GetWindow() != NULL
);
2912 return wxACC_NOT_IMPLEMENTED
;
2915 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2916 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2918 wxASSERT( GetWindow() != NULL
);
2922 wxWindow
* win
= NULL
;
2929 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2931 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2938 rect
= win
->GetRect();
2939 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2940 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2944 return wxACC_NOT_IMPLEMENTED
;
2947 // Navigates from fromId to toId/toObject.
2948 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2949 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2951 wxASSERT( GetWindow() != NULL
);
2957 case wxNAVDIR_FIRSTCHILD
:
2959 if (GetWindow()->GetChildren().GetCount() == 0)
2961 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2962 *toObject
= childWindow
->GetOrCreateAccessible();
2966 case wxNAVDIR_LASTCHILD
:
2968 if (GetWindow()->GetChildren().GetCount() == 0)
2970 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2971 *toObject
= childWindow
->GetOrCreateAccessible();
2975 case wxNAVDIR_RIGHT
:
2979 wxWindowList::compatibility_iterator node
=
2980 wxWindowList::compatibility_iterator();
2983 // Can't navigate to sibling of this window
2984 // if we're a top-level window.
2985 if (!GetWindow()->GetParent())
2986 return wxACC_NOT_IMPLEMENTED
;
2988 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2992 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2993 node
= GetWindow()->GetChildren().Item(fromId
-1);
2996 if (node
&& node
->GetNext())
2998 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2999 *toObject
= nextWindow
->GetOrCreateAccessible();
3007 case wxNAVDIR_PREVIOUS
:
3009 wxWindowList::compatibility_iterator node
=
3010 wxWindowList::compatibility_iterator();
3013 // Can't navigate to sibling of this window
3014 // if we're a top-level window.
3015 if (!GetWindow()->GetParent())
3016 return wxACC_NOT_IMPLEMENTED
;
3018 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3022 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
3023 node
= GetWindow()->GetChildren().Item(fromId
-1);
3026 if (node
&& node
->GetPrevious())
3028 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
3029 *toObject
= previousWindow
->GetOrCreateAccessible();
3037 return wxACC_NOT_IMPLEMENTED
;
3040 // Gets the name of the specified object.
3041 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
3043 wxASSERT( GetWindow() != NULL
);
3049 // If a child, leave wxWidgets to call the function on the actual
3052 return wxACC_NOT_IMPLEMENTED
;
3054 // This will eventually be replaced by specialised
3055 // accessible classes, one for each kind of wxWidgets
3056 // control or window.
3058 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
3059 title
= ((wxButton
*) GetWindow())->GetLabel();
3062 title
= GetWindow()->GetName();
3070 return wxACC_NOT_IMPLEMENTED
;
3073 // Gets the number of children.
3074 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
3076 wxASSERT( GetWindow() != NULL
);
3080 *childId
= (int) GetWindow()->GetChildren().GetCount();
3084 // Gets the specified child (starting from 1).
3085 // If *child is NULL and return value is wxACC_OK,
3086 // this means that the child is a simple element and
3087 // not an accessible object.
3088 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
3090 wxASSERT( GetWindow() != NULL
);
3100 if (childId
> (int) GetWindow()->GetChildren().GetCount())
3103 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
3104 *child
= childWindow
->GetOrCreateAccessible();
3111 // Gets the parent, or NULL.
3112 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
3114 wxASSERT( GetWindow() != NULL
);
3118 wxWindow
* parentWindow
= GetWindow()->GetParent();
3126 *parent
= parentWindow
->GetOrCreateAccessible();
3134 // Performs the default action. childId is 0 (the action for this object)
3135 // or > 0 (the action for a child).
3136 // Return wxACC_NOT_SUPPORTED if there is no default action for this
3137 // window (e.g. an edit control).
3138 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
3140 wxASSERT( GetWindow() != NULL
);
3144 return wxACC_NOT_IMPLEMENTED
;
3147 // Gets the default action for this object (0) or > 0 (the action for a child).
3148 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
3149 // string if there is no action.
3150 // The retrieved string describes the action that is performed on an object,
3151 // not what the object does as a result. For example, a toolbar button that prints
3152 // a document has a default action of "Press" rather than "Prints the current document."
3153 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
3155 wxASSERT( GetWindow() != NULL
);
3159 return wxACC_NOT_IMPLEMENTED
;
3162 // Returns the description for this object or a child.
3163 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
3165 wxASSERT( GetWindow() != NULL
);
3169 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3175 return wxACC_NOT_IMPLEMENTED
;
3178 // Returns help text for this object or a child, similar to tooltip text.
3179 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
3181 wxASSERT( GetWindow() != NULL
);
3185 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3191 return wxACC_NOT_IMPLEMENTED
;
3194 // Returns the keyboard shortcut for this object or child.
3195 // Return e.g. ALT+K
3196 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
3198 wxASSERT( GetWindow() != NULL
);
3202 return wxACC_NOT_IMPLEMENTED
;
3205 // Returns a role constant.
3206 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
3208 wxASSERT( GetWindow() != NULL
);
3212 // If a child, leave wxWidgets to call the function on the actual
3215 return wxACC_NOT_IMPLEMENTED
;
3217 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3218 return wxACC_NOT_IMPLEMENTED
;
3220 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3221 return wxACC_NOT_IMPLEMENTED
;
3224 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3225 return wxACC_NOT_IMPLEMENTED
;
3228 //*role = wxROLE_SYSTEM_CLIENT;
3229 *role
= wxROLE_SYSTEM_CLIENT
;
3233 return wxACC_NOT_IMPLEMENTED
;
3237 // Returns a state constant.
3238 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
3240 wxASSERT( GetWindow() != NULL
);
3244 // If a child, leave wxWidgets to call the function on the actual
3247 return wxACC_NOT_IMPLEMENTED
;
3249 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3250 return wxACC_NOT_IMPLEMENTED
;
3253 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3254 return wxACC_NOT_IMPLEMENTED
;
3257 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3258 return wxACC_NOT_IMPLEMENTED
;
3265 return wxACC_NOT_IMPLEMENTED
;
3269 // Returns a localized string representing the value for the object
3271 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3273 wxASSERT( GetWindow() != NULL
);
3277 return wxACC_NOT_IMPLEMENTED
;
3280 // Selects the object or child.
3281 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3283 wxASSERT( GetWindow() != NULL
);
3287 return wxACC_NOT_IMPLEMENTED
;
3290 // Gets the window with the keyboard focus.
3291 // If childId is 0 and child is NULL, no object in
3292 // this subhierarchy has the focus.
3293 // If this object has the focus, child should be 'this'.
3294 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3296 wxASSERT( GetWindow() != NULL
);
3300 return wxACC_NOT_IMPLEMENTED
;
3304 // Gets a variant representing the selected children
3306 // Acceptable values:
3307 // - a null variant (IsNull() returns true)
3308 // - a list variant (GetType() == wxT("list")
3309 // - an integer representing the selected child element,
3310 // or 0 if this object is selected (GetType() == wxT("long")
3311 // - a "void*" pointer to a wxAccessible child object
3312 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3314 wxASSERT( GetWindow() != NULL
);
3318 return wxACC_NOT_IMPLEMENTED
;
3320 #endif // wxUSE_VARIANT
3322 #endif // wxUSE_ACCESSIBILITY
3324 // ----------------------------------------------------------------------------
3326 // ----------------------------------------------------------------------------
3329 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3331 wxCoord widthTotal
) const
3333 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3335 x
= widthTotal
- x
- width
;