Steema Issues Database

Note: This database is for bugs and wishes only. For technical support help, if you are a customer please visit our online forums;
otherwise you can use StackOverflow.
Before using this bug-tracker we recommend a look at this document, Steema Bug Fixing Policy.



Bug 2437 - Auto width calculation does not work correctly if expander is shown
Summary: Auto width calculation does not work correctly if expander is shown
Status: RESOLVED FIXED
Alias: None
Product: TeeGrid for Delphi
Classification: Unclassified
Component: Grid (show other bugs)
Version: unspecified
Hardware: PC Windows
: --- enhancement
Target Milestone: ---
Assignee: david berneda
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-24 23:58 EDT by dean.mustakinov
Modified: 2022-11-16 03:37 EST (History)
1 user (show)

See Also:
Chart Series: ---
Delphi / C++ Builder RAD IDE Version:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dean.mustakinov 2021-06-24 23:58:11 EDT
When expander is shown in a column the automatic width calculation does not take it into account.

I have made a small change to fix this (my changes are marked with // DM CHANGE comments).
Tee.Grid.RowGroup.pas:

function TRowGroup.CalcAutoWidth(const APainter:TPainter; const AColumn:TColumn;
                                 const AWidth:Single):Single;

  function CustomColumnMargins:TMargins;
  begin
    if AColumn.HasRender then
       result:=AColumn.Margins
    else
    if TTextRenderAccess(Cells).HasMargins then
       result:=Cells.Margins
    else
       result:=nil;
  end;

  function HeaderWidth:Single;
  begin
    if Header.Visible then
       result:=Header.AutoWidth(APainter,AColumn)
    else
       result:=0;
  end;

var tmp : Single;
    rw : Single; // DM CHANGE
    tmpMargins : TMargins;
begin
  result:=HeaderWidth;

  if AColumn.HasItems then
     tmp:=WidthOf(APainter,AColumn.Items,AWidth)
  else
  if Data=nil then
     tmp:=0
  else
  begin
    APainter.SetFont(Rows.FontOf(AColumn));

    // DM CHANGE START
    if (AColumn.Render <> nil) and (AColumn.Render is TBoxRender) then
      rw := TBoxRender(AColumn.Render).Box.Size * 3 // roughly
    else
      rw := 0;
    // DM CHANGE END

    tmp:=TColumnAccess(AColumn).AutoWidth(APainter);

    if tmp=0 then
    begin
      tmp:=Data.AutoWidth(APainter,AColumn) + rw; // DM CHANGE

      tmpMargins:=CustomColumnMargins;

      if tmpMargins<>nil then
      begin
        tmpMargins.Prepare(tmp,0);
        tmp:=tmp+tmpMargins.Horizontal;
      end;
    end
    else tmp := tmp + rw; // DM CHANGE

    if tmp<MinColumnWidth then
       tmp:=MinColumnWidth;
  end;

  if tmp>result then
     result:=tmp;
end;