]> git.saurik.com Git - wxWidgets.git/commitdiff
Added DoGetClientBestSize() and use it for a couple of controls in wxMSW.
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 22 Jun 2009 20:36:13 +0000 (20:36 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 22 Jun 2009 20:36:13 +0000 (20:36 +0000)
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

include/wx/msw/listbox.h
include/wx/msw/stattext.h
include/wx/msw/window.h
include/wx/window.h
src/common/wincmn.cpp
src/msw/listbox.cpp
src/msw/stattext.cpp
src/msw/window.cpp

index 2d77f86c1a8263a7dc9607ed6c644c7915042bc2..8157cbdcbdc80f33cbeecd6f50c4bfb8f43baba3 100644 (file)
@@ -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;
index 28e1b79656250d3606ec396cc0a3390f58ce04f1..2bae45488975063e193e4d749c9e81df723252f6 100644 (file)
@@ -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);
index 8a9a2aa7bc87fd9e8d3109ae1da2bdf0fd4a61f2..4026e7ea06009443287a3035679eeebd5e529114 100644 (file)
@@ -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();
 
index 913cd7d0aad0fdfae1295fa84a31ddfdc96b9c38..c9e0c59546059deb25590b7cf084cf50ced25ed8 100644 (file)
@@ -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
index 8a0ae4f54fb46a827733fef477503fab425bd295..6243c4d73d807d7d3d0223c43c28652b0f6a4145 100644 (file)
@@ -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();
 }
 
index 3e6b8a7612eb47f17c0fd49f2bac850459e66923..84634d3088dc02fce0ceaead97dbddc56e897d02 100644 (file)
@@ -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);
 }
 
 // ----------------------------------------------------------------------------
index 7a20a94ae081c43564991063863a249d8a9c62bb..898487a88cda60356e44706ee8692f26ae571a34 100644 (file)
@@ -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)
index 45a3767f01829af55b5f23ea8f44e657c72bbd5c..be4133f07f1ed567d8984a18a46c786569173aeb 100644 (file)
@@ -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
 // ---------------------------------------------------------------------------