From c426bc5e166292e7f0d752455357d5ebde9ef9a4 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Tue, 2 Mar 2010 23:11:48 +0000 Subject: [PATCH] Enable variable node height in data and query grids. Customizable as number of lines per row. Fixes issue #1082. --- source/const.inc | 2 ++ source/main.dfm | 22 +++++++------- source/main.pas | 45 ++++++++++++++++++++++------- source/options.dfm | 71 ++++++++++++++++++++++++++++++++-------------- source/options.pas | 8 ++++++ 5 files changed, 107 insertions(+), 41 deletions(-) diff --git a/source/const.inc b/source/const.inc index 581e754e..ece44882 100644 --- a/source/const.inc +++ b/source/const.inc @@ -80,6 +80,8 @@ const DEFAULT_MAXTOTALROWS = 100000; REGNAME_ROWSPERSTEP = 'DatagridRowsPerStep'; DEFAULT_ROWSPERSTEP = 1000; + REGNAME_GRIDROWSLINECOUNT = 'GridRowLineCount'; + DEFAULT_GRIDROWSLINECOUNT = 1; REGNAME_REMEMBERFILTERS = 'RememberFilters'; DEFAULT_REMEMBERFILTERS = True; REGNAME_LOGTOFILE = 'LogToFile'; diff --git a/source/main.dfm b/source/main.dfm index c9db33e4..3ba362ce 100644 --- a/source/main.dfm +++ b/source/main.dfm @@ -1228,12 +1228,12 @@ object MainForm: TMainForm PopupMenu = popupDataGrid TabOrder = 2 TreeOptions.AutoOptions = [toAutoDropExpand, toAutoScroll, toAutoScrollOnExpand, toAutoTristateTracking, toAutoDeleteMovedNodes] - TreeOptions.MiscOptions = [toAcceptOLEDrop, toEditable, toFullRepaintOnResize, toGridExtensions, toInitOnSave, toToggleOnDblClick, toWheelPanning, toEditOnClick] + TreeOptions.MiscOptions = [toAcceptOLEDrop, toEditable, toFullRepaintOnResize, toGridExtensions, toInitOnSave, toToggleOnDblClick, toWheelPanning, toVariableNodeHeight, toEditOnClick] TreeOptions.PaintOptions = [toShowButtons, toShowDropmark, toShowHorzGridLines, toShowVertGridLines, toThemeAware, toUseBlendedImages, toAlwaysHideSelection] TreeOptions.SelectionOptions = [toExtendedFocus, toFullRowSelect, toMultiSelect, toRightClickSelect] WantTabs = True OnAfterCellPaint = DataGridAfterCellPaint - OnBeforeCellPaint = GridBeforeCellPaint + OnBeforeCellPaint = AnyGridBeforeCellPaint OnBeforePaint = DataGridBeforePaint OnChange = DataGridChange OnCreateEditor = DataGridCreateEditor @@ -1243,10 +1243,11 @@ object MainForm: TMainForm OnEnter = ValidateControls OnExit = ValidateControls OnFocusChanging = DataGridFocusChanging - OnGetText = GridGetText - OnPaintText = GridPaintText + OnGetText = AnyGridGetText + OnPaintText = AnyGridPaintText OnHeaderClick = DataGridHeaderClick - OnKeyDown = GridKeyDown + OnInitNode = AnyGridInitNode + OnKeyDown = AnyGridKeyDown OnMouseUp = DataGridMouseUp OnNewText = DataGridNewText Columns = <> @@ -1436,15 +1437,16 @@ object MainForm: TMainForm PopupMenu = popupResultGrid TabOrder = 1 TreeOptions.AutoOptions = [toAutoDropExpand, toAutoScroll, toAutoScrollOnExpand, toAutoTristateTracking, toAutoDeleteMovedNodes] - TreeOptions.MiscOptions = [toAcceptOLEDrop, toEditable, toFullRepaintOnResize, toGridExtensions, toInitOnSave, toToggleOnDblClick, toWheelPanning, toEditOnClick] + TreeOptions.MiscOptions = [toAcceptOLEDrop, toEditable, toFullRepaintOnResize, toGridExtensions, toInitOnSave, toToggleOnDblClick, toWheelPanning, toVariableNodeHeight, toEditOnClick] TreeOptions.PaintOptions = [toShowButtons, toShowDropmark, toShowHorzGridLines, toShowVertGridLines, toThemeAware, toUseBlendedImages, toAlwaysHideSelection] TreeOptions.SelectionOptions = [toExtendedFocus, toMultiSelect, toRightClickSelect] WantTabs = True - OnBeforeCellPaint = GridBeforeCellPaint + OnBeforeCellPaint = AnyGridBeforeCellPaint OnFocusChanged = QueryGridFocusChanged - OnGetText = GridGetText - OnPaintText = GridPaintText - OnKeyDown = GridKeyDown + OnGetText = AnyGridGetText + OnPaintText = AnyGridPaintText + OnInitNode = AnyGridInitNode + OnKeyDown = AnyGridKeyDown Columns = <> end end diff --git a/source/main.pas b/source/main.pas index 460c3b05..6a8be288 100644 --- a/source/main.pas +++ b/source/main.pas @@ -593,13 +593,13 @@ type TColumnIndex; var Allowed: Boolean); procedure DataGridFocusChanging(Sender: TBaseVirtualTree; OldNode, NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex; var Allowed: Boolean); - procedure GridGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: + procedure AnyGridGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: String); procedure DataGridHeaderClick(Sender: TVTHeader; HitInfo: TVTHeaderHitInfo); - procedure GridKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); + procedure AnyGridKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure DataGridNewText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; NewText: String); - procedure GridPaintText(Sender: TBaseVirtualTree; const TargetCanvas: + procedure AnyGridPaintText(Sender: TBaseVirtualTree; const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType); procedure menuDeleteSnippetClick(Sender: TObject); procedure menuExploreClick(Sender: TObject); @@ -660,7 +660,7 @@ type TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; CellRect: TRect); procedure menuShowSizeColumnClick(Sender: TObject); - procedure GridBeforeCellPaint(Sender: TBaseVirtualTree; + procedure AnyGridBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect); procedure QueryGridFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex); @@ -733,6 +733,8 @@ type procedure lblExplainProcessClick(Sender: TObject); procedure actDataShowNextExecute(Sender: TObject); procedure actDataShowAllExecute(Sender: TObject); + procedure AnyGridInitNode(Sender: TBaseVirtualTree; ParentNode, + Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates); private FDelimiter: String; FileNameSessionLog: String; @@ -812,6 +814,7 @@ type prefMaxColWidth: Integer; prefGridRowcountStep: Integer; prefGridRowcountMax: Integer; + prefGridRowsLineCount: Word; prefCSVSeparator: String; prefCSVEncloser: String; prefCSVTerminator: String; @@ -1281,6 +1284,7 @@ begin prefMaxColWidth := GetRegValue(REGNAME_MAXCOLWIDTH, DEFAULT_MAXCOLWIDTH); prefGridRowcountMax := GetRegValue(REGNAME_MAXTOTALROWS, DEFAULT_MAXTOTALROWS); prefGridRowcountStep := GetRegValue(REGNAME_ROWSPERSTEP, DEFAULT_ROWSPERSTEP); + prefGridRowsLineCount := GetRegValue(REGNAME_GRIDROWSLINECOUNT, DEFAULT_GRIDROWSLINECOUNT); actDataShowNext.Hint := 'Show next '+FormatNumber(prefGridRowcountStep)+' rows ...'; // Fix registry entry from older versions which can have 0 here which makes no sense // since the autosetting was removed @@ -3596,6 +3600,23 @@ begin end; +procedure TMainForm.AnyGridInitNode(Sender: TBaseVirtualTree; ParentNode, + Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates); +var + vt: TVirtualStringTree; +begin + // Display multiline grid rows + vt := Sender as TVirtualStringTree; + if prefGridRowsLineCount = DEFAULT_GRIDROWSLINECOUNT then begin + Node.NodeHeight := vt.DefaultNodeHeight; + Exclude(Node.States, vsMultiLine); + end else begin + Node.NodeHeight := prefGridRowsLineCount * (Integer(vt.DefaultNodeHeight) - 2*vt.TextMargin) + 2*vt.TextMargin; + Include(Node.States, vsMultiLine); + end; +end; + + {*** Occurs when active tab has changed. } @@ -6640,7 +6661,7 @@ end; {** A grid cell fetches its text content } -procedure TMainForm.GridGetText(Sender: TBaseVirtualTree; Node: +procedure TMainForm.AnyGridGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: String); var c: PGridCell; @@ -6686,7 +6707,7 @@ end; Cell in data- or query grid gets painted. Colorize font. This procedure is called extremely often for repainting the grid cells. Keep it highly optimized. } -procedure TMainForm.GridPaintText(Sender: TBaseVirtualTree; const +procedure TMainForm.AnyGridPaintText(Sender: TBaseVirtualTree; const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType); var @@ -7256,7 +7277,7 @@ end; -procedure TMainForm.GridKeyDown(Sender: TObject; var Key: Word; Shift: +procedure TMainForm.AnyGridKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var g: TVirtualStringTree; @@ -7370,7 +7391,7 @@ end; procedure TMainForm.AutoCalcColWidth(Tree: TVirtualStringTree; Column: TColumnIndex); var Node: PVirtualNode; - i, ColTextWidth: Integer; + i, ColTextWidth, ContentTextWidth: Integer; Rect: TRect; Col: TVirtualTreeColumn; begin @@ -7402,7 +7423,10 @@ begin // Note: this causes the node to load, an exception can propagate // here if the query or connection dies. Rect := Tree.GetDisplayRect(Node, Column, True, True); - ColTextWidth := Max(ColTextWidth, Rect.Right - Rect.Left); + ContentTextWidth := Rect.Right - Rect.Left; + if vsMultiLine in Node.States then + ContentTextWidth := Max(ContentTextWidth, Tree.Canvas.TextWidth(Tree.Text[Node, Column])); + ColTextWidth := Max(ColTextWidth, ContentTextWidth); inc(i); if i > 100 then break; // GetDisplayRect may have implicitely taken the node away. @@ -7417,7 +7441,7 @@ begin end; -procedure TMainForm.GridBeforeCellPaint(Sender: TBaseVirtualTree; +procedure TMainForm.AnyGridBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect); var @@ -8304,6 +8328,7 @@ begin QueryTab.Grid.OnBeforeCellPaint := QueryGrid.OnBeforeCellPaint; QueryTab.Grid.OnFocusChanged := QueryGrid.OnFocusChanged; QueryTab.Grid.OnGetText := QueryGrid.OnGetText; + QueryTab.Grid.OnInitNode := QueryGrid.OnInitNode; QueryTab.Grid.OnKeyDown := QueryGrid.OnKeyDown; QueryTab.Grid.OnPaintText := QueryGrid.OnPaintText; FixVT(QueryTab.Grid); diff --git a/source/options.dfm b/source/options.dfm index a96d48cd..0592581e 100644 --- a/source/options.dfm +++ b/source/options.dfm @@ -3,7 +3,7 @@ object optionsform: Toptionsform Top = 163 BorderStyle = bsDialog Caption = 'Preferences' - ClientHeight = 369 + ClientHeight = 395 ClientWidth = 472 Color = clBtnFace Font.Charset = DEFAULT_CHARSET @@ -17,14 +17,14 @@ object optionsform: Toptionsform OnShow = FormShow DesignSize = ( 472 - 369) + 395) PixelsPerInch = 96 TextHeight = 13 object pagecontrolMain: TPageControl Left = 8 Top = 8 Width = 458 - Height = 326 + Height = 352 ActivePage = tabMisc Anchors = [akLeft, akTop, akRight, akBottom] TabOrder = 3 @@ -410,7 +410,7 @@ object optionsform: Toptionsform Left = 0 Top = 132 Width = 438 - Height = 153 + Height = 179 Anchors = [akLeft, akTop, akRight, akBottom] Caption = 'Sample' TabOrder = 2 @@ -419,7 +419,7 @@ object optionsform: Toptionsform Left = 5 Top = 18 Width = 428 - Height = 130 + Height = 156 Cursor = crHandPoint SingleLineMode = False Align = alClient @@ -489,7 +489,7 @@ object optionsform: Toptionsform end object lblDataFontHint: TLabel Left = 362 - Top = 59 + Top = 84 Width = 29 Height = 13 Anchors = [akTop, akRight] @@ -497,7 +497,7 @@ object optionsform: Toptionsform end object lblDataFont: TLabel Left = 4 - Top = 59 + Top = 84 Width = 26 Height = 13 Caption = '&Font:' @@ -510,6 +510,13 @@ object optionsform: Toptionsform Height = 13 Caption = 'Number of rows displayed in data tab (Step, Maximum):' end + object lblGridRowsLinecount: TLabel + Left = 4 + Top = 58 + Width = 122 + Height = 13 + Caption = 'Lines of text in grid rows:' + end object editMaxColWidth: TEdit Left = 299 Top = 5 @@ -534,8 +541,8 @@ object optionsform: Toptionsform OnChanging = anyUpDownLimitChanging end object comboDataFontName: TComboBox - Left = 60 - Top = 55 + Left = 59 + Top = 80 Width = 234 Height = 21 Style = csDropDownList @@ -545,7 +552,7 @@ object optionsform: Toptionsform end object editDataFontSize: TEdit Left = 299 - Top = 55 + Top = 80 Width = 42 Height = 21 Anchors = [akTop, akRight] @@ -555,7 +562,7 @@ object optionsform: Toptionsform end object updownDataFontSize: TUpDown Left = 341 - Top = 55 + Top = 80 Width = 16 Height = 21 Anchors = [akTop, akRight] @@ -565,9 +572,9 @@ object optionsform: Toptionsform end object grpFieldLayout: TGroupBox Left = 4 - Top = 81 + Top = 112 Width = 433 - Height = 200 + Height = 195 Anchors = [akLeft, akTop, akRight, akBottom] Caption = 'Field colors and editors' TabOrder = 5 @@ -754,6 +761,28 @@ object optionsform: Toptionsform NumbersOnly = True TabOrder = 7 end + object editGridRowsLineCount: TEdit + Left = 299 + Top = 55 + Width = 42 + Height = 21 + Anchors = [akTop, akRight] + TabOrder = 8 + Text = '1' + OnChange = Modified + end + object updownGridRowsLineCount: TUpDown + Left = 341 + Top = 55 + Width = 16 + Height = 21 + Anchors = [akTop, akRight] + Associate = editGridRowsLineCount + Min = 1 + Position = 1 + TabOrder = 9 + OnChanging = anyUpDownLimitChanging + end end object tabCSV: TTabSheet BorderWidth = 5 @@ -894,7 +923,7 @@ object optionsform: Toptionsform ImageIndex = 4 DesignSize = ( 450 - 298) + 324) object lblShortcut1: TLabel Left = 199 Top = 62 @@ -907,7 +936,7 @@ object optionsform: Toptionsform Left = 199 Top = 3 Width = 211 - Height = 46 + Height = 72 Anchors = [akLeft, akTop, akBottom] AutoSize = False Caption = 'Please select a shortcut item in the tree.' @@ -970,7 +999,7 @@ object optionsform: Toptionsform end object btnCancel: TButton Left = 311 - Top = 338 + Top = 364 Width = 75 Height = 25 Anchors = [akRight, akBottom] @@ -981,7 +1010,7 @@ object optionsform: Toptionsform end object btnOK: TButton Left = 231 - Top = 338 + Top = 364 Width = 75 Height = 25 Anchors = [akRight, akBottom] @@ -993,7 +1022,7 @@ object optionsform: Toptionsform end object btnApply: TButton Left = 391 - Top = 338 + Top = 364 Width = 75 Height = 25 Anchors = [akRight, akBottom] @@ -1004,7 +1033,7 @@ object optionsform: Toptionsform end object btnRestoreDefaults: TButton Left = 8 - Top = 338 + Top = 364 Width = 97 Height = 25 Anchors = [akLeft, akBottom] @@ -1014,7 +1043,7 @@ object optionsform: Toptionsform end object SynSQLSynSQLSample: TSynSQLSyn SQLDialect = sqlMySQL - Left = 144 - Top = 336 + Left = 112 + Top = 360 end end diff --git a/source/options.pas b/source/options.pas index 9cb54a76..6bdaf702 100644 --- a/source/options.pas +++ b/source/options.pas @@ -129,6 +129,9 @@ type chkLogEventInfo: TCheckBox; chkLogEventDebug: TCheckBox; editGridRowCountStep: TEdit; + lblGridRowsLinecount: TLabel; + editGridRowsLineCount: TEdit; + updownGridRowsLineCount: TUpDown; procedure FormShow(Sender: TObject); procedure Modified(Sender: TObject); procedure Apply(Sender: TObject); @@ -246,6 +249,7 @@ begin Mainform.prefGridRowcountMax := StrToIntDef(editGridRowCountMax.Text, DEFAULT_MAXTOTALROWS); MainReg.WriteInteger(REGNAME_ROWSPERSTEP, Mainform.prefGridRowcountStep); MainReg.WriteInteger(REGNAME_MAXTOTALROWS, Mainform.prefGridRowcountMax); + MainReg.WriteInteger(REGNAME_GRIDROWSLINECOUNT, updownGridRowsLineCount.Position); MainReg.WriteString(REGNAME_DATAFONTNAME, comboDataFontName.Text); MainReg.WriteInteger(REGNAME_DATAFONTSIZE, updownDataFontSize.Position); MainReg.WriteBool(REGNAME_LOGTOFILE, chkLogToFile.Checked); @@ -296,12 +300,15 @@ begin // Set relevant properties in mainform Mainform.DataGrid.Font.Name := comboDataFontName.Text; Mainform.DataGrid.Font.Size := updownDataFontSize.Position; + Mainform.prefGridRowsLineCount := updownGridRowsLineCount.Position; FixVT(Mainform.DataGrid); + Mainform.DataGrid.ReinitChildren(nil, False); for i:=Mainform.tabQuery.PageIndex to Mainform.PageControlMain.PageCount-1 do begin Grid := TQueryTab(Mainform.QueryTabs[i-Mainform.tabQuery.PageIndex]).Grid; Grid.Font.Name := comboDataFontName.Text; Grid.Font.Size := updownDataFontSize.Position; FixVT(Grid); + Grid.ReinitChildren(nil, False); end; Mainform.prefLogsqlnum := updownLogLines.Position; @@ -415,6 +422,7 @@ begin updownMaxColWidth.Position := GetRegValue(REGNAME_MAXCOLWIDTH, DEFAULT_MAXCOLWIDTH); editGridRowCountStep.Text := IntToStr(GetRegValue(REGNAME_ROWSPERSTEP, DEFAULT_ROWSPERSTEP)); editGridRowCountMax.Text := IntToStr(GetRegValue(REGNAME_MAXTOTALROWS, DEFAULT_MAXTOTALROWS)); + updownGridRowsLineCount.Position := GetRegValue(REGNAME_GRIDROWSLINECOUNT, DEFAULT_GRIDROWSLINECOUNT); // Export-Options: editCSVSeparator.Text := GetRegValue(REGNAME_CSV_SEPARATOR, DEFAULT_CSV_SEPARATOR);