1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/window.cpp
3 // Purpose: common (to all ports) wxWindow functions
4 // Author: Julian Smart, Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/string.h"
32 #include "wx/window.h"
33 #include "wx/control.h"
34 #include "wx/checkbox.h"
35 #include "wx/radiobut.h"
36 #include "wx/statbox.h"
37 #include "wx/textctrl.h"
38 #include "wx/settings.h"
39 #include "wx/dialog.h"
40 #include "wx/msgdlg.h"
41 #include "wx/msgout.h"
42 #include "wx/statusbr.h"
43 #include "wx/toolbar.h"
44 #include "wx/dcclient.h"
45 #include "wx/scrolbar.h"
46 #include "wx/layout.h"
51 #if wxUSE_DRAG_AND_DROP
53 #endif // wxUSE_DRAG_AND_DROP
55 #if wxUSE_ACCESSIBILITY
56 #include "wx/access.h"
60 #include "wx/cshelp.h"
64 #include "wx/tooltip.h"
65 #endif // wxUSE_TOOLTIPS
71 #if wxUSE_SYSTEM_OPTIONS
72 #include "wx/sysopt.h"
75 #include "wx/platinfo.h"
76 #include "wx/private/window.h"
79 #include "wx/msw/wrapwin.h"
83 WXDLLIMPEXP_DATA_CORE(wxWindowList
) wxTopLevelWindows
;
87 wxMenu
*wxCurrentPopupMenu
= NULL
;
90 // ----------------------------------------------------------------------------
92 // ----------------------------------------------------------------------------
95 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
102 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
103 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
104 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
107 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
110 EVT_SIZE(wxWindowBase::InternalOnSize
)
113 // ============================================================================
114 // implementation of the common functionality of the wxWindow class
115 // ============================================================================
117 // ----------------------------------------------------------------------------
119 // ----------------------------------------------------------------------------
121 #if wxUSE_EXTENDED_RTTI
123 // windows that are created from a parent window during its Create method,
124 // eg. spin controls in a calendar controls must never been streamed out
125 // separately otherwise chaos occurs. Right now easiest is to test for negative ids,
126 // as windows with negative ids never can be recreated anyway
128 bool wxWindowStreamingCallback( const wxObject
*object
, wxObjectWriter
*,
129 wxObjectReaderCallback
*, wxVariantBaseArray
& )
131 const wxWindow
* win
= wx_dynamic_cast(const wxWindow
*, object
);
132 if ( win
&& win
->GetId() < 0 )
137 wxIMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
, "wx/window.h", \
138 wxWindowStreamingCallback
)
140 // make wxWindowList known before the property is used
142 wxCOLLECTION_TYPE_INFO( wxWindow
*, wxWindowList
);
144 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
,
145 wxVariantBaseArray
&value
)
147 wxListCollectionToVariantArray
<wxWindowList::compatibility_iterator
>( theList
, value
);
150 wxDEFINE_FLAGS( wxWindowStyle
)
152 wxBEGIN_FLAGS( wxWindowStyle
)
153 // new style border flags, we put them first to
154 // use them for streaming out
156 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
157 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
158 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
159 wxFLAGS_MEMBER(wxBORDER_RAISED
)
160 wxFLAGS_MEMBER(wxBORDER_STATIC
)
161 wxFLAGS_MEMBER(wxBORDER_NONE
)
163 // old style border flags
164 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
165 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
166 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
167 wxFLAGS_MEMBER(wxRAISED_BORDER
)
168 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
169 wxFLAGS_MEMBER(wxBORDER
)
171 // standard window styles
172 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
173 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
174 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
175 wxFLAGS_MEMBER(wxWANTS_CHARS
)
176 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
177 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
178 wxFLAGS_MEMBER(wxVSCROLL
)
179 wxFLAGS_MEMBER(wxHSCROLL
)
181 wxEND_FLAGS( wxWindowStyle
)
183 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
184 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
185 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
186 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
187 // Always constructor Properties first
189 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, wxEMPTY_PARAMETER_VALUE
, \
190 0 /*flags*/, wxT("Helpstring"), wxT("group"))
191 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, -1 /*wxID_ANY*/, 0 /*flags*/, \
192 wxT("Helpstring"), wxT("group") )
193 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, \
194 0 /*flags*/, wxT("Helpstring"), wxT("group")) // pos
195 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/, \
196 wxT("Helpstring"), wxT("group")) // size
197 wxPROPERTY( WindowStyle
, long, SetWindowStyleFlag
, GetWindowStyleFlag
, \
198 wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, wxT("Helpstring"), wxT("group")) // style
199 wxPROPERTY( Name
,wxString
, SetName
, GetName
, wxEmptyString
, 0 /*flags*/, \
200 wxT("Helpstring"), wxT("group") )
202 // Then all relations of the object graph
204 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
*, \
205 GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/, \
206 wxT("Helpstring"), wxT("group"))
208 // and finally all other properties
210 wxPROPERTY( ExtraStyle
, long, SetExtraStyle
, GetExtraStyle
, wxEMPTY_PARAMETER_VALUE
, \
211 0 /*flags*/, wxT("Helpstring"), wxT("group")) // extstyle
212 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, \
213 wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, wxT("Helpstring"), wxT("group")) // bg
214 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, \
215 wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, wxT("Helpstring"), wxT("group")) // fg
216 wxPROPERTY( Enabled
, bool, Enable
, IsEnabled
, wxVariantBase((bool)true), 0 /*flags*/, \
217 wxT("Helpstring"), wxT("group"))
218 wxPROPERTY( Shown
, bool, Show
, IsShown
, wxVariantBase((bool)true), 0 /*flags*/, \
219 wxT("Helpstring"), wxT("group"))
222 // possible property candidates (not in xrc) or not valid in all subclasses
223 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxEmptyString
)
224 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
225 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxEmptyString
)
226 // MaxHeight, Width, MinHeight, Width
227 // TODO switch label to control and title to toplevels
229 wxPROPERTY( ThemeEnabled
, bool, SetThemeEnabled
, GetThemeEnabled
, )
230 //wxPROPERTY( Cursor, wxCursor, SetCursor, GetCursor, )
231 // wxPROPERTY( ToolTip, wxString, SetToolTip, GetToolTipText, )
232 wxPROPERTY( AutoLayout
, bool, SetAutoLayout
, GetAutoLayout
, )
234 wxEND_PROPERTIES_TABLE()
236 wxEMPTY_HANDLERS_TABLE(wxWindow
)
238 wxCONSTRUCTOR_DUMMY(wxWindow
)
242 #ifndef __WXUNIVERSAL__
243 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
248 // ----------------------------------------------------------------------------
250 // ----------------------------------------------------------------------------
252 // the default initialization
253 wxWindowBase::wxWindowBase()
255 // no window yet, no parent nor children
257 m_windowId
= wxID_ANY
;
259 // no constraints on the minimal window size
261 m_maxWidth
= wxDefaultCoord
;
263 m_maxHeight
= wxDefaultCoord
;
265 // invalidiated cache value
266 m_bestSizeCache
= wxDefaultSize
;
268 // window are created enabled and visible by default
272 // the default event handler is just this window
273 m_eventHandler
= this;
277 m_windowValidator
= NULL
;
278 #endif // wxUSE_VALIDATORS
280 // the colours/fonts are default for now, so leave m_font,
281 // m_backgroundColour and m_foregroundColour uninitialized and set those
287 m_inheritFont
= false;
293 m_backgroundStyle
= wxBG_STYLE_ERASE
;
295 #if wxUSE_CONSTRAINTS
296 // no constraints whatsoever
297 m_constraints
= NULL
;
298 m_constraintsInvolvedIn
= NULL
;
299 #endif // wxUSE_CONSTRAINTS
301 m_windowSizer
= NULL
;
302 m_containingSizer
= NULL
;
303 m_autoLayout
= false;
305 #if wxUSE_DRAG_AND_DROP
307 #endif // wxUSE_DRAG_AND_DROP
311 #endif // wxUSE_TOOLTIPS
315 #endif // wxUSE_CARET
318 m_hasCustomPalette
= false;
319 #endif // wxUSE_PALETTE
321 #if wxUSE_ACCESSIBILITY
325 m_virtualSize
= wxDefaultSize
;
327 m_scrollHelper
= NULL
;
329 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
330 #if wxUSE_SYSTEM_OPTIONS
331 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
333 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
337 // Whether we're using the current theme for this window (wxGTK only for now)
338 m_themeEnabled
= false;
340 // This is set to true by SendDestroyEvent() which should be called by the
341 // most derived class to ensure that the destruction event is sent as soon
342 // as possible to allow its handlers to still see the undestroyed window
343 m_isBeingDeleted
= false;
348 // common part of window creation process
349 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
351 const wxPoint
& WXUNUSED(pos
),
354 const wxString
& name
)
356 // ids are limited to 16 bits under MSW so if you care about portability,
357 // it's not a good idea to use ids out of this range (and negative ids are
358 // reserved for wxWidgets own usage)
359 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767) ||
360 (id
>= wxID_AUTO_LOWEST
&& id
<= wxID_AUTO_HIGHEST
),
361 wxT("invalid id value") );
363 // generate a new id if the user doesn't care about it
364 if ( id
== wxID_ANY
)
366 m_windowId
= NewControlId();
368 else // valid id specified
373 // don't use SetWindowStyleFlag() here, this function should only be called
374 // to change the flag after creation as it tries to reflect the changes in
375 // flags by updating the window dynamically and we don't need this here
376 m_windowStyle
= style
;
378 // assume the user doesn't want this window to shrink beneath its initial
379 // size, this worked like this in wxWidgets 2.8 and before and generally
380 // often makes sense for child windows (for top level ones it definitely
381 // does not as the user should be able to resize the window)
383 // note that we can't use IsTopLevel() from ctor
384 if ( size
!= wxDefaultSize
&& !wxTopLevelWindows
.Find((wxWindow
*)this) )
393 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
398 const wxValidator
& wxVALIDATOR_PARAM(validator
),
399 const wxString
& name
)
401 if ( !CreateBase(parent
, id
, pos
, size
, style
, name
) )
405 SetValidator(validator
);
406 #endif // wxUSE_VALIDATORS
408 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
409 // have it too - like this it's possible to set it only in the top level
410 // dialog/frame and all children will inherit it by defult
411 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
413 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
419 bool wxWindowBase::ToggleWindowStyle(int flag
)
421 wxASSERT_MSG( flag
, wxT("flags with 0 value can't be toggled") );
424 long style
= GetWindowStyleFlag();
430 else // currently off
436 SetWindowStyleFlag(style
);
441 // ----------------------------------------------------------------------------
443 // ----------------------------------------------------------------------------
446 wxWindowBase::~wxWindowBase()
448 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
450 // FIXME if these 2 cases result from programming errors in the user code
451 // we should probably assert here instead of silently fixing them
453 // Just in case the window has been Closed, but we're then deleting
454 // immediately: don't leave dangling pointers.
455 wxPendingDelete
.DeleteObject(this);
457 // Just in case we've loaded a top-level window via LoadNativeDialog but
458 // we weren't a dialog class
459 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
461 // Any additional event handlers should be popped before the window is
462 // deleted as otherwise the last handler will be left with a dangling
463 // pointer to this window result in a difficult to diagnose crash later on.
464 wxASSERT_MSG( GetEventHandler() == this,
465 wxT("any pushed event handlers must have been removed") );
468 // The associated popup menu can still be alive, disassociate from it in
470 if ( wxCurrentPopupMenu
&& wxCurrentPopupMenu
->GetInvokingWindow() == this )
471 wxCurrentPopupMenu
->SetInvokingWindow(NULL
);
472 #endif // wxUSE_MENUS
474 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
476 // notify the parent about this window destruction
478 m_parent
->RemoveChild(this);
482 #endif // wxUSE_CARET
485 delete m_windowValidator
;
486 #endif // wxUSE_VALIDATORS
488 #if wxUSE_CONSTRAINTS
489 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
490 // at deleted windows as they delete themselves.
491 DeleteRelatedConstraints();
495 // This removes any dangling pointers to this window in other windows'
496 // constraintsInvolvedIn lists.
497 UnsetConstraints(m_constraints
);
498 wxDELETE(m_constraints
);
500 #endif // wxUSE_CONSTRAINTS
502 if ( m_containingSizer
)
503 m_containingSizer
->Detach( (wxWindow
*)this );
505 delete m_windowSizer
;
507 #if wxUSE_DRAG_AND_DROP
509 #endif // wxUSE_DRAG_AND_DROP
513 #endif // wxUSE_TOOLTIPS
515 #if wxUSE_ACCESSIBILITY
520 // NB: this has to be called unconditionally, because we don't know
521 // whether this window has associated help text or not
522 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
524 helpProvider
->RemoveHelp(this);
528 bool wxWindowBase::IsBeingDeleted() const
530 return m_isBeingDeleted
||
531 (!IsTopLevel() && m_parent
&& m_parent
->IsBeingDeleted());
534 void wxWindowBase::SendDestroyEvent()
536 if ( m_isBeingDeleted
)
538 // we could have been already called from a more derived class dtor,
539 // e.g. ~wxTLW calls us and so does ~wxWindow and the latter call
540 // should be simply ignored
544 m_isBeingDeleted
= true;
546 wxWindowDestroyEvent event
;
547 event
.SetEventObject(this);
548 event
.SetId(GetId());
549 GetEventHandler()->ProcessEvent(event
);
552 bool wxWindowBase::Destroy()
561 bool wxWindowBase::Close(bool force
)
563 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
564 event
.SetEventObject(this);
565 event
.SetCanVeto(!force
);
567 // return false if window wasn't closed because the application vetoed the
569 return HandleWindowEvent(event
) && !event
.GetVeto();
572 bool wxWindowBase::DestroyChildren()
574 wxWindowList::compatibility_iterator node
;
577 // we iterate until the list becomes empty
578 node
= GetChildren().GetFirst();
582 wxWindow
*child
= node
->GetData();
584 // note that we really want to delete it immediately so don't call the
585 // possible overridden Destroy() version which might not delete the
586 // child immediately resulting in problems with our (top level) child
587 // outliving its parent
588 child
->wxWindowBase::Destroy();
590 wxASSERT_MSG( !GetChildren().Find(child
),
591 wxT("child didn't remove itself using RemoveChild()") );
597 // ----------------------------------------------------------------------------
598 // size/position related methods
599 // ----------------------------------------------------------------------------
601 // centre the window with respect to its parent in either (or both) directions
602 void wxWindowBase::DoCentre(int dir
)
604 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
605 wxT("this method only implements centering child windows") );
607 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
610 // fits the window around the children
611 void wxWindowBase::Fit()
613 if ( !GetChildren().empty() )
615 SetSize(GetBestSize());
617 //else: do nothing if we have no children
620 // fits virtual size (ie. scrolled area etc.) around children
621 void wxWindowBase::FitInside()
623 if ( GetChildren().GetCount() > 0 )
625 SetVirtualSize( GetBestVirtualSize() );
629 // On Mac, scrollbars are explicitly children.
630 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
631 static bool wxHasRealChildren(const wxWindowBase
* win
)
633 int realChildCount
= 0;
635 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
637 node
= node
->GetNext() )
639 wxWindow
*win
= node
->GetData();
640 if ( !win
->IsTopLevel() && win
->IsShown()
642 && !win
->IsKindOf(CLASSINFO(wxScrollBar
))
647 return (realChildCount
> 0);
651 void wxWindowBase::InvalidateBestSize()
653 m_bestSizeCache
= wxDefaultSize
;
655 // parent's best size calculation may depend on its children's
656 // as long as child window we are in is not top level window itself
657 // (because the TLW size is never resized automatically)
658 // so let's invalidate it as well to be safe:
659 if (m_parent
&& !IsTopLevel())
660 m_parent
->InvalidateBestSize();
663 // return the size best suited for the current window
664 wxSize
wxWindowBase::DoGetBestSize() const
670 best
= m_windowSizer
->GetMinSize();
672 #if wxUSE_CONSTRAINTS
673 else if ( m_constraints
)
675 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
677 // our minimal acceptable size is such that all our windows fit inside
681 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
683 node
= node
->GetNext() )
685 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
688 // it's not normal that we have an unconstrained child, but
689 // what can we do about it?
693 int x
= c
->right
.GetValue(),
694 y
= c
->bottom
.GetValue();
702 // TODO: we must calculate the overlaps somehow, otherwise we
703 // will never return a size bigger than the current one :-(
706 best
= wxSize(maxX
, maxY
);
708 #endif // wxUSE_CONSTRAINTS
709 else if ( !GetChildren().empty()
710 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
711 && wxHasRealChildren(this)
715 // our minimal acceptable size is such that all our visible child
716 // windows fit inside
720 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
722 node
= node
->GetNext() )
724 wxWindow
*win
= node
->GetData();
725 if ( win
->IsTopLevel()
728 || wxDynamicCast(win
, wxStatusBar
)
729 #endif // wxUSE_STATUSBAR
732 // dialogs and frames lie in different top level windows -
733 // don't deal with them here; as for the status bars, they
734 // don't lie in the client area at all
739 win
->GetPosition(&wx
, &wy
);
741 // if the window hadn't been positioned yet, assume that it is in
743 if ( wx
== wxDefaultCoord
)
745 if ( wy
== wxDefaultCoord
)
748 win
->GetSize(&ww
, &wh
);
749 if ( wx
+ ww
> maxX
)
751 if ( wy
+ wh
> maxY
)
755 best
= wxSize(maxX
, maxY
);
757 else // ! has children
759 wxSize size
= GetMinSize();
760 if ( !size
.IsFullySpecified() )
762 // if the window doesn't define its best size we assume that it can
763 // be arbitrarily small -- usually this is not the case, of course,
764 // but we have no way to know what the limit is, it should really
765 // override DoGetBestClientSize() itself to tell us
766 size
.SetDefaults(wxSize(1, 1));
769 // return as-is, unadjusted by the client size difference.
773 // Add any difference between size and client size
774 wxSize diff
= GetSize() - GetClientSize();
775 best
.x
+= wxMax(0, diff
.x
);
776 best
.y
+= wxMax(0, diff
.y
);
781 // helper of GetWindowBorderSize(): as many ports don't implement support for
782 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
783 // fallbacks in this case
784 static int wxGetMetricOrDefault(wxSystemMetric what
, const wxWindowBase
* win
)
786 int rc
= wxSystemSettings::GetMetric(
787 what
, static_cast<wxWindow
*>(const_cast<wxWindowBase
*>(win
)));
794 // 2D border is by default 1 pixel wide
800 // 3D borders are by default 2 pixels
805 wxFAIL_MSG( wxT("unexpected wxGetMetricOrDefault() argument") );
813 wxSize
wxWindowBase::GetWindowBorderSize() const
817 switch ( GetBorder() )
820 // nothing to do, size is already (0, 0)
823 case wxBORDER_SIMPLE
:
824 case wxBORDER_STATIC
:
825 size
.x
= wxGetMetricOrDefault(wxSYS_BORDER_X
, this);
826 size
.y
= wxGetMetricOrDefault(wxSYS_BORDER_Y
, this);
829 case wxBORDER_SUNKEN
:
830 case wxBORDER_RAISED
:
831 size
.x
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X
, this),
832 wxGetMetricOrDefault(wxSYS_BORDER_X
, this));
833 size
.y
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y
, this),
834 wxGetMetricOrDefault(wxSYS_BORDER_Y
, this));
837 case wxBORDER_DOUBLE
:
838 size
.x
= wxGetMetricOrDefault(wxSYS_EDGE_X
, this) +
839 wxGetMetricOrDefault(wxSYS_BORDER_X
, this);
840 size
.y
= wxGetMetricOrDefault(wxSYS_EDGE_Y
, this) +
841 wxGetMetricOrDefault(wxSYS_BORDER_Y
, this);
845 wxFAIL_MSG(wxT("Unknown border style."));
849 // we have borders on both sides
853 wxSize
wxWindowBase::GetEffectiveMinSize() const
855 // merge the best size with the min size, giving priority to the min size
856 wxSize min
= GetMinSize();
858 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
860 wxSize best
= GetBestSize();
861 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
862 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
868 wxSize
wxWindowBase::DoGetBorderSize() const
870 // there is one case in which we can implement it for all ports easily
871 if ( GetBorder() == wxBORDER_NONE
)
874 // otherwise use the difference between the real size and the client size
875 // as a fallback: notice that this is incorrect in general as client size
876 // also doesn't take the scrollbars into account
877 return GetSize() - GetClientSize();
880 wxSize
wxWindowBase::GetBestSize() const
882 if ( !m_windowSizer
&& m_bestSizeCache
.IsFullySpecified() )
883 return m_bestSizeCache
;
885 // call DoGetBestClientSize() first, if a derived class overrides it wants
887 wxSize size
= DoGetBestClientSize();
888 if ( size
!= wxDefaultSize
)
890 size
+= DoGetBorderSize();
896 return DoGetBestSize();
899 void wxWindowBase::SetMinSize(const wxSize
& minSize
)
901 m_minWidth
= minSize
.x
;
902 m_minHeight
= minSize
.y
;
905 void wxWindowBase::SetMaxSize(const wxSize
& maxSize
)
907 m_maxWidth
= maxSize
.x
;
908 m_maxHeight
= maxSize
.y
;
911 void wxWindowBase::SetInitialSize(const wxSize
& size
)
913 // Set the min size to the size passed in. This will usually either be
914 // wxDefaultSize or the size passed to this window's ctor/Create function.
917 // Merge the size with the best size if needed
918 wxSize best
= GetEffectiveMinSize();
920 // If the current size doesn't match then change it
921 if (GetSize() != best
)
926 // by default the origin is not shifted
927 wxPoint
wxWindowBase::GetClientAreaOrigin() const
932 wxSize
wxWindowBase::ClientToWindowSize(const wxSize
& size
) const
934 const wxSize
diff(GetSize() - GetClientSize());
936 return wxSize(size
.x
== -1 ? -1 : size
.x
+ diff
.x
,
937 size
.y
== -1 ? -1 : size
.y
+ diff
.y
);
940 wxSize
wxWindowBase::WindowToClientSize(const wxSize
& size
) const
942 const wxSize
diff(GetSize() - GetClientSize());
944 return wxSize(size
.x
== -1 ? -1 : size
.x
- diff
.x
,
945 size
.y
== -1 ? -1 : size
.y
- diff
.y
);
948 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
950 if ( m_windowVariant
!= variant
)
952 m_windowVariant
= variant
;
954 DoSetWindowVariant(variant
);
958 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
960 // adjust the font height to correspond to our new variant (notice that
961 // we're only called if something really changed)
962 wxFont font
= GetFont();
963 int size
= font
.GetPointSize();
966 case wxWINDOW_VARIANT_NORMAL
:
969 case wxWINDOW_VARIANT_SMALL
:
970 size
= wxRound(size
* 3.0 / 4.0);
973 case wxWINDOW_VARIANT_MINI
:
974 size
= wxRound(size
* 2.0 / 3.0);
977 case wxWINDOW_VARIANT_LARGE
:
978 size
= wxRound(size
* 5.0 / 4.0);
982 wxFAIL_MSG(wxT("unexpected window variant"));
986 font
.SetPointSize(size
);
990 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
992 int WXUNUSED(incW
), int WXUNUSED(incH
) )
994 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
995 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
996 wxT("min width/height must be less than max width/height!") );
1005 #if WXWIN_COMPATIBILITY_2_8
1006 void wxWindowBase::SetVirtualSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
),
1007 int WXUNUSED(maxW
), int WXUNUSED(maxH
))
1011 void wxWindowBase::SetVirtualSizeHints(const wxSize
& WXUNUSED(minsize
),
1012 const wxSize
& WXUNUSED(maxsize
))
1015 #endif // WXWIN_COMPATIBILITY_2_8
1017 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
1019 m_virtualSize
= wxSize(x
, y
);
1022 wxSize
wxWindowBase::DoGetVirtualSize() const
1024 // we should use the entire client area so if it is greater than our
1025 // virtual size, expand it to fit (otherwise if the window is big enough we
1026 // wouldn't be using parts of it)
1027 wxSize size
= GetClientSize();
1028 if ( m_virtualSize
.x
> size
.x
)
1029 size
.x
= m_virtualSize
.x
;
1031 if ( m_virtualSize
.y
>= size
.y
)
1032 size
.y
= m_virtualSize
.y
;
1037 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
1039 // screen position is the same as (0, 0) in client coords for non TLWs (and
1040 // TLWs override this method)
1046 ClientToScreen(x
, y
);
1049 void wxWindowBase::SendSizeEvent(int flags
)
1051 wxSizeEvent
event(GetSize(), GetId());
1052 event
.SetEventObject(this);
1053 if ( flags
& wxSEND_EVENT_POST
)
1054 wxPostEvent(this, event
);
1056 HandleWindowEvent(event
);
1059 void wxWindowBase::SendSizeEventToParent(int flags
)
1061 wxWindow
* const parent
= GetParent();
1062 if ( parent
&& !parent
->IsBeingDeleted() )
1063 parent
->SendSizeEvent(flags
);
1066 bool wxWindowBase::HasScrollbar(int orient
) const
1068 // if scrolling in the given direction is disabled, we can't have the
1069 // corresponding scrollbar no matter what
1070 if ( !CanScroll(orient
) )
1073 const wxSize sizeVirt
= GetVirtualSize();
1074 const wxSize sizeClient
= GetClientSize();
1076 return orient
== wxHORIZONTAL
? sizeVirt
.x
> sizeClient
.x
1077 : sizeVirt
.y
> sizeClient
.y
;
1080 // ----------------------------------------------------------------------------
1081 // show/hide/enable/disable the window
1082 // ----------------------------------------------------------------------------
1084 bool wxWindowBase::Show(bool show
)
1086 if ( show
!= m_isShown
)
1098 bool wxWindowBase::IsEnabled() const
1100 return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
1103 void wxWindowBase::NotifyWindowOnEnableChange(bool enabled
)
1105 // Under some platforms there is no need to update the window state
1106 // explicitly, it will become disabled when its parent is. On other ones we
1107 // do need to disable all windows recursively though.
1108 #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
1110 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
1114 // Disabling a top level window is typically done when showing a modal
1115 // dialog and we don't need to disable its children in this case, they will
1116 // be logically disabled anyhow (i.e. their IsEnabled() will return false)
1117 // and the TLW won't accept any input for them. Moreover, explicitly
1118 // disabling them would look ugly as the entire TLW would be greyed out
1119 // whenever a modal dialog is shown and no native applications under any
1120 // platform behave like this.
1121 if ( IsTopLevel() && !enabled
)
1124 // When disabling (or enabling back) a non-TLW window we need to
1125 // recursively propagate the change of the state to its children, otherwise
1126 // they would still show as enabled even though they wouldn't actually
1127 // accept any input (at least under MSW where children don't accept input
1128 // if any of the windows in their parent chain is enabled).
1130 // Notice that we must do this even for wxHAS_NATIVE_ENABLED_MANAGEMENT
1131 // platforms as we still need to call the children OnEnabled() recursively.
1132 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1134 node
= node
->GetNext() )
1136 wxWindowBase
* const child
= node
->GetData();
1137 if ( !child
->IsTopLevel() && child
->IsThisEnabled() )
1138 child
->NotifyWindowOnEnableChange(enabled
);
1142 bool wxWindowBase::Enable(bool enable
)
1144 if ( enable
== IsThisEnabled() )
1147 m_isEnabled
= enable
;
1149 // If we call DoEnable() from NotifyWindowOnEnableChange(), we don't need
1150 // to do it from here.
1151 #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
1153 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
1155 NotifyWindowOnEnableChange(enable
);
1160 bool wxWindowBase::IsShownOnScreen() const
1162 // A window is shown on screen if it itself is shown and so are all its
1163 // parents. But if a window is toplevel one, then its always visible on
1164 // screen if IsShown() returns true, even if it has a hidden parent.
1166 (IsTopLevel() || GetParent() == NULL
|| GetParent()->IsShownOnScreen());
1169 // ----------------------------------------------------------------------------
1171 // ----------------------------------------------------------------------------
1173 bool wxWindowBase::IsTopLevel() const
1178 // ----------------------------------------------------------------------------
1180 // ----------------------------------------------------------------------------
1182 void wxWindowBase::Freeze()
1184 if ( !m_freezeCount
++ )
1186 // physically freeze this window:
1189 // and recursively freeze all children:
1190 for ( wxWindowList::iterator i
= GetChildren().begin();
1191 i
!= GetChildren().end(); ++i
)
1193 wxWindow
*child
= *i
;
1194 if ( child
->IsTopLevel() )
1202 void wxWindowBase::Thaw()
1204 wxASSERT_MSG( m_freezeCount
, "Thaw() without matching Freeze()" );
1206 if ( !--m_freezeCount
)
1208 // recursively thaw all children:
1209 for ( wxWindowList::iterator i
= GetChildren().begin();
1210 i
!= GetChildren().end(); ++i
)
1212 wxWindow
*child
= *i
;
1213 if ( child
->IsTopLevel() )
1219 // physically thaw this window:
1224 // ----------------------------------------------------------------------------
1225 // reparenting the window
1226 // ----------------------------------------------------------------------------
1228 void wxWindowBase::AddChild(wxWindowBase
*child
)
1230 wxCHECK_RET( child
, wxT("can't add a NULL child") );
1232 // this should never happen and it will lead to a crash later if it does
1233 // because RemoveChild() will remove only one node from the children list
1234 // and the other(s) one(s) will be left with dangling pointers in them
1235 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), wxT("AddChild() called twice") );
1237 GetChildren().Append((wxWindow
*)child
);
1238 child
->SetParent(this);
1240 // adding a child while frozen will assert when thawed, so freeze it as if
1241 // it had been already present when we were frozen
1242 if ( IsFrozen() && !child
->IsTopLevel() )
1246 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
1248 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
1250 // removing a child while frozen may result in permanently frozen window
1251 // if used e.g. from Reparent(), so thaw it
1253 // NB: IsTopLevel() doesn't return true any more when a TLW child is being
1254 // removed from its ~wxWindowBase, so check for IsBeingDeleted() too
1255 if ( IsFrozen() && !child
->IsBeingDeleted() && !child
->IsTopLevel() )
1258 GetChildren().DeleteObject((wxWindow
*)child
);
1259 child
->SetParent(NULL
);
1262 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
1264 wxWindow
*oldParent
= GetParent();
1265 if ( newParent
== oldParent
)
1271 const bool oldEnabledState
= IsEnabled();
1273 // unlink this window from the existing parent.
1276 oldParent
->RemoveChild(this);
1280 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
1283 // add it to the new one
1286 newParent
->AddChild(this);
1290 wxTopLevelWindows
.Append((wxWindow
*)this);
1293 // We need to notify window (and its subwindows) if by changing the parent
1294 // we also change our enabled/disabled status.
1295 const bool newEnabledState
= IsEnabled();
1296 if ( newEnabledState
!= oldEnabledState
)
1298 NotifyWindowOnEnableChange(newEnabledState
);
1304 // ----------------------------------------------------------------------------
1305 // event handler stuff
1306 // ----------------------------------------------------------------------------
1308 void wxWindowBase::SetEventHandler(wxEvtHandler
*handler
)
1310 wxCHECK_RET(handler
!= NULL
, "SetEventHandler(NULL) called");
1312 m_eventHandler
= handler
;
1315 void wxWindowBase::SetNextHandler(wxEvtHandler
*WXUNUSED(handler
))
1317 // disable wxEvtHandler chain mechanism for wxWindows:
1318 // wxWindow uses its own stack mechanism which doesn't mix well with wxEvtHandler's one
1320 wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
1322 void wxWindowBase::SetPreviousHandler(wxEvtHandler
*WXUNUSED(handler
))
1324 // we can't simply wxFAIL here as in SetNextHandler: in fact the last
1325 // handler of our stack when is destroyed will be Unlink()ed and thus
1326 // will call this function to update the pointer of this window...
1328 //wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
1331 void wxWindowBase::PushEventHandler(wxEvtHandler
*handlerToPush
)
1333 wxCHECK_RET( handlerToPush
!= NULL
, "PushEventHandler(NULL) called" );
1335 // the new handler is going to be part of the wxWindow stack of event handlers:
1336 // it can't be part also of an event handler double-linked chain:
1337 wxASSERT_MSG(handlerToPush
->IsUnlinked(),
1338 "The handler being pushed in the wxWindow stack shouldn't be part of "
1339 "a wxEvtHandler chain; call Unlink() on it first");
1341 wxEvtHandler
*handlerOld
= GetEventHandler();
1342 wxCHECK_RET( handlerOld
, "an old event handler is NULL?" );
1344 // now use wxEvtHandler double-linked list to implement a stack:
1345 handlerToPush
->SetNextHandler(handlerOld
);
1347 if (handlerOld
!= this)
1348 handlerOld
->SetPreviousHandler(handlerToPush
);
1350 SetEventHandler(handlerToPush
);
1353 // final checks of the operations done above:
1354 wxASSERT_MSG( handlerToPush
->GetPreviousHandler() == NULL
,
1355 "the first handler of the wxWindow stack should "
1356 "have no previous handlers set" );
1357 wxASSERT_MSG( handlerToPush
->GetNextHandler() != NULL
,
1358 "the first handler of the wxWindow stack should "
1359 "have non-NULL next handler" );
1361 wxEvtHandler
* pLast
= handlerToPush
;
1362 while ( pLast
&& pLast
!= this )
1363 pLast
= pLast
->GetNextHandler();
1364 wxASSERT_MSG( pLast
->GetNextHandler() == NULL
,
1365 "the last handler of the wxWindow stack should "
1366 "have this window as next handler" );
1367 #endif // wxDEBUG_LEVEL
1370 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
1372 // we need to pop the wxWindow stack, i.e. we need to remove the first handler
1374 wxEvtHandler
*firstHandler
= GetEventHandler();
1375 wxCHECK_MSG( firstHandler
!= NULL
, NULL
, "wxWindow cannot have a NULL event handler" );
1376 wxCHECK_MSG( firstHandler
!= this, NULL
, "cannot pop the wxWindow itself" );
1377 wxCHECK_MSG( firstHandler
->GetPreviousHandler() == NULL
, NULL
,
1378 "the first handler of the wxWindow stack should have no previous handlers set" );
1380 wxEvtHandler
*secondHandler
= firstHandler
->GetNextHandler();
1381 wxCHECK_MSG( secondHandler
!= NULL
, NULL
,
1382 "the first handler of the wxWindow stack should have non-NULL next handler" );
1384 firstHandler
->SetNextHandler(NULL
);
1385 secondHandler
->SetPreviousHandler(NULL
);
1387 // now firstHandler is completely unlinked; set secondHandler as the new window event handler
1388 SetEventHandler(secondHandler
);
1390 if ( deleteHandler
)
1392 wxDELETE(firstHandler
);
1395 return firstHandler
;
1398 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handlerToRemove
)
1400 wxCHECK_MSG( handlerToRemove
!= NULL
, false, "RemoveEventHandler(NULL) called" );
1401 wxCHECK_MSG( handlerToRemove
!= this, false, "Cannot remove the window itself" );
1403 if (handlerToRemove
== GetEventHandler())
1405 // removing the first event handler is equivalent to "popping" the stack
1406 PopEventHandler(false);
1410 // NOTE: the wxWindow event handler list is always terminated with "this" handler
1411 wxEvtHandler
*handlerCur
= GetEventHandler()->GetNextHandler();
1412 while ( handlerCur
!= this && handlerCur
)
1414 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
1416 if ( handlerCur
== handlerToRemove
)
1418 handlerCur
->Unlink();
1420 wxASSERT_MSG( handlerCur
!= GetEventHandler(),
1421 "the case Remove == Pop should was already handled" );
1425 handlerCur
= handlerNext
;
1428 wxFAIL_MSG( wxT("where has the event handler gone?") );
1433 bool wxWindowBase::HandleWindowEvent(wxEvent
& event
) const
1435 // SafelyProcessEvent() will handle exceptions nicely
1436 return GetEventHandler()->SafelyProcessEvent(event
);
1439 // ----------------------------------------------------------------------------
1440 // colours, fonts &c
1441 // ----------------------------------------------------------------------------
1443 void wxWindowBase::InheritAttributes()
1445 const wxWindowBase
* const parent
= GetParent();
1449 // we only inherit attributes which had been explicitly set for the parent
1450 // which ensures that this only happens if the user really wants it and
1451 // not by default which wouldn't make any sense in modern GUIs where the
1452 // controls don't all use the same fonts (nor colours)
1453 if ( parent
->m_inheritFont
&& !m_hasFont
)
1454 SetFont(parent
->GetFont());
1456 // in addition, there is a possibility to explicitly forbid inheriting
1457 // colours at each class level by overriding ShouldInheritColours()
1458 if ( ShouldInheritColours() )
1460 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1461 SetForegroundColour(parent
->GetForegroundColour());
1463 // inheriting (solid) background colour is wrong as it totally breaks
1464 // any kind of themed backgrounds
1466 // instead, the controls should use the same background as their parent
1467 // (ideally by not drawing it at all)
1469 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1470 SetBackgroundColour(parent
->GetBackgroundColour());
1475 /* static */ wxVisualAttributes
1476 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1478 // it is important to return valid values for all attributes from here,
1479 // GetXXX() below rely on this
1480 wxVisualAttributes attrs
;
1481 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1482 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1484 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1485 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1486 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1487 // colour on other platforms.
1489 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1490 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1492 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1497 wxColour
wxWindowBase::GetBackgroundColour() const
1499 if ( !m_backgroundColour
.IsOk() )
1501 wxASSERT_MSG( !m_hasBgCol
, wxT("we have invalid explicit bg colour?") );
1503 // get our default background colour
1504 wxColour colBg
= GetDefaultAttributes().colBg
;
1506 // we must return some valid colour to avoid redoing this every time
1507 // and also to avoid surprising the applications written for older
1508 // wxWidgets versions where GetBackgroundColour() always returned
1509 // something -- so give them something even if it doesn't make sense
1510 // for this window (e.g. it has a themed background)
1512 colBg
= GetClassDefaultAttributes().colBg
;
1517 return m_backgroundColour
;
1520 wxColour
wxWindowBase::GetForegroundColour() const
1522 // logic is the same as above
1523 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1525 wxColour colFg
= GetDefaultAttributes().colFg
;
1527 if ( !colFg
.IsOk() )
1528 colFg
= GetClassDefaultAttributes().colFg
;
1533 return m_foregroundColour
;
1536 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1538 if ( colour
== m_backgroundColour
)
1541 m_hasBgCol
= colour
.IsOk();
1543 m_inheritBgCol
= m_hasBgCol
;
1544 m_backgroundColour
= colour
;
1545 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1549 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1551 if (colour
== m_foregroundColour
)
1554 m_hasFgCol
= colour
.IsOk();
1555 m_inheritFgCol
= m_hasFgCol
;
1556 m_foregroundColour
= colour
;
1557 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1561 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1563 // setting an invalid cursor is ok, it means that we don't have any special
1565 if ( m_cursor
.IsSameAs(cursor
) )
1576 wxFont
wxWindowBase::GetFont() const
1578 // logic is the same as in GetBackgroundColour()
1579 if ( !m_font
.IsOk() )
1581 wxASSERT_MSG( !m_hasFont
, wxT("we have invalid explicit font?") );
1583 wxFont font
= GetDefaultAttributes().font
;
1585 font
= GetClassDefaultAttributes().font
;
1593 bool wxWindowBase::SetFont(const wxFont
& font
)
1595 if ( font
== m_font
)
1602 m_hasFont
= font
.IsOk();
1603 m_inheritFont
= m_hasFont
;
1605 InvalidateBestSize();
1612 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1614 m_hasCustomPalette
= true;
1617 // VZ: can anyone explain me what do we do here?
1618 wxWindowDC
d((wxWindow
*) this);
1622 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1624 wxWindow
*win
= (wxWindow
*)this;
1625 while ( win
&& !win
->HasCustomPalette() )
1627 win
= win
->GetParent();
1633 #endif // wxUSE_PALETTE
1636 void wxWindowBase::SetCaret(wxCaret
*caret
)
1647 wxASSERT_MSG( m_caret
->GetWindow() == this,
1648 wxT("caret should be created associated to this window") );
1651 #endif // wxUSE_CARET
1653 #if wxUSE_VALIDATORS
1654 // ----------------------------------------------------------------------------
1656 // ----------------------------------------------------------------------------
1658 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1660 if ( m_windowValidator
)
1661 delete m_windowValidator
;
1663 m_windowValidator
= (wxValidator
*)validator
.Clone();
1665 if ( m_windowValidator
)
1666 m_windowValidator
->SetWindow(this);
1668 #endif // wxUSE_VALIDATORS
1670 // ----------------------------------------------------------------------------
1671 // update region stuff
1672 // ----------------------------------------------------------------------------
1674 wxRect
wxWindowBase::GetUpdateClientRect() const
1676 wxRegion rgnUpdate
= GetUpdateRegion();
1677 rgnUpdate
.Intersect(GetClientRect());
1678 wxRect rectUpdate
= rgnUpdate
.GetBox();
1679 wxPoint ptOrigin
= GetClientAreaOrigin();
1680 rectUpdate
.x
-= ptOrigin
.x
;
1681 rectUpdate
.y
-= ptOrigin
.y
;
1686 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1688 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1691 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1693 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1696 void wxWindowBase::ClearBackground()
1698 // wxGTK uses its own version, no need to add never used code
1700 wxClientDC
dc((wxWindow
*)this);
1701 wxBrush
brush(GetBackgroundColour(), wxBRUSHSTYLE_SOLID
);
1702 dc
.SetBackground(brush
);
1707 // ----------------------------------------------------------------------------
1708 // find child window by id or name
1709 // ----------------------------------------------------------------------------
1711 wxWindow
*wxWindowBase::FindWindow(long id
) const
1713 if ( id
== m_windowId
)
1714 return (wxWindow
*)this;
1716 wxWindowBase
*res
= NULL
;
1717 wxWindowList::compatibility_iterator node
;
1718 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1720 wxWindowBase
*child
= node
->GetData();
1721 res
= child
->FindWindow( id
);
1724 return (wxWindow
*)res
;
1727 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1729 if ( name
== m_windowName
)
1730 return (wxWindow
*)this;
1732 wxWindowBase
*res
= NULL
;
1733 wxWindowList::compatibility_iterator node
;
1734 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1736 wxWindow
*child
= node
->GetData();
1737 res
= child
->FindWindow(name
);
1740 return (wxWindow
*)res
;
1744 // find any window by id or name or label: If parent is non-NULL, look through
1745 // children for a label or title matching the specified string. If NULL, look
1746 // through all top-level windows.
1748 // to avoid duplicating code we reuse the same helper function but with
1749 // different comparators
1751 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1752 const wxString
& label
, long id
);
1755 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1758 return win
->GetLabel() == label
;
1762 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1765 return win
->GetName() == label
;
1769 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1772 return win
->GetId() == id
;
1775 // recursive helper for the FindWindowByXXX() functions
1777 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1778 const wxString
& label
,
1780 wxFindWindowCmp cmp
)
1784 // see if this is the one we're looking for
1785 if ( (*cmp
)(parent
, label
, id
) )
1786 return (wxWindow
*)parent
;
1788 // It wasn't, so check all its children
1789 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1791 node
= node
->GetNext() )
1793 // recursively check each child
1794 wxWindow
*win
= (wxWindow
*)node
->GetData();
1795 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1805 // helper for FindWindowByXXX()
1807 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1808 const wxString
& label
,
1810 wxFindWindowCmp cmp
)
1814 // just check parent and all its children
1815 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1818 // start at very top of wx's windows
1819 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1821 node
= node
->GetNext() )
1823 // recursively check each window & its children
1824 wxWindow
*win
= node
->GetData();
1825 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1835 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1837 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1842 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1844 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1848 // fall back to the label
1849 win
= FindWindowByLabel(title
, parent
);
1857 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1859 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1862 // ----------------------------------------------------------------------------
1863 // dialog oriented functions
1864 // ----------------------------------------------------------------------------
1866 void wxWindowBase::MakeModal(bool modal
)
1868 // Disable all other windows
1871 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1874 wxWindow
*win
= node
->GetData();
1876 win
->Enable(!modal
);
1878 node
= node
->GetNext();
1883 bool wxWindowBase::Validate()
1885 #if wxUSE_VALIDATORS
1886 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1888 wxWindowList::compatibility_iterator node
;
1889 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1891 wxWindowBase
*child
= node
->GetData();
1892 wxValidator
*validator
= child
->GetValidator();
1893 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1898 if ( recurse
&& !child
->Validate() )
1903 #endif // wxUSE_VALIDATORS
1908 bool wxWindowBase::TransferDataToWindow()
1910 #if wxUSE_VALIDATORS
1911 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1913 wxWindowList::compatibility_iterator node
;
1914 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1916 wxWindowBase
*child
= node
->GetData();
1917 wxValidator
*validator
= child
->GetValidator();
1918 if ( validator
&& !validator
->TransferToWindow() )
1920 wxLogWarning(_("Could not transfer data to window"));
1922 wxLog::FlushActive();
1930 if ( !child
->TransferDataToWindow() )
1932 // warning already given
1937 #endif // wxUSE_VALIDATORS
1942 bool wxWindowBase::TransferDataFromWindow()
1944 #if wxUSE_VALIDATORS
1945 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1947 wxWindowList::compatibility_iterator node
;
1948 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1950 wxWindow
*child
= node
->GetData();
1951 wxValidator
*validator
= child
->GetValidator();
1952 if ( validator
&& !validator
->TransferFromWindow() )
1954 // nop warning here because the application is supposed to give
1955 // one itself - we don't know here what might have gone wrongly
1962 if ( !child
->TransferDataFromWindow() )
1964 // warning already given
1969 #endif // wxUSE_VALIDATORS
1974 void wxWindowBase::InitDialog()
1976 wxInitDialogEvent
event(GetId());
1977 event
.SetEventObject( this );
1978 GetEventHandler()->ProcessEvent(event
);
1981 // ----------------------------------------------------------------------------
1982 // context-sensitive help support
1983 // ----------------------------------------------------------------------------
1987 // associate this help text with this window
1988 void wxWindowBase::SetHelpText(const wxString
& text
)
1990 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1993 helpProvider
->AddHelp(this, text
);
1997 #if WXWIN_COMPATIBILITY_2_8
1998 // associate this help text with all windows with the same id as this
2000 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
2002 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
2005 helpProvider
->AddHelp(GetId(), text
);
2008 #endif // WXWIN_COMPATIBILITY_2_8
2010 // get the help string associated with this window (may be empty)
2011 // default implementation forwards calls to the help provider
2013 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
2014 wxHelpEvent::Origin
WXUNUSED(origin
)) const
2017 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
2020 text
= helpProvider
->GetHelp(this);
2026 // show help for this window
2027 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
2029 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
2032 wxPoint pos
= event
.GetPosition();
2033 const wxHelpEvent::Origin origin
= event
.GetOrigin();
2034 if ( origin
== wxHelpEvent::Origin_Keyboard
)
2036 // if the help event was generated from keyboard it shouldn't
2037 // appear at the mouse position (which is still the only position
2038 // associated with help event) if the mouse is far away, although
2039 // we still do use the mouse position if it's over the window
2040 // because we suppose the user looks approximately at the mouse
2041 // already and so it would be more convenient than showing tooltip
2042 // at some arbitrary position which can be quite far from it
2043 const wxRect rectClient
= GetClientRect();
2044 if ( !rectClient
.Contains(ScreenToClient(pos
)) )
2046 // position help slightly under and to the right of this window
2047 pos
= ClientToScreen(wxPoint(
2049 rectClient
.height
+ GetCharHeight()
2054 if ( helpProvider
->ShowHelpAtPoint(this, pos
, origin
) )
2056 // skip the event.Skip() below
2064 #endif // wxUSE_HELP
2066 // ----------------------------------------------------------------------------
2068 // ----------------------------------------------------------------------------
2072 wxString
wxWindowBase::GetToolTipText() const
2074 return m_tooltip
? m_tooltip
->GetTip() : wxString();
2077 void wxWindowBase::SetToolTip( const wxString
&tip
)
2079 // don't create the new tooltip if we already have one
2082 m_tooltip
->SetTip( tip
);
2086 SetToolTip( new wxToolTip( tip
) );
2089 // setting empty tooltip text does not remove the tooltip any more - use
2090 // SetToolTip(NULL) for this
2093 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
2095 if ( m_tooltip
!= tooltip
)
2100 m_tooltip
= tooltip
;
2104 #endif // wxUSE_TOOLTIPS
2106 // ----------------------------------------------------------------------------
2107 // constraints and sizers
2108 // ----------------------------------------------------------------------------
2110 #if wxUSE_CONSTRAINTS
2112 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
2114 if ( m_constraints
)
2116 UnsetConstraints(m_constraints
);
2117 delete m_constraints
;
2119 m_constraints
= constraints
;
2120 if ( m_constraints
)
2122 // Make sure other windows know they're part of a 'meaningful relationship'
2123 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
2124 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
2125 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
2126 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
2127 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
2128 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
2129 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
2130 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
2131 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
2132 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
2133 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
2134 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
2135 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
2136 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
2137 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
2138 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
2142 // This removes any dangling pointers to this window in other windows'
2143 // constraintsInvolvedIn lists.
2144 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
2148 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
2149 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
2150 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
2151 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
2152 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
2153 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
2154 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
2155 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
2156 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
2157 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
2158 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
2159 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
2160 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
2161 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
2162 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
2163 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
2167 // Back-pointer to other windows we're involved with, so if we delete this
2168 // window, we must delete any constraints we're involved with.
2169 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
2171 if ( !m_constraintsInvolvedIn
)
2172 m_constraintsInvolvedIn
= new wxWindowList
;
2173 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
2174 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
2177 // REMOVE back-pointer to other windows we're involved with.
2178 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
2180 if ( m_constraintsInvolvedIn
)
2181 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
2184 // Reset any constraints that mention this window
2185 void wxWindowBase::DeleteRelatedConstraints()
2187 if ( m_constraintsInvolvedIn
)
2189 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
2192 wxWindow
*win
= node
->GetData();
2193 wxLayoutConstraints
*constr
= win
->GetConstraints();
2195 // Reset any constraints involving this window
2198 constr
->left
.ResetIfWin(this);
2199 constr
->top
.ResetIfWin(this);
2200 constr
->right
.ResetIfWin(this);
2201 constr
->bottom
.ResetIfWin(this);
2202 constr
->width
.ResetIfWin(this);
2203 constr
->height
.ResetIfWin(this);
2204 constr
->centreX
.ResetIfWin(this);
2205 constr
->centreY
.ResetIfWin(this);
2208 wxWindowList::compatibility_iterator next
= node
->GetNext();
2209 m_constraintsInvolvedIn
->Erase(node
);
2213 wxDELETE(m_constraintsInvolvedIn
);
2217 #endif // wxUSE_CONSTRAINTS
2219 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
2221 if ( sizer
== m_windowSizer
)
2224 if ( m_windowSizer
)
2226 m_windowSizer
->SetContainingWindow(NULL
);
2229 delete m_windowSizer
;
2232 m_windowSizer
= sizer
;
2233 if ( m_windowSizer
)
2235 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
2238 SetAutoLayout(m_windowSizer
!= NULL
);
2241 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
2243 SetSizer( sizer
, deleteOld
);
2244 sizer
->SetSizeHints( (wxWindow
*) this );
2248 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
2250 // adding a window to a sizer twice is going to result in fatal and
2251 // hard to debug problems later because when deleting the second
2252 // associated wxSizerItem we're going to dereference a dangling
2253 // pointer; so try to detect this as early as possible
2254 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
2255 wxT("Adding a window to the same sizer twice?") );
2257 m_containingSizer
= sizer
;
2260 #if wxUSE_CONSTRAINTS
2262 void wxWindowBase::SatisfyConstraints()
2264 wxLayoutConstraints
*constr
= GetConstraints();
2265 bool wasOk
= constr
&& constr
->AreSatisfied();
2267 ResetConstraints(); // Mark all constraints as unevaluated
2271 // if we're a top level panel (i.e. our parent is frame/dialog), our
2272 // own constraints will never be satisfied any more unless we do it
2276 while ( noChanges
> 0 )
2278 LayoutPhase1(&noChanges
);
2282 LayoutPhase2(&noChanges
);
2285 #endif // wxUSE_CONSTRAINTS
2287 bool wxWindowBase::Layout()
2289 // If there is a sizer, use it instead of the constraints
2293 GetVirtualSize(&w
, &h
);
2294 GetSizer()->SetDimension( 0, 0, w
, h
);
2296 #if wxUSE_CONSTRAINTS
2299 SatisfyConstraints(); // Find the right constraints values
2300 SetConstraintSizes(); // Recursively set the real window sizes
2307 void wxWindowBase::InternalOnSize(wxSizeEvent
& event
)
2309 if ( GetAutoLayout() )
2315 #if wxUSE_CONSTRAINTS
2317 // first phase of the constraints evaluation: set our own constraints
2318 bool wxWindowBase::LayoutPhase1(int *noChanges
)
2320 wxLayoutConstraints
*constr
= GetConstraints();
2322 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
2325 // second phase: set the constraints for our children
2326 bool wxWindowBase::LayoutPhase2(int *noChanges
)
2333 // Layout grand children
2339 // Do a phase of evaluating child constraints
2340 bool wxWindowBase::DoPhase(int phase
)
2342 // the list containing the children for which the constraints are already
2344 wxWindowList succeeded
;
2346 // the max number of iterations we loop before concluding that we can't set
2348 static const int maxIterations
= 500;
2350 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
2354 // loop over all children setting their constraints
2355 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2357 node
= node
->GetNext() )
2359 wxWindow
*child
= node
->GetData();
2360 if ( child
->IsTopLevel() )
2362 // top level children are not inside our client area
2366 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
2368 // this one is either already ok or nothing we can do about it
2372 int tempNoChanges
= 0;
2373 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
2374 : child
->LayoutPhase2(&tempNoChanges
);
2375 noChanges
+= tempNoChanges
;
2379 succeeded
.Append(child
);
2385 // constraints are set
2393 void wxWindowBase::ResetConstraints()
2395 wxLayoutConstraints
*constr
= GetConstraints();
2398 constr
->left
.SetDone(false);
2399 constr
->top
.SetDone(false);
2400 constr
->right
.SetDone(false);
2401 constr
->bottom
.SetDone(false);
2402 constr
->width
.SetDone(false);
2403 constr
->height
.SetDone(false);
2404 constr
->centreX
.SetDone(false);
2405 constr
->centreY
.SetDone(false);
2408 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2411 wxWindow
*win
= node
->GetData();
2412 if ( !win
->IsTopLevel() )
2413 win
->ResetConstraints();
2414 node
= node
->GetNext();
2418 // Need to distinguish between setting the 'fake' size for windows and sizers,
2419 // and setting the real values.
2420 void wxWindowBase::SetConstraintSizes(bool recurse
)
2422 wxLayoutConstraints
*constr
= GetConstraints();
2423 if ( constr
&& constr
->AreSatisfied() )
2425 int x
= constr
->left
.GetValue();
2426 int y
= constr
->top
.GetValue();
2427 int w
= constr
->width
.GetValue();
2428 int h
= constr
->height
.GetValue();
2430 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
2431 (constr
->height
.GetRelationship() != wxAsIs
) )
2433 // We really shouldn't set negative sizes for the windows so make
2434 // them at least of 1*1 size
2435 SetSize(x
, y
, w
> 0 ? w
: 1, h
> 0 ? h
: 1);
2439 // If we don't want to resize this window, just move it...
2445 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
2446 GetClassInfo()->GetClassName(),
2452 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2455 wxWindow
*win
= node
->GetData();
2456 if ( !win
->IsTopLevel() && win
->GetConstraints() )
2457 win
->SetConstraintSizes();
2458 node
= node
->GetNext();
2463 // Only set the size/position of the constraint (if any)
2464 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
2466 wxLayoutConstraints
*constr
= GetConstraints();
2469 if ( x
!= wxDefaultCoord
)
2471 constr
->left
.SetValue(x
);
2472 constr
->left
.SetDone(true);
2474 if ( y
!= wxDefaultCoord
)
2476 constr
->top
.SetValue(y
);
2477 constr
->top
.SetDone(true);
2479 if ( w
!= wxDefaultCoord
)
2481 constr
->width
.SetValue(w
);
2482 constr
->width
.SetDone(true);
2484 if ( h
!= wxDefaultCoord
)
2486 constr
->height
.SetValue(h
);
2487 constr
->height
.SetDone(true);
2492 void wxWindowBase::MoveConstraint(int x
, int y
)
2494 wxLayoutConstraints
*constr
= GetConstraints();
2497 if ( x
!= wxDefaultCoord
)
2499 constr
->left
.SetValue(x
);
2500 constr
->left
.SetDone(true);
2502 if ( y
!= wxDefaultCoord
)
2504 constr
->top
.SetValue(y
);
2505 constr
->top
.SetDone(true);
2510 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2512 wxLayoutConstraints
*constr
= GetConstraints();
2515 *w
= constr
->width
.GetValue();
2516 *h
= constr
->height
.GetValue();
2522 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2524 wxLayoutConstraints
*constr
= GetConstraints();
2527 *w
= constr
->width
.GetValue();
2528 *h
= constr
->height
.GetValue();
2531 GetClientSize(w
, h
);
2534 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2536 wxLayoutConstraints
*constr
= GetConstraints();
2539 *x
= constr
->left
.GetValue();
2540 *y
= constr
->top
.GetValue();
2546 #endif // wxUSE_CONSTRAINTS
2548 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2550 // don't do it for the dialogs/frames - they float independently of their
2552 if ( !IsTopLevel() )
2554 wxWindow
*parent
= GetParent();
2555 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2557 wxPoint
pt(parent
->GetClientAreaOrigin());
2564 // ----------------------------------------------------------------------------
2565 // Update UI processing
2566 // ----------------------------------------------------------------------------
2568 void wxWindowBase::UpdateWindowUI(long flags
)
2570 wxUpdateUIEvent
event(GetId());
2571 event
.SetEventObject(this);
2573 if ( GetEventHandler()->ProcessEvent(event
) )
2575 DoUpdateWindowUI(event
);
2578 if (flags
& wxUPDATE_UI_RECURSE
)
2580 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2583 wxWindow
* child
= (wxWindow
*) node
->GetData();
2584 child
->UpdateWindowUI(flags
);
2585 node
= node
->GetNext();
2590 // do the window-specific processing after processing the update event
2591 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2593 if ( event
.GetSetEnabled() )
2594 Enable(event
.GetEnabled());
2596 if ( event
.GetSetShown() )
2597 Show(event
.GetShown());
2600 // ----------------------------------------------------------------------------
2601 // dialog units translations
2602 // ----------------------------------------------------------------------------
2604 // Windows' computes dialog units using average character width over upper-
2605 // and lower-case ASCII alphabet and not using the average character width
2606 // metadata stored in the font; see
2607 // http://support.microsoft.com/default.aspx/kb/145994 for detailed discussion.
2608 // It's important that we perform the conversion in identical way, because
2609 // dialog units natively exist only on Windows and Windows HIG is expressed
2611 wxSize
wxWindowBase::GetDlgUnitBase() const
2613 const wxWindowBase
* const parent
= wxGetTopLevelParent((wxWindow
*)this);
2615 if ( !parent
->m_font
.IsOk() )
2617 // Default GUI font is used. This is the most common case, so
2618 // cache the results.
2619 static wxSize s_defFontSize
;
2620 if ( s_defFontSize
.x
== 0 )
2621 s_defFontSize
= wxPrivate::GetAverageASCIILetterSize(*parent
);
2622 return s_defFontSize
;
2626 // Custom font, we always need to compute the result
2627 return wxPrivate::GetAverageASCIILetterSize(*parent
);
2631 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
) const
2633 const wxSize base
= GetDlgUnitBase();
2635 // NB: wxMulDivInt32() is used, because it correctly rounds the result
2637 wxPoint pt2
= wxDefaultPosition
;
2638 if (pt
.x
!= wxDefaultCoord
)
2639 pt2
.x
= wxMulDivInt32(pt
.x
, 4, base
.x
);
2640 if (pt
.y
!= wxDefaultCoord
)
2641 pt2
.y
= wxMulDivInt32(pt
.y
, 8, base
.y
);
2646 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
) const
2648 const wxSize base
= GetDlgUnitBase();
2650 wxPoint pt2
= wxDefaultPosition
;
2651 if (pt
.x
!= wxDefaultCoord
)
2652 pt2
.x
= wxMulDivInt32(pt
.x
, base
.x
, 4);
2653 if (pt
.y
!= wxDefaultCoord
)
2654 pt2
.y
= wxMulDivInt32(pt
.y
, base
.y
, 8);
2659 // ----------------------------------------------------------------------------
2661 // ----------------------------------------------------------------------------
2663 // propagate the colour change event to the subwindows
2664 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
2666 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2669 // Only propagate to non-top-level windows
2670 wxWindow
*win
= node
->GetData();
2671 if ( !win
->IsTopLevel() )
2673 wxSysColourChangedEvent event2
;
2674 event2
.SetEventObject(win
);
2675 win
->GetEventHandler()->ProcessEvent(event2
);
2678 node
= node
->GetNext();
2684 // the default action is to populate dialog with data when it's created,
2685 // and nudge the UI into displaying itself correctly in case
2686 // we've turned the wxUpdateUIEvents frequency down low.
2687 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2689 TransferDataToWindow();
2691 // Update the UI at this point
2692 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2695 // ----------------------------------------------------------------------------
2696 // menu-related functions
2697 // ----------------------------------------------------------------------------
2701 bool wxWindowBase::PopupMenu(wxMenu
*menu
, int x
, int y
)
2703 wxCHECK_MSG( menu
, false, "can't popup NULL menu" );
2705 wxMenuInvokingWindowSetter
2706 setInvokingWin(*menu
, static_cast<wxWindow
*>(this));
2708 wxCurrentPopupMenu
= menu
;
2709 const bool rc
= DoPopupMenu(menu
, x
, y
);
2710 wxCurrentPopupMenu
= NULL
;
2715 // this is used to pass the id of the selected item from the menu event handler
2716 // to the main function itself
2718 // it's ok to use a global here as there can be at most one popup menu shown at
2720 static int gs_popupMenuSelection
= wxID_NONE
;
2722 void wxWindowBase::InternalOnPopupMenu(wxCommandEvent
& event
)
2724 // store the id in a global variable where we'll retrieve it from later
2725 gs_popupMenuSelection
= event
.GetId();
2728 void wxWindowBase::InternalOnPopupMenuUpdate(wxUpdateUIEvent
& WXUNUSED(event
))
2730 // nothing to do but do not skip it
2734 wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu
& menu
, int x
, int y
)
2736 gs_popupMenuSelection
= wxID_NONE
;
2738 Connect(wxEVT_COMMAND_MENU_SELECTED
,
2739 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2743 // it is common to construct the menu passed to this function dynamically
2744 // using some fixed range of ids which could clash with the ids used
2745 // elsewhere in the program, which could result in some menu items being
2746 // unintentionally disabled or otherwise modified by update UI handlers
2747 // elsewhere in the program code and this is difficult to avoid in the
2748 // program itself, so instead we just temporarily suspend UI updating while
2749 // this menu is shown
2750 Connect(wxEVT_UPDATE_UI
,
2751 wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate
),
2755 PopupMenu(&menu
, x
, y
);
2757 Disconnect(wxEVT_UPDATE_UI
,
2758 wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate
),
2761 Disconnect(wxEVT_COMMAND_MENU_SELECTED
,
2762 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2766 return gs_popupMenuSelection
;
2769 #endif // wxUSE_MENUS
2771 // methods for drawing the sizers in a visible way: this is currently only
2772 // enabled for "full debug" builds with wxDEBUG_LEVEL==2 as it doesn't work
2773 // that well and also because we don't want to leave it enabled in default
2774 // builds used for production
2775 #if wxDEBUG_LEVEL > 1
2777 static void DrawSizers(wxWindowBase
*win
);
2779 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
, const wxPen
* pen
)
2781 wxClientDC
dc((wxWindow
*)win
);
2783 dc
.SetBrush(fill
? wxBrush(pen
->GetColour(), wxBRUSHSTYLE_CROSSDIAG_HATCH
) :
2784 *wxTRANSPARENT_BRUSH
);
2785 dc
.DrawRectangle(rect
.Deflate(1, 1));
2788 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2790 const wxSizerItemList
& items
= sizer
->GetChildren();
2791 for ( wxSizerItemList::const_iterator i
= items
.begin(),
2796 wxSizerItem
*item
= *i
;
2797 if ( item
->IsSizer() )
2799 DrawBorder(win
, item
->GetRect().Deflate(2), false, wxRED_PEN
);
2800 DrawSizer(win
, item
->GetSizer());
2802 else if ( item
->IsSpacer() )
2804 DrawBorder(win
, item
->GetRect().Deflate(2), true, wxBLUE_PEN
);
2806 else if ( item
->IsWindow() )
2808 DrawSizers(item
->GetWindow());
2811 wxFAIL_MSG("inconsistent wxSizerItem status!");
2815 static void DrawSizers(wxWindowBase
*win
)
2817 DrawBorder(win
, win
->GetClientSize(), false, wxGREEN_PEN
);
2819 wxSizer
*sizer
= win
->GetSizer();
2822 DrawSizer(win
, sizer
);
2824 else // no sizer, still recurse into the children
2826 const wxWindowList
& children
= win
->GetChildren();
2827 for ( wxWindowList::const_iterator i
= children
.begin(),
2828 end
= children
.end();
2835 // show all kind of sizes of this window; see the "window sizing" topic
2836 // overview for more info about the various differences:
2837 wxSize fullSz
= win
->GetSize();
2838 wxSize clientSz
= win
->GetClientSize();
2839 wxSize bestSz
= win
->GetBestSize();
2840 wxSize minSz
= win
->GetMinSize();
2841 wxSize maxSz
= win
->GetMaxSize();
2842 wxSize virtualSz
= win
->GetVirtualSize();
2844 wxMessageOutputDebug dbgout
;
2846 "%-10s => fullsz=%4d;%-4d clientsz=%4d;%-4d bestsz=%4d;%-4d minsz=%4d;%-4d maxsz=%4d;%-4d virtualsz=%4d;%-4d\n",
2849 clientSz
.x
, clientSz
.y
,
2853 virtualSz
.x
, virtualSz
.y
);
2857 #endif // wxDEBUG_LEVEL
2859 // process special middle clicks
2860 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2862 if ( event
.ControlDown() && event
.AltDown() )
2864 #if wxDEBUG_LEVEL > 1
2865 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2866 if ( event
.ShiftDown() )
2871 #endif // __WXDEBUG__
2874 // just Ctrl-Alt-middle click shows information about wx version
2875 ::wxInfoMessageBox((wxWindow
*)this);
2876 #endif // wxUSE_MSGDLG
2885 // ----------------------------------------------------------------------------
2887 // ----------------------------------------------------------------------------
2889 #if wxUSE_ACCESSIBILITY
2890 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2892 if (m_accessible
&& (accessible
!= m_accessible
))
2893 delete m_accessible
;
2894 m_accessible
= accessible
;
2896 m_accessible
->SetWindow((wxWindow
*) this);
2899 // Returns the accessible object, creating if necessary.
2900 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2903 m_accessible
= CreateAccessible();
2904 return m_accessible
;
2907 // Override to create a specific accessible object.
2908 wxAccessible
* wxWindowBase::CreateAccessible()
2910 return new wxWindowAccessible((wxWindow
*) this);
2915 // ----------------------------------------------------------------------------
2916 // list classes implementation
2917 // ----------------------------------------------------------------------------
2921 #include "wx/listimpl.cpp"
2922 WX_DEFINE_LIST(wxWindowList
)
2926 void wxWindowListNode::DeleteData()
2928 delete (wxWindow
*)GetData();
2931 #endif // wxUSE_STL/!wxUSE_STL
2933 // ----------------------------------------------------------------------------
2935 // ----------------------------------------------------------------------------
2937 wxBorder
wxWindowBase::GetBorder(long flags
) const
2939 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2940 if ( border
== wxBORDER_DEFAULT
)
2942 border
= GetDefaultBorder();
2944 else if ( border
== wxBORDER_THEME
)
2946 border
= GetDefaultBorderForControl();
2952 wxBorder
wxWindowBase::GetDefaultBorder() const
2954 return wxBORDER_NONE
;
2957 // ----------------------------------------------------------------------------
2959 // ----------------------------------------------------------------------------
2961 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2963 // here we just check if the point is inside the window or not
2965 // check the top and left border first
2966 bool outside
= x
< 0 || y
< 0;
2969 // check the right and bottom borders too
2970 wxSize size
= GetSize();
2971 outside
= x
>= size
.x
|| y
>= size
.y
;
2974 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2977 // ----------------------------------------------------------------------------
2979 // ----------------------------------------------------------------------------
2981 struct WXDLLEXPORT wxWindowNext
2985 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2986 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
2987 bool wxWindowBase::ms_winCaptureChanging
= false;
2989 void wxWindowBase::CaptureMouse()
2991 wxLogTrace(wxT("mousecapture"), wxT("CaptureMouse(%p)"), static_cast<void*>(this));
2993 wxASSERT_MSG( !ms_winCaptureChanging
, wxT("recursive CaptureMouse call?") );
2995 ms_winCaptureChanging
= true;
2997 wxWindow
*winOld
= GetCapture();
3000 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
3003 wxWindowNext
*item
= new wxWindowNext
;
3005 item
->next
= ms_winCaptureNext
;
3006 ms_winCaptureNext
= item
;
3008 //else: no mouse capture to save
3011 ms_winCaptureCurrent
= (wxWindow
*)this;
3013 ms_winCaptureChanging
= false;
3016 void wxWindowBase::ReleaseMouse()
3018 wxLogTrace(wxT("mousecapture"), wxT("ReleaseMouse(%p)"), static_cast<void*>(this));
3020 wxASSERT_MSG( !ms_winCaptureChanging
, wxT("recursive ReleaseMouse call?") );
3022 wxASSERT_MSG( GetCapture() == this,
3023 "attempt to release mouse, but this window hasn't captured it" );
3024 wxASSERT_MSG( ms_winCaptureCurrent
== this,
3025 "attempt to release mouse, but this window hasn't captured it" );
3027 ms_winCaptureChanging
= true;
3030 ms_winCaptureCurrent
= NULL
;
3032 if ( ms_winCaptureNext
)
3034 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
3035 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
3037 wxWindowNext
*item
= ms_winCaptureNext
;
3038 ms_winCaptureNext
= item
->next
;
3041 //else: stack is empty, no previous capture
3043 ms_winCaptureChanging
= false;
3045 wxLogTrace(wxT("mousecapture"),
3046 (const wxChar
*) wxT("After ReleaseMouse() mouse is captured by %p"),
3047 static_cast<void*>(GetCapture()));
3050 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
3052 wxMouseCaptureLostEvent
event(win
->GetId());
3053 event
.SetEventObject(win
);
3054 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
3056 // windows must handle this event, otherwise the app wouldn't behave
3057 // correctly if it loses capture unexpectedly; see the discussion here:
3058 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
3059 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
3060 wxFAIL_MSG( wxT("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
3065 void wxWindowBase::NotifyCaptureLost()
3067 // don't do anything if capture lost was expected, i.e. resulted from
3068 // a wx call to ReleaseMouse or CaptureMouse:
3069 if ( ms_winCaptureChanging
)
3072 // if the capture was lost unexpectedly, notify every window that has
3073 // capture (on stack or current) about it and clear the stack:
3075 if ( ms_winCaptureCurrent
)
3077 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
3078 ms_winCaptureCurrent
= NULL
;
3081 while ( ms_winCaptureNext
)
3083 wxWindowNext
*item
= ms_winCaptureNext
;
3084 ms_winCaptureNext
= item
->next
;
3086 DoNotifyWindowAboutCaptureLost(item
->win
);
3095 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
3096 int WXUNUSED(modifiers
),
3097 int WXUNUSED(keycode
))
3103 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
3109 #endif // wxUSE_HOTKEY
3111 // ----------------------------------------------------------------------------
3113 // ----------------------------------------------------------------------------
3115 bool wxWindowBase::TryBefore(wxEvent
& event
)
3117 #if wxUSE_VALIDATORS
3118 // Can only use the validator of the window which
3119 // is receiving the event
3120 if ( event
.GetEventObject() == this )
3122 wxValidator
* const validator
= GetValidator();
3123 if ( validator
&& validator
->ProcessEventLocally(event
) )
3128 #endif // wxUSE_VALIDATORS
3130 return wxEvtHandler::TryBefore(event
);
3133 bool wxWindowBase::TryAfter(wxEvent
& event
)
3135 // carry on up the parent-child hierarchy if the propagation count hasn't
3137 if ( event
.ShouldPropagate() )
3139 // honour the requests to stop propagation at this window: this is
3140 // used by the dialogs, for example, to prevent processing the events
3141 // from the dialog controls in the parent frame which rarely, if ever,
3143 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
3145 wxWindow
*parent
= GetParent();
3146 if ( parent
&& !parent
->IsBeingDeleted() )
3148 wxPropagateOnce
propagateOnce(event
);
3150 return parent
->GetEventHandler()->ProcessEvent(event
);
3155 return wxEvtHandler::TryAfter(event
);
3158 // ----------------------------------------------------------------------------
3159 // window relationships
3160 // ----------------------------------------------------------------------------
3162 wxWindow
*wxWindowBase::DoGetSibling(WindowOrder order
) const
3164 wxCHECK_MSG( GetParent(), NULL
,
3165 wxT("GetPrev/NextSibling() don't work for TLWs!") );
3167 wxWindowList
& siblings
= GetParent()->GetChildren();
3168 wxWindowList::compatibility_iterator i
= siblings
.Find((wxWindow
*)this);
3169 wxCHECK_MSG( i
, NULL
, wxT("window not a child of its parent?") );
3171 if ( order
== OrderBefore
)
3172 i
= i
->GetPrevious();
3176 return i
? i
->GetData() : NULL
;
3179 // ----------------------------------------------------------------------------
3180 // keyboard navigation
3181 // ----------------------------------------------------------------------------
3183 // Navigates in the specified direction inside this window
3184 bool wxWindowBase::DoNavigateIn(int flags
)
3186 #ifdef wxHAS_NATIVE_TAB_TRAVERSAL
3187 // native code doesn't process our wxNavigationKeyEvents anyhow
3190 #else // !wxHAS_NATIVE_TAB_TRAVERSAL
3191 wxNavigationKeyEvent eventNav
;
3192 wxWindow
*focused
= FindFocus();
3193 eventNav
.SetCurrentFocus(focused
);
3194 eventNav
.SetEventObject(focused
);
3195 eventNav
.SetFlags(flags
);
3196 return GetEventHandler()->ProcessEvent(eventNav
);
3197 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
3200 bool wxWindowBase::HandleAsNavigationKey(const wxKeyEvent
& event
)
3202 if ( event
.GetKeyCode() != WXK_TAB
)
3205 int flags
= wxNavigationKeyEvent::FromTab
;
3207 if ( event
.ShiftDown() )
3208 flags
|= wxNavigationKeyEvent::IsBackward
;
3210 flags
|= wxNavigationKeyEvent::IsForward
;
3212 if ( event
.ControlDown() )
3213 flags
|= wxNavigationKeyEvent::WinChange
;
3219 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, WindowOrder move
)
3221 // check that we're not a top level window
3222 wxCHECK_RET( GetParent(),
3223 wxT("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
3225 // detect the special case when we have nothing to do anyhow and when the
3226 // code below wouldn't work
3230 // find the target window in the siblings list
3231 wxWindowList
& siblings
= GetParent()->GetChildren();
3232 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
3233 wxCHECK_RET( i
, wxT("MoveBefore/AfterInTabOrder(): win is not a sibling") );
3235 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
3236 // can't just move the node around
3237 wxWindow
*self
= (wxWindow
*)this;
3238 siblings
.DeleteObject(self
);
3239 if ( move
== OrderAfter
)
3246 siblings
.Insert(i
, self
);
3248 else // OrderAfter and win was the last sibling
3250 siblings
.Append(self
);
3254 // ----------------------------------------------------------------------------
3256 // ----------------------------------------------------------------------------
3258 /*static*/ wxWindow
* wxWindowBase::FindFocus()
3260 wxWindowBase
*win
= DoFindFocus();
3261 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
3264 bool wxWindowBase::HasFocus() const
3266 wxWindowBase
*win
= DoFindFocus();
3267 return win
== this ||
3268 win
== wxConstCast(this, wxWindowBase
)->GetMainWindowOfCompositeControl();
3271 // ----------------------------------------------------------------------------
3273 // ----------------------------------------------------------------------------
3275 #if wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
3280 class DragAcceptFilesTarget
: public wxFileDropTarget
3283 DragAcceptFilesTarget(wxWindowBase
*win
) : m_win(win
) {}
3285 virtual bool OnDropFiles(wxCoord x
, wxCoord y
,
3286 const wxArrayString
& filenames
)
3288 wxDropFilesEvent
event(wxEVT_DROP_FILES
,
3290 wxCArrayString(filenames
).Release());
3291 event
.SetEventObject(m_win
);
3295 return m_win
->HandleWindowEvent(event
);
3299 wxWindowBase
* const m_win
;
3301 wxDECLARE_NO_COPY_CLASS(DragAcceptFilesTarget
);
3305 } // anonymous namespace
3307 // Generic version of DragAcceptFiles(). It works by installing a simple
3308 // wxFileDropTarget-to-EVT_DROP_FILES adaptor and therefore cannot be used
3309 // together with explicit SetDropTarget() calls.
3310 void wxWindowBase::DragAcceptFiles(bool accept
)
3314 wxASSERT_MSG( !GetDropTarget(),
3315 "cannot use DragAcceptFiles() and SetDropTarget() together" );
3316 SetDropTarget(new DragAcceptFilesTarget(this));
3320 SetDropTarget(NULL
);
3324 #endif // wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
3326 // ----------------------------------------------------------------------------
3328 // ----------------------------------------------------------------------------
3330 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
3332 while ( win
&& !win
->IsTopLevel() )
3333 win
= win
->GetParent();
3338 #if wxUSE_ACCESSIBILITY
3339 // ----------------------------------------------------------------------------
3340 // accessible object for windows
3341 // ----------------------------------------------------------------------------
3343 // Can return either a child object, or an integer
3344 // representing the child element, starting from 1.
3345 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
3347 wxASSERT( GetWindow() != NULL
);
3351 return wxACC_NOT_IMPLEMENTED
;
3354 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
3355 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
3357 wxASSERT( GetWindow() != NULL
);
3361 wxWindow
* win
= NULL
;
3368 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
3370 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
3377 rect
= win
->GetRect();
3378 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
3379 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
3383 return wxACC_NOT_IMPLEMENTED
;
3386 // Navigates from fromId to toId/toObject.
3387 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
3388 int* WXUNUSED(toId
), wxAccessible
** toObject
)
3390 wxASSERT( GetWindow() != NULL
);
3396 case wxNAVDIR_FIRSTCHILD
:
3398 if (GetWindow()->GetChildren().GetCount() == 0)
3400 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
3401 *toObject
= childWindow
->GetOrCreateAccessible();
3405 case wxNAVDIR_LASTCHILD
:
3407 if (GetWindow()->GetChildren().GetCount() == 0)
3409 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
3410 *toObject
= childWindow
->GetOrCreateAccessible();
3414 case wxNAVDIR_RIGHT
:
3418 wxWindowList::compatibility_iterator node
=
3419 wxWindowList::compatibility_iterator();
3422 // Can't navigate to sibling of this window
3423 // if we're a top-level window.
3424 if (!GetWindow()->GetParent())
3425 return wxACC_NOT_IMPLEMENTED
;
3427 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3431 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
3432 node
= GetWindow()->GetChildren().Item(fromId
-1);
3435 if (node
&& node
->GetNext())
3437 wxWindow
* nextWindow
= node
->GetNext()->GetData();
3438 *toObject
= nextWindow
->GetOrCreateAccessible();
3446 case wxNAVDIR_PREVIOUS
:
3448 wxWindowList::compatibility_iterator node
=
3449 wxWindowList::compatibility_iterator();
3452 // Can't navigate to sibling of this window
3453 // if we're a top-level window.
3454 if (!GetWindow()->GetParent())
3455 return wxACC_NOT_IMPLEMENTED
;
3457 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3461 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
3462 node
= GetWindow()->GetChildren().Item(fromId
-1);
3465 if (node
&& node
->GetPrevious())
3467 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
3468 *toObject
= previousWindow
->GetOrCreateAccessible();
3476 return wxACC_NOT_IMPLEMENTED
;
3479 // Gets the name of the specified object.
3480 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
3482 wxASSERT( GetWindow() != NULL
);
3488 // If a child, leave wxWidgets to call the function on the actual
3491 return wxACC_NOT_IMPLEMENTED
;
3493 // This will eventually be replaced by specialised
3494 // accessible classes, one for each kind of wxWidgets
3495 // control or window.
3497 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
3498 title
= ((wxButton
*) GetWindow())->GetLabel();
3501 title
= GetWindow()->GetName();
3509 return wxACC_NOT_IMPLEMENTED
;
3512 // Gets the number of children.
3513 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
3515 wxASSERT( GetWindow() != NULL
);
3519 *childId
= (int) GetWindow()->GetChildren().GetCount();
3523 // Gets the specified child (starting from 1).
3524 // If *child is NULL and return value is wxACC_OK,
3525 // this means that the child is a simple element and
3526 // not an accessible object.
3527 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
3529 wxASSERT( GetWindow() != NULL
);
3539 if (childId
> (int) GetWindow()->GetChildren().GetCount())
3542 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
3543 *child
= childWindow
->GetOrCreateAccessible();
3550 // Gets the parent, or NULL.
3551 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
3553 wxASSERT( GetWindow() != NULL
);
3557 wxWindow
* parentWindow
= GetWindow()->GetParent();
3565 *parent
= parentWindow
->GetOrCreateAccessible();
3573 // Performs the default action. childId is 0 (the action for this object)
3574 // or > 0 (the action for a child).
3575 // Return wxACC_NOT_SUPPORTED if there is no default action for this
3576 // window (e.g. an edit control).
3577 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
3579 wxASSERT( GetWindow() != NULL
);
3583 return wxACC_NOT_IMPLEMENTED
;
3586 // Gets the default action for this object (0) or > 0 (the action for a child).
3587 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
3588 // string if there is no action.
3589 // The retrieved string describes the action that is performed on an object,
3590 // not what the object does as a result. For example, a toolbar button that prints
3591 // a document has a default action of "Press" rather than "Prints the current document."
3592 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
3594 wxASSERT( GetWindow() != NULL
);
3598 return wxACC_NOT_IMPLEMENTED
;
3601 // Returns the description for this object or a child.
3602 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
3604 wxASSERT( GetWindow() != NULL
);
3608 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3614 return wxACC_NOT_IMPLEMENTED
;
3617 // Returns help text for this object or a child, similar to tooltip text.
3618 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
3620 wxASSERT( GetWindow() != NULL
);
3624 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3630 return wxACC_NOT_IMPLEMENTED
;
3633 // Returns the keyboard shortcut for this object or child.
3634 // Return e.g. ALT+K
3635 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
3637 wxASSERT( GetWindow() != NULL
);
3641 return wxACC_NOT_IMPLEMENTED
;
3644 // Returns a role constant.
3645 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
3647 wxASSERT( GetWindow() != NULL
);
3651 // If a child, leave wxWidgets to call the function on the actual
3654 return wxACC_NOT_IMPLEMENTED
;
3656 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3657 return wxACC_NOT_IMPLEMENTED
;
3659 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3660 return wxACC_NOT_IMPLEMENTED
;
3663 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3664 return wxACC_NOT_IMPLEMENTED
;
3667 //*role = wxROLE_SYSTEM_CLIENT;
3668 *role
= wxROLE_SYSTEM_CLIENT
;
3672 return wxACC_NOT_IMPLEMENTED
;
3676 // Returns a state constant.
3677 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
3679 wxASSERT( GetWindow() != NULL
);
3683 // If a child, leave wxWidgets to call the function on the actual
3686 return wxACC_NOT_IMPLEMENTED
;
3688 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
3689 return wxACC_NOT_IMPLEMENTED
;
3692 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
3693 return wxACC_NOT_IMPLEMENTED
;
3696 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
3697 return wxACC_NOT_IMPLEMENTED
;
3704 return wxACC_NOT_IMPLEMENTED
;
3708 // Returns a localized string representing the value for the object
3710 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3712 wxASSERT( GetWindow() != NULL
);
3716 return wxACC_NOT_IMPLEMENTED
;
3719 // Selects the object or child.
3720 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3722 wxASSERT( GetWindow() != NULL
);
3726 return wxACC_NOT_IMPLEMENTED
;
3729 // Gets the window with the keyboard focus.
3730 // If childId is 0 and child is NULL, no object in
3731 // this subhierarchy has the focus.
3732 // If this object has the focus, child should be 'this'.
3733 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3735 wxASSERT( GetWindow() != NULL
);
3739 return wxACC_NOT_IMPLEMENTED
;
3743 // Gets a variant representing the selected children
3745 // Acceptable values:
3746 // - a null variant (IsNull() returns true)
3747 // - a list variant (GetType() == wxT("list")
3748 // - an integer representing the selected child element,
3749 // or 0 if this object is selected (GetType() == wxT("long")
3750 // - a "void*" pointer to a wxAccessible child object
3751 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3753 wxASSERT( GetWindow() != NULL
);
3757 return wxACC_NOT_IMPLEMENTED
;
3759 #endif // wxUSE_VARIANT
3761 #endif // wxUSE_ACCESSIBILITY
3763 // ----------------------------------------------------------------------------
3765 // ----------------------------------------------------------------------------
3768 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3770 wxCoord widthTotal
) const
3772 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3774 x
= widthTotal
- x
- width
;