Added DoGetClientBestSize() and use it for a couple of controls in wxMSW.
DoGetClientBestSize() returns the best size of the client area, without accounting for the border which is done by GetBestSize() itself and DoGetBorderSize() called from it. Use DoGetClientBestSize() in wxStaticText (where it was done insideDoGetBestSize() before) and in wxListBox, to fix its height calculation. Also use correct height of listbox items as returned by the control itself instead of trying to guess it. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61169 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
8c6c5778c2
commit
743b426605
@ -133,6 +133,8 @@ public:
|
||||
virtual bool CanApplyThemeBorder() const { return false; }
|
||||
|
||||
protected:
|
||||
virtual wxSize DoGetBestClientSize() const;
|
||||
|
||||
virtual void DoClear();
|
||||
virtual void DoDeleteOneItem(unsigned int n);
|
||||
|
||||
@ -155,8 +157,6 @@ protected:
|
||||
|
||||
unsigned int m_noItems;
|
||||
|
||||
virtual wxSize DoGetBestSize() const;
|
||||
|
||||
#if wxUSE_OWNER_DRAWN
|
||||
// control items
|
||||
wxListBoxItemsArray m_aItems;
|
||||
|
@ -46,7 +46,7 @@ protected:
|
||||
// implement/override some base class virtuals
|
||||
virtual void DoSetSize(int x, int y, int w, int h,
|
||||
int sizeFlags = wxSIZE_AUTO);
|
||||
virtual wxSize DoGetBestSize() const;
|
||||
virtual wxSize DoGetBestClientSize() const;
|
||||
|
||||
virtual wxString DoGetLabel() const;
|
||||
virtual void DoSetLabel(const wxString& str);
|
||||
|
@ -501,6 +501,8 @@ protected:
|
||||
int sizeFlags = wxSIZE_AUTO);
|
||||
virtual void DoSetClientSize(int width, int height);
|
||||
|
||||
virtual wxSize DoGetBorderSize() const;
|
||||
|
||||
virtual void DoCaptureMouse();
|
||||
virtual void DoReleaseMouse();
|
||||
|
||||
|
@ -1633,6 +1633,11 @@ protected:
|
||||
// same size as it would have after a call to Fit()
|
||||
virtual wxSize DoGetBestSize() const;
|
||||
|
||||
// this method can be overridden instead of DoGetBestSize() if it computes
|
||||
// the best size of the client area of the window only, excluding borders
|
||||
// (GetBorderSize() will be used to add them)
|
||||
virtual wxSize DoGetBestClientSize() const { return wxDefaultSize; }
|
||||
|
||||
// this is the virtual function to be overriden in any derived class which
|
||||
// wants to change how SetSize() or Move() works - it is called by all
|
||||
// versions of these functions in the base class
|
||||
@ -1647,6 +1652,19 @@ protected:
|
||||
int maxW, int maxH,
|
||||
int incW, int incH );
|
||||
|
||||
// return the total size of the window borders, i.e. the sum of the widths
|
||||
// of the left and the right border in the x component of the returned size
|
||||
// and the sum of the heights of the top and bottom borders in the y one
|
||||
//
|
||||
// NB: this is new/temporary API only implemented by wxMSW so far and
|
||||
// subject to change, don't use
|
||||
virtual wxSize DoGetBorderSize() const
|
||||
{
|
||||
wxFAIL_MSG( "must be overridden if called" );
|
||||
|
||||
return wxDefaultSize;
|
||||
}
|
||||
|
||||
// move the window to the specified location and resize it: this is called
|
||||
// from both DoSetSize() and DoSetClientSize() and would usually just
|
||||
// reposition this window except for composite controls which will want to
|
||||
|
@ -705,9 +705,20 @@ wxSize wxWindowBase::GetEffectiveMinSize() const
|
||||
|
||||
wxSize wxWindowBase::GetBestSize() const
|
||||
{
|
||||
if ((!m_windowSizer) && (m_bestSizeCache.IsFullySpecified()))
|
||||
if ( !m_windowSizer && m_bestSizeCache.IsFullySpecified() )
|
||||
return m_bestSizeCache;
|
||||
|
||||
// call DoGetBestClientSize() first, if a derived class overrides it wants
|
||||
// it to be used
|
||||
wxSize size = DoGetBestClientSize();
|
||||
if ( size != wxDefaultSize )
|
||||
{
|
||||
size += DoGetBorderSize();
|
||||
|
||||
CacheBestSize(size);
|
||||
return size;
|
||||
}
|
||||
|
||||
return DoGetBestSize();
|
||||
}
|
||||
|
||||
|
@ -590,7 +590,7 @@ void wxListBox::SetHorizontalExtent(const wxString& s)
|
||||
//else: it shouldn't change
|
||||
}
|
||||
|
||||
wxSize wxListBox::DoGetBestSize() const
|
||||
wxSize wxListBox::DoGetBestClientSize() const
|
||||
{
|
||||
// find the widest string
|
||||
int wLine;
|
||||
@ -609,22 +609,17 @@ wxSize wxListBox::DoGetBestSize() const
|
||||
wListbox = 100;
|
||||
|
||||
// the listbox should be slightly larger than the widest string
|
||||
int cx, cy;
|
||||
wxGetCharSize(GetHWND(), &cx, &cy, GetFont());
|
||||
wListbox += 3*GetCharWidth();
|
||||
|
||||
wListbox += 3*cx;
|
||||
|
||||
// Add room for the scrollbar
|
||||
// add room for the scrollbar
|
||||
wListbox += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
|
||||
|
||||
// don't make the listbox too tall (limit height to 10 items) but don't
|
||||
// make it too small neither
|
||||
int hListbox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)*
|
||||
int hListbox = SendMessage(GetHwnd(), LB_GETITEMHEIGHT, 0, 0)*
|
||||
wxMin(wxMax(m_noItems, 3), 10);
|
||||
|
||||
wxSize best(wListbox, hListbox);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
return wxSize(wListbox, hListbox);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -142,7 +142,7 @@ WXDWORD wxStaticText::MSWGetStyle(long style, WXDWORD *exstyle) const
|
||||
return msStyle;
|
||||
}
|
||||
|
||||
wxSize wxStaticText::DoGetBestSize() const
|
||||
wxSize wxStaticText::DoGetBestClientSize() const
|
||||
{
|
||||
wxClientDC dc(const_cast<wxStaticText *>(this));
|
||||
wxFont font(GetFont());
|
||||
@ -159,40 +159,7 @@ wxSize wxStaticText::DoGetBestSize() const
|
||||
widthTextMax += 2;
|
||||
#endif // __WXWINCE__
|
||||
|
||||
// border takes extra space
|
||||
//
|
||||
// TODO: this is probably not wxStaticText-specific and should be moved
|
||||
wxCoord border;
|
||||
switch ( GetBorder() )
|
||||
{
|
||||
case wxBORDER_STATIC:
|
||||
case wxBORDER_SIMPLE:
|
||||
border = 1;
|
||||
break;
|
||||
|
||||
case wxBORDER_SUNKEN:
|
||||
border = 2;
|
||||
break;
|
||||
|
||||
case wxBORDER_RAISED:
|
||||
case wxBORDER_DOUBLE:
|
||||
border = 3;
|
||||
break;
|
||||
|
||||
default:
|
||||
wxFAIL_MSG( _T("unknown border style") );
|
||||
// fall through
|
||||
|
||||
case wxBORDER_NONE:
|
||||
border = 0;
|
||||
}
|
||||
|
||||
widthTextMax += 2*border;
|
||||
heightTextTotal += 2*border;
|
||||
|
||||
wxSize best(widthTextMax, heightTextTotal);
|
||||
CacheBestSize(best);
|
||||
return best;
|
||||
return wxSize(widthTextMax, heightTextTotal);
|
||||
}
|
||||
|
||||
void wxStaticText::DoSetSize(int x, int y, int w, int h, int sizeFlags)
|
||||
|
@ -2112,6 +2112,36 @@ void wxWindowMSW::DoSetClientSize(int width, int height)
|
||||
}
|
||||
}
|
||||
|
||||
wxSize wxWindowMSW::DoGetBorderSize() const
|
||||
{
|
||||
wxCoord border;
|
||||
switch ( GetBorder() )
|
||||
{
|
||||
case wxBORDER_STATIC:
|
||||
case wxBORDER_SIMPLE:
|
||||
border = 1;
|
||||
break;
|
||||
|
||||
case wxBORDER_SUNKEN:
|
||||
border = 2;
|
||||
break;
|
||||
|
||||
case wxBORDER_RAISED:
|
||||
case wxBORDER_DOUBLE:
|
||||
border = 3;
|
||||
break;
|
||||
|
||||
default:
|
||||
wxFAIL_MSG( _T("unknown border style") );
|
||||
// fall through
|
||||
|
||||
case wxBORDER_NONE:
|
||||
border = 0;
|
||||
}
|
||||
|
||||
return 2*wxSize(border, border);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// text metrics
|
||||
// ---------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user