View Issue Details

IDProjectCategoryView StatusLast Update
0025902LazarusLCLpublic2014-10-13 10:13
ReporterwpAssigned ToJesus Reyes 
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionfixed 
Platformx86OSWindowsOS VersionWin7
Product Version1.3 (SVN)Product Build 
Target Version1.4Fixed in Version1.3 (SVN) 
Summary0025902: Feature request: Multiline column titles for TStringGrid
DescriptionSometimes it would be nice to be able to show column titles of a string grid in multiple lines. There is a possibility to achieve this by means of the OnPrepareCanvas event, but it would be more straightforward for the application developer to have this feature directly avaiable in the Object Inspector.

The attached patch
- implements the correct property editor for the GridColumnTitle.Caption such that multiline text can be entered in the OI
- adds a property "Multiline" to TGridColumnTitle

See the attached project for a demonstration.
TagsNo tags attached.
Fixed in Revision44781
LazTarget1.4
Widgetset
Attached Files
  • multiline_gridtitles.patch (3,761 bytes)
    Index: components/ideintf/propedits.pp
    ===================================================================
    --- components/ideintf/propedits.pp	(revision 44473)
    +++ components/ideintf/propedits.pp	(working copy)
    @@ -1602,6 +1602,9 @@
     
     implementation
     
    +uses
    +  Grids;
    +
     var
       ListPropertyEditors: TList = nil;
       VirtualKeyStrings: TStringHashList = nil;
    @@ -6801,6 +6804,7 @@
       RegisterPropertyEditor(TypeInfo(TTranslateString), TCustomStaticText, 'Caption', TStringMultilinePropertyEditor);
       RegisterPropertyEditor(TypeInfo(TTranslateString), TCustomCheckBox, 'Caption', TStringMultilinePropertyEditor);
       RegisterPropertyEditor(TypeInfo(TTranslateString), TComponent, 'Hint', TStringMultilinePropertyEditor);
    +  RegisterPropertyEditor(TypeInfo(TCaption), TGridColumnTitle, 'Caption', TStringMultilinePropertyEditor);
       RegisterPropertyEditor(TypeInfo(TTabOrder), TControl, 'TabOrder', TTabOrderPropertyEditor);
       RegisterPropertyEditor(TypeInfo(ShortString), nil, '', TCaptionPropertyEditor);
       RegisterPropertyEditor(TypeInfo(TStrings), nil, '', TStringsPropertyEditor);
    Index: lcl/grids.pas
    ===================================================================
    --- lcl/grids.pas	(revision 44473)
    +++ lcl/grids.pas	(working copy)
    @@ -405,9 +405,10 @@
         FIsDefaultTitleFont: boolean;
         FLayout: ^TTextLayout;
         FPrefixOption: TPrefixOption;
    +    FMultiline: Boolean;
         procedure FontChanged(Sender: TObject);
         function GetAlignment: TAlignment;
    -    function GetCaption: string;
    +    function GetCaption: TCaption; //string;
         function GetColor: TColor;
         function GetFont: TFont;
         function GetLayout: TTextLayout;
    @@ -422,6 +423,7 @@
         procedure SetImageIndex(const AValue: Integer);
         procedure SetImageLayout(const AValue: TButtonLayout);
         procedure SetLayout(const AValue: TTextLayout);
    +    procedure SetMultiLine(const AValue: Boolean);
         procedure SetPrefixOption(const AValue: TPrefixOption);
         property IsDefaultFont: boolean read FIsDefaultTitleFont;
       protected
    @@ -446,6 +448,7 @@
         property ImageIndex: Integer read FImageIndex write SetImageIndex default -1;
         property ImageLayout: TButtonLayout read FImageLayout write SetImageLayout default blGlyphRight;
         property Layout: TTextLayout read GetLayout write SetLayout stored IsLayoutStored;
    +    property MultiLine: Boolean read FMultiLine write SetMultiLine;
         property PrefixOption: TPrefixOption read FPrefixOption write SetPrefixOption default poNone;
       end;
     
    @@ -3494,6 +3497,7 @@
       AColor: TColor;
       CurrentTextStyle: TTextStyle;
       IsSelected: boolean;
    +  gc: TGridColumn;
     begin
       if DefaultDrawing then begin
         Canvas.Pen.Mode := pmCopy;
    @@ -3529,6 +3533,8 @@
         CurrentTextStyle.ShowPrefix := ((gdFixed in aState) and (aRow < FFixedRows)) and GetTitleShowPrefix(aCol);
         CurrentTextStyle.RightToLeft := UseRightToLeftReading;
         CurrentTextStyle.EndEllipsis := (goCellEllipsis in Options);
    +    gc := ColumnFromGridColumn(aCol);
    +    CurrentTextStyle.SingleLine := (gc = nil) or (not gc.Title.MultiLine);
         Canvas.TextStyle := CurrentTextStyle;
       end else begin
         Canvas.TextStyle := DefaultTextStyle;
    @@ -10743,7 +10749,7 @@
         result := FAlignment^;
     end;
     
    -function TGridColumnTitle.GetCaption: string;
    +function TGridColumnTitle.GetCaption: TCaption; //string;
     begin
       if FCaption = nil then
         result := GetDefaultCaption
    @@ -10875,6 +10881,13 @@
       FColumn.ColumnChanged;
     end;
     
    +procedure TGridColumnTitle.SetMultiLine(const AValue: Boolean);
    +begin
    +  if FMultiLine = AValue then exit;
    +  FMultiLine := AValue;
    +  FColumn.ColumnChanged;
    +end;
    +
     procedure TGridColumnTitle.SetPrefixOption(const AValue: TPrefixOption);
     begin
       if FPrefixOption=AValue then exit;
    
  • StringGrid_MultiLine_Titles.zip (2,076 bytes)

