]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxHeaderCtrlSimple::GetBestFittingWidth() for even more automatic column resizing
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 8 Dec 2008 12:28:41 +0000 (12:28 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 8 Dec 2008 12:28:41 +0000 (12:28 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57187 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

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

index f7f8dda827e3432cfd1a0ba1399f06da78a1d07a..bf3a6632ba1837e6890ccf67bf2390a647fe8e48 100644 (file)
@@ -224,7 +224,17 @@ public:
     void RemoveSortIndicator();
 
 protected:
     void RemoveSortIndicator();
 
 protected:
+    // implement/override base class methods
     virtual wxHeaderColumnBase& GetColumn(unsigned int idx);
     virtual wxHeaderColumnBase& GetColumn(unsigned int idx);
+    virtual bool UpdateColumnWidthToFit(unsigned int idx, int widthTitle);
+
+    // and define another one to be overridden in the derived classes: it
+    // should return the best width for the given column contents or -1 if not
+    // implemented, we use it to implement UpdateColumnWidthToFit()
+    virtual int GetBestFittingWidth(unsigned int WXUNUSED(idx)) const
+    {
+        return -1;
+    }
 
 private:
     // functions implementing our public API
 
 private:
     // functions implementing our public API
index c7e5114da65e38e12dfd1138bfcaaf43657fc639..cca13106383d3444e2e7a5f05de9780a12dc130c 100644 (file)
@@ -356,6 +356,22 @@ public:
             The column to remove sort indicator for.
      */
     void RemoveSortIndicator(unsigned int idx);
             The column to remove sort indicator for.
      */
     void RemoveSortIndicator(unsigned int idx);
+
+protected:
+    /**
+        This function can be overridden in the classes deriving from this
+        control instead of overriding UpdateColumnWidthToFit().
+
+        To implement automatic column resizing to fit its contents width when
+        the column divider is double clicked, you need to simply return the
+        fitting width for the given column @a idx from this method, the control
+        will automatically use the biggest value between the one returned from
+        here and the one needed for the display of the column title itself.
+
+        The base class version returns -1 indicating that this function is not
+        implemented.
+     */
+    virtual int GetBestFittingWidth(unsigned int idx) const;
 };
 
 /**
 };
 
 /**
index fa9766ab815e2b9a370c82b70b4b6b2136638a92..a424e924d2a759630055011f2f31bad8a4a0feeb 100644 (file)
@@ -149,6 +149,19 @@ void wxHeaderCtrlSimple::RemoveSortIndicator()
     }
 }
 
     }
 }
 
+bool
+wxHeaderCtrlSimple::UpdateColumnWidthToFit(unsigned int idx, int widthTitle)
+{
+    const int widthContents = GetBestFittingWidth(idx);
+    if ( widthContents == -1 )
+        return false;
+
+    m_cols[idx].SetWidth(wxMax(widthContents, widthTitle));
+    UpdateColumn(idx);
+
+    return true;
+}
+
 // ============================================================================
 // wxHeaderCtrlEvent implementation
 // ============================================================================
 // ============================================================================
 // wxHeaderCtrlEvent implementation
 // ============================================================================