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 wxDELETE(m_constraints
);
369 #endif // wxUSE_CONSTRAINTS
371 if ( m_containingSizer
)
372 m_containingSizer
->Detach( (wxWindow
*)this );
374 delete m_windowSizer
;
376 #if wxUSE_DRAG_AND_DROP
378 #endif // wxUSE_DRAG_AND_DROP
382 #endif // wxUSE_TOOLTIPS
384 #if wxUSE_ACCESSIBILITY
389 // NB: this has to be called unconditionally, because we don't know
390 // whether this window has associated help text or not
391 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
393 helpProvider
->RemoveHelp(this);
397 bool wxWindowBase::IsBeingDeleted() const
399 return m_isBeingDeleted
||
400 (!IsTopLevel() && m_parent
&& m_parent
->IsBeingDeleted());
403 void wxWindowBase::SendDestroyEvent()
405 if ( m_isBeingDeleted
)
407 // we could have been already called from a more derived class dtor,
408 // e.g. ~wxTLW calls us and so does ~wxWindow and the latter call
409 // should be simply ignored
413 m_isBeingDeleted
= true;
415 wxWindowDestroyEvent event
;
416 event
.SetEventObject(this);
417 event
.SetId(GetId());
418 GetEventHandler()->ProcessEvent(event
);
421 bool wxWindowBase::Destroy()
430 bool wxWindowBase::Close(bool force
)
432 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
433 event
.SetEventObject(this);
434 event
.SetCanVeto(!force
);
436 // return false if window wasn't closed because the application vetoed the
438 return HandleWindowEvent(event
) && !event
.GetVeto();
441 bool wxWindowBase::DestroyChildren()
443 wxWindowList::compatibility_iterator node
;
446 // we iterate until the list becomes empty
447 node
= GetChildren().GetFirst();
451 wxWindow
*child
= node
->GetData();
453 // note that we really want to delete it immediately so don't call the
454 // possible overridden Destroy() version which might not delete the
455 // child immediately resulting in problems with our (top level) child
456 // outliving its parent
457 child
->wxWindowBase::Destroy();
459 wxASSERT_MSG( !GetChildren().Find(child
),
460 wxT("child didn't remove itself using RemoveChild()") );
466 // ----------------------------------------------------------------------------
467 // size/position related methods
468 // ----------------------------------------------------------------------------
470 // centre the window with respect to its parent in either (or both) directions
471 void wxWindowBase::DoCentre(int dir
)
473 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
474 wxT("this method only implements centering child windows") );
476 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
479 // fits the window around the children
480 void wxWindowBase::Fit()
482 if ( !GetChildren().empty() )
484 SetSize(GetBestSize());
486 //else: do nothing if we have no children
489 // fits virtual size (ie. scrolled area etc.) around children
490 void wxWindowBase::FitInside()
492 if ( GetChildren().GetCount() > 0 )
494 SetVirtualSize( GetBestVirtualSize() );
498 // On Mac, scrollbars are explicitly children.
499 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
500 static bool wxHasRealChildren(const wxWindowBase
* win
)
502 int realChildCount
= 0;
504 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
506 node
= node
->GetNext() )
508 wxWindow
*win
= node
->GetData();
509 if ( !win
->IsTopLevel() && win
->IsShown()
511 && !win
->IsKindOf(CLASSINFO(wxScrollBar
))
516 return (realChildCount
> 0);
520 void wxWindowBase::InvalidateBestSize()
522 m_bestSizeCache
= wxDefaultSize
;
524 // parent's best size calculation may depend on its children's
525 // as long as child window we are in is not top level window itself
526 // (because the TLW size is never resized automatically)
527 // so let's invalidate it as well to be safe:
528 if (m_parent
&& !IsTopLevel())
529 m_parent
->InvalidateBestSize();
532 // return the size best suited for the current window
533 wxSize
wxWindowBase::DoGetBestSize() const
539 best
= m_windowSizer
->GetMinSize();
541 #if wxUSE_CONSTRAINTS
542 else if ( m_constraints
)
544 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
546 // our minimal acceptable size is such that all our windows fit inside
550 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
552 node
= node
->GetNext() )
554 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
557 // it's not normal that we have an unconstrained child, but
558 // what can we do about it?
562 int x
= c
->right
.GetValue(),
563 y
= c
->bottom
.GetValue();
571 // TODO: we must calculate the overlaps somehow, otherwise we
572 // will never return a size bigger than the current one :-(
575 best
= wxSize(maxX
, maxY
);
577 #endif // wxUSE_CONSTRAINTS
578 else if ( !GetChildren().empty()
579 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
580 && wxHasRealChildren(this)
584 // our minimal acceptable size is such that all our visible child
585 // windows fit inside
589 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
591 node
= node
->GetNext() )
593 wxWindow
*win
= node
->GetData();
594 if ( win
->IsTopLevel()
597 || wxDynamicCast(win
, wxStatusBar
)
598 #endif // wxUSE_STATUSBAR
601 // dialogs and frames lie in different top level windows -
602 // don't deal with them here; as for the status bars, they
603 // don't lie in the client area at all
608 win
->GetPosition(&wx
, &wy
);
610 // if the window hadn't been positioned yet, assume that it is in
612 if ( wx
== wxDefaultCoord
)
614 if ( wy
== wxDefaultCoord
)
617 win
->GetSize(&ww
, &wh
);
618 if ( wx
+ ww
> maxX
)
620 if ( wy
+ wh
> maxY
)
624 best
= wxSize(maxX
, maxY
);
626 else // ! has children
628 wxSize size
= GetMinSize();
629 if ( !size
.IsFullySpecified() )
631 // if the window doesn't define its best size we assume that it can
632 // be arbitrarily small -- usually this is not the case, of course,
633 // but we have no way to know what the limit is, it should really
634 // override DoGetBestClientSize() itself to tell us
635 size
.SetDefaults(wxSize(1, 1));
638 // return as-is, unadjusted by the client size difference.
642 // Add any difference between size and client size
643 wxSize diff
= GetSize() - GetClientSize();
644 best
.x
+= wxMax(0, diff
.x
);
645 best
.y
+= wxMax(0, diff
.y
);
650 // helper of GetWindowBorderSize(): as many ports don't implement support for
651 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
652 // fallbacks in this case
653 static int wxGetMetricOrDefault(wxSystemMetric what
, const wxWindowBase
* win
)
655 int rc
= wxSystemSettings::GetMetric(
656 what
, static_cast<wxWindow
*>(const_cast<wxWindowBase
*>(win
)));
663 // 2D border is by default 1 pixel wide
669 // 3D borders are by default 2 pixels
674 wxFAIL_MSG( wxT("unexpected wxGetMetricOrDefault() argument") );
682 wxSize
wxWindowBase::GetWindowBorderSize() const
686 switch ( GetBorder() )
689 // nothing to do, size is already (0, 0)
692 case wxBORDER_SIMPLE
:
693 case wxBORDER_STATIC
:
694 size
.x
= wxGetMetricOrDefault(wxSYS_BORDER_X
, this);
695 size
.y
= wxGetMetricOrDefault(wxSYS_BORDER_Y
, this);
698 case wxBORDER_SUNKEN
:
699 case wxBORDER_RAISED
:
700 size
.x
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X
, this),
701 wxGetMetricOrDefault(wxSYS_BORDER_X
, this));
702 size
.y
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y
, this),
703 wxGetMetricOrDefault(wxSYS_BORDER_Y
, this));
706 case wxBORDER_DOUBLE
:
707 size
.x
= wxGetMetricOrDefault(wxSYS_EDGE_X
, this) +
708 wxGetMetricOrDefault(wxSYS_BORDER_X
, this);
709 size
.y
= wxGetMetricOrDefault(wxSYS_EDGE_Y
, this) +
710 wxGetMetricOrDefault(wxSYS_BORDER_Y
, this);
714 wxFAIL_MSG(wxT("Unknown border style."));
718 // we have borders on both sides
722 wxSize
wxWindowBase::GetEffectiveMinSize() const
724 // merge the best size with the min size, giving priority to the min size
725 wxSize min
= GetMinSize();
727 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
729 wxSize best
= GetBestSize();
730 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
731 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
737 wxSize
wxWindowBase::DoGetBorderSize() const
739 // there is one case in which we can implement it for all ports easily
740 if ( GetBorder() == wxBORDER_NONE
)
743 // otherwise use the difference between the real size and the client size
744 // as a fallback: notice that this is incorrect in general as client size
745 // also doesn't take the scrollbars into account
746 return GetSize() - GetClientSize();
749 wxSize
wxWindowBase::GetBestSize() const
751 if ( !m_windowSizer
&& m_bestSizeCache
.IsFullySpecified() )
752 return m_bestSizeCache
;
754 // call DoGetBestClientSize() first, if a derived class overrides it wants
756 wxSize size
= DoGetBestClientSize();
757 if ( size
!= wxDefaultSize
)
759 size
+= DoGetBorderSize();
765 return DoGetBestSize();
768 void wxWindowBase::SetMinSize(const wxSize
& minSize
)
770 m_minWidth
= minSize
.x
;
771 m_minHeight
= minSize
.y
;
774 void wxWindowBase::SetMaxSize(const wxSize
& maxSize
)
776 m_maxWidth
= maxSize
.x
;
777 m_maxHeight
= maxSize
.y
;
780 void wxWindowBase::SetInitialSize(const wxSize
& size
)
782 // Set the min size to the size passed in. This will usually either be
783 // wxDefaultSize or the size passed to this window's ctor/Create function.
786 // Merge the size with the best size if needed
787 wxSize best
= GetEffectiveMinSize();
789 // If the current size doesn't match then change it
790 if (GetSize() != best
)
795 // by default the origin is not shifted
796 wxPoint
wxWindowBase::GetClientAreaOrigin() const
801 wxSize
wxWindowBase::ClientToWindowSize(const wxSize
& size
) const
803 const wxSize
diff(GetSize() - GetClientSize());
805 return wxSize(size
.x
== -1 ? -1 : size
.x
+ diff
.x
,
806 size
.y
== -1 ? -1 : size
.y
+ diff
.y
);
809 wxSize
wxWindowBase::WindowToClientSize(const wxSize
& size
) const
811 const wxSize
diff(GetSize() - GetClientSize());
813 return wxSize(size
.x
== -1 ? -1 : size
.x
- diff
.x
,
814 size
.y
== -1 ? -1 : size
.y
- diff
.y
);
817 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
819 if ( m_windowVariant
!= variant
)
821 m_windowVariant
= variant
;
823 DoSetWindowVariant(variant
);
827 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
829 // adjust the font height to correspond to our new variant (notice that
830 // we're only called if something really changed)
831 wxFont font
= GetFont();
832 int size
= font
.GetPointSize();
835 case wxWINDOW_VARIANT_NORMAL
:
838 case wxWINDOW_VARIANT_SMALL
:
839 size
= wxRound(size
* 3.0 / 4.0);
842 case wxWINDOW_VARIANT_MINI
:
843 size
= wxRound(size
* 2.0 / 3.0);
846 case wxWINDOW_VARIANT_LARGE
:
847 size
= wxRound(size
* 5.0 / 4.0);
851 wxFAIL_MSG(wxT("unexpected window variant"));
855 font
.SetPointSize(size
);
859 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
861 int WXUNUSED(incW
), int WXUNUSED(incH
) )
863 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
864 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
865 wxT("min width/height must be less than max width/height!") );
874 #if WXWIN_COMPATIBILITY_2_8
875 void wxWindowBase::SetVirtualSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
),
876 int WXUNUSED(maxW
), int WXUNUSED(maxH
))
880 void wxWindowBase::SetVirtualSizeHints(const wxSize
& WXUNUSED(minsize
),
881 const wxSize
& WXUNUSED(maxsize
))
884 #endif // WXWIN_COMPATIBILITY_2_8
886 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
888 m_virtualSize
= wxSize(x
, y
);
891 wxSize
wxWindowBase::DoGetVirtualSize() const
893 // we should use the entire client area so if it is greater than our
894 // virtual size, expand it to fit (otherwise if the window is big enough we
895 // wouldn't be using parts of it)
896 wxSize size
= GetClientSize();
897 if ( m_virtualSize
.x
> size
.x
)
898 size
.x
= m_virtualSize
.x
;
900 if ( m_virtualSize
.y
>= size
.y
)
901 size
.y
= m_virtualSize
.y
;
906 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
908 // screen position is the same as (0, 0) in client coords for non TLWs (and
909 // TLWs override this method)
915 ClientToScreen(x
, y
);
918 void wxWindowBase::SendSizeEvent(int flags
)
920 wxSizeEvent
event(GetSize(), GetId());
921 event
.SetEventObject(this);
922 if ( flags
& wxSEND_EVENT_POST
)
923 wxPostEvent(this, event
);
925 HandleWindowEvent(event
);
928 void wxWindowBase::SendSizeEventToParent(int flags
)
930 wxWindow
* const parent
= GetParent();
931 if ( parent
&& !parent
->IsBeingDeleted() )
932 parent
->SendSizeEvent(flags
);
935 bool wxWindowBase::HasScrollbar(int orient
) const
937 // if scrolling in the given direction is disabled, we can't have the
938 // corresponding scrollbar no matter what
939 if ( !CanScroll(orient
) )
942 const wxSize sizeVirt
= GetVirtualSize();
943 const wxSize sizeClient
= GetClientSize();
945 return orient
== wxHORIZONTAL
? sizeVirt
.x
> sizeClient
.x
946 : sizeVirt
.y
> sizeClient
.y
;
949 // ----------------------------------------------------------------------------
950 // show/hide/enable/disable the window
951 // ----------------------------------------------------------------------------
953 bool wxWindowBase::Show(bool show
)
955 if ( show
!= m_isShown
)
967 bool wxWindowBase::IsEnabled() const
969 return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
972 void wxWindowBase::NotifyWindowOnEnableChange(bool enabled
)
974 #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
976 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
980 // If we are top-level then the logic doesn't apply - otherwise
981 // showing a modal dialog would result in total greying out (and ungreying
982 // out later) of everything which would be really ugly
986 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
988 node
= node
->GetNext() )
990 wxWindowBase
* const child
= node
->GetData();
991 if ( !child
->IsTopLevel() && child
->IsThisEnabled() )
992 child
->NotifyWindowOnEnableChange(enabled
);
996 bool wxWindowBase::Enable(bool enable
)
998 if ( enable
== IsThisEnabled() )
1001 m_isEnabled
= enable
;
1003 #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
1005 #else // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
1006 wxWindowBase
* const parent
= GetParent();
1007 if( !IsTopLevel() && parent
&& !parent
->IsEnabled() )
1011 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
1013 NotifyWindowOnEnableChange(enable
);
1018 bool wxWindowBase::IsShownOnScreen() const
1020 // A window is shown on screen if it itself is shown and so are all its
1021 // parents. But if a window is toplevel one, then its always visible on
1022 // screen if IsShown() returns true, even if it has a hidden parent.
1024 (IsTopLevel() || GetParent() == NULL
|| GetParent()->IsShownOnScreen());
1027 // ----------------------------------------------------------------------------
1029 // ----------------------------------------------------------------------------
1031 bool wxWindowBase::IsTopLevel() const
1036 // ----------------------------------------------------------------------------
1038 // ----------------------------------------------------------------------------
1040 void wxWindowBase::Freeze()
1042 if ( !m_freezeCount
++ )
1044 // physically freeze this window:
1047 // and recursively freeze all children:
1048 for ( wxWindowList::iterator i
= GetChildren().begin();
1049 i
!= GetChildren().end(); ++i
)
1051 wxWindow
*child
= *i
;
1052 if ( child
->IsTopLevel() )
1060 void wxWindowBase::Thaw()
1062 wxASSERT_MSG( m_freezeCount
, "Thaw() without matching Freeze()" );
1064 if ( !--m_freezeCount
)
1066 // recursively thaw all children:
1067 for ( wxWindowList::iterator i
= GetChildren().begin();
1068 i
!= GetChildren().end(); ++i
)
1070 wxWindow
*child
= *i
;
1071 if ( child
->IsTopLevel() )
1077 // physically thaw this window:
1082 // ----------------------------------------------------------------------------
1083 // reparenting the window
1084 // ----------------------------------------------------------------------------
1086 void wxWindowBase::AddChild(wxWindowBase
*child
)
1088 wxCHECK_RET( child
, wxT("can't add a NULL child") );
1090 // this should never happen and it will lead to a crash later if it does
1091 // because RemoveChild() will remove only one node from the children list
1092 // and the other(s) one(s) will be left with dangling pointers in them
1093 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), wxT("AddChild() called twice") );
1095 GetChildren().Append((wxWindow
*)child
);
1096 child
->SetParent(this);
1098 // adding a child while frozen will assert when thawed, so freeze it as if
1099 // it had been already present when we were frozen
1100 if ( IsFrozen() && !child
->IsTopLevel() )
1104 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
1106 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
1108 // removing a child while frozen may result in permanently frozen window
1109 // if used e.g. from Reparent(), so thaw it
1111 // NB: IsTopLevel() doesn't return true any more when a TLW child is being
1112 // removed from its ~wxWindowBase, so check for IsBeingDeleted() too
1113 if ( IsFrozen() && !child
->IsBeingDeleted() && !child
->IsTopLevel() )
1116 GetChildren().DeleteObject((wxWindow
*)child
);
1117 child
->SetParent(NULL
);
1120 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
1122 wxWindow
*oldParent
= GetParent();
1123 if ( newParent
== oldParent
)
1129 const bool oldEnabledState
= IsEnabled();
1131 // unlink this window from the existing parent.
1134 oldParent
->RemoveChild(this);
1138 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
1141 // add it to the new one
1144 newParent
->AddChild(this);
1148 wxTopLevelWindows
.Append((wxWindow
*)this);
1151 // We need to notify window (and its subwindows) if by changing the parent
1152 // we also change our enabled/disabled status.
1153 const bool newEnabledState
= IsEnabled();
1154 if ( newEnabledState
!= oldEnabledState
)
1156 NotifyWindowOnEnableChange(newEnabledState
);
1162 // ----------------------------------------------------------------------------
1163 // event handler stuff
1164 // ----------------------------------------------------------------------------
1166 void wxWindowBase::SetEventHandler(wxEvtHandler
*handler
)
1168 wxCHECK_RET(handler
!= NULL
, "SetEventHandler(NULL) called");
1170 m_eventHandler
= handler
;
1173 void wxWindowBase::SetNextHandler(wxEvtHandler
*WXUNUSED(handler
))
1175 // disable wxEvtHandler chain mechanism for wxWindows:
1176 // wxWindow uses its own stack mechanism which doesn't mix well with wxEvtHandler's one
1178 wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
1180 void wxWindowBase::SetPreviousHandler(wxEvtHandler
*WXUNUSED(handler
))
1182 // we can't simply wxFAIL here as in SetNextHandler: in fact the last
1183 // handler of our stack when is destroyed will be Unlink()ed and thus
1184 // will call this function to update the pointer of this window...
1186 //wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
1189 void wxWindowBase::PushEventHandler(wxEvtHandler
*handlerToPush
)
1191 wxCHECK_RET( handlerToPush
!= NULL
, "PushEventHandler(NULL) called" );
1193 // the new handler is going to be part of the wxWindow stack of event handlers:
1194 // it can't be part also of an event handler double-linked chain:
1195 wxASSERT_MSG(handlerToPush
->IsUnlinked(),
1196 "The handler being pushed in the wxWindow stack shouldn't be part of "
1197 "a wxEvtHandler chain; call Unlink() on it first");
1199 wxEvtHandler
*handlerOld
= GetEventHandler();
1200 wxCHECK_RET( handlerOld
, "an old event handler is NULL?" );
1202 // now use wxEvtHandler double-linked list to implement a stack:
1203 handlerToPush
->SetNextHandler(handlerOld
);
1205 if (handlerOld
!= this)
1206 handlerOld
->SetPreviousHandler(handlerToPush
);
1208 SetEventHandler(handlerToPush
);
1211 // final checks of the operations done above:
1212 wxASSERT_MSG( handlerToPush
->GetPreviousHandler() == NULL
,
1213 "the first handler of the wxWindow stack should "
1214 "have no previous handlers set" );
1215 wxASSERT_MSG( handlerToPush
->GetNextHandler() != NULL
,
1216 "the first handler of the wxWindow stack should "
1217 "have non-NULL next handler" );
1219 wxEvtHandler
* pLast
= handlerToPush
;
1220 while ( pLast
&& pLast
!= this )
1221 pLast
= pLast
->GetNextHandler();
1222 wxASSERT_MSG( pLast
->GetNextHandler() == NULL
,
1223 "the last handler of the wxWindow stack should "
1224 "have this window as next handler" );
1225 #endif // wxDEBUG_LEVEL
1228 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
1230 // we need to pop the wxWindow stack, i.e. we need to remove the first handler
1232 wxEvtHandler
*firstHandler
= GetEventHandler();
1233 wxCHECK_MSG( firstHandler
!= NULL
, NULL
, "wxWindow cannot have a NULL event handler" );
1234 wxCHECK_MSG( firstHandler
!= this, NULL
, "cannot pop the wxWindow itself" );
1235 wxCHECK_MSG( firstHandler
->GetPreviousHandler() == NULL
, NULL
,
1236 "the first handler of the wxWindow stack should have no previous handlers set" );
1238 wxEvtHandler
*secondHandler
= firstHandler
->GetNextHandler();
1239 wxCHECK_MSG( secondHandler
!= NULL
, NULL
,
1240 "the first handler of the wxWindow stack should have non-NULL next handler" );
1242 firstHandler
->SetNextHandler(NULL
);
1243 secondHandler
->SetPreviousHandler(NULL
);
1245 // now firstHandler is completely unlinked; set secondHandler as the new window event handler
1246 SetEventHandler(secondHandler
);
1248 if ( deleteHandler
)
1250 wxDELETE(firstHandler
);
1253 return firstHandler
;
1256 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handlerToRemove
)
1258 wxCHECK_MSG( handlerToRemove
!= NULL
, false, "RemoveEventHandler(NULL) called" );
1259 wxCHECK_MSG( handlerToRemove
!= this, false, "Cannot remove the window itself" );
1261 if (handlerToRemove
== GetEventHandler())
1263 // removing the first event handler is equivalent to "popping" the stack
1264 PopEventHandler(false);
1268 // NOTE: the wxWindow event handler list is always terminated with "this" handler
1269 wxEvtHandler
*handlerCur
= GetEventHandler()->GetNextHandler();
1270 while ( handlerCur
!= this && handlerCur
)
1272 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
1274 if ( handlerCur
== handlerToRemove
)
1276 handlerCur
->Unlink();
1278 wxASSERT_MSG( handlerCur
!= GetEventHandler(),
1279 "the case Remove == Pop should was already handled" );
1283 handlerCur
= handlerNext
;
1286 wxFAIL_MSG( wxT("where has the event handler gone?") );
1291 bool wxWindowBase::HandleWindowEvent(wxEvent
& event
) const
1293 // SafelyProcessEvent() will handle exceptions nicely
1294 return GetEventHandler()->SafelyProcessEvent(event
);
1297 // ----------------------------------------------------------------------------
1298 // colours, fonts &c
1299 // ----------------------------------------------------------------------------
1301 void wxWindowBase::InheritAttributes()
1303 const wxWindowBase
* const parent
= GetParent();
1307 // we only inherit attributes which had been explicitly set for the parent
1308 // which ensures that this only happens if the user really wants it and
1309 // not by default which wouldn't make any sense in modern GUIs where the
1310 // controls don't all use the same fonts (nor colours)
1311 if ( parent
->m_inheritFont
&& !m_hasFont
)
1312 SetFont(parent
->GetFont());
1314 // in addition, there is a possibility to explicitly forbid inheriting
1315 // colours at each class level by overriding ShouldInheritColours()
1316 if ( ShouldInheritColours() )
1318 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1319 SetForegroundColour(parent
->GetForegroundColour());
1321 // inheriting (solid) background colour is wrong as it totally breaks
1322 // any kind of themed backgrounds
1324 // instead, the controls should use the same background as their parent
1325 // (ideally by not drawing it at all)
1327 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1328 SetBackgroundColour(parent
->GetBackgroundColour());
1333 /* static */ wxVisualAttributes
1334 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1336 // it is important to return valid values for all attributes from here,
1337 // GetXXX() below rely on this
1338 wxVisualAttributes attrs
;
1339 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1340 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1342 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1343 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1344 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1345 // colour on other platforms.
1347 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1348 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1350 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1355 wxColour
wxWindowBase::GetBackgroundColour() const
1357 if ( !m_backgroundColour
.IsOk() )
1359 wxASSERT_MSG( !m_hasBgCol
, wxT("we have invalid explicit bg colour?") );
1361 // get our default background colour
1362 wxColour colBg
= GetDefaultAttributes().colBg
;
1364 // we must return some valid colour to avoid redoing this every time
1365 // and also to avoid surprising the applications written for older
1366 // wxWidgets versions where GetBackgroundColour() always returned
1367 // something -- so give them something even if it doesn't make sense
1368 // for this window (e.g. it has a themed background)
1370 colBg
= GetClassDefaultAttributes().colBg
;
1375 return m_backgroundColour
;
1378 wxColour
wxWindowBase::GetForegroundColour() const
1380 // logic is the same as above
1381 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1383 wxColour colFg
= GetDefaultAttributes().colFg
;
1385 if ( !colFg
.IsOk() )
1386 colFg
= GetClassDefaultAttributes().colFg
;
1391 return m_foregroundColour
;
1394 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1396 if ( colour
== m_backgroundColour
)
1399 m_hasBgCol
= colour
.IsOk();
1401 m_inheritBgCol
= m_hasBgCol
;
1402 m_backgroundColour
= colour
;
1403 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1407 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1409 if (colour
== m_foregroundColour
)
1412 m_hasFgCol
= colour
.IsOk();
1413 m_inheritFgCol
= m_hasFgCol
;
1414 m_foregroundColour
= colour
;
1415 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1419 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1421 // setting an invalid cursor is ok, it means that we don't have any special
1423 if ( m_cursor
.IsSameAs(cursor
) )
1434 wxFont
wxWindowBase::GetFont() const
1436 // logic is the same as in GetBackgroundColour()
1437 if ( !m_font
.IsOk() )
1439 wxASSERT_MSG( !m_hasFont
, wxT("we have invalid explicit font?") );
1441 wxFont font
= GetDefaultAttributes().font
;
1443 font
= GetClassDefaultAttributes().font
;
1451 bool wxWindowBase::SetFont(const wxFont
& font
)
1453 if ( font
== m_font
)
1460 m_hasFont
= font
.IsOk();
1461 m_inheritFont
= m_hasFont
;
1463 InvalidateBestSize();
1470 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1472 m_hasCustomPalette
= true;
1475 // VZ: can anyone explain me what do we do here?
1476 wxWindowDC
d((wxWindow
*) this);
1480 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1482 wxWindow
*win
= (wxWindow
*)this;
1483 while ( win
&& !win
->HasCustomPalette() )
1485 win
= win
->GetParent();
1491 #endif // wxUSE_PALETTE
1494 void wxWindowBase::SetCaret(wxCaret
*caret
)
1505 wxASSERT_MSG( m_caret
->GetWindow() == this,
1506 wxT("caret should be created associated to this window") );
1509 #endif // wxUSE_CARET
1511 #if wxUSE_VALIDATORS
1512 // ----------------------------------------------------------------------------
1514 // ----------------------------------------------------------------------------
1516 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1518 if ( m_windowValidator
)
1519 delete m_windowValidator
;
1521 m_windowValidator
= (wxValidator
*)validator
.Clone();
1523 if ( m_windowValidator
)
1524 m_windowValidator
->SetWindow(this);
1526 #endif // wxUSE_VALIDATORS
1528 // ----------------------------------------------------------------------------
1529 // update region stuff
1530 // ----------------------------------------------------------------------------
1532 wxRect
wxWindowBase::GetUpdateClientRect() const
1534 wxRegion rgnUpdate
= GetUpdateRegion();
1535 rgnUpdate
.Intersect(GetClientRect());
1536 wxRect rectUpdate
= rgnUpdate
.GetBox();
1537 wxPoint ptOrigin
= GetClientAreaOrigin();
1538 rectUpdate
.x
-= ptOrigin
.x
;
1539 rectUpdate
.y
-= ptOrigin
.y
;
1544 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1546 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1549 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1551 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1554 void wxWindowBase::ClearBackground()
1556 // wxGTK uses its own version, no need to add never used code
1558 wxClientDC
dc((wxWindow
*)this);
1559 wxBrush
brush(GetBackgroundColour(), wxBRUSHSTYLE_SOLID
);
1560 dc
.SetBackground(brush
);
1565 // ----------------------------------------------------------------------------
1566 // find child window by id or name
1567 // ----------------------------------------------------------------------------
1569 wxWindow
*wxWindowBase::FindWindow(long id
) const
1571 if ( id
== m_windowId
)
1572 return (wxWindow
*)this;
1574 wxWindowBase
*res
= NULL
;
1575 wxWindowList::compatibility_iterator node
;
1576 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1578 wxWindowBase
*child
= node
->GetData();
1579 res
= child
->FindWindow( id
);
1582 return (wxWindow
*)res
;
1585 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1587 if ( name
== m_windowName
)
1588 return (wxWindow
*)this;
1590 wxWindowBase
*res
= NULL
;
1591 wxWindowList::compatibility_iterator node
;
1592 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1594 wxWindow
*child
= node
->GetData();
1595 res
= child
->FindWindow(name
);
1598 return (wxWindow
*)res
;
1602 // find any window by id or name or label: If parent is non-NULL, look through
1603 // children for a label or title matching the specified string. If NULL, look
1604 // through all top-level windows.
1606 // to avoid duplicating code we reuse the same helper function but with
1607 // different comparators
1609 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1610 const wxString
& label
, long id
);
1613 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1616 return win
->GetLabel() == label
;
1620 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1623 return win
->GetName() == label
;
1627 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1630 return win
->GetId() == id
;
1633 // recursive helper for the FindWindowByXXX() functions
1635 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1636 const wxString
& label
,
1638 wxFindWindowCmp cmp
)
1642 // see if this is the one we're looking for
1643 if ( (*cmp
)(parent
, label
, id
) )
1644 return (wxWindow
*)parent
;
1646 // It wasn't, so check all its children
1647 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1649 node
= node
->GetNext() )
1651 // recursively check each child
1652 wxWindow
*win
= (wxWindow
*)node
->GetData();
1653 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1663 // helper for FindWindowByXXX()
1665 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1666 const wxString
& label
,
1668 wxFindWindowCmp cmp
)
1672 // just check parent and all its children
1673 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1676 // start at very top of wx's windows
1677 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1679 node
= node
->GetNext() )
1681 // recursively check each window & its children
1682 wxWindow
*win
= node
->GetData();
1683 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1693 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1695 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1700 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1702 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1706 // fall back to the label
1707 win
= FindWindowByLabel(title
, parent
);
1715 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1717 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1720 // ----------------------------------------------------------------------------
1721 // dialog oriented functions
1722 // ----------------------------------------------------------------------------
1724 void wxWindowBase::MakeModal(bool modal
)
1726 // Disable all other windows
1729 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1732 wxWindow
*win
= node
->GetData();
1734 win
->Enable(!modal
);
1736 node
= node
->GetNext();
1741 bool wxWindowBase::Validate()
1743 #if wxUSE_VALIDATORS
1744 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1746 wxWindowList::compatibility_iterator node
;
1747 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1749 wxWindowBase
*child
= node
->GetData();
1750 wxValidator
*validator
= child
->GetValidator();
1751 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1756 if ( recurse
&& !child
->Validate() )
1761 #endif // wxUSE_VALIDATORS
1766 bool wxWindowBase::TransferDataToWindow()
1768 #if wxUSE_VALIDATORS
1769 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1771 wxWindowList::compatibility_iterator node
;
1772 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1774 wxWindowBase
*child
= node
->GetData();
1775 wxValidator
*validator
= child
->GetValidator();
1776 if ( validator
&& !validator
->TransferToWindow() )
1778 wxLogWarning(_("Could not transfer data to window"));
1780 wxLog::FlushActive();
1788 if ( !child
->TransferDataToWindow() )
1790 // warning already given
1795 #endif // wxUSE_VALIDATORS
1800 bool wxWindowBase::TransferDataFromWindow()
1802 #if wxUSE_VALIDATORS
1803 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1805 wxWindowList::compatibility_iterator node
;
1806 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1808 wxWindow
*child
= node
->GetData();
1809 wxValidator
*validator
= child
->GetValidator();
1810 if ( validator
&& !validator
->TransferFromWindow() )
1812 // nop warning here because the application is supposed to give
1813 // one itself - we don't know here what might have gone wrongly
1820 if ( !child
->TransferDataFromWindow() )
1822 // warning already given
1827 #endif // wxUSE_VALIDATORS
1832 void wxWindowBase::InitDialog()
1834 wxInitDialogEvent
event(GetId());
1835 event
.SetEventObject( this );
1836 GetEventHandler()->ProcessEvent(event
);
1839 // ----------------------------------------------------------------------------
1840 // context-sensitive help support
1841 // ----------------------------------------------------------------------------
1845 // associate this help text with this window
1846 void wxWindowBase::SetHelpText(const wxString
& text
)
1848 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1851 helpProvider
->AddHelp(this, text
);
1855 #if WXWIN_COMPATIBILITY_2_8
1856 // associate this help text with all windows with the same id as this
1858 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1860 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1863 helpProvider
->AddHelp(GetId(), text
);
1866 #endif // WXWIN_COMPATIBILITY_2_8
1868 // get the help string associated with this window (may be empty)
1869 // default implementation forwards calls to the help provider
1871 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1872 wxHelpEvent::Origin
WXUNUSED(origin
)) const
1875 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1878 text
= helpProvider
->GetHelp(this);
1884 // show help for this window
1885 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1887 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1890 wxPoint pos
= event
.GetPosition();
1891 const wxHelpEvent::Origin origin
= event
.GetOrigin();
1892 if ( origin
== wxHelpEvent::Origin_Keyboard
)
1894 // if the help event was generated from keyboard it shouldn't
1895 // appear at the mouse position (which is still the only position
1896 // associated with help event) if the mouse is far away, although
1897 // we still do use the mouse position if it's over the window
1898 // because we suppose the user looks approximately at the mouse
1899 // already and so it would be more convenient than showing tooltip
1900 // at some arbitrary position which can be quite far from it
1901 const wxRect rectClient
= GetClientRect();
1902 if ( !rectClient
.Contains(ScreenToClient(pos
)) )
1904 // position help slightly under and to the right of this window
1905 pos
= ClientToScreen(wxPoint(
1907 rectClient
.height
+ GetCharHeight()
1912 if ( helpProvider
->ShowHelpAtPoint(this, pos
, origin
) )
1914 // skip the event.Skip() below
1922 #endif // wxUSE_HELP
1924 // ----------------------------------------------------------------------------
1926 // ----------------------------------------------------------------------------
1930 wxString
wxWindowBase::GetToolTipText() const
1932 return m_tooltip
? m_tooltip
->GetTip() : wxString();
1935 void wxWindowBase::SetToolTip( const wxString
&tip
)
1937 // don't create the new tooltip if we already have one
1940 m_tooltip
->SetTip( tip
);
1944 SetToolTip( new wxToolTip( tip
) );
1947 // setting empty tooltip text does not remove the tooltip any more - use
1948 // SetToolTip(NULL) for this
1951 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1953 if ( m_tooltip
!= tooltip
)
1958 m_tooltip
= tooltip
;
1962 #endif // wxUSE_TOOLTIPS
1964 // ----------------------------------------------------------------------------
1965 // constraints and sizers
1966 // ----------------------------------------------------------------------------
1968 #if wxUSE_CONSTRAINTS
1970 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1972 if ( m_constraints
)
1974 UnsetConstraints(m_constraints
);
1975 delete m_constraints
;
1977 m_constraints
= constraints
;
1978 if ( m_constraints
)
1980 // Make sure other windows know they're part of a 'meaningful relationship'
1981 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1982 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1983 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1984 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1985 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1986 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1987 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1988 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1989 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1990 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1991 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1992 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1993 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1994 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1995 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1996 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
2000 // This removes any dangling pointers to this window in other windows'
2001 // constraintsInvolvedIn lists.
2002 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
2006 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
2007 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
2008 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
2009 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
2010 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
2011 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
2012 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
2013 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
2014 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
2015 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
2016 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
2017 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
2018 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
2019 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
2020 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
2021 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
2025 // Back-pointer to other windows we're involved with, so if we delete this
2026 // window, we must delete any constraints we're involved with.
2027 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
2029 if ( !m_constraintsInvolvedIn
)
2030 m_constraintsInvolvedIn
= new wxWindowList
;
2031 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
2032 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
2035 // REMOVE back-pointer to other windows we're involved with.
2036 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
2038 if ( m_constraintsInvolvedIn
)
2039 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
2042 // Reset any constraints that mention this window
2043 void wxWindowBase::DeleteRelatedConstraints()
2045 if ( m_constraintsInvolvedIn
)
2047 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
2050 wxWindow
*win
= node
->GetData();
2051 wxLayoutConstraints
*constr
= win
->GetConstraints();
2053 // Reset any constraints involving this window
2056 constr
->left
.ResetIfWin(this);
2057 constr
->top
.ResetIfWin(this);
2058 constr
->right
.ResetIfWin(this);
2059 constr
->bottom
.ResetIfWin(this);
2060 constr
->width
.ResetIfWin(this);
2061 constr
->height
.ResetIfWin(this);
2062 constr
->centreX
.ResetIfWin(this);
2063 constr
->centreY
.ResetIfWin(this);
2066 wxWindowList::compatibility_iterator next
= node
->GetNext();
2067 m_constraintsInvolvedIn
->Erase(node
);
2071 wxDELETE(m_constraintsInvolvedIn
);
2075 #endif // wxUSE_CONSTRAINTS
2077 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
2079 if ( sizer
== m_windowSizer
)
2082 if ( m_windowSizer
)
2084 m_windowSizer
->SetContainingWindow(NULL
);
2087 delete m_windowSizer
;
2090 m_windowSizer
= sizer
;
2091 if ( m_windowSizer
)
2093 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
2096 SetAutoLayout(m_windowSizer
!= NULL
);
2099 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
2101 SetSizer( sizer
, deleteOld
);
2102 sizer
->SetSizeHints( (wxWindow
*) this );
2106 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
2108 // adding a window to a sizer twice is going to result in fatal and
2109 // hard to debug problems later because when deleting the second
2110 // associated wxSizerItem we're going to dereference a dangling
2111 // pointer; so try to detect this as early as possible
2112 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
2113 wxT("Adding a window to the same sizer twice?") );
2115 m_containingSizer
= sizer
;
2118 #if wxUSE_CONSTRAINTS
2120 void wxWindowBase::SatisfyConstraints()
2122 wxLayoutConstraints
*constr
= GetConstraints();
2123 bool wasOk
= constr
&& constr
->AreSatisfied();
2125 ResetConstraints(); // Mark all constraints as unevaluated
2129 // if we're a top level panel (i.e. our parent is frame/dialog), our
2130 // own constraints will never be satisfied any more unless we do it
2134 while ( noChanges
> 0 )
2136 LayoutPhase1(&noChanges
);
2140 LayoutPhase2(&noChanges
);
2143 #endif // wxUSE_CONSTRAINTS
2145 bool wxWindowBase::Layout()
2147 // If there is a sizer, use it instead of the constraints
2151 GetVirtualSize(&w
, &h
);
2152 GetSizer()->SetDimension( 0, 0, w
, h
);
2154 #if wxUSE_CONSTRAINTS
2157 SatisfyConstraints(); // Find the right constraints values
2158 SetConstraintSizes(); // Recursively set the real window sizes
2165 void wxWindowBase::InternalOnSize(wxSizeEvent
& event
)
2167 if ( GetAutoLayout() )
2173 #if wxUSE_CONSTRAINTS
2175 // first phase of the constraints evaluation: set our own constraints
2176 bool wxWindowBase::LayoutPhase1(int *noChanges
)
2178 wxLayoutConstraints
*constr
= GetConstraints();
2180 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
2183 // second phase: set the constraints for our children
2184 bool wxWindowBase::LayoutPhase2(int *noChanges
)
2191 // Layout grand children
2197 // Do a phase of evaluating child constraints
2198 bool wxWindowBase::DoPhase(int phase
)
2200 // the list containing the children for which the constraints are already
2202 wxWindowList succeeded
;
2204 // the max number of iterations we loop before concluding that we can't set
2206 static const int maxIterations
= 500;
2208 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
2212 // loop over all children setting their constraints
2213 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2215 node
= node
->GetNext() )
2217 wxWindow
*child
= node
->GetData();
2218 if ( child
->IsTopLevel() )
2220 // top level children are not inside our client area
2224 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
2226 // this one is either already ok or nothing we can do about it
2230 int tempNoChanges
= 0;
2231 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
2232 : child
->LayoutPhase2(&tempNoChanges
);
2233 noChanges
+= tempNoChanges
;
2237 succeeded
.Append(child
);
2243 // constraints are set
2251 void wxWindowBase::ResetConstraints()
2253 wxLayoutConstraints
*constr
= GetConstraints();
2256 constr
->left
.SetDone(false);
2257 constr
->top
.SetDone(false);
2258 constr
->right
.SetDone(false);
2259 constr
->bottom
.SetDone(false);
2260 constr
->width
.SetDone(false);
2261 constr
->height
.SetDone(false);
2262 constr
->centreX
.SetDone(false);
2263 constr
->centreY
.SetDone(false);
2266 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2269 wxWindow
*win
= node
->GetData();
2270 if ( !win
->IsTopLevel() )
2271 win
->ResetConstraints();
2272 node
= node
->GetNext();
2276 // Need to distinguish between setting the 'fake' size for windows and sizers,
2277 // and setting the real values.
2278 void wxWindowBase::SetConstraintSizes(bool recurse
)
2280 wxLayoutConstraints
*constr
= GetConstraints();
2281 if ( constr
&& constr
->AreSatisfied() )
2283 int x
= constr
->left
.GetValue();
2284 int y
= constr
->top
.GetValue();
2285 int w
= constr
->width
.GetValue();
2286 int h
= constr
->height
.GetValue();
2288 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
2289 (constr
->height
.GetRelationship() != wxAsIs
) )
2291 // We really shouldn't set negative sizes for the windows so make
2292 // them at least of 1*1 size
2293 SetSize(x
, y
, w
> 0 ? w
: 1, h
> 0 ? h
: 1);
2297 // If we don't want to resize this window, just move it...
2303 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
2304 GetClassInfo()->GetClassName(),
2310 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2313 wxWindow
*win
= node
->GetData();
2314 if ( !win
->IsTopLevel() && win
->GetConstraints() )
2315 win
->SetConstraintSizes();
2316 node
= node
->GetNext();
2321 // Only set the size/position of the constraint (if any)
2322 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
2324 wxLayoutConstraints
*constr
= GetConstraints();
2327 if ( x
!= wxDefaultCoord
)
2329 constr
->left
.SetValue(x
);
2330 constr
->left
.SetDone(true);
2332 if ( y
!= wxDefaultCoord
)
2334 constr
->top
.SetValue(y
);
2335 constr
->top
.SetDone(true);
2337 if ( w
!= wxDefaultCoord
)
2339 constr
->width
.SetValue(w
);
2340 constr
->width
.SetDone(true);
2342 if ( h
!= wxDefaultCoord
)
2344 constr
->height
.SetValue(h
);
2345 constr
->height
.SetDone(true);
2350 void wxWindowBase::MoveConstraint(int x
, int y
)
2352 wxLayoutConstraints
*constr
= GetConstraints();
2355 if ( x
!= wxDefaultCoord
)
2357 constr
->left
.SetValue(x
);
2358 constr
->left
.SetDone(true);
2360 if ( y
!= wxDefaultCoord
)
2362 constr
->top
.SetValue(y
);
2363 constr
->top
.SetDone(true);
2368 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2370 wxLayoutConstraints
*constr
= GetConstraints();
2373 *w
= constr
->width
.GetValue();
2374 *h
= constr
->height
.GetValue();
2380 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2382 wxLayoutConstraints
*constr
= GetConstraints();
2385 *w
= constr
->width
.GetValue();
2386 *h
= constr
->height
.GetValue();
2389 GetClientSize(w
, h
);
2392 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2394 wxLayoutConstraints
*constr
= GetConstraints();
2397 *x
= constr
->left
.GetValue();
2398 *y
= constr
->top
.GetValue();
2404 #endif // wxUSE_CONSTRAINTS
2406 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2408 // don't do it for the dialogs/frames - they float independently of their
2410 if ( !IsTopLevel() )
2412 wxWindow
*parent
= GetParent();
2413 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2415 wxPoint
pt(parent
->GetClientAreaOrigin());
2422 // ----------------------------------------------------------------------------
2423 // Update UI processing
2424 // ----------------------------------------------------------------------------
2426 void wxWindowBase::UpdateWindowUI(long flags
)
2428 wxUpdateUIEvent
event(GetId());
2429 event
.SetEventObject(this);
2431 if ( GetEventHandler()->ProcessEvent(event
) )
2433 DoUpdateWindowUI(event
);
2436 if (flags
& wxUPDATE_UI_RECURSE
)
2438 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2441 wxWindow
* child
= (wxWindow
*) node
->GetData();
2442 child
->UpdateWindowUI(flags
);
2443 node
= node
->GetNext();
2448 // do the window-specific processing after processing the update event
2449 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2451 if ( event
.GetSetEnabled() )
2452 Enable(event
.GetEnabled());
2454 if ( event
.GetSetShown() )
2455 Show(event
.GetShown());
2458 // ----------------------------------------------------------------------------
2459 // dialog units translations
2460 // ----------------------------------------------------------------------------
2462 // Windows' computes dialog units using average character width over upper-
2463 // and lower-case ASCII alphabet and not using the average character width
2464 // metadata stored in the font; see
2465 // http://support.microsoft.com/default.aspx/kb/145994 for detailed discussion.
2466 // It's important that we perform the conversion in identical way, because
2467 // dialog units natively exist only on Windows and Windows HIG is expressed
2469 wxSize
wxWindowBase::GetDlgUnitBase() const
2471 const wxWindow
*parent
= wxGetTopLevelParent((wxWindow
*)this);
2473 if ( !parent
->m_font
.IsOk() )
2475 // Default GUI font is used. This is the most common case, so
2476 // cache the results.
2477 static wxSize s_defFontSize
;
2478 if ( s_defFontSize
.x
== 0 )
2479 s_defFontSize
= wxPrivate::GetAverageASCIILetterSize(*parent
);
2480 return s_defFontSize
;
2484 // Custom font, we always need to compute the result
2485 return wxPrivate::GetAverageASCIILetterSize(*parent
);
2489 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
) const
2491 const wxSize base
= GetDlgUnitBase();
2493 // NB: wxMulDivInt32() is used, because it correctly rounds the result
2495 wxPoint pt2
= wxDefaultPosition
;
2496 if (pt
.x
!= wxDefaultCoord
)
2497 pt2
.x
= wxMulDivInt32(pt
.x
, 4, base
.x
);
2498 if (pt
.y
!= wxDefaultCoord
)
2499 pt2
.y
= wxMulDivInt32(pt
.y
, 8, base
.y
);
2504 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
) const
2506 const wxSize base
= GetDlgUnitBase();
2508 wxPoint pt2
= wxDefaultPosition
;
2509 if (pt
.x
!= wxDefaultCoord
)
2510 pt2
.x
= wxMulDivInt32(pt
.x
, base
.x
, 4);
2511 if (pt
.y
!= wxDefaultCoord
)
2512 pt2
.y
= wxMulDivInt32(pt
.y
, base
.y
, 8);
2517 // ----------------------------------------------------------------------------
2519 // ----------------------------------------------------------------------------
2521 // propagate the colour change event to the subwindows
2522 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
2524 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2527 // Only propagate to non-top-level windows
2528 wxWindow
*win
= node
->GetData();
2529 if ( !win
->IsTopLevel() )
2531 wxSysColourChangedEvent event2
;
2532 event2
.SetEventObject(win
);
2533 win
->GetEventHandler()->ProcessEvent(event2
);
2536 node
= node
->GetNext();
2542 // the default action is to populate dialog with data when it's created,
2543 // and nudge the UI into displaying itself correctly in case
2544 // we've turned the wxUpdateUIEvents frequency down low.
2545 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2547 TransferDataToWindow();
2549 // Update the UI at this point
2550 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2553 // ----------------------------------------------------------------------------
2554 // menu-related functions
2555 // ----------------------------------------------------------------------------
2559 bool wxWindowBase::PopupMenu(wxMenu
*menu
, int x
, int y
)
2561 wxCHECK_MSG( menu
, false, "can't popup NULL menu" );
2563 wxMenuInvokingWindowSetter
2564 setInvokingWin(*menu
, static_cast<wxWindow
*>(this));
2566 wxCurrentPopupMenu
= menu
;
2567 const bool rc
= DoPopupMenu(menu
, x
, y
);
2568 wxCurrentPopupMenu
= NULL
;
2573 // this is used to pass the id of the selected item from the menu event handler
2574 // to the main function itself
2576 // it's ok to use a global here as there can be at most one popup menu shown at
2578 static int gs_popupMenuSelection
= wxID_NONE
;
2580 void wxWindowBase::InternalOnPopupMenu(wxCommandEvent
& event
)
2582 // store the id in a global variable where we'll retrieve it from later
2583 gs_popupMenuSelection
= event
.GetId();
2586 void wxWindowBase::InternalOnPopupMenuUpdate(wxUpdateUIEvent
& WXUNUSED(event
))
2588 // nothing to do but do not skip it
2592 wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu
& menu
, int x
, int y
)
2594 gs_popupMenuSelection
= wxID_NONE
;
2596 Connect(wxEVT_COMMAND_MENU_SELECTED
,
2597 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2601 // it is common to construct the menu passed to this function dynamically
2602 // using some fixed range of ids which could clash with the ids used
2603 // elsewhere in the program, which could result in some menu items being
2604 // unintentionally disabled or otherwise modified by update UI handlers
2605 // elsewhere in the program code and this is difficult to avoid in the
2606 // program itself, so instead we just temporarily suspend UI updating while
2607 // this menu is shown
2608 Connect(wxEVT_UPDATE_UI
,
2609 wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate
),
2613 PopupMenu(&menu
, x
, y
);
2615 Disconnect(wxEVT_UPDATE_UI
,
2616 wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate
),
2619 Disconnect(wxEVT_COMMAND_MENU_SELECTED
,
2620 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2624 return gs_popupMenuSelection
;
2627 #endif // wxUSE_MENUS
2629 // methods for drawing the sizers in a visible way: this is currently only
2630 // enabled for "full debug" builds with wxDEBUG_LEVEL==2 as it doesn't work
2631 // that well and also because we don't want to leave it enabled in default
2632 // builds used for production
2633 #if wxDEBUG_LEVEL > 1
2635 static void DrawSizers(wxWindowBase
*win
);
2637 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
, const wxPen
* pen
)
2639 wxClientDC
dc((wxWindow
*)win
);
2641 dc
.SetBrush(fill
? wxBrush(pen
->GetColour(), wxBRUSHSTYLE_CROSSDIAG_HATCH
) :
2642 *wxTRANSPARENT_BRUSH
);
2643 dc
.DrawRectangle(rect
.Deflate(1, 1));
2646 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2648 const wxSizerItemList
& items
= sizer
->GetChildren();
2649 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2654 wxSizerItem
*item
= *i
;
2655 if ( item
->IsSizer() )
2657 DrawBorder(win
, item
->GetRect().Deflate(2), false, wxRED_PEN
);
2658 DrawSizer(win
, item
->GetSizer());
2660 else if ( item
->IsSpacer() )
2662 DrawBorder(win
, item
->GetRect().Deflate(2), true, wxBLUE_PEN
);
2664 else if ( item
->IsWindow() )
2666 DrawSizers(item
->GetWindow());
2669 wxFAIL_MSG("inconsistent wxSizerItem status!");
2673 static void DrawSizers(wxWindowBase
*win
)
2675 DrawBorder(win
, win
->GetClientSize(), false, wxGREEN_PEN
);
2677 wxSizer
*sizer
= win
->GetSizer();
2680 DrawSizer(win
, sizer
);
2682 else // no sizer, still recurse into the children
2684 const wxWindowList
& children
= win
->GetChildren();
2685 for ( wxWindowList::const_iterator i
= children
.begin(),
2686 end
= children
.end();
2693 // show all kind of sizes of this window; see the "window sizing" topic
2694 // overview for more info about the various differences:
2695 wxSize fullSz
= win
->GetSize();
2696 wxSize clientSz
= win
->GetClientSize();
2697 wxSize bestSz
= win
->GetBestSize();
2698 wxSize minSz
= win
->GetMinSize();
2699 wxSize maxSz
= win
->GetMaxSize();
2700 wxSize virtualSz
= win
->GetVirtualSize();
2702 wxMessageOutputDebug dbgout
;
2704 "%-10s => fullsz=%4d;%-4d clientsz=%4d;%-4d bestsz=%4d;%-4d minsz=%4d;%-4d maxsz=%4d;%-4d virtualsz=%4d;%-4d\n",
2707 clientSz
.x
, clientSz
.y
,
2711 virtualSz
.x
, virtualSz
.y
);
2715 #endif // wxDEBUG_LEVEL
2717 // process special middle clicks
2718 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2720 if ( event
.ControlDown() && event
.AltDown() )
2722 #if wxDEBUG_LEVEL > 1
2723 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2724 if ( event
.ShiftDown() )
2729 #endif // __WXDEBUG__
2731 // just Ctrl-Alt-middle click shows information about wx version
2732 ::wxInfoMessageBox((wxWindow
*)this);
2741 // ----------------------------------------------------------------------------
2743 // ----------------------------------------------------------------------------
2745 #if wxUSE_ACCESSIBILITY
2746 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2748 if (m_accessible
&& (accessible
!= m_accessible
))
2749 delete m_accessible
;
2750 m_accessible
= accessible
;
2752 m_accessible
->SetWindow((wxWindow
*) this);
2755 // Returns the accessible object, creating if necessary.
2756 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2759 m_accessible
= CreateAccessible();
2760 return m_accessible
;
2763 // Override to create a specific accessible object.
2764 wxAccessible
* wxWindowBase::CreateAccessible()
2766 return new wxWindowAccessible((wxWindow
*) this);
2771 // ----------------------------------------------------------------------------
2772 // list classes implementation
2773 // ----------------------------------------------------------------------------
2777 #include "wx/listimpl.cpp"
2778 WX_DEFINE_LIST(wxWindowList
)
2782 void wxWindowListNode::DeleteData()
2784 delete (wxWindow
*)GetData();
2787 #endif // wxUSE_STL/!wxUSE_STL
2789 // ----------------------------------------------------------------------------
2791 // ----------------------------------------------------------------------------
2793 wxBorder
wxWindowBase::GetBorder(long flags
) const
2795 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2796 if ( border
== wxBORDER_DEFAULT
)
2798 border
= GetDefaultBorder();
2800 else if ( border
== wxBORDER_THEME
)
2802 border
= GetDefaultBorderForControl();
2808 wxBorder
wxWindowBase::GetDefaultBorder() const
2810 return wxBORDER_NONE
;
2813 // ----------------------------------------------------------------------------
2815 // ----------------------------------------------------------------------------
2817 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2819 // here we just check if the point is inside the window or not
2821 // check the top and left border first
2822 bool outside
= x
< 0 || y
< 0;
2825 // check the right and bottom borders too
2826 wxSize size
= GetSize();
2827 outside
= x
>= size
.x
|| y
>= size
.y
;
2830 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2833 // ----------------------------------------------------------------------------
2835 // ----------------------------------------------------------------------------
2837 struct WXDLLEXPORT wxWindowNext
2841 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2842 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2843 bool wxWindowBase::ms_winCaptureChanging
= false;
2845 void wxWindowBase::CaptureMouse()
2847 wxLogTrace(wxT("mousecapture"), wxT("CaptureMouse(%p)"), static_cast<void*>(this));
2849 wxASSERT_MSG( !ms_winCaptureChanging
, wxT("recursive CaptureMouse call?") );
2851 ms_winCaptureChanging
= true;
2853 wxWindow
*winOld
= GetCapture();
2856 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2859 wxWindowNext
*item
= new wxWindowNext
;
2861 item
->next
= ms_winCaptureNext
;
2862 ms_winCaptureNext
= item
;
2864 //else: no mouse capture to save
2867 ms_winCaptureCurrent
= (wxWindow
*)this;
2869 ms_winCaptureChanging
= false;
2872 void wxWindowBase::ReleaseMouse()
2874 wxLogTrace(wxT("mousecapture"), wxT("ReleaseMouse(%p)"), static_cast<void*>(this));
2876 wxASSERT_MSG( !ms_winCaptureChanging
, wxT("recursive ReleaseMouse call?") );
2878 wxASSERT_MSG( GetCapture() == this,
2879 "attempt to release mouse, but this window hasn't captured it" );
2880 wxASSERT_MSG( ms_winCaptureCurrent
== this,
2881 "attempt to release mouse, but this window hasn't captured it" );
2883 ms_winCaptureChanging
= true;
2886 ms_winCaptureCurrent
= NULL
;
2888 if ( ms_winCaptureNext
)
2890 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2891 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2893 wxWindowNext
*item
= ms_winCaptureNext
;
2894 ms_winCaptureNext
= item
->next
;
2897 //else: stack is empty, no previous capture
2899 ms_winCaptureChanging
= false;
2901 wxLogTrace(wxT("mousecapture"),
2902 (const wxChar
*) wxT("After ReleaseMouse() mouse is captured by %p"),
2903 static_cast<void*>(GetCapture()));
2906 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2908 wxMouseCaptureLostEvent
event(win
->GetId());
2909 event
.SetEventObject(win
);
2910 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2912 // windows must handle this event, otherwise the app wouldn't behave
2913 // correctly if it loses capture unexpectedly; see the discussion here:
2914 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
2915 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
2916 wxFAIL_MSG( wxT("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2921 void wxWindowBase::NotifyCaptureLost()
2923 // don't do anything if capture lost was expected, i.e. resulted from
2924 // a wx call to ReleaseMouse or CaptureMouse:
2925 if ( ms_winCaptureChanging
)
2928 // if the capture was lost unexpectedly, notify every window that has
2929 // capture (on stack or current) about it and clear the stack:
2931 if ( ms_winCaptureCurrent
)
2933 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2934 ms_winCaptureCurrent
= NULL
;
2937 while ( ms_winCaptureNext
)
2939 wxWindowNext
*item
= ms_winCaptureNext
;
2940 ms_winCaptureNext
= item
->next
;
2942 DoNotifyWindowAboutCaptureLost(item
->win
);
2951 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2952 int WXUNUSED(modifiers
),
2953 int WXUNUSED(keycode
))
2959 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2965 #endif // wxUSE_HOTKEY
2967 // ----------------------------------------------------------------------------
2969 // ----------------------------------------------------------------------------
2971 bool wxWindowBase::TryBefore(wxEvent
& event
)
2973 #if wxUSE_VALIDATORS
2974 // Can only use the validator of the window which
2975 // is receiving the event
2976 if ( event
.GetEventObject() == this )
2978 wxValidator
* const validator
= GetValidator();
2979 if ( validator
&& validator
->ProcessEventLocally(event
) )
2984 #endif // wxUSE_VALIDATORS
2986 return wxEvtHandler::TryBefore(event
);
2989 bool wxWindowBase::TryAfter(wxEvent
& event
)
2991 // carry on up the parent-child hierarchy if the propagation count hasn't
2993 if ( event
.ShouldPropagate() )
2995 // honour the requests to stop propagation at this window: this is
2996 // used by the dialogs, for example, to prevent processing the events
2997 // from the dialog controls in the parent frame which rarely, if ever,
2999 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
3001 wxWindow
*parent
= GetParent();
3002 if ( parent
&& !parent
->IsBeingDeleted() )
3004 wxPropagateOnce
propagateOnce(event
);
3006 return parent
->GetEventHandler()->ProcessEvent(event
);
3011 return wxEvtHandler::TryAfter(event
);
3014 // ----------------------------------------------------------------------------
3015 // window relationships
3016 // ----------------------------------------------------------------------------
3018 wxWindow
*wxWindowBase::DoGetSibling(WindowOrder order
) const
3020 wxCHECK_MSG( GetParent(), NULL
,
3021 wxT("GetPrev/NextSibling() don't work for TLWs!") );
3023 wxWindowList
& siblings
= GetParent()->GetChildren();
3024 wxWindowList::compatibility_iterator i
= siblings
.Find((wxWindow
*)this);
3025 wxCHECK_MSG( i
, NULL
, wxT("window not a child of its parent?") );
3027 if ( order
== OrderBefore
)
3028 i
= i
->GetPrevious();
3032 return i
? i
->GetData() : NULL
;
3035 // ----------------------------------------------------------------------------
3036 // keyboard navigation
3037 // ----------------------------------------------------------------------------
3039 // Navigates in the specified direction inside this window
3040 bool wxWindowBase::DoNavigateIn(int flags
)
3042 #ifdef wxHAS_NATIVE_TAB_TRAVERSAL
3043 // native code doesn't process our wxNavigationKeyEvents anyhow
3046 #else // !wxHAS_NATIVE_TAB_TRAVERSAL
3047 wxNavigationKeyEvent eventNav
;
3048 wxWindow
*focused
= FindFocus();
3049 eventNav
.SetCurrentFocus(focused
);
3050 eventNav
.SetEventObject(focused
);
3051 eventNav
.SetFlags(flags
);
3052 return GetEventHandler()->ProcessEvent(eventNav
);
3053 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
3056 bool wxWindowBase::HandleAsNavigationKey(const wxKeyEvent
& event
)
3058 if ( event
.GetKeyCode() != WXK_TAB
)
3061 int flags
= wxNavigationKeyEvent::FromTab
;
3063 if ( event
.ShiftDown() )
3064 flags
|= wxNavigationKeyEvent::IsBackward
;
3066 flags
|= wxNavigationKeyEvent::IsForward
;
3068 if ( event
.ControlDown() )
3069 flags
|= wxNavigationKeyEvent::WinChange
;
3075 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, WindowOrder move
)
3077 // check that we're not a top level window
3078 wxCHECK_RET( GetParent(),
3079 wxT("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
3081 // detect the special case when we have nothing to do anyhow and when the
3082 // code below wouldn't work
3086 // find the target window in the siblings list
3087 wxWindowList
& siblings
= GetParent()->GetChildren();
3088 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
3089 wxCHECK_RET( i
, wxT("MoveBefore/AfterInTabOrder(): win is not a sibling") );
3091 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
3092 // can't just move the node around
3093 wxWindow
*self
= (wxWindow
*)this;
3094 siblings
.DeleteObject(self
);
3095 if ( move
== OrderAfter
)
3102 siblings
.Insert(i
, self
);
3104 else // OrderAfter and win was the last sibling
3106 siblings
.Append(self
);
3110 // ----------------------------------------------------------------------------
3112 // ----------------------------------------------------------------------------
3114 /*static*/ wxWindow
* wxWindowBase::FindFocus()
3116 wxWindowBase
*win
= DoFindFocus();
3117 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
3120 bool wxWindowBase::HasFocus() const
3122 wxWindowBase
*win
= DoFindFocus();
3123 return win
== this ||
3124 win
== wxConstCast(this, wxWindowBase
)->GetMainWindowOfCompositeControl();
3127 // ----------------------------------------------------------------------------
3129 // ----------------------------------------------------------------------------
3131 #if wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
3136 class DragAcceptFilesTarget
: public wxFileDropTarget
3139 DragAcceptFilesTarget(wxWindowBase
*win
) : m_win(win
) {}
3141 virtual bool OnDropFiles(wxCoord x
, wxCoord y
,
3142 const wxArrayString
& filenames
)
3144 wxDropFilesEvent
event(wxEVT_DROP_FILES
,
3146 wxCArrayString(filenames
).Release());
3147 event
.SetEventObject(m_win
);
3151 return m_win
->HandleWindowEvent(event
);
3155 wxWindowBase
* const m_win
;
3157 wxDECLARE_NO_COPY_CLASS(DragAcceptFilesTarget
);
3161 } // anonymous namespace
3163 // Generic version of DragAcceptFiles(). It works by installing a simple
3164 // wxFileDropTarget-to-EVT_DROP_FILES adaptor and therefore cannot be used
3165 // together with explicit SetDropTarget() calls.
3166 void wxWindowBase::DragAcceptFiles(bool accept
)
3170 wxASSERT_MSG( !GetDropTarget(),
3171 "cannot use DragAcceptFiles() and SetDropTarget() together" );
3172 SetDropTarget(new DragAcceptFilesTarget(this));
3176 SetDropTarget(NULL
);
3180 #endif // wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
3182 // ----------------------------------------------------------------------------
3184 // ----------------------------------------------------------------------------
3186 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
3188 while ( win
&& !win
->IsTopLevel() )
3189 win
= win
->GetParent();
3194 #if wxUSE_ACCESSIBILITY
3195 // ----------------------------------------------------------------------------
3196 // accessible object for windows
3197 // ----------------------------------------------------------------------------
3199 // Can return either a child object, or an integer
3200 // representing the child element, starting from 1.
3201 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
3203 wxASSERT( GetWindow() != NULL
);
3207 return wxACC_NOT_IMPLEMENTED
;
3210 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
3211 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
3213 wxASSERT( GetWindow() != NULL
);
3217 wxWindow
* win
= NULL
;
3224 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
3226 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
3233 rect
= win
->GetRect();
3234 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
3235 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
3239 return wxACC_NOT_IMPLEMENTED
;
3242 // Navigates from fromId to toId/toObject.
3243 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
3244 int* WXUNUSED(toId
), wxAccessible
** toObject
)
3246 wxASSERT( GetWindow() != NULL
);
3252 case wxNAVDIR_FIRSTCHILD
:
3254 if (GetWindow()->GetChildren().GetCount() == 0)
3256 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
3257 *toObject
= childWindow
->GetOrCreateAccessible();
3261 case wxNAVDIR_LASTCHILD
:
3263 if (GetWindow()->GetChildren().GetCount() == 0)
3265 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
3266 *toObject
= childWindow
->GetOrCreateAccessible();
3270 case wxNAVDIR_RIGHT
:
3274 wxWindowList::compatibility_iterator node
=
3275 wxWindowList::compatibility_iterator();
3278 // Can't navigate to sibling of this window
3279 // if we're a top-level window.
3280 if (!GetWindow()->GetParent())
3281 return wxACC_NOT_IMPLEMENTED
;
3283 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3287 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
3288 node
= GetWindow()->GetChildren().Item(fromId
-1);
3291 if (node
&& node
->GetNext())
3293 wxWindow
* nextWindow
= node
->GetNext()->GetData();
3294 *toObject
= nextWindow
->GetOrCreateAccessible();
3302 case wxNAVDIR_PREVIOUS
:
3304 wxWindowList::compatibility_iterator node
=
3305 wxWindowList::compatibility_iterator();
3308 // Can't navigate to sibling of this window
3309 // if we're a top-level window.
3310 if (!GetWindow()->GetParent())
3311 return wxACC_NOT_IMPLEMENTED
;
3313 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3317 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
3318 node
= GetWindow()->GetChildren().Item(fromId
-1);
3321 if (node
&& node
->GetPrevious())
3323 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
3324 *toObject
= previousWindow
->GetOrCreateAccessible();
3332 return wxACC_NOT_IMPLEMENTED
;
3335 // Gets the name of the specified object.
3336 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
3338 wxASSERT( GetWindow() != NULL
);
3344 // If a child, leave wxWidgets to call the function on the actual
3347 return wxACC_NOT_IMPLEMENTED
;
3349 // This will eventually be replaced by specialised
3350 // accessible classes, one for each kind of wxWidgets
3351 // control or window.
3353 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
3354 title
= ((wxButton
*) GetWindow())->GetLabel();
3357 title
= GetWindow()->GetName();
3365 return wxACC_NOT_IMPLEMENTED
;
3368 // Gets the number of children.
3369 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
3371 wxASSERT( GetWindow() != NULL
);
3375 *childId
= (int) GetWindow()->GetChildren().GetCount();
3379 // Gets the specified child (starting from 1).
3380 // If *child is NULL and return value is wxACC_OK,
3381 // this means that the child is a simple element and
3382 // not an accessible object.
3383 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
3385 wxASSERT( GetWindow() != NULL
);
3395 if (childId
> (int) GetWindow()->GetChildren().GetCount())
3398 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
3399 *child
= childWindow
->GetOrCreateAccessible();
3406 // Gets the parent, or NULL.
3407 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
3409 wxASSERT( GetWindow() != NULL
);
3413 wxWindow
* parentWindow
= GetWindow()->GetParent();
3421 *parent
= parentWindow
->GetOrCreateAccessible();
3429 // Performs the default action. childId is 0 (the action for this object)
3430 // or > 0 (the action for a child).
3431 // Return wxACC_NOT_SUPPORTED if there is no default action for this
3432 // window (e.g. an edit control).
3433 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
3435 wxASSERT( GetWindow() != NULL
);
3439 return wxACC_NOT_IMPLEMENTED
;
3442 // Gets the default action for this object (0) or > 0 (the action for a child).
3443 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
3444 // string if there is no action.
3445 // The retrieved string describes the action that is performed on an object,
3446 // not what the object does as a result. For example, a toolbar button that prints
3447 // a document has a default action of "Press" rather than "Prints the current document."
3448 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
3450 wxASSERT( GetWindow() != NULL
);
3454 return wxACC_NOT_IMPLEMENTED
;
3457 // Returns the description for this object or a child.
3458 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
3460 wxASSERT( GetWindow() != NULL
);
3464 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3470 return wxACC_NOT_IMPLEMENTED
;
3473 // Returns help text for this object or a child, similar to tooltip text.
3474 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
3476 wxASSERT( GetWindow() != NULL
);
3480 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3486 return wxACC_NOT_IMPLEMENTED
;
3489 // Returns the keyboard shortcut for this object or child.
3490 // Return e.g. ALT+K
3491 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
3493 wxASSERT( GetWindow() != NULL
);
3497 return wxACC_NOT_IMPLEMENTED
;
3500 // Returns a role constant.
3501 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
3503 wxASSERT( GetWindow() != NULL
);
3507 // If a child, leave wxWidgets to call the function on the actual
3510 return wxACC_NOT_IMPLEMENTED
;
3512 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3513 return wxACC_NOT_IMPLEMENTED
;
3515 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3516 return wxACC_NOT_IMPLEMENTED
;
3519 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3520 return wxACC_NOT_IMPLEMENTED
;
3523 //*role = wxROLE_SYSTEM_CLIENT;
3524 *role
= wxROLE_SYSTEM_CLIENT
;
3528 return wxACC_NOT_IMPLEMENTED
;
3532 // Returns a state constant.
3533 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
3535 wxASSERT( GetWindow() != NULL
);
3539 // If a child, leave wxWidgets to call the function on the actual
3542 return wxACC_NOT_IMPLEMENTED
;
3544 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3545 return wxACC_NOT_IMPLEMENTED
;
3548 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3549 return wxACC_NOT_IMPLEMENTED
;
3552 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3553 return wxACC_NOT_IMPLEMENTED
;
3560 return wxACC_NOT_IMPLEMENTED
;
3564 // Returns a localized string representing the value for the object
3566 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3568 wxASSERT( GetWindow() != NULL
);
3572 return wxACC_NOT_IMPLEMENTED
;
3575 // Selects the object or child.
3576 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3578 wxASSERT( GetWindow() != NULL
);
3582 return wxACC_NOT_IMPLEMENTED
;
3585 // Gets the window with the keyboard focus.
3586 // If childId is 0 and child is NULL, no object in
3587 // this subhierarchy has the focus.
3588 // If this object has the focus, child should be 'this'.
3589 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3591 wxASSERT( GetWindow() != NULL
);
3595 return wxACC_NOT_IMPLEMENTED
;
3599 // Gets a variant representing the selected children
3601 // Acceptable values:
3602 // - a null variant (IsNull() returns true)
3603 // - a list variant (GetType() == wxT("list")
3604 // - an integer representing the selected child element,
3605 // or 0 if this object is selected (GetType() == wxT("long")
3606 // - a "void*" pointer to a wxAccessible child object
3607 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3609 wxASSERT( GetWindow() != NULL
);
3613 return wxACC_NOT_IMPLEMENTED
;
3615 #endif // wxUSE_VARIANT
3617 #endif // wxUSE_ACCESSIBILITY
3619 // ----------------------------------------------------------------------------
3621 // ----------------------------------------------------------------------------
3624 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3626 wxCoord widthTotal
) const
3628 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3630 x
= widthTotal
- x
- width
;