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/msgout.h"
42 #include "wx/statusbr.h"
43 #include "wx/toolbar.h"
44 #include "wx/dcclient.h"
45 #include "wx/scrolbar.h"
46 #include "wx/layout.h"
51 #if wxUSE_DRAG_AND_DROP
53 #endif // wxUSE_DRAG_AND_DROP
55 #if wxUSE_ACCESSIBILITY
56 #include "wx/access.h"
60 #include "wx/cshelp.h"
64 #include "wx/tooltip.h"
65 #endif // wxUSE_TOOLTIPS
71 #if wxUSE_SYSTEM_OPTIONS
72 #include "wx/sysopt.h"
75 #include "wx/platinfo.h"
76 #include "wx/private/window.h"
79 #include "wx/msw/wrapwin.h"
83 WXDLLIMPEXP_DATA_CORE(wxWindowList
) wxTopLevelWindows
;
87 wxMenu
*wxCurrentPopupMenu
= NULL
;
90 // ----------------------------------------------------------------------------
92 // ----------------------------------------------------------------------------
95 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
102 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
103 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
104 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
107 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
110 EVT_SIZE(wxWindowBase::InternalOnSize
)
113 // ============================================================================
114 // implementation of the common functionality of the wxWindow class
115 // ============================================================================
117 // ----------------------------------------------------------------------------
119 // ----------------------------------------------------------------------------
121 // the default initialization
122 wxWindowBase::wxWindowBase()
124 // no window yet, no parent nor children
126 m_windowId
= wxID_ANY
;
128 // no constraints on the minimal window size
130 m_maxWidth
= wxDefaultCoord
;
132 m_maxHeight
= wxDefaultCoord
;
134 // invalidiated cache value
135 m_bestSizeCache
= wxDefaultSize
;
137 // window are created enabled and visible by default
141 // the default event handler is just this window
142 m_eventHandler
= this;
146 m_windowValidator
= NULL
;
147 #endif // wxUSE_VALIDATORS
149 // the colours/fonts are default for now, so leave m_font,
150 // m_backgroundColour and m_foregroundColour uninitialized and set those
156 m_inheritFont
= false;
162 m_backgroundStyle
= wxBG_STYLE_ERASE
;
164 #if wxUSE_CONSTRAINTS
165 // no constraints whatsoever
166 m_constraints
= NULL
;
167 m_constraintsInvolvedIn
= NULL
;
168 #endif // wxUSE_CONSTRAINTS
170 m_windowSizer
= NULL
;
171 m_containingSizer
= NULL
;
172 m_autoLayout
= false;
174 #if wxUSE_DRAG_AND_DROP
176 #endif // wxUSE_DRAG_AND_DROP
180 #endif // wxUSE_TOOLTIPS
184 #endif // wxUSE_CARET
187 m_hasCustomPalette
= false;
188 #endif // wxUSE_PALETTE
190 #if wxUSE_ACCESSIBILITY
194 m_virtualSize
= wxDefaultSize
;
196 m_scrollHelper
= NULL
;
198 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
199 #if wxUSE_SYSTEM_OPTIONS
200 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
202 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
206 // Whether we're using the current theme for this window (wxGTK only for now)
207 m_themeEnabled
= false;
209 // This is set to true by SendDestroyEvent() which should be called by the
210 // most derived class to ensure that the destruction event is sent as soon
211 // as possible to allow its handlers to still see the undestroyed window
212 m_isBeingDeleted
= false;
217 // common part of window creation process
218 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
220 const wxPoint
& WXUNUSED(pos
),
223 const wxString
& name
)
225 // ids are limited to 16 bits under MSW so if you care about portability,
226 // it's not a good idea to use ids out of this range (and negative ids are
227 // reserved for wxWidgets own usage)
228 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767) ||
229 (id
>= wxID_AUTO_LOWEST
&& id
<= wxID_AUTO_HIGHEST
),
230 wxT("invalid id value") );
232 // generate a new id if the user doesn't care about it
233 if ( id
== wxID_ANY
)
235 m_windowId
= NewControlId();
237 else // valid id specified
242 // don't use SetWindowStyleFlag() here, this function should only be called
243 // to change the flag after creation as it tries to reflect the changes in
244 // flags by updating the window dynamically and we don't need this here
245 m_windowStyle
= style
;
247 // assume the user doesn't want this window to shrink beneath its initial
248 // size, this worked like this in wxWidgets 2.8 and before and generally
249 // often makes sense for child windows (for top level ones it definitely
250 // does not as the user should be able to resize the window)
252 // note that we can't use IsTopLevel() from ctor
253 if ( size
!= wxDefaultSize
&& !wxTopLevelWindows
.Find((wxWindow
*)this) )
262 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
267 const wxValidator
& wxVALIDATOR_PARAM(validator
),
268 const wxString
& name
)
270 if ( !CreateBase(parent
, id
, pos
, size
, style
, name
) )
274 SetValidator(validator
);
275 #endif // wxUSE_VALIDATORS
277 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
278 // have it too - like this it's possible to set it only in the top level
279 // dialog/frame and all children will inherit it by defult
280 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
282 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
288 bool wxWindowBase::ToggleWindowStyle(int flag
)
290 wxASSERT_MSG( flag
, wxT("flags with 0 value can't be toggled") );
293 long style
= GetWindowStyleFlag();
299 else // currently off
305 SetWindowStyleFlag(style
);
310 // ----------------------------------------------------------------------------
312 // ----------------------------------------------------------------------------
315 wxWindowBase::~wxWindowBase()
317 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
319 // FIXME if these 2 cases result from programming errors in the user code
320 // we should probably assert here instead of silently fixing them
322 // Just in case the window has been Closed, but we're then deleting
323 // immediately: don't leave dangling pointers.
324 wxPendingDelete
.DeleteObject(this);
326 // Just in case we've loaded a top-level window via LoadNativeDialog but
327 // we weren't a dialog class
328 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
330 // Any additional event handlers should be popped before the window is
331 // deleted as otherwise the last handler will be left with a dangling
332 // pointer to this window result in a difficult to diagnose crash later on.
333 wxASSERT_MSG( GetEventHandler() == this,
334 wxT("any pushed event handlers must have been removed") );
337 // The associated popup menu can still be alive, disassociate from it in
339 if ( wxCurrentPopupMenu
&& wxCurrentPopupMenu
->GetInvokingWindow() == this )
340 wxCurrentPopupMenu
->SetInvokingWindow(NULL
);
341 #endif // wxUSE_MENUS
343 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
345 // notify the parent about this window destruction
347 m_parent
->RemoveChild(this);
351 #endif // wxUSE_CARET
354 delete m_windowValidator
;
355 #endif // wxUSE_VALIDATORS
357 #if wxUSE_CONSTRAINTS
358 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
359 // at deleted windows as they delete themselves.
360 DeleteRelatedConstraints();
364 // This removes any dangling pointers to this window in other windows'
365 // constraintsInvolvedIn lists.
366 UnsetConstraints(m_constraints
);
367 delete m_constraints
;
368 m_constraints
= NULL
;
370 #endif // wxUSE_CONSTRAINTS
372 if ( m_containingSizer
)
373 m_containingSizer
->Detach( (wxWindow
*)this );
375 delete m_windowSizer
;
377 #if wxUSE_DRAG_AND_DROP
379 #endif // wxUSE_DRAG_AND_DROP
383 #endif // wxUSE_TOOLTIPS
385 #if wxUSE_ACCESSIBILITY
390 // NB: this has to be called unconditionally, because we don't know
391 // whether this window has associated help text or not
392 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
394 helpProvider
->RemoveHelp(this);
398 bool wxWindowBase::IsBeingDeleted() const
400 return m_isBeingDeleted
||
401 (!IsTopLevel() && m_parent
&& m_parent
->IsBeingDeleted());
404 void wxWindowBase::SendDestroyEvent()
406 if ( m_isBeingDeleted
)
408 // we could have been already called from a more derived class dtor,
409 // e.g. ~wxTLW calls us and so does ~wxWindow and the latter call
410 // should be simply ignored
414 m_isBeingDeleted
= true;
416 wxWindowDestroyEvent event
;
417 event
.SetEventObject(this);
418 event
.SetId(GetId());
419 GetEventHandler()->ProcessEvent(event
);
422 bool wxWindowBase::Destroy()
431 bool wxWindowBase::Close(bool force
)
433 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
434 event
.SetEventObject(this);
435 event
.SetCanVeto(!force
);
437 // return false if window wasn't closed because the application vetoed the
439 return HandleWindowEvent(event
) && !event
.GetVeto();
442 bool wxWindowBase::DestroyChildren()
444 wxWindowList::compatibility_iterator node
;
447 // we iterate until the list becomes empty
448 node
= GetChildren().GetFirst();
452 wxWindow
*child
= node
->GetData();
454 // note that we really want to delete it immediately so don't call the
455 // possible overridden Destroy() version which might not delete the
456 // child immediately resulting in problems with our (top level) child
457 // outliving its parent
458 child
->wxWindowBase::Destroy();
460 wxASSERT_MSG( !GetChildren().Find(child
),
461 wxT("child didn't remove itself using RemoveChild()") );
467 // ----------------------------------------------------------------------------
468 // size/position related methods
469 // ----------------------------------------------------------------------------
471 // centre the window with respect to its parent in either (or both) directions
472 void wxWindowBase::DoCentre(int dir
)
474 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
475 wxT("this method only implements centering child windows") );
477 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
480 // fits the window around the children
481 void wxWindowBase::Fit()
483 if ( !GetChildren().empty() )
485 SetSize(GetBestSize());
487 //else: do nothing if we have no children
490 // fits virtual size (ie. scrolled area etc.) around children
491 void wxWindowBase::FitInside()
493 if ( GetChildren().GetCount() > 0 )
495 SetVirtualSize( GetBestVirtualSize() );
499 // On Mac, scrollbars are explicitly children.
500 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
501 static bool wxHasRealChildren(const wxWindowBase
* win
)
503 int realChildCount
= 0;
505 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
507 node
= node
->GetNext() )
509 wxWindow
*win
= node
->GetData();
510 if ( !win
->IsTopLevel() && win
->IsShown()
512 && !win
->IsKindOf(CLASSINFO(wxScrollBar
))
517 return (realChildCount
> 0);
521 void wxWindowBase::InvalidateBestSize()
523 m_bestSizeCache
= wxDefaultSize
;
525 // parent's best size calculation may depend on its children's
526 // as long as child window we are in is not top level window itself
527 // (because the TLW size is never resized automatically)
528 // so let's invalidate it as well to be safe:
529 if (m_parent
&& !IsTopLevel())
530 m_parent
->InvalidateBestSize();
533 // return the size best suited for the current window
534 wxSize
wxWindowBase::DoGetBestSize() const
540 best
= m_windowSizer
->GetMinSize();
542 #if wxUSE_CONSTRAINTS
543 else if ( m_constraints
)
545 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
547 // our minimal acceptable size is such that all our windows fit inside
551 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
553 node
= node
->GetNext() )
555 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
558 // it's not normal that we have an unconstrained child, but
559 // what can we do about it?
563 int x
= c
->right
.GetValue(),
564 y
= c
->bottom
.GetValue();
572 // TODO: we must calculate the overlaps somehow, otherwise we
573 // will never return a size bigger than the current one :-(
576 best
= wxSize(maxX
, maxY
);
578 #endif // wxUSE_CONSTRAINTS
579 else if ( !GetChildren().empty()
580 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
581 && wxHasRealChildren(this)
585 // our minimal acceptable size is such that all our visible child
586 // windows fit inside
590 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
592 node
= node
->GetNext() )
594 wxWindow
*win
= node
->GetData();
595 if ( win
->IsTopLevel()
598 || wxDynamicCast(win
, wxStatusBar
)
599 #endif // wxUSE_STATUSBAR
602 // dialogs and frames lie in different top level windows -
603 // don't deal with them here; as for the status bars, they
604 // don't lie in the client area at all
609 win
->GetPosition(&wx
, &wy
);
611 // if the window hadn't been positioned yet, assume that it is in
613 if ( wx
== wxDefaultCoord
)
615 if ( wy
== wxDefaultCoord
)
618 win
->GetSize(&ww
, &wh
);
619 if ( wx
+ ww
> maxX
)
621 if ( wy
+ wh
> maxY
)
625 best
= wxSize(maxX
, maxY
);
627 else // ! has children
629 wxSize size
= GetMinSize();
630 if ( !size
.IsFullySpecified() )
632 // if the window doesn't define its best size we assume that it can
633 // be arbitrarily small -- usually this is not the case, of course,
634 // but we have no way to know what the limit is, it should really
635 // override DoGetBestClientSize() itself to tell us
636 size
.SetDefaults(wxSize(1, 1));
639 // return as-is, unadjusted by the client size difference.
643 // Add any difference between size and client size
644 wxSize diff
= GetSize() - GetClientSize();
645 best
.x
+= wxMax(0, diff
.x
);
646 best
.y
+= wxMax(0, diff
.y
);
651 // helper of GetWindowBorderSize(): as many ports don't implement support for
652 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
653 // fallbacks in this case
654 static int wxGetMetricOrDefault(wxSystemMetric what
, const wxWindowBase
* win
)
656 int rc
= wxSystemSettings::GetMetric(
657 what
, static_cast<wxWindow
*>(const_cast<wxWindowBase
*>(win
)));
664 // 2D border is by default 1 pixel wide
670 // 3D borders are by default 2 pixels
675 wxFAIL_MSG( wxT("unexpected wxGetMetricOrDefault() argument") );
683 wxSize
wxWindowBase::GetWindowBorderSize() const
687 switch ( GetBorder() )
690 // nothing to do, size is already (0, 0)
693 case wxBORDER_SIMPLE
:
694 case wxBORDER_STATIC
:
695 size
.x
= wxGetMetricOrDefault(wxSYS_BORDER_X
, this);
696 size
.y
= wxGetMetricOrDefault(wxSYS_BORDER_Y
, this);
699 case wxBORDER_SUNKEN
:
700 case wxBORDER_RAISED
:
701 size
.x
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X
, this),
702 wxGetMetricOrDefault(wxSYS_BORDER_X
, this));
703 size
.y
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y
, this),
704 wxGetMetricOrDefault(wxSYS_BORDER_Y
, this));
707 case wxBORDER_DOUBLE
:
708 size
.x
= wxGetMetricOrDefault(wxSYS_EDGE_X
, this) +
709 wxGetMetricOrDefault(wxSYS_BORDER_X
, this);
710 size
.y
= wxGetMetricOrDefault(wxSYS_EDGE_Y
, this) +
711 wxGetMetricOrDefault(wxSYS_BORDER_Y
, this);
715 wxFAIL_MSG(wxT("Unknown border style."));
719 // we have borders on both sides
723 wxSize
wxWindowBase::GetEffectiveMinSize() const
725 // merge the best size with the min size, giving priority to the min size
726 wxSize min
= GetMinSize();
728 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
730 wxSize best
= GetBestSize();
731 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
732 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
738 wxSize
wxWindowBase::DoGetBorderSize() const
740 // there is one case in which we can implement it for all ports easily:
741 // do it as some classes used by both wxUniv and native ports (e.g.
742 // wxGenericStaticText) do override DoGetBestClientSize() and so this
743 // method must work for them and that ensures that it does, at least in
745 if ( GetBorder() == wxBORDER_NONE
)
748 wxFAIL_MSG( "must be overridden if called" );
750 return wxDefaultSize
;
753 wxSize
wxWindowBase::GetBestSize() const
755 if ( !m_windowSizer
&& m_bestSizeCache
.IsFullySpecified() )
756 return m_bestSizeCache
;
758 // call DoGetBestClientSize() first, if a derived class overrides it wants
760 wxSize size
= DoGetBestClientSize();
761 if ( size
!= wxDefaultSize
)
763 size
+= DoGetBorderSize();
769 return DoGetBestSize();
772 void wxWindowBase::SetMinSize(const wxSize
& minSize
)
774 m_minWidth
= minSize
.x
;
775 m_minHeight
= minSize
.y
;
778 void wxWindowBase::SetMaxSize(const wxSize
& maxSize
)
780 m_maxWidth
= maxSize
.x
;
781 m_maxHeight
= maxSize
.y
;
784 void wxWindowBase::SetInitialSize(const wxSize
& size
)
786 // Set the min size to the size passed in. This will usually either be
787 // wxDefaultSize or the size passed to this window's ctor/Create function.
790 // Merge the size with the best size if needed
791 wxSize best
= GetEffectiveMinSize();
793 // If the current size doesn't match then change it
794 if (GetSize() != best
)
799 // by default the origin is not shifted
800 wxPoint
wxWindowBase::GetClientAreaOrigin() const
805 wxSize
wxWindowBase::ClientToWindowSize(const wxSize
& size
) const
807 const wxSize
diff(GetSize() - GetClientSize());
809 return wxSize(size
.x
== -1 ? -1 : size
.x
+ diff
.x
,
810 size
.y
== -1 ? -1 : size
.y
+ diff
.y
);
813 wxSize
wxWindowBase::WindowToClientSize(const wxSize
& size
) const
815 const wxSize
diff(GetSize() - GetClientSize());
817 return wxSize(size
.x
== -1 ? -1 : size
.x
- diff
.x
,
818 size
.y
== -1 ? -1 : size
.y
- diff
.y
);
821 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
823 if ( m_windowVariant
!= variant
)
825 m_windowVariant
= variant
;
827 DoSetWindowVariant(variant
);
831 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
833 // adjust the font height to correspond to our new variant (notice that
834 // we're only called if something really changed)
835 wxFont font
= GetFont();
836 int size
= font
.GetPointSize();
839 case wxWINDOW_VARIANT_NORMAL
:
842 case wxWINDOW_VARIANT_SMALL
:
847 case wxWINDOW_VARIANT_MINI
:
852 case wxWINDOW_VARIANT_LARGE
:
858 wxFAIL_MSG(wxT("unexpected window variant"));
862 font
.SetPointSize(size
);
866 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
868 int WXUNUSED(incW
), int WXUNUSED(incH
) )
870 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
871 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
872 wxT("min width/height must be less than max width/height!") );
881 #if WXWIN_COMPATIBILITY_2_8
882 void wxWindowBase::SetVirtualSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
),
883 int WXUNUSED(maxW
), int WXUNUSED(maxH
))
887 void wxWindowBase::SetVirtualSizeHints(const wxSize
& WXUNUSED(minsize
),
888 const wxSize
& WXUNUSED(maxsize
))
891 #endif // WXWIN_COMPATIBILITY_2_8
893 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
895 m_virtualSize
= wxSize(x
, y
);
898 wxSize
wxWindowBase::DoGetVirtualSize() const
900 // we should use the entire client area so if it is greater than our
901 // virtual size, expand it to fit (otherwise if the window is big enough we
902 // wouldn't be using parts of it)
903 wxSize size
= GetClientSize();
904 if ( m_virtualSize
.x
> size
.x
)
905 size
.x
= m_virtualSize
.x
;
907 if ( m_virtualSize
.y
>= size
.y
)
908 size
.y
= m_virtualSize
.y
;
913 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
915 // screen position is the same as (0, 0) in client coords for non TLWs (and
916 // TLWs override this method)
922 ClientToScreen(x
, y
);
925 void wxWindowBase::SendSizeEvent(int flags
)
927 wxSizeEvent
event(GetSize(), GetId());
928 event
.SetEventObject(this);
929 if ( flags
& wxSEND_EVENT_POST
)
930 wxPostEvent(this, event
);
932 HandleWindowEvent(event
);
935 void wxWindowBase::SendSizeEventToParent(int flags
)
937 wxWindow
* const parent
= GetParent();
938 if ( parent
&& !parent
->IsBeingDeleted() )
939 parent
->SendSizeEvent(flags
);
942 bool wxWindowBase::HasScrollbar(int orient
) const
944 // if scrolling in the given direction is disabled, we can't have the
945 // corresponding scrollbar no matter what
946 if ( !CanScroll(orient
) )
949 const wxSize sizeVirt
= GetVirtualSize();
950 const wxSize sizeClient
= GetClientSize();
952 return orient
== wxHORIZONTAL
? sizeVirt
.x
> sizeClient
.x
953 : sizeVirt
.y
> sizeClient
.y
;
956 // ----------------------------------------------------------------------------
957 // show/hide/enable/disable the window
958 // ----------------------------------------------------------------------------
960 bool wxWindowBase::Show(bool show
)
962 if ( show
!= m_isShown
)
974 bool wxWindowBase::IsEnabled() const
976 return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
979 void wxWindowBase::NotifyWindowOnEnableChange(bool enabled
)
981 #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
983 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
987 // If we are top-level then the logic doesn't apply - otherwise
988 // showing a modal dialog would result in total greying out (and ungreying
989 // out later) of everything which would be really ugly
993 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
995 node
= node
->GetNext() )
997 wxWindowBase
* const child
= node
->GetData();
998 if ( !child
->IsTopLevel() && child
->IsThisEnabled() )
999 child
->NotifyWindowOnEnableChange(enabled
);
1003 bool wxWindowBase::Enable(bool enable
)
1005 if ( enable
== IsThisEnabled() )
1008 m_isEnabled
= enable
;
1010 #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
1012 #else // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
1013 wxWindowBase
* const parent
= GetParent();
1014 if( !IsTopLevel() && parent
&& !parent
->IsEnabled() )
1018 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
1020 NotifyWindowOnEnableChange(enable
);
1025 bool wxWindowBase::IsShownOnScreen() const
1027 // A window is shown on screen if it itself is shown and so are all its
1028 // parents. But if a window is toplevel one, then its always visible on
1029 // screen if IsShown() returns true, even if it has a hidden parent.
1031 (IsTopLevel() || GetParent() == NULL
|| GetParent()->IsShownOnScreen());
1034 // ----------------------------------------------------------------------------
1036 // ----------------------------------------------------------------------------
1038 bool wxWindowBase::IsTopLevel() const
1043 // ----------------------------------------------------------------------------
1045 // ----------------------------------------------------------------------------
1047 void wxWindowBase::Freeze()
1049 if ( !m_freezeCount
++ )
1051 // physically freeze this window:
1054 // and recursively freeze all children:
1055 for ( wxWindowList::iterator i
= GetChildren().begin();
1056 i
!= GetChildren().end(); ++i
)
1058 wxWindow
*child
= *i
;
1059 if ( child
->IsTopLevel() )
1067 void wxWindowBase::Thaw()
1069 wxASSERT_MSG( m_freezeCount
, "Thaw() without matching Freeze()" );
1071 if ( !--m_freezeCount
)
1073 // recursively thaw all children:
1074 for ( wxWindowList::iterator i
= GetChildren().begin();
1075 i
!= GetChildren().end(); ++i
)
1077 wxWindow
*child
= *i
;
1078 if ( child
->IsTopLevel() )
1084 // physically thaw this window:
1089 // ----------------------------------------------------------------------------
1090 // reparenting the window
1091 // ----------------------------------------------------------------------------
1093 void wxWindowBase::AddChild(wxWindowBase
*child
)
1095 wxCHECK_RET( child
, wxT("can't add a NULL child") );
1097 // this should never happen and it will lead to a crash later if it does
1098 // because RemoveChild() will remove only one node from the children list
1099 // and the other(s) one(s) will be left with dangling pointers in them
1100 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), wxT("AddChild() called twice") );
1102 GetChildren().Append((wxWindow
*)child
);
1103 child
->SetParent(this);
1105 // adding a child while frozen will assert when thawed, so freeze it as if
1106 // it had been already present when we were frozen
1107 if ( IsFrozen() && !child
->IsTopLevel() )
1111 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
1113 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
1115 // removing a child while frozen may result in permanently frozen window
1116 // if used e.g. from Reparent(), so thaw it
1118 // NB: IsTopLevel() doesn't return true any more when a TLW child is being
1119 // removed from its ~wxWindowBase, so check for IsBeingDeleted() too
1120 if ( IsFrozen() && !child
->IsBeingDeleted() && !child
->IsTopLevel() )
1123 GetChildren().DeleteObject((wxWindow
*)child
);
1124 child
->SetParent(NULL
);
1127 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
1129 wxWindow
*oldParent
= GetParent();
1130 if ( newParent
== oldParent
)
1136 const bool oldEnabledState
= IsEnabled();
1138 // unlink this window from the existing parent.
1141 oldParent
->RemoveChild(this);
1145 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
1148 // add it to the new one
1151 newParent
->AddChild(this);
1155 wxTopLevelWindows
.Append((wxWindow
*)this);
1158 // We need to notify window (and its subwindows) if by changing the parent
1159 // we also change our enabled/disabled status.
1160 const bool newEnabledState
= IsEnabled();
1161 if ( newEnabledState
!= oldEnabledState
)
1163 NotifyWindowOnEnableChange(newEnabledState
);
1169 // ----------------------------------------------------------------------------
1170 // event handler stuff
1171 // ----------------------------------------------------------------------------
1173 void wxWindowBase::SetEventHandler(wxEvtHandler
*handler
)
1175 wxCHECK_RET(handler
!= NULL
, "SetEventHandler(NULL) called");
1177 m_eventHandler
= handler
;
1180 void wxWindowBase::SetNextHandler(wxEvtHandler
*WXUNUSED(handler
))
1182 // disable wxEvtHandler chain mechanism for wxWindows:
1183 // wxWindow uses its own stack mechanism which doesn't mix well with wxEvtHandler's one
1185 wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
1187 void wxWindowBase::SetPreviousHandler(wxEvtHandler
*WXUNUSED(handler
))
1189 // we can't simply wxFAIL here as in SetNextHandler: in fact the last
1190 // handler of our stack when is destroyed will be Unlink()ed and thus
1191 // will call this function to update the pointer of this window...
1193 //wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
1196 void wxWindowBase::PushEventHandler(wxEvtHandler
*handlerToPush
)
1198 wxCHECK_RET( handlerToPush
!= NULL
, "PushEventHandler(NULL) called" );
1200 // the new handler is going to be part of the wxWindow stack of event handlers:
1201 // it can't be part also of an event handler double-linked chain:
1202 wxASSERT_MSG(handlerToPush
->IsUnlinked(),
1203 "The handler being pushed in the wxWindow stack shouldn't be part of "
1204 "a wxEvtHandler chain; call Unlink() on it first");
1206 wxEvtHandler
*handlerOld
= GetEventHandler();
1207 wxCHECK_RET( handlerOld
, "an old event handler is NULL?" );
1209 // now use wxEvtHandler double-linked list to implement a stack:
1210 handlerToPush
->SetNextHandler(handlerOld
);
1212 if (handlerOld
!= this)
1213 handlerOld
->SetPreviousHandler(handlerToPush
);
1215 SetEventHandler(handlerToPush
);
1218 // final checks of the operations done above:
1219 wxASSERT_MSG( handlerToPush
->GetPreviousHandler() == NULL
,
1220 "the first handler of the wxWindow stack should "
1221 "have no previous handlers set" );
1222 wxASSERT_MSG( handlerToPush
->GetNextHandler() != NULL
,
1223 "the first handler of the wxWindow stack should "
1224 "have non-NULL next handler" );
1226 wxEvtHandler
* pLast
= handlerToPush
;
1227 while ( pLast
&& pLast
!= this )
1228 pLast
= pLast
->GetNextHandler();
1229 wxASSERT_MSG( pLast
->GetNextHandler() == NULL
,
1230 "the last handler of the wxWindow stack should "
1231 "have this window as next handler" );
1232 #endif // wxDEBUG_LEVEL
1235 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
1237 // we need to pop the wxWindow stack, i.e. we need to remove the first handler
1239 wxEvtHandler
*firstHandler
= GetEventHandler();
1240 wxCHECK_MSG( firstHandler
!= NULL
, NULL
, "wxWindow cannot have a NULL event handler" );
1241 wxCHECK_MSG( firstHandler
!= this, NULL
, "cannot pop the wxWindow itself" );
1242 wxCHECK_MSG( firstHandler
->GetPreviousHandler() == NULL
, NULL
,
1243 "the first handler of the wxWindow stack should have no previous handlers set" );
1245 wxEvtHandler
*secondHandler
= firstHandler
->GetNextHandler();
1246 wxCHECK_MSG( secondHandler
!= NULL
, NULL
,
1247 "the first handler of the wxWindow stack should have non-NULL next handler" );
1249 firstHandler
->SetNextHandler(NULL
);
1250 secondHandler
->SetPreviousHandler(NULL
);
1252 // now firstHandler is completely unlinked; set secondHandler as the new window event handler
1253 SetEventHandler(secondHandler
);
1255 if ( deleteHandler
)
1257 delete firstHandler
;
1258 firstHandler
= NULL
;
1261 return firstHandler
;
1264 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handlerToRemove
)
1266 wxCHECK_MSG( handlerToRemove
!= NULL
, false, "RemoveEventHandler(NULL) called" );
1267 wxCHECK_MSG( handlerToRemove
!= this, false, "Cannot remove the window itself" );
1269 if (handlerToRemove
== GetEventHandler())
1271 // removing the first event handler is equivalent to "popping" the stack
1272 PopEventHandler(false);
1276 // NOTE: the wxWindow event handler list is always terminated with "this" handler
1277 wxEvtHandler
*handlerCur
= GetEventHandler()->GetNextHandler();
1278 while ( handlerCur
!= this && handlerCur
)
1280 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
1282 if ( handlerCur
== handlerToRemove
)
1284 handlerCur
->Unlink();
1286 wxASSERT_MSG( handlerCur
!= GetEventHandler(),
1287 "the case Remove == Pop should was already handled" );
1291 handlerCur
= handlerNext
;
1294 wxFAIL_MSG( wxT("where has the event handler gone?") );
1299 bool wxWindowBase::HandleWindowEvent(wxEvent
& event
) const
1301 // SafelyProcessEvent() will handle exceptions nicely
1302 return GetEventHandler()->SafelyProcessEvent(event
);
1305 // ----------------------------------------------------------------------------
1306 // colours, fonts &c
1307 // ----------------------------------------------------------------------------
1309 void wxWindowBase::InheritAttributes()
1311 const wxWindowBase
* const parent
= GetParent();
1315 // we only inherit attributes which had been explicitly set for the parent
1316 // which ensures that this only happens if the user really wants it and
1317 // not by default which wouldn't make any sense in modern GUIs where the
1318 // controls don't all use the same fonts (nor colours)
1319 if ( parent
->m_inheritFont
&& !m_hasFont
)
1320 SetFont(parent
->GetFont());
1322 // in addition, there is a possibility to explicitly forbid inheriting
1323 // colours at each class level by overriding ShouldInheritColours()
1324 if ( ShouldInheritColours() )
1326 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1327 SetForegroundColour(parent
->GetForegroundColour());
1329 // inheriting (solid) background colour is wrong as it totally breaks
1330 // any kind of themed backgrounds
1332 // instead, the controls should use the same background as their parent
1333 // (ideally by not drawing it at all)
1335 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1336 SetBackgroundColour(parent
->GetBackgroundColour());
1341 /* static */ wxVisualAttributes
1342 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1344 // it is important to return valid values for all attributes from here,
1345 // GetXXX() below rely on this
1346 wxVisualAttributes attrs
;
1347 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1348 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1350 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1351 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1352 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1353 // colour on other platforms.
1355 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1356 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1358 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1363 wxColour
wxWindowBase::GetBackgroundColour() const
1365 if ( !m_backgroundColour
.IsOk() )
1367 wxASSERT_MSG( !m_hasBgCol
, wxT("we have invalid explicit bg colour?") );
1369 // get our default background colour
1370 wxColour colBg
= GetDefaultAttributes().colBg
;
1372 // we must return some valid colour to avoid redoing this every time
1373 // and also to avoid surprising the applications written for older
1374 // wxWidgets versions where GetBackgroundColour() always returned
1375 // something -- so give them something even if it doesn't make sense
1376 // for this window (e.g. it has a themed background)
1378 colBg
= GetClassDefaultAttributes().colBg
;
1383 return m_backgroundColour
;
1386 wxColour
wxWindowBase::GetForegroundColour() const
1388 // logic is the same as above
1389 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1391 wxColour colFg
= GetDefaultAttributes().colFg
;
1393 if ( !colFg
.IsOk() )
1394 colFg
= GetClassDefaultAttributes().colFg
;
1399 return m_foregroundColour
;
1402 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1404 if ( colour
== m_backgroundColour
)
1407 m_hasBgCol
= colour
.IsOk();
1409 m_inheritBgCol
= m_hasBgCol
;
1410 m_backgroundColour
= colour
;
1411 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1415 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1417 if (colour
== m_foregroundColour
)
1420 m_hasFgCol
= colour
.IsOk();
1421 m_inheritFgCol
= m_hasFgCol
;
1422 m_foregroundColour
= colour
;
1423 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1427 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1429 // setting an invalid cursor is ok, it means that we don't have any special
1431 if ( m_cursor
.IsSameAs(cursor
) )
1442 wxFont
wxWindowBase::GetFont() const
1444 // logic is the same as in GetBackgroundColour()
1445 if ( !m_font
.IsOk() )
1447 wxASSERT_MSG( !m_hasFont
, wxT("we have invalid explicit font?") );
1449 wxFont font
= GetDefaultAttributes().font
;
1451 font
= GetClassDefaultAttributes().font
;
1459 bool wxWindowBase::SetFont(const wxFont
& font
)
1461 if ( font
== m_font
)
1468 m_hasFont
= font
.IsOk();
1469 m_inheritFont
= m_hasFont
;
1471 InvalidateBestSize();
1478 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1480 m_hasCustomPalette
= true;
1483 // VZ: can anyone explain me what do we do here?
1484 wxWindowDC
d((wxWindow
*) this);
1488 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1490 wxWindow
*win
= (wxWindow
*)this;
1491 while ( win
&& !win
->HasCustomPalette() )
1493 win
= win
->GetParent();
1499 #endif // wxUSE_PALETTE
1502 void wxWindowBase::SetCaret(wxCaret
*caret
)
1513 wxASSERT_MSG( m_caret
->GetWindow() == this,
1514 wxT("caret should be created associated to this window") );
1517 #endif // wxUSE_CARET
1519 #if wxUSE_VALIDATORS
1520 // ----------------------------------------------------------------------------
1522 // ----------------------------------------------------------------------------
1524 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1526 if ( m_windowValidator
)
1527 delete m_windowValidator
;
1529 m_windowValidator
= (wxValidator
*)validator
.Clone();
1531 if ( m_windowValidator
)
1532 m_windowValidator
->SetWindow(this);
1534 #endif // wxUSE_VALIDATORS
1536 // ----------------------------------------------------------------------------
1537 // update region stuff
1538 // ----------------------------------------------------------------------------
1540 wxRect
wxWindowBase::GetUpdateClientRect() const
1542 wxRegion rgnUpdate
= GetUpdateRegion();
1543 rgnUpdate
.Intersect(GetClientRect());
1544 wxRect rectUpdate
= rgnUpdate
.GetBox();
1545 wxPoint ptOrigin
= GetClientAreaOrigin();
1546 rectUpdate
.x
-= ptOrigin
.x
;
1547 rectUpdate
.y
-= ptOrigin
.y
;
1552 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1554 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1557 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1559 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1562 void wxWindowBase::ClearBackground()
1564 // wxGTK uses its own version, no need to add never used code
1566 wxClientDC
dc((wxWindow
*)this);
1567 wxBrush
brush(GetBackgroundColour(), wxBRUSHSTYLE_SOLID
);
1568 dc
.SetBackground(brush
);
1573 // ----------------------------------------------------------------------------
1574 // find child window by id or name
1575 // ----------------------------------------------------------------------------
1577 wxWindow
*wxWindowBase::FindWindow(long id
) const
1579 if ( id
== m_windowId
)
1580 return (wxWindow
*)this;
1582 wxWindowBase
*res
= NULL
;
1583 wxWindowList::compatibility_iterator node
;
1584 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1586 wxWindowBase
*child
= node
->GetData();
1587 res
= child
->FindWindow( id
);
1590 return (wxWindow
*)res
;
1593 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1595 if ( name
== m_windowName
)
1596 return (wxWindow
*)this;
1598 wxWindowBase
*res
= NULL
;
1599 wxWindowList::compatibility_iterator node
;
1600 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1602 wxWindow
*child
= node
->GetData();
1603 res
= child
->FindWindow(name
);
1606 return (wxWindow
*)res
;
1610 // find any window by id or name or label: If parent is non-NULL, look through
1611 // children for a label or title matching the specified string. If NULL, look
1612 // through all top-level windows.
1614 // to avoid duplicating code we reuse the same helper function but with
1615 // different comparators
1617 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1618 const wxString
& label
, long id
);
1621 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1624 return win
->GetLabel() == label
;
1628 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1631 return win
->GetName() == label
;
1635 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1638 return win
->GetId() == id
;
1641 // recursive helper for the FindWindowByXXX() functions
1643 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1644 const wxString
& label
,
1646 wxFindWindowCmp cmp
)
1650 // see if this is the one we're looking for
1651 if ( (*cmp
)(parent
, label
, id
) )
1652 return (wxWindow
*)parent
;
1654 // It wasn't, so check all its children
1655 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1657 node
= node
->GetNext() )
1659 // recursively check each child
1660 wxWindow
*win
= (wxWindow
*)node
->GetData();
1661 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1671 // helper for FindWindowByXXX()
1673 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1674 const wxString
& label
,
1676 wxFindWindowCmp cmp
)
1680 // just check parent and all its children
1681 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1684 // start at very top of wx's windows
1685 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1687 node
= node
->GetNext() )
1689 // recursively check each window & its children
1690 wxWindow
*win
= node
->GetData();
1691 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1701 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1703 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1708 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1710 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1714 // fall back to the label
1715 win
= FindWindowByLabel(title
, parent
);
1723 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1725 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1728 // ----------------------------------------------------------------------------
1729 // dialog oriented functions
1730 // ----------------------------------------------------------------------------
1732 void wxWindowBase::MakeModal(bool modal
)
1734 // Disable all other windows
1737 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1740 wxWindow
*win
= node
->GetData();
1742 win
->Enable(!modal
);
1744 node
= node
->GetNext();
1749 bool wxWindowBase::Validate()
1751 #if wxUSE_VALIDATORS
1752 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1754 wxWindowList::compatibility_iterator node
;
1755 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1757 wxWindowBase
*child
= node
->GetData();
1758 wxValidator
*validator
= child
->GetValidator();
1759 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1764 if ( recurse
&& !child
->Validate() )
1769 #endif // wxUSE_VALIDATORS
1774 bool wxWindowBase::TransferDataToWindow()
1776 #if wxUSE_VALIDATORS
1777 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1779 wxWindowList::compatibility_iterator node
;
1780 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1782 wxWindowBase
*child
= node
->GetData();
1783 wxValidator
*validator
= child
->GetValidator();
1784 if ( validator
&& !validator
->TransferToWindow() )
1786 wxLogWarning(_("Could not transfer data to window"));
1788 wxLog::FlushActive();
1796 if ( !child
->TransferDataToWindow() )
1798 // warning already given
1803 #endif // wxUSE_VALIDATORS
1808 bool wxWindowBase::TransferDataFromWindow()
1810 #if wxUSE_VALIDATORS
1811 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1813 wxWindowList::compatibility_iterator node
;
1814 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1816 wxWindow
*child
= node
->GetData();
1817 wxValidator
*validator
= child
->GetValidator();
1818 if ( validator
&& !validator
->TransferFromWindow() )
1820 // nop warning here because the application is supposed to give
1821 // one itself - we don't know here what might have gone wrongly
1828 if ( !child
->TransferDataFromWindow() )
1830 // warning already given
1835 #endif // wxUSE_VALIDATORS
1840 void wxWindowBase::InitDialog()
1842 wxInitDialogEvent
event(GetId());
1843 event
.SetEventObject( this );
1844 GetEventHandler()->ProcessEvent(event
);
1847 // ----------------------------------------------------------------------------
1848 // context-sensitive help support
1849 // ----------------------------------------------------------------------------
1853 // associate this help text with this window
1854 void wxWindowBase::SetHelpText(const wxString
& text
)
1856 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1859 helpProvider
->AddHelp(this, text
);
1863 #if WXWIN_COMPATIBILITY_2_8
1864 // associate this help text with all windows with the same id as this
1866 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1868 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1871 helpProvider
->AddHelp(GetId(), text
);
1874 #endif // WXWIN_COMPATIBILITY_2_8
1876 // get the help string associated with this window (may be empty)
1877 // default implementation forwards calls to the help provider
1879 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1880 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1883 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1886 text
= helpProvider
->GetHelp(this);
1892 // show help for this window
1893 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1895 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1898 wxPoint pos
= event
.GetPosition();
1899 const wxHelpEvent::Origin origin
= event
.GetOrigin();
1900 if ( origin
== wxHelpEvent::Origin_Keyboard
)
1902 // if the help event was generated from keyboard it shouldn't
1903 // appear at the mouse position (which is still the only position
1904 // associated with help event) if the mouse is far away, although
1905 // we still do use the mouse position if it's over the window
1906 // because we suppose the user looks approximately at the mouse
1907 // already and so it would be more convenient than showing tooltip
1908 // at some arbitrary position which can be quite far from it
1909 const wxRect rectClient
= GetClientRect();
1910 if ( !rectClient
.Contains(ScreenToClient(pos
)) )
1912 // position help slightly under and to the right of this window
1913 pos
= ClientToScreen(wxPoint(
1915 rectClient
.height
+ GetCharHeight()
1920 if ( helpProvider
->ShowHelpAtPoint(this, pos
, origin
) )
1922 // skip the event.Skip() below
1930 #endif // wxUSE_HELP
1932 // ----------------------------------------------------------------------------
1934 // ----------------------------------------------------------------------------
1938 wxString
wxWindowBase::GetToolTipText() const
1940 return m_tooltip
? m_tooltip
->GetTip() : wxString();
1943 void wxWindowBase::SetToolTip( const wxString
&tip
)
1945 // don't create the new tooltip if we already have one
1948 m_tooltip
->SetTip( tip
);
1952 SetToolTip( new wxToolTip( tip
) );
1955 // setting empty tooltip text does not remove the tooltip any more - use
1956 // SetToolTip(NULL) for this
1959 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1961 if ( m_tooltip
!= tooltip
)
1966 m_tooltip
= tooltip
;
1970 #endif // wxUSE_TOOLTIPS
1972 // ----------------------------------------------------------------------------
1973 // constraints and sizers
1974 // ----------------------------------------------------------------------------
1976 #if wxUSE_CONSTRAINTS
1978 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1980 if ( m_constraints
)
1982 UnsetConstraints(m_constraints
);
1983 delete m_constraints
;
1985 m_constraints
= constraints
;
1986 if ( m_constraints
)
1988 // Make sure other windows know they're part of a 'meaningful relationship'
1989 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1990 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1991 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1992 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1993 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1994 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1995 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1996 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1997 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1998 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1999 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
2000 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
2001 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
2002 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
2003 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
2004 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
2008 // This removes any dangling pointers to this window in other windows'
2009 // constraintsInvolvedIn lists.
2010 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
2014 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
2015 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
2016 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
2017 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
2018 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
2019 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
2020 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
2021 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
2022 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
2023 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
2024 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
2025 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
2026 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
2027 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
2028 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
2029 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
2033 // Back-pointer to other windows we're involved with, so if we delete this
2034 // window, we must delete any constraints we're involved with.
2035 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
2037 if ( !m_constraintsInvolvedIn
)
2038 m_constraintsInvolvedIn
= new wxWindowList
;
2039 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
2040 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
2043 // REMOVE back-pointer to other windows we're involved with.
2044 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
2046 if ( m_constraintsInvolvedIn
)
2047 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
2050 // Reset any constraints that mention this window
2051 void wxWindowBase::DeleteRelatedConstraints()
2053 if ( m_constraintsInvolvedIn
)
2055 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
2058 wxWindow
*win
= node
->GetData();
2059 wxLayoutConstraints
*constr
= win
->GetConstraints();
2061 // Reset any constraints involving this window
2064 constr
->left
.ResetIfWin(this);
2065 constr
->top
.ResetIfWin(this);
2066 constr
->right
.ResetIfWin(this);
2067 constr
->bottom
.ResetIfWin(this);
2068 constr
->width
.ResetIfWin(this);
2069 constr
->height
.ResetIfWin(this);
2070 constr
->centreX
.ResetIfWin(this);
2071 constr
->centreY
.ResetIfWin(this);
2074 wxWindowList::compatibility_iterator next
= node
->GetNext();
2075 m_constraintsInvolvedIn
->Erase(node
);
2079 delete m_constraintsInvolvedIn
;
2080 m_constraintsInvolvedIn
= NULL
;
2084 #endif // wxUSE_CONSTRAINTS
2086 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
2088 if ( sizer
== m_windowSizer
)
2091 if ( m_windowSizer
)
2093 m_windowSizer
->SetContainingWindow(NULL
);
2096 delete m_windowSizer
;
2099 m_windowSizer
= sizer
;
2100 if ( m_windowSizer
)
2102 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
2105 SetAutoLayout(m_windowSizer
!= NULL
);
2108 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
2110 SetSizer( sizer
, deleteOld
);
2111 sizer
->SetSizeHints( (wxWindow
*) this );
2115 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
2117 // adding a window to a sizer twice is going to result in fatal and
2118 // hard to debug problems later because when deleting the second
2119 // associated wxSizerItem we're going to dereference a dangling
2120 // pointer; so try to detect this as early as possible
2121 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
2122 wxT("Adding a window to the same sizer twice?") );
2124 m_containingSizer
= sizer
;
2127 #if wxUSE_CONSTRAINTS
2129 void wxWindowBase::SatisfyConstraints()
2131 wxLayoutConstraints
*constr
= GetConstraints();
2132 bool wasOk
= constr
&& constr
->AreSatisfied();
2134 ResetConstraints(); // Mark all constraints as unevaluated
2138 // if we're a top level panel (i.e. our parent is frame/dialog), our
2139 // own constraints will never be satisfied any more unless we do it
2143 while ( noChanges
> 0 )
2145 LayoutPhase1(&noChanges
);
2149 LayoutPhase2(&noChanges
);
2152 #endif // wxUSE_CONSTRAINTS
2154 bool wxWindowBase::Layout()
2156 // If there is a sizer, use it instead of the constraints
2160 GetVirtualSize(&w
, &h
);
2161 GetSizer()->SetDimension( 0, 0, w
, h
);
2163 #if wxUSE_CONSTRAINTS
2166 SatisfyConstraints(); // Find the right constraints values
2167 SetConstraintSizes(); // Recursively set the real window sizes
2174 void wxWindowBase::InternalOnSize(wxSizeEvent
& event
)
2176 if ( GetAutoLayout() )
2182 #if wxUSE_CONSTRAINTS
2184 // first phase of the constraints evaluation: set our own constraints
2185 bool wxWindowBase::LayoutPhase1(int *noChanges
)
2187 wxLayoutConstraints
*constr
= GetConstraints();
2189 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
2192 // second phase: set the constraints for our children
2193 bool wxWindowBase::LayoutPhase2(int *noChanges
)
2200 // Layout grand children
2206 // Do a phase of evaluating child constraints
2207 bool wxWindowBase::DoPhase(int phase
)
2209 // the list containing the children for which the constraints are already
2211 wxWindowList succeeded
;
2213 // the max number of iterations we loop before concluding that we can't set
2215 static const int maxIterations
= 500;
2217 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
2221 // loop over all children setting their constraints
2222 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2224 node
= node
->GetNext() )
2226 wxWindow
*child
= node
->GetData();
2227 if ( child
->IsTopLevel() )
2229 // top level children are not inside our client area
2233 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
2235 // this one is either already ok or nothing we can do about it
2239 int tempNoChanges
= 0;
2240 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
2241 : child
->LayoutPhase2(&tempNoChanges
);
2242 noChanges
+= tempNoChanges
;
2246 succeeded
.Append(child
);
2252 // constraints are set
2260 void wxWindowBase::ResetConstraints()
2262 wxLayoutConstraints
*constr
= GetConstraints();
2265 constr
->left
.SetDone(false);
2266 constr
->top
.SetDone(false);
2267 constr
->right
.SetDone(false);
2268 constr
->bottom
.SetDone(false);
2269 constr
->width
.SetDone(false);
2270 constr
->height
.SetDone(false);
2271 constr
->centreX
.SetDone(false);
2272 constr
->centreY
.SetDone(false);
2275 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2278 wxWindow
*win
= node
->GetData();
2279 if ( !win
->IsTopLevel() )
2280 win
->ResetConstraints();
2281 node
= node
->GetNext();
2285 // Need to distinguish between setting the 'fake' size for windows and sizers,
2286 // and setting the real values.
2287 void wxWindowBase::SetConstraintSizes(bool recurse
)
2289 wxLayoutConstraints
*constr
= GetConstraints();
2290 if ( constr
&& constr
->AreSatisfied() )
2292 int x
= constr
->left
.GetValue();
2293 int y
= constr
->top
.GetValue();
2294 int w
= constr
->width
.GetValue();
2295 int h
= constr
->height
.GetValue();
2297 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
2298 (constr
->height
.GetRelationship() != wxAsIs
) )
2300 SetSize(x
, y
, w
, h
);
2304 // If we don't want to resize this window, just move it...
2310 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
2311 GetClassInfo()->GetClassName(),
2317 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2320 wxWindow
*win
= node
->GetData();
2321 if ( !win
->IsTopLevel() && win
->GetConstraints() )
2322 win
->SetConstraintSizes();
2323 node
= node
->GetNext();
2328 // Only set the size/position of the constraint (if any)
2329 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
2331 wxLayoutConstraints
*constr
= GetConstraints();
2334 if ( x
!= wxDefaultCoord
)
2336 constr
->left
.SetValue(x
);
2337 constr
->left
.SetDone(true);
2339 if ( y
!= wxDefaultCoord
)
2341 constr
->top
.SetValue(y
);
2342 constr
->top
.SetDone(true);
2344 if ( w
!= wxDefaultCoord
)
2346 constr
->width
.SetValue(w
);
2347 constr
->width
.SetDone(true);
2349 if ( h
!= wxDefaultCoord
)
2351 constr
->height
.SetValue(h
);
2352 constr
->height
.SetDone(true);
2357 void wxWindowBase::MoveConstraint(int x
, int y
)
2359 wxLayoutConstraints
*constr
= GetConstraints();
2362 if ( x
!= wxDefaultCoord
)
2364 constr
->left
.SetValue(x
);
2365 constr
->left
.SetDone(true);
2367 if ( y
!= wxDefaultCoord
)
2369 constr
->top
.SetValue(y
);
2370 constr
->top
.SetDone(true);
2375 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2377 wxLayoutConstraints
*constr
= GetConstraints();
2380 *w
= constr
->width
.GetValue();
2381 *h
= constr
->height
.GetValue();
2387 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2389 wxLayoutConstraints
*constr
= GetConstraints();
2392 *w
= constr
->width
.GetValue();
2393 *h
= constr
->height
.GetValue();
2396 GetClientSize(w
, h
);
2399 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2401 wxLayoutConstraints
*constr
= GetConstraints();
2404 *x
= constr
->left
.GetValue();
2405 *y
= constr
->top
.GetValue();
2411 #endif // wxUSE_CONSTRAINTS
2413 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2415 // don't do it for the dialogs/frames - they float independently of their
2417 if ( !IsTopLevel() )
2419 wxWindow
*parent
= GetParent();
2420 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2422 wxPoint
pt(parent
->GetClientAreaOrigin());
2429 // ----------------------------------------------------------------------------
2430 // Update UI processing
2431 // ----------------------------------------------------------------------------
2433 void wxWindowBase::UpdateWindowUI(long flags
)
2435 wxUpdateUIEvent
event(GetId());
2436 event
.SetEventObject(this);
2438 if ( GetEventHandler()->ProcessEvent(event
) )
2440 DoUpdateWindowUI(event
);
2443 if (flags
& wxUPDATE_UI_RECURSE
)
2445 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2448 wxWindow
* child
= (wxWindow
*) node
->GetData();
2449 child
->UpdateWindowUI(flags
);
2450 node
= node
->GetNext();
2455 // do the window-specific processing after processing the update event
2456 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2458 if ( event
.GetSetEnabled() )
2459 Enable(event
.GetEnabled());
2461 if ( event
.GetSetShown() )
2462 Show(event
.GetShown());
2465 // ----------------------------------------------------------------------------
2466 // dialog units translations
2467 // ----------------------------------------------------------------------------
2469 // Windows' computes dialog units using average character width over upper-
2470 // and lower-case ASCII alphabet and not using the average character width
2471 // metadata stored in the font; see
2472 // http://support.microsoft.com/default.aspx/kb/145994 for detailed discussion.
2473 // It's important that we perform the conversion in identical way, because
2474 // dialog units natively exist only on Windows and Windows HIG is expressed
2476 wxSize
wxWindowBase::GetDlgUnitBase() const
2478 const wxWindow
*parent
= wxGetTopLevelParent((wxWindow
*)this);
2480 if ( !parent
->m_font
.IsOk() )
2482 // Default GUI font is used. This is the most common case, so
2483 // cache the results.
2484 static wxSize s_defFontSize
;
2485 if ( s_defFontSize
.x
== 0 )
2486 s_defFontSize
= wxPrivate::GetAverageASCIILetterSize(*parent
);
2487 return s_defFontSize
;
2491 // Custom font, we always need to compute the result
2492 return wxPrivate::GetAverageASCIILetterSize(*parent
);
2496 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
) const
2498 const wxSize base
= GetDlgUnitBase();
2500 // NB: wxMulDivInt32() is used, because it correctly rounds the result
2502 wxPoint pt2
= wxDefaultPosition
;
2503 if (pt
.x
!= wxDefaultCoord
)
2504 pt2
.x
= wxMulDivInt32(pt
.x
, 4, base
.x
);
2505 if (pt
.y
!= wxDefaultCoord
)
2506 pt2
.y
= wxMulDivInt32(pt
.y
, 8, base
.y
);
2511 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
) const
2513 const wxSize base
= GetDlgUnitBase();
2515 wxPoint pt2
= wxDefaultPosition
;
2516 if (pt
.x
!= wxDefaultCoord
)
2517 pt2
.x
= wxMulDivInt32(pt
.x
, base
.x
, 4);
2518 if (pt
.y
!= wxDefaultCoord
)
2519 pt2
.y
= wxMulDivInt32(pt
.y
, base
.y
, 8);
2524 // ----------------------------------------------------------------------------
2526 // ----------------------------------------------------------------------------
2528 // propagate the colour change event to the subwindows
2529 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
2531 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2534 // Only propagate to non-top-level windows
2535 wxWindow
*win
= node
->GetData();
2536 if ( !win
->IsTopLevel() )
2538 wxSysColourChangedEvent event2
;
2539 event2
.SetEventObject(win
);
2540 win
->GetEventHandler()->ProcessEvent(event2
);
2543 node
= node
->GetNext();
2549 // the default action is to populate dialog with data when it's created,
2550 // and nudge the UI into displaying itself correctly in case
2551 // we've turned the wxUpdateUIEvents frequency down low.
2552 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2554 TransferDataToWindow();
2556 // Update the UI at this point
2557 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2560 // ----------------------------------------------------------------------------
2561 // menu-related functions
2562 // ----------------------------------------------------------------------------
2566 bool wxWindowBase::PopupMenu(wxMenu
*menu
, int x
, int y
)
2568 wxCHECK_MSG( menu
, false, "can't popup NULL menu" );
2570 wxCurrentPopupMenu
= menu
;
2571 const bool rc
= DoPopupMenu(menu
, x
, y
);
2572 wxCurrentPopupMenu
= NULL
;
2577 // this is used to pass the id of the selected item from the menu event handler
2578 // to the main function itself
2580 // it's ok to use a global here as there can be at most one popup menu shown at
2582 static int gs_popupMenuSelection
= wxID_NONE
;
2584 void wxWindowBase::InternalOnPopupMenu(wxCommandEvent
& event
)
2586 // store the id in a global variable where we'll retrieve it from later
2587 gs_popupMenuSelection
= event
.GetId();
2590 void wxWindowBase::InternalOnPopupMenuUpdate(wxUpdateUIEvent
& WXUNUSED(event
))
2592 // nothing to do but do not skip it
2596 wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu
& menu
, int x
, int y
)
2598 gs_popupMenuSelection
= wxID_NONE
;
2600 Connect(wxEVT_COMMAND_MENU_SELECTED
,
2601 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2605 // it is common to construct the menu passed to this function dynamically
2606 // using some fixed range of ids which could clash with the ids used
2607 // elsewhere in the program, which could result in some menu items being
2608 // unintentionally disabled or otherwise modified by update UI handlers
2609 // elsewhere in the program code and this is difficult to avoid in the
2610 // program itself, so instead we just temporarily suspend UI updating while
2611 // this menu is shown
2612 Connect(wxEVT_UPDATE_UI
,
2613 wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate
),
2617 PopupMenu(&menu
, x
, y
);
2619 Disconnect(wxEVT_UPDATE_UI
,
2620 wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate
),
2623 Disconnect(wxEVT_COMMAND_MENU_SELECTED
,
2624 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2628 return gs_popupMenuSelection
;
2631 #endif // wxUSE_MENUS
2633 // methods for drawing the sizers in a visible way: this is currently only
2634 // enabled for "full debug" builds with wxDEBUG_LEVEL==2 as it doesn't work
2635 // that well and also because we don't want to leave it enabled in default
2636 // builds used for production
2637 #if wxDEBUG_LEVEL > 1
2639 static void DrawSizers(wxWindowBase
*win
);
2641 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
, const wxPen
* pen
)
2643 wxClientDC
dc((wxWindow
*)win
);
2645 dc
.SetBrush(fill
? wxBrush(pen
->GetColour(), wxBRUSHSTYLE_CROSSDIAG_HATCH
) :
2646 *wxTRANSPARENT_BRUSH
);
2647 dc
.DrawRectangle(rect
.Deflate(1, 1));
2650 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2652 const wxSizerItemList
& items
= sizer
->GetChildren();
2653 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2658 wxSizerItem
*item
= *i
;
2659 if ( item
->IsSizer() )
2661 DrawBorder(win
, item
->GetRect().Deflate(2), false, wxRED_PEN
);
2662 DrawSizer(win
, item
->GetSizer());
2664 else if ( item
->IsSpacer() )
2666 DrawBorder(win
, item
->GetRect().Deflate(2), true, wxBLUE_PEN
);
2668 else if ( item
->IsWindow() )
2670 DrawSizers(item
->GetWindow());
2673 wxFAIL_MSG("inconsistent wxSizerItem status!");
2677 static void DrawSizers(wxWindowBase
*win
)
2679 DrawBorder(win
, win
->GetClientSize(), false, wxGREEN_PEN
);
2681 wxSizer
*sizer
= win
->GetSizer();
2684 DrawSizer(win
, sizer
);
2686 else // no sizer, still recurse into the children
2688 const wxWindowList
& children
= win
->GetChildren();
2689 for ( wxWindowList::const_iterator i
= children
.begin(),
2690 end
= children
.end();
2697 // show all kind of sizes of this window; see the "window sizing" topic
2698 // overview for more info about the various differences:
2699 wxSize fullSz
= win
->GetSize();
2700 wxSize clientSz
= win
->GetClientSize();
2701 wxSize bestSz
= win
->GetBestSize();
2702 wxSize minSz
= win
->GetMinSize();
2703 wxSize maxSz
= win
->GetMaxSize();
2704 wxSize virtualSz
= win
->GetVirtualSize();
2706 wxMessageOutputDebug dbgout
;
2708 "%-10s => fullsz=%4d;%-4d clientsz=%4d;%-4d bestsz=%4d;%-4d minsz=%4d;%-4d maxsz=%4d;%-4d virtualsz=%4d;%-4d\n",
2711 clientSz
.x
, clientSz
.y
,
2715 virtualSz
.x
, virtualSz
.y
);
2719 #endif // wxDEBUG_LEVEL
2721 // process special middle clicks
2722 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2724 if ( event
.ControlDown() && event
.AltDown() )
2726 #if wxDEBUG_LEVEL > 1
2727 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2728 if ( event
.ShiftDown() )
2733 #endif // __WXDEBUG__
2735 // just Ctrl-Alt-middle click shows information about wx version
2736 ::wxInfoMessageBox((wxWindow
*)this);
2745 // ----------------------------------------------------------------------------
2747 // ----------------------------------------------------------------------------
2749 #if wxUSE_ACCESSIBILITY
2750 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2752 if (m_accessible
&& (accessible
!= m_accessible
))
2753 delete m_accessible
;
2754 m_accessible
= accessible
;
2756 m_accessible
->SetWindow((wxWindow
*) this);
2759 // Returns the accessible object, creating if necessary.
2760 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2763 m_accessible
= CreateAccessible();
2764 return m_accessible
;
2767 // Override to create a specific accessible object.
2768 wxAccessible
* wxWindowBase::CreateAccessible()
2770 return new wxWindowAccessible((wxWindow
*) this);
2775 // ----------------------------------------------------------------------------
2776 // list classes implementation
2777 // ----------------------------------------------------------------------------
2781 #include "wx/listimpl.cpp"
2782 WX_DEFINE_LIST(wxWindowList
)
2786 void wxWindowListNode::DeleteData()
2788 delete (wxWindow
*)GetData();
2791 #endif // wxUSE_STL/!wxUSE_STL
2793 // ----------------------------------------------------------------------------
2795 // ----------------------------------------------------------------------------
2797 wxBorder
wxWindowBase::GetBorder(long flags
) const
2799 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2800 if ( border
== wxBORDER_DEFAULT
)
2802 border
= GetDefaultBorder();
2804 else if ( border
== wxBORDER_THEME
)
2806 border
= GetDefaultBorderForControl();
2812 wxBorder
wxWindowBase::GetDefaultBorder() const
2814 return wxBORDER_NONE
;
2817 // ----------------------------------------------------------------------------
2819 // ----------------------------------------------------------------------------
2821 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2823 // here we just check if the point is inside the window or not
2825 // check the top and left border first
2826 bool outside
= x
< 0 || y
< 0;
2829 // check the right and bottom borders too
2830 wxSize size
= GetSize();
2831 outside
= x
>= size
.x
|| y
>= size
.y
;
2834 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2837 // ----------------------------------------------------------------------------
2839 // ----------------------------------------------------------------------------
2841 struct WXDLLEXPORT wxWindowNext
2845 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2846 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2847 bool wxWindowBase::ms_winCaptureChanging
= false;
2849 void wxWindowBase::CaptureMouse()
2851 wxLogTrace(wxT("mousecapture"), wxT("CaptureMouse(%p)"), static_cast<void*>(this));
2853 wxASSERT_MSG( !ms_winCaptureChanging
, wxT("recursive CaptureMouse call?") );
2855 ms_winCaptureChanging
= true;
2857 wxWindow
*winOld
= GetCapture();
2860 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2863 wxWindowNext
*item
= new wxWindowNext
;
2865 item
->next
= ms_winCaptureNext
;
2866 ms_winCaptureNext
= item
;
2868 //else: no mouse capture to save
2871 ms_winCaptureCurrent
= (wxWindow
*)this;
2873 ms_winCaptureChanging
= false;
2876 void wxWindowBase::ReleaseMouse()
2878 wxLogTrace(wxT("mousecapture"), wxT("ReleaseMouse(%p)"), static_cast<void*>(this));
2880 wxASSERT_MSG( !ms_winCaptureChanging
, wxT("recursive ReleaseMouse call?") );
2882 wxASSERT_MSG( GetCapture() == this,
2883 "attempt to release mouse, but this window hasn't captured it" );
2884 wxASSERT_MSG( ms_winCaptureCurrent
== this,
2885 "attempt to release mouse, but this window hasn't captured it" );
2887 ms_winCaptureChanging
= true;
2890 ms_winCaptureCurrent
= NULL
;
2892 if ( ms_winCaptureNext
)
2894 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2895 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2897 wxWindowNext
*item
= ms_winCaptureNext
;
2898 ms_winCaptureNext
= item
->next
;
2901 //else: stack is empty, no previous capture
2903 ms_winCaptureChanging
= false;
2905 wxLogTrace(wxT("mousecapture"),
2906 (const wxChar
*) wxT("After ReleaseMouse() mouse is captured by %p"),
2907 static_cast<void*>(GetCapture()));
2910 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2912 wxMouseCaptureLostEvent
event(win
->GetId());
2913 event
.SetEventObject(win
);
2914 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2916 // windows must handle this event, otherwise the app wouldn't behave
2917 // correctly if it loses capture unexpectedly; see the discussion here:
2918 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
2919 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
2920 wxFAIL_MSG( wxT("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2925 void wxWindowBase::NotifyCaptureLost()
2927 // don't do anything if capture lost was expected, i.e. resulted from
2928 // a wx call to ReleaseMouse or CaptureMouse:
2929 if ( ms_winCaptureChanging
)
2932 // if the capture was lost unexpectedly, notify every window that has
2933 // capture (on stack or current) about it and clear the stack:
2935 if ( ms_winCaptureCurrent
)
2937 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2938 ms_winCaptureCurrent
= NULL
;
2941 while ( ms_winCaptureNext
)
2943 wxWindowNext
*item
= ms_winCaptureNext
;
2944 ms_winCaptureNext
= item
->next
;
2946 DoNotifyWindowAboutCaptureLost(item
->win
);
2955 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2956 int WXUNUSED(modifiers
),
2957 int WXUNUSED(keycode
))
2963 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2969 #endif // wxUSE_HOTKEY
2971 // ----------------------------------------------------------------------------
2973 // ----------------------------------------------------------------------------
2975 bool wxWindowBase::TryBefore(wxEvent
& event
)
2977 #if wxUSE_VALIDATORS
2978 // Can only use the validator of the window which
2979 // is receiving the event
2980 if ( event
.GetEventObject() == this )
2982 wxValidator
* const validator
= GetValidator();
2983 if ( validator
&& validator
->ProcessEventHere(event
) )
2988 #endif // wxUSE_VALIDATORS
2990 return wxEvtHandler::TryBefore(event
);
2993 bool wxWindowBase::TryAfter(wxEvent
& event
)
2995 // carry on up the parent-child hierarchy if the propagation count hasn't
2997 if ( event
.ShouldPropagate() )
2999 // honour the requests to stop propagation at this window: this is
3000 // used by the dialogs, for example, to prevent processing the events
3001 // from the dialog controls in the parent frame which rarely, if ever,
3003 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
3005 wxWindow
*parent
= GetParent();
3006 if ( parent
&& !parent
->IsBeingDeleted() )
3008 wxPropagateOnce
propagateOnce(event
);
3010 return parent
->GetEventHandler()->ProcessEvent(event
);
3015 return wxEvtHandler::TryAfter(event
);
3018 // ----------------------------------------------------------------------------
3019 // window relationships
3020 // ----------------------------------------------------------------------------
3022 wxWindow
*wxWindowBase::DoGetSibling(WindowOrder order
) const
3024 wxCHECK_MSG( GetParent(), NULL
,
3025 wxT("GetPrev/NextSibling() don't work for TLWs!") );
3027 wxWindowList
& siblings
= GetParent()->GetChildren();
3028 wxWindowList::compatibility_iterator i
= siblings
.Find((wxWindow
*)this);
3029 wxCHECK_MSG( i
, NULL
, wxT("window not a child of its parent?") );
3031 if ( order
== OrderBefore
)
3032 i
= i
->GetPrevious();
3036 return i
? i
->GetData() : NULL
;
3039 // ----------------------------------------------------------------------------
3040 // keyboard navigation
3041 // ----------------------------------------------------------------------------
3043 // Navigates in the specified direction inside this window
3044 bool wxWindowBase::DoNavigateIn(int flags
)
3046 #ifdef wxHAS_NATIVE_TAB_TRAVERSAL
3047 // native code doesn't process our wxNavigationKeyEvents anyhow
3050 #else // !wxHAS_NATIVE_TAB_TRAVERSAL
3051 wxNavigationKeyEvent eventNav
;
3052 wxWindow
*focused
= FindFocus();
3053 eventNav
.SetCurrentFocus(focused
);
3054 eventNav
.SetEventObject(focused
);
3055 eventNav
.SetFlags(flags
);
3056 return GetEventHandler()->ProcessEvent(eventNav
);
3057 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
3060 bool wxWindowBase::HandleAsNavigationKey(const wxKeyEvent
& event
)
3062 if ( event
.GetKeyCode() != WXK_TAB
)
3065 int flags
= wxNavigationKeyEvent::FromTab
;
3067 if ( event
.ShiftDown() )
3068 flags
|= wxNavigationKeyEvent::IsBackward
;
3070 flags
|= wxNavigationKeyEvent::IsForward
;
3072 if ( event
.ControlDown() )
3073 flags
|= wxNavigationKeyEvent::WinChange
;
3079 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, WindowOrder move
)
3081 // check that we're not a top level window
3082 wxCHECK_RET( GetParent(),
3083 wxT("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
3085 // detect the special case when we have nothing to do anyhow and when the
3086 // code below wouldn't work
3090 // find the target window in the siblings list
3091 wxWindowList
& siblings
= GetParent()->GetChildren();
3092 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
3093 wxCHECK_RET( i
, wxT("MoveBefore/AfterInTabOrder(): win is not a sibling") );
3095 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
3096 // can't just move the node around
3097 wxWindow
*self
= (wxWindow
*)this;
3098 siblings
.DeleteObject(self
);
3099 if ( move
== OrderAfter
)
3106 siblings
.Insert(i
, self
);
3108 else // OrderAfter and win was the last sibling
3110 siblings
.Append(self
);
3114 // ----------------------------------------------------------------------------
3116 // ----------------------------------------------------------------------------
3118 /*static*/ wxWindow
* wxWindowBase::FindFocus()
3120 wxWindowBase
*win
= DoFindFocus();
3121 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
3124 bool wxWindowBase::HasFocus() const
3126 wxWindowBase
*win
= DoFindFocus();
3127 return win
== this ||
3128 win
== wxConstCast(this, wxWindowBase
)->GetMainWindowOfCompositeControl();
3131 // ----------------------------------------------------------------------------
3133 // ----------------------------------------------------------------------------
3135 #if wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
3140 class DragAcceptFilesTarget
: public wxFileDropTarget
3143 DragAcceptFilesTarget(wxWindowBase
*win
) : m_win(win
) {}
3145 virtual bool OnDropFiles(wxCoord x
, wxCoord y
,
3146 const wxArrayString
& filenames
)
3148 wxDropFilesEvent
event(wxEVT_DROP_FILES
,
3150 wxCArrayString(filenames
).Release());
3151 event
.SetEventObject(m_win
);
3155 return m_win
->HandleWindowEvent(event
);
3159 wxWindowBase
* const m_win
;
3161 wxDECLARE_NO_COPY_CLASS(DragAcceptFilesTarget
);
3165 } // anonymous namespace
3167 // Generic version of DragAcceptFiles(). It works by installing a simple
3168 // wxFileDropTarget-to-EVT_DROP_FILES adaptor and therefore cannot be used
3169 // together with explicit SetDropTarget() calls.
3170 void wxWindowBase::DragAcceptFiles(bool accept
)
3174 wxASSERT_MSG( !GetDropTarget(),
3175 "cannot use DragAcceptFiles() and SetDropTarget() together" );
3176 SetDropTarget(new DragAcceptFilesTarget(this));
3180 SetDropTarget(NULL
);
3184 #endif // wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
3186 // ----------------------------------------------------------------------------
3188 // ----------------------------------------------------------------------------
3190 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
3192 while ( win
&& !win
->IsTopLevel() )
3193 win
= win
->GetParent();
3198 #if wxUSE_ACCESSIBILITY
3199 // ----------------------------------------------------------------------------
3200 // accessible object for windows
3201 // ----------------------------------------------------------------------------
3203 // Can return either a child object, or an integer
3204 // representing the child element, starting from 1.
3205 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
3207 wxASSERT( GetWindow() != NULL
);
3211 return wxACC_NOT_IMPLEMENTED
;
3214 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
3215 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
3217 wxASSERT( GetWindow() != NULL
);
3221 wxWindow
* win
= NULL
;
3228 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
3230 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
3237 rect
= win
->GetRect();
3238 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
3239 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
3243 return wxACC_NOT_IMPLEMENTED
;
3246 // Navigates from fromId to toId/toObject.
3247 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
3248 int* WXUNUSED(toId
), wxAccessible
** toObject
)
3250 wxASSERT( GetWindow() != NULL
);
3256 case wxNAVDIR_FIRSTCHILD
:
3258 if (GetWindow()->GetChildren().GetCount() == 0)
3260 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
3261 *toObject
= childWindow
->GetOrCreateAccessible();
3265 case wxNAVDIR_LASTCHILD
:
3267 if (GetWindow()->GetChildren().GetCount() == 0)
3269 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
3270 *toObject
= childWindow
->GetOrCreateAccessible();
3274 case wxNAVDIR_RIGHT
:
3278 wxWindowList::compatibility_iterator node
=
3279 wxWindowList::compatibility_iterator();
3282 // Can't navigate to sibling of this window
3283 // if we're a top-level window.
3284 if (!GetWindow()->GetParent())
3285 return wxACC_NOT_IMPLEMENTED
;
3287 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3291 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
3292 node
= GetWindow()->GetChildren().Item(fromId
-1);
3295 if (node
&& node
->GetNext())
3297 wxWindow
* nextWindow
= node
->GetNext()->GetData();
3298 *toObject
= nextWindow
->GetOrCreateAccessible();
3306 case wxNAVDIR_PREVIOUS
:
3308 wxWindowList::compatibility_iterator node
=
3309 wxWindowList::compatibility_iterator();
3312 // Can't navigate to sibling of this window
3313 // if we're a top-level window.
3314 if (!GetWindow()->GetParent())
3315 return wxACC_NOT_IMPLEMENTED
;
3317 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3321 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
3322 node
= GetWindow()->GetChildren().Item(fromId
-1);
3325 if (node
&& node
->GetPrevious())
3327 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
3328 *toObject
= previousWindow
->GetOrCreateAccessible();
3336 return wxACC_NOT_IMPLEMENTED
;
3339 // Gets the name of the specified object.
3340 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
3342 wxASSERT( GetWindow() != NULL
);
3348 // If a child, leave wxWidgets to call the function on the actual
3351 return wxACC_NOT_IMPLEMENTED
;
3353 // This will eventually be replaced by specialised
3354 // accessible classes, one for each kind of wxWidgets
3355 // control or window.
3357 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
3358 title
= ((wxButton
*) GetWindow())->GetLabel();
3361 title
= GetWindow()->GetName();
3369 return wxACC_NOT_IMPLEMENTED
;
3372 // Gets the number of children.
3373 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
3375 wxASSERT( GetWindow() != NULL
);
3379 *childId
= (int) GetWindow()->GetChildren().GetCount();
3383 // Gets the specified child (starting from 1).
3384 // If *child is NULL and return value is wxACC_OK,
3385 // this means that the child is a simple element and
3386 // not an accessible object.
3387 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
3389 wxASSERT( GetWindow() != NULL
);
3399 if (childId
> (int) GetWindow()->GetChildren().GetCount())
3402 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
3403 *child
= childWindow
->GetOrCreateAccessible();
3410 // Gets the parent, or NULL.
3411 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
3413 wxASSERT( GetWindow() != NULL
);
3417 wxWindow
* parentWindow
= GetWindow()->GetParent();
3425 *parent
= parentWindow
->GetOrCreateAccessible();
3433 // Performs the default action. childId is 0 (the action for this object)
3434 // or > 0 (the action for a child).
3435 // Return wxACC_NOT_SUPPORTED if there is no default action for this
3436 // window (e.g. an edit control).
3437 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
3439 wxASSERT( GetWindow() != NULL
);
3443 return wxACC_NOT_IMPLEMENTED
;
3446 // Gets the default action for this object (0) or > 0 (the action for a child).
3447 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
3448 // string if there is no action.
3449 // The retrieved string describes the action that is performed on an object,
3450 // not what the object does as a result. For example, a toolbar button that prints
3451 // a document has a default action of "Press" rather than "Prints the current document."
3452 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
3454 wxASSERT( GetWindow() != NULL
);
3458 return wxACC_NOT_IMPLEMENTED
;
3461 // Returns the description for this object or a child.
3462 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
3464 wxASSERT( GetWindow() != NULL
);
3468 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3474 return wxACC_NOT_IMPLEMENTED
;
3477 // Returns help text for this object or a child, similar to tooltip text.
3478 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
3480 wxASSERT( GetWindow() != NULL
);
3484 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3490 return wxACC_NOT_IMPLEMENTED
;
3493 // Returns the keyboard shortcut for this object or child.
3494 // Return e.g. ALT+K
3495 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
3497 wxASSERT( GetWindow() != NULL
);
3501 return wxACC_NOT_IMPLEMENTED
;
3504 // Returns a role constant.
3505 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
3507 wxASSERT( GetWindow() != NULL
);
3511 // If a child, leave wxWidgets to call the function on the actual
3514 return wxACC_NOT_IMPLEMENTED
;
3516 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3517 return wxACC_NOT_IMPLEMENTED
;
3519 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3520 return wxACC_NOT_IMPLEMENTED
;
3523 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3524 return wxACC_NOT_IMPLEMENTED
;
3527 //*role = wxROLE_SYSTEM_CLIENT;
3528 *role
= wxROLE_SYSTEM_CLIENT
;
3532 return wxACC_NOT_IMPLEMENTED
;
3536 // Returns a state constant.
3537 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
3539 wxASSERT( GetWindow() != NULL
);
3543 // If a child, leave wxWidgets to call the function on the actual
3546 return wxACC_NOT_IMPLEMENTED
;
3548 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3549 return wxACC_NOT_IMPLEMENTED
;
3552 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3553 return wxACC_NOT_IMPLEMENTED
;
3556 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3557 return wxACC_NOT_IMPLEMENTED
;
3564 return wxACC_NOT_IMPLEMENTED
;
3568 // Returns a localized string representing the value for the object
3570 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3572 wxASSERT( GetWindow() != NULL
);
3576 return wxACC_NOT_IMPLEMENTED
;
3579 // Selects the object or child.
3580 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3582 wxASSERT( GetWindow() != NULL
);
3586 return wxACC_NOT_IMPLEMENTED
;
3589 // Gets the window with the keyboard focus.
3590 // If childId is 0 and child is NULL, no object in
3591 // this subhierarchy has the focus.
3592 // If this object has the focus, child should be 'this'.
3593 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3595 wxASSERT( GetWindow() != NULL
);
3599 return wxACC_NOT_IMPLEMENTED
;
3603 // Gets a variant representing the selected children
3605 // Acceptable values:
3606 // - a null variant (IsNull() returns true)
3607 // - a list variant (GetType() == wxT("list")
3608 // - an integer representing the selected child element,
3609 // or 0 if this object is selected (GetType() == wxT("long")
3610 // - a "void*" pointer to a wxAccessible child object
3611 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3613 wxASSERT( GetWindow() != NULL
);
3617 return wxACC_NOT_IMPLEMENTED
;
3619 #endif // wxUSE_VARIANT
3621 #endif // wxUSE_ACCESSIBILITY
3623 // ----------------------------------------------------------------------------
3625 // ----------------------------------------------------------------------------
3628 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3630 wxCoord widthTotal
) const
3632 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3634 x
= widthTotal
- x
- width
;