source: cprs/branches/foia-cprs/CPRS-Chart/fDeviceSelect.pas@ 459

Last change on this file since 459 was 459, checked in by Kevin Toppenberg, 16 years ago

Adding foia-cprs branch

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