1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/wincmn.cpp
3 // Purpose: common (to all ports) wxWindow functions
4 // Author: Julian Smart, Vadim Zeitlin
7 // Copyright: (c) wxWidgets team
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
27 #include "wx/string.h"
31 #include "wx/window.h"
32 #include "wx/control.h"
33 #include "wx/checkbox.h"
34 #include "wx/radiobut.h"
35 #include "wx/statbox.h"
36 #include "wx/textctrl.h"
37 #include "wx/settings.h"
38 #include "wx/dialog.h"
39 #include "wx/msgdlg.h"
40 #include "wx/msgout.h"
41 #include "wx/statusbr.h"
42 #include "wx/toolbar.h"
43 #include "wx/dcclient.h"
44 #include "wx/scrolbar.h"
45 #include "wx/layout.h"
50 #if wxUSE_DRAG_AND_DROP
52 #endif // wxUSE_DRAG_AND_DROP
54 #if wxUSE_ACCESSIBILITY
55 #include "wx/access.h"
59 #include "wx/cshelp.h"
63 #include "wx/tooltip.h"
64 #endif // wxUSE_TOOLTIPS
70 #if wxUSE_SYSTEM_OPTIONS
71 #include "wx/sysopt.h"
74 #include "wx/platinfo.h"
75 #include "wx/private/window.h"
78 #include "wx/msw/wrapwin.h"
82 WXDLLIMPEXP_DATA_CORE(wxWindowList
) wxTopLevelWindows
;
86 wxMenu
*wxCurrentPopupMenu
= NULL
;
89 extern WXDLLEXPORT_DATA(const char) wxPanelNameStr
[] = "panel";
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
96 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
102 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
103 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
104 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
105 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
108 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
111 EVT_SIZE(wxWindowBase::InternalOnSize
)
114 // ============================================================================
115 // implementation of the common functionality of the wxWindow class
116 // ============================================================================
118 // ----------------------------------------------------------------------------
120 // ----------------------------------------------------------------------------
122 #if wxUSE_EXTENDED_RTTI
124 // windows that are created from a parent window during its Create method,
125 // eg. spin controls in a calendar controls must never been streamed out
126 // separately otherwise chaos occurs. Right now easiest is to test for negative ids,
127 // as windows with negative ids never can be recreated anyway
130 bool wxWindowStreamingCallback( const wxObject
*object
, wxObjectWriter
*,
131 wxObjectWriterCallback
*, const wxStringToAnyHashMap
& )
133 const wxWindow
* win
= wx_dynamic_cast(const wxWindow
*, object
);
134 if ( win
&& win
->GetId() < 0 )
139 wxIMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
, "wx/window.h", \
140 wxWindowStreamingCallback
)
142 // make wxWindowList known before the property is used
144 wxCOLLECTION_TYPE_INFO( wxWindow
*, wxWindowList
);
146 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
,
149 wxListCollectionToAnyList
<wxWindowList::compatibility_iterator
>( theList
, value
);
152 wxDEFINE_FLAGS( wxWindowStyle
)
154 wxBEGIN_FLAGS( wxWindowStyle
)
155 // new style border flags, we put them first to
156 // use them for streaming out
158 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
159 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
160 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
161 wxFLAGS_MEMBER(wxBORDER_RAISED
)
162 wxFLAGS_MEMBER(wxBORDER_STATIC
)
163 wxFLAGS_MEMBER(wxBORDER_NONE
)
165 // old style border flags
166 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
167 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
168 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
169 wxFLAGS_MEMBER(wxRAISED_BORDER
)
170 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
171 wxFLAGS_MEMBER(wxBORDER
)
173 // standard window styles
174 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
175 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
176 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
177 wxFLAGS_MEMBER(wxWANTS_CHARS
)
178 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
179 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
180 wxFLAGS_MEMBER(wxVSCROLL
)
181 wxFLAGS_MEMBER(wxHSCROLL
)
183 wxEND_FLAGS( wxWindowStyle
)
185 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
186 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
187 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
188 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
189 // Always constructor Properties first
191 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, wxEMPTY_PARAMETER_VALUE
, \
192 0 /*flags*/, wxT("Helpstring"), wxT("group"))
193 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, -1 /*wxID_ANY*/, 0 /*flags*/, \
194 wxT("Helpstring"), wxT("group") )
195 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, \
196 0 /*flags*/, wxT("Helpstring"), wxT("group")) // pos
197 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/, \
198 wxT("Helpstring"), wxT("group")) // size
199 wxPROPERTY( WindowStyle
, long, SetWindowStyleFlag
, GetWindowStyleFlag
, \
200 wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, wxT("Helpstring"), wxT("group")) // style
201 wxPROPERTY( Name
,wxString
, SetName
, GetName
, wxEmptyString
, 0 /*flags*/, \
202 wxT("Helpstring"), wxT("group") )
204 // Then all relations of the object graph
206 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
*, \
207 GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/, \
208 wxT("Helpstring"), wxT("group"))
210 // and finally all other properties
212 wxPROPERTY( ExtraStyle
, long, SetExtraStyle
, GetExtraStyle
, wxEMPTY_PARAMETER_VALUE
, \
213 0 /*flags*/, wxT("Helpstring"), wxT("group")) // extstyle
214 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, \
215 wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, wxT("Helpstring"), wxT("group")) // bg
216 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, \
217 wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, wxT("Helpstring"), wxT("group")) // fg
218 wxPROPERTY( Enabled
, bool, Enable
, IsEnabled
, wxAny((bool)true), 0 /*flags*/, \
219 wxT("Helpstring"), wxT("group"))
220 wxPROPERTY( Shown
, bool, Show
, IsShown
, wxAny((bool)true), 0 /*flags*/, \
221 wxT("Helpstring"), wxT("group"))
224 // possible property candidates (not in xrc) or not valid in all subclasses
225 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxEmptyString
)
226 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
227 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxEmptyString
)
228 // MaxHeight, Width, MinHeight, Width
229 // TODO switch label to control and title to toplevels
231 wxPROPERTY( ThemeEnabled
, bool, SetThemeEnabled
, GetThemeEnabled
, )
232 //wxPROPERTY( Cursor, wxCursor, SetCursor, GetCursor, )
233 // wxPROPERTY( ToolTip, wxString, SetToolTip, GetToolTipText, )
234 wxPROPERTY( AutoLayout
, bool, SetAutoLayout
, GetAutoLayout
, )
236 wxEND_PROPERTIES_TABLE()
238 wxEMPTY_HANDLERS_TABLE(wxWindow
)
240 wxCONSTRUCTOR_DUMMY(wxWindow
)
244 #ifndef __WXUNIVERSAL__
245 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
250 // ----------------------------------------------------------------------------
252 // ----------------------------------------------------------------------------
254 // the default initialization
255 wxWindowBase::wxWindowBase()
257 // no window yet, no parent nor children
259 m_windowId
= wxID_ANY
;
261 // no constraints on the minimal window size
263 m_maxWidth
= wxDefaultCoord
;
265 m_maxHeight
= wxDefaultCoord
;
267 // invalidiated cache value
268 m_bestSizeCache
= wxDefaultSize
;
270 // window are created enabled and visible by default
274 // the default event handler is just this window
275 m_eventHandler
= this;
279 m_windowValidator
= NULL
;
280 #endif // wxUSE_VALIDATORS
282 // the colours/fonts are default for now, so leave m_font,
283 // m_backgroundColour and m_foregroundColour uninitialized and set those
289 m_inheritFont
= false;
295 m_backgroundStyle
= wxBG_STYLE_ERASE
;
297 #if wxUSE_CONSTRAINTS
298 // no constraints whatsoever
299 m_constraints
= NULL
;
300 m_constraintsInvolvedIn
= NULL
;
301 #endif // wxUSE_CONSTRAINTS
303 m_windowSizer
= NULL
;
304 m_containingSizer
= NULL
;
305 m_autoLayout
= false;
307 #if wxUSE_DRAG_AND_DROP
309 #endif // wxUSE_DRAG_AND_DROP
313 #endif // wxUSE_TOOLTIPS
317 #endif // wxUSE_CARET
320 m_hasCustomPalette
= false;
321 #endif // wxUSE_PALETTE
323 #if wxUSE_ACCESSIBILITY
327 m_virtualSize
= wxDefaultSize
;
329 m_scrollHelper
= NULL
;
331 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
332 #if wxUSE_SYSTEM_OPTIONS
333 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
335 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
339 // Whether we're using the current theme for this window (wxGTK only for now)
340 m_themeEnabled
= false;
342 // This is set to true by SendDestroyEvent() which should be called by the
343 // most derived class to ensure that the destruction event is sent as soon
344 // as possible to allow its handlers to still see the undestroyed window
345 m_isBeingDeleted
= false;
350 // common part of window creation process
351 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
353 const wxPoint
& WXUNUSED(pos
),
356 const wxString
& name
)
358 // ids are limited to 16 bits under MSW so if you care about portability,
359 // it's not a good idea to use ids out of this range (and negative ids are
360 // reserved for wxWidgets own usage)
361 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767) ||
362 (id
>= wxID_AUTO_LOWEST
&& id
<= wxID_AUTO_HIGHEST
),
363 wxT("invalid id value") );
365 // generate a new id if the user doesn't care about it
366 if ( id
== wxID_ANY
)
368 m_windowId
= NewControlId();
370 else // valid id specified
375 // don't use SetWindowStyleFlag() here, this function should only be called
376 // to change the flag after creation as it tries to reflect the changes in
377 // flags by updating the window dynamically and we don't need this here
378 m_windowStyle
= style
;
380 // assume the user doesn't want this window to shrink beneath its initial
381 // size, this worked like this in wxWidgets 2.8 and before and generally
382 // often makes sense for child windows (for top level ones it definitely
383 // does not as the user should be able to resize the window)
385 // note that we can't use IsTopLevel() from ctor
386 if ( size
!= wxDefaultSize
&& !wxTopLevelWindows
.Find((wxWindow
*)this) )
395 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
400 const wxValidator
& wxVALIDATOR_PARAM(validator
),
401 const wxString
& name
)
403 if ( !CreateBase(parent
, id
, pos
, size
, style
, name
) )
407 SetValidator(validator
);
408 #endif // wxUSE_VALIDATORS
410 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
411 // have it too - like this it's possible to set it only in the top level
412 // dialog/frame and all children will inherit it by defult
413 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
415 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
421 bool wxWindowBase::ToggleWindowStyle(int flag
)
423 wxASSERT_MSG( flag
, wxT("flags with 0 value can't be toggled") );
426 long style
= GetWindowStyleFlag();
432 else // currently off
438 SetWindowStyleFlag(style
);
443 // ----------------------------------------------------------------------------
445 // ----------------------------------------------------------------------------
448 wxWindowBase::~wxWindowBase()
450 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
452 // FIXME if these 2 cases result from programming errors in the user code
453 // we should probably assert here instead of silently fixing them
455 // Just in case the window has been Closed, but we're then deleting
456 // immediately: don't leave dangling pointers.
457 wxPendingDelete
.DeleteObject(this);
459 // Just in case we've loaded a top-level window via LoadNativeDialog but
460 // we weren't a dialog class
461 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
463 // Any additional event handlers should be popped before the window is
464 // deleted as otherwise the last handler will be left with a dangling
465 // pointer to this window result in a difficult to diagnose crash later on.
466 wxASSERT_MSG( GetEventHandler() == this,
467 wxT("any pushed event handlers must have been removed") );
470 // The associated popup menu can still be alive, disassociate from it in
472 if ( wxCurrentPopupMenu
&& wxCurrentPopupMenu
->GetInvokingWindow() == this )
473 wxCurrentPopupMenu
->SetInvokingWindow(NULL
);
474 #endif // wxUSE_MENUS
476 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
478 // notify the parent about this window destruction
480 m_parent
->RemoveChild(this);
484 #endif // wxUSE_CARET
487 delete m_windowValidator
;
488 #endif // wxUSE_VALIDATORS
490 #if wxUSE_CONSTRAINTS
491 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
492 // at deleted windows as they delete themselves.
493 DeleteRelatedConstraints();
497 // This removes any dangling pointers to this window in other windows'
498 // constraintsInvolvedIn lists.
499 UnsetConstraints(m_constraints
);
500 wxDELETE(m_constraints
);
502 #endif // wxUSE_CONSTRAINTS
504 if ( m_containingSizer
)
505 m_containingSizer
->Detach( (wxWindow
*)this );
507 delete m_windowSizer
;
509 #if wxUSE_DRAG_AND_DROP
511 #endif // wxUSE_DRAG_AND_DROP
515 #endif // wxUSE_TOOLTIPS
517 #if wxUSE_ACCESSIBILITY
522 // NB: this has to be called unconditionally, because we don't know
523 // whether this window has associated help text or not
524 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
526 helpProvider
->RemoveHelp(this);
530 bool wxWindowBase::IsBeingDeleted() const
532 return m_isBeingDeleted
||
533 (!IsTopLevel() && m_parent
&& m_parent
->IsBeingDeleted());
536 void wxWindowBase::SendDestroyEvent()
538 if ( m_isBeingDeleted
)
540 // we could have been already called from a more derived class dtor,
541 // e.g. ~wxTLW calls us and so does ~wxWindow and the latter call
542 // should be simply ignored
546 m_isBeingDeleted
= true;
548 wxWindowDestroyEvent event
;
549 event
.SetEventObject(this);
550 event
.SetId(GetId());
551 GetEventHandler()->ProcessEvent(event
);
554 bool wxWindowBase::Destroy()
556 // If our handle is invalid, it means that this window has never been
557 // created, either because creating it failed or, more typically, because
558 // this wxWindow object was default-constructed and its Create() method had
559 // never been called. As we didn't send wxWindowCreateEvent in this case
560 // (which is sent after successful creation), don't send the matching
561 // wxWindowDestroyEvent neither.
570 bool wxWindowBase::Close(bool force
)
572 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
573 event
.SetEventObject(this);
574 event
.SetCanVeto(!force
);
576 // return false if window wasn't closed because the application vetoed the
578 return HandleWindowEvent(event
) && !event
.GetVeto();
581 bool wxWindowBase::DestroyChildren()
583 wxWindowList::compatibility_iterator node
;
586 // we iterate until the list becomes empty
587 node
= GetChildren().GetFirst();
591 wxWindow
*child
= node
->GetData();
593 // note that we really want to delete it immediately so don't call the
594 // possible overridden Destroy() version which might not delete the
595 // child immediately resulting in problems with our (top level) child
596 // outliving its parent
597 child
->wxWindowBase::Destroy();
599 wxASSERT_MSG( !GetChildren().Find(child
),
600 wxT("child didn't remove itself using RemoveChild()") );
606 // ----------------------------------------------------------------------------
607 // size/position related methods
608 // ----------------------------------------------------------------------------
610 // centre the window with respect to its parent in either (or both) directions
611 void wxWindowBase::DoCentre(int dir
)
613 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
614 wxT("this method only implements centering child windows") );
616 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
619 // fits the window around the children
620 void wxWindowBase::Fit()
622 SetSize(GetBestSize());
625 // fits virtual size (ie. scrolled area etc.) around children
626 void wxWindowBase::FitInside()
628 SetVirtualSize( GetBestVirtualSize() );
631 // On Mac, scrollbars are explicitly children.
632 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
633 static bool wxHasRealChildren(const wxWindowBase
* win
)
635 int realChildCount
= 0;
637 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
639 node
= node
->GetNext() )
641 wxWindow
*win
= node
->GetData();
642 if ( !win
->IsTopLevel() && win
->IsShown()
644 && !wxDynamicCast(win
, wxScrollBar
)
649 return (realChildCount
> 0);
653 void wxWindowBase::InvalidateBestSize()
655 m_bestSizeCache
= wxDefaultSize
;
657 // parent's best size calculation may depend on its children's
658 // as long as child window we are in is not top level window itself
659 // (because the TLW size is never resized automatically)
660 // so let's invalidate it as well to be safe:
661 if (m_parent
&& !IsTopLevel())
662 m_parent
->InvalidateBestSize();
665 // return the size best suited for the current window
666 wxSize
wxWindowBase::DoGetBestSize() const
672 best
= m_windowSizer
->GetMinSize();
674 #if wxUSE_CONSTRAINTS
675 else if ( m_constraints
)
677 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
679 // our minimal acceptable size is such that all our windows fit inside
683 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
685 node
= node
->GetNext() )
687 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
690 // it's not normal that we have an unconstrained child, but
691 // what can we do about it?
695 int x
= c
->right
.GetValue(),
696 y
= c
->bottom
.GetValue();
704 // TODO: we must calculate the overlaps somehow, otherwise we
705 // will never return a size bigger than the current one :-(
708 best
= wxSize(maxX
, maxY
);
710 #endif // wxUSE_CONSTRAINTS
711 else if ( !GetChildren().empty()
712 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
713 && wxHasRealChildren(this)
717 // our minimal acceptable size is such that all our visible child
718 // windows fit inside
722 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
724 node
= node
->GetNext() )
726 wxWindow
*win
= node
->GetData();
727 if ( win
->IsTopLevel()
730 || wxDynamicCast(win
, wxStatusBar
)
731 #endif // wxUSE_STATUSBAR
734 // dialogs and frames lie in different top level windows -
735 // don't deal with them here; as for the status bars, they
736 // don't lie in the client area at all
741 win
->GetPosition(&wx
, &wy
);
743 // if the window hadn't been positioned yet, assume that it is in
745 if ( wx
== wxDefaultCoord
)
747 if ( wy
== wxDefaultCoord
)
750 win
->GetSize(&ww
, &wh
);
751 if ( wx
+ ww
> maxX
)
753 if ( wy
+ wh
> maxY
)
757 best
= wxSize(maxX
, maxY
);
759 else // ! has children
761 wxSize size
= GetMinSize();
762 if ( !size
.IsFullySpecified() )
764 // if the window doesn't define its best size we assume that it can
765 // be arbitrarily small -- usually this is not the case, of course,
766 // but we have no way to know what the limit is, it should really
767 // override DoGetBestClientSize() itself to tell us
768 size
.SetDefaults(wxSize(1, 1));
771 // return as-is, unadjusted by the client size difference.
775 // Add any difference between size and client size
776 wxSize diff
= GetSize() - GetClientSize();
777 best
.x
+= wxMax(0, diff
.x
);
778 best
.y
+= wxMax(0, diff
.y
);
783 // helper of GetWindowBorderSize(): as many ports don't implement support for
784 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
785 // fallbacks in this case
786 static int wxGetMetricOrDefault(wxSystemMetric what
, const wxWindowBase
* win
)
788 int rc
= wxSystemSettings::GetMetric(
789 what
, static_cast<wxWindow
*>(const_cast<wxWindowBase
*>(win
)));
796 // 2D border is by default 1 pixel wide
802 // 3D borders are by default 2 pixels
807 wxFAIL_MSG( wxT("unexpected wxGetMetricOrDefault() argument") );
815 wxSize
wxWindowBase::GetWindowBorderSize() const
819 switch ( GetBorder() )
822 // nothing to do, size is already (0, 0)
825 case wxBORDER_SIMPLE
:
826 case wxBORDER_STATIC
:
827 size
.x
= wxGetMetricOrDefault(wxSYS_BORDER_X
, this);
828 size
.y
= wxGetMetricOrDefault(wxSYS_BORDER_Y
, this);
831 case wxBORDER_SUNKEN
:
832 case wxBORDER_RAISED
:
833 size
.x
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X
, this),
834 wxGetMetricOrDefault(wxSYS_BORDER_X
, this));
835 size
.y
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y
, this),
836 wxGetMetricOrDefault(wxSYS_BORDER_Y
, this));
839 case wxBORDER_DOUBLE
:
840 size
.x
= wxGetMetricOrDefault(wxSYS_EDGE_X
, this) +
841 wxGetMetricOrDefault(wxSYS_BORDER_X
, this);
842 size
.y
= wxGetMetricOrDefault(wxSYS_EDGE_Y
, this) +
843 wxGetMetricOrDefault(wxSYS_BORDER_Y
, this);
847 wxFAIL_MSG(wxT("Unknown border style."));
851 // we have borders on both sides
856 wxWindowBase::InformFirstDirection(int direction
,
858 int availableOtherDir
)
860 return GetSizer() && GetSizer()->InformFirstDirection(direction
,
865 wxSize
wxWindowBase::GetEffectiveMinSize() const
867 // merge the best size with the min size, giving priority to the min size
868 wxSize min
= GetMinSize();
870 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
872 wxSize best
= GetBestSize();
873 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
874 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
880 wxSize
wxWindowBase::DoGetBorderSize() const
882 // there is one case in which we can implement it for all ports easily
883 if ( GetBorder() == wxBORDER_NONE
)
886 // otherwise use the difference between the real size and the client size
887 // as a fallback: notice that this is incorrect in general as client size
888 // also doesn't take the scrollbars into account
889 return GetSize() - GetClientSize();
892 wxSize
wxWindowBase::GetBestSize() const
894 if ( !m_windowSizer
&& m_bestSizeCache
.IsFullySpecified() )
895 return m_bestSizeCache
;
897 // call DoGetBestClientSize() first, if a derived class overrides it wants
899 wxSize size
= DoGetBestClientSize();
900 if ( size
!= wxDefaultSize
)
901 size
+= DoGetBorderSize();
903 size
= DoGetBestSize();
905 // Ensure that the best size is at least as large as min size.
906 size
.IncTo(GetMinSize());
908 // And not larger than max size.
909 size
.DecToIfSpecified(GetMaxSize());
911 // Finally cache result and return.
916 int wxWindowBase::GetBestHeight(int width
) const
918 const int height
= DoGetBestClientHeight(width
);
920 return height
== wxDefaultCoord
922 : height
+ DoGetBorderSize().y
;
925 int wxWindowBase::GetBestWidth(int height
) const
927 const int width
= DoGetBestClientWidth(height
);
929 return width
== wxDefaultCoord
931 : width
+ DoGetBorderSize().x
;
934 void wxWindowBase::SetMinSize(const wxSize
& minSize
)
936 m_minWidth
= minSize
.x
;
937 m_minHeight
= minSize
.y
;
939 InvalidateBestSize();
942 void wxWindowBase::SetMaxSize(const wxSize
& maxSize
)
944 m_maxWidth
= maxSize
.x
;
945 m_maxHeight
= maxSize
.y
;
947 InvalidateBestSize();
950 void wxWindowBase::SetInitialSize(const wxSize
& size
)
952 // Set the min size to the size passed in. This will usually either be
953 // wxDefaultSize or the size passed to this window's ctor/Create function.
956 // Merge the size with the best size if needed
957 wxSize best
= GetEffectiveMinSize();
959 // If the current size doesn't match then change it
960 if (GetSize() != best
)
965 // by default the origin is not shifted
966 wxPoint
wxWindowBase::GetClientAreaOrigin() const
971 wxSize
wxWindowBase::ClientToWindowSize(const wxSize
& size
) const
973 const wxSize
diff(GetSize() - GetClientSize());
975 return wxSize(size
.x
== -1 ? -1 : size
.x
+ diff
.x
,
976 size
.y
== -1 ? -1 : size
.y
+ diff
.y
);
979 wxSize
wxWindowBase::WindowToClientSize(const wxSize
& size
) const
981 const wxSize
diff(GetSize() - GetClientSize());
983 return wxSize(size
.x
== -1 ? -1 : size
.x
- diff
.x
,
984 size
.y
== -1 ? -1 : size
.y
- diff
.y
);
987 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
989 if ( m_windowVariant
!= variant
)
991 m_windowVariant
= variant
;
993 DoSetWindowVariant(variant
);
997 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
999 // adjust the font height to correspond to our new variant (notice that
1000 // we're only called if something really changed)
1001 wxFont font
= GetFont();
1002 int size
= font
.GetPointSize();
1005 case wxWINDOW_VARIANT_NORMAL
:
1008 case wxWINDOW_VARIANT_SMALL
:
1009 size
= wxRound(size
* 3.0 / 4.0);
1012 case wxWINDOW_VARIANT_MINI
:
1013 size
= wxRound(size
* 2.0 / 3.0);
1016 case wxWINDOW_VARIANT_LARGE
:
1017 size
= wxRound(size
* 5.0 / 4.0);
1021 wxFAIL_MSG(wxT("unexpected window variant"));
1025 font
.SetPointSize(size
);
1029 void wxWindowBase::DoSetSizeHints( int minW
, int minH
,
1031 int WXUNUSED(incW
), int WXUNUSED(incH
) )
1033 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
1034 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
1035 wxT("min width/height must be less than max width/height!") );
1044 #if WXWIN_COMPATIBILITY_2_8
1045 void wxWindowBase::SetVirtualSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
),
1046 int WXUNUSED(maxW
), int WXUNUSED(maxH
))
1050 void wxWindowBase::SetVirtualSizeHints(const wxSize
& WXUNUSED(minsize
),
1051 const wxSize
& WXUNUSED(maxsize
))
1054 #endif // WXWIN_COMPATIBILITY_2_8
1056 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
1058 m_virtualSize
= wxSize(x
, y
);
1061 wxSize
wxWindowBase::DoGetVirtualSize() const
1063 // we should use the entire client area so if it is greater than our
1064 // virtual size, expand it to fit (otherwise if the window is big enough we
1065 // wouldn't be using parts of it)
1066 wxSize size
= GetClientSize();
1067 if ( m_virtualSize
.x
> size
.x
)
1068 size
.x
= m_virtualSize
.x
;
1070 if ( m_virtualSize
.y
>= size
.y
)
1071 size
.y
= m_virtualSize
.y
;
1076 void wxWindowBase::DoGetScreenPosition(int *x
, int *y
) const
1078 // screen position is the same as (0, 0) in client coords for non TLWs (and
1079 // TLWs override this method)
1085 ClientToScreen(x
, y
);
1088 void wxWindowBase::SendSizeEvent(int flags
)
1090 wxSizeEvent
event(GetSize(), GetId());
1091 event
.SetEventObject(this);
1092 if ( flags
& wxSEND_EVENT_POST
)
1093 wxPostEvent(GetEventHandler(), event
);
1095 HandleWindowEvent(event
);
1098 void wxWindowBase::SendSizeEventToParent(int flags
)
1100 wxWindow
* const parent
= GetParent();
1101 if ( parent
&& !parent
->IsBeingDeleted() )
1102 parent
->SendSizeEvent(flags
);
1105 bool wxWindowBase::HasScrollbar(int orient
) const
1107 // if scrolling in the given direction is disabled, we can't have the
1108 // corresponding scrollbar no matter what
1109 if ( !CanScroll(orient
) )
1112 const wxSize sizeVirt
= GetVirtualSize();
1113 const wxSize sizeClient
= GetClientSize();
1115 return orient
== wxHORIZONTAL
? sizeVirt
.x
> sizeClient
.x
1116 : sizeVirt
.y
> sizeClient
.y
;
1119 // ----------------------------------------------------------------------------
1120 // show/hide/enable/disable the window
1121 // ----------------------------------------------------------------------------
1123 bool wxWindowBase::Show(bool show
)
1125 if ( show
!= m_isShown
)
1137 bool wxWindowBase::IsEnabled() const
1139 return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
1142 void wxWindowBase::NotifyWindowOnEnableChange(bool enabled
)
1144 // Under some platforms there is no need to update the window state
1145 // explicitly, it will become disabled when its parent is. On other ones we
1146 // do need to disable all windows recursively though.
1147 #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
1149 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
1151 // Disabling a top level window is typically done when showing a modal
1152 // dialog and we don't need to disable its children in this case, they will
1153 // be logically disabled anyhow (i.e. their IsEnabled() will return false)
1154 // and the TLW won't accept any input for them. Moreover, explicitly
1155 // disabling them would look ugly as the entire TLW would be greyed out
1156 // whenever a modal dialog is shown and no native applications under any
1157 // platform behave like this.
1158 if ( IsTopLevel() && !enabled
)
1161 // When disabling (or enabling back) a non-TLW window we need to
1162 // recursively propagate the change of the state to its children, otherwise
1163 // they would still show as enabled even though they wouldn't actually
1164 // accept any input (at least under MSW where children don't accept input
1165 // if any of the windows in their parent chain is enabled).
1166 #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
1167 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1169 node
= node
->GetNext() )
1171 wxWindowBase
* const child
= node
->GetData();
1172 if ( !child
->IsTopLevel() && child
->IsThisEnabled() )
1173 child
->NotifyWindowOnEnableChange(enabled
);
1175 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
1178 bool wxWindowBase::Enable(bool enable
)
1180 if ( enable
== IsThisEnabled() )
1183 m_isEnabled
= enable
;
1185 // If we call DoEnable() from NotifyWindowOnEnableChange(), we don't need
1186 // to do it from here.
1187 #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
1189 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
1191 NotifyWindowOnEnableChange(enable
);
1196 bool wxWindowBase::IsShownOnScreen() const
1198 // A window is shown on screen if it itself is shown and so are all its
1199 // parents. But if a window is toplevel one, then its always visible on
1200 // screen if IsShown() returns true, even if it has a hidden parent.
1202 (IsTopLevel() || GetParent() == NULL
|| GetParent()->IsShownOnScreen());
1205 // ----------------------------------------------------------------------------
1207 // ----------------------------------------------------------------------------
1209 bool wxWindowBase::IsTopLevel() const
1214 // ----------------------------------------------------------------------------
1216 // ----------------------------------------------------------------------------
1218 void wxWindowBase::Freeze()
1220 if ( !m_freezeCount
++ )
1222 // physically freeze this window:
1225 // and recursively freeze all children:
1226 for ( wxWindowList::iterator i
= GetChildren().begin();
1227 i
!= GetChildren().end(); ++i
)
1229 wxWindow
*child
= *i
;
1230 if ( child
->IsTopLevel() )
1238 void wxWindowBase::Thaw()
1240 wxASSERT_MSG( m_freezeCount
, "Thaw() without matching Freeze()" );
1242 if ( !--m_freezeCount
)
1244 // recursively thaw all children:
1245 for ( wxWindowList::iterator i
= GetChildren().begin();
1246 i
!= GetChildren().end(); ++i
)
1248 wxWindow
*child
= *i
;
1249 if ( child
->IsTopLevel() )
1255 // physically thaw this window:
1260 // ----------------------------------------------------------------------------
1261 // Dealing with parents and children.
1262 // ----------------------------------------------------------------------------
1264 bool wxWindowBase::IsDescendant(wxWindowBase
* win
) const
1266 // Iterate until we find this window in the parent chain or exhaust it.
1272 // Stop iterating on reaching the top level window boundary.
1273 if ( win
->IsTopLevel() )
1276 win
= win
->GetParent();
1282 void wxWindowBase::AddChild(wxWindowBase
*child
)
1284 wxCHECK_RET( child
, wxT("can't add a NULL child") );
1286 // this should never happen and it will lead to a crash later if it does
1287 // because RemoveChild() will remove only one node from the children list
1288 // and the other(s) one(s) will be left with dangling pointers in them
1289 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), wxT("AddChild() called twice") );
1291 GetChildren().Append((wxWindow
*)child
);
1292 child
->SetParent(this);
1294 // adding a child while frozen will assert when thawed, so freeze it as if
1295 // it had been already present when we were frozen
1296 if ( IsFrozen() && !child
->IsTopLevel() )
1300 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
1302 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
1304 // removing a child while frozen may result in permanently frozen window
1305 // if used e.g. from Reparent(), so thaw it
1307 // NB: IsTopLevel() doesn't return true any more when a TLW child is being
1308 // removed from its ~wxWindowBase, so check for IsBeingDeleted() too
1309 if ( IsFrozen() && !child
->IsBeingDeleted() && !child
->IsTopLevel() )
1312 GetChildren().DeleteObject((wxWindow
*)child
);
1313 child
->SetParent(NULL
);
1316 void wxWindowBase::SetParent(wxWindowBase
*parent
)
1318 // This assert catches typos which may result in using "this" instead of
1319 // "parent" when creating the window. This doesn't happen often but when it
1320 // does the results are unpleasant because the program typically just
1321 // crashes when due to a stack overflow or something similar and this
1322 // assert doesn't cost much (OTOH doing a more general check that the
1323 // parent is not one of our children would be more expensive and probably
1325 wxASSERT_MSG( parent
!= this, wxS("Can't use window as its own parent") );
1327 m_parent
= (wxWindow
*)parent
;
1330 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
1332 wxWindow
*oldParent
= GetParent();
1333 if ( newParent
== oldParent
)
1339 const bool oldEnabledState
= IsEnabled();
1341 // unlink this window from the existing parent.
1344 oldParent
->RemoveChild(this);
1348 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
1351 // add it to the new one
1354 newParent
->AddChild(this);
1358 wxTopLevelWindows
.Append((wxWindow
*)this);
1361 // We need to notify window (and its subwindows) if by changing the parent
1362 // we also change our enabled/disabled status.
1363 const bool newEnabledState
= IsEnabled();
1364 if ( newEnabledState
!= oldEnabledState
)
1366 NotifyWindowOnEnableChange(newEnabledState
);
1372 // ----------------------------------------------------------------------------
1373 // event handler stuff
1374 // ----------------------------------------------------------------------------
1376 void wxWindowBase::SetEventHandler(wxEvtHandler
*handler
)
1378 wxCHECK_RET(handler
!= NULL
, "SetEventHandler(NULL) called");
1380 m_eventHandler
= handler
;
1383 void wxWindowBase::SetNextHandler(wxEvtHandler
*WXUNUSED(handler
))
1385 // disable wxEvtHandler chain mechanism for wxWindows:
1386 // wxWindow uses its own stack mechanism which doesn't mix well with wxEvtHandler's one
1388 wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
1390 void wxWindowBase::SetPreviousHandler(wxEvtHandler
*WXUNUSED(handler
))
1392 // we can't simply wxFAIL here as in SetNextHandler: in fact the last
1393 // handler of our stack when is destroyed will be Unlink()ed and thus
1394 // will call this function to update the pointer of this window...
1396 //wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
1399 void wxWindowBase::PushEventHandler(wxEvtHandler
*handlerToPush
)
1401 wxCHECK_RET( handlerToPush
!= NULL
, "PushEventHandler(NULL) called" );
1403 // the new handler is going to be part of the wxWindow stack of event handlers:
1404 // it can't be part also of an event handler double-linked chain:
1405 wxASSERT_MSG(handlerToPush
->IsUnlinked(),
1406 "The handler being pushed in the wxWindow stack shouldn't be part of "
1407 "a wxEvtHandler chain; call Unlink() on it first");
1409 wxEvtHandler
*handlerOld
= GetEventHandler();
1410 wxCHECK_RET( handlerOld
, "an old event handler is NULL?" );
1412 // now use wxEvtHandler double-linked list to implement a stack:
1413 handlerToPush
->SetNextHandler(handlerOld
);
1415 if (handlerOld
!= this)
1416 handlerOld
->SetPreviousHandler(handlerToPush
);
1418 SetEventHandler(handlerToPush
);
1421 // final checks of the operations done above:
1422 wxASSERT_MSG( handlerToPush
->GetPreviousHandler() == NULL
,
1423 "the first handler of the wxWindow stack should "
1424 "have no previous handlers set" );
1425 wxASSERT_MSG( handlerToPush
->GetNextHandler() != NULL
,
1426 "the first handler of the wxWindow stack should "
1427 "have non-NULL next handler" );
1429 wxEvtHandler
* pLast
= handlerToPush
;
1430 while ( pLast
&& pLast
!= this )
1431 pLast
= pLast
->GetNextHandler();
1432 wxASSERT_MSG( pLast
->GetNextHandler() == NULL
,
1433 "the last handler of the wxWindow stack should "
1434 "have this window as next handler" );
1435 #endif // wxDEBUG_LEVEL
1438 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
1440 // we need to pop the wxWindow stack, i.e. we need to remove the first handler
1442 wxEvtHandler
*firstHandler
= GetEventHandler();
1443 wxCHECK_MSG( firstHandler
!= NULL
, NULL
, "wxWindow cannot have a NULL event handler" );
1444 wxCHECK_MSG( firstHandler
!= this, NULL
, "cannot pop the wxWindow itself" );
1445 wxCHECK_MSG( firstHandler
->GetPreviousHandler() == NULL
, NULL
,
1446 "the first handler of the wxWindow stack should have no previous handlers set" );
1448 wxEvtHandler
*secondHandler
= firstHandler
->GetNextHandler();
1449 wxCHECK_MSG( secondHandler
!= NULL
, NULL
,
1450 "the first handler of the wxWindow stack should have non-NULL next handler" );
1452 firstHandler
->SetNextHandler(NULL
);
1454 // It is harmless but useless to unset the previous handler of the window
1455 // itself as it's always NULL anyhow, so don't do this.
1456 if ( secondHandler
!= this )
1457 secondHandler
->SetPreviousHandler(NULL
);
1459 // now firstHandler is completely unlinked; set secondHandler as the new window event handler
1460 SetEventHandler(secondHandler
);
1462 if ( deleteHandler
)
1464 wxDELETE(firstHandler
);
1467 return firstHandler
;
1470 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handlerToRemove
)
1472 wxCHECK_MSG( handlerToRemove
!= NULL
, false, "RemoveEventHandler(NULL) called" );
1473 wxCHECK_MSG( handlerToRemove
!= this, false, "Cannot remove the window itself" );
1475 if (handlerToRemove
== GetEventHandler())
1477 // removing the first event handler is equivalent to "popping" the stack
1478 PopEventHandler(false);
1482 // NOTE: the wxWindow event handler list is always terminated with "this" handler
1483 wxEvtHandler
*handlerCur
= GetEventHandler()->GetNextHandler();
1484 while ( handlerCur
!= this && handlerCur
)
1486 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
1488 if ( handlerCur
== handlerToRemove
)
1490 handlerCur
->Unlink();
1492 wxASSERT_MSG( handlerCur
!= GetEventHandler(),
1493 "the case Remove == Pop should was already handled" );
1497 handlerCur
= handlerNext
;
1500 wxFAIL_MSG( wxT("where has the event handler gone?") );
1505 bool wxWindowBase::HandleWindowEvent(wxEvent
& event
) const
1507 // SafelyProcessEvent() will handle exceptions nicely
1508 return GetEventHandler()->SafelyProcessEvent(event
);
1511 // ----------------------------------------------------------------------------
1512 // colours, fonts &c
1513 // ----------------------------------------------------------------------------
1515 void wxWindowBase::InheritAttributes()
1517 const wxWindowBase
* const parent
= GetParent();
1521 // we only inherit attributes which had been explicitly set for the parent
1522 // which ensures that this only happens if the user really wants it and
1523 // not by default which wouldn't make any sense in modern GUIs where the
1524 // controls don't all use the same fonts (nor colours)
1525 if ( parent
->m_inheritFont
&& !m_hasFont
)
1526 SetFont(parent
->GetFont());
1528 // in addition, there is a possibility to explicitly forbid inheriting
1529 // colours at each class level by overriding ShouldInheritColours()
1530 if ( ShouldInheritColours() )
1532 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1533 SetForegroundColour(parent
->GetForegroundColour());
1535 // inheriting (solid) background colour is wrong as it totally breaks
1536 // any kind of themed backgrounds
1538 // instead, the controls should use the same background as their parent
1539 // (ideally by not drawing it at all)
1541 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1542 SetBackgroundColour(parent
->GetBackgroundColour());
1547 /* static */ wxVisualAttributes
1548 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1550 // it is important to return valid values for all attributes from here,
1551 // GetXXX() below rely on this
1552 wxVisualAttributes attrs
;
1553 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1554 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1556 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1557 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1558 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1559 // colour on other platforms.
1561 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1562 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1564 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1569 wxColour
wxWindowBase::GetBackgroundColour() const
1571 if ( !m_backgroundColour
.IsOk() )
1573 wxASSERT_MSG( !m_hasBgCol
, wxT("we have invalid explicit bg colour?") );
1575 // get our default background colour
1576 wxColour colBg
= GetDefaultAttributes().colBg
;
1578 // we must return some valid colour to avoid redoing this every time
1579 // and also to avoid surprising the applications written for older
1580 // wxWidgets versions where GetBackgroundColour() always returned
1581 // something -- so give them something even if it doesn't make sense
1582 // for this window (e.g. it has a themed background)
1583 if ( !colBg
.IsOk() )
1584 colBg
= GetClassDefaultAttributes().colBg
;
1589 return m_backgroundColour
;
1592 wxColour
wxWindowBase::GetForegroundColour() const
1594 // logic is the same as above
1595 if ( !m_hasFgCol
&& !m_foregroundColour
.IsOk() )
1597 wxColour colFg
= GetDefaultAttributes().colFg
;
1599 if ( !colFg
.IsOk() )
1600 colFg
= GetClassDefaultAttributes().colFg
;
1605 return m_foregroundColour
;
1608 bool wxWindowBase::SetBackgroundStyle(wxBackgroundStyle style
)
1610 // The checks below shouldn't be triggered if we're not really changing the
1612 if ( style
== m_backgroundStyle
)
1615 // Transparent background style can be only set before creation because of
1616 // wxGTK limitation.
1617 wxCHECK_MSG( (style
!= wxBG_STYLE_TRANSPARENT
) || !GetHandle(),
1619 "wxBG_STYLE_TRANSPARENT style can only be set before "
1620 "Create()-ing the window." );
1622 // And once it is set, wxBG_STYLE_TRANSPARENT can't be unset.
1623 wxCHECK_MSG( (m_backgroundStyle
!= wxBG_STYLE_TRANSPARENT
) ||
1624 (style
== wxBG_STYLE_TRANSPARENT
),
1626 "wxBG_STYLE_TRANSPARENT can't be unset once it was set." );
1628 m_backgroundStyle
= style
;
1633 bool wxWindowBase::IsTransparentBackgroundSupported(wxString
*reason
) const
1636 *reason
= _("This platform does not support background transparency.");
1641 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1643 if ( colour
== m_backgroundColour
)
1646 m_hasBgCol
= colour
.IsOk();
1648 m_inheritBgCol
= m_hasBgCol
;
1649 m_backgroundColour
= colour
;
1650 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.IsOk() );
1654 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1656 if (colour
== m_foregroundColour
)
1659 m_hasFgCol
= colour
.IsOk();
1660 m_inheritFgCol
= m_hasFgCol
;
1661 m_foregroundColour
= colour
;
1662 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.IsOk() );
1666 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1668 // setting an invalid cursor is ok, it means that we don't have any special
1670 if ( m_cursor
.IsSameAs(cursor
) )
1681 wxFont
wxWindowBase::GetFont() const
1683 // logic is the same as in GetBackgroundColour()
1684 if ( !m_font
.IsOk() )
1686 wxASSERT_MSG( !m_hasFont
, wxT("we have invalid explicit font?") );
1688 wxFont font
= GetDefaultAttributes().font
;
1690 font
= GetClassDefaultAttributes().font
;
1698 bool wxWindowBase::SetFont(const wxFont
& font
)
1700 if ( font
== m_font
)
1707 m_hasFont
= font
.IsOk();
1708 m_inheritFont
= m_hasFont
;
1710 InvalidateBestSize();
1717 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1719 m_hasCustomPalette
= true;
1722 // VZ: can anyone explain me what do we do here?
1723 wxWindowDC
d((wxWindow
*) this);
1727 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1729 wxWindow
*win
= (wxWindow
*)this;
1730 while ( win
&& !win
->HasCustomPalette() )
1732 win
= win
->GetParent();
1738 #endif // wxUSE_PALETTE
1741 void wxWindowBase::SetCaret(wxCaret
*caret
)
1752 wxASSERT_MSG( m_caret
->GetWindow() == this,
1753 wxT("caret should be created associated to this window") );
1756 #endif // wxUSE_CARET
1758 #if wxUSE_VALIDATORS
1759 // ----------------------------------------------------------------------------
1761 // ----------------------------------------------------------------------------
1763 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1765 if ( m_windowValidator
)
1766 delete m_windowValidator
;
1768 m_windowValidator
= (wxValidator
*)validator
.Clone();
1770 if ( m_windowValidator
)
1771 m_windowValidator
->SetWindow(this);
1773 #endif // wxUSE_VALIDATORS
1775 // ----------------------------------------------------------------------------
1776 // update region stuff
1777 // ----------------------------------------------------------------------------
1779 wxRect
wxWindowBase::GetUpdateClientRect() const
1781 wxRegion rgnUpdate
= GetUpdateRegion();
1782 rgnUpdate
.Intersect(GetClientRect());
1783 wxRect rectUpdate
= rgnUpdate
.GetBox();
1784 wxPoint ptOrigin
= GetClientAreaOrigin();
1785 rectUpdate
.x
-= ptOrigin
.x
;
1786 rectUpdate
.y
-= ptOrigin
.y
;
1791 bool wxWindowBase::DoIsExposed(int x
, int y
) const
1793 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1796 bool wxWindowBase::DoIsExposed(int x
, int y
, int w
, int h
) const
1798 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1801 void wxWindowBase::ClearBackground()
1803 // wxGTK uses its own version, no need to add never used code
1805 wxClientDC
dc((wxWindow
*)this);
1806 wxBrush
brush(GetBackgroundColour(), wxBRUSHSTYLE_SOLID
);
1807 dc
.SetBackground(brush
);
1812 // ----------------------------------------------------------------------------
1813 // find child window by id or name
1814 // ----------------------------------------------------------------------------
1816 wxWindow
*wxWindowBase::FindWindow(long id
) const
1818 if ( id
== m_windowId
)
1819 return (wxWindow
*)this;
1821 wxWindowBase
*res
= NULL
;
1822 wxWindowList::compatibility_iterator node
;
1823 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1825 wxWindowBase
*child
= node
->GetData();
1826 res
= child
->FindWindow( id
);
1829 return (wxWindow
*)res
;
1832 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1834 if ( name
== m_windowName
)
1835 return (wxWindow
*)this;
1837 wxWindowBase
*res
= NULL
;
1838 wxWindowList::compatibility_iterator node
;
1839 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1841 wxWindow
*child
= node
->GetData();
1842 res
= child
->FindWindow(name
);
1845 return (wxWindow
*)res
;
1849 // find any window by id or name or label: If parent is non-NULL, look through
1850 // children for a label or title matching the specified string. If NULL, look
1851 // through all top-level windows.
1853 // to avoid duplicating code we reuse the same helper function but with
1854 // different comparators
1856 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1857 const wxString
& label
, long id
);
1860 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1863 return win
->GetLabel() == label
;
1867 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1870 return win
->GetName() == label
;
1874 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1877 return win
->GetId() == id
;
1880 // recursive helper for the FindWindowByXXX() functions
1882 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1883 const wxString
& label
,
1885 wxFindWindowCmp cmp
)
1889 // see if this is the one we're looking for
1890 if ( (*cmp
)(parent
, label
, id
) )
1891 return (wxWindow
*)parent
;
1893 // It wasn't, so check all its children
1894 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1896 node
= node
->GetNext() )
1898 // recursively check each child
1899 wxWindow
*win
= (wxWindow
*)node
->GetData();
1900 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1910 // helper for FindWindowByXXX()
1912 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1913 const wxString
& label
,
1915 wxFindWindowCmp cmp
)
1919 // just check parent and all its children
1920 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1923 // start at very top of wx's windows
1924 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1926 node
= node
->GetNext() )
1928 // recursively check each window & its children
1929 wxWindow
*win
= node
->GetData();
1930 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1940 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1942 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1947 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1949 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1953 // fall back to the label
1954 win
= FindWindowByLabel(title
, parent
);
1962 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1964 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1967 // ----------------------------------------------------------------------------
1968 // dialog oriented functions
1969 // ----------------------------------------------------------------------------
1971 #if WXWIN_COMPATIBILITY_2_8
1972 void wxWindowBase::MakeModal(bool modal
)
1974 // Disable all other windows
1977 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1980 wxWindow
*win
= node
->GetData();
1982 win
->Enable(!modal
);
1984 node
= node
->GetNext();
1988 #endif // WXWIN_COMPATIBILITY_2_8
1990 #if wxUSE_VALIDATORS
1995 // This class encapsulates possibly recursive iteration on window children done
1996 // by Validate() and TransferData{To,From}Window() and allows to avoid code
1997 // duplication in all three functions.
1998 class ValidationTraverserBase
2001 wxEXPLICIT
ValidationTraverserBase(wxWindowBase
* win
)
2002 : m_win(static_cast<wxWindow
*>(win
))
2006 // Traverse all the direct children calling OnDo() on them and also all
2007 // grandchildren if wxWS_EX_VALIDATE_RECURSIVELY is used, calling
2008 // OnRecurse() for them.
2009 bool DoForAllChildren()
2011 const bool recurse
= m_win
->HasExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY
);
2013 wxWindowList
& children
= m_win
->GetChildren();
2014 for ( wxWindowList::iterator i
= children
.begin();
2015 i
!= children
.end();
2018 wxWindow
* const child
= static_cast<wxWindow
*>(*i
);
2019 wxValidator
* const validator
= child
->GetValidator();
2020 if ( validator
&& !OnDo(validator
) )
2025 // Notice that validation should never recurse into top level
2026 // children, e.g. some other dialog which might happen to be
2028 if ( recurse
&& !child
->IsTopLevel() && !OnRecurse(child
) )
2037 // Give it a virtual dtor just to suppress gcc warnings about a class with
2038 // virtual methods but non-virtual dtor -- even if this is completely safe
2039 // here as we never use the objects of this class polymorphically.
2040 virtual ~ValidationTraverserBase() { }
2043 // Called for each child, validator is guaranteed to be non-NULL.
2044 virtual bool OnDo(wxValidator
* validator
) = 0;
2046 // Called for each child if we need to recurse into its children.
2047 virtual bool OnRecurse(wxWindow
* child
) = 0;
2050 // The window whose children we're traversing.
2051 wxWindow
* const m_win
;
2053 wxDECLARE_NO_COPY_CLASS(ValidationTraverserBase
);
2056 } // anonymous namespace
2058 #endif // wxUSE_VALIDATORS
2060 bool wxWindowBase::Validate()
2062 #if wxUSE_VALIDATORS
2063 class ValidateTraverser
: public ValidationTraverserBase
2066 wxEXPLICIT
ValidateTraverser(wxWindowBase
* win
)
2067 : ValidationTraverserBase(win
)
2071 virtual bool OnDo(wxValidator
* validator
)
2073 return validator
->Validate(m_win
);
2076 virtual bool OnRecurse(wxWindow
* child
)
2078 return child
->Validate();
2082 return ValidateTraverser(this).DoForAllChildren();
2083 #else // !wxUSE_VALIDATORS
2085 #endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS
2088 bool wxWindowBase::TransferDataToWindow()
2090 #if wxUSE_VALIDATORS
2091 class DataToWindowTraverser
: public ValidationTraverserBase
2094 wxEXPLICIT
DataToWindowTraverser(wxWindowBase
* win
)
2095 : ValidationTraverserBase(win
)
2099 virtual bool OnDo(wxValidator
* validator
)
2101 if ( !validator
->TransferToWindow() )
2103 wxLogWarning(_("Could not transfer data to window"));
2105 wxLog::FlushActive();
2114 virtual bool OnRecurse(wxWindow
* child
)
2116 return child
->TransferDataToWindow();
2120 return DataToWindowTraverser(this).DoForAllChildren();
2121 #else // !wxUSE_VALIDATORS
2123 #endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS
2126 bool wxWindowBase::TransferDataFromWindow()
2128 #if wxUSE_VALIDATORS
2129 class DataFromWindowTraverser
: public ValidationTraverserBase
2132 DataFromWindowTraverser(wxWindowBase
* win
)
2133 : ValidationTraverserBase(win
)
2137 virtual bool OnDo(wxValidator
* validator
)
2139 return validator
->TransferFromWindow();
2142 virtual bool OnRecurse(wxWindow
* child
)
2144 return child
->TransferDataFromWindow();
2148 return DataFromWindowTraverser(this).DoForAllChildren();
2149 #else // !wxUSE_VALIDATORS
2151 #endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS
2154 void wxWindowBase::InitDialog()
2156 wxInitDialogEvent
event(GetId());
2157 event
.SetEventObject( this );
2158 GetEventHandler()->ProcessEvent(event
);
2161 // ----------------------------------------------------------------------------
2162 // context-sensitive help support
2163 // ----------------------------------------------------------------------------
2167 // associate this help text with this window
2168 void wxWindowBase::SetHelpText(const wxString
& text
)
2170 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
2173 helpProvider
->AddHelp(this, text
);
2177 #if WXWIN_COMPATIBILITY_2_8
2178 // associate this help text with all windows with the same id as this
2180 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
2182 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
2185 helpProvider
->AddHelp(GetId(), text
);
2188 #endif // WXWIN_COMPATIBILITY_2_8
2190 // get the help string associated with this window (may be empty)
2191 // default implementation forwards calls to the help provider
2193 wxWindowBase::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
2194 wxHelpEvent::Origin
WXUNUSED(origin
)) const
2197 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
2200 text
= helpProvider
->GetHelp(this);
2206 // show help for this window
2207 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
2209 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
2212 wxPoint pos
= event
.GetPosition();
2213 const wxHelpEvent::Origin origin
= event
.GetOrigin();
2214 if ( origin
== wxHelpEvent::Origin_Keyboard
)
2216 // if the help event was generated from keyboard it shouldn't
2217 // appear at the mouse position (which is still the only position
2218 // associated with help event) if the mouse is far away, although
2219 // we still do use the mouse position if it's over the window
2220 // because we suppose the user looks approximately at the mouse
2221 // already and so it would be more convenient than showing tooltip
2222 // at some arbitrary position which can be quite far from it
2223 const wxRect rectClient
= GetClientRect();
2224 if ( !rectClient
.Contains(ScreenToClient(pos
)) )
2226 // position help slightly under and to the right of this window
2227 pos
= ClientToScreen(wxPoint(
2229 rectClient
.height
+ GetCharHeight()
2234 if ( helpProvider
->ShowHelpAtPoint(this, pos
, origin
) )
2236 // skip the event.Skip() below
2244 #endif // wxUSE_HELP
2246 // ----------------------------------------------------------------------------
2248 // ----------------------------------------------------------------------------
2252 wxString
wxWindowBase::GetToolTipText() const
2254 return m_tooltip
? m_tooltip
->GetTip() : wxString();
2257 void wxWindowBase::SetToolTip( const wxString
&tip
)
2259 // don't create the new tooltip if we already have one
2262 m_tooltip
->SetTip( tip
);
2266 SetToolTip( new wxToolTip( tip
) );
2269 // setting empty tooltip text does not remove the tooltip any more - use
2270 // SetToolTip(NULL) for this
2273 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
2275 if ( m_tooltip
!= tooltip
)
2280 m_tooltip
= tooltip
;
2284 bool wxWindowBase::CopyToolTip(wxToolTip
*tip
)
2286 SetToolTip(tip
? new wxToolTip(tip
->GetTip()) : NULL
);
2291 #endif // wxUSE_TOOLTIPS
2293 // ----------------------------------------------------------------------------
2294 // constraints and sizers
2295 // ----------------------------------------------------------------------------
2297 #if wxUSE_CONSTRAINTS
2299 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
2301 if ( m_constraints
)
2303 UnsetConstraints(m_constraints
);
2304 delete m_constraints
;
2306 m_constraints
= constraints
;
2307 if ( m_constraints
)
2309 // Make sure other windows know they're part of a 'meaningful relationship'
2310 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
2311 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
2312 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
2313 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
2314 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
2315 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
2316 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
2317 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
2318 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
2319 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
2320 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
2321 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
2322 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
2323 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
2324 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
2325 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
2329 // This removes any dangling pointers to this window in other windows'
2330 // constraintsInvolvedIn lists.
2331 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
2335 if ( c
->left
.GetOtherWindow() && (c
->left
.GetOtherWindow() != this) )
2336 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
2337 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
2338 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
2339 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
2340 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
2341 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
2342 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
2343 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
2344 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
2345 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
2346 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
2347 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
2348 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
2349 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
2350 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
2354 // Back-pointer to other windows we're involved with, so if we delete this
2355 // window, we must delete any constraints we're involved with.
2356 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
2358 if ( !m_constraintsInvolvedIn
)
2359 m_constraintsInvolvedIn
= new wxWindowList
;
2360 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
2361 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
2364 // REMOVE back-pointer to other windows we're involved with.
2365 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
2367 if ( m_constraintsInvolvedIn
)
2368 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
2371 // Reset any constraints that mention this window
2372 void wxWindowBase::DeleteRelatedConstraints()
2374 if ( m_constraintsInvolvedIn
)
2376 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
2379 wxWindow
*win
= node
->GetData();
2380 wxLayoutConstraints
*constr
= win
->GetConstraints();
2382 // Reset any constraints involving this window
2385 constr
->left
.ResetIfWin(this);
2386 constr
->top
.ResetIfWin(this);
2387 constr
->right
.ResetIfWin(this);
2388 constr
->bottom
.ResetIfWin(this);
2389 constr
->width
.ResetIfWin(this);
2390 constr
->height
.ResetIfWin(this);
2391 constr
->centreX
.ResetIfWin(this);
2392 constr
->centreY
.ResetIfWin(this);
2395 wxWindowList::compatibility_iterator next
= node
->GetNext();
2396 m_constraintsInvolvedIn
->Erase(node
);
2400 wxDELETE(m_constraintsInvolvedIn
);
2404 #endif // wxUSE_CONSTRAINTS
2406 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
2408 if ( sizer
== m_windowSizer
)
2411 if ( m_windowSizer
)
2413 m_windowSizer
->SetContainingWindow(NULL
);
2416 delete m_windowSizer
;
2419 m_windowSizer
= sizer
;
2420 if ( m_windowSizer
)
2422 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
2425 SetAutoLayout(m_windowSizer
!= NULL
);
2428 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
2430 SetSizer( sizer
, deleteOld
);
2431 sizer
->SetSizeHints( (wxWindow
*) this );
2435 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
2437 // adding a window to a sizer twice is going to result in fatal and
2438 // hard to debug problems later because when deleting the second
2439 // associated wxSizerItem we're going to dereference a dangling
2440 // pointer; so try to detect this as early as possible
2441 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
2442 wxT("Adding a window to the same sizer twice?") );
2444 m_containingSizer
= sizer
;
2447 #if wxUSE_CONSTRAINTS
2449 void wxWindowBase::SatisfyConstraints()
2451 wxLayoutConstraints
*constr
= GetConstraints();
2452 bool wasOk
= constr
&& constr
->AreSatisfied();
2454 ResetConstraints(); // Mark all constraints as unevaluated
2458 // if we're a top level panel (i.e. our parent is frame/dialog), our
2459 // own constraints will never be satisfied any more unless we do it
2463 while ( noChanges
> 0 )
2465 LayoutPhase1(&noChanges
);
2469 LayoutPhase2(&noChanges
);
2472 #endif // wxUSE_CONSTRAINTS
2474 bool wxWindowBase::Layout()
2476 // If there is a sizer, use it instead of the constraints
2480 GetVirtualSize(&w
, &h
);
2481 GetSizer()->SetDimension( 0, 0, w
, h
);
2483 #if wxUSE_CONSTRAINTS
2486 SatisfyConstraints(); // Find the right constraints values
2487 SetConstraintSizes(); // Recursively set the real window sizes
2494 void wxWindowBase::InternalOnSize(wxSizeEvent
& event
)
2496 if ( GetAutoLayout() )
2502 #if wxUSE_CONSTRAINTS
2504 // first phase of the constraints evaluation: set our own constraints
2505 bool wxWindowBase::LayoutPhase1(int *noChanges
)
2507 wxLayoutConstraints
*constr
= GetConstraints();
2509 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
2512 // second phase: set the constraints for our children
2513 bool wxWindowBase::LayoutPhase2(int *noChanges
)
2520 // Layout grand children
2526 // Do a phase of evaluating child constraints
2527 bool wxWindowBase::DoPhase(int phase
)
2529 // the list containing the children for which the constraints are already
2531 wxWindowList succeeded
;
2533 // the max number of iterations we loop before concluding that we can't set
2535 static const int maxIterations
= 500;
2537 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
2541 // loop over all children setting their constraints
2542 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2544 node
= node
->GetNext() )
2546 wxWindow
*child
= node
->GetData();
2547 if ( child
->IsTopLevel() )
2549 // top level children are not inside our client area
2553 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
2555 // this one is either already ok or nothing we can do about it
2559 int tempNoChanges
= 0;
2560 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
2561 : child
->LayoutPhase2(&tempNoChanges
);
2562 noChanges
+= tempNoChanges
;
2566 succeeded
.Append(child
);
2572 // constraints are set
2580 void wxWindowBase::ResetConstraints()
2582 wxLayoutConstraints
*constr
= GetConstraints();
2585 constr
->left
.SetDone(false);
2586 constr
->top
.SetDone(false);
2587 constr
->right
.SetDone(false);
2588 constr
->bottom
.SetDone(false);
2589 constr
->width
.SetDone(false);
2590 constr
->height
.SetDone(false);
2591 constr
->centreX
.SetDone(false);
2592 constr
->centreY
.SetDone(false);
2595 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2598 wxWindow
*win
= node
->GetData();
2599 if ( !win
->IsTopLevel() )
2600 win
->ResetConstraints();
2601 node
= node
->GetNext();
2605 // Need to distinguish between setting the 'fake' size for windows and sizers,
2606 // and setting the real values.
2607 void wxWindowBase::SetConstraintSizes(bool recurse
)
2609 wxLayoutConstraints
*constr
= GetConstraints();
2610 if ( constr
&& constr
->AreSatisfied() )
2612 ChildrenRepositioningGuard
repositionGuard(this);
2614 int x
= constr
->left
.GetValue();
2615 int y
= constr
->top
.GetValue();
2616 int w
= constr
->width
.GetValue();
2617 int h
= constr
->height
.GetValue();
2619 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
2620 (constr
->height
.GetRelationship() != wxAsIs
) )
2622 // We really shouldn't set negative sizes for the windows so make
2623 // them at least of 1*1 size
2624 SetSize(x
, y
, w
> 0 ? w
: 1, h
> 0 ? h
: 1);
2628 // If we don't want to resize this window, just move it...
2634 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
2635 GetClassInfo()->GetClassName(),
2641 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2644 wxWindow
*win
= node
->GetData();
2645 if ( !win
->IsTopLevel() && win
->GetConstraints() )
2646 win
->SetConstraintSizes();
2647 node
= node
->GetNext();
2652 // Only set the size/position of the constraint (if any)
2653 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
2655 wxLayoutConstraints
*constr
= GetConstraints();
2658 if ( x
!= wxDefaultCoord
)
2660 constr
->left
.SetValue(x
);
2661 constr
->left
.SetDone(true);
2663 if ( y
!= wxDefaultCoord
)
2665 constr
->top
.SetValue(y
);
2666 constr
->top
.SetDone(true);
2668 if ( w
!= wxDefaultCoord
)
2670 constr
->width
.SetValue(w
);
2671 constr
->width
.SetDone(true);
2673 if ( h
!= wxDefaultCoord
)
2675 constr
->height
.SetValue(h
);
2676 constr
->height
.SetDone(true);
2681 void wxWindowBase::MoveConstraint(int x
, int y
)
2683 wxLayoutConstraints
*constr
= GetConstraints();
2686 if ( x
!= wxDefaultCoord
)
2688 constr
->left
.SetValue(x
);
2689 constr
->left
.SetDone(true);
2691 if ( y
!= wxDefaultCoord
)
2693 constr
->top
.SetValue(y
);
2694 constr
->top
.SetDone(true);
2699 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2701 wxLayoutConstraints
*constr
= GetConstraints();
2704 *w
= constr
->width
.GetValue();
2705 *h
= constr
->height
.GetValue();
2711 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2713 wxLayoutConstraints
*constr
= GetConstraints();
2716 *w
= constr
->width
.GetValue();
2717 *h
= constr
->height
.GetValue();
2720 GetClientSize(w
, h
);
2723 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2725 wxLayoutConstraints
*constr
= GetConstraints();
2728 *x
= constr
->left
.GetValue();
2729 *y
= constr
->top
.GetValue();
2735 #endif // wxUSE_CONSTRAINTS
2737 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2739 wxWindow
*parent
= GetParent();
2740 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2742 wxPoint
pt(parent
->GetClientAreaOrigin());
2748 // ----------------------------------------------------------------------------
2749 // Update UI processing
2750 // ----------------------------------------------------------------------------
2752 void wxWindowBase::UpdateWindowUI(long flags
)
2754 wxUpdateUIEvent
event(GetId());
2755 event
.SetEventObject(this);
2757 if ( GetEventHandler()->ProcessEvent(event
) )
2759 DoUpdateWindowUI(event
);
2762 if (flags
& wxUPDATE_UI_RECURSE
)
2764 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2767 wxWindow
* child
= (wxWindow
*) node
->GetData();
2768 child
->UpdateWindowUI(flags
);
2769 node
= node
->GetNext();
2774 // do the window-specific processing after processing the update event
2775 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2777 if ( event
.GetSetEnabled() )
2778 Enable(event
.GetEnabled());
2780 if ( event
.GetSetShown() )
2781 Show(event
.GetShown());
2784 // ----------------------------------------------------------------------------
2786 // ----------------------------------------------------------------------------
2788 // Send idle event to window and all subwindows
2789 bool wxWindowBase::SendIdleEvents(wxIdleEvent
& event
)
2791 bool needMore
= false;
2795 // should we send idle event to this window?
2796 if (wxIdleEvent::GetMode() == wxIDLE_PROCESS_ALL
||
2797 HasExtraStyle(wxWS_EX_PROCESS_IDLE
))
2799 event
.SetEventObject(this);
2800 HandleWindowEvent(event
);
2802 if (event
.MoreRequested())
2805 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2806 for (; node
; node
= node
->GetNext())
2808 wxWindow
* child
= node
->GetData();
2809 if (child
->SendIdleEvents(event
))
2816 void wxWindowBase::OnInternalIdle()
2818 if ( wxUpdateUIEvent::CanUpdate(this) )
2819 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2822 // ----------------------------------------------------------------------------
2823 // dialog units translations
2824 // ----------------------------------------------------------------------------
2826 // Windows' computes dialog units using average character width over upper-
2827 // and lower-case ASCII alphabet and not using the average character width
2828 // metadata stored in the font; see
2829 // http://support.microsoft.com/default.aspx/kb/145994 for detailed discussion.
2830 // It's important that we perform the conversion in identical way, because
2831 // dialog units natively exist only on Windows and Windows HIG is expressed
2833 wxSize
wxWindowBase::GetDlgUnitBase() const
2835 const wxWindowBase
* const parent
= wxGetTopLevelParent((wxWindow
*)this);
2837 wxCHECK_MSG( parent
, wxDefaultSize
, wxS("Must have TLW parent") );
2839 if ( !parent
->m_font
.IsOk() )
2841 // Default GUI font is used. This is the most common case, so
2842 // cache the results.
2843 static wxSize s_defFontSize
;
2844 if ( s_defFontSize
.x
== 0 )
2845 s_defFontSize
= wxPrivate::GetAverageASCIILetterSize(*parent
);
2846 return s_defFontSize
;
2850 // Custom font, we always need to compute the result
2851 return wxPrivate::GetAverageASCIILetterSize(*parent
);
2855 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
) const
2857 const wxSize base
= GetDlgUnitBase();
2859 // NB: wxMulDivInt32() is used, because it correctly rounds the result
2861 wxPoint pt2
= wxDefaultPosition
;
2862 if (pt
.x
!= wxDefaultCoord
)
2863 pt2
.x
= wxMulDivInt32(pt
.x
, 4, base
.x
);
2864 if (pt
.y
!= wxDefaultCoord
)
2865 pt2
.y
= wxMulDivInt32(pt
.y
, 8, base
.y
);
2870 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
) const
2872 const wxSize base
= GetDlgUnitBase();
2874 wxPoint pt2
= wxDefaultPosition
;
2875 if (pt
.x
!= wxDefaultCoord
)
2876 pt2
.x
= wxMulDivInt32(pt
.x
, base
.x
, 4);
2877 if (pt
.y
!= wxDefaultCoord
)
2878 pt2
.y
= wxMulDivInt32(pt
.y
, base
.y
, 8);
2883 // ----------------------------------------------------------------------------
2885 // ----------------------------------------------------------------------------
2887 // propagate the colour change event to the subwindows
2888 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
2890 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2893 // Only propagate to non-top-level windows
2894 wxWindow
*win
= node
->GetData();
2895 if ( !win
->IsTopLevel() )
2897 wxSysColourChangedEvent event2
;
2898 event2
.SetEventObject(win
);
2899 win
->GetEventHandler()->ProcessEvent(event2
);
2902 node
= node
->GetNext();
2908 // the default action is to populate dialog with data when it's created,
2909 // and nudge the UI into displaying itself correctly in case
2910 // we've turned the wxUpdateUIEvents frequency down low.
2911 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2913 TransferDataToWindow();
2915 // Update the UI at this point
2916 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2919 // ----------------------------------------------------------------------------
2920 // menu-related functions
2921 // ----------------------------------------------------------------------------
2925 bool wxWindowBase::PopupMenu(wxMenu
*menu
, int x
, int y
)
2927 wxCHECK_MSG( menu
, false, "can't popup NULL menu" );
2929 wxMenuInvokingWindowSetter
2930 setInvokingWin(*menu
, static_cast<wxWindow
*>(this));
2932 wxCurrentPopupMenu
= menu
;
2933 const bool rc
= DoPopupMenu(menu
, x
, y
);
2934 wxCurrentPopupMenu
= NULL
;
2939 // this is used to pass the id of the selected item from the menu event handler
2940 // to the main function itself
2942 // it's ok to use a global here as there can be at most one popup menu shown at
2944 static int gs_popupMenuSelection
= wxID_NONE
;
2946 void wxWindowBase::InternalOnPopupMenu(wxCommandEvent
& event
)
2948 // store the id in a global variable where we'll retrieve it from later
2949 gs_popupMenuSelection
= event
.GetId();
2952 void wxWindowBase::InternalOnPopupMenuUpdate(wxUpdateUIEvent
& WXUNUSED(event
))
2954 // nothing to do but do not skip it
2958 wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu
& menu
, int x
, int y
)
2960 gs_popupMenuSelection
= wxID_NONE
;
2963 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2967 // it is common to construct the menu passed to this function dynamically
2968 // using some fixed range of ids which could clash with the ids used
2969 // elsewhere in the program, which could result in some menu items being
2970 // unintentionally disabled or otherwise modified by update UI handlers
2971 // elsewhere in the program code and this is difficult to avoid in the
2972 // program itself, so instead we just temporarily suspend UI updating while
2973 // this menu is shown
2974 Connect(wxEVT_UPDATE_UI
,
2975 wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate
),
2979 PopupMenu(&menu
, x
, y
);
2981 Disconnect(wxEVT_UPDATE_UI
,
2982 wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate
),
2985 Disconnect(wxEVT_MENU
,
2986 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu
),
2990 return gs_popupMenuSelection
;
2993 #endif // wxUSE_MENUS
2995 // methods for drawing the sizers in a visible way: this is currently only
2996 // enabled for "full debug" builds with wxDEBUG_LEVEL==2 as it doesn't work
2997 // that well and also because we don't want to leave it enabled in default
2998 // builds used for production
2999 #if wxDEBUG_LEVEL > 1
3001 static void DrawSizers(wxWindowBase
*win
);
3003 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
, const wxPen
* pen
)
3005 wxClientDC
dc((wxWindow
*)win
);
3007 dc
.SetBrush(fill
? wxBrush(pen
->GetColour(), wxBRUSHSTYLE_CROSSDIAG_HATCH
) :
3008 *wxTRANSPARENT_BRUSH
);
3009 dc
.DrawRectangle(rect
.Deflate(1, 1));
3012 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
3014 const wxSizerItemList
& items
= sizer
->GetChildren();
3015 for ( wxSizerItemList::const_iterator i
= items
.begin(),
3020 wxSizerItem
*item
= *i
;
3021 if ( item
->IsSizer() )
3023 DrawBorder(win
, item
->GetRect().Deflate(2), false, wxRED_PEN
);
3024 DrawSizer(win
, item
->GetSizer());
3026 else if ( item
->IsSpacer() )
3028 DrawBorder(win
, item
->GetRect().Deflate(2), true, wxBLUE_PEN
);
3030 else if ( item
->IsWindow() )
3032 DrawSizers(item
->GetWindow());
3035 wxFAIL_MSG("inconsistent wxSizerItem status!");
3039 static void DrawSizers(wxWindowBase
*win
)
3041 DrawBorder(win
, win
->GetClientSize(), false, wxGREEN_PEN
);
3043 wxSizer
*sizer
= win
->GetSizer();
3046 DrawSizer(win
, sizer
);
3048 else // no sizer, still recurse into the children
3050 const wxWindowList
& children
= win
->GetChildren();
3051 for ( wxWindowList::const_iterator i
= children
.begin(),
3052 end
= children
.end();
3059 // show all kind of sizes of this window; see the "window sizing" topic
3060 // overview for more info about the various differences:
3061 wxSize fullSz
= win
->GetSize();
3062 wxSize clientSz
= win
->GetClientSize();
3063 wxSize bestSz
= win
->GetBestSize();
3064 wxSize minSz
= win
->GetMinSize();
3065 wxSize maxSz
= win
->GetMaxSize();
3066 wxSize virtualSz
= win
->GetVirtualSize();
3068 wxMessageOutputDebug dbgout
;
3070 "%-10s => fullsz=%4d;%-4d clientsz=%4d;%-4d bestsz=%4d;%-4d minsz=%4d;%-4d maxsz=%4d;%-4d virtualsz=%4d;%-4d\n",
3073 clientSz
.x
, clientSz
.y
,
3077 virtualSz
.x
, virtualSz
.y
);
3081 #endif // wxDEBUG_LEVEL
3083 // process special middle clicks
3084 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
3086 if ( event
.ControlDown() && event
.AltDown() )
3088 #if wxDEBUG_LEVEL > 1
3089 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
3090 if ( event
.ShiftDown() )
3095 #endif // __WXDEBUG__
3098 // just Ctrl-Alt-middle click shows information about wx version
3099 ::wxInfoMessageBox((wxWindow
*)this);
3100 #endif // wxUSE_MSGDLG
3109 // ----------------------------------------------------------------------------
3111 // ----------------------------------------------------------------------------
3113 #if wxUSE_ACCESSIBILITY
3114 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
3116 if (m_accessible
&& (accessible
!= m_accessible
))
3117 delete m_accessible
;
3118 m_accessible
= accessible
;
3120 m_accessible
->SetWindow((wxWindow
*) this);
3123 // Returns the accessible object, creating if necessary.
3124 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
3127 m_accessible
= CreateAccessible();
3128 return m_accessible
;
3131 // Override to create a specific accessible object.
3132 wxAccessible
* wxWindowBase::CreateAccessible()
3134 return new wxWindowAccessible((wxWindow
*) this);
3139 // ----------------------------------------------------------------------------
3140 // list classes implementation
3141 // ----------------------------------------------------------------------------
3143 #if wxUSE_STD_CONTAINERS
3145 #include "wx/listimpl.cpp"
3146 WX_DEFINE_LIST(wxWindowList
)
3148 #else // !wxUSE_STD_CONTAINERS
3150 void wxWindowListNode::DeleteData()
3152 delete (wxWindow
*)GetData();
3155 #endif // wxUSE_STD_CONTAINERS/!wxUSE_STD_CONTAINERS
3157 // ----------------------------------------------------------------------------
3159 // ----------------------------------------------------------------------------
3161 wxBorder
wxWindowBase::GetBorder(long flags
) const
3163 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
3164 if ( border
== wxBORDER_DEFAULT
)
3166 border
= GetDefaultBorder();
3168 else if ( border
== wxBORDER_THEME
)
3170 border
= GetDefaultBorderForControl();
3176 wxBorder
wxWindowBase::GetDefaultBorder() const
3178 return wxBORDER_NONE
;
3181 // ----------------------------------------------------------------------------
3183 // ----------------------------------------------------------------------------
3185 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
3187 // here we just check if the point is inside the window or not
3189 // check the top and left border first
3190 bool outside
= x
< 0 || y
< 0;
3193 // check the right and bottom borders too
3194 wxSize size
= GetSize();
3195 outside
= x
>= size
.x
|| y
>= size
.y
;
3198 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
3201 // ----------------------------------------------------------------------------
3203 // ----------------------------------------------------------------------------
3205 struct WXDLLEXPORT wxWindowNext
3209 } *wxWindowBase::ms_winCaptureNext
= NULL
;
3210 wxWindow
*wxWindowBase::ms_winCaptureCurrent
= NULL
;
3211 bool wxWindowBase::ms_winCaptureChanging
= false;
3213 void wxWindowBase::CaptureMouse()
3215 wxLogTrace(wxT("mousecapture"), wxT("CaptureMouse(%p)"), static_cast<void*>(this));
3217 wxASSERT_MSG( !ms_winCaptureChanging
, wxT("recursive CaptureMouse call?") );
3219 ms_winCaptureChanging
= true;
3221 wxWindow
*winOld
= GetCapture();
3224 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
3227 wxWindowNext
*item
= new wxWindowNext
;
3229 item
->next
= ms_winCaptureNext
;
3230 ms_winCaptureNext
= item
;
3232 //else: no mouse capture to save
3235 ms_winCaptureCurrent
= (wxWindow
*)this;
3237 ms_winCaptureChanging
= false;
3240 void wxWindowBase::ReleaseMouse()
3242 wxLogTrace(wxT("mousecapture"), wxT("ReleaseMouse(%p)"), static_cast<void*>(this));
3244 wxASSERT_MSG( !ms_winCaptureChanging
, wxT("recursive ReleaseMouse call?") );
3246 wxASSERT_MSG( GetCapture() == this,
3247 "attempt to release mouse, but this window hasn't captured it" );
3248 wxASSERT_MSG( ms_winCaptureCurrent
== this,
3249 "attempt to release mouse, but this window hasn't captured it" );
3251 ms_winCaptureChanging
= true;
3254 ms_winCaptureCurrent
= NULL
;
3256 if ( ms_winCaptureNext
)
3258 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
3259 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
3261 wxWindowNext
*item
= ms_winCaptureNext
;
3262 ms_winCaptureNext
= item
->next
;
3265 //else: stack is empty, no previous capture
3267 ms_winCaptureChanging
= false;
3269 wxLogTrace(wxT("mousecapture"),
3270 (const wxChar
*) wxT("After ReleaseMouse() mouse is captured by %p"),
3271 static_cast<void*>(GetCapture()));
3274 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
3276 wxMouseCaptureLostEvent
event(win
->GetId());
3277 event
.SetEventObject(win
);
3278 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
3280 // windows must handle this event, otherwise the app wouldn't behave
3281 // correctly if it loses capture unexpectedly; see the discussion here:
3282 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
3283 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
3284 wxFAIL_MSG( wxT("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
3289 void wxWindowBase::NotifyCaptureLost()
3291 // don't do anything if capture lost was expected, i.e. resulted from
3292 // a wx call to ReleaseMouse or CaptureMouse:
3293 if ( ms_winCaptureChanging
)
3296 // if the capture was lost unexpectedly, notify every window that has
3297 // capture (on stack or current) about it and clear the stack:
3299 if ( ms_winCaptureCurrent
)
3301 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
3302 ms_winCaptureCurrent
= NULL
;
3305 while ( ms_winCaptureNext
)
3307 wxWindowNext
*item
= ms_winCaptureNext
;
3308 ms_winCaptureNext
= item
->next
;
3310 DoNotifyWindowAboutCaptureLost(item
->win
);
3319 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
3320 int WXUNUSED(modifiers
),
3321 int WXUNUSED(keycode
))
3327 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
3333 #endif // wxUSE_HOTKEY
3335 // ----------------------------------------------------------------------------
3337 // ----------------------------------------------------------------------------
3339 bool wxWindowBase::TryBefore(wxEvent
& event
)
3341 #if wxUSE_VALIDATORS
3342 // Can only use the validator of the window which
3343 // is receiving the event
3344 if ( event
.GetEventObject() == this )
3346 wxValidator
* const validator
= GetValidator();
3347 if ( validator
&& validator
->ProcessEventLocally(event
) )
3352 #endif // wxUSE_VALIDATORS
3354 return wxEvtHandler::TryBefore(event
);
3357 bool wxWindowBase::TryAfter(wxEvent
& event
)
3359 // carry on up the parent-child hierarchy if the propagation count hasn't
3361 if ( event
.ShouldPropagate() )
3363 // honour the requests to stop propagation at this window: this is
3364 // used by the dialogs, for example, to prevent processing the events
3365 // from the dialog controls in the parent frame which rarely, if ever,
3367 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
3369 wxWindow
*parent
= GetParent();
3370 if ( parent
&& !parent
->IsBeingDeleted() )
3372 wxPropagateOnce
propagateOnce(event
, this);
3374 return parent
->GetEventHandler()->ProcessEvent(event
);
3379 return wxEvtHandler::TryAfter(event
);
3382 // ----------------------------------------------------------------------------
3383 // window relationships
3384 // ----------------------------------------------------------------------------
3386 wxWindow
*wxWindowBase::DoGetSibling(WindowOrder order
) const
3388 wxCHECK_MSG( GetParent(), NULL
,
3389 wxT("GetPrev/NextSibling() don't work for TLWs!") );
3391 wxWindowList
& siblings
= GetParent()->GetChildren();
3392 wxWindowList::compatibility_iterator i
= siblings
.Find((wxWindow
*)this);
3393 wxCHECK_MSG( i
, NULL
, wxT("window not a child of its parent?") );
3395 if ( order
== OrderBefore
)
3396 i
= i
->GetPrevious();
3400 return i
? i
->GetData() : NULL
;
3403 // ----------------------------------------------------------------------------
3404 // keyboard navigation
3405 // ----------------------------------------------------------------------------
3407 // Navigates in the specified direction inside this window
3408 bool wxWindowBase::DoNavigateIn(int flags
)
3410 #ifdef wxHAS_NATIVE_TAB_TRAVERSAL
3411 // native code doesn't process our wxNavigationKeyEvents anyhow
3414 #else // !wxHAS_NATIVE_TAB_TRAVERSAL
3415 wxNavigationKeyEvent eventNav
;
3416 wxWindow
*focused
= FindFocus();
3417 eventNav
.SetCurrentFocus(focused
);
3418 eventNav
.SetEventObject(focused
);
3419 eventNav
.SetFlags(flags
);
3420 return GetEventHandler()->ProcessEvent(eventNav
);
3421 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
3424 bool wxWindowBase::HandleAsNavigationKey(const wxKeyEvent
& event
)
3426 if ( event
.GetKeyCode() != WXK_TAB
)
3429 int flags
= wxNavigationKeyEvent::FromTab
;
3431 if ( event
.ShiftDown() )
3432 flags
|= wxNavigationKeyEvent::IsBackward
;
3434 flags
|= wxNavigationKeyEvent::IsForward
;
3436 if ( event
.ControlDown() )
3437 flags
|= wxNavigationKeyEvent::WinChange
;
3443 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, WindowOrder move
)
3445 // check that we're not a top level window
3446 wxCHECK_RET( GetParent(),
3447 wxT("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
3449 // detect the special case when we have nothing to do anyhow and when the
3450 // code below wouldn't work
3454 // find the target window in the siblings list
3455 wxWindowList
& siblings
= GetParent()->GetChildren();
3456 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
3457 wxCHECK_RET( i
, wxT("MoveBefore/AfterInTabOrder(): win is not a sibling") );
3459 // unfortunately, when wxUSE_STD_CONTAINERS == 1 DetachNode() is not
3460 // implemented so we can't just move the node around
3461 wxWindow
*self
= (wxWindow
*)this;
3462 siblings
.DeleteObject(self
);
3463 if ( move
== OrderAfter
)
3470 siblings
.Insert(i
, self
);
3472 else // OrderAfter and win was the last sibling
3474 siblings
.Append(self
);
3478 // ----------------------------------------------------------------------------
3480 // ----------------------------------------------------------------------------
3482 /*static*/ wxWindow
* wxWindowBase::FindFocus()
3484 wxWindowBase
*win
= DoFindFocus();
3485 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
3488 bool wxWindowBase::HasFocus() const
3490 wxWindowBase
* const win
= DoFindFocus();
3492 (this == win
|| this == win
->GetMainWindowOfCompositeControl());
3495 // ----------------------------------------------------------------------------
3497 // ----------------------------------------------------------------------------
3499 #if wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
3504 class DragAcceptFilesTarget
: public wxFileDropTarget
3507 DragAcceptFilesTarget(wxWindowBase
*win
) : m_win(win
) {}
3509 virtual bool OnDropFiles(wxCoord x
, wxCoord y
,
3510 const wxArrayString
& filenames
)
3512 wxDropFilesEvent
event(wxEVT_DROP_FILES
,
3514 wxCArrayString(filenames
).Release());
3515 event
.SetEventObject(m_win
);
3519 return m_win
->HandleWindowEvent(event
);
3523 wxWindowBase
* const m_win
;
3525 wxDECLARE_NO_COPY_CLASS(DragAcceptFilesTarget
);
3529 } // anonymous namespace
3531 // Generic version of DragAcceptFiles(). It works by installing a simple
3532 // wxFileDropTarget-to-EVT_DROP_FILES adaptor and therefore cannot be used
3533 // together with explicit SetDropTarget() calls.
3534 void wxWindowBase::DragAcceptFiles(bool accept
)
3538 wxASSERT_MSG( !GetDropTarget(),
3539 "cannot use DragAcceptFiles() and SetDropTarget() together" );
3540 SetDropTarget(new DragAcceptFilesTarget(this));
3544 SetDropTarget(NULL
);
3548 #endif // wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
3550 // ----------------------------------------------------------------------------
3552 // ----------------------------------------------------------------------------
3554 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
3556 while ( win
&& !win
->IsTopLevel() )
3557 win
= win
->GetParent();
3562 #if wxUSE_ACCESSIBILITY
3563 // ----------------------------------------------------------------------------
3564 // accessible object for windows
3565 // ----------------------------------------------------------------------------
3567 // Can return either a child object, or an integer
3568 // representing the child element, starting from 1.
3569 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
3571 wxASSERT( GetWindow() != NULL
);
3575 return wxACC_NOT_IMPLEMENTED
;
3578 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
3579 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
3581 wxASSERT( GetWindow() != NULL
);
3585 wxWindow
* win
= NULL
;
3592 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
3594 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
3601 rect
= win
->GetRect();
3602 if (win
->GetParent() && !wxDynamicCast(win
, wxTopLevelWindow
))
3603 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
3607 return wxACC_NOT_IMPLEMENTED
;
3610 // Navigates from fromId to toId/toObject.
3611 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
3612 int* WXUNUSED(toId
), wxAccessible
** toObject
)
3614 wxASSERT( GetWindow() != NULL
);
3620 case wxNAVDIR_FIRSTCHILD
:
3622 if (GetWindow()->GetChildren().GetCount() == 0)
3624 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
3625 *toObject
= childWindow
->GetOrCreateAccessible();
3629 case wxNAVDIR_LASTCHILD
:
3631 if (GetWindow()->GetChildren().GetCount() == 0)
3633 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
3634 *toObject
= childWindow
->GetOrCreateAccessible();
3638 case wxNAVDIR_RIGHT
:
3642 wxWindowList::compatibility_iterator node
=
3643 wxWindowList::compatibility_iterator();
3646 // Can't navigate to sibling of this window
3647 // if we're a top-level window.
3648 if (!GetWindow()->GetParent())
3649 return wxACC_NOT_IMPLEMENTED
;
3651 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3655 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
3656 node
= GetWindow()->GetChildren().Item(fromId
-1);
3659 if (node
&& node
->GetNext())
3661 wxWindow
* nextWindow
= node
->GetNext()->GetData();
3662 *toObject
= nextWindow
->GetOrCreateAccessible();
3670 case wxNAVDIR_PREVIOUS
:
3672 wxWindowList::compatibility_iterator node
=
3673 wxWindowList::compatibility_iterator();
3676 // Can't navigate to sibling of this window
3677 // if we're a top-level window.
3678 if (!GetWindow()->GetParent())
3679 return wxACC_NOT_IMPLEMENTED
;
3681 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3685 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
3686 node
= GetWindow()->GetChildren().Item(fromId
-1);
3689 if (node
&& node
->GetPrevious())
3691 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
3692 *toObject
= previousWindow
->GetOrCreateAccessible();
3700 return wxACC_NOT_IMPLEMENTED
;
3703 // Gets the name of the specified object.
3704 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
3706 wxASSERT( GetWindow() != NULL
);
3712 // If a child, leave wxWidgets to call the function on the actual
3715 return wxACC_NOT_IMPLEMENTED
;
3717 // This will eventually be replaced by specialised
3718 // accessible classes, one for each kind of wxWidgets
3719 // control or window.
3721 if (wxDynamicCast(GetWindow(), wxButton
))
3722 title
= ((wxButton
*) GetWindow())->GetLabel();
3725 title
= GetWindow()->GetName();
3733 return wxACC_NOT_IMPLEMENTED
;
3736 // Gets the number of children.
3737 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
3739 wxASSERT( GetWindow() != NULL
);
3743 *childId
= (int) GetWindow()->GetChildren().GetCount();
3747 // Gets the specified child (starting from 1).
3748 // If *child is NULL and return value is wxACC_OK,
3749 // this means that the child is a simple element and
3750 // not an accessible object.
3751 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
3753 wxASSERT( GetWindow() != NULL
);
3763 if (childId
> (int) GetWindow()->GetChildren().GetCount())
3766 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
3767 *child
= childWindow
->GetOrCreateAccessible();
3774 // Gets the parent, or NULL.
3775 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
3777 wxASSERT( GetWindow() != NULL
);
3781 wxWindow
* parentWindow
= GetWindow()->GetParent();
3789 *parent
= parentWindow
->GetOrCreateAccessible();
3797 // Performs the default action. childId is 0 (the action for this object)
3798 // or > 0 (the action for a child).
3799 // Return wxACC_NOT_SUPPORTED if there is no default action for this
3800 // window (e.g. an edit control).
3801 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
3803 wxASSERT( GetWindow() != NULL
);
3807 return wxACC_NOT_IMPLEMENTED
;
3810 // Gets the default action for this object (0) or > 0 (the action for a child).
3811 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
3812 // string if there is no action.
3813 // The retrieved string describes the action that is performed on an object,
3814 // not what the object does as a result. For example, a toolbar button that prints
3815 // a document has a default action of "Press" rather than "Prints the current document."
3816 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
3818 wxASSERT( GetWindow() != NULL
);
3822 return wxACC_NOT_IMPLEMENTED
;
3825 // Returns the description for this object or a child.
3826 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
3828 wxASSERT( GetWindow() != NULL
);
3832 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3838 return wxACC_NOT_IMPLEMENTED
;
3841 // Returns help text for this object or a child, similar to tooltip text.
3842 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
3844 wxASSERT( GetWindow() != NULL
);
3848 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent::Origin_Keyboard
));
3854 return wxACC_NOT_IMPLEMENTED
;
3857 // Returns the keyboard shortcut for this object or child.
3858 // Return e.g. ALT+K
3859 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
3861 wxASSERT( GetWindow() != NULL
);
3865 return wxACC_NOT_IMPLEMENTED
;
3868 // Returns a role constant.
3869 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
3871 wxASSERT( GetWindow() != NULL
);
3875 // If a child, leave wxWidgets to call the function on the actual
3878 return wxACC_NOT_IMPLEMENTED
;
3880 if (wxDynamicCast(GetWindow(), wxControl
))
3881 return wxACC_NOT_IMPLEMENTED
;
3883 if (wxDynamicCast(GetWindow(), wxStatusBar
))
3884 return wxACC_NOT_IMPLEMENTED
;
3887 if (wxDynamicCast(GetWindow(), wxToolBar
))
3888 return wxACC_NOT_IMPLEMENTED
;
3891 //*role = wxROLE_SYSTEM_CLIENT;
3892 *role
= wxROLE_SYSTEM_CLIENT
;
3896 return wxACC_NOT_IMPLEMENTED
;
3900 // Returns a state constant.
3901 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
3903 wxASSERT( GetWindow() != NULL
);
3907 // If a child, leave wxWidgets to call the function on the actual
3910 return wxACC_NOT_IMPLEMENTED
;
3912 if (wxDynamicCast(GetWindow(), wxControl
))
3913 return wxACC_NOT_IMPLEMENTED
;
3916 if (wxDynamicCast(GetWindow(), wxStatusBar
))
3917 return wxACC_NOT_IMPLEMENTED
;
3920 if (wxDynamicCast(GetWindow(), wxToolBar
))
3921 return wxACC_NOT_IMPLEMENTED
;
3928 return wxACC_NOT_IMPLEMENTED
;
3932 // Returns a localized string representing the value for the object
3934 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3936 wxASSERT( GetWindow() != NULL
);
3940 return wxACC_NOT_IMPLEMENTED
;
3943 // Selects the object or child.
3944 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3946 wxASSERT( GetWindow() != NULL
);
3950 return wxACC_NOT_IMPLEMENTED
;
3953 // Gets the window with the keyboard focus.
3954 // If childId is 0 and child is NULL, no object in
3955 // this subhierarchy has the focus.
3956 // If this object has the focus, child should be 'this'.
3957 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3959 wxASSERT( GetWindow() != NULL
);
3963 return wxACC_NOT_IMPLEMENTED
;
3967 // Gets a variant representing the selected children
3969 // Acceptable values:
3970 // - a null variant (IsNull() returns true)
3971 // - a list variant (GetType() == wxT("list")
3972 // - an integer representing the selected child element,
3973 // or 0 if this object is selected (GetType() == wxT("long")
3974 // - a "void*" pointer to a wxAccessible child object
3975 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3977 wxASSERT( GetWindow() != NULL
);
3981 return wxACC_NOT_IMPLEMENTED
;
3983 #endif // wxUSE_VARIANT
3985 #endif // wxUSE_ACCESSIBILITY
3987 // ----------------------------------------------------------------------------
3989 // ----------------------------------------------------------------------------
3992 wxWindowBase::AdjustForLayoutDirection(wxCoord x
,
3994 wxCoord widthTotal
) const
3996 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3998 x
= widthTotal
- x
- width
;