From 5cfeeee16ee77e0bfda4cb8b185b9a9dc2e3eded Mon Sep 17 00:00:00 2001 From: alexs75 Date: Wed, 17 Oct 2012 13:17:40 +0000 Subject: [PATCH] RxDBGrid - allow word wrap in data cell. For details see RxDBGrid demo git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2568 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi | 383 ++++++++++-------- .../rx/Demos/RxDBGrid/rxdbgridmainunit.lfm | 14 + .../rx/Demos/RxDBGrid/rxdbgridmainunit.pas | 10 + components/rx/rxdbgrid.pas | 174 +++++++- 4 files changed, 403 insertions(+), 178 deletions(-) diff --git a/components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi b/components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi index 06159c460..30399a8b0 100644 --- a/components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi +++ b/components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi @@ -54,7 +54,7 @@ - + @@ -62,7 +62,7 @@ - + @@ -73,9 +73,9 @@ - - - + + + @@ -84,20 +84,20 @@ - + - + - + @@ -105,7 +105,7 @@ - + @@ -116,73 +116,73 @@ - + - + - + - + - + - + - + - + - + - + - + @@ -192,75 +192,75 @@ - + - + - + - + - + - + - + - + - + - + - + @@ -269,41 +269,41 @@ - + - + - + - + - + - + @@ -313,21 +313,21 @@ - + - + - + @@ -337,7 +337,7 @@ - + @@ -347,49 +347,49 @@ - + - + - + - + - + - + - + @@ -399,7 +399,7 @@ - + @@ -407,7 +407,7 @@ - + @@ -415,7 +415,7 @@ - + @@ -423,14 +423,14 @@ - + - + @@ -438,7 +438,7 @@ - + @@ -446,14 +446,14 @@ - + - + @@ -461,14 +461,14 @@ - + - + @@ -477,14 +477,14 @@ - + - + @@ -492,33 +492,32 @@ - + + - - - - - - - - + + + + + + + - - - - + + + @@ -526,9 +525,9 @@ - - - + + + @@ -536,7 +535,7 @@ - + @@ -544,7 +543,7 @@ - + @@ -552,7 +551,7 @@ - + @@ -560,14 +559,14 @@ - + - + @@ -575,21 +574,21 @@ - + - + - + @@ -600,7 +599,7 @@ - + @@ -611,21 +610,21 @@ - + - - - + + + - + @@ -633,7 +632,7 @@ - + @@ -641,7 +640,7 @@ - + @@ -649,7 +648,7 @@ - + @@ -657,21 +656,21 @@ - + - + - + @@ -679,7 +678,7 @@ - + @@ -687,25 +686,23 @@ - + - - - + - - - + + + @@ -713,7 +710,7 @@ - + @@ -721,7 +718,7 @@ - + @@ -729,129 +726,181 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - - + + - + - + - - + + - - + + - - + + - + - + - - + + - - + + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + + + + + + + + + @@ -880,16 +929,22 @@ - + - + - + - + + + + + + + diff --git a/components/rx/Demos/RxDBGrid/rxdbgridmainunit.lfm b/components/rx/Demos/RxDBGrid/rxdbgridmainunit.lfm index f1c9f6f63..735113a85 100644 --- a/components/rx/Demos/RxDBGrid/rxdbgridmainunit.lfm +++ b/components/rx/Demos/RxDBGrid/rxdbgridmainunit.lfm @@ -90,6 +90,7 @@ object RxDBGridMainForm: TRxDBGridMainForm Filter.EmptyFont.Style = [fsItalic] Filter.ItemIndex = -1 EditButtons = <> + WordWrap = True end item Title.Alignment = taCenter @@ -392,6 +393,19 @@ object RxDBGridMainForm: TRxDBGridMainForm State = cbChecked TabOrder = 6 end + object CheckBox5: TCheckBox + AnchorSideLeft.Control = CheckBox3 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = Panel1 + Left = 721 + Height = 22 + Top = 7 + Width = 90 + BorderSpacing.Around = 6 + Caption = 'Word wrap' + OnChange = CheckBox5Change + TabOrder = 7 + end end object SpeedButton1: TSpeedButton Left = 596 diff --git a/components/rx/Demos/RxDBGrid/rxdbgridmainunit.pas b/components/rx/Demos/RxDBGrid/rxdbgridmainunit.pas index 1746140dd..531e2fb1a 100644 --- a/components/rx/Demos/RxDBGrid/rxdbgridmainunit.pas +++ b/components/rx/Demos/RxDBGrid/rxdbgridmainunit.pas @@ -15,6 +15,7 @@ type TRxDBGridMainForm = class(TForm) actCalcTotal: TAction; + CheckBox5: TCheckBox; MenuItem10: TMenuItem; MenuItem11: TMenuItem; MenuItem8: TMenuItem; @@ -69,6 +70,7 @@ type procedure CheckBox2Change(Sender: TObject); procedure CheckBox3Change(Sender: TObject); procedure CheckBox4Change(Sender: TObject); + procedure CheckBox5Change(Sender: TObject); procedure ComboBox1Change(Sender: TObject); procedure FormCreate(Sender: TObject); procedure hlpAboutExecute(Sender: TObject); @@ -252,6 +254,14 @@ begin RxDBGrid1.Options:=RxDBGrid1.Options - [dgTitles]; end; +procedure TRxDBGridMainForm.CheckBox5Change(Sender: TObject); +begin + if CheckBox5.Checked then + RxDBGrid1.OptionsRx:=RxDBGrid1.OptionsRx + [rdgWordWrap] + else + RxDBGrid1.OptionsRx:=RxDBGrid1.OptionsRx - [rdgWordWrap]; +end; + procedure TRxDBGridMainForm.ComboBox1Change(Sender: TObject); begin RxDBGrid1.ReadOnly:=ComboBox1.ItemIndex <> 0; diff --git a/components/rx/rxdbgrid.pas b/components/rx/rxdbgrid.pas index 4fd3ee683..bc473d3ec 100644 --- a/components/rx/rxdbgrid.pas +++ b/components/rx/rxdbgrid.pas @@ -91,7 +91,8 @@ type rdgAllowFilterForm, rdgAllowSortForm, rdgAllowToolMenu, - rdgCaseInsensitiveSort + rdgCaseInsensitiveSort, + rdgWordWrap ); TOptionsRx = set of TOptionRx; @@ -364,6 +365,7 @@ type FOnDrawColumnCell: TDrawColumnCellEvent; FSortOrder: TSortMarker; FSortPosition: integer; + FWordWrap: boolean; function GetFooter: TRxColumnFooter; function GetKeyList: TStrings; procedure SetEditButtons(AValue: TRxColumnEditButtons); @@ -372,6 +374,7 @@ type procedure SetImageList(const AValue: TImageList); procedure SetKeyList(const AValue: TStrings); procedure SetNotInKeyListIndex(const AValue: integer); + procedure SetWordWrap(AValue: boolean); protected function CreateTitle: TGridColumnTitle; override; public @@ -390,6 +393,7 @@ type property DirectInput : boolean read FDirectInput write FDirectInput default true; property EditButtons:TRxColumnEditButtons read FEditButtons write SetEditButtons; property OnDrawColumnCell: TDrawColumnCellEvent read FOnDrawColumnCell write FOnDrawColumnCell; + property WordWrap:boolean read FWordWrap write SetWordWrap default false; end; { TRxDbGridColumns } @@ -541,6 +545,9 @@ type procedure CollumnSortListUpdate; procedure CollumnSortListClear; procedure CollumnSortListApply; + + procedure UpdateRowsHeight; + procedure ResetRowHeght; protected function DatalinkActive: boolean; procedure LinkActive(Value: Boolean); override; @@ -577,6 +584,7 @@ type procedure UpdateActive; override; procedure UpdateData; override; procedure MoveSelection; override; + //function GetBufferCount: integer; override; procedure CMHintShow(var Message: TLMessage); message CM_HINTSHOW; procedure FFilterListEditorOnChange(Sender: TObject); procedure FFilterListEditorOnCloseUp(Sender: TObject); @@ -847,7 +855,7 @@ type public constructor Create(Aowner : TComponent); override; - // procedure SetBounds(aLeft, aTop, aWidth, aHeight: integer); override; + //procedure SetBounds(aLeft, aTop, aWidth, aHeight: integer); override; procedure EditingDone; override; end; @@ -1196,13 +1204,15 @@ begin UpdateMask; end; -{procedure TRxDBGridDateEditor.SetBounds(aLeft, aTop, aWidth, aHeight: integer); +{ +procedure TRxDBGridDateEditor.SetBounds(aLeft, aTop, aWidth, aHeight: integer); begin BeginUpdateBounds; - Dec(aWidth, 25); + Dec(aWidth, 25); //ButtonWidth); inherited SetBounds(aLeft, aTop, aWidth, aHeight); EndUpdateBounds; -end;} +end; +} procedure TRxDBGridDateEditor.EditingDone; begin @@ -1698,6 +1708,10 @@ begin end; FFooterOptions.FActive:=rdgFooterRows in FOptionsRx; + + if (rdgWordWrap in OldOpt) and not (rdgWordWrap in FOptionsRx) then + ResetRowHeght; + VisualChange; end; @@ -2294,6 +2308,58 @@ begin FSortingNow:=false; end; +procedure TRxDBGrid.UpdateRowsHeight; +var + i, J, H, H1:integer; + B:boolean; + F:TField; + S:string; + CurActiveRecord: Integer; + R:TRxColumn; +begin + if not (Assigned(DataLink) and DataLink.Active) then + exit; + + CurActiveRecord:=DataLink.ActiveRecord; + for i:=GCache.VisibleGrid.Top to GCache.VisibleGrid.Bottom do + begin + DataLink.ActiveRecord:=i - FixedRows; + H:=1; + for j:=0 to Columns.Count-1 do + begin + R:=Columns[j] as TRxColumn;; + if R.WordWrap then + begin + F:=R.Field; + if Assigned(F) then + S:=F.DisplayText + else + S:=''; + + H1 := Max((Canvas.TextWidth(S) + 2) div R.Width + 1, H); + if H1 > WordCount(S, [' ']) then + H1 := WordCount(S, [' ']); + end + else + H1:=1; + H:=Max(H, H1); + end; + + if i WordCount(S, [' ']) then + H1 := WordCount(S, [' ']); + end; + H:=Max(H, H1); + end; + HW:=HW + H * DefaultRowHeight; + + if HW>Height then + break; + + RowHeights[K] := DefaultRowHeight * H; + + inc(K); + inc(Result); + end; + DataLink.ActiveRecord:=CurActiveRecord; +{ + if (ARow>=FixedRows) and FDataLink.Active then + begin + FDataLink.ActiveRecord:=ARow-FixedRows; + FDrawingActiveRecord := ARow = Row; + FDrawingMultiSelRecord := (dgMultiSelect in Options) and + SelectedRows.CurrentRowSelected + end else begin + FDrawingActiveRecord := False; + FDrawingMultiSelRecord := False; + end; + + } + end; +end; +*) + procedure TRxDBGrid.CMHintShow(var Message: TLMessage); var Cell: TGridCoord; @@ -3440,8 +3578,10 @@ end; procedure TRxDBGrid.VisualChange; begin inherited VisualChange; - // if Canvas.HandleAllocated then CalcTitle; + + if rdgWordWrap in FOptionsRx then + UpdateRowsHeight; end; function TRxDBGrid.EditorByStyle(Style: TColumnButtonStyle): TWinControl; @@ -4202,6 +4342,12 @@ begin Grid.Invalidate; end; +procedure TRxColumn.SetWordWrap(AValue: boolean); +begin + if FWordWrap=AValue then Exit; + FWordWrap:=AValue; +end; + function TRxColumn.CreateTitle: TGridColumnTitle; begin Result := TRxColumnTitle.Create(Self);