unit SelectPrinter;

  interface
    uses
      Classes  (**),
      Controls (**),
      Forms    (* tForm *),
      StdCtrls (* TGroupBox, tListBox *),
      Windows  (**);

    type
      tfmSelectPrinter = class(tForm)
          grpPrinters: tGroupBox;
          lbxPrinters: tListBox;
          procedure FormDblClick    (Sender: tObject);
          procedure lbxPrintersClick(Sender: tObject);
          procedure SetDefaultPrinter;
        end (* tfmSelectPrinter *);

    var
     fmSelectPrinter: tfmSelectPrinter;
     
  implementation
    uses
      GraphManager2 (* fmGraphManager *),
      HC3DM         (* Global *),
      HC4Main       (* fmHC4Main *),
      Printers      (* Printer *);
      {$R *.dfm}

    procedure tfmSelectPrinter.FormDblClick(Sender: tObject);
      (* show master form *)
    
      begin (* tfmSelectPrinter.FormDblClick *)
        fmHC4Main.Show
      end   (* tfmSelectPrinter.FormDblClick *);

    procedure tfmSelectPrinter.lbxPrintersClick(Sender: tObject);
      (* Set selected printer as the one to use in printing charts *)

      begin (* tfmSelectPrinter.lbxPrintersClick *)
        with lbxPrinters do
          if ItemIndex >= 0 then
            begin (* lbxPrinters *)
              Printer.PrinterIndex := ItemIndex;
              Global.GraphPrinterName := Printer.Printers[ItemIndex]
            end   (* lbxPrinters *)
      end   (* tfmSelectPrinter.lbxPrintersClick *);

    procedure tfmSelectPrinter.SetDefaultPrinter;
      (* called from HC4Main *)
    
      begin (* tfmSelectPrinter.SetDefaultPrinter *)
        with lbxPrinters do
          begin (* lbxPrinters *)
            Items.Assign(Printer.Printers);
            ItemIndex := Items.IndexOf('PDFCreator');
            lbxPrintersClick(nil)
          end   (* lbxPrinters *);
      end   (* tfmSelectPrinter.SetDefaultPrinter *);

end.
