]> git.saurik.com Git - wxWidgets.git/commitdiff
Make column width calculations in wxDataViewCtrl and wxHeaderCtrl consistent.
authorVáclav Slavík <vslavik@fastmail.fm>
Sat, 14 Jan 2012 16:51:57 +0000 (16:51 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Sat, 14 Jan 2012 16:51:57 +0000 (16:51 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70338 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/headerctrl.h
interface/wx/headerctrl.h
src/common/headerctrlcmn.cpp
src/generic/datavgen.cpp

index 2d36093efca812975edbfb18f1f4adc3a38a3aa0..9555e26155dd5ee2acf846e31389101d7f2d3a13 100644 (file)
@@ -154,6 +154,8 @@ public:
     // specified) and if the control has wxHD_ALLOW_REORDER style as well
     bool ShowCustomizeDialog();
 
+    // compute column title width
+    int GetColumnTitleWidth(const wxHeaderColumn& col);
 
     // implementation only from now on
     // -------------------------------
index 718e02749a0b641f9b4645bbd64406531f466768..1ead47803925f1929baa7be2fae401208955f3a8 100644 (file)
@@ -374,6 +374,13 @@ public:
      */
     bool ShowCustomizeDialog();
 
+    /**
+        Returns width needed for given column's title.
+
+        @since 2.9.4
+     */
+    int GetColumnTitleWidth(const wxHeaderColumn& col);
+
 protected:
     /**
         Method to be implemented by the derived classes to return the
index be858a6848d6c98cc82cc782f1171a97579537b0..98025723ad1cc73521577b9de1b82cda8cc00e9c 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "wx/headerctrl.h"
 #include "wx/rearrangectrl.h"
+#include "wx/renderer.h"
 
 namespace
 {
@@ -107,6 +108,21 @@ void wxHeaderCtrlBase::SetColumnCount(unsigned int count)
     DoSetCount(count);
 }
 
+int wxHeaderCtrlBase::GetColumnTitleWidth(const wxHeaderColumn& col)
+{
+    int w = wxWindowBase::GetTextExtent(col.GetTitle()).x;
+
+    // add some margin:
+    w += wxRendererNative::Get().GetHeaderButtonMargin(this);
+
+    // if a bitmap is used, add space for it and 2px border:
+    wxBitmap bmp = col.GetBitmap();
+    if ( bmp.IsOk() )
+        w += bmp.GetWidth() + 2;
+
+    return w;
+}
+
 // ----------------------------------------------------------------------------
 // wxHeaderCtrlBase event handling
 // ----------------------------------------------------------------------------
@@ -122,8 +138,7 @@ void wxHeaderCtrlBase::OnSeparatorDClick(wxHeaderCtrlEvent& event)
         return;
     }
 
-    int w = wxWindowBase::GetTextExtent(column.GetTitle()).x;
-    w += 4*GetCharWidth(); // add some arbitrary margins around text
+    int w = GetColumnTitleWidth(column);
 
     if ( !UpdateColumnWidthToFit(col, w) )
         event.Skip();
index e8d83fed0a6ac0ffc6888790ffbbf17179a9e29c..852a50815ec0a27ddc21c29a437f763d3de95334 100644 (file)
@@ -4647,13 +4647,7 @@ unsigned int wxDataViewCtrl::GetBestColumnWidth(int idx) const
                                   m_clientArea->GetRowHeight());
 
     if ( m_headerArea )
-    {
-        int header_width = m_headerArea->GetTextExtent(column->GetTitle()).x;
-        // Labels on native MSW header are indented on both sides
-        header_width +=
-            wxRendererNative::Get().GetHeaderButtonMargin(m_headerArea);
-        calculator.UpdateWithWidth(header_width);
-    }
+        calculator.UpdateWithWidth(m_headerArea->GetColumnTitleWidth(*column));
 
     // The code below deserves some explanation. For very large controls, we
     // simply can't afford to calculate sizes for all items, it takes too