Browse Source

Considering items out of the current view when sizing dialogs list columns

(HDN_DIVIDERDBLCLICK considers only items in the current view)

Source commit: 44cdbd8f1980fc64607de8132077865198816c0a
Martin Prikryl 9 years ago
parent
commit
c0ddc724ab
1 changed files with 18 additions and 30 deletions
  1. 18 30
      source/windows/VCLCommon.cpp

+ 18 - 30
source/windows/VCLCommon.cpp

@@ -82,38 +82,26 @@ void __fastcall AutoSizeListColumnsWidth(TListView * ListView, int ColumnToShrin
       }
       else
       {
-        // For the first column, we can simulate header double-click
-        if (Index == 0)
+        Width = 0;
+        for (int ItemIndex = 0; ItemIndex < ListView->Items->Count; ItemIndex++)
         {
-          HWND HeaderHandle = ListView_GetHeader(ListView->Handle);
-          UINT_PTR From = GetDlgCtrlID(HeaderHandle);
-          NMHEADER NMHeader;
-          NMHeader.hdr.idFrom = From;
-          NMHeader.hdr.hwndFrom = HeaderHandle;
-          NMHeader.hdr.code = HDN_DIVIDERDBLCLICK;
-          NMHeader.iItem = Index;
-          NMHeader.iButton = 0;
-          NMHeader.pitem = NULL;
-          SendMessage(ListView->Handle, WM_NOTIFY, From, reinterpret_cast<LPARAM>(&NMHeader));
-          Width = ListView_GetColumnWidth(ListView->Handle, Index);
-        }
-        else
-        {
-          // For sub columns, header double click does not work reliably.
-          // It resizes based on the focused line only and even then not consistently.
-          Width = 0;
-          for (int ItemIndex = 0; ItemIndex < ListView->Items->Count; ItemIndex++)
+          TListItem * Item = ListView->Items->Item[ItemIndex];
+
+          UnicodeString Text;
+          if (Index == 0)
           {
-            TListItem * Item = ListView->Items->Item[ItemIndex];
-            if (Index < Item->SubItems->Count)
-            {
-              UnicodeString Text = Item->SubItems->Strings[Index - 1];
-              int TextWidth = GetColumnTextWidth(ListView, ColumnPadding, Text);
-              if (TextWidth > Width)
-              {
-                Width = TextWidth;
-              }
-            }
+            Text = Item->Caption;
+          }
+          // Particularly EditorListView3 on Preferences dialog does not have all subitems filled for internal editor
+          else if (Index <= Item->SubItems->Count)
+          {
+            Text = Item->SubItems->Strings[Index - 1];
+          }
+
+          int TextWidth = GetColumnTextWidth(ListView, ColumnPadding, Text);
+          if (TextWidth > Width)
+          {
+            Width = TextWidth;
           }
         }
       }