| [459] | 1 | unit fDeviceSelect; | 
|---|
|  | 2 |  | 
|---|
|  | 3 | interface | 
|---|
|  | 4 |  | 
|---|
|  | 5 | uses | 
|---|
|  | 6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, | 
|---|
| [460] | 7 | StdCtrls, fAutoSz, ORCtrls, ORNet, Mask, ExtCtrls; | 
|---|
| [459] | 8 |  | 
|---|
|  | 9 | type | 
|---|
|  | 10 | TfrmDeviceSelect = class(TfrmAutoSz) | 
|---|
|  | 11 | grpDevice: TGroupBox; | 
|---|
|  | 12 | cboDevice: TORComboBox; | 
|---|
| [460] | 13 | pnlBottom: TPanel; | 
|---|
| [459] | 14 | cmdOK: TButton; | 
|---|
|  | 15 | cmdCancel: TButton; | 
|---|
|  | 16 | chkDefault: TCheckBox; | 
|---|
| [460] | 17 | pnlGBBottom: TPanel; | 
|---|
|  | 18 | lblMargin: TLabel; | 
|---|
|  | 19 | txtRightMargin: TMaskEdit; | 
|---|
|  | 20 | lblLength: TLabel; | 
|---|
|  | 21 | txtPageLength: TMaskEdit; | 
|---|
| [459] | 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); | 
|---|
| [460] | 27 | procedure FormShow(Sender: TObject); | 
|---|
|  | 28 | procedure FormClose(Sender: TObject; var Action: TCloseAction); | 
|---|
| [459] | 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 |  | 
|---|
| [460] | 43 | uses ORFn, rCore, uCore, rReports, Printers, fFrame, rMisc; | 
|---|
| [459] | 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 | ResizeFormToFont(TForm(frmDeviceSelect)); | 
|---|
|  | 59 | with frmDeviceSelect do | 
|---|
|  | 60 | begin | 
|---|
|  | 61 | FWinPrint := AllowWindowsPrinter; | 
|---|
|  | 62 | with cboDevice do | 
|---|
|  | 63 | begin | 
|---|
|  | 64 | if (FWinPrint) and (Printer.Printers.Count > 0) then | 
|---|
|  | 65 | begin | 
|---|
|  | 66 | Items.Add('WIN;Windows Printer^Windows Printer'); | 
|---|
|  | 67 | Items.Add('^--------------------VistA Printers----------------------'); | 
|---|
|  | 68 | end; | 
|---|
|  | 69 | end; | 
|---|
|  | 70 | if Sender <> frmFrame then | 
|---|
|  | 71 | begin | 
|---|
|  | 72 | DefPrt := User.CurrentPrinter; | 
|---|
|  | 73 | if DefPrt = '' then DefPrt := GetDefaultPrinter(User.Duz, Encounter.Location); | 
|---|
|  | 74 | if DefPrt <> '' then | 
|---|
|  | 75 | begin | 
|---|
|  | 76 | if (not FWinPrint) then | 
|---|
|  | 77 | begin | 
|---|
|  | 78 | if (DefPrt <> 'WIN;Windows Printer') then | 
|---|
|  | 79 | begin | 
|---|
|  | 80 | cboDevice.InitLongList(Piece(DefPrt, ';', 2)); | 
|---|
|  | 81 | cboDevice.SelectByID(DefPrt); | 
|---|
|  | 82 | end | 
|---|
|  | 83 | else | 
|---|
|  | 84 | cboDevice.InitLongList(''); | 
|---|
|  | 85 | end | 
|---|
|  | 86 | else if FWinprint then | 
|---|
|  | 87 | begin | 
|---|
|  | 88 | cboDevice.InitLongList(Piece(DefPrt, ';', 2)); | 
|---|
|  | 89 | cboDevice.SelectByID(DefPrt); | 
|---|
|  | 90 | end; | 
|---|
|  | 91 | end | 
|---|
|  | 92 | else | 
|---|
|  | 93 | begin | 
|---|
|  | 94 | cboDevice.InitLongList(''); | 
|---|
|  | 95 | end; | 
|---|
|  | 96 | if ACaption<>'' then frmDeviceSelect.Caption:=ACaption; | 
|---|
|  | 97 | end | 
|---|
|  | 98 | else | 
|---|
|  | 99 | begin | 
|---|
|  | 100 | frmDeviceSelect.Caption := 'Print Device Selection'; | 
|---|
|  | 101 | cboDevice.InitLongList(''); | 
|---|
|  | 102 | end; | 
|---|
|  | 103 | ShowModal; | 
|---|
|  | 104 | Result := ADevice; | 
|---|
|  | 105 | //Result := Piece(ADevice, ';', 1) + U + Piece(ADevice, U, 2); | 
|---|
|  | 106 | end; | 
|---|
|  | 107 | finally | 
|---|
|  | 108 | frmDeviceSelect.Release; | 
|---|
|  | 109 | end; | 
|---|
|  | 110 | end; | 
|---|
|  | 111 |  | 
|---|
|  | 112 | procedure TfrmDeviceSelect.cboDeviceChange(Sender: TObject); | 
|---|
|  | 113 | begin | 
|---|
|  | 114 | inherited; | 
|---|
|  | 115 | with cboDevice do if ItemIndex > -1 then | 
|---|
|  | 116 | begin | 
|---|
|  | 117 | txtRightMargin.Text := Piece(Items[ItemIndex], '^', 4); | 
|---|
|  | 118 | txtPageLength.Text := Piece(Items[ItemIndex], '^', 5); | 
|---|
|  | 119 | end; | 
|---|
|  | 120 | end; | 
|---|
|  | 121 |  | 
|---|
|  | 122 | procedure TfrmDeviceSelect.cmdOKClick(Sender: TObject); | 
|---|
|  | 123 | begin | 
|---|
|  | 124 | inherited; | 
|---|
|  | 125 | if cboDevice.ItemID = '' then | 
|---|
|  | 126 | begin | 
|---|
|  | 127 | InfoBox(TX_NODEVICE, TX_NODEVICE_CAP, MB_OK); | 
|---|
|  | 128 | Exit; | 
|---|
|  | 129 | end; | 
|---|
|  | 130 | ADevice := cboDevice.Items[cboDevice.ItemIndex]; | 
|---|
|  | 131 | if chkDefault.Checked then SaveDefaultPrinter(Piece(cboDevice.ItemID, ';', 1)); | 
|---|
|  | 132 | Close; | 
|---|
|  | 133 | end; | 
|---|
|  | 134 |  | 
|---|
|  | 135 | procedure TfrmDeviceSelect.cmdCancelClick(Sender: TObject); | 
|---|
|  | 136 | begin | 
|---|
|  | 137 | inherited; | 
|---|
|  | 138 | ADevice := ''; | 
|---|
|  | 139 | Close; | 
|---|
|  | 140 | end; | 
|---|
|  | 141 |  | 
|---|
|  | 142 | procedure TfrmDeviceSelect.cboDeviceNeedData(Sender: TObject; | 
|---|
|  | 143 | const StartFrom: String; Direction, InsertAt: Integer); | 
|---|
|  | 144 | begin | 
|---|
|  | 145 | inherited; | 
|---|
|  | 146 | cboDevice.ForDataUse(SubsetOfDevices(StartFrom, Direction)); | 
|---|
|  | 147 | end; | 
|---|
|  | 148 |  | 
|---|
| [460] | 149 | procedure TfrmDeviceSelect.FormShow(Sender: TObject); | 
|---|
|  | 150 | begin | 
|---|
|  | 151 | SetFormPosition(Self); | 
|---|
|  | 152 | inherited; | 
|---|
|  | 153 | end; | 
|---|
|  | 154 |  | 
|---|
|  | 155 | procedure TfrmDeviceSelect.FormClose(Sender: TObject; | 
|---|
|  | 156 | var Action: TCloseAction); | 
|---|
|  | 157 | begin | 
|---|
|  | 158 | inherited; | 
|---|
|  | 159 | SaveUserBounds(Self); | 
|---|
|  | 160 | end; | 
|---|
|  | 161 |  | 
|---|
| [459] | 162 | end. | 
|---|