]> git.saurik.com Git - wxWidgets.git/commitdiff
Add support for wxLIST_AUTOSIZE_USEHEADER to InsertColumn().
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 7 Jan 2012 15:09:51 +0000 (15:09 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 7 Jan 2012 15:09:51 +0000 (15:09 +0000)
Use the fixed default width in InsertColumn() by default for compatibility but
allow more useful behaviour in it by supporting wxLIST_AUTOSIZE_USEHEADER as
well.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70284 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/listbase.h
interface/wx/listctrl.h
src/common/listctrlcmn.cpp
src/msw/listctrl.cpp

index fe247e8299e92797d4868c154cfe504f94c5112a..87700aa4c2fcfb6f1e90e98e5138655b2a14c887 100644 (file)
@@ -424,7 +424,7 @@ public:
     long InsertColumn(long col,
                       const wxString& heading,
                       int format = wxLIST_FORMAT_LEFT,
-                      int width = -1);
+                      int width = wxLIST_AUTOSIZE);
 
     // Delete the given or all columns.
     virtual bool DeleteColumn(int col) = 0;
index 3103be6b2fc5fed747a02aaf308a8f9b3d098317..28db0e46d07c956b5275f884afd1ee42152102fc 100644 (file)
@@ -661,16 +661,48 @@ public:
     bool InReportView() const;
 
     /**
-        For report view mode (only), inserts a column. For more details, see SetItem().
+        For report view mode (only), inserts a column.
+
+        For more details, see SetItem(). Also see InsertColumn(long, const
+        wxString&, int, int) overload for a usually more convenient
+        alternative to this method and the description of how the item width
+        is interpreted by this method.
     */
-    long InsertColumn(long col, wxListItem& info);
+    long InsertColumn(long col, const wxListItem& info);
 
     /**
-        For report view mode (only), inserts a column. For more details, see SetItem().
+        For report view mode (only), inserts a column.
+
+        Insert a new column in the list control in report view mode at the
+        given position specifying its most common attributes.
+
+        Notice that to set the image for the column you need to use
+        Insert(long, const wxListItem&) overload and specify ::wxLIST_MASK_IMAGE
+        in the item mask.
+
+        @param col
+            The index where the column should be inserted. Valid indices are
+            from 0 up to GetColumnCount() inclusive and the latter can be used
+            to append the new column after the last existing one.
+        @param heading
+            The string specifying the column heading.
+        @param format
+            The flags specifying the control heading text alignment.
+        @param width
+            If positive, the width of the column in pixels. Otherwise it can be
+            @c wxLIST_AUTOSIZE to choose the default size for the column or @c
+            wxLIST_AUTOSIZE_USEHEADER to fit the column width to @a heading or
+            to extend to fill all the remaining space for the last column.
+            Notice that in case of @c wxLIST_AUTOSIZE fixed width is used as
+            there are no items in this column to use for determining its best
+            size yet. If you want to fit the column to its contents, use
+            SetColumnWidth() after adding the items with values in this column.
+        @return
+            The index of the inserted column or -1 if adding it failed.
     */
     long InsertColumn(long col, const wxString& heading,
                       int format = wxLIST_FORMAT_LEFT,
-                      int width = -1);
+                      int width = wxLIST_AUTOSIZE);
 
     /**
         Inserts an item, returning the index of the new item if successful, -1 otherwise.
index b19ed6e38cb42d7ca401e5f53ff9e8ab9c82e335..5edcf420f121fb111ee53d17167618b9fa72da7e 100644 (file)
@@ -153,7 +153,9 @@ wxListCtrlBase::InsertColumn(long col,
     wxListItem item;
     item.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_FORMAT;
     item.m_text = heading;
-    if ( width > -1 )
+    if ( width >= 0
+            || width == wxLIST_AUTOSIZE
+                || width == wxLIST_AUTOSIZE_USEHEADER )
     {
         item.m_mask |= wxLIST_MASK_WIDTH;
         item.m_width = width;
index 0d8ee0e785ce007fdb6ceacd1bf2c011343bcfbb..8d0bead33322e74eb0fdfe37d8e76e9bdef60782 100644 (file)
@@ -1735,7 +1735,14 @@ long wxListCtrl::DoInsertColumn(long col, const wxListItem& item)
     LV_COLUMN lvCol;
     wxConvertToMSWListCol(GetHwnd(), col, item, lvCol);
 
-    if ( !(lvCol.mask & LVCF_WIDTH) )
+    // LVSCW_AUTOSIZE_USEHEADER is not supported when inserting new column,
+    // we'll deal with it below instead. Plain LVSCW_AUTOSIZE is not supported
+    // neither but it doesn't need any special handling as we use fixed value
+    // for it here, both because we can't do anything else (there are no items
+    // with values in this column to compute the size from yet) and for
+    // compatibility as wxLIST_AUTOSIZE == -1 and -1 as InsertColumn() width
+    // parameter used to mean "arbitrary fixed width".
+    if ( !(lvCol.mask & LVCF_WIDTH) || lvCol.cx < 0 )
     {
         // always give some width to the new column: this one is compatible
         // with the generic version
@@ -1744,14 +1751,20 @@ long wxListCtrl::DoInsertColumn(long col, const wxListItem& item)
     }
 
     long n = ListView_InsertColumn(GetHwnd(), col, &lvCol);
-    if ( n != -1 )
-    {
-        m_colCount++;
-    }
-    else // failed to insert?
+    if ( n == -1 )
     {
         wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
                    lvCol.pszText);
+        return -1;
+    }
+
+    m_colCount++;
+
+    // Now adjust the new column size.
+    if ( (item.GetMask() & wxLIST_MASK_WIDTH) &&
+            (item.GetWidth() == wxLIST_AUTOSIZE_USEHEADER) )
+    {
+        SetColumnWidth(n, wxLIST_AUTOSIZE_USEHEADER);
     }
 
     return n;