diff --git a/include/wx/control.h b/include/wx/control.h index 62ea97b1b3..b891236e4a 100644 --- a/include/wx/control.h +++ b/include/wx/control.h @@ -77,6 +77,17 @@ protected: // initialize the common fields of wxCommandEvent void InitCommandEvent(wxCommandEvent& event) const; + // set the initial window size if none is given (i.e. at least one of the + // components of the size passed to ctor/Create() is -1) + // + // normally just calls SetBestSize() but can be overridden not to do it for + // the controls which have to do some additional initialization (e.g. add + // strings to list box) before their best size can be accurately calculated + virtual void SetInitialBestSize(const wxSize& size) + { + SetBestSize(size); + } + DECLARE_NO_COPY_CLASS(wxControlBase) }; diff --git a/src/msw/control.cpp b/src/msw/control.cpp index 3b60836933..a4b4718831 100644 --- a/src/msw/control.cpp +++ b/src/msw/control.cpp @@ -171,10 +171,7 @@ bool wxControl::MSWCreateControl(const wxChar *classname, SetFont(GetDefaultAttributes().font); // set the size now if no initial size specified - if ( w <= 0 || h <= 0 ) - { - SetBestSize(size); - } + SetInitialBestSize(size); return TRUE; }