Listview autosize does not work.
Original Reporter info from Mantis: JoshyFun @joshyfun
-
Reporter name: José Mejuto
Original Reporter info from Mantis: JoshyFun @joshyfun
- Reporter name: José Mejuto
Description:
Setting a column to be "Autosize" does not work.
Steps to reproduce:
Set a column content to be autosize.
Additional information:
A proposed patch involves several functions of "lcl\interfaces\win32\win32wscustomlistview.inc"
"TWin32WSCustomListView.ItemSetText" add just before the function end:
\****************<br/>
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.
Mantis conversion info:
- Mantis ID: 12533
- OS: Win32 maybe Win64
- OS Build: All
- Platform: x86
- Version: 0.9.27 (SVN)
- Fixed in version: 0.9.29 (SVN)
- Fixed in revision: 26846 (#72d00b69)
- Target version: 0.9.30