View Issue Details

IDProjectCategoryView StatusLast Update
0012533LazarusLCLpublic2010-08-06 13:49
ReporterJosé MejutoAssigned ToFelipe Monteiro de Carvalho 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformx86OSWin32 maybe Win64OS VersionAll
Product Version0.9.27 (SVN)Product Build 
Target VersionFixed in Version0.9.29 (SVN) 
Summary0012533: Listview autosize does not work.
DescriptionSetting a column to be "Autosize" does not work.
Steps To ReproduceSet a column content to be autosize.
Additional InformationA proposed patch involves several functions of "lcl\interfaces\win32\win32wscustomlistview.inc"

"TWin32WSCustomListView.ItemSetText" add just before the function end:
****************
  if ALV.Column[ASubIndex].AutoSize then begin
    ListView_SetColumnWidth(ALV.Handle, 0, LVSCW_AUTOSIZE);
  end;
****************
This forces the size to be calculated on every new item addition. The calculation seens to be fast.

Change "TWin32WSCustomListView.SetViewStyle" by:

**********************************************
class procedure TWin32WSCustomListView.SetViewStyle(const ALV: TCustomListView; const Avalue: TViewStyle);
const
  //vsIcon, vsSmallIcon, vsList, vsReport
  STYLES: array[TViewStyle] of DWORD = (LVS_ICON, LVS_SMALLICON, LVS_LIST, LVS_REPORT);
var
  j: integer;
begin
  if not WSCheckHandleAllocated(ALV, 'SetViewStyle')
  then Exit;
  UpdateStyle(ALV.Handle, LVS_TYPEMASK, STYLES[AValue]);

  //Maybe this is not the proper fix but it should not
  //present any permanent conflict as nothing is changed
  //in the settings stablished by the user, only some data
  //is resent.
  if Avalue=vsReport then
    begin
    //Restore size and autosize properties
    for j := 0 to TListView(ALV).Columns.Count-1 do
      begin
      with ALV.Column[j] do
        begin
        if AutoSize then
          ColumnSetAutoSize(ALV,j,ALV.Column[j],true);
        else
          ColumnSetWidth(ALV,j,ALV.Column[j],Width);
      end;
    end;
  end;
end;
*************************************

In the file "lcl\include\listcolumn.inc" the fix should be checked in other platforms (I only have Win32). I suspect that both attributes (width and autosize) must be sent but in Win32 the order must be inverted (autosize means width=-1), so first send the size and later the autosize property. Proposed fix is:

***********************************************
procedure TListColumn.WSCreateColumn;
var
  LV: TCustomListView;
  WSC: TWSCustomListViewClass;
begin
  LV := TListColumns(Collection).FOwner;
  WSC := TWSCustomListViewClass(LV.WidgetSetClass);
  WSC.ColumnInsert(LV, Index, Self);
  WSC.ColumnSetAlignment(LV, Index, Self, FAlignment);
  WSC.ColumnSetCaption(LV, Index, Self, FCaption);
  WSC.ColumnSetMaxWidth(LV, Index, Self, FMaxWidth);
  WSC.ColumnSetMinWidth(LV, Index, Self, FMinWidth);
  if FAutoSize then begin
    WSC.ColumnSetAutosize(LV, Index, Self, FAutosize);
  end else begin
    WSC.ColumnSetWidth(LV, Index, Self, FWidth);
  end;
  WSC.ColumnSetImage(LV, Index, Self, FImageIndex);
  WSC.ColumnSetVisible(LV, Index, Self, FVisible);
end;
****************************************

but the "IF" could be changed by:
    WSC.ColumnSetWidth(LV, Index, Self, FWidth);
    WSC.ColumnSetAutosize(LV, Index, Self, FAutosize);

