From c5f93d23e9758903fde3d93704340ac46c64c76c Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Wed, 1 May 2024 12:00:18 +0200 Subject: [PATCH] Issue #139: use alternating row background in database tab, and in all sub tabs of the host tab --- source/main.dfm | 1 + source/main.pas | 61 +++++++++++++++++++++++++++++++++-------- source/table_editor.pas | 16 ++--------- 3 files changed, 54 insertions(+), 24 deletions(-) diff --git a/source/main.dfm b/source/main.dfm index 47abf593..38151743 100644 --- a/source/main.dfm +++ b/source/main.dfm @@ -587,6 +587,7 @@ object MainForm: TMainForm TreeOptions.PaintOptions = [toHotTrack, toShowDropmark, toShowHorzGridLines, toShowVertGridLines, toThemeAware, toUseBlendedImages, toUseExplorerTheme] TreeOptions.SelectionOptions = [toExtendedFocus, toFullRowSelect, toRightClickSelect] OnAfterPaint = AnyGridAfterPaint + OnBeforeCellPaint = ListStatusBeforeCellPaint OnBeforePaint = HostListBeforePaint OnCompareNodes = AnyGridCompareNodes OnGetText = HostListGetText diff --git a/source/main.pas b/source/main.pas index c594e490..afe71319 100644 --- a/source/main.pas +++ b/source/main.pas @@ -1192,6 +1192,9 @@ TMainForm = class(TExtForm) procedure menuTabsInMultipleLinesClick(Sender: TObject); procedure actResetPanelDimensionsExecute(Sender: TObject); procedure menuAlwaysGenerateFilterClick(Sender: TObject); + procedure ListStatusBeforeCellPaint(Sender: TBaseVirtualTree; + TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; + CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect); private // Executable file details FAppVerMajor: Integer; @@ -1332,6 +1335,8 @@ TMainForm = class(TExtForm) property Connections: TDBConnectionList read FConnections; property Delimiter: String read FDelimiter write SetDelimiter; property FocusedTables: TDBObjectList read FFocusedTables; + function GetAlternatingRowBackground(Node: PVirtualNode): TColor; + procedure PaintAlternatingRowBackground(TargetCanvas: TCanvas; Node: PVirtualNode; CellRect: TRect); procedure PaintColorBar(Value, Max: Extended; TargetCanvas: TCanvas; CellRect: TRect); procedure CallSQLHelpWithKeyword( keyword: String ); procedure AddOrRemoveFromQueryLoadHistory(Filename: String; AddIt: Boolean; CheckIfFileExists: Boolean); @@ -8864,6 +8869,8 @@ procedure TMainForm.ListTablesBeforeCellPaint(Sender: TBaseVirtualTree; TargetCa var Obj: PDBObject; begin + PaintAlternatingRowBackground(TargetCanvas, Node, CellRect); + // Only paint bar in rows + size column if Column in [1, 2] then begin Obj := Sender.GetNodeData(Node); @@ -8875,6 +8882,36 @@ procedure TMainForm.ListTablesBeforeCellPaint(Sender: TBaseVirtualTree; TargetCa end; +function TMainForm.GetAlternatingRowBackground(Node: PVirtualNode): TColor; +var + clEven, clOdd: TColor; + isEven: Boolean; +begin + // Alternating row background. See issue #139 + Result := clNone; + clEven := AppSettings.ReadInt(asRowBackgroundEven); + clOdd := AppSettings.ReadInt(asRowBackgroundOdd); + isEven := Node.Index mod 2 = 0; + if IsEven and (clEven <> clNone) then + Result := clEven + else if (not IsEven) and (clOdd <> clNone) then + Result := clOdd; +end; + + +procedure TMainForm.PaintAlternatingRowBackground(TargetCanvas: TCanvas; Node: PVirtualNode; CellRect: TRect); +var + BgColor: TColor; +begin + // Apply color + BgColor := GetAlternatingRowBackground(Node); + if BgColor <> clNone then begin + TargetCanvas.Brush.Color := BgColor; + TargetCanvas.FillRect(CellRect); + end; +end; + + procedure TMainForm.PaintColorBar(Value, Max: Extended; TargetCanvas: TCanvas; CellRect: TRect); var BarWidth, CellWidth: Integer; @@ -8929,6 +8966,13 @@ procedure TMainForm.ListProcessesFocusChanged(Sender: TBaseVirtualTree; end; +procedure TMainForm.ListStatusBeforeCellPaint(Sender: TBaseVirtualTree; + TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; + CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect); +begin + PaintAlternatingRowBackground(TargetCanvas, Node, CellRect); +end; + {*** Apply a filter to a Virtual Tree. } @@ -9120,6 +9164,7 @@ procedure TMainForm.ListVariablesBeforeCellPaint(Sender: TBaseVirtualTree; SessionVal, GlobalVal: String; vt: TVirtualStringTree; begin + PaintAlternatingRowBackground(TargetCanvas, Node, CellRect); // Highlight cell if session variable is different to global variable vt := Sender as TVirtualStringTree; if Column = 1 then begin @@ -10937,9 +10982,9 @@ procedure TMainForm.AnyGridBeforeCellPaint(Sender: TBaseVirtualTree; CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect); var r: TDBQuery; - cl, clNull, clEven, clOdd, clSameData: TColor; + cl, clNull, clSameData: TColor; RowNumber: PInt64; - isEven, FocusedIsNull, CurrentIsNull: Boolean; + FocusedIsNull, CurrentIsNull: Boolean; FieldText, FocusedFieldText: String; VT: TVirtualStringTree; ResultCol: Integer; @@ -10968,15 +11013,7 @@ procedure TMainForm.AnyGridBeforeCellPaint(Sender: TBaseVirtualTree; RowNumber := Sender.GetNodeData(Node); r.RecNo := RowNumber^; - clEven := AppSettings.ReadInt(asRowBackgroundEven); - clOdd := AppSettings.ReadInt(asRowBackgroundOdd); - isEven := Node.Index mod 2 = 0; - if IsEven and (clEven <> clNone) then - cl := clEven - else if (not IsEven) and (clOdd <> clNone) then - cl := clOdd - else - cl := clNone; + cl := GetAlternatingRowBackground(Node); if (vsSelected in Node.States) and (Node = Sender.FocusedNode) and (Column = Sender.FocusedColumn) then begin // Focused cell @@ -11184,6 +11221,7 @@ procedure TMainForm.ListDatabasesBeforeCellPaint(Sender: TBaseVirtualTree; Targe Val, Max: Extended; LoopNode: PVirtualNode; begin + PaintAlternatingRowBackground(TargetCanvas, Node, CellRect); // Display color bars if Column in [1,2,4..9] then begin vt := Sender as TVirtualStringTree; @@ -11541,6 +11579,7 @@ procedure TMainForm.HostListBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanv var vt: TVirtualStringTree; begin + PaintAlternatingRowBackground(TargetCanvas, Node, CellRect); vt := Sender as TVirtualStringTree; if (Column = 5) and (vt = ListProcesses) then PaintColorBar(MakeFloat(vt.Text[Node, Column]), FProcessListMaxTime, TargetCanvas, CellRect); diff --git a/source/table_editor.pas b/source/table_editor.pas index 5cb74d23..243b875e 100644 --- a/source/table_editor.pas +++ b/source/table_editor.pas @@ -1093,19 +1093,9 @@ procedure TfrmTableEditor.listColumnsBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect); var - clEven, clOdd, BgColor: TColor; - isEven: Boolean; -begin - BgColor := clNone; - - // Alternating row background. See issue #139 - clEven := AppSettings.ReadInt(asRowBackgroundEven); - clOdd := AppSettings.ReadInt(asRowBackgroundOdd); - isEven := Node.Index mod 2 = 0; - if IsEven and (clEven <> clNone) then - BgColor := clEven - else if (not IsEven) and (clOdd <> clNone) then - BgColor := clOdd; + BgColor: TColor; +begin + BgColor := MainForm.GetAlternatingRowBackground(Node); // Darken cell background to signalize it doesn't allow length/set // Exclude non editable checkbox columns - grey looks ugly there.