View Issue Details

IDProjectCategoryView StatusLast Update
0028144LazarusPatchpublic2015-05-20 18:47
ReporterValdas JankūnasAssigned ToJesus Reyes 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformlinux 64bOSKubuntu OS Version
Product Version1.5 (SVN)Product Build49119 
Target Version1.6Fixed in Version1.5 (SVN) 
Summary0028144: [LCL, Grids] correction in AutoAdjustColumn of TStringGrid
DescriptionTo calculate width of column code uses DrawText with DT_CALCRECT. But there is line of rect initialization:

aRect := rect(0, 0, DefaultColWidth, DefaultRowHeight);

which prevents autosizing: DrawText returns rect that is no wider than DefaultColWidth.

Solution is: aRect := Rect(0, 0, MaxInt, MaxInt);

Tried in Linux (QT) and Windows 7.
TagsNo tags attached.
Fixed in Revision49120
LazTarget1.6
WidgetsetWin32/Win64, QT
Attached Files
  • autosize.diff (518 bytes)
    Index: lcl/grids.pas
    ===================================================================
    --- lcl/grids.pas	(revision 49119)
    +++ lcl/grids.pas	(working copy)
    @@ -10421,7 +10421,7 @@
             aText := Cells[aCol, i];
     
           if isMultiLine then begin
    -        aRect := rect(0, 0, DefaultColWidth, DefaultRowHeight);
    +        aRect := Rect(0, 0, MaxInt, MaxInt);
             DrawText(tmpCanvas.Handle, @aText[1], Length(aText), aRect, DT_CALCRECT or DT_WORDBREAK);
             Ts.cx := aRect.Right-aRect.Left;
           end else
    
    autosize.diff (518 bytes)
  • autosize_2.diff (711 bytes)
    Index: lcl/grids.pas
    ===================================================================
    --- lcl/grids.pas	(revision 49119)
    +++ lcl/grids.pas	(working copy)
    @@ -10419,10 +10419,9 @@
             aText := C.Title.Caption
           else
             aText := Cells[aCol, i];
    -
           if isMultiLine then begin
    -        aRect := rect(0, 0, DefaultColWidth, DefaultRowHeight);
    -        DrawText(tmpCanvas.Handle, @aText[1], Length(aText), aRect, DT_CALCRECT or DT_WORDBREAK);
    +        aRect := Rect(0, 0, MaxInt, MaxInt);
    +        DrawText(tmpCanvas.Handle, PChar(aText), Length(aText), aRect, DT_CALCRECT or DT_WORDBREAK);
             Ts.cx := aRect.Right-aRect.Left;
           end else
             Ts := tmpCanvas.TextExtent(aText);
    
    autosize_2.diff (711 bytes)

Activities

Valdas Jankūnas

2015-05-20 16:12

reporter  

autosize.diff (518 bytes)
Index: lcl/grids.pas
===================================================================
--- lcl/grids.pas	(revision 49119)
+++ lcl/grids.pas	(working copy)
@@ -10421,7 +10421,7 @@
         aText := Cells[aCol, i];
 
       if isMultiLine then begin
-        aRect := rect(0, 0, DefaultColWidth, DefaultRowHeight);
+        aRect := Rect(0, 0, MaxInt, MaxInt);
         DrawText(tmpCanvas.Handle, @aText[1], Length(aText), aRect, DT_CALCRECT or DT_WORDBREAK);
         Ts.cx := aRect.Right-aRect.Left;
       end else
autosize.diff (518 bytes)

Valdas Jankūnas

2015-05-20 18:13

reporter   ~0083844

Found another bug in next line: DrawText(..., @aText[1],...) causes Exception with empty cells. Attaching new patch (previous is obsolete).

Valdas Jankūnas

2015-05-20 18:13

reporter  

autosize_2.diff (711 bytes)
Index: lcl/grids.pas
===================================================================
--- lcl/grids.pas	(revision 49119)
+++ lcl/grids.pas	(working copy)
@@ -10419,10 +10419,9 @@
         aText := C.Title.Caption
       else
         aText := Cells[aCol, i];
-
       if isMultiLine then begin
-        aRect := rect(0, 0, DefaultColWidth, DefaultRowHeight);
-        DrawText(tmpCanvas.Handle, @aText[1], Length(aText), aRect, DT_CALCRECT or DT_WORDBREAK);
+        aRect := Rect(0, 0, MaxInt, MaxInt);
+        DrawText(tmpCanvas.Handle, PChar(aText), Length(aText), aRect, DT_CALCRECT or DT_WORDBREAK);
         Ts.cx := aRect.Right-aRect.Left;
       end else
         Ts := tmpCanvas.TextExtent(aText);
autosize_2.diff (711 bytes)

Jesus Reyes

2015-05-20 18:37

developer   ~0083847

Applied, thanks.

Issue History

Date Modified Username Field Change
2015-05-20 16:12 Valdas Jankūnas New Issue
2015-05-20 16:12 Valdas Jankūnas File Added: autosize.diff
2015-05-20 16:25 Zeljan Rikalo Assigned To => Jesus Reyes
2015-05-20 16:25 Zeljan Rikalo Status new => assigned
2015-05-20 18:13 Valdas Jankūnas Note Added: 0083844
2015-05-20 18:13 Valdas Jankūnas File Added: autosize_2.diff
2015-05-20 18:37 Jesus Reyes Fixed in Revision => 49120
2015-05-20 18:37 Jesus Reyes LazTarget => 1.6
2015-05-20 18:37 Jesus Reyes Note Added: 0083847
2015-05-20 18:37 Jesus Reyes Status assigned => resolved
2015-05-20 18:37 Jesus Reyes Fixed in Version => 1.5 (SVN)
2015-05-20 18:37 Jesus Reyes Resolution open => fixed
2015-05-20 18:37 Jesus Reyes Target Version => 1.6
2015-05-20 18:47 Valdas Jankūnas Status resolved => closed