and it will work as expected in Win32 anyway.
TagsNo tags attached.
Fixed in Revision26846
LazTarget0.9.30
WidgetsetWin32/Win64
Attached Files
  • win32lv.patch (2,081 bytes)
    Index: lcl/interfaces/win32/win32wscustomlistview.inc
    ===================================================================
    --- lcl/interfaces/win32/win32wscustomlistview.inc	(revision 17166)
    +++ lcl/interfaces/win32/win32wscustomlistview.inc	(working copy)
    @@ -457,6 +457,10 @@
       {$else}
         ListView_SetItemText(ALV.Handle, AIndex, ASubIndex, PChar(AText));
       {$endif}
    +  //Forces the listview to recalculate the new width.
    +  if ALV.Column[ASubIndex].AutoSize then begin
    +    ListView_SetColumnWidth(ALV.Handle, ASubIndex, LVSCW_AUTOSIZE);
    +  end;
     end;
     
     class procedure TWin32WSCustomListView.ItemShow(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const PartialOK: Boolean);
    @@ -787,7 +791,7 @@
           lsInvert: begin
             Mask := Mask or LV_STYLES[Prop].Style;
     
    -        if (LV_STYLES[Prop].StyleType = lsStyle) = (Prop in AProps)
    +        if (LV_STYLES[Prop].StyleType = lsStyle) and (Prop in AProps)
             then Style := Style or LV_STYLES[Prop].Style
             else Style := Style and not LV_STYLES[Prop].Style;
           end;
    @@ -846,11 +850,30 @@
     const
       //vsIcon, vsSmallIcon, vsList, vsReport
       STYLES: array[TViewStyle] of DWORD = (LVS_ICON, LVS_SMALLICON, LVS_LIST, LVS_REPORT);
    +var
    +  j: integer;
     begin
       if not WSCheckHandleAllocated(ALV, 'SetViewStyle')
       then Exit;
     
       UpdateStyle(ALV.Handle, LVS_TYPEMASK, STYLES[AValue]);
    +
    +  //Maybe this is not the proper fix but it should not
    +  //present any permanent conflict as nothing is changed
    +  //in the settings stablished by the user, only some data
    +  //is resent.
    +  if Avalue=vsReport then begin
    +    //Restore size and autosize properties
    +    for j := 0 to TListView(ALV).Columns.Count-1 do begin
    +      with ALV.Column[j] do begin
    +        if AutoSize then begin
    +          ColumnSetAutoSize(ALV,j,ALV.Column[j],true);
    +        end else begin
    +          ColumnSetWidth(ALV,j,ALV.Column[j],Width);
    +        end;
    +      end;
    +    end;
    +  end;
     end;
     
     class procedure TWin32WSCustomListView.UpdateStyle(const AHandle: THandle; const AMask, AStyle: Integer);
    
    win32lv.patch (2,081 bytes)
  • listviewautosizewin32.patch (1,334 bytes)
    Index: include/listcolumn.inc
    ===================================================================
    --- include/listcolumn.inc	(revision 23660)
    +++ include/listcolumn.inc	(working copy)
    @@ -94,7 +94,11 @@
       WSC.ColumnSetCaption(LV, Index, Self, FCaption);
       WSC.ColumnSetMaxWidth(LV, Index, Self, FMaxWidth);
       WSC.ColumnSetMinWidth(LV, Index, Self, FMinWidth);
    -  WSC.ColumnSetWidth(LV, Index, Self, FWidth);
    +  if FAutoSize then begin
    +    WSC.ColumnSetAutosize(LV, Index, Self, FAutosize);
    +  end else begin
    +    WSC.ColumnSetWidth(LV, Index, Self, FWidth);
    +  end;
       WSC.ColumnSetImage(LV, Index, Self, FImageIndex);
       WSC.ColumnSetVisible(LV, Index, Self, FVisible);
     end;
    Index: interfaces/win32/win32wscustomlistview.inc
    ===================================================================
    --- interfaces/win32/win32wscustomlistview.inc	(revision 23660)
    +++ interfaces/win32/win32wscustomlistview.inc	(working copy)
    @@ -666,6 +666,9 @@
       {$else}
         ListView_SetItemText(ALV.Handle, AIndex, ASubIndex, PChar(AText));
       {$endif}
    +  if ALV.Column[ASubIndex].AutoSize then begin
    +    ListView_SetColumnWidth(ALV.Handle, ASubIndex, LVSCW_AUTOSIZE);
    +  end;
     end;
     
     class procedure TWin32WSCustomListView.ItemShow(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const PartialOK: Boolean);
    

Relationships

parent of 0012534 closedVincent Snijders Listview does not correctly set properties 
has duplicate 0016690 closedFelipe Monteiro de Carvalho TListView.columns[].Autosize problem 
has duplicate 0016946 closedFelipe Monteiro de Carvalho TListView column autosize problem in ToDo list 
related to 0007938 resolvedZeljan Rikalo Listview column autosize gtk2 
related to 0007937 closedFelipe Monteiro de Carvalho Listview column autosize win32 
related to 0017115 assignedDmitry Boyarintsev TListView Column.Autosize doesn't work in Carbon 

Activities

Vincent Snijders

2008-10-31 09:17

manager   ~0023053

Can you create a patch as described here: http://wiki.lazarus.freepascal.org/Creating_A_Patch

2008-11-01 00:24

 

