From c0ac3149bfac1e37fb6eb1a7388603020d319676 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 1 Apr 2007 14:53:02 +0000 Subject: [PATCH] implement GetBestSize() (patch 1386199) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45202 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/statbr95.h | 5 +++-- src/msw/statbr95.cpp | 47 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/include/wx/msw/statbr95.h b/include/wx/msw/statbr95.h index afa3db8486..3b26a1fa3a 100644 --- a/include/wx/msw/statbr95.h +++ b/include/wx/msw/statbr95.h @@ -64,8 +64,9 @@ protected: void CopyFieldsWidth(const int widths[]); void SetFieldsWidth(); - // override base class virtual - void DoMoveWindow(int x, int y, int width, int height); + // override some base class virtuals + virtual wxSize DoGetBestSize() const; + virtual void DoMoveWindow(int x, int y, int width, int height); private: DECLARE_DYNAMIC_CLASS_NO_COPY(wxStatusBar95) diff --git a/src/msw/statbr95.cpp b/src/msw/statbr95.cpp index 52d64680ee..2fd1936449 100644 --- a/src/msw/statbr95.cpp +++ b/src/msw/statbr95.cpp @@ -296,6 +296,53 @@ bool wxStatusBar95::GetFieldRect(int i, wxRect& rect) const return true; } +// no idea for a default width, just choose something +#define DEFAULT_FIELD_WIDTH 25 + +wxSize wxStatusBar95::DoGetBestSize() const +{ + int borders[3]; + SendMessage(GetHwnd(), SB_GETBORDERS, 0, (LPARAM)borders); + + // calculate width + int width = 0; + for ( int i = 0; i < m_nFields; ++i ) + { + int widthField = m_statusWidths ? m_statusWidths[i] + : DEFAULT_FIELD_WIDTH; + if ( widthField >= 0 ) + { + width += m_statusWidths[i]; + } + else + { + // variable width field, its width is really a proportion + // related to the other fields + width += -widthField*DEFAULT_FIELD_WIDTH; + } + + // add the space between fields + width += borders[2]; + } + + if ( !width ) + { + // still need something even for an empty status bar + width = 2*DEFAULT_FIELD_WIDTH; + } + + + // calculate height + int height; + wxGetCharSize(GetHWND(), NULL, &height, GetFont()); + height = EDIT_HEIGHT_FROM_CHAR_HEIGHT(height); + height += borders[1]; + + wxSize best(width, height); + CacheBestSize(best); + return best; +} + void wxStatusBar95::DoMoveWindow(int x, int y, int width, int height) { if ( GetParent()->IsSizeDeferred() ) -- 2.47.2