source: cprs/trunk/CPRS-Chart/Templates/fTemplateFields.pas@ 1405

Last change on this file since 1405 was 829, checked in by Kevin Toppenberg, 14 years ago

Upgrade to version 27

File size: 5.9 KB
RevLine 
[456]1unit fTemplateFields;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
[829]7 ORCtrls, ComCtrls, StdCtrls, ExtCtrls, fBase508Form, VA508AccessibilityManager;
[456]8
9type
[829]10 TfrmTemplateFields = class(TfrmBase508Form)
[456]11 pnlBottom: TPanel;
12 btnCancel: TButton;
13 cboObjects: TORComboBox;
14 btnInsert: TButton;
15 btnPreview: TButton;
[829]16 lblReq: TVA508StaticText;
17 pnlBottomSR: TPanel;
18 lblSRCont2: TVA508StaticText;
19 lblSRCont1: TVA508StaticText;
20 lblSRStop: TVA508StaticText;
21 pnlSRIntro: TPanel;
22 lblSRIntro1: TVA508StaticText;
23 lblSRIntro2: TVA508StaticText;
[456]24 procedure FormShow(Sender: TObject);
25 procedure FormCreate(Sender: TObject);
26 procedure cboObjectsNeedData(Sender: TObject; const StartFrom: String;
27 Direction, InsertAt: Integer);
28 procedure cboObjectsDblClick(Sender: TObject);
29 procedure btnCancelClick(Sender: TObject);
30 procedure FormClose(Sender: TObject; var Action: TCloseAction);
31 procedure btnInsertClick(Sender: TObject);
32 procedure btnPreviewClick(Sender: TObject);
33 procedure cboObjectsChange(Sender: TObject);
34 private
35{ Fre: TRichEdit;}
36 Fre: TCustomEdit;
[829]37 FInsertAllowed: boolean;
38 FInitialized: boolean;
[456]39 FAutoLongLines: TNotifyEvent;
40 procedure InsertField;
41{ procedure Setre(const Value: TRichEdit);}
42 procedure Setre(const Value: TCustomEdit);
[829]43 function ValidPreview: boolean;
44 function ValidInsert: boolean;
[456]45 public
46 procedure UpdateStatus;
47{ property re: TRichEdit read Fre write Setre;}
48 property re: TCustomEdit read Fre write Setre;
49 property AutoLongLines: TNotifyEvent read FAutoLongLines write FAutoLongLines;
50 end;
51
52implementation
53
54uses
55 ORFn, rTemplates, uTemplateFields, fTemplateDialog, ORClasses;
56
57{$R *.DFM}
58
59procedure TfrmTemplateFields.FormShow(Sender: TObject);
[829]60var
61 i: integer;
[456]62begin
[829]63 if not FInitialized then
64 begin
65 with cboObjects do
66 begin
67 for i := low(ScreenReaderCodeLines) to high(ScreenReaderCodeLines) do
68 Items.Add(ScreenReaderCodeLines[i]);
69 InsertSeparator;
70 InitLongList('');
71 end;
72 FInitialized := TRUE;
73 end;
[456]74 cboObjects.SelectAll;
75 cboObjects.SetFocus;
76end;
77
78procedure TfrmTemplateFields.FormCreate(Sender: TObject);
79begin
[829]80 ResizeFormToFont(self);
81 cboObjects.ItemHeight := lblReq.Height - 1;
82 FInsertAllowed := TRUE;
83 lblReq.Top := (pnlBottom.Height - lblReq.Height);
84 pnlSRIntro.Height := lblSRStop.Height;
85 pnlBottomSR.Height := lblSRCont1.Height * 4 + 5;
[456]86end;
87
88procedure TfrmTemplateFields.cboObjectsNeedData(Sender: TObject;
89 const StartFrom: String; Direction, InsertAt: Integer);
90var
91 tmp: TStrings;
92
93begin
94 tmp := SubSetOfTemplateFields(StartFrom, Direction);
95 ConvertCodes2Text(tmp, FALSE);
96 cboObjects.ForDataUse(tmp);
97end;
98
99procedure TfrmTemplateFields.InsertField;
100var
101 cnt: integer;
[829]102 p1, p2: string;
103 check: boolean;
104 i: integer;
[456]105
106begin
[829]107 p1 := Piece(cboObjects.Items[cboObjects.ItemIndex],U,1);
108 if p1 = '' then exit;
[456]109 if assigned(Fre) and (not TORExposedCustomEdit(Fre).ReadOnly) and (cboObjects.ItemIndex >= 0) then
110 begin
111 if Fre is TRichEdit then
112 cnt := TRichEdit(FRe).Lines.Count
113 else
[829]114 cnt := 0;
115 if StrToIntDef(p1, 0) < 0 then
116 begin
117 check := true;
118 for i := low(ScreenReaderCodeIDs) to high(ScreenReaderCodeIDs) do
119 begin
120 if p1 = ScreenReaderCodeIDs[i] then
121 begin
122 p2 := ScreenReaderCodes[i];
123 check := FALSE;
124 break;
125 end;
126 end;
127 end
128 else
129 check := TRUE;
130 if check then
131 p2 := TemplateFieldBeginSignature + Piece(cboObjects.Items[cboObjects.ItemIndex],U,2) +
132 TemplateFieldEndSignature;
133 Fre.SelText := p2;
[456]134 if Fre is TRichEdit then
135 if(assigned(FAutoLongLines) and (cnt <> TRichEdit(FRe).Lines.Count)) then
136 FAutoLongLines(Self);
137 end;
138end;
139
140procedure TfrmTemplateFields.cboObjectsDblClick(Sender: TObject);
141begin
[829]142 if ValidInsert then
[456]143 InsertField;
144end;
145
146procedure TfrmTemplateFields.btnCancelClick(Sender: TObject);
147begin
148 Close;
149end;
150
151procedure TfrmTemplateFields.FormClose(Sender: TObject;
152 var Action: TCloseAction);
153begin
154 Action := caHide;
155end;
156
157procedure TfrmTemplateFields.Setre(const Value: TCustomEdit);
158begin
159 Fre := Value;
160 UpdateStatus;
161end;
162
163procedure TfrmTemplateFields.UpdateStatus;
164begin
[829]165 FInsertAllowed := (not TORExposedCustomEdit(re).ReadOnly);
166 btnInsert.Enabled := ValidInsert and FInsertAllowed;
[456]167end;
168
[829]169function TfrmTemplateFields.ValidInsert: boolean;
170begin
171 Result := (cboObjects.ItemIndex >= 0);
172 if Result then
173 Result := (Piece(cboObjects.Items[cboObjects.ItemIndex],U,1) <> '');
174end;
175
176function TfrmTemplateFields.ValidPreview: boolean;
177var
178 i: integer;
179 code: string;
180begin
181 Result := ValidInsert;
182 if Result then
183 begin
184 code := Piece(cboObjects.Items[cboObjects.ItemIndex],U,1);
185 for I := low(ScreenReaderCodeIDs) to high(ScreenReaderCodeIDs) do
186 begin
187 if code = ScreenReaderCodeIDs[i] then
188 begin
189 Result := FALSE;
190 break;
191 end;
192 end;
193 end;
194end;
195
[456]196procedure TfrmTemplateFields.btnInsertClick(Sender: TObject);
197begin
[829]198 if ValidInsert then
199 InsertField;
[456]200end;
201
202procedure TfrmTemplateFields.btnPreviewClick(Sender: TObject);
203var
204 tmp, txt: string;
205
206
207begin
208 if(cboObjects.ItemIndex >= 0) then
209 begin
210 FormStyle := fsNormal;
211 try
212 txt := Piece(cboObjects.Items[cboObjects.ItemIndex],U,2);
213 tmp := TemplateFieldBeginSignature + txt + TemplateFieldEndSignature;
214 CheckBoilerplate4Fields(tmp, 'Preview Template Field: ' + txt, TRUE);
215 finally
216 FormStyle := fsStayOnTop;
217 end;
218 end;
219end;
220
221procedure TfrmTemplateFields.cboObjectsChange(Sender: TObject);
222begin
[829]223 btnPreview.Enabled := ValidPreview;
224 btnInsert.Enabled := ValidInsert and FInsertAllowed;
[456]225end;
226
227end.
Note: See TracBrowser for help on using the repository browser.