win32lv.patch (2,081 bytes)
Index: lcl/interfaces/win32/win32wscustomlistview.inc
===================================================================
--- lcl/interfaces/win32/win32wscustomlistview.inc	(revision 17166)
+++ lcl/interfaces/win32/win32wscustomlistview.inc	(working copy)
@@ -457,6 +457,10 @@
   {$else}
     ListView_SetItemText(ALV.Handle, AIndex, ASubIndex, PChar(AText));
   {$endif}
+  //Forces the listview to recalculate the new width.
+  if ALV.Column[ASubIndex].AutoSize then begin
+    ListView_SetColumnWidth(ALV.Handle, ASubIndex, LVSCW_AUTOSIZE);
+  end;
 end;
 
 class procedure TWin32WSCustomListView.ItemShow(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const PartialOK: Boolean);
@@ -787,7 +791,7 @@
       lsInvert: begin
         Mask := Mask or LV_STYLES[Prop].Style;
 
-        if (LV_STYLES[Prop].StyleType = lsStyle) = (Prop in AProps)
+        if (LV_STYLES[Prop].StyleType = lsStyle) and (Prop in AProps)
         then Style := Style or LV_STYLES[Prop].Style
         else Style := Style and not LV_STYLES[Prop].Style;
       end;
@@ -846,11 +850,30 @@
 const
   //vsIcon, vsSmallIcon, vsList, vsReport
   STYLES: array[TViewStyle] of DWORD = (LVS_ICON, LVS_SMALLICON, LVS_LIST, LVS_REPORT);
+var
+  j: integer;
 begin
   if not WSCheckHandleAllocated(ALV, 'SetViewStyle')
   then Exit;
 
   UpdateStyle(ALV.Handle, LVS_TYPEMASK, STYLES[AValue]);
+
+  //Maybe this is not the proper fix but it should not
+  //present any permanent conflict as nothing is changed
+  //in the settings stablished by the user, only some data
+  //is resent.
+  if Avalue=vsReport then begin
+    //Restore size and autosize properties
+    for j := 0 to TListView(ALV).Columns.Count-1 do begin
+      with ALV.Column[j] do begin
+        if AutoSize then begin
+          ColumnSetAutoSize(ALV,j,ALV.Column[j],true);
+        end else begin
+          ColumnSetWidth(ALV,j,ALV.Column[j],Width);
+        end;
+      end;
+    end;
+  end;
 end;
 
 class procedure TWin32WSCustomListView.UpdateStyle(const AHandle: THandle; const AMask, AStyle: Integer);
win32lv.patch (2,081 bytes)

José Mejuto

2008-11-01 00:25

reporter   ~0023071

Patch for bugs:

http://bugs.freepascal.org/view.php?id=12533
http://bugs.freepascal.org/view.php?id=12534

both tested in win32 implementation only (only affects win32 items).

Marc Weustink

2009-01-08 16:42

administrator   ~0024288

* TWin32WSCustomListView.ItemSetText: OK

* SetViewStyle: this doesn't belong in the LCL, this should be part of the
widgetset, since some widgetset do this by themself correctly

* WSCreateColumn: WSC.ColumnSetAutosize(LV, Index, Self, FAutosize); should always be called, not only when true. IMO width too. LCL should not make assumptions on Widgetset implementation. (as in comment)

José Mejuto

2009-01-10 13:42

reporter   ~0024339

Please do not commit any patch, I think I can find a way more Delphi compatible and easy to patch. I'm not completly sure that new added items by "ItemSetText" must dynamically adjust the autosize or if the autosize is performed just after each full repaint.

Paul Ishenin

2009-02-19 09:09

manager   ~0025572

I'm moving this issue to post 1.2 since reporter dont want to apply his patch anymore and there are other questions. Maybe for that time all questions will be solved.

José Mejuto

2009-02-19 12:13

reporter   ~0025579

I'll try to write a LCL only patch but I wish to setup first a linux machine to verify that the changes do not alter other platforms in an unexpected way. Post 1.2 until a proper patch is written is OK for me.

sfeinst

2010-03-01 22:29

reporter   ~0034886

The latest issue update does not state a version (according to Issue History). Is this issue being looked at because it still exists.

2010-03-02 01:34

 

listviewautosizewin32.patch (1,334 bytes)
Index: include/listcolumn.inc
===================================================================
--- include/listcolumn.inc	(revision 23660)
+++ include/listcolumn.inc	(working copy)
@@ -94,7 +94,11 @@
   WSC.ColumnSetCaption(LV, Index, Self, FCaption);
   WSC.ColumnSetMaxWidth(LV, Index, Self, FMaxWidth);
   WSC.ColumnSetMinWidth(LV, Index, Self, FMinWidth);
