From a4dc12c51760b9b25fdb59fa563d1a241051626d Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Tue, 4 Mar 2025 16:39:40 +0100 Subject: [PATCH] Issue #1482: add printlist dialog, yet non-functional due to undefined EnablePrint constant --- heidisql.lpi | 11 +++++ heidisql.lpr | 4 +- source/printlist.lfm | 82 +++++++++++++++++++++++++++++++++ source/printlist.pas | 107 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 source/printlist.lfm create mode 100644 source/printlist.pas diff --git a/heidisql.lpi b/heidisql.lpi index 3fc01e3c..40d02129 100644 --- a/heidisql.lpi +++ b/heidisql.lpi @@ -29,6 +29,9 @@ + + + @@ -102,6 +105,7 @@ + @@ -115,6 +119,13 @@ + + + + + + + diff --git a/heidisql.lpr b/heidisql.lpr index 2f8dacad..092248b0 100644 --- a/heidisql.lpr +++ b/heidisql.lpr @@ -11,12 +11,12 @@ uses {$ENDIF} Interfaces, // this includes the LCL widgetset SysUtils, - Forms, + Forms, printer4lazarus, { you can add units after this } main, apphelpers, dbconnection, { gnugettext,} dbstructures, dbstructures.mysql, About, generic_types, dbstructures.interbase, dbstructures.mssql, dbstructures.postgresql, - dbstructures.sqlite, change_password, loginform + dbstructures.sqlite, change_password, loginform {, printlist (EnablePrint not defined) } ; {$R *.res} diff --git a/source/printlist.lfm b/source/printlist.lfm new file mode 100644 index 00000000..cdc81df6 --- /dev/null +++ b/source/printlist.lfm @@ -0,0 +1,82 @@ +object printlistForm: TprintlistForm + Left = 521 + Height = 115 + Top = 91 + Width = 471 + BorderStyle = bsDialog + Caption = 'Print List...' + ClientHeight = 115 + ClientWidth = 471 + Color = clBtnFace + DesignTimePPI = 120 + Font.Color = clWindowText + Font.Height = -15 + Font.Name = 'Tahoma' + OnShow = FormShow + Position = poMainFormCenter + object lblSelect: TLabel + Left = 10 + Height = 18 + Top = 14 + Width = 89 + Caption = '&Select printer:' + FocusControl = comboPrinters + end + object comboPrinters: TComboBox + Left = 102 + Height = 26 + Top = 10 + Width = 258 + ItemHeight = 18 + Style = csDropDownList + TabOrder = 0 + OnChange = comboPrintersChange + end + object btnConfigure: TButton + Left = 368 + Height = 31 + Top = 10 + Width = 94 + Caption = 'Configure' + TabOrder = 1 + OnClick = btnConfigureClick + end + object btnCancel: TButton + Left = 367 + Height = 31 + Top = 74 + Width = 94 + Anchors = [akRight, akBottom] + Cancel = True + Caption = 'Cancel' + ModalResult = 2 + TabOrder = 3 + end + object btnPrint: TButton + Left = 266 + Height = 31 + Top = 74 + Width = 94 + Anchors = [akRight, akBottom] + Caption = 'Print' + Default = True + ModalResult = 1 + TabOrder = 2 + OnClick = btnPrintClick + end + object chkPrintHeader: TCheckBox + Left = 102 + Height = 22 + Top = 45 + Width = 258 + Anchors = [akTop, akLeft, akRight] + Caption = 'Print column headers' + Checked = True + State = cbChecked + TabOrder = 4 + end + object PrinterSetup: TPrinterSetupDialog + Left = 10 + Top = 40 + end +end diff --git a/source/printlist.pas b/source/printlist.pas new file mode 100644 index 00000000..fe452642 --- /dev/null +++ b/source/printlist.pas @@ -0,0 +1,107 @@ +unit printlist; + +{$mode delphi}{$H+} + +// ------------------------------------- +// Print TListView-Content +// ------------------------------------- + + +interface + +uses + Classes, Controls, Forms, Dialogs, StdCtrls, Printers, laz.VirtualTrees, + PrintersDlgs; + +type + + { TprintlistForm } + + TprintlistForm = class(TForm) + comboPrinters: TComboBox; + btnConfigure: TButton; + btnCancel: TButton; + btnPrint: TButton; + PrinterSetup: TPrinterSetupDialog; + lblSelect: TLabel; + chkPrintHeader: TCheckBox; + procedure btnConfigureClick(Sender: TObject); + procedure btnPrintClick(Sender: TObject); + procedure comboPrintersChange(Sender: TObject); + procedure FormShow(Sender: TObject); + private + { Private declarations } + public + { Public declarations } + end; + + +implementation + +uses main, apphelpers, {table_editor, }dbconnection; + +{$R *.lfm} + + +procedure TprintlistForm.FormShow(Sender: TObject); +begin + // show! + Screen.Cursor := crHourGlass; + comboPrinters.Items := Printer.printers; + comboPrinters.ItemIndex := Printer.printerIndex; + Screen.Cursor := crDefault; +end; + +procedure TprintlistForm.btnConfigureClick(Sender: TObject); +begin + Screen.Cursor := crHourglass; + printerSetup.Execute; + comboPrinters.ItemIndex := Printer.PrinterIndex; + Screen.Cursor := crDefault; +end; + +procedure TprintlistForm.btnPrintClick(Sender: TObject); +var + list: TVirtualStringTree; +begin + // print! + Screen.Cursor := crHourglass; + list := nil; + // which ListView to print? + case Mainform.PageControlMain.ActivePageIndex of + 0: case Mainform.PageControlHost.ActivePageIndex of + 0: list := Mainform.ListDatabases; + 1: list := Mainform.ListVariables; + 2: list := Mainform.ListStatus; + 3: list := Mainform.ListProcesses; + else list := Mainform.ListCommandStats; + end; + 1: list := Mainform.ListTables; + 2: begin + if Assigned(Mainform.ActiveObjectEditor) + and (Mainform.ActiveObjectEditor.DBObject.NodeType = lntTable) + and Mainform.ActiveObjectEditor.Visible then + {list := (Mainform.ActiveObjectEditor as TfrmTableEditor).listColumns;} + end; + else list := Mainform.ActiveGrid; + end; + if Assigned(list) then + try + list.Print(Printer, chkPrintHeader.Checked); + except + on E:EPrinter do + ErrorDialog(E.Message); + end; + Screen.Cursor := crDefault; +end; + + +procedure TprintlistForm.comboPrintersChange(Sender: TObject); +begin + // chose printer + Screen.Cursor := crHourglass; + Printer.PrinterIndex := comboPrinters.ItemIndex; + Screen.Cursor := crDefault; +end; + +end.