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);
320 // The associated popup menu can still be alive, disassociate from it in
322 if ( wxCurrentPopupMenu
&& wxCurrentPopupMenu
->GetInvokingWindow() == this )
323 wxCurrentPopupMenu
->SetInvokingWindow(NULL
);
325 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
327 // notify the parent about this window destruction
329 m_parent
->RemoveChild(this);
333 #endif // wxUSE_CARET
336 delete m_windowValidator
;
337 #endif // wxUSE_VALIDATORS
339 #if wxUSE_CONSTRAINTS
340 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
341 // at deleted windows as they delete themselves.
342 DeleteRelatedConstraints();
346 // This removes any dangling pointers to this window in other windows'
347 // constraintsInvolvedIn lists.
348 UnsetConstraints(m_constraints
);
349 delete m_constraints
;
350 m_constraints
= NULL
;
352 #endif // wxUSE_CONSTRAINTS
354 if ( m_containingSizer
)
355 m_containingSizer
->Detach( (wxWindow
*)this );
357 delete m_windowSizer
;
359 #if wxUSE_DRAG_AND_DROP
361 #endif // wxUSE_DRAG_AND_DROP
365 #endif // wxUSE_TOOLTIPS
367 #if wxUSE_ACCESSIBILITY
372 void wxWindowBase::SendDestroyEvent()
374 wxWindowDestroyEvent event
;
375 event
.SetEventObject(this);
376 event
.SetId(GetId());
377 GetEventHandler()->ProcessEvent(event
);
380 bool wxWindowBase::Destroy()
387 bool wxWindowBase::Close(bool force
)
389 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
390 event
.SetEventObject(this);
391 event
.SetCanVeto(!force
);
393 // return false if window wasn't closed because the application vetoed the
395 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
398 bool wxWindowBase::DestroyChildren()
400 wxWindowList::compatibility_iterator node
;
403 // we iterate until the list becomes empty
404 node
= GetChildren().GetFirst();
408 wxWindow
*child
= node
->GetData();
410 // note that we really want to call delete and not ->Destroy() here
411 // because we want to delete the child immediately, before we are
412 // deleted, and delayed deletion would result in problems as our (top
413 // level) child could outlive its parent
416 wxASSERT_MSG( !GetChildren().Find(child
),
417 wxT("child didn't remove itself using RemoveChild()") );
423 // ----------------------------------------------------------------------------
424 // size/position related methods
425 // ----------------------------------------------------------------------------
427 // centre the window with respect to its parent in either (or both) directions
428 void wxWindowBase::DoCentre(int dir
)
430 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
431 _T("this method only implements centering child windows") );
433 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
436 // fits the window around the children
437 void wxWindowBase::Fit()
439 if ( !GetChildren().empty() )
441 SetSize(GetBestSize());
443 //else: do nothing if we have no children
446 // fits virtual size (ie. scrolled area etc.) around children
447 void wxWindowBase::FitInside()
449 if ( GetChildren().GetCount() > 0 )
451 SetVirtualSize( GetBestVirtualSize() );
455 // On Mac, scrollbars are explicitly children.
457 static bool wxHasRealChildren(const wxWindowBase
* win
)
459 int realChildCount
= 0;
461 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
463 node
= node
->GetNext() )
465 wxWindow
*win
= node
->GetData();
466 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
469 return (realChildCount
> 0);
473 void wxWindowBase::InvalidateBestSize()
475 m_bestSizeCache
= wxDefaultSize
;
477 // parent's best size calculation may depend on its children's
478 // as long as child window we are in is not top level window itself
479 // (because the TLW size is never resized automatically)
480 // so let's invalidate it as well to be safe:
481 if (m_parent
&& !IsTopLevel())
482 m_parent
->InvalidateBestSize();
485 // return the size best suited for the current window
486 wxSize
wxWindowBase::DoGetBestSize() const
492 best
= m_windowSizer
->GetMinSize();
494 #if wxUSE_CONSTRAINTS
495 else if ( m_constraints
)
497 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
499 // our minimal acceptable size is such that all our windows fit inside
503 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
505 node
= node
->GetNext() )
507 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
510 // it's not normal that we have an unconstrained child, but
511 // what can we do about it?
515 int x
= c
->right
.GetValue(),
516 y
= c
->bottom
.GetValue();
524 // TODO: we must calculate the overlaps somehow, otherwise we
525 // will never return a size bigger than the current one :-(
528 best
= wxSize(maxX
, maxY
);
530 #endif // wxUSE_CONSTRAINTS
531 else if ( !GetChildren().empty()
533 && wxHasRealChildren(this)
537 // our minimal acceptable size is such that all our visible child
538 // windows fit inside
542 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
544 node
= node
->GetNext() )
546 wxWindow
*win
= node
->GetData();
547 if ( win
->IsTopLevel()
550 || wxDynamicCast(win
, wxStatusBar
)
551 #endif // wxUSE_STATUSBAR
554 // dialogs and frames lie in different top level windows -
555 // don't deal with them here; as for the status bars, they
556 // don't lie in the client area at all
561 win
->GetPosition(&wx
, &wy
);
563 // if the window hadn't been positioned yet, assume that it is in
565 if ( wx
== wxDefaultCoord
)
567 if ( wy
== wxDefaultCoord
)
570 win
->GetSize(&ww
, &wh
);
571 if ( wx
+ ww
> maxX
)
573 if ( wy
+ wh
> maxY
)
577 best
= wxSize(maxX
, maxY
);
579 else // ! has children
581 // for a generic window there is no natural best size so, if the
582 // minimal size is not set, use the current size but take care to
583 // remember it as minimal size for the next time because our best size
584 // should be constant: otherwise we could get into a situation when the
585 // window is initially at some size, then expanded to a larger size and
586 // then, when the containing window is shrunk back (because our initial
587 // best size had been used for computing the parent min size), we can't
588 // be shrunk back any more because our best size is now bigger
589 wxSize size
= GetMinSize();
590 if ( !size
.IsFullySpecified() )
592 size
.SetDefaults(GetSize());
593 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
596 // return as-is, unadjusted by the client size difference.
600 // Add any difference between size and client size
601 wxSize diff
= GetSize() - GetClientSize();
602 best
.x
+= wxMax(0, diff
.x
);
603 best
.y
+= wxMax(0, diff
.y
);
608 // helper of GetWindowBorderSize(): as many ports don't implement support for
609 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
610 // fallbacks in this case
611 static int wxGetMetricOrDefault(wxSystemMetric what
)
613 int rc
= wxSystemSettings::GetMetric(what
);
620 // 2D border is by default 1 pixel wide
626 // 3D borders are by default 2 pixels
631 wxFAIL_MSG( _T("unexpected wxGetMetricOrDefault() argument") );
639 wxSize
wxWindowBase::GetWindowBorderSize() const
643 switch ( GetBorder() )
646 // nothing to do, size is already (0, 0)
649 case wxBORDER_SIMPLE
:
650 case wxBORDER_STATIC
:
651 size
.x
= wxGetMetricOrDefault(wxSYS_BORDER_X
);
652 size
.y
= wxGetMetricOrDefault(wxSYS_BORDER_Y
);
655 case wxBORDER_SUNKEN
:
656 case wxBORDER_RAISED
:
657 size
.x
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X
),
658 wxGetMetricOrDefault(wxSYS_BORDER_X
));
659 size
.y
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y
),
660 wxGetMetricOrDefault(wxSYS_BORDER_Y
));
663 case wxBORDER_DOUBLE
:
664 size
.x
= wxGetMetricOrDefault(wxSYS_EDGE_X
) +
665 wxGetMetricOrDefault(wxSYS_BORDER_X
);
666 size
.y
= wxGetMetricOrDefault(wxSYS_EDGE_Y
) +
667 wxGetMetricOrDefault(wxSYS_BORDER_Y
);
671 wxFAIL_MSG(_T("Unknown border style."));
675 // we have borders on both sides
679 wxSize
wxWindowBase::GetEffectiveMinSize() const
681 // merge the best size with the min size, giving priority to the min size
682 wxSize min
= GetMinSize();
683 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
685 wxSize best
= GetBestSize();
686 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
687 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
693 void wxWindowBase::SetInitialSize(const wxSize
& size
)
695 // Set the min size to the size passed in. This will usually either be
696 // wxDefaultSize or the size passed to this window's ctor/Create function.
699 // Merge the size with the best size if needed
700 wxSize best
= GetEffectiveMinSize();
702 // If the current size doesn't match then change it
703 if (GetSize() != best
)
708 // by default the origin is not shifted
709 wxPoint
wxWindowBase::GetClientAreaOrigin() const
714 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
716 if ( m_windowVariant
!= variant
)
718 m_windowVariant
= variant
;
720 DoSetWindowVariant(variant
);
724 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
726 // adjust the font height to correspond to our new variant (notice that
727 // we're only called if something really changed)
728 wxFont font
= GetFont();
729 int size
= font
.GetPointSize();
732 case wxWINDOW_VARIANT_NORMAL
:
735 case wxWINDOW_VARIANT_SMALL
:
740 case wxWINDOW_VARIANT_MINI
:
745 case wxWINDOW_VARIANT_LARGE
:
751 wxFAIL_MSG(_T("unexpected window variant"));
755 font
.SetPointSize(size
);
759 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
761 int WXUNUSED(incW
), int WXUNUSED(incH
) )
763 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
764 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
765 _T("min width/height must be less than max width/height!") );
774 #if WXWIN_COMPATIBILITY_2_8
775 void wxWindowBase::SetVirtualSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
),
776 int WXUNUSED(maxW
), int WXUNUSED(maxH
))
780 void wxWindowBase::SetVirtualSizeHints(const wxSize
& WXUNUSED(minsize
),
781 const wxSize
& WXUNUSED(maxsize
))
784 #endif // WXWIN_COMPATIBILITY_2_8
786 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
788 m_virtualSize
= wxSize(x
, y
);
791 wxSize
wxWindowBase::DoGetVirtualSize() const
793 // we should use the entire client area so if it is greater than our
794 // virtual size, expand it to fit (otherwise if the window is big enough we
795 // wouldn't be using parts of it)
796 wxSize size
= GetClientSize();
797 if ( m_virtualSize
.x
> size
.x
)
798 size
.x
= m_virtualSize
.x
;
800 if ( m_virtualSize
.y
>= size
.y
)
801 size
.y
= m_virtualSize
.y
;
806 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
808 // screen position is the same as (0, 0) in client coords for non TLWs (and
809 // TLWs override this method)
815 ClientToScreen(x
, y
);
818 // ----------------------------------------------------------------------------
819 // show/hide/enable/disable the window
820 // ----------------------------------------------------------------------------
822 bool wxWindowBase::Show(bool show
)
824 if ( show
!= m_isShown
)
836 bool wxWindowBase::IsEnabled() const
838 return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
841 void wxWindowBase::NotifyWindowOnEnableChange(bool enabled
)
843 #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
845 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
849 // If we are top-level then the logic doesn't apply - otherwise
850 // showing a modal dialog would result in total greying out (and ungreying
851 // out later) of everything which would be really ugly
855 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
857 node
= node
->GetNext() )
859 wxWindowBase
* const child
= node
->GetData();
860 if ( !child
->IsTopLevel() && child
->IsThisEnabled() )
861 child
->NotifyWindowOnEnableChange(enabled
);
865 bool wxWindowBase::Enable(bool enable
)
867 if ( enable
== IsThisEnabled() )
870 m_isEnabled
= enable
;
872 #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
874 #else // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
875 wxWindowBase
* const parent
= GetParent();
876 if( !IsTopLevel() && parent
&& !parent
->IsEnabled() )
880 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
882 NotifyWindowOnEnableChange(enable
);
887 bool wxWindowBase::IsShownOnScreen() const
889 // A window is shown on screen if it itself is shown and so are all its
890 // parents. But if a window is toplevel one, then its always visible on
891 // screen if IsShown() returns true, even if it has a hidden parent.
893 (IsTopLevel() || GetParent() == NULL
|| GetParent()->IsShownOnScreen());
896 // ----------------------------------------------------------------------------
898 // ----------------------------------------------------------------------------
900 bool wxWindowBase::IsTopLevel() const
905 // ----------------------------------------------------------------------------
906 // reparenting the window
907 // ----------------------------------------------------------------------------
909 void wxWindowBase::AddChild(wxWindowBase
*child
)
911 wxCHECK_RET( child
, wxT("can't add a NULL child") );
913 // this should never happen and it will lead to a crash later if it does
914 // because RemoveChild() will remove only one node from the children list
915 // and the other(s) one(s) will be left with dangling pointers in them
916 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
918 GetChildren().Append((wxWindow
*)child
);
919 child
->SetParent(this);
922 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
924 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
926 GetChildren().DeleteObject((wxWindow
*)child
);
927 child
->SetParent(NULL
);
930 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
932 wxWindow
*oldParent
= GetParent();
933 if ( newParent
== oldParent
)
939 const bool oldEnabledState
= IsEnabled();
941 // unlink this window from the existing parent.
944 oldParent
->RemoveChild(this);
948 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
951 // add it to the new one
954 newParent
->AddChild(this);
958 wxTopLevelWindows
.Append((wxWindow
*)this);
961 // We need to notify window (and its subwindows) if by changing the parent
962 // we also change our enabled/disabled status.
963 const bool newEnabledState
= IsEnabled();
964 if ( newEnabledState
!= oldEnabledState
)
966 NotifyWindowOnEnableChange(newEnabledState
);
972 // ----------------------------------------------------------------------------
973 // event handler stuff
974 // ----------------------------------------------------------------------------
976 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
978 wxEvtHandler
*handlerOld
= GetEventHandler();
980 handler
->SetNextHandler(handlerOld
);
983 GetEventHandler()->SetPreviousHandler(handler
);
985 SetEventHandler(handler
);
988 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
990 wxEvtHandler
*handlerA
= GetEventHandler();
993 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
994 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
997 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
998 SetEventHandler(handlerB
);
1000 if ( deleteHandler
)
1003 handlerA
= (wxEvtHandler
*)NULL
;
1010 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
1012 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
1014 wxEvtHandler
*handlerPrev
= NULL
,
1015 *handlerCur
= GetEventHandler();
1016 while ( handlerCur
)
1018 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
1020 if ( handlerCur
== handler
)
1024 handlerPrev
->SetNextHandler(handlerNext
);
1028 SetEventHandler(handlerNext
);
1033 handlerNext
->SetPreviousHandler ( handlerPrev
);
1036 handler
->SetNextHandler(NULL
);
1037 handler
->SetPreviousHandler(NULL
);
1042 handlerPrev
= handlerCur
;
1043 handlerCur
= handlerNext
;
1046 wxFAIL_MSG( _T("where has the event handler gone?") );
1051 bool wxWindowBase::HandleWindowEvent(wxEvent
& event
) const
1053 return GetEventHandler()->SafelyProcessEvent(event
);
1056 // ----------------------------------------------------------------------------
1057 // colours, fonts &c
1058 // ----------------------------------------------------------------------------
1060 void wxWindowBase::InheritAttributes()
1062 const wxWindowBase
* const parent
= GetParent();
1066 // we only inherit attributes which had been explicitly set for the parent
1067 // which ensures that this only happens if the user really wants it and
1068 // not by default which wouldn't make any sense in modern GUIs where the
1069 // controls don't all use the same fonts (nor colours)
1070 if ( parent
->m_inheritFont
&& !m_hasFont
)
1071 SetFont(parent
->GetFont());
1073 // in addition, there is a possibility to explicitly forbid inheriting
1074 // colours at each class level by overriding ShouldInheritColours()
1075 if ( ShouldInheritColours() )
1077 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1078 SetForegroundColour(parent
->GetForegroundColour());
1080 // inheriting (solid) background colour is wrong as it totally breaks
1081 // any kind of themed backgrounds
1083 // instead, the controls should use the same background as their parent
1084 // (ideally by not drawing it at all)
1086 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1087 SetBackgroundColour(parent
->GetBackgroundColour());
1092 /* static */ wxVisualAttributes
1093 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1095 // it is important to return valid values for all attributes from here,
1096 // GetXXX() below rely on this
1097 wxVisualAttributes attrs
;
1098 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1099 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1101 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1102 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1103 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1104 // colour on other platforms.
1106 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1107 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1109 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1114 wxColour
wxWindowBase::GetBackgroundColour() const
1116 if ( !m_backgroundColour
.IsOk() )
1118 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
1120 // get our default background colour
1121 wxColour colBg
= GetDefaultAttributes().colBg
;
1123 // we must return some valid colour to avoid redoing this every time
1124 // and also to avoid surprizing the applications written for older
1125 // wxWidgets versions where GetBackgroundColour() always returned
1126 // something -- so give them something even if it doesn't make sense
1127 // for this window (e.g. it has a themed background)
1129 colBg
= GetClassDefaultAttributes().colBg
;
1134 return m_backgroundColour
;
1137 wxColour
wxWindowBase::GetForegroundColour() const
1139 // logic is the same as above
1140 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1142 wxColour colFg
= GetDefaultAttributes().colFg
;
1144 if ( !colFg
.IsOk() )
1145 colFg
= GetClassDefaultAttributes().colFg
;
1150 return m_foregroundColour
;
1153 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1155 if ( colour
== m_backgroundColour
)
1158 m_hasBgCol
= colour
.IsOk();
1159 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1160 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1162 m_inheritBgCol
= m_hasBgCol
;
1163 m_backgroundColour
= colour
;
1164 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1168 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1170 if (colour
== m_foregroundColour
)
1173 m_hasFgCol
= colour
.IsOk();
1174 m_inheritFgCol
= m_hasFgCol
;
1175 m_foregroundColour
= colour
;
1176 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1180 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1182 // setting an invalid cursor is ok, it means that we don't have any special
1184 if ( m_cursor
.IsSameAs(cursor
) )
1195 wxFont
wxWindowBase::GetFont() const
1197 // logic is the same as in GetBackgroundColour()
1198 if ( !m_font
.IsOk() )
1200 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1202 wxFont font
= GetDefaultAttributes().font
;
1204 font
= GetClassDefaultAttributes().font
;
1212 bool wxWindowBase::SetFont(const wxFont
& font
)
1214 if ( font
== m_font
)
1221 m_hasFont
= font
.IsOk();
1222 m_inheritFont
= m_hasFont
;
1224 InvalidateBestSize();
1231 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1233 m_hasCustomPalette
= true;
1236 // VZ: can anyone explain me what do we do here?
1237 wxWindowDC
d((wxWindow
*) this);
1241 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1243 wxWindow
*win
= (wxWindow
*)this;
1244 while ( win
&& !win
->HasCustomPalette() )
1246 win
= win
->GetParent();
1252 #endif // wxUSE_PALETTE
1255 void wxWindowBase::SetCaret(wxCaret
*caret
)
1266 wxASSERT_MSG( m_caret
->GetWindow() == this,
1267 wxT("caret should be created associated to this window") );
1270 #endif // wxUSE_CARET
1272 #if wxUSE_VALIDATORS
1273 // ----------------------------------------------------------------------------
1275 // ----------------------------------------------------------------------------
1277 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1279 if ( m_windowValidator
)
1280 delete m_windowValidator
;
1282 m_windowValidator
= (wxValidator
*)validator
.Clone();
1284 if ( m_windowValidator
)
1285 m_windowValidator
->SetWindow(this);
1287 #endif // wxUSE_VALIDATORS
1289 // ----------------------------------------------------------------------------
1290 // update region stuff
1291 // ----------------------------------------------------------------------------
1293 wxRect
wxWindowBase::GetUpdateClientRect() const
1295 wxRegion rgnUpdate
= GetUpdateRegion();
1296 rgnUpdate
.Intersect(GetClientRect());
1297 wxRect rectUpdate
= rgnUpdate
.GetBox();
1298 wxPoint ptOrigin
= GetClientAreaOrigin();
1299 rectUpdate
.x
-= ptOrigin
.x
;
1300 rectUpdate
.y
-= ptOrigin
.y
;
1305 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1307 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1310 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1312 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1315 void wxWindowBase::ClearBackground()
1317 // wxGTK uses its own version, no need to add never used code
1319 wxClientDC
dc((wxWindow
*)this);
1320 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1321 dc
.SetBackground(brush
);
1326 // ----------------------------------------------------------------------------
1327 // find child window by id or name
1328 // ----------------------------------------------------------------------------
1330 wxWindow
*wxWindowBase::FindWindow(long id
) const
1332 if ( id
== m_windowId
)
1333 return (wxWindow
*)this;
1335 wxWindowBase
*res
= (wxWindow
*)NULL
;
1336 wxWindowList::compatibility_iterator node
;
1337 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1339 wxWindowBase
*child
= node
->GetData();
1340 res
= child
->FindWindow( id
);
1343 return (wxWindow
*)res
;
1346 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1348 if ( name
== m_windowName
)
1349 return (wxWindow
*)this;
1351 wxWindowBase
*res
= (wxWindow
*)NULL
;
1352 wxWindowList::compatibility_iterator node
;
1353 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1355 wxWindow
*child
= node
->GetData();
1356 res
= child
->FindWindow(name
);
1359 return (wxWindow
*)res
;
1363 // find any window by id or name or label: If parent is non-NULL, look through
1364 // children for a label or title matching the specified string. If NULL, look
1365 // through all top-level windows.
1367 // to avoid duplicating code we reuse the same helper function but with
1368 // different comparators
1370 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1371 const wxString
& label
, long id
);
1374 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1377 return win
->GetLabel() == label
;
1381 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1384 return win
->GetName() == label
;
1388 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1391 return win
->GetId() == id
;
1394 // recursive helper for the FindWindowByXXX() functions
1396 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1397 const wxString
& label
,
1399 wxFindWindowCmp cmp
)
1403 // see if this is the one we're looking for
1404 if ( (*cmp
)(parent
, label
, id
) )
1405 return (wxWindow
*)parent
;
1407 // It wasn't, so check all its children
1408 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1410 node
= node
->GetNext() )
1412 // recursively check each child
1413 wxWindow
*win
= (wxWindow
*)node
->GetData();
1414 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1424 // helper for FindWindowByXXX()
1426 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1427 const wxString
& label
,
1429 wxFindWindowCmp cmp
)
1433 // just check parent and all its children
1434 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1437 // start at very top of wx's windows
1438 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1440 node
= node
->GetNext() )
1442 // recursively check each window & its children
1443 wxWindow
*win
= node
->GetData();
1444 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1454 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1456 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1461 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1463 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1467 // fall back to the label
1468 win
= FindWindowByLabel(title
, parent
);
1476 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1478 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1481 // ----------------------------------------------------------------------------
1482 // dialog oriented functions
1483 // ----------------------------------------------------------------------------
1485 void wxWindowBase::MakeModal(bool modal
)
1487 // Disable all other windows
1490 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1493 wxWindow
*win
= node
->GetData();
1495 win
->Enable(!modal
);
1497 node
= node
->GetNext();
1502 bool wxWindowBase::Validate()
1504 #if wxUSE_VALIDATORS
1505 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1507 wxWindowList::compatibility_iterator node
;
1508 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1510 wxWindowBase
*child
= node
->GetData();
1511 wxValidator
*validator
= child
->GetValidator();
1512 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1517 if ( recurse
&& !child
->Validate() )
1522 #endif // wxUSE_VALIDATORS
1527 bool wxWindowBase::TransferDataToWindow()
1529 #if wxUSE_VALIDATORS
1530 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1532 wxWindowList::compatibility_iterator node
;
1533 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1535 wxWindowBase
*child
= node
->GetData();
1536 wxValidator
*validator
= child
->GetValidator();
1537 if ( validator
&& !validator
->TransferToWindow() )
1539 wxLogWarning(_("Could not transfer data to window"));
1541 wxLog::FlushActive();
1549 if ( !child
->TransferDataToWindow() )
1551 // warning already given
1556 #endif // wxUSE_VALIDATORS
1561 bool wxWindowBase::TransferDataFromWindow()
1563 #if wxUSE_VALIDATORS
1564 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1566 wxWindowList::compatibility_iterator node
;
1567 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1569 wxWindow
*child
= node
->GetData();
1570 wxValidator
*validator
= child
->GetValidator();
1571 if ( validator
&& !validator
->TransferFromWindow() )
1573 // nop warning here because the application is supposed to give
1574 // one itself - we don't know here what might have gone wrongly
1581 if ( !child
->TransferDataFromWindow() )
1583 // warning already given
1588 #endif // wxUSE_VALIDATORS
1593 void wxWindowBase::InitDialog()
1595 wxInitDialogEvent
event(GetId());
1596 event
.SetEventObject( this );
1597 GetEventHandler()->ProcessEvent(event
);
1600 // ----------------------------------------------------------------------------
1601 // context-sensitive help support
1602 // ----------------------------------------------------------------------------
1606 // associate this help text with this window
1607 void wxWindowBase::SetHelpText(const wxString
& text
)
1609 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1612 helpProvider
->AddHelp(this, text
);
1616 // associate this help text with all windows with the same id as this
1618 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1620 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1623 helpProvider
->AddHelp(GetId(), text
);
1627 // get the help string associated with this window (may be empty)
1628 // default implementation forwards calls to the help provider
1630 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1631 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1634 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1637 text
= helpProvider
->GetHelp(this);
1643 // show help for this window
1644 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1646 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1649 if ( helpProvider
->ShowHelpAtPoint(this, event
.GetPosition(), event
.GetOrigin()) )
1651 // skip the event.Skip() below
1659 #endif // wxUSE_HELP
1661 // ----------------------------------------------------------------------------
1663 // ----------------------------------------------------------------------------
1667 void wxWindowBase::SetToolTip( const wxString
&tip
)
1669 // don't create the new tooltip if we already have one
1672 m_tooltip
->SetTip( tip
);
1676 SetToolTip( new wxToolTip( tip
) );
1679 // setting empty tooltip text does not remove the tooltip any more - use
1680 // SetToolTip((wxToolTip *)NULL) for this
1683 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1685 if ( m_tooltip
!= tooltip
)
1690 m_tooltip
= tooltip
;
1694 #endif // wxUSE_TOOLTIPS
1696 // ----------------------------------------------------------------------------
1697 // constraints and sizers
1698 // ----------------------------------------------------------------------------
1700 #if wxUSE_CONSTRAINTS
1702 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1704 if ( m_constraints
)
1706 UnsetConstraints(m_constraints
);
1707 delete m_constraints
;
1709 m_constraints
= constraints
;
1710 if ( m_constraints
)
1712 // Make sure other windows know they're part of a 'meaningful relationship'
1713 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1714 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1715 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1716 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1717 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1718 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1719 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1720 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1721 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1722 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1723 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1724 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1725 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1726 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1727 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1728 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1732 // This removes any dangling pointers to this window in other windows'
1733 // constraintsInvolvedIn lists.
1734 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1738 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1739 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1740 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1741 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1742 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1743 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1744 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1745 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1746 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1747 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1748 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1749 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1750 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1751 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1752 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1753 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1757 // Back-pointer to other windows we're involved with, so if we delete this
1758 // window, we must delete any constraints we're involved with.
1759 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1761 if ( !m_constraintsInvolvedIn
)
1762 m_constraintsInvolvedIn
= new wxWindowList
;
1763 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1764 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1767 // REMOVE back-pointer to other windows we're involved with.
1768 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1770 if ( m_constraintsInvolvedIn
)
1771 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1774 // Reset any constraints that mention this window
1775 void wxWindowBase::DeleteRelatedConstraints()
1777 if ( m_constraintsInvolvedIn
)
1779 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1782 wxWindow
*win
= node
->GetData();
1783 wxLayoutConstraints
*constr
= win
->GetConstraints();
1785 // Reset any constraints involving this window
1788 constr
->left
.ResetIfWin(this);
1789 constr
->top
.ResetIfWin(this);
1790 constr
->right
.ResetIfWin(this);
1791 constr
->bottom
.ResetIfWin(this);
1792 constr
->width
.ResetIfWin(this);
1793 constr
->height
.ResetIfWin(this);
1794 constr
->centreX
.ResetIfWin(this);
1795 constr
->centreY
.ResetIfWin(this);
1798 wxWindowList::compatibility_iterator next
= node
->GetNext();
1799 m_constraintsInvolvedIn
->Erase(node
);
1803 delete m_constraintsInvolvedIn
;
1804 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1808 #endif // wxUSE_CONSTRAINTS
1810 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1812 if ( sizer
== m_windowSizer
)
1815 if ( m_windowSizer
)
1817 m_windowSizer
->SetContainingWindow(NULL
);
1820 delete m_windowSizer
;
1823 m_windowSizer
= sizer
;
1824 if ( m_windowSizer
)
1826 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
1829 SetAutoLayout(m_windowSizer
!= NULL
);
1832 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1834 SetSizer( sizer
, deleteOld
);
1835 sizer
->SetSizeHints( (wxWindow
*) this );
1839 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1841 // adding a window to a sizer twice is going to result in fatal and
1842 // hard to debug problems later because when deleting the second
1843 // associated wxSizerItem we're going to dereference a dangling
1844 // pointer; so try to detect this as early as possible
1845 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1846 _T("Adding a window to the same sizer twice?") );
1848 m_containingSizer
= sizer
;
1851 #if wxUSE_CONSTRAINTS
1853 void wxWindowBase::SatisfyConstraints()
1855 wxLayoutConstraints
*constr
= GetConstraints();
1856 bool wasOk
= constr
&& constr
->AreSatisfied();
1858 ResetConstraints(); // Mark all constraints as unevaluated
1862 // if we're a top level panel (i.e. our parent is frame/dialog), our
1863 // own constraints will never be satisfied any more unless we do it
1867 while ( noChanges
> 0 )
1869 LayoutPhase1(&noChanges
);
1873 LayoutPhase2(&noChanges
);
1876 #endif // wxUSE_CONSTRAINTS
1878 bool wxWindowBase::Layout()
1880 // If there is a sizer, use it instead of the constraints
1884 GetVirtualSize(&w
, &h
);
1885 GetSizer()->SetDimension( 0, 0, w
, h
);
1887 #if wxUSE_CONSTRAINTS
1890 SatisfyConstraints(); // Find the right constraints values
1891 SetConstraintSizes(); // Recursively set the real window sizes
1898 #if wxUSE_CONSTRAINTS
1900 // first phase of the constraints evaluation: set our own constraints
1901 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1903 wxLayoutConstraints
*constr
= GetConstraints();
1905 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1908 // second phase: set the constraints for our children
1909 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1916 // Layout grand children
1922 // Do a phase of evaluating child constraints
1923 bool wxWindowBase::DoPhase(int phase
)
1925 // the list containing the children for which the constraints are already
1927 wxWindowList succeeded
;
1929 // the max number of iterations we loop before concluding that we can't set
1931 static const int maxIterations
= 500;
1933 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1937 // loop over all children setting their constraints
1938 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1940 node
= node
->GetNext() )
1942 wxWindow
*child
= node
->GetData();
1943 if ( child
->IsTopLevel() )
1945 // top level children are not inside our client area
1949 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1951 // this one is either already ok or nothing we can do about it
1955 int tempNoChanges
= 0;
1956 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1957 : child
->LayoutPhase2(&tempNoChanges
);
1958 noChanges
+= tempNoChanges
;
1962 succeeded
.Append(child
);
1968 // constraints are set
1976 void wxWindowBase::ResetConstraints()
1978 wxLayoutConstraints
*constr
= GetConstraints();
1981 constr
->left
.SetDone(false);
1982 constr
->top
.SetDone(false);
1983 constr
->right
.SetDone(false);
1984 constr
->bottom
.SetDone(false);
1985 constr
->width
.SetDone(false);
1986 constr
->height
.SetDone(false);
1987 constr
->centreX
.SetDone(false);
1988 constr
->centreY
.SetDone(false);
1991 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1994 wxWindow
*win
= node
->GetData();
1995 if ( !win
->IsTopLevel() )
1996 win
->ResetConstraints();
1997 node
= node
->GetNext();
2001 // Need to distinguish between setting the 'fake' size for windows and sizers,
2002 // and setting the real values.
2003 void wxWindowBase::SetConstraintSizes(bool recurse
)
2005 wxLayoutConstraints
*constr
= GetConstraints();
2006 if ( constr
&& constr
->AreSatisfied() )
2008 int x
= constr
->left
.GetValue();
2009 int y
= constr
->top
.GetValue();
2010 int w
= constr
->width
.GetValue();
2011 int h
= constr
->height
.GetValue();
2013 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
2014 (constr
->height
.GetRelationship() != wxAsIs
) )
2016 SetSize(x
, y
, w
, h
);
2020 // If we don't want to resize this window, just move it...
2026 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
2027 GetClassInfo()->GetClassName(),
2033 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2036 wxWindow
*win
= node
->GetData();
2037 if ( !win
->IsTopLevel() && win
->GetConstraints() )
2038 win
->SetConstraintSizes();
2039 node
= node
->GetNext();
2044 // Only set the size/position of the constraint (if any)
2045 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
2047 wxLayoutConstraints
*constr
= GetConstraints();
2050 if ( x
!= wxDefaultCoord
)
2052 constr
->left
.SetValue(x
);
2053 constr
->left
.SetDone(true);
2055 if ( y
!= wxDefaultCoord
)
2057 constr
->top
.SetValue(y
);
2058 constr
->top
.SetDone(true);
2060 if ( w
!= wxDefaultCoord
)
2062 constr
->width
.SetValue(w
);
2063 constr
->width
.SetDone(true);
2065 if ( h
!= wxDefaultCoord
)
2067 constr
->height
.SetValue(h
);
2068 constr
->height
.SetDone(true);
2073 void wxWindowBase::MoveConstraint(int x
, int y
)
2075 wxLayoutConstraints
*constr
= GetConstraints();
2078 if ( x
!= wxDefaultCoord
)
2080 constr
->left
.SetValue(x
);
2081 constr
->left
.SetDone(true);
2083 if ( y
!= wxDefaultCoord
)
2085 constr
->top
.SetValue(y
);
2086 constr
->top
.SetDone(true);
2091 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2093 wxLayoutConstraints
*constr
= GetConstraints();
2096 *w
= constr
->width
.GetValue();
2097 *h
= constr
->height
.GetValue();
2103 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2105 wxLayoutConstraints
*constr
= GetConstraints();
2108 *w
= constr
->width
.GetValue();
2109 *h
= constr
->height
.GetValue();
2112 GetClientSize(w
, h
);
2115 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2117 wxLayoutConstraints
*constr
= GetConstraints();
2120 *x
= constr
->left
.GetValue();
2121 *y
= constr
->top
.GetValue();
2127 #endif // wxUSE_CONSTRAINTS
2129 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2131 // don't do it for the dialogs/frames - they float independently of their
2133 if ( !IsTopLevel() )
2135 wxWindow
*parent
= GetParent();
2136 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2138 wxPoint
pt(parent
->GetClientAreaOrigin());
2145 // ----------------------------------------------------------------------------
2146 // Update UI processing
2147 // ----------------------------------------------------------------------------
2149 void wxWindowBase::UpdateWindowUI(long flags
)
2151 wxUpdateUIEvent
event(GetId());
2152 event
.SetEventObject(this);
2154 if ( GetEventHandler()->ProcessEvent(event
) )
2156 DoUpdateWindowUI(event
);
2159 if (flags
& wxUPDATE_UI_RECURSE
)
2161 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2164 wxWindow
* child
= (wxWindow
*) node
->GetData();
2165 child
->UpdateWindowUI(flags
);
2166 node
= node
->GetNext();
2171 // do the window-specific processing after processing the update event
2172 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2174 if ( event
.GetSetEnabled() )
2175 Enable(event
.GetEnabled());
2177 if ( event
.GetSetShown() )
2178 Show(event
.GetShown());
2181 // ----------------------------------------------------------------------------
2182 // dialog units translations
2183 // ----------------------------------------------------------------------------
2185 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2187 int charWidth
= GetCharWidth();
2188 int charHeight
= GetCharHeight();
2189 wxPoint pt2
= wxDefaultPosition
;
2190 if (pt
.x
!= wxDefaultCoord
)
2191 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2192 if (pt
.y
!= wxDefaultCoord
)
2193 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2198 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2200 int charWidth
= GetCharWidth();
2201 int charHeight
= GetCharHeight();
2202 wxPoint pt2
= wxDefaultPosition
;
2203 if (pt
.x
!= wxDefaultCoord
)
2204 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2205 if (pt
.y
!= wxDefaultCoord
)
2206 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2211 // ----------------------------------------------------------------------------
2213 // ----------------------------------------------------------------------------
2215 // propagate the colour change event to the subwindows
2216 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2218 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2221 // Only propagate to non-top-level windows
2222 wxWindow
*win
= node
->GetData();
2223 if ( !win
->IsTopLevel() )
2225 wxSysColourChangedEvent event2
;
2226 event
.SetEventObject(win
);
2227 win
->GetEventHandler()->ProcessEvent(event2
);
2230 node
= node
->GetNext();
2236 // the default action is to populate dialog with data when it's created,
2237 // and nudge the UI into displaying itself correctly in case
2238 // we've turned the wxUpdateUIEvents frequency down low.
2239 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2241 TransferDataToWindow();
2243 // Update the UI at this point
2244 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2247 // ----------------------------------------------------------------------------
2248 // menu-related functions
2249 // ----------------------------------------------------------------------------
2253 bool wxWindowBase::PopupMenu(wxMenu
*menu
, int x
, int y
)
2255 wxCHECK_MSG( menu
, false, "can't popup NULL menu" );
2257 wxCurrentPopupMenu
= menu
;
2258 const bool rc
= DoPopupMenu(menu
, x
, y
);
2259 wxCurrentPopupMenu
= NULL
;
2264 // this is used to pass the id of the selected item from the menu event handler
2265 // to the main function itself
2267 // it's ok to use a global here as there can be at most one popup menu shown at
2269 static int gs_popupMenuSelection
= wxID_NONE
;
2271 void wxWindowBase::InternalOnPopupMenu(wxCommandEvent
& event
)
2273 // store the id in a global variable where we'll retrieve it from later
2274 gs_popupMenuSelection
= event
.GetId();
2278 wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu
& menu
, int x
, int y
)
2280 gs_popupMenuSelection
= wxID_NONE
;
2282 Connect(wxEVT_COMMAND_MENU_SELECTED
,
2283 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2287 PopupMenu(&menu
, x
, y
);
2289 Disconnect(wxEVT_COMMAND_MENU_SELECTED
,
2290 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2294 return gs_popupMenuSelection
;
2297 #endif // wxUSE_MENUS
2299 // methods for drawing the sizers in a visible way
2302 static void DrawSizers(wxWindowBase
*win
);
2304 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2306 wxClientDC
dc((wxWindow
*)win
);
2307 dc
.SetPen(*wxRED_PEN
);
2308 dc
.SetBrush(fill
? wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2309 dc
.DrawRectangle(rect
.Deflate(1, 1));
2312 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2314 const wxSizerItemList
& items
= sizer
->GetChildren();
2315 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2320 wxSizerItem
*item
= *i
;
2321 if ( item
->IsSizer() )
2323 DrawBorder(win
, item
->GetRect().Deflate(2));
2324 DrawSizer(win
, item
->GetSizer());
2326 else if ( item
->IsSpacer() )
2328 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2330 else if ( item
->IsWindow() )
2332 DrawSizers(item
->GetWindow());
2337 static void DrawSizers(wxWindowBase
*win
)
2339 wxSizer
*sizer
= win
->GetSizer();
2342 DrawBorder(win
, win
->GetClientSize());
2343 DrawSizer(win
, sizer
);
2345 else // no sizer, still recurse into the children
2347 const wxWindowList
& children
= win
->GetChildren();
2348 for ( wxWindowList::const_iterator i
= children
.begin(),
2349 end
= children
.end();
2358 #endif // __WXDEBUG__
2360 // process special middle clicks
2361 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2363 if ( event
.ControlDown() && event
.AltDown() )
2366 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2367 if ( event
.ShiftDown() )
2372 #endif // __WXDEBUG__
2373 ::wxInfoMessageBox((wxWindow
*)this);
2381 // ----------------------------------------------------------------------------
2383 // ----------------------------------------------------------------------------
2385 #if wxUSE_ACCESSIBILITY
2386 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2388 if (m_accessible
&& (accessible
!= m_accessible
))
2389 delete m_accessible
;
2390 m_accessible
= accessible
;
2392 m_accessible
->SetWindow((wxWindow
*) this);
2395 // Returns the accessible object, creating if necessary.
2396 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2399 m_accessible
= CreateAccessible();
2400 return m_accessible
;
2403 // Override to create a specific accessible object.
2404 wxAccessible
* wxWindowBase::CreateAccessible()
2406 return new wxWindowAccessible((wxWindow
*) this);
2411 // ----------------------------------------------------------------------------
2412 // list classes implementation
2413 // ----------------------------------------------------------------------------
2417 #include "wx/listimpl.cpp"
2418 WX_DEFINE_LIST(wxWindowList
)
2422 void wxWindowListNode::DeleteData()
2424 delete (wxWindow
*)GetData();
2427 #endif // wxUSE_STL/!wxUSE_STL
2429 // ----------------------------------------------------------------------------
2431 // ----------------------------------------------------------------------------
2433 wxBorder
wxWindowBase::GetBorder(long flags
) const
2435 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2436 if ( border
== wxBORDER_DEFAULT
)
2438 border
= GetDefaultBorder();
2440 else if ( border
== wxBORDER_THEME
)
2442 border
= GetDefaultBorderForControl();
2448 wxBorder
wxWindowBase::GetDefaultBorder() const
2450 return wxBORDER_NONE
;
2453 // ----------------------------------------------------------------------------
2455 // ----------------------------------------------------------------------------
2457 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2459 // here we just check if the point is inside the window or not
2461 // check the top and left border first
2462 bool outside
= x
< 0 || y
< 0;
2465 // check the right and bottom borders too
2466 wxSize size
= GetSize();
2467 outside
= x
>= size
.x
|| y
>= size
.y
;
2470 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2473 // ----------------------------------------------------------------------------
2475 // ----------------------------------------------------------------------------
2477 struct WXDLLEXPORT wxWindowNext
2481 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2482 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2483 bool wxWindowBase::ms_winCaptureChanging
= false;
2485 void wxWindowBase::CaptureMouse()
2487 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2489 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2491 ms_winCaptureChanging
= true;
2493 wxWindow
*winOld
= GetCapture();
2496 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2499 wxWindowNext
*item
= new wxWindowNext
;
2501 item
->next
= ms_winCaptureNext
;
2502 ms_winCaptureNext
= item
;
2504 //else: no mouse capture to save
2507 ms_winCaptureCurrent
= (wxWindow
*)this;
2509 ms_winCaptureChanging
= false;
2512 void wxWindowBase::ReleaseMouse()
2514 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2516 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2518 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2520 ms_winCaptureChanging
= true;
2523 ms_winCaptureCurrent
= NULL
;
2525 if ( ms_winCaptureNext
)
2527 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2528 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2530 wxWindowNext
*item
= ms_winCaptureNext
;
2531 ms_winCaptureNext
= item
->next
;
2534 //else: stack is empty, no previous capture
2536 ms_winCaptureChanging
= false;
2538 wxLogTrace(_T("mousecapture"),
2539 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2540 wx_static_cast(void*, GetCapture()));
2543 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2545 wxMouseCaptureLostEvent
event(win
->GetId());
2546 event
.SetEventObject(win
);
2547 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2549 // windows must handle this event, otherwise the app wouldn't behave
2550 // correctly if it loses capture unexpectedly; see the discussion here:
2551 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
2552 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
2553 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2558 void wxWindowBase::NotifyCaptureLost()
2560 // don't do anything if capture lost was expected, i.e. resulted from
2561 // a wx call to ReleaseMouse or CaptureMouse:
2562 if ( ms_winCaptureChanging
)
2565 // if the capture was lost unexpectedly, notify every window that has
2566 // capture (on stack or current) about it and clear the stack:
2568 if ( ms_winCaptureCurrent
)
2570 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2571 ms_winCaptureCurrent
= NULL
;
2574 while ( ms_winCaptureNext
)
2576 wxWindowNext
*item
= ms_winCaptureNext
;
2577 ms_winCaptureNext
= item
->next
;
2579 DoNotifyWindowAboutCaptureLost(item
->win
);
2588 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2589 int WXUNUSED(modifiers
),
2590 int WXUNUSED(keycode
))
2596 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2602 #endif // wxUSE_HOTKEY
2604 // ----------------------------------------------------------------------------
2606 // ----------------------------------------------------------------------------
2608 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2610 #if wxUSE_VALIDATORS
2611 // Can only use the validator of the window which
2612 // is receiving the event
2613 if ( event
.GetEventObject() == this )
2615 wxValidator
*validator
= GetValidator();
2616 if ( validator
&& validator
->ProcessEvent(event
) )
2621 #endif // wxUSE_VALIDATORS
2626 bool wxWindowBase::TryParent(wxEvent
& event
)
2628 // carry on up the parent-child hierarchy if the propagation count hasn't
2630 if ( event
.ShouldPropagate() )
2632 // honour the requests to stop propagation at this window: this is
2633 // used by the dialogs, for example, to prevent processing the events
2634 // from the dialog controls in the parent frame which rarely, if ever,
2636 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2638 wxWindow
*parent
= GetParent();
2639 if ( parent
&& !parent
->IsBeingDeleted() )
2641 wxPropagateOnce
propagateOnce(event
);
2643 return parent
->GetEventHandler()->ProcessEvent(event
);
2648 return wxEvtHandler::TryParent(event
);
2651 // ----------------------------------------------------------------------------
2652 // window relationships
2653 // ----------------------------------------------------------------------------
2655 wxWindow
*wxWindowBase::DoGetSibling(WindowOrder order
) const
2657 wxCHECK_MSG( GetParent(), NULL
,
2658 _T("GetPrev/NextSibling() don't work for TLWs!") );
2660 wxWindowList
& siblings
= GetParent()->GetChildren();
2661 wxWindowList::compatibility_iterator i
= siblings
.Find((wxWindow
*)this);
2662 wxCHECK_MSG( i
, NULL
, _T("window not a child of its parent?") );
2664 if ( order
== OrderBefore
)
2665 i
= i
->GetPrevious();
2669 return i
? i
->GetData() : NULL
;
2672 // ----------------------------------------------------------------------------
2673 // keyboard navigation
2674 // ----------------------------------------------------------------------------
2676 // Navigates in the specified direction inside this window
2677 bool wxWindowBase::DoNavigateIn(int flags
)
2679 #ifdef wxHAS_NATIVE_TAB_TRAVERSAL
2680 // native code doesn't process our wxNavigationKeyEvents anyhow
2683 #else // !wxHAS_NATIVE_TAB_TRAVERSAL
2684 wxNavigationKeyEvent eventNav
;
2685 eventNav
.SetFlags(flags
);
2686 eventNav
.SetEventObject(FindFocus());
2687 return GetEventHandler()->ProcessEvent(eventNav
);
2688 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
2691 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, WindowOrder move
)
2693 // check that we're not a top level window
2694 wxCHECK_RET( GetParent(),
2695 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2697 // detect the special case when we have nothing to do anyhow and when the
2698 // code below wouldn't work
2702 // find the target window in the siblings list
2703 wxWindowList
& siblings
= GetParent()->GetChildren();
2704 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2705 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2707 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2708 // can't just move the node around
2709 wxWindow
*self
= (wxWindow
*)this;
2710 siblings
.DeleteObject(self
);
2711 if ( move
== OrderAfter
)
2718 siblings
.Insert(i
, self
);
2720 else // OrderAfter and win was the last sibling
2722 siblings
.Append(self
);
2726 // ----------------------------------------------------------------------------
2728 // ----------------------------------------------------------------------------
2730 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2732 wxWindowBase
*win
= DoFindFocus();
2733 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2736 // ----------------------------------------------------------------------------
2738 // ----------------------------------------------------------------------------
2740 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2742 while ( win
&& !win
->IsTopLevel() )
2743 win
= win
->GetParent();
2748 #if wxUSE_ACCESSIBILITY
2749 // ----------------------------------------------------------------------------
2750 // accessible object for windows
2751 // ----------------------------------------------------------------------------
2753 // Can return either a child object, or an integer
2754 // representing the child element, starting from 1.
2755 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2757 wxASSERT( GetWindow() != NULL
);
2761 return wxACC_NOT_IMPLEMENTED
;
2764 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2765 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2767 wxASSERT( GetWindow() != NULL
);
2771 wxWindow
* win
= NULL
;
2778 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2780 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2787 rect
= win
->GetRect();
2788 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2789 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2793 return wxACC_NOT_IMPLEMENTED
;
2796 // Navigates from fromId to toId/toObject.
2797 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2798 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2800 wxASSERT( GetWindow() != NULL
);
2806 case wxNAVDIR_FIRSTCHILD
:
2808 if (GetWindow()->GetChildren().GetCount() == 0)
2810 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2811 *toObject
= childWindow
->GetOrCreateAccessible();
2815 case wxNAVDIR_LASTCHILD
:
2817 if (GetWindow()->GetChildren().GetCount() == 0)
2819 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2820 *toObject
= childWindow
->GetOrCreateAccessible();
2824 case wxNAVDIR_RIGHT
:
2828 wxWindowList::compatibility_iterator node
=
2829 wxWindowList::compatibility_iterator();
2832 // Can't navigate to sibling of this window
2833 // if we're a top-level window.
2834 if (!GetWindow()->GetParent())
2835 return wxACC_NOT_IMPLEMENTED
;
2837 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2841 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2842 node
= GetWindow()->GetChildren().Item(fromId
-1);
2845 if (node
&& node
->GetNext())
2847 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2848 *toObject
= nextWindow
->GetOrCreateAccessible();
2856 case wxNAVDIR_PREVIOUS
:
2858 wxWindowList::compatibility_iterator node
=
2859 wxWindowList::compatibility_iterator();
2862 // Can't navigate to sibling of this window
2863 // if we're a top-level window.
2864 if (!GetWindow()->GetParent())
2865 return wxACC_NOT_IMPLEMENTED
;
2867 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2871 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2872 node
= GetWindow()->GetChildren().Item(fromId
-1);
2875 if (node
&& node
->GetPrevious())
2877 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2878 *toObject
= previousWindow
->GetOrCreateAccessible();
2886 return wxACC_NOT_IMPLEMENTED
;
2889 // Gets the name of the specified object.
2890 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2892 wxASSERT( GetWindow() != NULL
);
2898 // If a child, leave wxWidgets to call the function on the actual
2901 return wxACC_NOT_IMPLEMENTED
;
2903 // This will eventually be replaced by specialised
2904 // accessible classes, one for each kind of wxWidgets
2905 // control or window.
2907 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2908 title
= ((wxButton
*) GetWindow())->GetLabel();
2911 title
= GetWindow()->GetName();
2919 return wxACC_NOT_IMPLEMENTED
;
2922 // Gets the number of children.
2923 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2925 wxASSERT( GetWindow() != NULL
);
2929 *childId
= (int) GetWindow()->GetChildren().GetCount();
2933 // Gets the specified child (starting from 1).
2934 // If *child is NULL and return value is wxACC_OK,
2935 // this means that the child is a simple element and
2936 // not an accessible object.
2937 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2939 wxASSERT( GetWindow() != NULL
);
2949 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2952 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2953 *child
= childWindow
->GetOrCreateAccessible();
2960 // Gets the parent, or NULL.
2961 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2963 wxASSERT( GetWindow() != NULL
);
2967 wxWindow
* parentWindow
= GetWindow()->GetParent();
2975 *parent
= parentWindow
->GetOrCreateAccessible();
2983 // Performs the default action. childId is 0 (the action for this object)
2984 // or > 0 (the action for a child).
2985 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2986 // window (e.g. an edit control).
2987 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2989 wxASSERT( GetWindow() != NULL
);
2993 return wxACC_NOT_IMPLEMENTED
;
2996 // Gets the default action for this object (0) or > 0 (the action for a child).
2997 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2998 // string if there is no action.
2999 // The retrieved string describes the action that is performed on an object,
3000 // not what the object does as a result. For example, a toolbar button that prints
3001 // a document has a default action of "Press" rather than "Prints the current document."
3002 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
3004 wxASSERT( GetWindow() != NULL
);
3008 return wxACC_NOT_IMPLEMENTED
;
3011 // Returns the description for this object or a child.
3012 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
3014 wxASSERT( GetWindow() != NULL
);
3018 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3024 return wxACC_NOT_IMPLEMENTED
;
3027 // Returns help text for this object or a child, similar to tooltip text.
3028 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
3030 wxASSERT( GetWindow() != NULL
);
3034 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3040 return wxACC_NOT_IMPLEMENTED
;
3043 // Returns the keyboard shortcut for this object or child.
3044 // Return e.g. ALT+K
3045 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
3047 wxASSERT( GetWindow() != NULL
);
3051 return wxACC_NOT_IMPLEMENTED
;
3054 // Returns a role constant.
3055 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
3057 wxASSERT( GetWindow() != NULL
);
3061 // If a child, leave wxWidgets to call the function on the actual
3064 return wxACC_NOT_IMPLEMENTED
;
3066 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3067 return wxACC_NOT_IMPLEMENTED
;
3069 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3070 return wxACC_NOT_IMPLEMENTED
;
3073 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3074 return wxACC_NOT_IMPLEMENTED
;
3077 //*role = wxROLE_SYSTEM_CLIENT;
3078 *role
= wxROLE_SYSTEM_CLIENT
;
3082 return wxACC_NOT_IMPLEMENTED
;
3086 // Returns a state constant.
3087 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
3089 wxASSERT( GetWindow() != NULL
);
3093 // If a child, leave wxWidgets to call the function on the actual
3096 return wxACC_NOT_IMPLEMENTED
;
3098 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3099 return wxACC_NOT_IMPLEMENTED
;
3102 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3103 return wxACC_NOT_IMPLEMENTED
;
3106 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3107 return wxACC_NOT_IMPLEMENTED
;
3114 return wxACC_NOT_IMPLEMENTED
;
3118 // Returns a localized string representing the value for the object
3120 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3122 wxASSERT( GetWindow() != NULL
);
3126 return wxACC_NOT_IMPLEMENTED
;
3129 // Selects the object or child.
3130 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3132 wxASSERT( GetWindow() != NULL
);
3136 return wxACC_NOT_IMPLEMENTED
;
3139 // Gets the window with the keyboard focus.
3140 // If childId is 0 and child is NULL, no object in
3141 // this subhierarchy has the focus.
3142 // If this object has the focus, child should be 'this'.
3143 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3145 wxASSERT( GetWindow() != NULL
);
3149 return wxACC_NOT_IMPLEMENTED
;
3153 // Gets a variant representing the selected children
3155 // Acceptable values:
3156 // - a null variant (IsNull() returns true)
3157 // - a list variant (GetType() == wxT("list")
3158 // - an integer representing the selected child element,
3159 // or 0 if this object is selected (GetType() == wxT("long")
3160 // - a "void*" pointer to a wxAccessible child object
3161 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3163 wxASSERT( GetWindow() != NULL
);
3167 return wxACC_NOT_IMPLEMENTED
;
3169 #endif // wxUSE_VARIANT
3171 #endif // wxUSE_ACCESSIBILITY
3173 // ----------------------------------------------------------------------------
3175 // ----------------------------------------------------------------------------
3178 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3180 wxCoord widthTotal
) const
3182 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3184 x
= widthTotal
- x
- width
;