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 void wxWindowBase::SendDestroyEvent()
376 wxWindowDestroyEvent event
;
377 event
.SetEventObject(this);
378 event
.SetId(GetId());
379 GetEventHandler()->ProcessEvent(event
);
382 bool wxWindowBase::Destroy()
389 bool wxWindowBase::Close(bool force
)
391 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
392 event
.SetEventObject(this);
393 event
.SetCanVeto(!force
);
395 // return false if window wasn't closed because the application vetoed the
397 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
400 bool wxWindowBase::DestroyChildren()
402 wxWindowList::compatibility_iterator node
;
405 // we iterate until the list becomes empty
406 node
= GetChildren().GetFirst();
410 wxWindow
*child
= node
->GetData();
412 // note that we really want to call delete and not ->Destroy() here
413 // because we want to delete the child immediately, before we are
414 // deleted, and delayed deletion would result in problems as our (top
415 // level) child could outlive its parent
418 wxASSERT_MSG( !GetChildren().Find(child
),
419 wxT("child didn't remove itself using RemoveChild()") );
425 // ----------------------------------------------------------------------------
426 // size/position related methods
427 // ----------------------------------------------------------------------------
429 // centre the window with respect to its parent in either (or both) directions
430 void wxWindowBase::DoCentre(int dir
)
432 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
433 _T("this method only implements centering child windows") );
435 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
438 // fits the window around the children
439 void wxWindowBase::Fit()
441 if ( !GetChildren().empty() )
443 SetSize(GetBestSize());
445 //else: do nothing if we have no children
448 // fits virtual size (ie. scrolled area etc.) around children
449 void wxWindowBase::FitInside()
451 if ( GetChildren().GetCount() > 0 )
453 SetVirtualSize( GetBestVirtualSize() );
457 // On Mac, scrollbars are explicitly children.
459 static bool wxHasRealChildren(const wxWindowBase
* win
)
461 int realChildCount
= 0;
463 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
465 node
= node
->GetNext() )
467 wxWindow
*win
= node
->GetData();
468 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
471 return (realChildCount
> 0);
475 void wxWindowBase::InvalidateBestSize()
477 m_bestSizeCache
= wxDefaultSize
;
479 // parent's best size calculation may depend on its children's
480 // as long as child window we are in is not top level window itself
481 // (because the TLW size is never resized automatically)
482 // so let's invalidate it as well to be safe:
483 if (m_parent
&& !IsTopLevel())
484 m_parent
->InvalidateBestSize();
487 // return the size best suited for the current window
488 wxSize
wxWindowBase::DoGetBestSize() const
494 best
= m_windowSizer
->GetMinSize();
496 #if wxUSE_CONSTRAINTS
497 else if ( m_constraints
)
499 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
501 // our minimal acceptable size is such that all our windows fit inside
505 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
507 node
= node
->GetNext() )
509 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
512 // it's not normal that we have an unconstrained child, but
513 // what can we do about it?
517 int x
= c
->right
.GetValue(),
518 y
= c
->bottom
.GetValue();
526 // TODO: we must calculate the overlaps somehow, otherwise we
527 // will never return a size bigger than the current one :-(
530 best
= wxSize(maxX
, maxY
);
532 #endif // wxUSE_CONSTRAINTS
533 else if ( !GetChildren().empty()
535 && wxHasRealChildren(this)
539 // our minimal acceptable size is such that all our visible child
540 // windows fit inside
544 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
546 node
= node
->GetNext() )
548 wxWindow
*win
= node
->GetData();
549 if ( win
->IsTopLevel()
552 || wxDynamicCast(win
, wxStatusBar
)
553 #endif // wxUSE_STATUSBAR
556 // dialogs and frames lie in different top level windows -
557 // don't deal with them here; as for the status bars, they
558 // don't lie in the client area at all
563 win
->GetPosition(&wx
, &wy
);
565 // if the window hadn't been positioned yet, assume that it is in
567 if ( wx
== wxDefaultCoord
)
569 if ( wy
== wxDefaultCoord
)
572 win
->GetSize(&ww
, &wh
);
573 if ( wx
+ ww
> maxX
)
575 if ( wy
+ wh
> maxY
)
579 best
= wxSize(maxX
, maxY
);
581 else // ! has children
583 // for a generic window there is no natural best size so, if the
584 // minimal size is not set, use the current size but take care to
585 // remember it as minimal size for the next time because our best size
586 // should be constant: otherwise we could get into a situation when the
587 // window is initially at some size, then expanded to a larger size and
588 // then, when the containing window is shrunk back (because our initial
589 // best size had been used for computing the parent min size), we can't
590 // be shrunk back any more because our best size is now bigger
591 wxSize size
= GetMinSize();
592 if ( !size
.IsFullySpecified() )
594 size
.SetDefaults(GetSize());
595 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
598 // return as-is, unadjusted by the client size difference.
602 // Add any difference between size and client size
603 wxSize diff
= GetSize() - GetClientSize();
604 best
.x
+= wxMax(0, diff
.x
);
605 best
.y
+= wxMax(0, diff
.y
);
610 // helper of GetWindowBorderSize(): as many ports don't implement support for
611 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
612 // fallbacks in this case
613 static int wxGetMetricOrDefault(wxSystemMetric what
)
615 int rc
= wxSystemSettings::GetMetric(what
);
622 // 2D border is by default 1 pixel wide
628 // 3D borders are by default 2 pixels
633 wxFAIL_MSG( _T("unexpected wxGetMetricOrDefault() argument") );
641 wxSize
wxWindowBase::GetWindowBorderSize() const
645 switch ( GetBorder() )
648 // nothing to do, size is already (0, 0)
651 case wxBORDER_SIMPLE
:
652 case wxBORDER_STATIC
:
653 size
.x
= wxGetMetricOrDefault(wxSYS_BORDER_X
);
654 size
.y
= wxGetMetricOrDefault(wxSYS_BORDER_Y
);
657 case wxBORDER_SUNKEN
:
658 case wxBORDER_RAISED
:
659 size
.x
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X
),
660 wxGetMetricOrDefault(wxSYS_BORDER_X
));
661 size
.y
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y
),
662 wxGetMetricOrDefault(wxSYS_BORDER_Y
));
665 case wxBORDER_DOUBLE
:
666 size
.x
= wxGetMetricOrDefault(wxSYS_EDGE_X
) +
667 wxGetMetricOrDefault(wxSYS_BORDER_X
);
668 size
.y
= wxGetMetricOrDefault(wxSYS_EDGE_Y
) +
669 wxGetMetricOrDefault(wxSYS_BORDER_Y
);
673 wxFAIL_MSG(_T("Unknown border style."));
677 // we have borders on both sides
681 wxSize
wxWindowBase::GetEffectiveMinSize() const
683 // merge the best size with the min size, giving priority to the min size
684 wxSize min
= GetMinSize();
685 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
687 wxSize best
= GetBestSize();
688 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
689 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
695 void wxWindowBase::SetInitialSize(const wxSize
& size
)
697 // Set the min size to the size passed in. This will usually either be
698 // wxDefaultSize or the size passed to this window's ctor/Create function.
701 // Merge the size with the best size if needed
702 wxSize best
= GetEffectiveMinSize();
704 // If the current size doesn't match then change it
705 if (GetSize() != best
)
710 // by default the origin is not shifted
711 wxPoint
wxWindowBase::GetClientAreaOrigin() const
716 wxSize
wxWindowBase::ClientToWindowSize(const wxSize
& size
) const
718 const wxSize
diff(GetSize() - GetClientSize());
720 return wxSize(size
.x
== -1 ? -1 : size
.x
+ diff
.x
,
721 size
.y
== -1 ? -1 : size
.y
+ diff
.y
);
724 wxSize
wxWindowBase::WindowToClientSize(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 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
734 if ( m_windowVariant
!= variant
)
736 m_windowVariant
= variant
;
738 DoSetWindowVariant(variant
);
742 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
744 // adjust the font height to correspond to our new variant (notice that
745 // we're only called if something really changed)
746 wxFont font
= GetFont();
747 int size
= font
.GetPointSize();
750 case wxWINDOW_VARIANT_NORMAL
:
753 case wxWINDOW_VARIANT_SMALL
:
758 case wxWINDOW_VARIANT_MINI
:
763 case wxWINDOW_VARIANT_LARGE
:
769 wxFAIL_MSG(_T("unexpected window variant"));
773 font
.SetPointSize(size
);
777 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
779 int WXUNUSED(incW
), int WXUNUSED(incH
) )
781 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
782 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
783 _T("min width/height must be less than max width/height!") );
792 #if WXWIN_COMPATIBILITY_2_8
793 void wxWindowBase::SetVirtualSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
),
794 int WXUNUSED(maxW
), int WXUNUSED(maxH
))
798 void wxWindowBase::SetVirtualSizeHints(const wxSize
& WXUNUSED(minsize
),
799 const wxSize
& WXUNUSED(maxsize
))
802 #endif // WXWIN_COMPATIBILITY_2_8
804 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
806 m_virtualSize
= wxSize(x
, y
);
809 wxSize
wxWindowBase::DoGetVirtualSize() const
811 // we should use the entire client area so if it is greater than our
812 // virtual size, expand it to fit (otherwise if the window is big enough we
813 // wouldn't be using parts of it)
814 wxSize size
= GetClientSize();
815 if ( m_virtualSize
.x
> size
.x
)
816 size
.x
= m_virtualSize
.x
;
818 if ( m_virtualSize
.y
>= size
.y
)
819 size
.y
= m_virtualSize
.y
;
824 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
826 // screen position is the same as (0, 0) in client coords for non TLWs (and
827 // TLWs override this method)
833 ClientToScreen(x
, y
);
836 // ----------------------------------------------------------------------------
837 // show/hide/enable/disable the window
838 // ----------------------------------------------------------------------------
840 bool wxWindowBase::Show(bool show
)
842 if ( show
!= m_isShown
)
854 bool wxWindowBase::IsEnabled() const
856 return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
859 void wxWindowBase::NotifyWindowOnEnableChange(bool enabled
)
861 #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
863 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
867 // If we are top-level then the logic doesn't apply - otherwise
868 // showing a modal dialog would result in total greying out (and ungreying
869 // out later) of everything which would be really ugly
873 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
875 node
= node
->GetNext() )
877 wxWindowBase
* const child
= node
->GetData();
878 if ( !child
->IsTopLevel() && child
->IsThisEnabled() )
879 child
->NotifyWindowOnEnableChange(enabled
);
883 bool wxWindowBase::Enable(bool enable
)
885 if ( enable
== IsThisEnabled() )
888 m_isEnabled
= enable
;
890 #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
892 #else // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
893 wxWindowBase
* const parent
= GetParent();
894 if( !IsTopLevel() && parent
&& !parent
->IsEnabled() )
898 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
900 NotifyWindowOnEnableChange(enable
);
905 bool wxWindowBase::IsShownOnScreen() const
907 // A window is shown on screen if it itself is shown and so are all its
908 // parents. But if a window is toplevel one, then its always visible on
909 // screen if IsShown() returns true, even if it has a hidden parent.
911 (IsTopLevel() || GetParent() == NULL
|| GetParent()->IsShownOnScreen());
914 // ----------------------------------------------------------------------------
916 // ----------------------------------------------------------------------------
918 bool wxWindowBase::IsTopLevel() const
923 // ----------------------------------------------------------------------------
924 // reparenting the window
925 // ----------------------------------------------------------------------------
927 void wxWindowBase::AddChild(wxWindowBase
*child
)
929 wxCHECK_RET( child
, wxT("can't add a NULL child") );
931 // this should never happen and it will lead to a crash later if it does
932 // because RemoveChild() will remove only one node from the children list
933 // and the other(s) one(s) will be left with dangling pointers in them
934 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
936 GetChildren().Append((wxWindow
*)child
);
937 child
->SetParent(this);
940 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
942 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
944 GetChildren().DeleteObject((wxWindow
*)child
);
945 child
->SetParent(NULL
);
948 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
950 wxWindow
*oldParent
= GetParent();
951 if ( newParent
== oldParent
)
957 const bool oldEnabledState
= IsEnabled();
959 // unlink this window from the existing parent.
962 oldParent
->RemoveChild(this);
966 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
969 // add it to the new one
972 newParent
->AddChild(this);
976 wxTopLevelWindows
.Append((wxWindow
*)this);
979 // We need to notify window (and its subwindows) if by changing the parent
980 // we also change our enabled/disabled status.
981 const bool newEnabledState
= IsEnabled();
982 if ( newEnabledState
!= oldEnabledState
)
984 NotifyWindowOnEnableChange(newEnabledState
);
990 // ----------------------------------------------------------------------------
991 // event handler stuff
992 // ----------------------------------------------------------------------------
994 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
996 wxEvtHandler
*handlerOld
= GetEventHandler();
998 handler
->SetNextHandler(handlerOld
);
1001 GetEventHandler()->SetPreviousHandler(handler
);
1003 SetEventHandler(handler
);
1006 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
1008 wxEvtHandler
*handlerA
= GetEventHandler();
1011 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
1012 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
1015 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
1016 SetEventHandler(handlerB
);
1018 if ( deleteHandler
)
1021 handlerA
= (wxEvtHandler
*)NULL
;
1028 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
1030 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
1032 wxEvtHandler
*handlerPrev
= NULL
,
1033 *handlerCur
= GetEventHandler();
1034 while ( handlerCur
)
1036 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
1038 if ( handlerCur
== handler
)
1042 handlerPrev
->SetNextHandler(handlerNext
);
1046 SetEventHandler(handlerNext
);
1051 handlerNext
->SetPreviousHandler ( handlerPrev
);
1054 handler
->SetNextHandler(NULL
);
1055 handler
->SetPreviousHandler(NULL
);
1060 handlerPrev
= handlerCur
;
1061 handlerCur
= handlerNext
;
1064 wxFAIL_MSG( _T("where has the event handler gone?") );
1069 bool wxWindowBase::HandleWindowEvent(wxEvent
& event
) const
1071 return GetEventHandler()->SafelyProcessEvent(event
);
1074 // ----------------------------------------------------------------------------
1075 // colours, fonts &c
1076 // ----------------------------------------------------------------------------
1078 void wxWindowBase::InheritAttributes()
1080 const wxWindowBase
* const parent
= GetParent();
1084 // we only inherit attributes which had been explicitly set for the parent
1085 // which ensures that this only happens if the user really wants it and
1086 // not by default which wouldn't make any sense in modern GUIs where the
1087 // controls don't all use the same fonts (nor colours)
1088 if ( parent
->m_inheritFont
&& !m_hasFont
)
1089 SetFont(parent
->GetFont());
1091 // in addition, there is a possibility to explicitly forbid inheriting
1092 // colours at each class level by overriding ShouldInheritColours()
1093 if ( ShouldInheritColours() )
1095 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1096 SetForegroundColour(parent
->GetForegroundColour());
1098 // inheriting (solid) background colour is wrong as it totally breaks
1099 // any kind of themed backgrounds
1101 // instead, the controls should use the same background as their parent
1102 // (ideally by not drawing it at all)
1104 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1105 SetBackgroundColour(parent
->GetBackgroundColour());
1110 /* static */ wxVisualAttributes
1111 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1113 // it is important to return valid values for all attributes from here,
1114 // GetXXX() below rely on this
1115 wxVisualAttributes attrs
;
1116 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1117 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1119 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1120 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1121 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1122 // colour on other platforms.
1124 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1125 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1127 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1132 wxColour
wxWindowBase::GetBackgroundColour() const
1134 if ( !m_backgroundColour
.IsOk() )
1136 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
1138 // get our default background colour
1139 wxColour colBg
= GetDefaultAttributes().colBg
;
1141 // we must return some valid colour to avoid redoing this every time
1142 // and also to avoid surprizing the applications written for older
1143 // wxWidgets versions where GetBackgroundColour() always returned
1144 // something -- so give them something even if it doesn't make sense
1145 // for this window (e.g. it has a themed background)
1147 colBg
= GetClassDefaultAttributes().colBg
;
1152 return m_backgroundColour
;
1155 wxColour
wxWindowBase::GetForegroundColour() const
1157 // logic is the same as above
1158 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1160 wxColour colFg
= GetDefaultAttributes().colFg
;
1162 if ( !colFg
.IsOk() )
1163 colFg
= GetClassDefaultAttributes().colFg
;
1168 return m_foregroundColour
;
1171 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1173 if ( colour
== m_backgroundColour
)
1176 m_hasBgCol
= colour
.IsOk();
1177 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1178 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1180 m_inheritBgCol
= m_hasBgCol
;
1181 m_backgroundColour
= colour
;
1182 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1186 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1188 if (colour
== m_foregroundColour
)
1191 m_hasFgCol
= colour
.IsOk();
1192 m_inheritFgCol
= m_hasFgCol
;
1193 m_foregroundColour
= colour
;
1194 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1198 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1200 // setting an invalid cursor is ok, it means that we don't have any special
1202 if ( m_cursor
.IsSameAs(cursor
) )
1213 wxFont
wxWindowBase::GetFont() const
1215 // logic is the same as in GetBackgroundColour()
1216 if ( !m_font
.IsOk() )
1218 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1220 wxFont font
= GetDefaultAttributes().font
;
1222 font
= GetClassDefaultAttributes().font
;
1230 bool wxWindowBase::SetFont(const wxFont
& font
)
1232 if ( font
== m_font
)
1239 m_hasFont
= font
.IsOk();
1240 m_inheritFont
= m_hasFont
;
1242 InvalidateBestSize();
1249 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1251 m_hasCustomPalette
= true;
1254 // VZ: can anyone explain me what do we do here?
1255 wxWindowDC
d((wxWindow
*) this);
1259 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1261 wxWindow
*win
= (wxWindow
*)this;
1262 while ( win
&& !win
->HasCustomPalette() )
1264 win
= win
->GetParent();
1270 #endif // wxUSE_PALETTE
1273 void wxWindowBase::SetCaret(wxCaret
*caret
)
1284 wxASSERT_MSG( m_caret
->GetWindow() == this,
1285 wxT("caret should be created associated to this window") );
1288 #endif // wxUSE_CARET
1290 #if wxUSE_VALIDATORS
1291 // ----------------------------------------------------------------------------
1293 // ----------------------------------------------------------------------------
1295 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1297 if ( m_windowValidator
)
1298 delete m_windowValidator
;
1300 m_windowValidator
= (wxValidator
*)validator
.Clone();
1302 if ( m_windowValidator
)
1303 m_windowValidator
->SetWindow(this);
1305 #endif // wxUSE_VALIDATORS
1307 // ----------------------------------------------------------------------------
1308 // update region stuff
1309 // ----------------------------------------------------------------------------
1311 wxRect
wxWindowBase::GetUpdateClientRect() const
1313 wxRegion rgnUpdate
= GetUpdateRegion();
1314 rgnUpdate
.Intersect(GetClientRect());
1315 wxRect rectUpdate
= rgnUpdate
.GetBox();
1316 wxPoint ptOrigin
= GetClientAreaOrigin();
1317 rectUpdate
.x
-= ptOrigin
.x
;
1318 rectUpdate
.y
-= ptOrigin
.y
;
1323 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1325 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1328 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1330 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1333 void wxWindowBase::ClearBackground()
1335 // wxGTK uses its own version, no need to add never used code
1337 wxClientDC
dc((wxWindow
*)this);
1338 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1339 dc
.SetBackground(brush
);
1344 // ----------------------------------------------------------------------------
1345 // find child window by id or name
1346 // ----------------------------------------------------------------------------
1348 wxWindow
*wxWindowBase::FindWindow(long id
) const
1350 if ( id
== m_windowId
)
1351 return (wxWindow
*)this;
1353 wxWindowBase
*res
= (wxWindow
*)NULL
;
1354 wxWindowList::compatibility_iterator node
;
1355 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1357 wxWindowBase
*child
= node
->GetData();
1358 res
= child
->FindWindow( id
);
1361 return (wxWindow
*)res
;
1364 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1366 if ( name
== m_windowName
)
1367 return (wxWindow
*)this;
1369 wxWindowBase
*res
= (wxWindow
*)NULL
;
1370 wxWindowList::compatibility_iterator node
;
1371 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1373 wxWindow
*child
= node
->GetData();
1374 res
= child
->FindWindow(name
);
1377 return (wxWindow
*)res
;
1381 // find any window by id or name or label: If parent is non-NULL, look through
1382 // children for a label or title matching the specified string. If NULL, look
1383 // through all top-level windows.
1385 // to avoid duplicating code we reuse the same helper function but with
1386 // different comparators
1388 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1389 const wxString
& label
, long id
);
1392 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1395 return win
->GetLabel() == label
;
1399 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1402 return win
->GetName() == label
;
1406 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1409 return win
->GetId() == id
;
1412 // recursive helper for the FindWindowByXXX() functions
1414 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1415 const wxString
& label
,
1417 wxFindWindowCmp cmp
)
1421 // see if this is the one we're looking for
1422 if ( (*cmp
)(parent
, label
, id
) )
1423 return (wxWindow
*)parent
;
1425 // It wasn't, so check all its children
1426 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1428 node
= node
->GetNext() )
1430 // recursively check each child
1431 wxWindow
*win
= (wxWindow
*)node
->GetData();
1432 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1442 // helper for FindWindowByXXX()
1444 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1445 const wxString
& label
,
1447 wxFindWindowCmp cmp
)
1451 // just check parent and all its children
1452 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1455 // start at very top of wx's windows
1456 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1458 node
= node
->GetNext() )
1460 // recursively check each window & its children
1461 wxWindow
*win
= node
->GetData();
1462 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1472 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1474 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1479 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1481 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1485 // fall back to the label
1486 win
= FindWindowByLabel(title
, parent
);
1494 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1496 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1499 // ----------------------------------------------------------------------------
1500 // dialog oriented functions
1501 // ----------------------------------------------------------------------------
1503 void wxWindowBase::MakeModal(bool modal
)
1505 // Disable all other windows
1508 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1511 wxWindow
*win
= node
->GetData();
1513 win
->Enable(!modal
);
1515 node
= node
->GetNext();
1520 bool wxWindowBase::Validate()
1522 #if wxUSE_VALIDATORS
1523 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1525 wxWindowList::compatibility_iterator node
;
1526 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1528 wxWindowBase
*child
= node
->GetData();
1529 wxValidator
*validator
= child
->GetValidator();
1530 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1535 if ( recurse
&& !child
->Validate() )
1540 #endif // wxUSE_VALIDATORS
1545 bool wxWindowBase::TransferDataToWindow()
1547 #if wxUSE_VALIDATORS
1548 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1550 wxWindowList::compatibility_iterator node
;
1551 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1553 wxWindowBase
*child
= node
->GetData();
1554 wxValidator
*validator
= child
->GetValidator();
1555 if ( validator
&& !validator
->TransferToWindow() )
1557 wxLogWarning(_("Could not transfer data to window"));
1559 wxLog::FlushActive();
1567 if ( !child
->TransferDataToWindow() )
1569 // warning already given
1574 #endif // wxUSE_VALIDATORS
1579 bool wxWindowBase::TransferDataFromWindow()
1581 #if wxUSE_VALIDATORS
1582 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1584 wxWindowList::compatibility_iterator node
;
1585 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1587 wxWindow
*child
= node
->GetData();
1588 wxValidator
*validator
= child
->GetValidator();
1589 if ( validator
&& !validator
->TransferFromWindow() )
1591 // nop warning here because the application is supposed to give
1592 // one itself - we don't know here what might have gone wrongly
1599 if ( !child
->TransferDataFromWindow() )
1601 // warning already given
1606 #endif // wxUSE_VALIDATORS
1611 void wxWindowBase::InitDialog()
1613 wxInitDialogEvent
event(GetId());
1614 event
.SetEventObject( this );
1615 GetEventHandler()->ProcessEvent(event
);
1618 // ----------------------------------------------------------------------------
1619 // context-sensitive help support
1620 // ----------------------------------------------------------------------------
1624 // associate this help text with this window
1625 void wxWindowBase::SetHelpText(const wxString
& text
)
1627 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1630 helpProvider
->AddHelp(this, text
);
1634 // associate this help text with all windows with the same id as this
1636 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1638 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1641 helpProvider
->AddHelp(GetId(), text
);
1645 // get the help string associated with this window (may be empty)
1646 // default implementation forwards calls to the help provider
1648 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1649 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1652 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1655 text
= helpProvider
->GetHelp(this);
1661 // show help for this window
1662 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1664 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1667 if ( helpProvider
->ShowHelpAtPoint(this, event
.GetPosition(), event
.GetOrigin()) )
1669 // skip the event.Skip() below
1677 #endif // wxUSE_HELP
1679 // ----------------------------------------------------------------------------
1681 // ----------------------------------------------------------------------------
1685 void wxWindowBase::SetToolTip( const wxString
&tip
)
1687 // don't create the new tooltip if we already have one
1690 m_tooltip
->SetTip( tip
);
1694 SetToolTip( new wxToolTip( tip
) );
1697 // setting empty tooltip text does not remove the tooltip any more - use
1698 // SetToolTip((wxToolTip *)NULL) for this
1701 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1703 if ( m_tooltip
!= tooltip
)
1708 m_tooltip
= tooltip
;
1712 #endif // wxUSE_TOOLTIPS
1714 // ----------------------------------------------------------------------------
1715 // constraints and sizers
1716 // ----------------------------------------------------------------------------
1718 #if wxUSE_CONSTRAINTS
1720 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1722 if ( m_constraints
)
1724 UnsetConstraints(m_constraints
);
1725 delete m_constraints
;
1727 m_constraints
= constraints
;
1728 if ( m_constraints
)
1730 // Make sure other windows know they're part of a 'meaningful relationship'
1731 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1732 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1733 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1734 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1735 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1736 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1737 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1738 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1739 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1740 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1741 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1742 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1743 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1744 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1745 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1746 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1750 // This removes any dangling pointers to this window in other windows'
1751 // constraintsInvolvedIn lists.
1752 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1756 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1757 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1758 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1759 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1760 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1761 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1762 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1763 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1764 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1765 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1766 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1767 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1768 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1769 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1770 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1771 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1775 // Back-pointer to other windows we're involved with, so if we delete this
1776 // window, we must delete any constraints we're involved with.
1777 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1779 if ( !m_constraintsInvolvedIn
)
1780 m_constraintsInvolvedIn
= new wxWindowList
;
1781 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1782 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1785 // REMOVE back-pointer to other windows we're involved with.
1786 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1788 if ( m_constraintsInvolvedIn
)
1789 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1792 // Reset any constraints that mention this window
1793 void wxWindowBase::DeleteRelatedConstraints()
1795 if ( m_constraintsInvolvedIn
)
1797 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1800 wxWindow
*win
= node
->GetData();
1801 wxLayoutConstraints
*constr
= win
->GetConstraints();
1803 // Reset any constraints involving this window
1806 constr
->left
.ResetIfWin(this);
1807 constr
->top
.ResetIfWin(this);
1808 constr
->right
.ResetIfWin(this);
1809 constr
->bottom
.ResetIfWin(this);
1810 constr
->width
.ResetIfWin(this);
1811 constr
->height
.ResetIfWin(this);
1812 constr
->centreX
.ResetIfWin(this);
1813 constr
->centreY
.ResetIfWin(this);
1816 wxWindowList::compatibility_iterator next
= node
->GetNext();
1817 m_constraintsInvolvedIn
->Erase(node
);
1821 delete m_constraintsInvolvedIn
;
1822 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1826 #endif // wxUSE_CONSTRAINTS
1828 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1830 if ( sizer
== m_windowSizer
)
1833 if ( m_windowSizer
)
1835 m_windowSizer
->SetContainingWindow(NULL
);
1838 delete m_windowSizer
;
1841 m_windowSizer
= sizer
;
1842 if ( m_windowSizer
)
1844 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
1847 SetAutoLayout(m_windowSizer
!= NULL
);
1850 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1852 SetSizer( sizer
, deleteOld
);
1853 sizer
->SetSizeHints( (wxWindow
*) this );
1857 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1859 // adding a window to a sizer twice is going to result in fatal and
1860 // hard to debug problems later because when deleting the second
1861 // associated wxSizerItem we're going to dereference a dangling
1862 // pointer; so try to detect this as early as possible
1863 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1864 _T("Adding a window to the same sizer twice?") );
1866 m_containingSizer
= sizer
;
1869 #if wxUSE_CONSTRAINTS
1871 void wxWindowBase::SatisfyConstraints()
1873 wxLayoutConstraints
*constr
= GetConstraints();
1874 bool wasOk
= constr
&& constr
->AreSatisfied();
1876 ResetConstraints(); // Mark all constraints as unevaluated
1880 // if we're a top level panel (i.e. our parent is frame/dialog), our
1881 // own constraints will never be satisfied any more unless we do it
1885 while ( noChanges
> 0 )
1887 LayoutPhase1(&noChanges
);
1891 LayoutPhase2(&noChanges
);
1894 #endif // wxUSE_CONSTRAINTS
1896 bool wxWindowBase::Layout()
1898 // If there is a sizer, use it instead of the constraints
1902 GetVirtualSize(&w
, &h
);
1903 GetSizer()->SetDimension( 0, 0, w
, h
);
1905 #if wxUSE_CONSTRAINTS
1908 SatisfyConstraints(); // Find the right constraints values
1909 SetConstraintSizes(); // Recursively set the real window sizes
1916 #if wxUSE_CONSTRAINTS
1918 // first phase of the constraints evaluation: set our own constraints
1919 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1921 wxLayoutConstraints
*constr
= GetConstraints();
1923 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1926 // second phase: set the constraints for our children
1927 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1934 // Layout grand children
1940 // Do a phase of evaluating child constraints
1941 bool wxWindowBase::DoPhase(int phase
)
1943 // the list containing the children for which the constraints are already
1945 wxWindowList succeeded
;
1947 // the max number of iterations we loop before concluding that we can't set
1949 static const int maxIterations
= 500;
1951 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1955 // loop over all children setting their constraints
1956 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1958 node
= node
->GetNext() )
1960 wxWindow
*child
= node
->GetData();
1961 if ( child
->IsTopLevel() )
1963 // top level children are not inside our client area
1967 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1969 // this one is either already ok or nothing we can do about it
1973 int tempNoChanges
= 0;
1974 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1975 : child
->LayoutPhase2(&tempNoChanges
);
1976 noChanges
+= tempNoChanges
;
1980 succeeded
.Append(child
);
1986 // constraints are set
1994 void wxWindowBase::ResetConstraints()
1996 wxLayoutConstraints
*constr
= GetConstraints();
1999 constr
->left
.SetDone(false);
2000 constr
->top
.SetDone(false);
2001 constr
->right
.SetDone(false);
2002 constr
->bottom
.SetDone(false);
2003 constr
->width
.SetDone(false);
2004 constr
->height
.SetDone(false);
2005 constr
->centreX
.SetDone(false);
2006 constr
->centreY
.SetDone(false);
2009 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2012 wxWindow
*win
= node
->GetData();
2013 if ( !win
->IsTopLevel() )
2014 win
->ResetConstraints();
2015 node
= node
->GetNext();
2019 // Need to distinguish between setting the 'fake' size for windows and sizers,
2020 // and setting the real values.
2021 void wxWindowBase::SetConstraintSizes(bool recurse
)
2023 wxLayoutConstraints
*constr
= GetConstraints();
2024 if ( constr
&& constr
->AreSatisfied() )
2026 int x
= constr
->left
.GetValue();
2027 int y
= constr
->top
.GetValue();
2028 int w
= constr
->width
.GetValue();
2029 int h
= constr
->height
.GetValue();
2031 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
2032 (constr
->height
.GetRelationship() != wxAsIs
) )
2034 SetSize(x
, y
, w
, h
);
2038 // If we don't want to resize this window, just move it...
2044 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
2045 GetClassInfo()->GetClassName(),
2051 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2054 wxWindow
*win
= node
->GetData();
2055 if ( !win
->IsTopLevel() && win
->GetConstraints() )
2056 win
->SetConstraintSizes();
2057 node
= node
->GetNext();
2062 // Only set the size/position of the constraint (if any)
2063 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
2065 wxLayoutConstraints
*constr
= GetConstraints();
2068 if ( x
!= wxDefaultCoord
)
2070 constr
->left
.SetValue(x
);
2071 constr
->left
.SetDone(true);
2073 if ( y
!= wxDefaultCoord
)
2075 constr
->top
.SetValue(y
);
2076 constr
->top
.SetDone(true);
2078 if ( w
!= wxDefaultCoord
)
2080 constr
->width
.SetValue(w
);
2081 constr
->width
.SetDone(true);
2083 if ( h
!= wxDefaultCoord
)
2085 constr
->height
.SetValue(h
);
2086 constr
->height
.SetDone(true);
2091 void wxWindowBase::MoveConstraint(int x
, int y
)
2093 wxLayoutConstraints
*constr
= GetConstraints();
2096 if ( x
!= wxDefaultCoord
)
2098 constr
->left
.SetValue(x
);
2099 constr
->left
.SetDone(true);
2101 if ( y
!= wxDefaultCoord
)
2103 constr
->top
.SetValue(y
);
2104 constr
->top
.SetDone(true);
2109 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2111 wxLayoutConstraints
*constr
= GetConstraints();
2114 *w
= constr
->width
.GetValue();
2115 *h
= constr
->height
.GetValue();
2121 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2123 wxLayoutConstraints
*constr
= GetConstraints();
2126 *w
= constr
->width
.GetValue();
2127 *h
= constr
->height
.GetValue();
2130 GetClientSize(w
, h
);
2133 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2135 wxLayoutConstraints
*constr
= GetConstraints();
2138 *x
= constr
->left
.GetValue();
2139 *y
= constr
->top
.GetValue();
2145 #endif // wxUSE_CONSTRAINTS
2147 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2149 // don't do it for the dialogs/frames - they float independently of their
2151 if ( !IsTopLevel() )
2153 wxWindow
*parent
= GetParent();
2154 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2156 wxPoint
pt(parent
->GetClientAreaOrigin());
2163 // ----------------------------------------------------------------------------
2164 // Update UI processing
2165 // ----------------------------------------------------------------------------
2167 void wxWindowBase::UpdateWindowUI(long flags
)
2169 wxUpdateUIEvent
event(GetId());
2170 event
.SetEventObject(this);
2172 if ( GetEventHandler()->ProcessEvent(event
) )
2174 DoUpdateWindowUI(event
);
2177 if (flags
& wxUPDATE_UI_RECURSE
)
2179 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2182 wxWindow
* child
= (wxWindow
*) node
->GetData();
2183 child
->UpdateWindowUI(flags
);
2184 node
= node
->GetNext();
2189 // do the window-specific processing after processing the update event
2190 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2192 if ( event
.GetSetEnabled() )
2193 Enable(event
.GetEnabled());
2195 if ( event
.GetSetShown() )
2196 Show(event
.GetShown());
2199 // ----------------------------------------------------------------------------
2200 // dialog units translations
2201 // ----------------------------------------------------------------------------
2203 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2205 int charWidth
= GetCharWidth();
2206 int charHeight
= GetCharHeight();
2207 wxPoint pt2
= wxDefaultPosition
;
2208 if (pt
.x
!= wxDefaultCoord
)
2209 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2210 if (pt
.y
!= wxDefaultCoord
)
2211 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2216 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2218 int charWidth
= GetCharWidth();
2219 int charHeight
= GetCharHeight();
2220 wxPoint pt2
= wxDefaultPosition
;
2221 if (pt
.x
!= wxDefaultCoord
)
2222 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2223 if (pt
.y
!= wxDefaultCoord
)
2224 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2229 // ----------------------------------------------------------------------------
2231 // ----------------------------------------------------------------------------
2233 // propagate the colour change event to the subwindows
2234 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2236 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2239 // Only propagate to non-top-level windows
2240 wxWindow
*win
= node
->GetData();
2241 if ( !win
->IsTopLevel() )
2243 wxSysColourChangedEvent event2
;
2244 event
.SetEventObject(win
);
2245 win
->GetEventHandler()->ProcessEvent(event2
);
2248 node
= node
->GetNext();
2254 // the default action is to populate dialog with data when it's created,
2255 // and nudge the UI into displaying itself correctly in case
2256 // we've turned the wxUpdateUIEvents frequency down low.
2257 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2259 TransferDataToWindow();
2261 // Update the UI at this point
2262 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2265 // ----------------------------------------------------------------------------
2266 // menu-related functions
2267 // ----------------------------------------------------------------------------
2271 bool wxWindowBase::PopupMenu(wxMenu
*menu
, int x
, int y
)
2273 wxCHECK_MSG( menu
, false, "can't popup NULL menu" );
2275 wxCurrentPopupMenu
= menu
;
2276 const bool rc
= DoPopupMenu(menu
, x
, y
);
2277 wxCurrentPopupMenu
= NULL
;
2282 // this is used to pass the id of the selected item from the menu event handler
2283 // to the main function itself
2285 // it's ok to use a global here as there can be at most one popup menu shown at
2287 static int gs_popupMenuSelection
= wxID_NONE
;
2289 void wxWindowBase::InternalOnPopupMenu(wxCommandEvent
& event
)
2291 // store the id in a global variable where we'll retrieve it from later
2292 gs_popupMenuSelection
= event
.GetId();
2296 wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu
& menu
, int x
, int y
)
2298 gs_popupMenuSelection
= wxID_NONE
;
2300 Connect(wxEVT_COMMAND_MENU_SELECTED
,
2301 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2305 PopupMenu(&menu
, x
, y
);
2307 Disconnect(wxEVT_COMMAND_MENU_SELECTED
,
2308 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2312 return gs_popupMenuSelection
;
2315 #endif // wxUSE_MENUS
2317 // methods for drawing the sizers in a visible way
2320 static void DrawSizers(wxWindowBase
*win
);
2322 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2324 wxClientDC
dc((wxWindow
*)win
);
2325 dc
.SetPen(*wxRED_PEN
);
2326 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2327 dc
.DrawRectangle(rect
.Deflate(1, 1));
2330 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2332 const wxSizerItemList
& items
= sizer
->GetChildren();
2333 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2338 wxSizerItem
*item
= *i
;
2339 if ( item
->IsSizer() )
2341 DrawBorder(win
, item
->GetRect().Deflate(2));
2342 DrawSizer(win
, item
->GetSizer());
2344 else if ( item
->IsSpacer() )
2346 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2348 else if ( item
->IsWindow() )
2350 DrawSizers(item
->GetWindow());
2355 static void DrawSizers(wxWindowBase
*win
)
2357 wxSizer
*sizer
= win
->GetSizer();
2360 DrawBorder(win
, win
->GetClientSize());
2361 DrawSizer(win
, sizer
);
2363 else // no sizer, still recurse into the children
2365 const wxWindowList
& children
= win
->GetChildren();
2366 for ( wxWindowList::const_iterator i
= children
.begin(),
2367 end
= children
.end();
2376 #endif // __WXDEBUG__
2378 // process special middle clicks
2379 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2381 if ( event
.ControlDown() && event
.AltDown() )
2384 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2385 if ( event
.ShiftDown() )
2390 #endif // __WXDEBUG__
2391 ::wxInfoMessageBox((wxWindow
*)this);
2399 // ----------------------------------------------------------------------------
2401 // ----------------------------------------------------------------------------
2403 #if wxUSE_ACCESSIBILITY
2404 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2406 if (m_accessible
&& (accessible
!= m_accessible
))
2407 delete m_accessible
;
2408 m_accessible
= accessible
;
2410 m_accessible
->SetWindow((wxWindow
*) this);
2413 // Returns the accessible object, creating if necessary.
2414 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2417 m_accessible
= CreateAccessible();
2418 return m_accessible
;
2421 // Override to create a specific accessible object.
2422 wxAccessible
* wxWindowBase::CreateAccessible()
2424 return new wxWindowAccessible((wxWindow
*) this);
2429 // ----------------------------------------------------------------------------
2430 // list classes implementation
2431 // ----------------------------------------------------------------------------
2435 #include "wx/listimpl.cpp"
2436 WX_DEFINE_LIST(wxWindowList
)
2440 void wxWindowListNode::DeleteData()
2442 delete (wxWindow
*)GetData();
2445 #endif // wxUSE_STL/!wxUSE_STL
2447 // ----------------------------------------------------------------------------
2449 // ----------------------------------------------------------------------------
2451 wxBorder
wxWindowBase::GetBorder(long flags
) const
2453 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2454 if ( border
== wxBORDER_DEFAULT
)
2456 border
= GetDefaultBorder();
2458 else if ( border
== wxBORDER_THEME
)
2460 border
= GetDefaultBorderForControl();
2466 wxBorder
wxWindowBase::GetDefaultBorder() const
2468 return wxBORDER_NONE
;
2471 // ----------------------------------------------------------------------------
2473 // ----------------------------------------------------------------------------
2475 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2477 // here we just check if the point is inside the window or not
2479 // check the top and left border first
2480 bool outside
= x
< 0 || y
< 0;
2483 // check the right and bottom borders too
2484 wxSize size
= GetSize();
2485 outside
= x
>= size
.x
|| y
>= size
.y
;
2488 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2491 // ----------------------------------------------------------------------------
2493 // ----------------------------------------------------------------------------
2495 struct WXDLLEXPORT wxWindowNext
2499 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2500 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2501 bool wxWindowBase::ms_winCaptureChanging
= false;
2503 void wxWindowBase::CaptureMouse()
2505 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2507 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2509 ms_winCaptureChanging
= true;
2511 wxWindow
*winOld
= GetCapture();
2514 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2517 wxWindowNext
*item
= new wxWindowNext
;
2519 item
->next
= ms_winCaptureNext
;
2520 ms_winCaptureNext
= item
;
2522 //else: no mouse capture to save
2525 ms_winCaptureCurrent
= (wxWindow
*)this;
2527 ms_winCaptureChanging
= false;
2530 void wxWindowBase::ReleaseMouse()
2532 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2534 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2536 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2538 ms_winCaptureChanging
= true;
2541 ms_winCaptureCurrent
= NULL
;
2543 if ( ms_winCaptureNext
)
2545 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2546 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2548 wxWindowNext
*item
= ms_winCaptureNext
;
2549 ms_winCaptureNext
= item
->next
;
2552 //else: stack is empty, no previous capture
2554 ms_winCaptureChanging
= false;
2556 wxLogTrace(_T("mousecapture"),
2557 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2558 wx_static_cast(void*, GetCapture()));
2561 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2563 wxMouseCaptureLostEvent
event(win
->GetId());
2564 event
.SetEventObject(win
);
2565 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2567 // windows must handle this event, otherwise the app wouldn't behave
2568 // correctly if it loses capture unexpectedly; see the discussion here:
2569 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
2570 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
2571 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2576 void wxWindowBase::NotifyCaptureLost()
2578 // don't do anything if capture lost was expected, i.e. resulted from
2579 // a wx call to ReleaseMouse or CaptureMouse:
2580 if ( ms_winCaptureChanging
)
2583 // if the capture was lost unexpectedly, notify every window that has
2584 // capture (on stack or current) about it and clear the stack:
2586 if ( ms_winCaptureCurrent
)
2588 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2589 ms_winCaptureCurrent
= NULL
;
2592 while ( ms_winCaptureNext
)
2594 wxWindowNext
*item
= ms_winCaptureNext
;
2595 ms_winCaptureNext
= item
->next
;
2597 DoNotifyWindowAboutCaptureLost(item
->win
);
2606 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2607 int WXUNUSED(modifiers
),
2608 int WXUNUSED(keycode
))
2614 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2620 #endif // wxUSE_HOTKEY
2622 // ----------------------------------------------------------------------------
2624 // ----------------------------------------------------------------------------
2626 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2628 #if wxUSE_VALIDATORS
2629 // Can only use the validator of the window which
2630 // is receiving the event
2631 if ( event
.GetEventObject() == this )
2633 wxValidator
*validator
= GetValidator();
2634 if ( validator
&& validator
->ProcessEvent(event
) )
2639 #endif // wxUSE_VALIDATORS
2644 bool wxWindowBase::TryParent(wxEvent
& event
)
2646 // carry on up the parent-child hierarchy if the propagation count hasn't
2648 if ( event
.ShouldPropagate() )
2650 // honour the requests to stop propagation at this window: this is
2651 // used by the dialogs, for example, to prevent processing the events
2652 // from the dialog controls in the parent frame which rarely, if ever,
2654 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2656 wxWindow
*parent
= GetParent();
2657 if ( parent
&& !parent
->IsBeingDeleted() )
2659 wxPropagateOnce
propagateOnce(event
);
2661 return parent
->GetEventHandler()->ProcessEvent(event
);
2666 return wxEvtHandler::TryParent(event
);
2669 // ----------------------------------------------------------------------------
2670 // window relationships
2671 // ----------------------------------------------------------------------------
2673 wxWindow
*wxWindowBase::DoGetSibling(WindowOrder order
) const
2675 wxCHECK_MSG( GetParent(), NULL
,
2676 _T("GetPrev/NextSibling() don't work for TLWs!") );
2678 wxWindowList
& siblings
= GetParent()->GetChildren();
2679 wxWindowList::compatibility_iterator i
= siblings
.Find((wxWindow
*)this);
2680 wxCHECK_MSG( i
, NULL
, _T("window not a child of its parent?") );
2682 if ( order
== OrderBefore
)
2683 i
= i
->GetPrevious();
2687 return i
? i
->GetData() : NULL
;
2690 // ----------------------------------------------------------------------------
2691 // keyboard navigation
2692 // ----------------------------------------------------------------------------
2694 // Navigates in the specified direction inside this window
2695 bool wxWindowBase::DoNavigateIn(int flags
)
2697 #ifdef wxHAS_NATIVE_TAB_TRAVERSAL
2698 // native code doesn't process our wxNavigationKeyEvents anyhow
2701 #else // !wxHAS_NATIVE_TAB_TRAVERSAL
2702 wxNavigationKeyEvent eventNav
;
2703 wxWindow
*focused
= FindFocus();
2704 eventNav
.SetCurrentFocus(focused
);
2705 eventNav
.SetEventObject(focused
);
2706 eventNav
.SetFlags(flags
);
2707 return GetEventHandler()->ProcessEvent(eventNav
);
2708 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
2711 bool wxWindowBase::HandleAsNavigationKey(const wxKeyEvent
& event
)
2713 if ( event
.GetKeyCode() != WXK_TAB
)
2716 int flags
= wxNavigationKeyEvent::FromTab
;
2718 if ( event
.ShiftDown() )
2719 flags
|= wxNavigationKeyEvent::IsBackward
;
2721 flags
|= wxNavigationKeyEvent::IsForward
;
2723 if ( event
.ControlDown() )
2724 flags
|= wxNavigationKeyEvent::WinChange
;
2730 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, WindowOrder move
)
2732 // check that we're not a top level window
2733 wxCHECK_RET( GetParent(),
2734 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2736 // detect the special case when we have nothing to do anyhow and when the
2737 // code below wouldn't work
2741 // find the target window in the siblings list
2742 wxWindowList
& siblings
= GetParent()->GetChildren();
2743 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2744 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2746 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2747 // can't just move the node around
2748 wxWindow
*self
= (wxWindow
*)this;
2749 siblings
.DeleteObject(self
);
2750 if ( move
== OrderAfter
)
2757 siblings
.Insert(i
, self
);
2759 else // OrderAfter and win was the last sibling
2761 siblings
.Append(self
);
2765 // ----------------------------------------------------------------------------
2767 // ----------------------------------------------------------------------------
2769 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2771 wxWindowBase
*win
= DoFindFocus();
2772 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2775 bool wxWindowBase::HasFocus() const
2777 wxWindowBase
*win
= DoFindFocus();
2778 return win
== this ||
2779 win
== wxConstCast(this, wxWindowBase
)->GetMainWindowOfCompositeControl();
2782 // ----------------------------------------------------------------------------
2784 // ----------------------------------------------------------------------------
2786 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2788 while ( win
&& !win
->IsTopLevel() )
2789 win
= win
->GetParent();
2794 #if wxUSE_ACCESSIBILITY
2795 // ----------------------------------------------------------------------------
2796 // accessible object for windows
2797 // ----------------------------------------------------------------------------
2799 // Can return either a child object, or an integer
2800 // representing the child element, starting from 1.
2801 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2803 wxASSERT( GetWindow() != NULL
);
2807 return wxACC_NOT_IMPLEMENTED
;
2810 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2811 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2813 wxASSERT( GetWindow() != NULL
);
2817 wxWindow
* win
= NULL
;
2824 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2826 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2833 rect
= win
->GetRect();
2834 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2835 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2839 return wxACC_NOT_IMPLEMENTED
;
2842 // Navigates from fromId to toId/toObject.
2843 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2844 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2846 wxASSERT( GetWindow() != NULL
);
2852 case wxNAVDIR_FIRSTCHILD
:
2854 if (GetWindow()->GetChildren().GetCount() == 0)
2856 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2857 *toObject
= childWindow
->GetOrCreateAccessible();
2861 case wxNAVDIR_LASTCHILD
:
2863 if (GetWindow()->GetChildren().GetCount() == 0)
2865 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2866 *toObject
= childWindow
->GetOrCreateAccessible();
2870 case wxNAVDIR_RIGHT
:
2874 wxWindowList::compatibility_iterator node
=
2875 wxWindowList::compatibility_iterator();
2878 // Can't navigate to sibling of this window
2879 // if we're a top-level window.
2880 if (!GetWindow()->GetParent())
2881 return wxACC_NOT_IMPLEMENTED
;
2883 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2887 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2888 node
= GetWindow()->GetChildren().Item(fromId
-1);
2891 if (node
&& node
->GetNext())
2893 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2894 *toObject
= nextWindow
->GetOrCreateAccessible();
2902 case wxNAVDIR_PREVIOUS
:
2904 wxWindowList::compatibility_iterator node
=
2905 wxWindowList::compatibility_iterator();
2908 // Can't navigate to sibling of this window
2909 // if we're a top-level window.
2910 if (!GetWindow()->GetParent())
2911 return wxACC_NOT_IMPLEMENTED
;
2913 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2917 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2918 node
= GetWindow()->GetChildren().Item(fromId
-1);
2921 if (node
&& node
->GetPrevious())
2923 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2924 *toObject
= previousWindow
->GetOrCreateAccessible();
2932 return wxACC_NOT_IMPLEMENTED
;
2935 // Gets the name of the specified object.
2936 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2938 wxASSERT( GetWindow() != NULL
);
2944 // If a child, leave wxWidgets to call the function on the actual
2947 return wxACC_NOT_IMPLEMENTED
;
2949 // This will eventually be replaced by specialised
2950 // accessible classes, one for each kind of wxWidgets
2951 // control or window.
2953 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2954 title
= ((wxButton
*) GetWindow())->GetLabel();
2957 title
= GetWindow()->GetName();
2965 return wxACC_NOT_IMPLEMENTED
;
2968 // Gets the number of children.
2969 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2971 wxASSERT( GetWindow() != NULL
);
2975 *childId
= (int) GetWindow()->GetChildren().GetCount();
2979 // Gets the specified child (starting from 1).
2980 // If *child is NULL and return value is wxACC_OK,
2981 // this means that the child is a simple element and
2982 // not an accessible object.
2983 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2985 wxASSERT( GetWindow() != NULL
);
2995 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2998 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2999 *child
= childWindow
->GetOrCreateAccessible();
3006 // Gets the parent, or NULL.
3007 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
3009 wxASSERT( GetWindow() != NULL
);
3013 wxWindow
* parentWindow
= GetWindow()->GetParent();
3021 *parent
= parentWindow
->GetOrCreateAccessible();
3029 // Performs the default action. childId is 0 (the action for this object)
3030 // or > 0 (the action for a child).
3031 // Return wxACC_NOT_SUPPORTED if there is no default action for this
3032 // window (e.g. an edit control).
3033 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
3035 wxASSERT( GetWindow() != NULL
);
3039 return wxACC_NOT_IMPLEMENTED
;
3042 // Gets the default action for this object (0) or > 0 (the action for a child).
3043 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
3044 // string if there is no action.
3045 // The retrieved string describes the action that is performed on an object,
3046 // not what the object does as a result. For example, a toolbar button that prints
3047 // a document has a default action of "Press" rather than "Prints the current document."
3048 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
3050 wxASSERT( GetWindow() != NULL
);
3054 return wxACC_NOT_IMPLEMENTED
;
3057 // Returns the description for this object or a child.
3058 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
3060 wxASSERT( GetWindow() != NULL
);
3064 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3070 return wxACC_NOT_IMPLEMENTED
;
3073 // Returns help text for this object or a child, similar to tooltip text.
3074 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
3076 wxASSERT( GetWindow() != NULL
);
3080 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3086 return wxACC_NOT_IMPLEMENTED
;
3089 // Returns the keyboard shortcut for this object or child.
3090 // Return e.g. ALT+K
3091 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
3093 wxASSERT( GetWindow() != NULL
);
3097 return wxACC_NOT_IMPLEMENTED
;
3100 // Returns a role constant.
3101 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
3103 wxASSERT( GetWindow() != NULL
);
3107 // If a child, leave wxWidgets to call the function on the actual
3110 return wxACC_NOT_IMPLEMENTED
;
3112 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3113 return wxACC_NOT_IMPLEMENTED
;
3115 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3116 return wxACC_NOT_IMPLEMENTED
;
3119 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3120 return wxACC_NOT_IMPLEMENTED
;
3123 //*role = wxROLE_SYSTEM_CLIENT;
3124 *role
= wxROLE_SYSTEM_CLIENT
;
3128 return wxACC_NOT_IMPLEMENTED
;
3132 // Returns a state constant.
3133 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
3135 wxASSERT( GetWindow() != NULL
);
3139 // If a child, leave wxWidgets to call the function on the actual
3142 return wxACC_NOT_IMPLEMENTED
;
3144 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3145 return wxACC_NOT_IMPLEMENTED
;
3148 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3149 return wxACC_NOT_IMPLEMENTED
;
3152 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3153 return wxACC_NOT_IMPLEMENTED
;
3160 return wxACC_NOT_IMPLEMENTED
;
3164 // Returns a localized string representing the value for the object
3166 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3168 wxASSERT( GetWindow() != NULL
);
3172 return wxACC_NOT_IMPLEMENTED
;
3175 // Selects the object or child.
3176 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3178 wxASSERT( GetWindow() != NULL
);
3182 return wxACC_NOT_IMPLEMENTED
;
3185 // Gets the window with the keyboard focus.
3186 // If childId is 0 and child is NULL, no object in
3187 // this subhierarchy has the focus.
3188 // If this object has the focus, child should be 'this'.
3189 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3191 wxASSERT( GetWindow() != NULL
);
3195 return wxACC_NOT_IMPLEMENTED
;
3199 // Gets a variant representing the selected children
3201 // Acceptable values:
3202 // - a null variant (IsNull() returns true)
3203 // - a list variant (GetType() == wxT("list")
3204 // - an integer representing the selected child element,
3205 // or 0 if this object is selected (GetType() == wxT("long")
3206 // - a "void*" pointer to a wxAccessible child object
3207 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3209 wxASSERT( GetWindow() != NULL
);
3213 return wxACC_NOT_IMPLEMENTED
;
3215 #endif // wxUSE_VARIANT
3217 #endif // wxUSE_ACCESSIBILITY
3219 // ----------------------------------------------------------------------------
3221 // ----------------------------------------------------------------------------
3224 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3226 wxCoord widthTotal
) const
3228 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3230 x
= widthTotal
- x
- width
;