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 extern WXDLLEXPORT_DATA(const char) wxPanelNameStr
[] = "panel";
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
97 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
104 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
105 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
106 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
109 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
112 EVT_SIZE(wxWindowBase::InternalOnSize
)
115 // ============================================================================
116 // implementation of the common functionality of the wxWindow class
117 // ============================================================================
119 // ----------------------------------------------------------------------------
121 // ----------------------------------------------------------------------------
123 #if wxUSE_EXTENDED_RTTI
125 // windows that are created from a parent window during its Create method,
126 // eg. spin controls in a calendar controls must never been streamed out
127 // separately otherwise chaos occurs. Right now easiest is to test for negative ids,
128 // as windows with negative ids never can be recreated anyway
130 bool wxWindowStreamingCallback( const wxObject
*object
, wxObjectWriter
*,
131 wxObjectReaderCallback
*, wxVariantBaseArray
& )
133 const wxWindow
* win
= wx_dynamic_cast(const wxWindow
*, object
);
134 if ( win
&& win
->GetId() < 0 )
139 wxIMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
, "wx/window.h", \
140 wxWindowStreamingCallback
)
142 // make wxWindowList known before the property is used
144 wxCOLLECTION_TYPE_INFO( wxWindow
*, wxWindowList
);
146 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
,
147 wxVariantBaseArray
&value
)
149 wxListCollectionToVariantArray
<wxWindowList::compatibility_iterator
>( theList
, value
);
152 wxDEFINE_FLAGS( wxWindowStyle
)
154 wxBEGIN_FLAGS( wxWindowStyle
)
155 // new style border flags, we put them first to
156 // use them for streaming out
158 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
159 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
160 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
161 wxFLAGS_MEMBER(wxBORDER_RAISED
)
162 wxFLAGS_MEMBER(wxBORDER_STATIC
)
163 wxFLAGS_MEMBER(wxBORDER_NONE
)
165 // old style border flags
166 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
167 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
168 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
169 wxFLAGS_MEMBER(wxRAISED_BORDER
)
170 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
171 wxFLAGS_MEMBER(wxBORDER
)
173 // standard window styles
174 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
175 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
176 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
177 wxFLAGS_MEMBER(wxWANTS_CHARS
)
178 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
179 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
180 wxFLAGS_MEMBER(wxVSCROLL
)
181 wxFLAGS_MEMBER(wxHSCROLL
)
183 wxEND_FLAGS( wxWindowStyle
)
185 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
186 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
187 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
188 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
189 // Always constructor Properties first
191 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, wxEMPTY_PARAMETER_VALUE
, \
192 0 /*flags*/, wxT("Helpstring"), wxT("group"))
193 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, -1 /*wxID_ANY*/, 0 /*flags*/, \
194 wxT("Helpstring"), wxT("group") )
195 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, \
196 0 /*flags*/, wxT("Helpstring"), wxT("group")) // pos
197 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/, \
198 wxT("Helpstring"), wxT("group")) // size
199 wxPROPERTY( WindowStyle
, long, SetWindowStyleFlag
, GetWindowStyleFlag
, \
200 wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, wxT("Helpstring"), wxT("group")) // style
201 wxPROPERTY( Name
,wxString
, SetName
, GetName
, wxEmptyString
, 0 /*flags*/, \
202 wxT("Helpstring"), wxT("group") )
204 // Then all relations of the object graph
206 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
*, \
207 GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/, \
208 wxT("Helpstring"), wxT("group"))
210 // and finally all other properties
212 wxPROPERTY( ExtraStyle
, long, SetExtraStyle
, GetExtraStyle
, wxEMPTY_PARAMETER_VALUE
, \
213 0 /*flags*/, wxT("Helpstring"), wxT("group")) // extstyle
214 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, \
215 wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, wxT("Helpstring"), wxT("group")) // bg
216 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, \
217 wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, wxT("Helpstring"), wxT("group")) // fg
218 wxPROPERTY( Enabled
, bool, Enable
, IsEnabled
, wxVariantBase((bool)true), 0 /*flags*/, \
219 wxT("Helpstring"), wxT("group"))
220 wxPROPERTY( Shown
, bool, Show
, IsShown
, wxVariantBase((bool)true), 0 /*flags*/, \
221 wxT("Helpstring"), wxT("group"))
224 // possible property candidates (not in xrc) or not valid in all subclasses
225 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxEmptyString
)
226 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
227 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxEmptyString
)
228 // MaxHeight, Width, MinHeight, Width
229 // TODO switch label to control and title to toplevels
231 wxPROPERTY( ThemeEnabled
, bool, SetThemeEnabled
, GetThemeEnabled
, )
232 //wxPROPERTY( Cursor, wxCursor, SetCursor, GetCursor, )
233 // wxPROPERTY( ToolTip, wxString, SetToolTip, GetToolTipText, )
234 wxPROPERTY( AutoLayout
, bool, SetAutoLayout
, GetAutoLayout
, )
236 wxEND_PROPERTIES_TABLE()
238 wxEMPTY_HANDLERS_TABLE(wxWindow
)
240 wxCONSTRUCTOR_DUMMY(wxWindow
)
244 #ifndef __WXUNIVERSAL__
245 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
250 // ----------------------------------------------------------------------------
252 // ----------------------------------------------------------------------------
254 // the default initialization
255 wxWindowBase::wxWindowBase()
257 // no window yet, no parent nor children
259 m_windowId
= wxID_ANY
;
261 // no constraints on the minimal window size
263 m_maxWidth
= wxDefaultCoord
;
265 m_maxHeight
= wxDefaultCoord
;
267 // invalidiated cache value
268 m_bestSizeCache
= wxDefaultSize
;
270 // window are created enabled and visible by default
274 // the default event handler is just this window
275 m_eventHandler
= this;
279 m_windowValidator
= NULL
;
280 #endif // wxUSE_VALIDATORS
282 // the colours/fonts are default for now, so leave m_font,
283 // m_backgroundColour and m_foregroundColour uninitialized and set those
289 m_inheritFont
= false;
295 m_backgroundStyle
= wxBG_STYLE_ERASE
;
297 #if wxUSE_CONSTRAINTS
298 // no constraints whatsoever
299 m_constraints
= NULL
;
300 m_constraintsInvolvedIn
= NULL
;
301 #endif // wxUSE_CONSTRAINTS
303 m_windowSizer
= NULL
;
304 m_containingSizer
= NULL
;
305 m_autoLayout
= false;
307 #if wxUSE_DRAG_AND_DROP
309 #endif // wxUSE_DRAG_AND_DROP
313 #endif // wxUSE_TOOLTIPS
317 #endif // wxUSE_CARET
320 m_hasCustomPalette
= false;
321 #endif // wxUSE_PALETTE
323 #if wxUSE_ACCESSIBILITY
327 m_virtualSize
= wxDefaultSize
;
329 m_scrollHelper
= NULL
;
331 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
332 #if wxUSE_SYSTEM_OPTIONS
333 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
335 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
339 // Whether we're using the current theme for this window (wxGTK only for now)
340 m_themeEnabled
= false;
342 // This is set to true by SendDestroyEvent() which should be called by the
343 // most derived class to ensure that the destruction event is sent as soon
344 // as possible to allow its handlers to still see the undestroyed window
345 m_isBeingDeleted
= false;
350 // common part of window creation process
351 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
353 const wxPoint
& WXUNUSED(pos
),
356 const wxString
& name
)
358 // ids are limited to 16 bits under MSW so if you care about portability,
359 // it's not a good idea to use ids out of this range (and negative ids are
360 // reserved for wxWidgets own usage)
361 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767) ||
362 (id
>= wxID_AUTO_LOWEST
&& id
<= wxID_AUTO_HIGHEST
),
363 wxT("invalid id value") );
365 // generate a new id if the user doesn't care about it
366 if ( id
== wxID_ANY
)
368 m_windowId
= NewControlId();
370 else // valid id specified
375 // don't use SetWindowStyleFlag() here, this function should only be called
376 // to change the flag after creation as it tries to reflect the changes in
377 // flags by updating the window dynamically and we don't need this here
378 m_windowStyle
= style
;
380 // assume the user doesn't want this window to shrink beneath its initial
381 // size, this worked like this in wxWidgets 2.8 and before and generally
382 // often makes sense for child windows (for top level ones it definitely
383 // does not as the user should be able to resize the window)
385 // note that we can't use IsTopLevel() from ctor
386 if ( size
!= wxDefaultSize
&& !wxTopLevelWindows
.Find((wxWindow
*)this) )
395 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
400 const wxValidator
& wxVALIDATOR_PARAM(validator
),
401 const wxString
& name
)
403 if ( !CreateBase(parent
, id
, pos
, size
, style
, name
) )
407 SetValidator(validator
);
408 #endif // wxUSE_VALIDATORS
410 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
411 // have it too - like this it's possible to set it only in the top level
412 // dialog/frame and all children will inherit it by defult
413 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
415 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
421 bool wxWindowBase::ToggleWindowStyle(int flag
)
423 wxASSERT_MSG( flag
, wxT("flags with 0 value can't be toggled") );
426 long style
= GetWindowStyleFlag();
432 else // currently off
438 SetWindowStyleFlag(style
);
443 // ----------------------------------------------------------------------------
445 // ----------------------------------------------------------------------------
448 wxWindowBase::~wxWindowBase()
450 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
452 // FIXME if these 2 cases result from programming errors in the user code
453 // we should probably assert here instead of silently fixing them
455 // Just in case the window has been Closed, but we're then deleting
456 // immediately: don't leave dangling pointers.
457 wxPendingDelete
.DeleteObject(this);
459 // Just in case we've loaded a top-level window via LoadNativeDialog but
460 // we weren't a dialog class
461 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
463 // Any additional event handlers should be popped before the window is
464 // deleted as otherwise the last handler will be left with a dangling
465 // pointer to this window result in a difficult to diagnose crash later on.
466 wxASSERT_MSG( GetEventHandler() == this,
467 wxT("any pushed event handlers must have been removed") );
470 // The associated popup menu can still be alive, disassociate from it in
472 if ( wxCurrentPopupMenu
&& wxCurrentPopupMenu
->GetInvokingWindow() == this )
473 wxCurrentPopupMenu
->SetInvokingWindow(NULL
);
474 #endif // wxUSE_MENUS
476 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
478 // notify the parent about this window destruction
480 m_parent
->RemoveChild(this);
484 #endif // wxUSE_CARET
487 delete m_windowValidator
;
488 #endif // wxUSE_VALIDATORS
490 #if wxUSE_CONSTRAINTS
491 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
492 // at deleted windows as they delete themselves.
493 DeleteRelatedConstraints();
497 // This removes any dangling pointers to this window in other windows'
498 // constraintsInvolvedIn lists.
499 UnsetConstraints(m_constraints
);
500 wxDELETE(m_constraints
);
502 #endif // wxUSE_CONSTRAINTS
504 if ( m_containingSizer
)
505 m_containingSizer
->Detach( (wxWindow
*)this );
507 delete m_windowSizer
;
509 #if wxUSE_DRAG_AND_DROP
511 #endif // wxUSE_DRAG_AND_DROP
515 #endif // wxUSE_TOOLTIPS
517 #if wxUSE_ACCESSIBILITY
522 // NB: this has to be called unconditionally, because we don't know
523 // whether this window has associated help text or not
524 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
526 helpProvider
->RemoveHelp(this);
530 bool wxWindowBase::IsBeingDeleted() const
532 return m_isBeingDeleted
||
533 (!IsTopLevel() && m_parent
&& m_parent
->IsBeingDeleted());
536 void wxWindowBase::SendDestroyEvent()
538 if ( m_isBeingDeleted
)
540 // we could have been already called from a more derived class dtor,
541 // e.g. ~wxTLW calls us and so does ~wxWindow and the latter call
542 // should be simply ignored
546 m_isBeingDeleted
= true;
548 wxWindowDestroyEvent event
;
549 event
.SetEventObject(this);
550 event
.SetId(GetId());
551 GetEventHandler()->ProcessEvent(event
);
554 bool wxWindowBase::Destroy()
563 bool wxWindowBase::Close(bool force
)
565 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
566 event
.SetEventObject(this);
567 event
.SetCanVeto(!force
);
569 // return false if window wasn't closed because the application vetoed the
571 return HandleWindowEvent(event
) && !event
.GetVeto();
574 bool wxWindowBase::DestroyChildren()
576 wxWindowList::compatibility_iterator node
;
579 // we iterate until the list becomes empty
580 node
= GetChildren().GetFirst();
584 wxWindow
*child
= node
->GetData();
586 // note that we really want to delete it immediately so don't call the
587 // possible overridden Destroy() version which might not delete the
588 // child immediately resulting in problems with our (top level) child
589 // outliving its parent
590 child
->wxWindowBase::Destroy();
592 wxASSERT_MSG( !GetChildren().Find(child
),
593 wxT("child didn't remove itself using RemoveChild()") );
599 // ----------------------------------------------------------------------------
600 // size/position related methods
601 // ----------------------------------------------------------------------------
603 // centre the window with respect to its parent in either (or both) directions
604 void wxWindowBase::DoCentre(int dir
)
606 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
607 wxT("this method only implements centering child windows") );
609 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
612 // fits the window around the children
613 void wxWindowBase::Fit()
615 if ( !GetChildren().empty() )
617 SetSize(GetBestSize());
619 //else: do nothing if we have no children
622 // fits virtual size (ie. scrolled area etc.) around children
623 void wxWindowBase::FitInside()
625 if ( GetChildren().GetCount() > 0 )
627 SetVirtualSize( GetBestVirtualSize() );
631 // On Mac, scrollbars are explicitly children.
632 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
633 static bool wxHasRealChildren(const wxWindowBase
* win
)
635 int realChildCount
= 0;
637 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
639 node
= node
->GetNext() )
641 wxWindow
*win
= node
->GetData();
642 if ( !win
->IsTopLevel() && win
->IsShown()
644 && !win
->IsKindOf(CLASSINFO(wxScrollBar
))
649 return (realChildCount
> 0);
653 void wxWindowBase::InvalidateBestSize()
655 m_bestSizeCache
= wxDefaultSize
;
657 // parent's best size calculation may depend on its children's
658 // as long as child window we are in is not top level window itself
659 // (because the TLW size is never resized automatically)
660 // so let's invalidate it as well to be safe:
661 if (m_parent
&& !IsTopLevel())
662 m_parent
->InvalidateBestSize();
665 // return the size best suited for the current window
666 wxSize
wxWindowBase::DoGetBestSize() const
672 best
= m_windowSizer
->GetMinSize();
674 #if wxUSE_CONSTRAINTS
675 else if ( m_constraints
)
677 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
679 // our minimal acceptable size is such that all our windows fit inside
683 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
685 node
= node
->GetNext() )
687 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
690 // it's not normal that we have an unconstrained child, but
691 // what can we do about it?
695 int x
= c
->right
.GetValue(),
696 y
= c
->bottom
.GetValue();
704 // TODO: we must calculate the overlaps somehow, otherwise we
705 // will never return a size bigger than the current one :-(
708 best
= wxSize(maxX
, maxY
);
710 #endif // wxUSE_CONSTRAINTS
711 else if ( !GetChildren().empty()
712 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
713 && wxHasRealChildren(this)
717 // our minimal acceptable size is such that all our visible child
718 // windows fit inside
722 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
724 node
= node
->GetNext() )
726 wxWindow
*win
= node
->GetData();
727 if ( win
->IsTopLevel()
730 || wxDynamicCast(win
, wxStatusBar
)
731 #endif // wxUSE_STATUSBAR
734 // dialogs and frames lie in different top level windows -
735 // don't deal with them here; as for the status bars, they
736 // don't lie in the client area at all
741 win
->GetPosition(&wx
, &wy
);
743 // if the window hadn't been positioned yet, assume that it is in
745 if ( wx
== wxDefaultCoord
)
747 if ( wy
== wxDefaultCoord
)
750 win
->GetSize(&ww
, &wh
);
751 if ( wx
+ ww
> maxX
)
753 if ( wy
+ wh
> maxY
)
757 best
= wxSize(maxX
, maxY
);
759 else // ! has children
761 wxSize size
= GetMinSize();
762 if ( !size
.IsFullySpecified() )
764 // if the window doesn't define its best size we assume that it can
765 // be arbitrarily small -- usually this is not the case, of course,
766 // but we have no way to know what the limit is, it should really
767 // override DoGetBestClientSize() itself to tell us
768 size
.SetDefaults(wxSize(1, 1));
771 // return as-is, unadjusted by the client size difference.
775 // Add any difference between size and client size
776 wxSize diff
= GetSize() - GetClientSize();
777 best
.x
+= wxMax(0, diff
.x
);
778 best
.y
+= wxMax(0, diff
.y
);
783 // helper of GetWindowBorderSize(): as many ports don't implement support for
784 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
785 // fallbacks in this case
786 static int wxGetMetricOrDefault(wxSystemMetric what
, const wxWindowBase
* win
)
788 int rc
= wxSystemSettings::GetMetric(
789 what
, static_cast<wxWindow
*>(const_cast<wxWindowBase
*>(win
)));
796 // 2D border is by default 1 pixel wide
802 // 3D borders are by default 2 pixels
807 wxFAIL_MSG( wxT("unexpected wxGetMetricOrDefault() argument") );
815 wxSize
wxWindowBase::GetWindowBorderSize() const
819 switch ( GetBorder() )
822 // nothing to do, size is already (0, 0)
825 case wxBORDER_SIMPLE
:
826 case wxBORDER_STATIC
:
827 size
.x
= wxGetMetricOrDefault(wxSYS_BORDER_X
, this);
828 size
.y
= wxGetMetricOrDefault(wxSYS_BORDER_Y
, this);
831 case wxBORDER_SUNKEN
:
832 case wxBORDER_RAISED
:
833 size
.x
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X
, this),
834 wxGetMetricOrDefault(wxSYS_BORDER_X
, this));
835 size
.y
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y
, this),
836 wxGetMetricOrDefault(wxSYS_BORDER_Y
, this));
839 case wxBORDER_DOUBLE
:
840 size
.x
= wxGetMetricOrDefault(wxSYS_EDGE_X
, this) +
841 wxGetMetricOrDefault(wxSYS_BORDER_X
, this);
842 size
.y
= wxGetMetricOrDefault(wxSYS_EDGE_Y
, this) +
843 wxGetMetricOrDefault(wxSYS_BORDER_Y
, this);
847 wxFAIL_MSG(wxT("Unknown border style."));
851 // we have borders on both sides
855 wxSize
wxWindowBase::GetEffectiveMinSize() const
857 // merge the best size with the min size, giving priority to the min size
858 wxSize min
= GetMinSize();
860 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
862 wxSize best
= GetBestSize();
863 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
864 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
870 wxSize
wxWindowBase::DoGetBorderSize() const
872 // there is one case in which we can implement it for all ports easily
873 if ( GetBorder() == wxBORDER_NONE
)
876 // otherwise use the difference between the real size and the client size
877 // as a fallback: notice that this is incorrect in general as client size
878 // also doesn't take the scrollbars into account
879 return GetSize() - GetClientSize();
882 wxSize
wxWindowBase::GetBestSize() const
884 if ( !m_windowSizer
&& m_bestSizeCache
.IsFullySpecified() )
885 return m_bestSizeCache
;
887 // call DoGetBestClientSize() first, if a derived class overrides it wants
889 wxSize size
= DoGetBestClientSize();
890 if ( size
!= wxDefaultSize
)
892 size
+= DoGetBorderSize();
898 return DoGetBestSize();
901 void wxWindowBase::SetMinSize(const wxSize
& minSize
)
903 m_minWidth
= minSize
.x
;
904 m_minHeight
= minSize
.y
;
907 void wxWindowBase::SetMaxSize(const wxSize
& maxSize
)
909 m_maxWidth
= maxSize
.x
;
910 m_maxHeight
= maxSize
.y
;
913 void wxWindowBase::SetInitialSize(const wxSize
& size
)
915 // Set the min size to the size passed in. This will usually either be
916 // wxDefaultSize or the size passed to this window's ctor/Create function.
919 // Merge the size with the best size if needed
920 wxSize best
= GetEffectiveMinSize();
922 // If the current size doesn't match then change it
923 if (GetSize() != best
)
928 // by default the origin is not shifted
929 wxPoint
wxWindowBase::GetClientAreaOrigin() const
934 wxSize
wxWindowBase::ClientToWindowSize(const wxSize
& size
) const
936 const wxSize
diff(GetSize() - GetClientSize());
938 return wxSize(size
.x
== -1 ? -1 : size
.x
+ diff
.x
,
939 size
.y
== -1 ? -1 : size
.y
+ diff
.y
);
942 wxSize
wxWindowBase::WindowToClientSize(const wxSize
& size
) const
944 const wxSize
diff(GetSize() - GetClientSize());
946 return wxSize(size
.x
== -1 ? -1 : size
.x
- diff
.x
,
947 size
.y
== -1 ? -1 : size
.y
- diff
.y
);
950 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
952 if ( m_windowVariant
!= variant
)
954 m_windowVariant
= variant
;
956 DoSetWindowVariant(variant
);
960 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
962 // adjust the font height to correspond to our new variant (notice that
963 // we're only called if something really changed)
964 wxFont font
= GetFont();
965 int size
= font
.GetPointSize();
968 case wxWINDOW_VARIANT_NORMAL
:
971 case wxWINDOW_VARIANT_SMALL
:
972 size
= wxRound(size
* 3.0 / 4.0);
975 case wxWINDOW_VARIANT_MINI
:
976 size
= wxRound(size
* 2.0 / 3.0);
979 case wxWINDOW_VARIANT_LARGE
:
980 size
= wxRound(size
* 5.0 / 4.0);
984 wxFAIL_MSG(wxT("unexpected window variant"));
988 font
.SetPointSize(size
);
992 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
994 int WXUNUSED(incW
), int WXUNUSED(incH
) )
996 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
997 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
998 wxT("min width/height must be less than max width/height!") );
1007 #if WXWIN_COMPATIBILITY_2_8
1008 void wxWindowBase::SetVirtualSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
),
1009 int WXUNUSED(maxW
), int WXUNUSED(maxH
))
1013 void wxWindowBase::SetVirtualSizeHints(const wxSize
& WXUNUSED(minsize
),
1014 const wxSize
& WXUNUSED(maxsize
))
1017 #endif // WXWIN_COMPATIBILITY_2_8
1019 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
1021 m_virtualSize
= wxSize(x
, y
);
1024 wxSize
wxWindowBase::DoGetVirtualSize() const
1026 // we should use the entire client area so if it is greater than our
1027 // virtual size, expand it to fit (otherwise if the window is big enough we
1028 // wouldn't be using parts of it)
1029 wxSize size
= GetClientSize();
1030 if ( m_virtualSize
.x
> size
.x
)
1031 size
.x
= m_virtualSize
.x
;
1033 if ( m_virtualSize
.y
>= size
.y
)
1034 size
.y
= m_virtualSize
.y
;
1039 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
1041 // screen position is the same as (0, 0) in client coords for non TLWs (and
1042 // TLWs override this method)
1048 ClientToScreen(x
, y
);
1051 void wxWindowBase::SendSizeEvent(int flags
)
1053 wxSizeEvent
event(GetSize(), GetId());
1054 event
.SetEventObject(this);
1055 if ( flags
& wxSEND_EVENT_POST
)
1056 wxPostEvent(this, event
);
1058 HandleWindowEvent(event
);
1061 void wxWindowBase::SendSizeEventToParent(int flags
)
1063 wxWindow
* const parent
= GetParent();
1064 if ( parent
&& !parent
->IsBeingDeleted() )
1065 parent
->SendSizeEvent(flags
);
1068 bool wxWindowBase::HasScrollbar(int orient
) const
1070 // if scrolling in the given direction is disabled, we can't have the
1071 // corresponding scrollbar no matter what
1072 if ( !CanScroll(orient
) )
1075 const wxSize sizeVirt
= GetVirtualSize();
1076 const wxSize sizeClient
= GetClientSize();
1078 return orient
== wxHORIZONTAL
? sizeVirt
.x
> sizeClient
.x
1079 : sizeVirt
.y
> sizeClient
.y
;
1082 // ----------------------------------------------------------------------------
1083 // show/hide/enable/disable the window
1084 // ----------------------------------------------------------------------------
1086 bool wxWindowBase::Show(bool show
)
1088 if ( show
!= m_isShown
)
1100 bool wxWindowBase::IsEnabled() const
1102 return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
1105 void wxWindowBase::NotifyWindowOnEnableChange(bool enabled
)
1107 // Under some platforms there is no need to update the window state
1108 // explicitly, it will become disabled when its parent is. On other ones we
1109 // do need to disable all windows recursively though.
1110 #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
1112 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
1116 // Disabling a top level window is typically done when showing a modal
1117 // dialog and we don't need to disable its children in this case, they will
1118 // be logically disabled anyhow (i.e. their IsEnabled() will return false)
1119 // and the TLW won't accept any input for them. Moreover, explicitly
1120 // disabling them would look ugly as the entire TLW would be greyed out
1121 // whenever a modal dialog is shown and no native applications under any
1122 // platform behave like this.
1123 if ( IsTopLevel() && !enabled
)
1126 // When disabling (or enabling back) a non-TLW window we need to
1127 // recursively propagate the change of the state to its children, otherwise
1128 // they would still show as enabled even though they wouldn't actually
1129 // accept any input (at least under MSW where children don't accept input
1130 // if any of the windows in their parent chain is enabled).
1132 // Notice that we must do this even for wxHAS_NATIVE_ENABLED_MANAGEMENT
1133 // platforms as we still need to call the children OnEnabled() recursively.
1134 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1136 node
= node
->GetNext() )
1138 wxWindowBase
* const child
= node
->GetData();
1139 if ( !child
->IsTopLevel() && child
->IsThisEnabled() )
1140 child
->NotifyWindowOnEnableChange(enabled
);
1144 bool wxWindowBase::Enable(bool enable
)
1146 if ( enable
== IsThisEnabled() )
1149 m_isEnabled
= enable
;
1151 // If we call DoEnable() from NotifyWindowOnEnableChange(), we don't need
1152 // to do it from here.
1153 #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
1155 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
1157 NotifyWindowOnEnableChange(enable
);
1162 bool wxWindowBase::IsShownOnScreen() const
1164 // A window is shown on screen if it itself is shown and so are all its
1165 // parents. But if a window is toplevel one, then its always visible on
1166 // screen if IsShown() returns true, even if it has a hidden parent.
1168 (IsTopLevel() || GetParent() == NULL
|| GetParent()->IsShownOnScreen());
1171 // ----------------------------------------------------------------------------
1173 // ----------------------------------------------------------------------------
1175 bool wxWindowBase::IsTopLevel() const
1180 // ----------------------------------------------------------------------------
1182 // ----------------------------------------------------------------------------
1184 void wxWindowBase::Freeze()
1186 if ( !m_freezeCount
++ )
1188 // physically freeze this window:
1191 // and recursively freeze all children:
1192 for ( wxWindowList::iterator i
= GetChildren().begin();
1193 i
!= GetChildren().end(); ++i
)
1195 wxWindow
*child
= *i
;
1196 if ( child
->IsTopLevel() )
1204 void wxWindowBase::Thaw()
1206 wxASSERT_MSG( m_freezeCount
, "Thaw() without matching Freeze()" );
1208 if ( !--m_freezeCount
)
1210 // recursively thaw all children:
1211 for ( wxWindowList::iterator i
= GetChildren().begin();
1212 i
!= GetChildren().end(); ++i
)
1214 wxWindow
*child
= *i
;
1215 if ( child
->IsTopLevel() )
1221 // physically thaw this window:
1226 // ----------------------------------------------------------------------------
1227 // reparenting the window
1228 // ----------------------------------------------------------------------------
1230 void wxWindowBase::AddChild(wxWindowBase
*child
)
1232 wxCHECK_RET( child
, wxT("can't add a NULL child") );
1234 // this should never happen and it will lead to a crash later if it does
1235 // because RemoveChild() will remove only one node from the children list
1236 // and the other(s) one(s) will be left with dangling pointers in them
1237 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), wxT("AddChild() called twice") );
1239 GetChildren().Append((wxWindow
*)child
);
1240 child
->SetParent(this);
1242 // adding a child while frozen will assert when thawed, so freeze it as if
1243 // it had been already present when we were frozen
1244 if ( IsFrozen() && !child
->IsTopLevel() )
1248 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
1250 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
1252 // removing a child while frozen may result in permanently frozen window
1253 // if used e.g. from Reparent(), so thaw it
1255 // NB: IsTopLevel() doesn't return true any more when a TLW child is being
1256 // removed from its ~wxWindowBase, so check for IsBeingDeleted() too
1257 if ( IsFrozen() && !child
->IsBeingDeleted() && !child
->IsTopLevel() )
1260 GetChildren().DeleteObject((wxWindow
*)child
);
1261 child
->SetParent(NULL
);
1264 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
1266 wxWindow
*oldParent
= GetParent();
1267 if ( newParent
== oldParent
)
1273 const bool oldEnabledState
= IsEnabled();
1275 // unlink this window from the existing parent.
1278 oldParent
->RemoveChild(this);
1282 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
1285 // add it to the new one
1288 newParent
->AddChild(this);
1292 wxTopLevelWindows
.Append((wxWindow
*)this);
1295 // We need to notify window (and its subwindows) if by changing the parent
1296 // we also change our enabled/disabled status.
1297 const bool newEnabledState
= IsEnabled();
1298 if ( newEnabledState
!= oldEnabledState
)
1300 NotifyWindowOnEnableChange(newEnabledState
);
1306 // ----------------------------------------------------------------------------
1307 // event handler stuff
1308 // ----------------------------------------------------------------------------
1310 void wxWindowBase::SetEventHandler(wxEvtHandler
*handler
)
1312 wxCHECK_RET(handler
!= NULL
, "SetEventHandler(NULL) called");
1314 m_eventHandler
= handler
;
1317 void wxWindowBase::SetNextHandler(wxEvtHandler
*WXUNUSED(handler
))
1319 // disable wxEvtHandler chain mechanism for wxWindows:
1320 // wxWindow uses its own stack mechanism which doesn't mix well with wxEvtHandler's one
1322 wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
1324 void wxWindowBase::SetPreviousHandler(wxEvtHandler
*WXUNUSED(handler
))
1326 // we can't simply wxFAIL here as in SetNextHandler: in fact the last
1327 // handler of our stack when is destroyed will be Unlink()ed and thus
1328 // will call this function to update the pointer of this window...
1330 //wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
1333 void wxWindowBase::PushEventHandler(wxEvtHandler
*handlerToPush
)
1335 wxCHECK_RET( handlerToPush
!= NULL
, "PushEventHandler(NULL) called" );
1337 // the new handler is going to be part of the wxWindow stack of event handlers:
1338 // it can't be part also of an event handler double-linked chain:
1339 wxASSERT_MSG(handlerToPush
->IsUnlinked(),
1340 "The handler being pushed in the wxWindow stack shouldn't be part of "
1341 "a wxEvtHandler chain; call Unlink() on it first");
1343 wxEvtHandler
*handlerOld
= GetEventHandler();
1344 wxCHECK_RET( handlerOld
, "an old event handler is NULL?" );
1346 // now use wxEvtHandler double-linked list to implement a stack:
1347 handlerToPush
->SetNextHandler(handlerOld
);
1349 if (handlerOld
!= this)
1350 handlerOld
->SetPreviousHandler(handlerToPush
);
1352 SetEventHandler(handlerToPush
);
1355 // final checks of the operations done above:
1356 wxASSERT_MSG( handlerToPush
->GetPreviousHandler() == NULL
,
1357 "the first handler of the wxWindow stack should "
1358 "have no previous handlers set" );
1359 wxASSERT_MSG( handlerToPush
->GetNextHandler() != NULL
,
1360 "the first handler of the wxWindow stack should "
1361 "have non-NULL next handler" );
1363 wxEvtHandler
* pLast
= handlerToPush
;
1364 while ( pLast
&& pLast
!= this )
1365 pLast
= pLast
->GetNextHandler();
1366 wxASSERT_MSG( pLast
->GetNextHandler() == NULL
,
1367 "the last handler of the wxWindow stack should "
1368 "have this window as next handler" );
1369 #endif // wxDEBUG_LEVEL
1372 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
1374 // we need to pop the wxWindow stack, i.e. we need to remove the first handler
1376 wxEvtHandler
*firstHandler
= GetEventHandler();
1377 wxCHECK_MSG( firstHandler
!= NULL
, NULL
, "wxWindow cannot have a NULL event handler" );
1378 wxCHECK_MSG( firstHandler
!= this, NULL
, "cannot pop the wxWindow itself" );
1379 wxCHECK_MSG( firstHandler
->GetPreviousHandler() == NULL
, NULL
,
1380 "the first handler of the wxWindow stack should have no previous handlers set" );
1382 wxEvtHandler
*secondHandler
= firstHandler
->GetNextHandler();
1383 wxCHECK_MSG( secondHandler
!= NULL
, NULL
,
1384 "the first handler of the wxWindow stack should have non-NULL next handler" );
1386 firstHandler
->SetNextHandler(NULL
);
1387 secondHandler
->SetPreviousHandler(NULL
);
1389 // now firstHandler is completely unlinked; set secondHandler as the new window event handler
1390 SetEventHandler(secondHandler
);
1392 if ( deleteHandler
)
1394 wxDELETE(firstHandler
);
1397 return firstHandler
;
1400 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handlerToRemove
)
1402 wxCHECK_MSG( handlerToRemove
!= NULL
, false, "RemoveEventHandler(NULL) called" );
1403 wxCHECK_MSG( handlerToRemove
!= this, false, "Cannot remove the window itself" );
1405 if (handlerToRemove
== GetEventHandler())
1407 // removing the first event handler is equivalent to "popping" the stack
1408 PopEventHandler(false);
1412 // NOTE: the wxWindow event handler list is always terminated with "this" handler
1413 wxEvtHandler
*handlerCur
= GetEventHandler()->GetNextHandler();
1414 while ( handlerCur
!= this && handlerCur
)
1416 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
1418 if ( handlerCur
== handlerToRemove
)
1420 handlerCur
->Unlink();
1422 wxASSERT_MSG( handlerCur
!= GetEventHandler(),
1423 "the case Remove == Pop should was already handled" );
1427 handlerCur
= handlerNext
;
1430 wxFAIL_MSG( wxT("where has the event handler gone?") );
1435 bool wxWindowBase::HandleWindowEvent(wxEvent
& event
) const
1437 // SafelyProcessEvent() will handle exceptions nicely
1438 return GetEventHandler()->SafelyProcessEvent(event
);
1441 // ----------------------------------------------------------------------------
1442 // colours, fonts &c
1443 // ----------------------------------------------------------------------------
1445 void wxWindowBase::InheritAttributes()
1447 const wxWindowBase
* const parent
= GetParent();
1451 // we only inherit attributes which had been explicitly set for the parent
1452 // which ensures that this only happens if the user really wants it and
1453 // not by default which wouldn't make any sense in modern GUIs where the
1454 // controls don't all use the same fonts (nor colours)
1455 if ( parent
->m_inheritFont
&& !m_hasFont
)
1456 SetFont(parent
->GetFont());
1458 // in addition, there is a possibility to explicitly forbid inheriting
1459 // colours at each class level by overriding ShouldInheritColours()
1460 if ( ShouldInheritColours() )
1462 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1463 SetForegroundColour(parent
->GetForegroundColour());
1465 // inheriting (solid) background colour is wrong as it totally breaks
1466 // any kind of themed backgrounds
1468 // instead, the controls should use the same background as their parent
1469 // (ideally by not drawing it at all)
1471 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1472 SetBackgroundColour(parent
->GetBackgroundColour());
1477 /* static */ wxVisualAttributes
1478 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1480 // it is important to return valid values for all attributes from here,
1481 // GetXXX() below rely on this
1482 wxVisualAttributes attrs
;
1483 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1484 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1486 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1487 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1488 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1489 // colour on other platforms.
1491 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1492 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1494 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1499 wxColour
wxWindowBase::GetBackgroundColour() const
1501 if ( !m_backgroundColour
.IsOk() )
1503 wxASSERT_MSG( !m_hasBgCol
, wxT("we have invalid explicit bg colour?") );
1505 // get our default background colour
1506 wxColour colBg
= GetDefaultAttributes().colBg
;
1508 // we must return some valid colour to avoid redoing this every time
1509 // and also to avoid surprising the applications written for older
1510 // wxWidgets versions where GetBackgroundColour() always returned
1511 // something -- so give them something even if it doesn't make sense
1512 // for this window (e.g. it has a themed background)
1514 colBg
= GetClassDefaultAttributes().colBg
;
1519 return m_backgroundColour
;
1522 wxColour
wxWindowBase::GetForegroundColour() const
1524 // logic is the same as above
1525 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1527 wxColour colFg
= GetDefaultAttributes().colFg
;
1529 if ( !colFg
.IsOk() )
1530 colFg
= GetClassDefaultAttributes().colFg
;
1535 return m_foregroundColour
;
1538 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1540 if ( colour
== m_backgroundColour
)
1543 m_hasBgCol
= colour
.IsOk();
1545 m_inheritBgCol
= m_hasBgCol
;
1546 m_backgroundColour
= colour
;
1547 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1551 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1553 if (colour
== m_foregroundColour
)
1556 m_hasFgCol
= colour
.IsOk();
1557 m_inheritFgCol
= m_hasFgCol
;
1558 m_foregroundColour
= colour
;
1559 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1563 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1565 // setting an invalid cursor is ok, it means that we don't have any special
1567 if ( m_cursor
.IsSameAs(cursor
) )
1578 wxFont
wxWindowBase::GetFont() const
1580 // logic is the same as in GetBackgroundColour()
1581 if ( !m_font
.IsOk() )
1583 wxASSERT_MSG( !m_hasFont
, wxT("we have invalid explicit font?") );
1585 wxFont font
= GetDefaultAttributes().font
;
1587 font
= GetClassDefaultAttributes().font
;
1595 bool wxWindowBase::SetFont(const wxFont
& font
)
1597 if ( font
== m_font
)
1604 m_hasFont
= font
.IsOk();
1605 m_inheritFont
= m_hasFont
;
1607 InvalidateBestSize();
1614 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1616 m_hasCustomPalette
= true;
1619 // VZ: can anyone explain me what do we do here?
1620 wxWindowDC
d((wxWindow
*) this);
1624 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1626 wxWindow
*win
= (wxWindow
*)this;
1627 while ( win
&& !win
->HasCustomPalette() )
1629 win
= win
->GetParent();
1635 #endif // wxUSE_PALETTE
1638 void wxWindowBase::SetCaret(wxCaret
*caret
)
1649 wxASSERT_MSG( m_caret
->GetWindow() == this,
1650 wxT("caret should be created associated to this window") );
1653 #endif // wxUSE_CARET
1655 #if wxUSE_VALIDATORS
1656 // ----------------------------------------------------------------------------
1658 // ----------------------------------------------------------------------------
1660 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1662 if ( m_windowValidator
)
1663 delete m_windowValidator
;
1665 m_windowValidator
= (wxValidator
*)validator
.Clone();
1667 if ( m_windowValidator
)
1668 m_windowValidator
->SetWindow(this);
1670 #endif // wxUSE_VALIDATORS
1672 // ----------------------------------------------------------------------------
1673 // update region stuff
1674 // ----------------------------------------------------------------------------
1676 wxRect
wxWindowBase::GetUpdateClientRect() const
1678 wxRegion rgnUpdate
= GetUpdateRegion();
1679 rgnUpdate
.Intersect(GetClientRect());
1680 wxRect rectUpdate
= rgnUpdate
.GetBox();
1681 wxPoint ptOrigin
= GetClientAreaOrigin();
1682 rectUpdate
.x
-= ptOrigin
.x
;
1683 rectUpdate
.y
-= ptOrigin
.y
;
1688 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1690 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1693 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1695 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1698 void wxWindowBase::ClearBackground()
1700 // wxGTK uses its own version, no need to add never used code
1702 wxClientDC
dc((wxWindow
*)this);
1703 wxBrush
brush(GetBackgroundColour(), wxBRUSHSTYLE_SOLID
);
1704 dc
.SetBackground(brush
);
1709 // ----------------------------------------------------------------------------
1710 // find child window by id or name
1711 // ----------------------------------------------------------------------------
1713 wxWindow
*wxWindowBase::FindWindow(long id
) const
1715 if ( id
== m_windowId
)
1716 return (wxWindow
*)this;
1718 wxWindowBase
*res
= NULL
;
1719 wxWindowList::compatibility_iterator node
;
1720 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1722 wxWindowBase
*child
= node
->GetData();
1723 res
= child
->FindWindow( id
);
1726 return (wxWindow
*)res
;
1729 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1731 if ( name
== m_windowName
)
1732 return (wxWindow
*)this;
1734 wxWindowBase
*res
= NULL
;
1735 wxWindowList::compatibility_iterator node
;
1736 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1738 wxWindow
*child
= node
->GetData();
1739 res
= child
->FindWindow(name
);
1742 return (wxWindow
*)res
;
1746 // find any window by id or name or label: If parent is non-NULL, look through
1747 // children for a label or title matching the specified string. If NULL, look
1748 // through all top-level windows.
1750 // to avoid duplicating code we reuse the same helper function but with
1751 // different comparators
1753 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1754 const wxString
& label
, long id
);
1757 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1760 return win
->GetLabel() == label
;
1764 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1767 return win
->GetName() == label
;
1771 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1774 return win
->GetId() == id
;
1777 // recursive helper for the FindWindowByXXX() functions
1779 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1780 const wxString
& label
,
1782 wxFindWindowCmp cmp
)
1786 // see if this is the one we're looking for
1787 if ( (*cmp
)(parent
, label
, id
) )
1788 return (wxWindow
*)parent
;
1790 // It wasn't, so check all its children
1791 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1793 node
= node
->GetNext() )
1795 // recursively check each child
1796 wxWindow
*win
= (wxWindow
*)node
->GetData();
1797 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1807 // helper for FindWindowByXXX()
1809 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1810 const wxString
& label
,
1812 wxFindWindowCmp cmp
)
1816 // just check parent and all its children
1817 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1820 // start at very top of wx's windows
1821 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1823 node
= node
->GetNext() )
1825 // recursively check each window & its children
1826 wxWindow
*win
= node
->GetData();
1827 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1837 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1839 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1844 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1846 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1850 // fall back to the label
1851 win
= FindWindowByLabel(title
, parent
);
1859 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1861 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1864 // ----------------------------------------------------------------------------
1865 // dialog oriented functions
1866 // ----------------------------------------------------------------------------
1868 void wxWindowBase::MakeModal(bool modal
)
1870 // Disable all other windows
1873 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1876 wxWindow
*win
= node
->GetData();
1878 win
->Enable(!modal
);
1880 node
= node
->GetNext();
1885 bool wxWindowBase::Validate()
1887 #if wxUSE_VALIDATORS
1888 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1890 wxWindowList::compatibility_iterator node
;
1891 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1893 wxWindowBase
*child
= node
->GetData();
1894 wxValidator
*validator
= child
->GetValidator();
1895 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1900 if ( recurse
&& !child
->Validate() )
1905 #endif // wxUSE_VALIDATORS
1910 bool wxWindowBase::TransferDataToWindow()
1912 #if wxUSE_VALIDATORS
1913 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1915 wxWindowList::compatibility_iterator node
;
1916 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1918 wxWindowBase
*child
= node
->GetData();
1919 wxValidator
*validator
= child
->GetValidator();
1920 if ( validator
&& !validator
->TransferToWindow() )
1922 wxLogWarning(_("Could not transfer data to window"));
1924 wxLog::FlushActive();
1932 if ( !child
->TransferDataToWindow() )
1934 // warning already given
1939 #endif // wxUSE_VALIDATORS
1944 bool wxWindowBase::TransferDataFromWindow()
1946 #if wxUSE_VALIDATORS
1947 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1949 wxWindowList::compatibility_iterator node
;
1950 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1952 wxWindow
*child
= node
->GetData();
1953 wxValidator
*validator
= child
->GetValidator();
1954 if ( validator
&& !validator
->TransferFromWindow() )
1956 // nop warning here because the application is supposed to give
1957 // one itself - we don't know here what might have gone wrongly
1964 if ( !child
->TransferDataFromWindow() )
1966 // warning already given
1971 #endif // wxUSE_VALIDATORS
1976 void wxWindowBase::InitDialog()
1978 wxInitDialogEvent
event(GetId());
1979 event
.SetEventObject( this );
1980 GetEventHandler()->ProcessEvent(event
);
1983 // ----------------------------------------------------------------------------
1984 // context-sensitive help support
1985 // ----------------------------------------------------------------------------
1989 // associate this help text with this window
1990 void wxWindowBase::SetHelpText(const wxString
& text
)
1992 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1995 helpProvider
->AddHelp(this, text
);
1999 #if WXWIN_COMPATIBILITY_2_8
2000 // associate this help text with all windows with the same id as this
2002 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
2004 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
2007 helpProvider
->AddHelp(GetId(), text
);
2010 #endif // WXWIN_COMPATIBILITY_2_8
2012 // get the help string associated with this window (may be empty)
2013 // default implementation forwards calls to the help provider
2015 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
2016 wxHelpEvent::Origin
WXUNUSED(origin
)) const
2019 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
2022 text
= helpProvider
->GetHelp(this);
2028 // show help for this window
2029 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
2031 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
2034 wxPoint pos
= event
.GetPosition();
2035 const wxHelpEvent::Origin origin
= event
.GetOrigin();
2036 if ( origin
== wxHelpEvent::Origin_Keyboard
)
2038 // if the help event was generated from keyboard it shouldn't
2039 // appear at the mouse position (which is still the only position
2040 // associated with help event) if the mouse is far away, although
2041 // we still do use the mouse position if it's over the window
2042 // because we suppose the user looks approximately at the mouse
2043 // already and so it would be more convenient than showing tooltip
2044 // at some arbitrary position which can be quite far from it
2045 const wxRect rectClient
= GetClientRect();
2046 if ( !rectClient
.Contains(ScreenToClient(pos
)) )
2048 // position help slightly under and to the right of this window
2049 pos
= ClientToScreen(wxPoint(
2051 rectClient
.height
+ GetCharHeight()
2056 if ( helpProvider
->ShowHelpAtPoint(this, pos
, origin
) )
2058 // skip the event.Skip() below
2066 #endif // wxUSE_HELP
2068 // ----------------------------------------------------------------------------
2070 // ----------------------------------------------------------------------------
2074 wxString
wxWindowBase::GetToolTipText() const
2076 return m_tooltip
? m_tooltip
->GetTip() : wxString();
2079 void wxWindowBase::SetToolTip( const wxString
&tip
)
2081 // don't create the new tooltip if we already have one
2084 m_tooltip
->SetTip( tip
);
2088 SetToolTip( new wxToolTip( tip
) );
2091 // setting empty tooltip text does not remove the tooltip any more - use
2092 // SetToolTip(NULL) for this
2095 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
2097 if ( m_tooltip
!= tooltip
)
2102 m_tooltip
= tooltip
;
2106 #endif // wxUSE_TOOLTIPS
2108 // ----------------------------------------------------------------------------
2109 // constraints and sizers
2110 // ----------------------------------------------------------------------------
2112 #if wxUSE_CONSTRAINTS
2114 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
2116 if ( m_constraints
)
2118 UnsetConstraints(m_constraints
);
2119 delete m_constraints
;
2121 m_constraints
= constraints
;
2122 if ( m_constraints
)
2124 // Make sure other windows know they're part of a 'meaningful relationship'
2125 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
2126 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
2127 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
2128 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
2129 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
2130 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
2131 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
2132 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
2133 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
2134 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
2135 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
2136 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
2137 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
2138 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
2139 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
2140 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
2144 // This removes any dangling pointers to this window in other windows'
2145 // constraintsInvolvedIn lists.
2146 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
2150 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
2151 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
2152 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
2153 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
2154 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
2155 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
2156 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
2157 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
2158 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
2159 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
2160 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
2161 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
2162 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
2163 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
2164 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
2165 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
2169 // Back-pointer to other windows we're involved with, so if we delete this
2170 // window, we must delete any constraints we're involved with.
2171 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
2173 if ( !m_constraintsInvolvedIn
)
2174 m_constraintsInvolvedIn
= new wxWindowList
;
2175 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
2176 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
2179 // REMOVE back-pointer to other windows we're involved with.
2180 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
2182 if ( m_constraintsInvolvedIn
)
2183 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
2186 // Reset any constraints that mention this window
2187 void wxWindowBase::DeleteRelatedConstraints()
2189 if ( m_constraintsInvolvedIn
)
2191 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
2194 wxWindow
*win
= node
->GetData();
2195 wxLayoutConstraints
*constr
= win
->GetConstraints();
2197 // Reset any constraints involving this window
2200 constr
->left
.ResetIfWin(this);
2201 constr
->top
.ResetIfWin(this);
2202 constr
->right
.ResetIfWin(this);
2203 constr
->bottom
.ResetIfWin(this);
2204 constr
->width
.ResetIfWin(this);
2205 constr
->height
.ResetIfWin(this);
2206 constr
->centreX
.ResetIfWin(this);
2207 constr
->centreY
.ResetIfWin(this);
2210 wxWindowList::compatibility_iterator next
= node
->GetNext();
2211 m_constraintsInvolvedIn
->Erase(node
);
2215 wxDELETE(m_constraintsInvolvedIn
);
2219 #endif // wxUSE_CONSTRAINTS
2221 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
2223 if ( sizer
== m_windowSizer
)
2226 if ( m_windowSizer
)
2228 m_windowSizer
->SetContainingWindow(NULL
);
2231 delete m_windowSizer
;
2234 m_windowSizer
= sizer
;
2235 if ( m_windowSizer
)
2237 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
2240 SetAutoLayout(m_windowSizer
!= NULL
);
2243 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
2245 SetSizer( sizer
, deleteOld
);
2246 sizer
->SetSizeHints( (wxWindow
*) this );
2250 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
2252 // adding a window to a sizer twice is going to result in fatal and
2253 // hard to debug problems later because when deleting the second
2254 // associated wxSizerItem we're going to dereference a dangling
2255 // pointer; so try to detect this as early as possible
2256 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
2257 wxT("Adding a window to the same sizer twice?") );
2259 m_containingSizer
= sizer
;
2262 #if wxUSE_CONSTRAINTS
2264 void wxWindowBase::SatisfyConstraints()
2266 wxLayoutConstraints
*constr
= GetConstraints();
2267 bool wasOk
= constr
&& constr
->AreSatisfied();
2269 ResetConstraints(); // Mark all constraints as unevaluated
2273 // if we're a top level panel (i.e. our parent is frame/dialog), our
2274 // own constraints will never be satisfied any more unless we do it
2278 while ( noChanges
> 0 )
2280 LayoutPhase1(&noChanges
);
2284 LayoutPhase2(&noChanges
);
2287 #endif // wxUSE_CONSTRAINTS
2289 bool wxWindowBase::Layout()
2291 // If there is a sizer, use it instead of the constraints
2295 GetVirtualSize(&w
, &h
);
2296 GetSizer()->SetDimension( 0, 0, w
, h
);
2298 #if wxUSE_CONSTRAINTS
2301 SatisfyConstraints(); // Find the right constraints values
2302 SetConstraintSizes(); // Recursively set the real window sizes
2309 void wxWindowBase::InternalOnSize(wxSizeEvent
& event
)
2311 if ( GetAutoLayout() )
2317 #if wxUSE_CONSTRAINTS
2319 // first phase of the constraints evaluation: set our own constraints
2320 bool wxWindowBase::LayoutPhase1(int *noChanges
)
2322 wxLayoutConstraints
*constr
= GetConstraints();
2324 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
2327 // second phase: set the constraints for our children
2328 bool wxWindowBase::LayoutPhase2(int *noChanges
)
2335 // Layout grand children
2341 // Do a phase of evaluating child constraints
2342 bool wxWindowBase::DoPhase(int phase
)
2344 // the list containing the children for which the constraints are already
2346 wxWindowList succeeded
;
2348 // the max number of iterations we loop before concluding that we can't set
2350 static const int maxIterations
= 500;
2352 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
2356 // loop over all children setting their constraints
2357 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2359 node
= node
->GetNext() )
2361 wxWindow
*child
= node
->GetData();
2362 if ( child
->IsTopLevel() )
2364 // top level children are not inside our client area
2368 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
2370 // this one is either already ok or nothing we can do about it
2374 int tempNoChanges
= 0;
2375 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
2376 : child
->LayoutPhase2(&tempNoChanges
);
2377 noChanges
+= tempNoChanges
;
2381 succeeded
.Append(child
);
2387 // constraints are set
2395 void wxWindowBase::ResetConstraints()
2397 wxLayoutConstraints
*constr
= GetConstraints();
2400 constr
->left
.SetDone(false);
2401 constr
->top
.SetDone(false);
2402 constr
->right
.SetDone(false);
2403 constr
->bottom
.SetDone(false);
2404 constr
->width
.SetDone(false);
2405 constr
->height
.SetDone(false);
2406 constr
->centreX
.SetDone(false);
2407 constr
->centreY
.SetDone(false);
2410 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2413 wxWindow
*win
= node
->GetData();
2414 if ( !win
->IsTopLevel() )
2415 win
->ResetConstraints();
2416 node
= node
->GetNext();
2420 // Need to distinguish between setting the 'fake' size for windows and sizers,
2421 // and setting the real values.
2422 void wxWindowBase::SetConstraintSizes(bool recurse
)
2424 wxLayoutConstraints
*constr
= GetConstraints();
2425 if ( constr
&& constr
->AreSatisfied() )
2427 int x
= constr
->left
.GetValue();
2428 int y
= constr
->top
.GetValue();
2429 int w
= constr
->width
.GetValue();
2430 int h
= constr
->height
.GetValue();
2432 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
2433 (constr
->height
.GetRelationship() != wxAsIs
) )
2435 // We really shouldn't set negative sizes for the windows so make
2436 // them at least of 1*1 size
2437 SetSize(x
, y
, w
> 0 ? w
: 1, h
> 0 ? h
: 1);
2441 // If we don't want to resize this window, just move it...
2447 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
2448 GetClassInfo()->GetClassName(),
2454 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2457 wxWindow
*win
= node
->GetData();
2458 if ( !win
->IsTopLevel() && win
->GetConstraints() )
2459 win
->SetConstraintSizes();
2460 node
= node
->GetNext();
2465 // Only set the size/position of the constraint (if any)
2466 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
2468 wxLayoutConstraints
*constr
= GetConstraints();
2471 if ( x
!= wxDefaultCoord
)
2473 constr
->left
.SetValue(x
);
2474 constr
->left
.SetDone(true);
2476 if ( y
!= wxDefaultCoord
)
2478 constr
->top
.SetValue(y
);
2479 constr
->top
.SetDone(true);
2481 if ( w
!= wxDefaultCoord
)
2483 constr
->width
.SetValue(w
);
2484 constr
->width
.SetDone(true);
2486 if ( h
!= wxDefaultCoord
)
2488 constr
->height
.SetValue(h
);
2489 constr
->height
.SetDone(true);
2494 void wxWindowBase::MoveConstraint(int x
, int y
)
2496 wxLayoutConstraints
*constr
= GetConstraints();
2499 if ( x
!= wxDefaultCoord
)
2501 constr
->left
.SetValue(x
);
2502 constr
->left
.SetDone(true);
2504 if ( y
!= wxDefaultCoord
)
2506 constr
->top
.SetValue(y
);
2507 constr
->top
.SetDone(true);
2512 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2514 wxLayoutConstraints
*constr
= GetConstraints();
2517 *w
= constr
->width
.GetValue();
2518 *h
= constr
->height
.GetValue();
2524 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2526 wxLayoutConstraints
*constr
= GetConstraints();
2529 *w
= constr
->width
.GetValue();
2530 *h
= constr
->height
.GetValue();
2533 GetClientSize(w
, h
);
2536 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2538 wxLayoutConstraints
*constr
= GetConstraints();
2541 *x
= constr
->left
.GetValue();
2542 *y
= constr
->top
.GetValue();
2548 #endif // wxUSE_CONSTRAINTS
2550 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2552 // don't do it for the dialogs/frames - they float independently of their
2554 if ( !IsTopLevel() )
2556 wxWindow
*parent
= GetParent();
2557 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2559 wxPoint
pt(parent
->GetClientAreaOrigin());
2566 // ----------------------------------------------------------------------------
2567 // Update UI processing
2568 // ----------------------------------------------------------------------------
2570 void wxWindowBase::UpdateWindowUI(long flags
)
2572 wxUpdateUIEvent
event(GetId());
2573 event
.SetEventObject(this);
2575 if ( GetEventHandler()->ProcessEvent(event
) )
2577 DoUpdateWindowUI(event
);
2580 if (flags
& wxUPDATE_UI_RECURSE
)
2582 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2585 wxWindow
* child
= (wxWindow
*) node
->GetData();
2586 child
->UpdateWindowUI(flags
);
2587 node
= node
->GetNext();
2592 // do the window-specific processing after processing the update event
2593 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2595 if ( event
.GetSetEnabled() )
2596 Enable(event
.GetEnabled());
2598 if ( event
.GetSetShown() )
2599 Show(event
.GetShown());
2602 // ----------------------------------------------------------------------------
2603 // dialog units translations
2604 // ----------------------------------------------------------------------------
2606 // Windows' computes dialog units using average character width over upper-
2607 // and lower-case ASCII alphabet and not using the average character width
2608 // metadata stored in the font; see
2609 // http://support.microsoft.com/default.aspx/kb/145994 for detailed discussion.
2610 // It's important that we perform the conversion in identical way, because
2611 // dialog units natively exist only on Windows and Windows HIG is expressed
2613 wxSize
wxWindowBase::GetDlgUnitBase() const
2615 const wxWindowBase
* const parent
= wxGetTopLevelParent((wxWindow
*)this);
2617 if ( !parent
->m_font
.IsOk() )
2619 // Default GUI font is used. This is the most common case, so
2620 // cache the results.
2621 static wxSize s_defFontSize
;
2622 if ( s_defFontSize
.x
== 0 )
2623 s_defFontSize
= wxPrivate::GetAverageASCIILetterSize(*parent
);
2624 return s_defFontSize
;
2628 // Custom font, we always need to compute the result
2629 return wxPrivate::GetAverageASCIILetterSize(*parent
);
2633 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
) const
2635 const wxSize base
= GetDlgUnitBase();
2637 // NB: wxMulDivInt32() is used, because it correctly rounds the result
2639 wxPoint pt2
= wxDefaultPosition
;
2640 if (pt
.x
!= wxDefaultCoord
)
2641 pt2
.x
= wxMulDivInt32(pt
.x
, 4, base
.x
);
2642 if (pt
.y
!= wxDefaultCoord
)
2643 pt2
.y
= wxMulDivInt32(pt
.y
, 8, base
.y
);
2648 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
) const
2650 const wxSize base
= GetDlgUnitBase();
2652 wxPoint pt2
= wxDefaultPosition
;
2653 if (pt
.x
!= wxDefaultCoord
)
2654 pt2
.x
= wxMulDivInt32(pt
.x
, base
.x
, 4);
2655 if (pt
.y
!= wxDefaultCoord
)
2656 pt2
.y
= wxMulDivInt32(pt
.y
, base
.y
, 8);
2661 // ----------------------------------------------------------------------------
2663 // ----------------------------------------------------------------------------
2665 // propagate the colour change event to the subwindows
2666 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
2668 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2671 // Only propagate to non-top-level windows
2672 wxWindow
*win
= node
->GetData();
2673 if ( !win
->IsTopLevel() )
2675 wxSysColourChangedEvent event2
;
2676 event2
.SetEventObject(win
);
2677 win
->GetEventHandler()->ProcessEvent(event2
);
2680 node
= node
->GetNext();
2686 // the default action is to populate dialog with data when it's created,
2687 // and nudge the UI into displaying itself correctly in case
2688 // we've turned the wxUpdateUIEvents frequency down low.
2689 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2691 TransferDataToWindow();
2693 // Update the UI at this point
2694 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2697 // ----------------------------------------------------------------------------
2698 // menu-related functions
2699 // ----------------------------------------------------------------------------
2703 bool wxWindowBase::PopupMenu(wxMenu
*menu
, int x
, int y
)
2705 wxCHECK_MSG( menu
, false, "can't popup NULL menu" );
2707 wxMenuInvokingWindowSetter
2708 setInvokingWin(*menu
, static_cast<wxWindow
*>(this));
2710 wxCurrentPopupMenu
= menu
;
2711 const bool rc
= DoPopupMenu(menu
, x
, y
);
2712 wxCurrentPopupMenu
= NULL
;
2717 // this is used to pass the id of the selected item from the menu event handler
2718 // to the main function itself
2720 // it's ok to use a global here as there can be at most one popup menu shown at
2722 static int gs_popupMenuSelection
= wxID_NONE
;
2724 void wxWindowBase::InternalOnPopupMenu(wxCommandEvent
& event
)
2726 // store the id in a global variable where we'll retrieve it from later
2727 gs_popupMenuSelection
= event
.GetId();
2730 void wxWindowBase::InternalOnPopupMenuUpdate(wxUpdateUIEvent
& WXUNUSED(event
))
2732 // nothing to do but do not skip it
2736 wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu
& menu
, int x
, int y
)
2738 gs_popupMenuSelection
= wxID_NONE
;
2740 Connect(wxEVT_COMMAND_MENU_SELECTED
,
2741 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2745 // it is common to construct the menu passed to this function dynamically
2746 // using some fixed range of ids which could clash with the ids used
2747 // elsewhere in the program, which could result in some menu items being
2748 // unintentionally disabled or otherwise modified by update UI handlers
2749 // elsewhere in the program code and this is difficult to avoid in the
2750 // program itself, so instead we just temporarily suspend UI updating while
2751 // this menu is shown
2752 Connect(wxEVT_UPDATE_UI
,
2753 wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate
),
2757 PopupMenu(&menu
, x
, y
);
2759 Disconnect(wxEVT_UPDATE_UI
,
2760 wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate
),
2763 Disconnect(wxEVT_COMMAND_MENU_SELECTED
,
2764 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2768 return gs_popupMenuSelection
;
2771 #endif // wxUSE_MENUS
2773 // methods for drawing the sizers in a visible way: this is currently only
2774 // enabled for "full debug" builds with wxDEBUG_LEVEL==2 as it doesn't work
2775 // that well and also because we don't want to leave it enabled in default
2776 // builds used for production
2777 #if wxDEBUG_LEVEL > 1
2779 static void DrawSizers(wxWindowBase
*win
);
2781 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
, const wxPen
* pen
)
2783 wxClientDC
dc((wxWindow
*)win
);
2785 dc
.SetBrush(fill
? wxBrush(pen
->GetColour(), wxBRUSHSTYLE_CROSSDIAG_HATCH
) :
2786 *wxTRANSPARENT_BRUSH
);
2787 dc
.DrawRectangle(rect
.Deflate(1, 1));
2790 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2792 const wxSizerItemList
& items
= sizer
->GetChildren();
2793 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2798 wxSizerItem
*item
= *i
;
2799 if ( item
->IsSizer() )
2801 DrawBorder(win
, item
->GetRect().Deflate(2), false, wxRED_PEN
);
2802 DrawSizer(win
, item
->GetSizer());
2804 else if ( item
->IsSpacer() )
2806 DrawBorder(win
, item
->GetRect().Deflate(2), true, wxBLUE_PEN
);
2808 else if ( item
->IsWindow() )
2810 DrawSizers(item
->GetWindow());
2813 wxFAIL_MSG("inconsistent wxSizerItem status!");
2817 static void DrawSizers(wxWindowBase
*win
)
2819 DrawBorder(win
, win
->GetClientSize(), false, wxGREEN_PEN
);
2821 wxSizer
*sizer
= win
->GetSizer();
2824 DrawSizer(win
, sizer
);
2826 else // no sizer, still recurse into the children
2828 const wxWindowList
& children
= win
->GetChildren();
2829 for ( wxWindowList::const_iterator i
= children
.begin(),
2830 end
= children
.end();
2837 // show all kind of sizes of this window; see the "window sizing" topic
2838 // overview for more info about the various differences:
2839 wxSize fullSz
= win
->GetSize();
2840 wxSize clientSz
= win
->GetClientSize();
2841 wxSize bestSz
= win
->GetBestSize();
2842 wxSize minSz
= win
->GetMinSize();
2843 wxSize maxSz
= win
->GetMaxSize();
2844 wxSize virtualSz
= win
->GetVirtualSize();
2846 wxMessageOutputDebug dbgout
;
2848 "%-10s => fullsz=%4d;%-4d clientsz=%4d;%-4d bestsz=%4d;%-4d minsz=%4d;%-4d maxsz=%4d;%-4d virtualsz=%4d;%-4d\n",
2851 clientSz
.x
, clientSz
.y
,
2855 virtualSz
.x
, virtualSz
.y
);
2859 #endif // wxDEBUG_LEVEL
2861 // process special middle clicks
2862 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2864 if ( event
.ControlDown() && event
.AltDown() )
2866 #if wxDEBUG_LEVEL > 1
2867 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2868 if ( event
.ShiftDown() )
2873 #endif // __WXDEBUG__
2876 // just Ctrl-Alt-middle click shows information about wx version
2877 ::wxInfoMessageBox((wxWindow
*)this);
2878 #endif // wxUSE_MSGDLG
2887 // ----------------------------------------------------------------------------
2889 // ----------------------------------------------------------------------------
2891 #if wxUSE_ACCESSIBILITY
2892 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2894 if (m_accessible
&& (accessible
!= m_accessible
))
2895 delete m_accessible
;
2896 m_accessible
= accessible
;
2898 m_accessible
->SetWindow((wxWindow
*) this);
2901 // Returns the accessible object, creating if necessary.
2902 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2905 m_accessible
= CreateAccessible();
2906 return m_accessible
;
2909 // Override to create a specific accessible object.
2910 wxAccessible
* wxWindowBase::CreateAccessible()
2912 return new wxWindowAccessible((wxWindow
*) this);
2917 // ----------------------------------------------------------------------------
2918 // list classes implementation
2919 // ----------------------------------------------------------------------------
2923 #include "wx/listimpl.cpp"
2924 WX_DEFINE_LIST(wxWindowList
)
2928 void wxWindowListNode::DeleteData()
2930 delete (wxWindow
*)GetData();
2933 #endif // wxUSE_STL/!wxUSE_STL
2935 // ----------------------------------------------------------------------------
2937 // ----------------------------------------------------------------------------
2939 wxBorder
wxWindowBase::GetBorder(long flags
) const
2941 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2942 if ( border
== wxBORDER_DEFAULT
)
2944 border
= GetDefaultBorder();
2946 else if ( border
== wxBORDER_THEME
)
2948 border
= GetDefaultBorderForControl();
2954 wxBorder
wxWindowBase::GetDefaultBorder() const
2956 return wxBORDER_NONE
;
2959 // ----------------------------------------------------------------------------
2961 // ----------------------------------------------------------------------------
2963 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2965 // here we just check if the point is inside the window or not
2967 // check the top and left border first
2968 bool outside
= x
< 0 || y
< 0;
2971 // check the right and bottom borders too
2972 wxSize size
= GetSize();
2973 outside
= x
>= size
.x
|| y
>= size
.y
;
2976 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2979 // ----------------------------------------------------------------------------
2981 // ----------------------------------------------------------------------------
2983 struct WXDLLEXPORT wxWindowNext
2987 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2988 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2989 bool wxWindowBase::ms_winCaptureChanging
= false;
2991 void wxWindowBase::CaptureMouse()
2993 wxLogTrace(wxT("mousecapture"), wxT("CaptureMouse(%p)"), static_cast<void*>(this));
2995 wxASSERT_MSG( !ms_winCaptureChanging
, wxT("recursive CaptureMouse call?") );
2997 ms_winCaptureChanging
= true;
2999 wxWindow
*winOld
= GetCapture();
3002 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
3005 wxWindowNext
*item
= new wxWindowNext
;
3007 item
->next
= ms_winCaptureNext
;
3008 ms_winCaptureNext
= item
;
3010 //else: no mouse capture to save
3013 ms_winCaptureCurrent
= (wxWindow
*)this;
3015 ms_winCaptureChanging
= false;
3018 void wxWindowBase::ReleaseMouse()
3020 wxLogTrace(wxT("mousecapture"), wxT("ReleaseMouse(%p)"), static_cast<void*>(this));
3022 wxASSERT_MSG( !ms_winCaptureChanging
, wxT("recursive ReleaseMouse call?") );
3024 wxASSERT_MSG( GetCapture() == this,
3025 "attempt to release mouse, but this window hasn't captured it" );
3026 wxASSERT_MSG( ms_winCaptureCurrent
== this,
3027 "attempt to release mouse, but this window hasn't captured it" );
3029 ms_winCaptureChanging
= true;
3032 ms_winCaptureCurrent
= NULL
;
3034 if ( ms_winCaptureNext
)
3036 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
3037 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
3039 wxWindowNext
*item
= ms_winCaptureNext
;
3040 ms_winCaptureNext
= item
->next
;
3043 //else: stack is empty, no previous capture
3045 ms_winCaptureChanging
= false;
3047 wxLogTrace(wxT("mousecapture"),
3048 (const wxChar
*) wxT("After ReleaseMouse() mouse is captured by %p"),
3049 static_cast<void*>(GetCapture()));
3052 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
3054 wxMouseCaptureLostEvent
event(win
->GetId());
3055 event
.SetEventObject(win
);
3056 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
3058 // windows must handle this event, otherwise the app wouldn't behave
3059 // correctly if it loses capture unexpectedly; see the discussion here:
3060 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
3061 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
3062 wxFAIL_MSG( wxT("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
3067 void wxWindowBase::NotifyCaptureLost()
3069 // don't do anything if capture lost was expected, i.e. resulted from
3070 // a wx call to ReleaseMouse or CaptureMouse:
3071 if ( ms_winCaptureChanging
)
3074 // if the capture was lost unexpectedly, notify every window that has
3075 // capture (on stack or current) about it and clear the stack:
3077 if ( ms_winCaptureCurrent
)
3079 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
3080 ms_winCaptureCurrent
= NULL
;
3083 while ( ms_winCaptureNext
)
3085 wxWindowNext
*item
= ms_winCaptureNext
;
3086 ms_winCaptureNext
= item
->next
;
3088 DoNotifyWindowAboutCaptureLost(item
->win
);
3097 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
3098 int WXUNUSED(modifiers
),
3099 int WXUNUSED(keycode
))
3105 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
3111 #endif // wxUSE_HOTKEY
3113 // ----------------------------------------------------------------------------
3115 // ----------------------------------------------------------------------------
3117 bool wxWindowBase::TryBefore(wxEvent
& event
)
3119 #if wxUSE_VALIDATORS
3120 // Can only use the validator of the window which
3121 // is receiving the event
3122 if ( event
.GetEventObject() == this )
3124 wxValidator
* const validator
= GetValidator();
3125 if ( validator
&& validator
->ProcessEventLocally(event
) )
3130 #endif // wxUSE_VALIDATORS
3132 return wxEvtHandler::TryBefore(event
);
3135 bool wxWindowBase::TryAfter(wxEvent
& event
)
3137 // carry on up the parent-child hierarchy if the propagation count hasn't
3139 if ( event
.ShouldPropagate() )
3141 // honour the requests to stop propagation at this window: this is
3142 // used by the dialogs, for example, to prevent processing the events
3143 // from the dialog controls in the parent frame which rarely, if ever,
3145 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
3147 wxWindow
*parent
= GetParent();
3148 if ( parent
&& !parent
->IsBeingDeleted() )
3150 wxPropagateOnce
propagateOnce(event
);
3152 return parent
->GetEventHandler()->ProcessEvent(event
);
3157 return wxEvtHandler::TryAfter(event
);
3160 // ----------------------------------------------------------------------------
3161 // window relationships
3162 // ----------------------------------------------------------------------------
3164 wxWindow
*wxWindowBase::DoGetSibling(WindowOrder order
) const
3166 wxCHECK_MSG( GetParent(), NULL
,
3167 wxT("GetPrev/NextSibling() don't work for TLWs!") );
3169 wxWindowList
& siblings
= GetParent()->GetChildren();
3170 wxWindowList::compatibility_iterator i
= siblings
.Find((wxWindow
*)this);
3171 wxCHECK_MSG( i
, NULL
, wxT("window not a child of its parent?") );
3173 if ( order
== OrderBefore
)
3174 i
= i
->GetPrevious();
3178 return i
? i
->GetData() : NULL
;
3181 // ----------------------------------------------------------------------------
3182 // keyboard navigation
3183 // ----------------------------------------------------------------------------
3185 // Navigates in the specified direction inside this window
3186 bool wxWindowBase::DoNavigateIn(int flags
)
3188 #ifdef wxHAS_NATIVE_TAB_TRAVERSAL
3189 // native code doesn't process our wxNavigationKeyEvents anyhow
3192 #else // !wxHAS_NATIVE_TAB_TRAVERSAL
3193 wxNavigationKeyEvent eventNav
;
3194 wxWindow
*focused
= FindFocus();
3195 eventNav
.SetCurrentFocus(focused
);
3196 eventNav
.SetEventObject(focused
);
3197 eventNav
.SetFlags(flags
);
3198 return GetEventHandler()->ProcessEvent(eventNav
);
3199 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
3202 bool wxWindowBase::HandleAsNavigationKey(const wxKeyEvent
& event
)
3204 if ( event
.GetKeyCode() != WXK_TAB
)
3207 int flags
= wxNavigationKeyEvent::FromTab
;
3209 if ( event
.ShiftDown() )
3210 flags
|= wxNavigationKeyEvent::IsBackward
;
3212 flags
|= wxNavigationKeyEvent::IsForward
;
3214 if ( event
.ControlDown() )
3215 flags
|= wxNavigationKeyEvent::WinChange
;
3221 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, WindowOrder move
)
3223 // check that we're not a top level window
3224 wxCHECK_RET( GetParent(),
3225 wxT("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
3227 // detect the special case when we have nothing to do anyhow and when the
3228 // code below wouldn't work
3232 // find the target window in the siblings list
3233 wxWindowList
& siblings
= GetParent()->GetChildren();
3234 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
3235 wxCHECK_RET( i
, wxT("MoveBefore/AfterInTabOrder(): win is not a sibling") );
3237 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
3238 // can't just move the node around
3239 wxWindow
*self
= (wxWindow
*)this;
3240 siblings
.DeleteObject(self
);
3241 if ( move
== OrderAfter
)
3248 siblings
.Insert(i
, self
);
3250 else // OrderAfter and win was the last sibling
3252 siblings
.Append(self
);
3256 // ----------------------------------------------------------------------------
3258 // ----------------------------------------------------------------------------
3260 /*static*/ wxWindow
* wxWindowBase::FindFocus()
3262 wxWindowBase
*win
= DoFindFocus();
3263 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
3266 bool wxWindowBase::HasFocus() const
3268 wxWindowBase
*win
= DoFindFocus();
3269 return win
== this ||
3270 win
== wxConstCast(this, wxWindowBase
)->GetMainWindowOfCompositeControl();
3273 // ----------------------------------------------------------------------------
3275 // ----------------------------------------------------------------------------
3277 #if wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
3282 class DragAcceptFilesTarget
: public wxFileDropTarget
3285 DragAcceptFilesTarget(wxWindowBase
*win
) : m_win(win
) {}
3287 virtual bool OnDropFiles(wxCoord x
, wxCoord y
,
3288 const wxArrayString
& filenames
)
3290 wxDropFilesEvent
event(wxEVT_DROP_FILES
,
3292 wxCArrayString(filenames
).Release());
3293 event
.SetEventObject(m_win
);
3297 return m_win
->HandleWindowEvent(event
);
3301 wxWindowBase
* const m_win
;
3303 wxDECLARE_NO_COPY_CLASS(DragAcceptFilesTarget
);
3307 } // anonymous namespace
3309 // Generic version of DragAcceptFiles(). It works by installing a simple
3310 // wxFileDropTarget-to-EVT_DROP_FILES adaptor and therefore cannot be used
3311 // together with explicit SetDropTarget() calls.
3312 void wxWindowBase::DragAcceptFiles(bool accept
)
3316 wxASSERT_MSG( !GetDropTarget(),
3317 "cannot use DragAcceptFiles() and SetDropTarget() together" );
3318 SetDropTarget(new DragAcceptFilesTarget(this));
3322 SetDropTarget(NULL
);
3326 #endif // wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
3328 // ----------------------------------------------------------------------------
3330 // ----------------------------------------------------------------------------
3332 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
3334 while ( win
&& !win
->IsTopLevel() )
3335 win
= win
->GetParent();
3340 #if wxUSE_ACCESSIBILITY
3341 // ----------------------------------------------------------------------------
3342 // accessible object for windows
3343 // ----------------------------------------------------------------------------
3345 // Can return either a child object, or an integer
3346 // representing the child element, starting from 1.
3347 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
3349 wxASSERT( GetWindow() != NULL
);
3353 return wxACC_NOT_IMPLEMENTED
;
3356 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
3357 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
3359 wxASSERT( GetWindow() != NULL
);
3363 wxWindow
* win
= NULL
;
3370 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
3372 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
3379 rect
= win
->GetRect();
3380 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
3381 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
3385 return wxACC_NOT_IMPLEMENTED
;
3388 // Navigates from fromId to toId/toObject.
3389 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
3390 int* WXUNUSED(toId
), wxAccessible
** toObject
)
3392 wxASSERT( GetWindow() != NULL
);
3398 case wxNAVDIR_FIRSTCHILD
:
3400 if (GetWindow()->GetChildren().GetCount() == 0)
3402 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
3403 *toObject
= childWindow
->GetOrCreateAccessible();
3407 case wxNAVDIR_LASTCHILD
:
3409 if (GetWindow()->GetChildren().GetCount() == 0)
3411 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
3412 *toObject
= childWindow
->GetOrCreateAccessible();
3416 case wxNAVDIR_RIGHT
:
3420 wxWindowList::compatibility_iterator node
=
3421 wxWindowList::compatibility_iterator();
3424 // Can't navigate to sibling of this window
3425 // if we're a top-level window.
3426 if (!GetWindow()->GetParent())
3427 return wxACC_NOT_IMPLEMENTED
;
3429 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3433 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
3434 node
= GetWindow()->GetChildren().Item(fromId
-1);
3437 if (node
&& node
->GetNext())
3439 wxWindow
* nextWindow
= node
->GetNext()->GetData();
3440 *toObject
= nextWindow
->GetOrCreateAccessible();
3448 case wxNAVDIR_PREVIOUS
:
3450 wxWindowList::compatibility_iterator node
=
3451 wxWindowList::compatibility_iterator();
3454 // Can't navigate to sibling of this window
3455 // if we're a top-level window.
3456 if (!GetWindow()->GetParent())
3457 return wxACC_NOT_IMPLEMENTED
;
3459 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3463 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
3464 node
= GetWindow()->GetChildren().Item(fromId
-1);
3467 if (node
&& node
->GetPrevious())
3469 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
3470 *toObject
= previousWindow
->GetOrCreateAccessible();
3478 return wxACC_NOT_IMPLEMENTED
;
3481 // Gets the name of the specified object.
3482 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
3484 wxASSERT( GetWindow() != NULL
);
3490 // If a child, leave wxWidgets to call the function on the actual
3493 return wxACC_NOT_IMPLEMENTED
;
3495 // This will eventually be replaced by specialised
3496 // accessible classes, one for each kind of wxWidgets
3497 // control or window.
3499 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
3500 title
= ((wxButton
*) GetWindow())->GetLabel();
3503 title
= GetWindow()->GetName();
3511 return wxACC_NOT_IMPLEMENTED
;
3514 // Gets the number of children.
3515 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
3517 wxASSERT( GetWindow() != NULL
);
3521 *childId
= (int) GetWindow()->GetChildren().GetCount();
3525 // Gets the specified child (starting from 1).
3526 // If *child is NULL and return value is wxACC_OK,
3527 // this means that the child is a simple element and
3528 // not an accessible object.
3529 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
3531 wxASSERT( GetWindow() != NULL
);
3541 if (childId
> (int) GetWindow()->GetChildren().GetCount())
3544 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
3545 *child
= childWindow
->GetOrCreateAccessible();
3552 // Gets the parent, or NULL.
3553 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
3555 wxASSERT( GetWindow() != NULL
);
3559 wxWindow
* parentWindow
= GetWindow()->GetParent();
3567 *parent
= parentWindow
->GetOrCreateAccessible();
3575 // Performs the default action. childId is 0 (the action for this object)
3576 // or > 0 (the action for a child).
3577 // Return wxACC_NOT_SUPPORTED if there is no default action for this
3578 // window (e.g. an edit control).
3579 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
3581 wxASSERT( GetWindow() != NULL
);
3585 return wxACC_NOT_IMPLEMENTED
;
3588 // Gets the default action for this object (0) or > 0 (the action for a child).
3589 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
3590 // string if there is no action.
3591 // The retrieved string describes the action that is performed on an object,
3592 // not what the object does as a result. For example, a toolbar button that prints
3593 // a document has a default action of "Press" rather than "Prints the current document."
3594 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
3596 wxASSERT( GetWindow() != NULL
);
3600 return wxACC_NOT_IMPLEMENTED
;
3603 // Returns the description for this object or a child.
3604 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
3606 wxASSERT( GetWindow() != NULL
);
3610 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3616 return wxACC_NOT_IMPLEMENTED
;
3619 // Returns help text for this object or a child, similar to tooltip text.
3620 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
3622 wxASSERT( GetWindow() != NULL
);
3626 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3632 return wxACC_NOT_IMPLEMENTED
;
3635 // Returns the keyboard shortcut for this object or child.
3636 // Return e.g. ALT+K
3637 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
3639 wxASSERT( GetWindow() != NULL
);
3643 return wxACC_NOT_IMPLEMENTED
;
3646 // Returns a role constant.
3647 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
3649 wxASSERT( GetWindow() != NULL
);
3653 // If a child, leave wxWidgets to call the function on the actual
3656 return wxACC_NOT_IMPLEMENTED
;
3658 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3659 return wxACC_NOT_IMPLEMENTED
;
3661 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3662 return wxACC_NOT_IMPLEMENTED
;
3665 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3666 return wxACC_NOT_IMPLEMENTED
;
3669 //*role = wxROLE_SYSTEM_CLIENT;
3670 *role
= wxROLE_SYSTEM_CLIENT
;
3674 return wxACC_NOT_IMPLEMENTED
;
3678 // Returns a state constant.
3679 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
3681 wxASSERT( GetWindow() != NULL
);
3685 // If a child, leave wxWidgets to call the function on the actual
3688 return wxACC_NOT_IMPLEMENTED
;
3690 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3691 return wxACC_NOT_IMPLEMENTED
;
3694 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3695 return wxACC_NOT_IMPLEMENTED
;
3698 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3699 return wxACC_NOT_IMPLEMENTED
;
3706 return wxACC_NOT_IMPLEMENTED
;
3710 // Returns a localized string representing the value for the object
3712 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3714 wxASSERT( GetWindow() != NULL
);
3718 return wxACC_NOT_IMPLEMENTED
;
3721 // Selects the object or child.
3722 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3724 wxASSERT( GetWindow() != NULL
);
3728 return wxACC_NOT_IMPLEMENTED
;
3731 // Gets the window with the keyboard focus.
3732 // If childId is 0 and child is NULL, no object in
3733 // this subhierarchy has the focus.
3734 // If this object has the focus, child should be 'this'.
3735 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3737 wxASSERT( GetWindow() != NULL
);
3741 return wxACC_NOT_IMPLEMENTED
;
3745 // Gets a variant representing the selected children
3747 // Acceptable values:
3748 // - a null variant (IsNull() returns true)
3749 // - a list variant (GetType() == wxT("list")
3750 // - an integer representing the selected child element,
3751 // or 0 if this object is selected (GetType() == wxT("long")
3752 // - a "void*" pointer to a wxAccessible child object
3753 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3755 wxASSERT( GetWindow() != NULL
);
3759 return wxACC_NOT_IMPLEMENTED
;
3761 #endif // wxUSE_VARIANT
3763 #endif // wxUSE_ACCESSIBILITY
3765 // ----------------------------------------------------------------------------
3767 // ----------------------------------------------------------------------------
3770 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3772 wxCoord widthTotal
) const
3774 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3776 x
= widthTotal
- x
- width
;