]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/headerctrl.cpp
use a slightly less ugly way to conditionally suppress unused parameter warnings
[wxWidgets.git] / src / msw / headerctrl.cpp
index 463ef53132463b08534d17b9baf62952692ec1f7..d6ad5ccddaad6e63e8d7e36efe1fbf91b81c7be7 100644 (file)
@@ -151,16 +151,22 @@ void wxHeaderCtrl::DoSetCount(unsigned int count)
     // and add the new ones
     for ( n = 0; n < count; n++ )
     {
-        DoSetOrInsertItem(Insert, n);
+        DoInsertItem(n);
     }
 }
 
 void wxHeaderCtrl::DoUpdate(unsigned int idx)
 {
-    DoSetOrInsertItem(Set, idx);
+    // the native control does provide Header_SetItem() but it's inconvenient
+    // to use it because it sends HDN_ITEMCHANGING messages and we'd have to
+    // arrange not to block setting the width from there and the logic would be
+    // more complicated as we'd have to reset the old values as well as setting
+    // the new ones -- so instead just recreate the column
+    Header_DeleteItem(GetHwnd(), idx);
+    DoInsertItem(idx);
 }
 
-void wxHeaderCtrl::DoSetOrInsertItem(Operation oper, unsigned int idx)
+void wxHeaderCtrl::DoInsertItem(unsigned int idx)
 {
     const wxHeaderColumnBase& col = GetColumn(idx);
 
@@ -168,41 +174,44 @@ void wxHeaderCtrl::DoSetOrInsertItem(Operation oper, unsigned int idx)
 
     // notice that we need to store the string we use the pointer to until we
     // pass it to the control
-    wxWxCharBuffer buf;
-    if ( !col.GetTitle().empty() )
-    {
-        hdi.mask |= HDI_TEXT;
-
-        buf = col.GetTitle().wx_str();
-        hdi.pszText = buf.data();
-        hdi.cchTextMax = wxStrlen(buf);
-    }
+    hdi.mask |= HDI_TEXT;
+    wxWxCharBuffer buf = col.GetTitle().wx_str();
+    hdi.pszText = buf.data();
+    hdi.cchTextMax = wxStrlen(buf);
 
     const wxBitmap bmp = col.GetBitmap();
     if ( bmp.IsOk() )
     {
-        const int bmpWidth = bmp.GetWidth(),
-                  bmpHeight = bmp.GetHeight();
+        hdi.mask |= HDI_IMAGE;
 
-        if ( !m_imageList )
+        if ( bmp.IsOk() )
         {
-            m_imageList = new wxImageList(bmpWidth, bmpHeight);
-            Header_SetImageList(GetHwnd(), GetHimagelistOf(m_imageList));
+            const int bmpWidth = bmp.GetWidth(),
+                      bmpHeight = bmp.GetHeight();
+
+            if ( !m_imageList )
+            {
+                m_imageList = new wxImageList(bmpWidth, bmpHeight);
+                Header_SetImageList(GetHwnd(), GetHimagelistOf(m_imageList));
+            }
+            else // already have an image list
+            {
+                // check that all bitmaps we use have the same size
+                int imageWidth,
+                    imageHeight;
+                m_imageList->GetSize(0, imageWidth, imageHeight);
+
+                wxASSERT_MSG( imageWidth == bmpWidth && imageHeight == bmpHeight,
+                              "all column bitmaps must have the same size" );
+            }
+
+            m_imageList->Add(bmp);
+            hdi.iImage = m_imageList->GetImageCount() - 1;
         }
-        else // already have an image list
+        else // no bitmap but we still need to update the item
         {
-            // check that all bitmaps we use have the same size
-            int imageWidth,
-                imageHeight;
-            m_imageList->GetSize(0, imageWidth, imageHeight);
-
-            wxASSERT_MSG( imageWidth == bmpWidth && imageHeight == bmpHeight,
-                          "all column bitmaps must have the same size" );
+            hdi.iImage = I_IMAGENONE;
         }
-
-        m_imageList->Add(bmp);
-        hdi.mask |= HDI_IMAGE;
-        hdi.iImage = m_imageList->GetImageCount() - 1;
     }
 
     if ( col.GetAlignment() != wxALIGN_NOT )
@@ -240,19 +249,9 @@ void wxHeaderCtrl::DoSetOrInsertItem(Operation oper, unsigned int idx)
         hdi.cxy = col.IsHidden() ? 0 : col.GetWidth();
     }
 
-    const LRESULT rc = ::SendMessage(GetHwnd(),
-                                     oper == Set ? HDM_SETITEM : HDM_INSERTITEM,
-                                     idx,
-                                     (LPARAM)&hdi);
-    if ( oper == Set )
-    {
-        if ( !rc )
-            wxLogLastError(_T("Header_SetItem()"));
-    }
-    else // Insert
+    if ( ::SendMessage(GetHwnd(), HDM_INSERTITEM, idx, (LPARAM)&hdi) == -1 )
     {
-        if ( rc == -1 )
-            wxLogLastError(_T("Header_InsertItem()"));
+        wxLogLastError(_T("Header_InsertItem()"));
     }
 }
 
@@ -333,6 +332,15 @@ bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
         // ASCII and Unicode versions of this message
         case HDN_BEGINTRACKA:
         case HDN_BEGINTRACKW:
+            // non-resizeable columns can't be resized no matter what, don't
+            // even generate any events for them
+            if ( !GetColumn(idx).IsResizeable() )
+            {
+                *result = TRUE;
+
+                return true;
+            }
+
             evtType = wxEVT_COMMAND_HEADER_BEGIN_RESIZE;
             // fall through