Activities

wp

2014-03-22 15:20

developer  

multiline_gridtitles.patch (3,761 bytes)
Index: components/ideintf/propedits.pp
===================================================================
--- components/ideintf/propedits.pp	(revision 44473)
+++ components/ideintf/propedits.pp	(working copy)
@@ -1602,6 +1602,9 @@
 
 implementation
 
+uses
+  Grids;
+
 var
   ListPropertyEditors: TList = nil;
   VirtualKeyStrings: TStringHashList = nil;
@@ -6801,6 +6804,7 @@
   RegisterPropertyEditor(TypeInfo(TTranslateString), TCustomStaticText, 'Caption', TStringMultilinePropertyEditor);
   RegisterPropertyEditor(TypeInfo(TTranslateString), TCustomCheckBox, 'Caption', TStringMultilinePropertyEditor);
   RegisterPropertyEditor(TypeInfo(TTranslateString), TComponent, 'Hint', TStringMultilinePropertyEditor);
+  RegisterPropertyEditor(TypeInfo(TCaption), TGridColumnTitle, 'Caption', TStringMultilinePropertyEditor);
   RegisterPropertyEditor(TypeInfo(TTabOrder), TControl, 'TabOrder', TTabOrderPropertyEditor);
   RegisterPropertyEditor(TypeInfo(ShortString), nil, '', TCaptionPropertyEditor);
   RegisterPropertyEditor(TypeInfo(TStrings), nil, '', TStringsPropertyEditor);
Index: lcl/grids.pas
===================================================================
--- lcl/grids.pas	(revision 44473)
+++ lcl/grids.pas	(working copy)
@@ -405,9 +405,10 @@
     FIsDefaultTitleFont: boolean;
     FLayout: ^TTextLayout;
     FPrefixOption: TPrefixOption;
+    FMultiline: Boolean;
     procedure FontChanged(Sender: TObject);
     function GetAlignment: TAlignment;
-    function GetCaption: string;
+    function GetCaption: TCaption; //string;
     function GetColor: TColor;
     function GetFont: TFont;
     function GetLayout: TTextLayout;