-  WSC.ColumnSetWidth(LV, Index, Self, FWidth);
+  if FAutoSize then begin
+    WSC.ColumnSetAutosize(LV, Index, Self, FAutosize);
+  end else begin
+    WSC.ColumnSetWidth(LV, Index, Self, FWidth);
+  end;
   WSC.ColumnSetImage(LV, Index, Self, FImageIndex);
   WSC.ColumnSetVisible(LV, Index, Self, FVisible);
 end;
Index: interfaces/win32/win32wscustomlistview.inc
===================================================================
--- interfaces/win32/win32wscustomlistview.inc	(revision 23660)
+++ interfaces/win32/win32wscustomlistview.inc	(working copy)
@@ -666,6 +666,9 @@
   {$else}
     ListView_SetItemText(ALV.Handle, AIndex, ASubIndex, PChar(AText));
   {$endif}
+  if ALV.Column[ASubIndex].AutoSize then begin
+    ListView_SetColumnWidth(ALV.Handle, ASubIndex, LVSCW_AUTOSIZE);
+  end;
 end;
 
 class procedure TWin32WSCustomListView.ItemShow(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const PartialOK: Boolean);

José Mejuto

2010-03-02 01:37

reporter   ~0034890

I had added a new patch that fix win32 listview autosize only touching win32wscustomlistview and listcolumn.inc. Also tested GTK2 and I was unable to see any difference with previous behavior but I'm not used with GTK2.

Felipe Monteiro de Carvalho

2010-07-27 09:41

developer   ~0039721

Thanks, applied. This came in a good time, I was needing that fix =)

Issue History

Date Modified Username Field Change
2008-10-31 00:03 José Mejuto New Issue
2008-10-31 00:03 José Mejuto Widgetset => Win32
2008-10-31 09:17 Vincent Snijders LazTarget => 0.9.28
2008-10-31 09:17 Vincent Snijders Note Added: 0023053
2008-10-31 09:17 Vincent Snijders Status new => feedback
2008-10-31 09:17 Vincent Snijders Target Version => 0.9.28
2008-10-31 09:20 Vincent Snijders Relationship added related to 0007938
2008-11-01 00:24 José Mejuto File Added: win32lv.patch
2008-11-01 00:25 José Mejuto Note Added: 0023071
2008-12-07 21:35 Vincent Snijders Relationship added parent of 0012534
2009-01-08 16:42 Marc Weustink Note Added: 0024288
2009-01-10 13:42 José Mejuto Note Added: 0024339
2009-02-19 09:09 Paul Ishenin LazTarget 0.9.28 => post 1.2
2009-02-19 09:09 Paul Ishenin Note Added: 0025572
2009-02-19 12:13 José Mejuto Note Added: 0025579
2009-04-16 22:06 Vincent Snijders Status feedback => acknowledged
2009-04-16 22:06 Vincent Snijders Target Version 0.9.28 =>
2010-03-01 22:29 sfeinst Note Added: 0034886
2010-03-02 01:34 José Mejuto File Added: listviewautosizewin32.patch
2010-03-02 01:37 José Mejuto Note Added: 0034890
2010-04-27 04:27 Paul Ishenin Relationship added related to 0007937
2010-07-27 07:43 Felipe Monteiro de Carvalho Status acknowledged => assigned
2010-07-27 07:43 Felipe Monteiro de Carvalho Assigned To => Felipe Monteiro de Carvalho
2010-07-27 07:44 Felipe Monteiro de Carvalho LazTarget post 1.2 => 0.9.30
2010-07-27 09:41 Felipe Monteiro de Carvalho Fixed in Revision => 26846
2010-07-27 09:41 Felipe Monteiro de Carvalho Status assigned => resolved
2010-07-27 09:41 Felipe Monteiro de Carvalho Fixed in Version => 0.9.29 (SVN)
2010-07-27 09:41 Felipe Monteiro de Carvalho Resolution open => fixed
2010-07-27 09:41 Felipe Monteiro de Carvalho Note Added: 0039721
2010-08-05 15:46 Felipe Monteiro de Carvalho Relationship added related to 0017115
2010-08-05 15:46 Felipe Monteiro de Carvalho Relationship added has duplicate 0016690
2010-08-05 15:47 Felipe Monteiro de Carvalho Relationship added has duplicate 0016946
2010-08-06 13:49 José Mejuto Status resolved => closed