Permalink
Browse files

Fix growing column widths of VirtualTrees through SaveListSetup and R…

…estoreListSetup. Related to #446, see #446 (comment)
  • Loading branch information...
ansgarbecker committed Dec 22, 2018
1 parent e61c87f commit 0f700d1b0c43e03227f9c54fd67d606bafffd3e1
Showing with 13 additions and 6 deletions.
  1. +13 −6 source/main.pas
@@ -7127,19 +7127,27 @@ procedure TMainForm.AnyGridAfterPaint(Sender: TBaseVirtualTree;
}
procedure TMainForm.SaveListSetup( List: TVirtualStringTree );
var
i : Byte;
i, ColWidth: Integer;
ColWidths, ColsVisible, ColPos, Regname: String;
OwnerForm: TWinControl;
IsFrame: Boolean;
ScaleDownFactor: Double;
begin
ColWidths := '';
ColsVisible := '';
ColPos := '';
OwnerForm := GetParentFormOrFrame(List);
IsFrame := OwnerForm is TFrame;
ScaleDownFactor := DpiScaleFactor(GetParentForm(List) as TForm);
for i := 0 to List.Header.Columns.Count - 1 do
begin
// Column widths
if ColWidths <> '' then
ColWidths := ColWidths + ',';
ColWidths := ColWidths + IntToStr(List.Header.Columns[i].Width);
ColWidth := List.Header.Columns[i].Width;
if IsFrame then
ColWidth := Round(ColWidth / ScaleDownFactor);
ColWidths := ColWidths + IntToStr(ColWidth);

// Column visibility
if coVisible in List.Header.Columns[i].Options then
@@ -7156,15 +7164,14 @@ procedure TMainForm.SaveListSetup( List: TVirtualStringTree );

end;

// Lists can have the same name over different forms or frames. Find parent form or frame,
// so we can prepend its name into the registry value name.
OwnerForm := GetParentFormOrFrame(List);
// On a windows shutdown, GetParentForm() seems sporadically unable to find the owner form
// In that case we would cause an exception when accessing it. Emergency break in that case.
// See issue #1462
// TODO: Test this, probably fixed by implementing GetParentFormOrFrame, and then again, probably not.
if not Assigned(OwnerForm) then
Exit;
// Lists can have the same name over different forms or frames. Find parent form or frame,
// so we can prepend its name into the registry value name.
Regname := OwnerForm.Name + '.' + List.Name;
AppSettings.ResetPath;
AppSettings.WriteString(asListColWidths, ColWidths, Regname);
@@ -7198,7 +7205,7 @@ procedure TMainForm.RestoreListSetup( List: TVirtualStringTree );
begin
colwidth := MakeInt(ValueList[i]);
// Check if column number exists and width is at least 1 pixel
if (List.Header.Columns.Count > i) and (colwidth > 0) then
if (List.Header.Columns.Count > i) and (colwidth > 0) and (colwidth < 1000) then
List.Header.Columns[i].Width := colwidth;
end;
end;

0 comments on commit 0f700d1

Please sign in to comment.