@@ -422,6 +423,7 @@
     procedure SetImageIndex(const AValue: Integer);
     procedure SetImageLayout(const AValue: TButtonLayout);
     procedure SetLayout(const AValue: TTextLayout);
+    procedure SetMultiLine(const AValue: Boolean);
     procedure SetPrefixOption(const AValue: TPrefixOption);
     property IsDefaultFont: boolean read FIsDefaultTitleFont;
   protected
@@ -446,6 +448,7 @@
     property ImageIndex: Integer read FImageIndex write SetImageIndex default -1;
     property ImageLayout: TButtonLayout read FImageLayout write SetImageLayout default blGlyphRight;
     property Layout: TTextLayout read GetLayout write SetLayout stored IsLayoutStored;
+    property MultiLine: Boolean read FMultiLine write SetMultiLine;
     property PrefixOption: TPrefixOption read FPrefixOption write SetPrefixOption default poNone;
   end;
 
@@ -3494,6 +3497,7 @@
   AColor: TColor;
   CurrentTextStyle: TTextStyle;
   IsSelected: boolean;
+  gc: TGridColumn;
 begin
   if DefaultDrawing then begin
     Canvas.Pen.Mode := pmCopy;
@@ -3529,6 +3533,8 @@
     CurrentTextStyle.ShowPrefix := ((gdFixed in aState) and (aRow < FFixedRows)) and GetTitleShowPrefix(aCol);
     CurrentTextStyle.RightToLeft := UseRightToLeftReading;
     CurrentTextStyle.EndEllipsis := (goCellEllipsis in Options);
+    gc := ColumnFromGridColumn(aCol);
+    CurrentTextStyle.SingleLine := (gc = nil) or (not gc.Title.MultiLine);
     Canvas.TextStyle := CurrentTextStyle;
   end else begin
     Canvas.TextStyle := DefaultTextStyle;
@@ -10743,7 +10749,7 @@
     result := FAlignment^;
 end;
 
-function TGridColumnTitle.GetCaption: string;
+function TGridColumnTitle.GetCaption: TCaption; //string;
 begin
   if FCaption = nil then
     result := GetDefaultCaption
@@ -10875,6 +10881,13 @@
   FColumn.ColumnChanged;
 end;
 
+procedure TGridColumnTitle.SetMultiLine(const AValue: Boolean);
+begin
+  if FMultiLine = AValue then exit;
+  FMultiLine := AValue;
+  FColumn.ColumnChanged;
+end;
+
 procedure TGridColumnTitle.SetPrefixOption(const AValue: TPrefixOption);
 begin
   if FPrefixOption=AValue then exit;

wp

2014-03-22 15:20

developer  

StringGrid_MultiLine_Titles.zip (2,076 bytes)

Jesus Reyes

2014-04-22 02:36

developer   ~0074504

Applied with small change.

Issue History

Date Modified Username Field Change
2014-03-22 15:20 wp New Issue
2014-03-22 15:20 wp File Added: multiline_gridtitles.patch
2014-03-22 15:20 wp File Added: StringGrid_MultiLine_Titles.zip
2014-04-15 05:03 Jesus Reyes Assigned To => Jesus Reyes
2014-04-15 05:03 Jesus Reyes Status new => assigned
2014-04-22 02:36 Jesus Reyes Fixed in Revision => 44781
2014-04-22 02:36 Jesus Reyes LazTarget => 1.4
2014-04-22 02:36 Jesus Reyes Note Added: 0074504
2014-04-22 02:36 Jesus Reyes Status assigned => resolved
2014-04-22 02:36 Jesus Reyes Fixed in Version => 1.3 (SVN)
2014-04-22 02:36 Jesus Reyes Resolution open => fixed
2014-04-22 02:36 Jesus Reyes Target Version => 1.4
2014-10-13 10:13 wp Status resolved => closed