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 GetEventHandler()->ProcessEvent(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 // ----------------------------------------------------------------------------
845 // show/hide/enable/disable the window
846 // ----------------------------------------------------------------------------
848 bool wxWindowBase
::Show(bool show
)
850 if ( show
!= m_isShown
)
862 bool wxWindowBase
::IsEnabled() const
864 return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
867 void wxWindowBase
::NotifyWindowOnEnableChange(bool enabled
)
869 #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
871 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
875 // If we are top-level then the logic doesn't apply - otherwise
876 // showing a modal dialog would result in total greying out (and ungreying
877 // out later) of everything which would be really ugly
881 for ( wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
883 node
= node
->GetNext() )
885 wxWindowBase
* const child
= node
->GetData();
886 if ( !child
->IsTopLevel() && child
->IsThisEnabled() )
887 child
->NotifyWindowOnEnableChange(enabled
);
891 bool wxWindowBase
::Enable(bool enable
)
893 if ( enable
== IsThisEnabled() )
896 m_isEnabled
= enable
;
898 #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
900 #else // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
901 wxWindowBase
* const parent
= GetParent();
902 if( !IsTopLevel() && parent
&& !parent
->IsEnabled() )
906 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
908 NotifyWindowOnEnableChange(enable
);
913 bool wxWindowBase
::IsShownOnScreen() const
915 // A window is shown on screen if it itself is shown and so are all its
916 // parents. But if a window is toplevel one, then its always visible on
917 // screen if IsShown() returns true, even if it has a hidden parent.
919 (IsTopLevel() || GetParent() == NULL
|| GetParent()->IsShownOnScreen());
922 // ----------------------------------------------------------------------------
924 // ----------------------------------------------------------------------------
926 bool wxWindowBase
::IsTopLevel() const
931 // ----------------------------------------------------------------------------
933 // ----------------------------------------------------------------------------
935 void wxWindowBase
::Freeze()
937 if ( !m_freezeCount
++ )
939 // physically freeze this window:
942 // and recursively freeze all children:
943 for ( wxWindowList
::iterator i
= GetChildren().begin();
944 i
!= GetChildren().end(); ++i
)
946 wxWindow
*child
= *i
;
947 if ( child
->IsTopLevel() )
955 void wxWindowBase
::Thaw()
957 wxASSERT_MSG( m_freezeCount
, "Thaw() without matching Freeze()" );
959 if ( !--m_freezeCount
)
961 // recursively thaw all children:
962 for ( wxWindowList
::iterator i
= GetChildren().begin();
963 i
!= GetChildren().end(); ++i
)
965 wxWindow
*child
= *i
;
966 if ( child
->IsTopLevel() )
972 // physically thaw this window:
977 // ----------------------------------------------------------------------------
978 // reparenting the window
979 // ----------------------------------------------------------------------------
981 void wxWindowBase
::AddChild(wxWindowBase
*child
)
983 wxCHECK_RET( child
, wxT("can't add a NULL child") );
985 // this should never happen and it will lead to a crash later if it does
986 // because RemoveChild() will remove only one node from the children list
987 // and the other(s) one(s) will be left with dangling pointers in them
988 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
990 GetChildren().Append((wxWindow
*)child
);
991 child
->SetParent(this);
993 // adding a child while frozen will assert when thawn, so freeze it as if
994 // it had been already present when we were frozen
995 if ( IsFrozen() && !child
->IsTopLevel() )
999 void wxWindowBase
::RemoveChild(wxWindowBase
*child
)
1001 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
1003 // removing a child while frozen may result in permanently frozen window
1004 // if used e.g. from Reparent(), so thaw it
1005 if ( IsFrozen() && !child
->IsTopLevel() )
1008 GetChildren().DeleteObject((wxWindow
*)child
);
1009 child
->SetParent(NULL
);
1012 bool wxWindowBase
::Reparent(wxWindowBase
*newParent
)
1014 wxWindow
*oldParent
= GetParent();
1015 if ( newParent
== oldParent
)
1021 const bool oldEnabledState
= IsEnabled();
1023 // unlink this window from the existing parent.
1026 oldParent
->RemoveChild(this);
1030 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
1033 // add it to the new one
1036 newParent
->AddChild(this);
1040 wxTopLevelWindows
.Append((wxWindow
*)this);
1043 // We need to notify window (and its subwindows) if by changing the parent
1044 // we also change our enabled/disabled status.
1045 const bool newEnabledState
= IsEnabled();
1046 if ( newEnabledState
!= oldEnabledState
)
1048 NotifyWindowOnEnableChange(newEnabledState
);
1054 // ----------------------------------------------------------------------------
1055 // event handler stuff
1056 // ----------------------------------------------------------------------------
1058 void wxWindowBase
::PushEventHandler(wxEvtHandler
*handler
)
1060 wxEvtHandler
*handlerOld
= GetEventHandler();
1062 handler
->SetNextHandler(handlerOld
);
1065 GetEventHandler()->SetPreviousHandler(handler
);
1067 SetEventHandler(handler
);
1070 wxEvtHandler
*wxWindowBase
::PopEventHandler(bool deleteHandler
)
1072 wxEvtHandler
*handlerA
= GetEventHandler();
1075 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
1076 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
1079 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
1080 SetEventHandler(handlerB
);
1082 if ( deleteHandler
)
1085 handlerA
= (wxEvtHandler
*)NULL
;
1092 bool wxWindowBase
::RemoveEventHandler(wxEvtHandler
*handler
)
1094 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
1096 wxEvtHandler
*handlerPrev
= NULL
,
1097 *handlerCur
= GetEventHandler();
1098 while ( handlerCur
)
1100 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
1102 if ( handlerCur
== handler
)
1106 handlerPrev
->SetNextHandler(handlerNext
);
1110 SetEventHandler(handlerNext
);
1115 handlerNext
->SetPreviousHandler ( handlerPrev
);
1118 handler
->SetNextHandler(NULL
);
1119 handler
->SetPreviousHandler(NULL
);
1124 handlerPrev
= handlerCur
;
1125 handlerCur
= handlerNext
;
1128 wxFAIL_MSG( _T("where has the event handler gone?") );
1133 bool wxWindowBase
::HandleWindowEvent(wxEvent
& event
) const
1135 return GetEventHandler()->SafelyProcessEvent(event
);
1138 // ----------------------------------------------------------------------------
1139 // colours, fonts &c
1140 // ----------------------------------------------------------------------------
1142 void wxWindowBase
::InheritAttributes()
1144 const wxWindowBase
* const parent
= GetParent();
1148 // we only inherit attributes which had been explicitly set for the parent
1149 // which ensures that this only happens if the user really wants it and
1150 // not by default which wouldn't make any sense in modern GUIs where the
1151 // controls don't all use the same fonts (nor colours)
1152 if ( parent
->m_inheritFont
&& !m_hasFont
)
1153 SetFont(parent
->GetFont());
1155 // in addition, there is a possibility to explicitly forbid inheriting
1156 // colours at each class level by overriding ShouldInheritColours()
1157 if ( ShouldInheritColours() )
1159 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1160 SetForegroundColour(parent
->GetForegroundColour());
1162 // inheriting (solid) background colour is wrong as it totally breaks
1163 // any kind of themed backgrounds
1165 // instead, the controls should use the same background as their parent
1166 // (ideally by not drawing it at all)
1168 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1169 SetBackgroundColour(parent
->GetBackgroundColour());
1174 /* static */ wxVisualAttributes
1175 wxWindowBase
::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1177 // it is important to return valid values for all attributes from here,
1178 // GetXXX() below rely on this
1179 wxVisualAttributes attrs
;
1180 attrs
.font
= wxSystemSettings
::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1181 attrs
.colFg
= wxSystemSettings
::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1183 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1184 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1185 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1186 // colour on other platforms.
1188 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1189 attrs
.colBg
= wxSystemSettings
::GetColour(wxSYS_COLOUR_WINDOW
);
1191 attrs
.colBg
= wxSystemSettings
::GetColour(wxSYS_COLOUR_BTNFACE
);
1196 wxColour wxWindowBase
::GetBackgroundColour() const
1198 if ( !m_backgroundColour
.IsOk() )
1200 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
1202 // get our default background colour
1203 wxColour colBg
= GetDefaultAttributes().colBg
;
1205 // we must return some valid colour to avoid redoing this every time
1206 // and also to avoid surprizing the applications written for older
1207 // wxWidgets versions where GetBackgroundColour() always returned
1208 // something -- so give them something even if it doesn't make sense
1209 // for this window (e.g. it has a themed background)
1211 colBg
= GetClassDefaultAttributes().colBg
;
1216 return m_backgroundColour
;
1219 wxColour wxWindowBase
::GetForegroundColour() const
1221 // logic is the same as above
1222 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1224 wxColour colFg
= GetDefaultAttributes().colFg
;
1226 if ( !colFg
.IsOk() )
1227 colFg
= GetClassDefaultAttributes().colFg
;
1232 return m_foregroundColour
;
1235 bool wxWindowBase
::SetBackgroundColour( const wxColour
&colour
)
1237 if ( colour
== m_backgroundColour
)
1240 m_hasBgCol
= colour
.IsOk();
1241 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1242 m_backgroundStyle
= m_hasBgCol ? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1244 m_inheritBgCol
= m_hasBgCol
;
1245 m_backgroundColour
= colour
;
1246 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1250 bool wxWindowBase
::SetForegroundColour( const wxColour
&colour
)
1252 if (colour
== m_foregroundColour
)
1255 m_hasFgCol
= colour
.IsOk();
1256 m_inheritFgCol
= m_hasFgCol
;
1257 m_foregroundColour
= colour
;
1258 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1262 bool wxWindowBase
::SetCursor(const wxCursor
& cursor
)
1264 // setting an invalid cursor is ok, it means that we don't have any special
1266 if ( m_cursor
.IsSameAs(cursor
) )
1277 wxFont wxWindowBase
::GetFont() const
1279 // logic is the same as in GetBackgroundColour()
1280 if ( !m_font
.IsOk() )
1282 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1284 wxFont font
= GetDefaultAttributes().font
;
1286 font
= GetClassDefaultAttributes().font
;
1294 bool wxWindowBase
::SetFont(const wxFont
& font
)
1296 if ( font
== m_font
)
1303 m_hasFont
= font
.IsOk();
1304 m_inheritFont
= m_hasFont
;
1306 InvalidateBestSize();
1313 void wxWindowBase
::SetPalette(const wxPalette
& pal
)
1315 m_hasCustomPalette
= true;
1318 // VZ: can anyone explain me what do we do here?
1319 wxWindowDC
d((wxWindow
*) this);
1323 wxWindow
*wxWindowBase
::GetAncestorWithCustomPalette() const
1325 wxWindow
*win
= (wxWindow
*)this;
1326 while ( win
&& !win
->HasCustomPalette() )
1328 win
= win
->GetParent();
1334 #endif // wxUSE_PALETTE
1337 void wxWindowBase
::SetCaret(wxCaret
*caret
)
1348 wxASSERT_MSG( m_caret
->GetWindow() == this,
1349 wxT("caret should be created associated to this window") );
1352 #endif // wxUSE_CARET
1354 #if wxUSE_VALIDATORS
1355 // ----------------------------------------------------------------------------
1357 // ----------------------------------------------------------------------------
1359 void wxWindowBase
::SetValidator(const wxValidator
& validator
)
1361 if ( m_windowValidator
)
1362 delete m_windowValidator
;
1364 m_windowValidator
= (wxValidator
*)validator
.Clone();
1366 if ( m_windowValidator
)
1367 m_windowValidator
->SetWindow(this);
1369 #endif // wxUSE_VALIDATORS
1371 // ----------------------------------------------------------------------------
1372 // update region stuff
1373 // ----------------------------------------------------------------------------
1375 wxRect wxWindowBase
::GetUpdateClientRect() const
1377 wxRegion rgnUpdate
= GetUpdateRegion();
1378 rgnUpdate
.Intersect(GetClientRect());
1379 wxRect rectUpdate
= rgnUpdate
.GetBox();
1380 wxPoint ptOrigin
= GetClientAreaOrigin();
1381 rectUpdate
.x
-= ptOrigin
.x
;
1382 rectUpdate
.y
-= ptOrigin
.y
;
1387 bool wxWindowBase
::DoIsExposed(int x
, int y
) const
1389 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1392 bool wxWindowBase
::DoIsExposed(int x
, int y
, int w
, int h
) const
1394 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1397 void wxWindowBase
::ClearBackground()
1399 // wxGTK uses its own version, no need to add never used code
1401 wxClientDC
dc((wxWindow
*)this);
1402 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1403 dc
.SetBackground(brush
);
1408 // ----------------------------------------------------------------------------
1409 // find child window by id or name
1410 // ----------------------------------------------------------------------------
1412 wxWindow
*wxWindowBase
::FindWindow(long id
) const
1414 if ( id
== m_windowId
)
1415 return (wxWindow
*)this;
1417 wxWindowBase
*res
= (wxWindow
*)NULL
;
1418 wxWindowList
::compatibility_iterator node
;
1419 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1421 wxWindowBase
*child
= node
->GetData();
1422 res
= child
->FindWindow( id
);
1425 return (wxWindow
*)res
;
1428 wxWindow
*wxWindowBase
::FindWindow(const wxString
& name
) const
1430 if ( name
== m_windowName
)
1431 return (wxWindow
*)this;
1433 wxWindowBase
*res
= (wxWindow
*)NULL
;
1434 wxWindowList
::compatibility_iterator node
;
1435 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1437 wxWindow
*child
= node
->GetData();
1438 res
= child
->FindWindow(name
);
1441 return (wxWindow
*)res
;
1445 // find any window by id or name or label: If parent is non-NULL, look through
1446 // children for a label or title matching the specified string. If NULL, look
1447 // through all top-level windows.
1449 // to avoid duplicating code we reuse the same helper function but with
1450 // different comparators
1452 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1453 const wxString
& label
, long id
);
1456 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1459 return win
->GetLabel() == label
;
1463 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1466 return win
->GetName() == label
;
1470 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1473 return win
->GetId() == id
;
1476 // recursive helper for the FindWindowByXXX() functions
1478 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1479 const wxString
& label
,
1481 wxFindWindowCmp cmp
)
1485 // see if this is the one we're looking for
1486 if ( (*cmp
)(parent
, label
, id
) )
1487 return (wxWindow
*)parent
;
1489 // It wasn't, so check all its children
1490 for ( wxWindowList
::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1492 node
= node
->GetNext() )
1494 // recursively check each child
1495 wxWindow
*win
= (wxWindow
*)node
->GetData();
1496 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1506 // helper for FindWindowByXXX()
1508 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1509 const wxString
& label
,
1511 wxFindWindowCmp cmp
)
1515 // just check parent and all its children
1516 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1519 // start at very top of wx's windows
1520 for ( wxWindowList
::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1522 node
= node
->GetNext() )
1524 // recursively check each window & its children
1525 wxWindow
*win
= node
->GetData();
1526 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1536 wxWindowBase
::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1538 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1543 wxWindowBase
::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1545 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1549 // fall back to the label
1550 win
= FindWindowByLabel(title
, parent
);
1558 wxWindowBase
::FindWindowById( long id
, const wxWindow
* parent
)
1560 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1563 // ----------------------------------------------------------------------------
1564 // dialog oriented functions
1565 // ----------------------------------------------------------------------------
1567 void wxWindowBase
::MakeModal(bool modal
)
1569 // Disable all other windows
1572 wxWindowList
::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1575 wxWindow
*win
= node
->GetData();
1577 win
->Enable(!modal
);
1579 node
= node
->GetNext();
1584 bool wxWindowBase
::Validate()
1586 #if wxUSE_VALIDATORS
1587 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1589 wxWindowList
::compatibility_iterator node
;
1590 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1592 wxWindowBase
*child
= node
->GetData();
1593 wxValidator
*validator
= child
->GetValidator();
1594 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1599 if ( recurse
&& !child
->Validate() )
1604 #endif // wxUSE_VALIDATORS
1609 bool wxWindowBase
::TransferDataToWindow()
1611 #if wxUSE_VALIDATORS
1612 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1614 wxWindowList
::compatibility_iterator node
;
1615 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1617 wxWindowBase
*child
= node
->GetData();
1618 wxValidator
*validator
= child
->GetValidator();
1619 if ( validator
&& !validator
->TransferToWindow() )
1621 wxLogWarning(_("Could not transfer data to window"));
1623 wxLog
::FlushActive();
1631 if ( !child
->TransferDataToWindow() )
1633 // warning already given
1638 #endif // wxUSE_VALIDATORS
1643 bool wxWindowBase
::TransferDataFromWindow()
1645 #if wxUSE_VALIDATORS
1646 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1648 wxWindowList
::compatibility_iterator node
;
1649 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1651 wxWindow
*child
= node
->GetData();
1652 wxValidator
*validator
= child
->GetValidator();
1653 if ( validator
&& !validator
->TransferFromWindow() )
1655 // nop warning here because the application is supposed to give
1656 // one itself - we don't know here what might have gone wrongly
1663 if ( !child
->TransferDataFromWindow() )
1665 // warning already given
1670 #endif // wxUSE_VALIDATORS
1675 void wxWindowBase
::InitDialog()
1677 wxInitDialogEvent
event(GetId());
1678 event
.SetEventObject( this );
1679 GetEventHandler()->ProcessEvent(event
);
1682 // ----------------------------------------------------------------------------
1683 // context-sensitive help support
1684 // ----------------------------------------------------------------------------
1688 // associate this help text with this window
1689 void wxWindowBase
::SetHelpText(const wxString
& text
)
1691 wxHelpProvider
*helpProvider
= wxHelpProvider
::Get();
1694 helpProvider
->AddHelp(this, text
);
1698 // associate this help text with all windows with the same id as this
1700 void wxWindowBase
::SetHelpTextForId(const wxString
& text
)
1702 wxHelpProvider
*helpProvider
= wxHelpProvider
::Get();
1705 helpProvider
->AddHelp(GetId(), text
);
1709 // get the help string associated with this window (may be empty)
1710 // default implementation forwards calls to the help provider
1712 wxWindowBase
::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1713 wxHelpEvent
::Origin
WXUNUSED(origin
)) const
1716 wxHelpProvider
*helpProvider
= wxHelpProvider
::Get();
1719 text
= helpProvider
->GetHelp(this);
1725 // show help for this window
1726 void wxWindowBase
::OnHelp(wxHelpEvent
& event
)
1728 wxHelpProvider
*helpProvider
= wxHelpProvider
::Get();
1731 wxPoint pos
= event
.GetPosition();
1732 const wxHelpEvent
::Origin origin
= event
.GetOrigin();
1733 if ( origin
== wxHelpEvent
::Origin_Keyboard
)
1735 // if the help event was generated from keyboard it shouldn't
1736 // appear at the mouse position (which is still the only position
1737 // associated with help event) if the mouse is far away, although
1738 // we still do use the mouse position if it's over the window
1739 // because we suppose the user looks approximately at the mouse
1740 // already and so it would be more convenient than showing tooltip
1741 // at some arbitrary position which can be quite far from it
1742 const wxRect rectClient
= GetClientRect();
1743 if ( !rectClient
.Contains(ScreenToClient(pos
)) )
1745 // position help slightly under and to the right of this window
1746 pos
= ClientToScreen(wxPoint(
1748 rectClient
.height
+ GetCharHeight()
1753 if ( helpProvider
->ShowHelpAtPoint(this, pos
, origin
) )
1755 // skip the event.Skip() below
1763 #endif // wxUSE_HELP
1765 // ----------------------------------------------------------------------------
1767 // ----------------------------------------------------------------------------
1771 void wxWindowBase
::SetToolTip( const wxString
&tip
)
1773 // don't create the new tooltip if we already have one
1776 m_tooltip
->SetTip( tip
);
1780 SetToolTip( new wxToolTip( tip
) );
1783 // setting empty tooltip text does not remove the tooltip any more - use
1784 // SetToolTip((wxToolTip *)NULL) for this
1787 void wxWindowBase
::DoSetToolTip(wxToolTip
*tooltip
)
1789 if ( m_tooltip
!= tooltip
)
1794 m_tooltip
= tooltip
;
1798 #endif // wxUSE_TOOLTIPS
1800 // ----------------------------------------------------------------------------
1801 // constraints and sizers
1802 // ----------------------------------------------------------------------------
1804 #if wxUSE_CONSTRAINTS
1806 void wxWindowBase
::SetConstraints( wxLayoutConstraints
*constraints
)
1808 if ( m_constraints
)
1810 UnsetConstraints(m_constraints
);
1811 delete m_constraints
;
1813 m_constraints
= constraints
;
1814 if ( m_constraints
)
1816 // Make sure other windows know they're part of a 'meaningful relationship'
1817 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1818 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1819 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1820 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1821 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1822 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1823 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1824 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1825 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1826 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1827 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1828 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1829 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1830 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1831 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1832 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1836 // This removes any dangling pointers to this window in other windows'
1837 // constraintsInvolvedIn lists.
1838 void wxWindowBase
::UnsetConstraints(wxLayoutConstraints
*c
)
1842 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1843 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1844 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1845 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1846 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1847 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1848 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1849 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1850 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1851 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1852 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1853 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1854 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1855 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1856 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1857 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1861 // Back-pointer to other windows we're involved with, so if we delete this
1862 // window, we must delete any constraints we're involved with.
1863 void wxWindowBase
::AddConstraintReference(wxWindowBase
*otherWin
)
1865 if ( !m_constraintsInvolvedIn
)
1866 m_constraintsInvolvedIn
= new wxWindowList
;
1867 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1868 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1871 // REMOVE back-pointer to other windows we're involved with.
1872 void wxWindowBase
::RemoveConstraintReference(wxWindowBase
*otherWin
)
1874 if ( m_constraintsInvolvedIn
)
1875 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1878 // Reset any constraints that mention this window
1879 void wxWindowBase
::DeleteRelatedConstraints()
1881 if ( m_constraintsInvolvedIn
)
1883 wxWindowList
::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1886 wxWindow
*win
= node
->GetData();
1887 wxLayoutConstraints
*constr
= win
->GetConstraints();
1889 // Reset any constraints involving this window
1892 constr
->left
.ResetIfWin(this);
1893 constr
->top
.ResetIfWin(this);
1894 constr
->right
.ResetIfWin(this);
1895 constr
->bottom
.ResetIfWin(this);
1896 constr
->width
.ResetIfWin(this);
1897 constr
->height
.ResetIfWin(this);
1898 constr
->centreX
.ResetIfWin(this);
1899 constr
->centreY
.ResetIfWin(this);
1902 wxWindowList
::compatibility_iterator next
= node
->GetNext();
1903 m_constraintsInvolvedIn
->Erase(node
);
1907 delete m_constraintsInvolvedIn
;
1908 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1912 #endif // wxUSE_CONSTRAINTS
1914 void wxWindowBase
::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1916 if ( sizer
== m_windowSizer
)
1919 if ( m_windowSizer
)
1921 m_windowSizer
->SetContainingWindow(NULL
);
1924 delete m_windowSizer
;
1927 m_windowSizer
= sizer
;
1928 if ( m_windowSizer
)
1930 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
1933 SetAutoLayout(m_windowSizer
!= NULL
);
1936 void wxWindowBase
::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1938 SetSizer( sizer
, deleteOld
);
1939 sizer
->SetSizeHints( (wxWindow
*) this );
1943 void wxWindowBase
::SetContainingSizer(wxSizer
* sizer
)
1945 // adding a window to a sizer twice is going to result in fatal and
1946 // hard to debug problems later because when deleting the second
1947 // associated wxSizerItem we're going to dereference a dangling
1948 // pointer; so try to detect this as early as possible
1949 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1950 _T("Adding a window to the same sizer twice?") );
1952 m_containingSizer
= sizer
;
1955 #if wxUSE_CONSTRAINTS
1957 void wxWindowBase
::SatisfyConstraints()
1959 wxLayoutConstraints
*constr
= GetConstraints();
1960 bool wasOk
= constr
&& constr
->AreSatisfied();
1962 ResetConstraints(); // Mark all constraints as unevaluated
1966 // if we're a top level panel (i.e. our parent is frame/dialog), our
1967 // own constraints will never be satisfied any more unless we do it
1971 while ( noChanges
> 0 )
1973 LayoutPhase1(&noChanges
);
1977 LayoutPhase2(&noChanges
);
1980 #endif // wxUSE_CONSTRAINTS
1982 bool wxWindowBase
::Layout()
1984 // If there is a sizer, use it instead of the constraints
1988 GetVirtualSize(&w
, &h
);
1989 GetSizer()->SetDimension( 0, 0, w
, h
);
1991 #if wxUSE_CONSTRAINTS
1994 SatisfyConstraints(); // Find the right constraints values
1995 SetConstraintSizes(); // Recursively set the real window sizes
2002 #if wxUSE_CONSTRAINTS
2004 // first phase of the constraints evaluation: set our own constraints
2005 bool wxWindowBase
::LayoutPhase1(int *noChanges
)
2007 wxLayoutConstraints
*constr
= GetConstraints();
2009 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
2012 // second phase: set the constraints for our children
2013 bool wxWindowBase
::LayoutPhase2(int *noChanges
)
2020 // Layout grand children
2026 // Do a phase of evaluating child constraints
2027 bool wxWindowBase
::DoPhase(int phase
)
2029 // the list containing the children for which the constraints are already
2031 wxWindowList succeeded
;
2033 // the max number of iterations we loop before concluding that we can't set
2035 static const int maxIterations
= 500;
2037 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
2041 // loop over all children setting their constraints
2042 for ( wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
2044 node
= node
->GetNext() )
2046 wxWindow
*child
= node
->GetData();
2047 if ( child
->IsTopLevel() )
2049 // top level children are not inside our client area
2053 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
2055 // this one is either already ok or nothing we can do about it
2059 int tempNoChanges
= 0;
2060 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
2061 : child
->LayoutPhase2(&tempNoChanges
);
2062 noChanges
+= tempNoChanges
;
2066 succeeded
.Append(child
);
2072 // constraints are set
2080 void wxWindowBase
::ResetConstraints()
2082 wxLayoutConstraints
*constr
= GetConstraints();
2085 constr
->left
.SetDone(false);
2086 constr
->top
.SetDone(false);
2087 constr
->right
.SetDone(false);
2088 constr
->bottom
.SetDone(false);
2089 constr
->width
.SetDone(false);
2090 constr
->height
.SetDone(false);
2091 constr
->centreX
.SetDone(false);
2092 constr
->centreY
.SetDone(false);
2095 wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
2098 wxWindow
*win
= node
->GetData();
2099 if ( !win
->IsTopLevel() )
2100 win
->ResetConstraints();
2101 node
= node
->GetNext();
2105 // Need to distinguish between setting the 'fake' size for windows and sizers,
2106 // and setting the real values.
2107 void wxWindowBase
::SetConstraintSizes(bool recurse
)
2109 wxLayoutConstraints
*constr
= GetConstraints();
2110 if ( constr
&& constr
->AreSatisfied() )
2112 int x
= constr
->left
.GetValue();
2113 int y
= constr
->top
.GetValue();
2114 int w
= constr
->width
.GetValue();
2115 int h
= constr
->height
.GetValue();
2117 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
2118 (constr
->height
.GetRelationship() != wxAsIs
) )
2120 SetSize(x
, y
, w
, h
);
2124 // If we don't want to resize this window, just move it...
2130 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
2131 GetClassInfo()->GetClassName(),
2137 wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
2140 wxWindow
*win
= node
->GetData();
2141 if ( !win
->IsTopLevel() && win
->GetConstraints() )
2142 win
->SetConstraintSizes();
2143 node
= node
->GetNext();
2148 // Only set the size/position of the constraint (if any)
2149 void wxWindowBase
::SetSizeConstraint(int x
, int y
, int w
, int h
)
2151 wxLayoutConstraints
*constr
= GetConstraints();
2154 if ( x
!= wxDefaultCoord
)
2156 constr
->left
.SetValue(x
);
2157 constr
->left
.SetDone(true);
2159 if ( y
!= wxDefaultCoord
)
2161 constr
->top
.SetValue(y
);
2162 constr
->top
.SetDone(true);
2164 if ( w
!= wxDefaultCoord
)
2166 constr
->width
.SetValue(w
);
2167 constr
->width
.SetDone(true);
2169 if ( h
!= wxDefaultCoord
)
2171 constr
->height
.SetValue(h
);
2172 constr
->height
.SetDone(true);
2177 void wxWindowBase
::MoveConstraint(int x
, int y
)
2179 wxLayoutConstraints
*constr
= GetConstraints();
2182 if ( x
!= wxDefaultCoord
)
2184 constr
->left
.SetValue(x
);
2185 constr
->left
.SetDone(true);
2187 if ( y
!= wxDefaultCoord
)
2189 constr
->top
.SetValue(y
);
2190 constr
->top
.SetDone(true);
2195 void wxWindowBase
::GetSizeConstraint(int *w
, int *h
) const
2197 wxLayoutConstraints
*constr
= GetConstraints();
2200 *w
= constr
->width
.GetValue();
2201 *h
= constr
->height
.GetValue();
2207 void wxWindowBase
::GetClientSizeConstraint(int *w
, int *h
) const
2209 wxLayoutConstraints
*constr
= GetConstraints();
2212 *w
= constr
->width
.GetValue();
2213 *h
= constr
->height
.GetValue();
2216 GetClientSize(w
, h
);
2219 void wxWindowBase
::GetPositionConstraint(int *x
, int *y
) const
2221 wxLayoutConstraints
*constr
= GetConstraints();
2224 *x
= constr
->left
.GetValue();
2225 *y
= constr
->top
.GetValue();
2231 #endif // wxUSE_CONSTRAINTS
2233 void wxWindowBase
::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2235 // don't do it for the dialogs/frames - they float independently of their
2237 if ( !IsTopLevel() )
2239 wxWindow
*parent
= GetParent();
2240 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2242 wxPoint
pt(parent
->GetClientAreaOrigin());
2249 // ----------------------------------------------------------------------------
2250 // Update UI processing
2251 // ----------------------------------------------------------------------------
2253 void wxWindowBase
::UpdateWindowUI(long flags
)
2255 wxUpdateUIEvent
event(GetId());
2256 event
.SetEventObject(this);
2258 if ( GetEventHandler()->ProcessEvent(event
) )
2260 DoUpdateWindowUI(event
);
2263 if (flags
& wxUPDATE_UI_RECURSE
)
2265 wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
2268 wxWindow
* child
= (wxWindow
*) node
->GetData();
2269 child
->UpdateWindowUI(flags
);
2270 node
= node
->GetNext();
2275 // do the window-specific processing after processing the update event
2276 void wxWindowBase
::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2278 if ( event
.GetSetEnabled() )
2279 Enable(event
.GetEnabled());
2281 if ( event
.GetSetShown() )
2282 Show(event
.GetShown());
2285 // ----------------------------------------------------------------------------
2286 // dialog units translations
2287 // ----------------------------------------------------------------------------
2289 wxPoint wxWindowBase
::ConvertPixelsToDialog(const wxPoint
& pt
)
2291 int charWidth
= GetCharWidth();
2292 int charHeight
= GetCharHeight();
2293 wxPoint pt2
= wxDefaultPosition
;
2294 if (pt
.x
!= wxDefaultCoord
)
2295 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2296 if (pt
.y
!= wxDefaultCoord
)
2297 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2302 wxPoint wxWindowBase
::ConvertDialogToPixels(const wxPoint
& pt
)
2304 int charWidth
= GetCharWidth();
2305 int charHeight
= GetCharHeight();
2306 wxPoint pt2
= wxDefaultPosition
;
2307 if (pt
.x
!= wxDefaultCoord
)
2308 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2309 if (pt
.y
!= wxDefaultCoord
)
2310 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2315 // ----------------------------------------------------------------------------
2317 // ----------------------------------------------------------------------------
2319 // propagate the colour change event to the subwindows
2320 void wxWindowBase
::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2322 wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
2325 // Only propagate to non-top-level windows
2326 wxWindow
*win
= node
->GetData();
2327 if ( !win
->IsTopLevel() )
2329 wxSysColourChangedEvent event2
;
2330 event
.SetEventObject(win
);
2331 win
->GetEventHandler()->ProcessEvent(event2
);
2334 node
= node
->GetNext();
2340 // the default action is to populate dialog with data when it's created,
2341 // and nudge the UI into displaying itself correctly in case
2342 // we've turned the wxUpdateUIEvents frequency down low.
2343 void wxWindowBase
::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2345 TransferDataToWindow();
2347 // Update the UI at this point
2348 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2351 // ----------------------------------------------------------------------------
2352 // menu-related functions
2353 // ----------------------------------------------------------------------------
2357 bool wxWindowBase
::PopupMenu(wxMenu
*menu
, int x
, int y
)
2359 wxCHECK_MSG( menu
, false, "can't popup NULL menu" );
2361 wxCurrentPopupMenu
= menu
;
2362 const bool rc
= DoPopupMenu(menu
, x
, y
);
2363 wxCurrentPopupMenu
= NULL
;
2368 // this is used to pass the id of the selected item from the menu event handler
2369 // to the main function itself
2371 // it's ok to use a global here as there can be at most one popup menu shown at
2373 static int gs_popupMenuSelection
= wxID_NONE
;
2375 void wxWindowBase
::InternalOnPopupMenu(wxCommandEvent
& event
)
2377 // store the id in a global variable where we'll retrieve it from later
2378 gs_popupMenuSelection
= event
.GetId();
2382 wxWindowBase
::DoGetPopupMenuSelectionFromUser(wxMenu
& menu
, int x
, int y
)
2384 gs_popupMenuSelection
= wxID_NONE
;
2386 Connect(wxEVT_COMMAND_MENU_SELECTED
,
2387 wxCommandEventHandler(wxWindowBase
::InternalOnPopupMenu
),
2391 PopupMenu(&menu
, x
, y
);
2393 Disconnect(wxEVT_COMMAND_MENU_SELECTED
,
2394 wxCommandEventHandler(wxWindowBase
::InternalOnPopupMenu
),
2398 return gs_popupMenuSelection
;
2401 #endif // wxUSE_MENUS
2403 // methods for drawing the sizers in a visible way
2406 static void DrawSizers(wxWindowBase
*win
);
2408 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2410 wxClientDC
dc((wxWindow
*)win
);
2411 dc
.SetPen(*wxRED_PEN
);
2412 dc
.SetBrush(fill ?
wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2413 dc
.DrawRectangle(rect
.Deflate(1, 1));
2416 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2418 const wxSizerItemList
& items
= sizer
->GetChildren();
2419 for ( wxSizerItemList
::const_iterator i
= items
.begin(),
2424 wxSizerItem
*item
= *i
;
2425 if ( item
->IsSizer() )
2427 DrawBorder(win
, item
->GetRect().Deflate(2));
2428 DrawSizer(win
, item
->GetSizer());
2430 else if ( item
->IsSpacer() )
2432 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2434 else if ( item
->IsWindow() )
2436 DrawSizers(item
->GetWindow());
2441 static void DrawSizers(wxWindowBase
*win
)
2443 wxSizer
*sizer
= win
->GetSizer();
2446 DrawBorder(win
, win
->GetClientSize());
2447 DrawSizer(win
, sizer
);
2449 else // no sizer, still recurse into the children
2451 const wxWindowList
& children
= win
->GetChildren();
2452 for ( wxWindowList
::const_iterator i
= children
.begin(),
2453 end
= children
.end();
2462 #endif // __WXDEBUG__
2464 // process special middle clicks
2465 void wxWindowBase
::OnMiddleClick( wxMouseEvent
& event
)
2467 if ( event
.ControlDown() && event
.AltDown() )
2470 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2471 if ( event
.ShiftDown() )
2476 #endif // __WXDEBUG__
2477 ::wxInfoMessageBox((wxWindow
*)this);
2485 // ----------------------------------------------------------------------------
2487 // ----------------------------------------------------------------------------
2489 #if wxUSE_ACCESSIBILITY
2490 void wxWindowBase
::SetAccessible(wxAccessible
* accessible
)
2492 if (m_accessible
&& (accessible
!= m_accessible
))
2493 delete m_accessible
;
2494 m_accessible
= accessible
;
2496 m_accessible
->SetWindow((wxWindow
*) this);
2499 // Returns the accessible object, creating if necessary.
2500 wxAccessible
* wxWindowBase
::GetOrCreateAccessible()
2503 m_accessible
= CreateAccessible();
2504 return m_accessible
;
2507 // Override to create a specific accessible object.
2508 wxAccessible
* wxWindowBase
::CreateAccessible()
2510 return new wxWindowAccessible((wxWindow
*) this);
2515 // ----------------------------------------------------------------------------
2516 // list classes implementation
2517 // ----------------------------------------------------------------------------
2521 #include "wx/listimpl.cpp"
2522 WX_DEFINE_LIST(wxWindowList
)
2526 void wxWindowListNode
::DeleteData()
2528 delete (wxWindow
*)GetData();
2531 #endif // wxUSE_STL/!wxUSE_STL
2533 // ----------------------------------------------------------------------------
2535 // ----------------------------------------------------------------------------
2537 wxBorder wxWindowBase
::GetBorder(long flags
) const
2539 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2540 if ( border
== wxBORDER_DEFAULT
)
2542 border
= GetDefaultBorder();
2544 else if ( border
== wxBORDER_THEME
)
2546 border
= GetDefaultBorderForControl();
2552 wxBorder wxWindowBase
::GetDefaultBorder() const
2554 return wxBORDER_NONE
;
2557 // ----------------------------------------------------------------------------
2559 // ----------------------------------------------------------------------------
2561 wxHitTest wxWindowBase
::DoHitTest(wxCoord x
, wxCoord y
) const
2563 // here we just check if the point is inside the window or not
2565 // check the top and left border first
2566 bool outside
= x
< 0 || y
< 0;
2569 // check the right and bottom borders too
2570 wxSize size
= GetSize();
2571 outside
= x
>= size
.x
|| y
>= size
.y
;
2574 return outside ? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2577 // ----------------------------------------------------------------------------
2579 // ----------------------------------------------------------------------------
2581 struct WXDLLEXPORT wxWindowNext
2585 } *wxWindowBase
::ms_winCaptureNext
= NULL
;
2586 wxWindow
*wxWindowBase
::ms_winCaptureCurrent
= NULL
;
2587 bool wxWindowBase
::ms_winCaptureChanging
= false;
2589 void wxWindowBase
::CaptureMouse()
2591 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2593 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2595 ms_winCaptureChanging
= true;
2597 wxWindow
*winOld
= GetCapture();
2600 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2603 wxWindowNext
*item
= new wxWindowNext
;
2605 item
->next
= ms_winCaptureNext
;
2606 ms_winCaptureNext
= item
;
2608 //else: no mouse capture to save
2611 ms_winCaptureCurrent
= (wxWindow
*)this;
2613 ms_winCaptureChanging
= false;
2616 void wxWindowBase
::ReleaseMouse()
2618 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2620 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2622 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2624 ms_winCaptureChanging
= true;
2627 ms_winCaptureCurrent
= NULL
;
2629 if ( ms_winCaptureNext
)
2631 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2632 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2634 wxWindowNext
*item
= ms_winCaptureNext
;
2635 ms_winCaptureNext
= item
->next
;
2638 //else: stack is empty, no previous capture
2640 ms_winCaptureChanging
= false;
2642 wxLogTrace(_T("mousecapture"),
2643 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2644 wx_static_cast(void*, GetCapture()));
2647 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2649 wxMouseCaptureLostEvent
event(win
->GetId());
2650 event
.SetEventObject(win
);
2651 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2653 // windows must handle this event, otherwise the app wouldn't behave
2654 // correctly if it loses capture unexpectedly; see the discussion here:
2655 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
2656 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
2657 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2662 void wxWindowBase
::NotifyCaptureLost()
2664 // don't do anything if capture lost was expected, i.e. resulted from
2665 // a wx call to ReleaseMouse or CaptureMouse:
2666 if ( ms_winCaptureChanging
)
2669 // if the capture was lost unexpectedly, notify every window that has
2670 // capture (on stack or current) about it and clear the stack:
2672 if ( ms_winCaptureCurrent
)
2674 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2675 ms_winCaptureCurrent
= NULL
;
2678 while ( ms_winCaptureNext
)
2680 wxWindowNext
*item
= ms_winCaptureNext
;
2681 ms_winCaptureNext
= item
->next
;
2683 DoNotifyWindowAboutCaptureLost(item
->win
);
2692 wxWindowBase
::RegisterHotKey(int WXUNUSED(hotkeyId
),
2693 int WXUNUSED(modifiers
),
2694 int WXUNUSED(keycode
))
2700 bool wxWindowBase
::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2706 #endif // wxUSE_HOTKEY
2708 // ----------------------------------------------------------------------------
2710 // ----------------------------------------------------------------------------
2712 bool wxWindowBase
::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2714 #if wxUSE_VALIDATORS
2715 // Can only use the validator of the window which
2716 // is receiving the event
2717 if ( event
.GetEventObject() == this )
2719 wxValidator
*validator
= GetValidator();
2720 if ( validator
&& validator
->ProcessEvent(event
) )
2725 #endif // wxUSE_VALIDATORS
2730 bool wxWindowBase
::TryParent(wxEvent
& event
)
2732 // carry on up the parent-child hierarchy if the propagation count hasn't
2734 if ( event
.ShouldPropagate() )
2736 // honour the requests to stop propagation at this window: this is
2737 // used by the dialogs, for example, to prevent processing the events
2738 // from the dialog controls in the parent frame which rarely, if ever,
2740 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2742 wxWindow
*parent
= GetParent();
2743 if ( parent
&& !parent
->IsBeingDeleted() )
2745 wxPropagateOnce
propagateOnce(event
);
2747 return parent
->GetEventHandler()->ProcessEvent(event
);
2752 return wxEvtHandler
::TryParent(event
);
2755 // ----------------------------------------------------------------------------
2756 // window relationships
2757 // ----------------------------------------------------------------------------
2759 wxWindow
*wxWindowBase
::DoGetSibling(WindowOrder order
) const
2761 wxCHECK_MSG( GetParent(), NULL
,
2762 _T("GetPrev/NextSibling() don't work for TLWs!") );
2764 wxWindowList
& siblings
= GetParent()->GetChildren();
2765 wxWindowList
::compatibility_iterator i
= siblings
.Find((wxWindow
*)this);
2766 wxCHECK_MSG( i
, NULL
, _T("window not a child of its parent?") );
2768 if ( order
== OrderBefore
)
2769 i
= i
->GetPrevious();
2773 return i ? i
->GetData() : NULL
;
2776 // ----------------------------------------------------------------------------
2777 // keyboard navigation
2778 // ----------------------------------------------------------------------------
2780 // Navigates in the specified direction inside this window
2781 bool wxWindowBase
::DoNavigateIn(int flags
)
2783 #ifdef wxHAS_NATIVE_TAB_TRAVERSAL
2784 // native code doesn't process our wxNavigationKeyEvents anyhow
2787 #else // !wxHAS_NATIVE_TAB_TRAVERSAL
2788 wxNavigationKeyEvent eventNav
;
2789 wxWindow
*focused
= FindFocus();
2790 eventNav
.SetCurrentFocus(focused
);
2791 eventNav
.SetEventObject(focused
);
2792 eventNav
.SetFlags(flags
);
2793 return GetEventHandler()->ProcessEvent(eventNav
);
2794 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
2797 bool wxWindowBase
::HandleAsNavigationKey(const wxKeyEvent
& event
)
2799 if ( event
.GetKeyCode() != WXK_TAB
)
2802 int flags
= wxNavigationKeyEvent
::FromTab
;
2804 if ( event
.ShiftDown() )
2805 flags
|= wxNavigationKeyEvent
::IsBackward
;
2807 flags
|= wxNavigationKeyEvent
::IsForward
;
2809 if ( event
.ControlDown() )
2810 flags
|= wxNavigationKeyEvent
::WinChange
;
2816 void wxWindowBase
::DoMoveInTabOrder(wxWindow
*win
, WindowOrder move
)
2818 // check that we're not a top level window
2819 wxCHECK_RET( GetParent(),
2820 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2822 // detect the special case when we have nothing to do anyhow and when the
2823 // code below wouldn't work
2827 // find the target window in the siblings list
2828 wxWindowList
& siblings
= GetParent()->GetChildren();
2829 wxWindowList
::compatibility_iterator i
= siblings
.Find(win
);
2830 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2832 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2833 // can't just move the node around
2834 wxWindow
*self
= (wxWindow
*)this;
2835 siblings
.DeleteObject(self
);
2836 if ( move
== OrderAfter
)
2843 siblings
.Insert(i
, self
);
2845 else // OrderAfter and win was the last sibling
2847 siblings
.Append(self
);
2851 // ----------------------------------------------------------------------------
2853 // ----------------------------------------------------------------------------
2855 /*static*/ wxWindow
* wxWindowBase
::FindFocus()
2857 wxWindowBase
*win
= DoFindFocus();
2858 return win ? win
->GetMainWindowOfCompositeControl() : NULL
;
2861 bool wxWindowBase
::HasFocus() const
2863 wxWindowBase
*win
= DoFindFocus();
2864 return win
== this ||
2865 win
== wxConstCast(this, wxWindowBase
)->GetMainWindowOfCompositeControl();
2868 // ----------------------------------------------------------------------------
2870 // ----------------------------------------------------------------------------
2872 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2874 while ( win
&& !win
->IsTopLevel() )
2875 win
= win
->GetParent();
2880 #if wxUSE_ACCESSIBILITY
2881 // ----------------------------------------------------------------------------
2882 // accessible object for windows
2883 // ----------------------------------------------------------------------------
2885 // Can return either a child object, or an integer
2886 // representing the child element, starting from 1.
2887 wxAccStatus wxWindowAccessible
::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2889 wxASSERT( GetWindow() != NULL
);
2893 return wxACC_NOT_IMPLEMENTED
;
2896 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2897 wxAccStatus wxWindowAccessible
::GetLocation(wxRect
& rect
, int elementId
)
2899 wxASSERT( GetWindow() != NULL
);
2903 wxWindow
* win
= NULL
;
2910 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2912 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2919 rect
= win
->GetRect();
2920 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2921 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2925 return wxACC_NOT_IMPLEMENTED
;
2928 // Navigates from fromId to toId/toObject.
2929 wxAccStatus wxWindowAccessible
::Navigate(wxNavDir navDir
, int fromId
,
2930 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2932 wxASSERT( GetWindow() != NULL
);
2938 case wxNAVDIR_FIRSTCHILD
:
2940 if (GetWindow()->GetChildren().GetCount() == 0)
2942 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2943 *toObject
= childWindow
->GetOrCreateAccessible();
2947 case wxNAVDIR_LASTCHILD
:
2949 if (GetWindow()->GetChildren().GetCount() == 0)
2951 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2952 *toObject
= childWindow
->GetOrCreateAccessible();
2956 case wxNAVDIR_RIGHT
:
2960 wxWindowList
::compatibility_iterator node
=
2961 wxWindowList
::compatibility_iterator();
2964 // Can't navigate to sibling of this window
2965 // if we're a top-level window.
2966 if (!GetWindow()->GetParent())
2967 return wxACC_NOT_IMPLEMENTED
;
2969 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2973 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2974 node
= GetWindow()->GetChildren().Item(fromId
-1);
2977 if (node
&& node
->GetNext())
2979 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2980 *toObject
= nextWindow
->GetOrCreateAccessible();
2988 case wxNAVDIR_PREVIOUS
:
2990 wxWindowList
::compatibility_iterator node
=
2991 wxWindowList
::compatibility_iterator();
2994 // Can't navigate to sibling of this window
2995 // if we're a top-level window.
2996 if (!GetWindow()->GetParent())
2997 return wxACC_NOT_IMPLEMENTED
;
2999 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3003 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
3004 node
= GetWindow()->GetChildren().Item(fromId
-1);
3007 if (node
&& node
->GetPrevious())
3009 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
3010 *toObject
= previousWindow
->GetOrCreateAccessible();
3018 return wxACC_NOT_IMPLEMENTED
;
3021 // Gets the name of the specified object.
3022 wxAccStatus wxWindowAccessible
::GetName(int childId
, wxString
* name
)
3024 wxASSERT( GetWindow() != NULL
);
3030 // If a child, leave wxWidgets to call the function on the actual
3033 return wxACC_NOT_IMPLEMENTED
;
3035 // This will eventually be replaced by specialised
3036 // accessible classes, one for each kind of wxWidgets
3037 // control or window.
3039 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
3040 title
= ((wxButton
*) GetWindow())->GetLabel();
3043 title
= GetWindow()->GetName();
3051 return wxACC_NOT_IMPLEMENTED
;
3054 // Gets the number of children.
3055 wxAccStatus wxWindowAccessible
::GetChildCount(int* childId
)
3057 wxASSERT( GetWindow() != NULL
);
3061 *childId
= (int) GetWindow()->GetChildren().GetCount();
3065 // Gets the specified child (starting from 1).
3066 // If *child is NULL and return value is wxACC_OK,
3067 // this means that the child is a simple element and
3068 // not an accessible object.
3069 wxAccStatus wxWindowAccessible
::GetChild(int childId
, wxAccessible
** child
)
3071 wxASSERT( GetWindow() != NULL
);
3081 if (childId
> (int) GetWindow()->GetChildren().GetCount())
3084 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
3085 *child
= childWindow
->GetOrCreateAccessible();
3092 // Gets the parent, or NULL.
3093 wxAccStatus wxWindowAccessible
::GetParent(wxAccessible
** parent
)
3095 wxASSERT( GetWindow() != NULL
);
3099 wxWindow
* parentWindow
= GetWindow()->GetParent();
3107 *parent
= parentWindow
->GetOrCreateAccessible();
3115 // Performs the default action. childId is 0 (the action for this object)
3116 // or > 0 (the action for a child).
3117 // Return wxACC_NOT_SUPPORTED if there is no default action for this
3118 // window (e.g. an edit control).
3119 wxAccStatus wxWindowAccessible
::DoDefaultAction(int WXUNUSED(childId
))
3121 wxASSERT( GetWindow() != NULL
);
3125 return wxACC_NOT_IMPLEMENTED
;
3128 // Gets the default action for this object (0) or > 0 (the action for a child).
3129 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
3130 // string if there is no action.
3131 // The retrieved string describes the action that is performed on an object,
3132 // not what the object does as a result. For example, a toolbar button that prints
3133 // a document has a default action of "Press" rather than "Prints the current document."
3134 wxAccStatus wxWindowAccessible
::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
3136 wxASSERT( GetWindow() != NULL
);
3140 return wxACC_NOT_IMPLEMENTED
;
3143 // Returns the description for this object or a child.
3144 wxAccStatus wxWindowAccessible
::GetDescription(int WXUNUSED(childId
), wxString
* description
)
3146 wxASSERT( GetWindow() != NULL
);
3150 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent
::Origin_Keyboard
));
3156 return wxACC_NOT_IMPLEMENTED
;
3159 // Returns help text for this object or a child, similar to tooltip text.
3160 wxAccStatus wxWindowAccessible
::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
3162 wxASSERT( GetWindow() != NULL
);
3166 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent
::Origin_Keyboard
));
3172 return wxACC_NOT_IMPLEMENTED
;
3175 // Returns the keyboard shortcut for this object or child.
3176 // Return e.g. ALT+K
3177 wxAccStatus wxWindowAccessible
::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
3179 wxASSERT( GetWindow() != NULL
);
3183 return wxACC_NOT_IMPLEMENTED
;
3186 // Returns a role constant.
3187 wxAccStatus wxWindowAccessible
::GetRole(int childId
, wxAccRole
* role
)
3189 wxASSERT( GetWindow() != NULL
);
3193 // If a child, leave wxWidgets to call the function on the actual
3196 return wxACC_NOT_IMPLEMENTED
;
3198 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3199 return wxACC_NOT_IMPLEMENTED
;
3201 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3202 return wxACC_NOT_IMPLEMENTED
;
3205 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3206 return wxACC_NOT_IMPLEMENTED
;
3209 //*role = wxROLE_SYSTEM_CLIENT;
3210 *role
= wxROLE_SYSTEM_CLIENT
;
3214 return wxACC_NOT_IMPLEMENTED
;
3218 // Returns a state constant.
3219 wxAccStatus wxWindowAccessible
::GetState(int childId
, long* state
)
3221 wxASSERT( GetWindow() != NULL
);
3225 // If a child, leave wxWidgets to call the function on the actual
3228 return wxACC_NOT_IMPLEMENTED
;
3230 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3231 return wxACC_NOT_IMPLEMENTED
;
3234 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3235 return wxACC_NOT_IMPLEMENTED
;
3238 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3239 return wxACC_NOT_IMPLEMENTED
;
3246 return wxACC_NOT_IMPLEMENTED
;
3250 // Returns a localized string representing the value for the object
3252 wxAccStatus wxWindowAccessible
::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3254 wxASSERT( GetWindow() != NULL
);
3258 return wxACC_NOT_IMPLEMENTED
;
3261 // Selects the object or child.
3262 wxAccStatus wxWindowAccessible
::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3264 wxASSERT( GetWindow() != NULL
);
3268 return wxACC_NOT_IMPLEMENTED
;
3271 // Gets the window with the keyboard focus.
3272 // If childId is 0 and child is NULL, no object in
3273 // this subhierarchy has the focus.
3274 // If this object has the focus, child should be 'this'.
3275 wxAccStatus wxWindowAccessible
::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3277 wxASSERT( GetWindow() != NULL
);
3281 return wxACC_NOT_IMPLEMENTED
;
3285 // Gets a variant representing the selected children
3287 // Acceptable values:
3288 // - a null variant (IsNull() returns true)
3289 // - a list variant (GetType() == wxT("list")
3290 // - an integer representing the selected child element,
3291 // or 0 if this object is selected (GetType() == wxT("long")
3292 // - a "void*" pointer to a wxAccessible child object
3293 wxAccStatus wxWindowAccessible
::GetSelections(wxVariant
* WXUNUSED(selections
))
3295 wxASSERT( GetWindow() != NULL
);
3299 return wxACC_NOT_IMPLEMENTED
;
3301 #endif // wxUSE_VARIANT
3303 #endif // wxUSE_ACCESSIBILITY
3305 // ----------------------------------------------------------------------------
3307 // ----------------------------------------------------------------------------
3310 wxWindowBase
::AdjustForLayoutDirection(wxCoord x
,
3312 wxCoord widthTotal
) const
3314 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3316 x
= widthTotal
- x
- width
;