[456] | 1 | unit fDeviceSelect;
|
---|
| 2 |
|
---|
| 3 | interface
|
---|
| 4 |
|
---|
| 5 | uses
|
---|
| 6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
---|
[830] | 7 | StdCtrls, fAutoSz, ORCtrls, ORNet, Mask, ExtCtrls, VA508AccessibilityManager;
|
---|
[456] | 8 |
|
---|
| 9 | type
|
---|
| 10 | TfrmDeviceSelect = class(TfrmAutoSz)
|
---|
| 11 | grpDevice: TGroupBox;
|
---|
| 12 | cboDevice: TORComboBox;
|
---|
| 13 | pnlBottom: TPanel;
|
---|
| 14 | cmdOK: TButton;
|
---|
| 15 | cmdCancel: TButton;
|
---|
| 16 | chkDefault: TCheckBox;
|
---|
| 17 | pnlGBBottom: TPanel;
|
---|
| 18 | lblMargin: TLabel;
|
---|
| 19 | txtRightMargin: TMaskEdit;
|
---|
| 20 | lblLength: TLabel;
|
---|
| 21 | txtPageLength: TMaskEdit;
|
---|
| 22 | procedure cboDeviceChange(Sender: TObject);
|
---|
| 23 | procedure cmdOKClick(Sender: TObject);
|
---|
| 24 | procedure cmdCancelClick(Sender: TObject);
|
---|
| 25 | procedure cboDeviceNeedData(Sender: TObject; const StartFrom: String;
|
---|
| 26 | Direction, InsertAt: Integer);
|
---|
| 27 | procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
[830] | 28 | procedure FormCreate(Sender: TObject);
|
---|
[456] | 29 | private
|
---|
| 30 | FWinPrint: Boolean;
|
---|
| 31 | end;
|
---|
| 32 |
|
---|
| 33 | var
|
---|
| 34 | frmDeviceSelect: TfrmDeviceSelect;
|
---|
| 35 | ADevice: string;
|
---|
| 36 |
|
---|
| 37 | function SelectDevice(Sender: TObject; ALocation: integer; AllowWindowsPrinter: boolean; ACaption: String): string ;
|
---|
| 38 |
|
---|
| 39 | implementation
|
---|
| 40 |
|
---|
| 41 | {$R *.DFM}
|
---|
| 42 |
|
---|
| 43 | uses ORFn, rCore, uCore, rReports, Printers, fFrame, rMisc;
|
---|
| 44 |
|
---|
| 45 | const
|
---|
| 46 | TX_NODEVICE = 'A device must be selected to print, or press ''Cancel'' to not print.';
|
---|
| 47 | TX_NODEVICE_CAP = 'Device Not Selected';
|
---|
| 48 | TX_ERR_CAP = 'Print Error';
|
---|
| 49 |
|
---|
| 50 | function SelectDevice(Sender: TObject; ALocation: integer; AllowWindowsPrinter: boolean; ACaption: String): string ;
|
---|
| 51 | { displays a form that prompts for a device}
|
---|
| 52 | var
|
---|
| 53 | frmDeviceSelect: TfrmDeviceSelect;
|
---|
| 54 | DefPrt: string;
|
---|
| 55 | begin
|
---|
| 56 | frmDeviceSelect := TfrmDeviceSelect.Create(Application);
|
---|
| 57 | try
|
---|
| 58 | with frmDeviceSelect do
|
---|
| 59 | begin
|
---|
| 60 | FWinPrint := AllowWindowsPrinter;
|
---|
| 61 | with cboDevice do
|
---|
| 62 | begin
|
---|
| 63 | if (FWinPrint) and (Printer.Printers.Count > 0) then
|
---|
| 64 | begin
|
---|
| 65 | Items.Add('WIN;Windows Printer^Windows Printer');
|
---|
| 66 | Items.Add('^--------------------VistA Printers----------------------');
|
---|
| 67 | end;
|
---|
| 68 | end;
|
---|
| 69 | if Sender <> frmFrame then
|
---|
| 70 | begin
|
---|
| 71 | DefPrt := User.CurrentPrinter;
|
---|
| 72 | if DefPrt = '' then DefPrt := GetDefaultPrinter(User.Duz, Encounter.Location);
|
---|
| 73 | if DefPrt <> '' then
|
---|
| 74 | begin
|
---|
| 75 | if (not FWinPrint) then
|
---|
| 76 | begin
|
---|
| 77 | if (DefPrt <> 'WIN;Windows Printer') then
|
---|
| 78 | begin
|
---|
| 79 | cboDevice.InitLongList(Piece(DefPrt, ';', 2));
|
---|
| 80 | cboDevice.SelectByID(DefPrt);
|
---|
| 81 | end
|
---|
| 82 | else
|
---|
| 83 | cboDevice.InitLongList('');
|
---|
| 84 | end
|
---|
| 85 | else if FWinprint then
|
---|
| 86 | begin
|
---|
| 87 | cboDevice.InitLongList(Piece(DefPrt, ';', 2));
|
---|
| 88 | cboDevice.SelectByID(DefPrt);
|
---|
| 89 | end;
|
---|
| 90 | end
|
---|
| 91 | else
|
---|
| 92 | begin
|
---|
| 93 | cboDevice.InitLongList('');
|
---|
| 94 | end;
|
---|
| 95 | if ACaption<>'' then frmDeviceSelect.Caption:=ACaption;
|
---|
| 96 | end
|
---|
| 97 | else
|
---|
| 98 | begin
|
---|
| 99 | frmDeviceSelect.Caption := 'Print Device Selection';
|
---|
| 100 | cboDevice.InitLongList('');
|
---|
| 101 | end;
|
---|
| 102 | ShowModal;
|
---|
| 103 | Result := ADevice;
|
---|
| 104 | //Result := Piece(ADevice, ';', 1) + U + Piece(ADevice, U, 2);
|
---|
| 105 | end;
|
---|
| 106 | finally
|
---|
| 107 | frmDeviceSelect.Release;
|
---|
| 108 | end;
|
---|
| 109 | end;
|
---|
| 110 |
|
---|
| 111 | procedure TfrmDeviceSelect.cboDeviceChange(Sender: TObject);
|
---|
| 112 | begin
|
---|
| 113 | inherited;
|
---|
| 114 | with cboDevice do if ItemIndex > -1 then
|
---|
| 115 | begin
|
---|
| 116 | txtRightMargin.Text := Piece(Items[ItemIndex], '^', 4);
|
---|
| 117 | txtPageLength.Text := Piece(Items[ItemIndex], '^', 5);
|
---|
| 118 | end;
|
---|
| 119 | end;
|
---|
| 120 |
|
---|
| 121 | procedure TfrmDeviceSelect.cmdOKClick(Sender: TObject);
|
---|
| 122 | begin
|
---|
| 123 | inherited;
|
---|
| 124 | if cboDevice.ItemID = '' then
|
---|
| 125 | begin
|
---|
| 126 | InfoBox(TX_NODEVICE, TX_NODEVICE_CAP, MB_OK);
|
---|
| 127 | Exit;
|
---|
| 128 | end;
|
---|
| 129 | ADevice := cboDevice.Items[cboDevice.ItemIndex];
|
---|
| 130 | if chkDefault.Checked then SaveDefaultPrinter(Piece(cboDevice.ItemID, ';', 1));
|
---|
| 131 | Close;
|
---|
| 132 | end;
|
---|
| 133 |
|
---|
| 134 | procedure TfrmDeviceSelect.cmdCancelClick(Sender: TObject);
|
---|
| 135 | begin
|
---|
| 136 | inherited;
|
---|
| 137 | ADevice := '';
|
---|
| 138 | Close;
|
---|
| 139 | end;
|
---|
| 140 |
|
---|
| 141 | procedure TfrmDeviceSelect.cboDeviceNeedData(Sender: TObject;
|
---|
| 142 | const StartFrom: String; Direction, InsertAt: Integer);
|
---|
| 143 | begin
|
---|
| 144 | inherited;
|
---|
| 145 | cboDevice.ForDataUse(SubsetOfDevices(StartFrom, Direction));
|
---|
| 146 | end;
|
---|
| 147 |
|
---|
[830] | 148 | procedure TfrmDeviceSelect.FormClose(Sender: TObject;
|
---|
| 149 | var Action: TCloseAction);
|
---|
[456] | 150 | begin
|
---|
| 151 | inherited;
|
---|
[830] | 152 | SaveUserBounds(Self);
|
---|
[456] | 153 | end;
|
---|
| 154 |
|
---|
[830] | 155 | procedure TfrmDeviceSelect.FormCreate(Sender: TObject);
|
---|
[456] | 156 | begin
|
---|
| 157 | inherited;
|
---|
[830] | 158 | ResizeFormToFont(Self);
|
---|
| 159 | SetFormPosition(Self);
|
---|
[456] | 160 | end;
|
---|
| 161 |
|
---|
| 162 | end.
|
---|