1 | //kt -- Modified with SourceScanner on 8/8/2007
|
---|
2 | unit fTemplateDialog;
|
---|
3 |
|
---|
4 | interface
|
---|
5 |
|
---|
6 | uses
|
---|
7 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
---|
8 | StdCtrls, StrUtils, ExtCtrls, ORCtrls, ORFn, AppEvnts, uTemplates, DKLang;
|
---|
9 |
|
---|
10 | type
|
---|
11 | TfrmTemplateDialog = class(TForm)
|
---|
12 | sbMain: TScrollBox;
|
---|
13 | pnlBottom: TScrollBox;
|
---|
14 | btnCancel: TButton;
|
---|
15 | btnOK: TButton;
|
---|
16 | btnAll: TButton;
|
---|
17 | btnNone: TButton;
|
---|
18 | lblFootnote: TStaticText;
|
---|
19 | btnPreview: TButton;
|
---|
20 | DKLanguageController1: TDKLanguageController;
|
---|
21 | procedure btnAllClick(Sender: TObject);
|
---|
22 | procedure btnNoneClick(Sender: TObject);
|
---|
23 | procedure FormPaint(Sender: TObject);
|
---|
24 | procedure FormCreate(Sender: TObject);
|
---|
25 | procedure FormDestroy(Sender: TObject);
|
---|
26 | procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
---|
27 | procedure btnOKClick(Sender: TObject);
|
---|
28 | procedure btnPreviewClick(Sender: TObject);
|
---|
29 | procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
30 | private
|
---|
31 | SL: TStrings;
|
---|
32 | BuildIdx: TStringList;
|
---|
33 | Entries: TStringList;
|
---|
34 | NoTextID: TStringList;
|
---|
35 | Index: string;
|
---|
36 | OneOnly: boolean;
|
---|
37 | Count: integer;
|
---|
38 | RepaintBuild: boolean;
|
---|
39 | FirstIndent: integer;
|
---|
40 | FBuilding: boolean;
|
---|
41 | FOldHintEvent: TShowHintEvent;
|
---|
42 | FMaxPnlWidth: integer;
|
---|
43 | FTabPos: integer;
|
---|
44 | FCheck4Required: boolean;
|
---|
45 | FSilent: boolean;
|
---|
46 | FHTMLMode : boolean; //kt added 12/28/09
|
---|
47 | FAnswerOpenTag : string; //kt added 12/28/09
|
---|
48 | FAnswerCloseTag : string; //kt added 12/28/09
|
---|
49 | procedure SizeFormToCancelBtn();
|
---|
50 | procedure ChkAll(Chk: boolean);
|
---|
51 | procedure BuildCB(CBidx: integer; var Y: integer; FirstTime: boolean);
|
---|
52 | procedure ItemChecked(Sender: TObject);
|
---|
53 | procedure BuildAllControls;
|
---|
54 | procedure AppShowHint(var HintStr: string; var CanShow: Boolean;
|
---|
55 | var HintInfo: THintInfo);
|
---|
56 | procedure FieldChanged(Sender: TObject);
|
---|
57 | procedure EntryDestroyed(Sender: TObject);
|
---|
58 | function GetObjectID( Control: TControl): string;
|
---|
59 | function GetParentID( Control: TControl): string;
|
---|
60 | function FindObjectByID( id: string): TControl;
|
---|
61 | function IsAncestor( OldID: string; NewID: string): boolean;
|
---|
62 | procedure ParentCBEnter(Sender: TObject);
|
---|
63 | procedure ParentCBExit(Sender: TObject);
|
---|
64 | procedure SetAnswerHTMLTag(Value : string); //kt 12/28/09
|
---|
65 | public
|
---|
66 | property Silent: boolean read FSilent write FSilent ;
|
---|
67 | property HTMLMode : boolean read FHTMLMode write FHTMLMode; //kt added 12/28/09
|
---|
68 | property HTMLAnswerOpenTag : string read FAnswerOpenTag write SetAnswerHTMLTag; //kt added 12/28/09
|
---|
69 | property HTMLAnswerCloseTag : string read FAnswerCloseTag write SetAnswerHTMLTag; //kt added 12/28/09
|
---|
70 | published
|
---|
71 | end;
|
---|
72 |
|
---|
73 | // Returns True if Cancel button is pressed
|
---|
74 | function DoTemplateDialog(SL: TStrings; const CaptionText: string; PreviewMode: boolean = FALSE): boolean;
|
---|
75 | function RemoveHTMLTags(Txt : string) : string;
|
---|
76 | function FormatHTMLTags(Txt : string): string;
|
---|
77 | procedure CheckBoilerplate4Fields(SL: TStrings; const CaptionText: string = ''; PreviewMode: boolean = FALSE); overload;
|
---|
78 | procedure CheckBoilerplate4Fields(var AText: string; const CaptionText: string = ''; PreviewMode: boolean = FALSE); overload;
|
---|
79 |
|
---|
80 | var
|
---|
81 | frmTemplateDialog: TfrmTemplateDialog;
|
---|
82 |
|
---|
83 | const
|
---|
84 | HTMLBEGINNINGTAG = '{HTML:'; //kt
|
---|
85 | HTMLENDINGTAG = '}'; //kt
|
---|
86 | HTMLBEGINNINGTAGLEN = length(HTMLBEGINNINGTAG); //kt
|
---|
87 | HTMLENDINGTAGLEN = length(HTMLENDINGTAG); //kt
|
---|
88 |
|
---|
89 | implementation
|
---|
90 |
|
---|
91 | uses dShared, uConst, uTemplateFields, fRptBox, uInit, rMisc, fNotes;
|
---|
92 |
|
---|
93 | {$R *.DFM}
|
---|
94 |
|
---|
95 | const
|
---|
96 | Gap = 4;
|
---|
97 | IndentGap = 18;
|
---|
98 |
|
---|
99 |
|
---|
100 |
|
---|
101 | procedure GetText(SL: TStrings; IncludeEmbeddedFields: Boolean);
|
---|
102 | var
|
---|
103 | i, p1, p2: integer;
|
---|
104 | Txt, tmp: string;
|
---|
105 | Save, Hidden: boolean;
|
---|
106 | TmpCtrl: TStringList;
|
---|
107 | HTMLMode : boolean; //kt added 12/28/09
|
---|
108 | HTMLOpenTag,HTMLCloseTag : string; //kt added 12/28/09
|
---|
109 | begin
|
---|
110 | Txt := SL.Text;
|
---|
111 | SL.Clear;
|
---|
112 | TmpCtrl := TStringList.Create;
|
---|
113 | HTMLMode := frmTemplateDialog.HTMLMode; //kt added 12/28/09
|
---|
114 | HTMLOpenTag := frmTemplateDialog.HTMLAnswerOpenTag; //kt added 12/28/09
|
---|
115 | HTMLCloseTag := frmTemplateDialog.HTMLAnswerCloseTag; //kt added 12/28/09
|
---|
116 | //kt added 12/28/09
|
---|
117 | try
|
---|
118 | for i := 0 to frmTemplateDialog.sbMain.ControlCount-1 do
|
---|
119 | with frmTemplateDialog.sbMain do
|
---|
120 | begin
|
---|
121 | tmp := IntToStr(Controls[i].Tag);
|
---|
122 | tmp := StringOfChar('0', 7-length(tmp)) + tmp;
|
---|
123 | TmpCtrl.AddObject(tmp, Controls[i]);
|
---|
124 | end;
|
---|
125 | TmpCtrl.Sort;
|
---|
126 | for i := 0 to TmpCtrl.Count-1 do
|
---|
127 | begin
|
---|
128 | Save := FALSE;
|
---|
129 | if(TmpCtrl.Objects[i] is TORCheckBox) and (TORCheckBox(TmpCtrl.Objects[i]).Checked) then
|
---|
130 | Save := TRUE
|
---|
131 | else
|
---|
132 | if(frmTemplateDialog.OneOnly and (TmpCtrl.Objects[i] is TPanel)) then
|
---|
133 | Save := TRUE;
|
---|
134 | if(Save) then
|
---|
135 | begin
|
---|
136 | tmp := Piece(frmTemplateDialog.Index,U,TControl(TmpCtrl.Objects[i]).Tag);
|
---|
137 | p1 := StrToInt(Piece(tmp,'~',1));
|
---|
138 | p2 := StrToInt(Piece(tmp,'~',2));
|
---|
139 | Hidden := (copy(Piece(tmp,'~',3),2,1)=BOOLCHAR[TRUE]);
|
---|
140 | //kt original line 12/28/09 --> SL.Text := SL.Text + ResolveTemplateFields(Copy(Txt,p1,p2), FALSE, Hidden, IncludeEmbeddedFields);
|
---|
141 | SL.Text := SL.Text + ResolveTemplateFields(Copy(Txt,p1,p2), FALSE, Hidden, IncludeEmbeddedFields,
|
---|
142 | HTMLMode, HTMLOpenTag, HTMLCloseTag );
|
---|
143 | end;
|
---|
144 | end;
|
---|
145 | finally
|
---|
146 | TmpCtrl.Free;
|
---|
147 | end;
|
---|
148 | end;
|
---|
149 |
|
---|
150 | // Returns True if Cancel button is pressed
|
---|
151 | function DoTemplateDialog(SL: TStrings; const CaptionText: string; PreviewMode: boolean = FALSE): boolean;
|
---|
152 | var
|
---|
153 | i, j, idx, Indent: integer;
|
---|
154 | DlgProps, Txt: string;
|
---|
155 | DlgIDCounts: TStringList;
|
---|
156 | DlgInt: TIntStruc;
|
---|
157 | CancelDlg: Boolean;
|
---|
158 | CancelMsg: String;
|
---|
159 |
|
---|
160 |
|
---|
161 | procedure IncDlgID(var id: string); //Appends an item count in the form of id.0, id.1, id.2, etc
|
---|
162 | var //based on what is in the StringList for id.
|
---|
163 | k: integer;
|
---|
164 |
|
---|
165 | begin
|
---|
166 | k := DlgIDCounts.IndexOf(id);
|
---|
167 |
|
---|
168 | if (k >= 0) then
|
---|
169 | begin
|
---|
170 | DlgInt := TIntStruc(DlgIDCounts.Objects[k]);
|
---|
171 | DlgInt.x := DlgInt.x + 1;
|
---|
172 | id := id + '.' + InttoStr(DlgInt.x);
|
---|
173 | end
|
---|
174 | else
|
---|
175 | begin
|
---|
176 | DlgInt := TIntStruc.Create;
|
---|
177 | DlgInt.x := 0;
|
---|
178 | DlgIDCounts.AddObject(id, DlgInt);
|
---|
179 | id := id + '.0';
|
---|
180 | end;
|
---|
181 |
|
---|
182 | end;
|
---|
183 |
|
---|
184 | procedure CountDlgProps(var DlgID: string); //Updates the item and parent item id's with the count
|
---|
185 | var // value id.0, id.1, id.2, id.3, etc. The input dialog
|
---|
186 | x: integer; // id is in the form 'a;b;c;d', where c is the item id
|
---|
187 | id, pid: string; // and d is the parent item id
|
---|
188 |
|
---|
189 | begin
|
---|
190 | id := piece(DlgID,';',3);
|
---|
191 | pid := piece(DlgID,';',4);
|
---|
192 |
|
---|
193 | if length(pid) > 0 then
|
---|
194 | x := DlgIDCounts.IndexOf(pid)
|
---|
195 | else
|
---|
196 | x := -1;
|
---|
197 |
|
---|
198 | if (x >= 0) then
|
---|
199 | begin
|
---|
200 | DlgInt := TIntStruc(DlgIDCounts.Objects[x]);
|
---|
201 | pid := pid + '.' + InttoStr(DlgInt.x);
|
---|
202 | end;
|
---|
203 |
|
---|
204 | if length(id) > 0 then
|
---|
205 | IncDlgID(id);
|
---|
206 |
|
---|
207 | SetPiece(DlgID,';',3,id);
|
---|
208 | SetPiece(DlgID,';',4,pid);
|
---|
209 | end;
|
---|
210 |
|
---|
211 | begin
|
---|
212 | Result := FALSE;
|
---|
213 | CancelDlg := FALSE;
|
---|
214 | frmTemplateDialog := TfrmTemplateDialog.Create(Application);
|
---|
215 | try
|
---|
216 | DlgIDCounts := TStringList.Create;
|
---|
217 | DlgIDCounts.Sorted := TRUE;
|
---|
218 | DlgIDCounts.Duplicates := dupError;
|
---|
219 | frmTemplateDialog.Caption := CaptionText;
|
---|
220 | frmTemplateDialog.HTMLMode := uTemplates.bUsingHTMLMode; //kt
|
---|
221 | frmTemplateDialog.HTMLAnswerOpenTag := '<I>'; //kt 12/28/09
|
---|
222 | //SL.Text := RemoveHTMLTags(SL.Text); //elh
|
---|
223 | AssignFieldIDs(SL);
|
---|
224 | frmTemplateDialog.SL := SL;
|
---|
225 | frmTemplateDialog.Index := '';
|
---|
226 | Txt := SL.Text;
|
---|
227 | frmTemplateDialog.OneOnly := (DelimCount(Txt, ObjMarker) = 1);
|
---|
228 | frmTemplateDialog.Count := 0;
|
---|
229 | idx := 1;
|
---|
230 | frmTemplateDialog.FirstIndent := 99999;
|
---|
231 | repeat
|
---|
232 | i := pos(ObjMarker, Txt);
|
---|
233 | if(i > 1) then
|
---|
234 | begin
|
---|
235 | j := pos(DlgPropMarker, Txt);
|
---|
236 | if(j > 0) then
|
---|
237 | begin
|
---|
238 | DlgProps := copy(Txt, j + DlgPropMarkerLen, (i - j - DlgPropMarkerLen));
|
---|
239 | CountDlgProps(DlgProps);
|
---|
240 | end
|
---|
241 | else
|
---|
242 | begin
|
---|
243 | DlgProps := '';
|
---|
244 | j := i;
|
---|
245 | end;
|
---|
246 | inc(frmTemplateDialog.Count);
|
---|
247 | frmTemplateDialog.Index := frmTemplateDialog.Index +
|
---|
248 | IntToStr(idx)+'~'+IntToStr(j-1)+'~'+DlgProps+U;
|
---|
249 | inc(idx,i+ObjMarkerLen-1);
|
---|
250 | Indent := StrToIntDef(Piece(DlgProps, ';', 5),0);
|
---|
251 | if(frmTemplateDialog.FirstIndent > Indent) then
|
---|
252 | frmTemplateDialog.FirstIndent := Indent;
|
---|
253 | end;
|
---|
254 | if(i > 0) then
|
---|
255 | delete(txt, 1, i + ObjMarkerLen - 1);
|
---|
256 | until (i = 0);
|
---|
257 | if(frmTemplateDialog.Count > 0) then
|
---|
258 | begin
|
---|
259 | if(frmTemplateDialog.OneOnly) then
|
---|
260 | begin
|
---|
261 | frmTemplateDialog.btnNone.Visible := FALSE;
|
---|
262 | frmTemplateDialog.btnAll.Visible := FALSE;
|
---|
263 | end;
|
---|
264 | frmTemplateDialog.BuildAllControls;
|
---|
265 | repeat
|
---|
266 | if (assigned(frmNotes)) and (frmTemplateDialog.HTMLMode) then frmNotes.HTMLEditor.SetMsgActive(False); //kt 2-1-10
|
---|
267 | frmTemplateDialog.ShowModal;
|
---|
268 | if (assigned(frmNotes)) and (frmTemplateDialog.HTMLMode) then frmNotes.HTMLEditor.SetMsgActive(True); //kt 2-1-10
|
---|
269 | if(frmTemplateDialog.ModalResult = mrOK) then begin
|
---|
270 | GetText(SL, TRUE); {TRUE = Include embedded fields}
|
---|
271 | {
|
---|
272 | if uTemplates.bUsingHTMLMode then begin
|
---|
273 | SL.Text := FormatHTMLTags(SL.Text);
|
---|
274 | end else begin
|
---|
275 | SL.Text := RemoveHTMLTags(SL.Text);
|
---|
276 | end;
|
---|
277 | }
|
---|
278 | end else begin
|
---|
279 | if (not PreviewMode) and (not frmTemplateDialog.Silent) and (not uInit.TimedOut) then
|
---|
280 | begin
|
---|
281 | // CancelMsg := 'If you cancel, your changes will not be saved. Are you sure you want to cancel?'; <-- original line. //kt 8/8/2007
|
---|
282 | CancelMsg := DKLangConstW('fTemplateDialog_If_you_cancelx_your_changes_will_not_be_savedx__Are_you_sure_you_want_to_cancelx'); //kt added 8/8/2007
|
---|
283 | // if (InfoBox(CancelMsg, 'Cancel Dialog Processing', MB_YESNO or MB_DEFBUTTON2 or MB_ICONQUESTION) = ID_YES) then <-- original line. //kt 8/8/2007
|
---|
284 | if (InfoBox(CancelMsg, DKLangConstW('fTemplateDialog_Cancel_Dialog_Processing'), MB_YESNO or MB_DEFBUTTON2 or MB_ICONQUESTION) = ID_YES) then //kt added 8/8/2007
|
---|
285 | begin
|
---|
286 | SL.Clear;
|
---|
287 | Result := TRUE;
|
---|
288 | CancelDlg := TRUE;
|
---|
289 | end
|
---|
290 | else
|
---|
291 | CancelDlg := FALSE;
|
---|
292 | end
|
---|
293 | else
|
---|
294 | begin
|
---|
295 | SL.Clear;
|
---|
296 | Result := TRUE;
|
---|
297 | CancelDlg := TRUE;
|
---|
298 | end;
|
---|
299 | end;
|
---|
300 | until CancelDlg or (frmTemplateDialog.ModalResult = mrOK)
|
---|
301 | end
|
---|
302 | else
|
---|
303 | SL.Clear;
|
---|
304 | finally
|
---|
305 | //frmTemplateDialog.Free; v22.11e RV
|
---|
306 | frmTemplateDialog.Release;
|
---|
307 | //frmTemplateDialog := nil; access violation source? removed 7/28/03 RV
|
---|
308 | for i := 0 to DlgIDCounts.Count-1 do begin
|
---|
309 | DlgIDCounts.Objects[i].Free;
|
---|
310 | end;
|
---|
311 | DlgIDCounts.Free;
|
---|
312 | end;
|
---|
313 |
|
---|
314 | if not Result then
|
---|
315 | CheckBoilerplate4Fields(SL, CaptionText, PreviewMode);
|
---|
316 |
|
---|
317 | end;
|
---|
318 |
|
---|
319 | function RemoveHTMLTags(Txt : string): string;
|
---|
320 | var
|
---|
321 | beginning,ending : integer;
|
---|
322 | tempString,tempResult : string;
|
---|
323 | begin
|
---|
324 | tempString := Txt;
|
---|
325 | //here we will strip out all HTML formatting tags //elh
|
---|
326 | beginning := pos(HTMLBEGINNINGTAG, tempString);
|
---|
327 | if beginning = 0 then begin
|
---|
328 | Result := Txt;
|
---|
329 | end else begin
|
---|
330 | while beginning > 0 do
|
---|
331 | begin
|
---|
332 | tempResult := tempResult + Leftstr(tempString,beginning-1);
|
---|
333 | tempString := Rightstr(tempString,length(tempString)-beginning-HTMLBEGINNINGTAGLEN);
|
---|
334 | ending := pos(HTMLENDINGTAG, tempString);
|
---|
335 | tempString := Rightstr(tempString,length(tempString)-ending);
|
---|
336 | beginning := pos(HTMLBEGINNINGTAG, tempString);
|
---|
337 | // tempString := Midstr(Txt,i,HTMLBEGINNINGTAGLEN);
|
---|
338 | end;
|
---|
339 | Result := tempResult + tempString;
|
---|
340 | end;
|
---|
341 | end;
|
---|
342 |
|
---|
343 | function FormatHTMLTags(Txt : string): string;
|
---|
344 | var
|
---|
345 | beginning,ending : integer;
|
---|
346 | tempString,tempResult : string;
|
---|
347 | begin
|
---|
348 | tempString := Txt;
|
---|
349 | //here we will strip out all HTML formatting tags //elh
|
---|
350 | beginning := pos(HTMLBEGINNINGTAG, tempString);
|
---|
351 | if beginning = 0 then begin
|
---|
352 | Result := Txt;
|
---|
353 | end else begin
|
---|
354 | while beginning > 0 do
|
---|
355 | begin
|
---|
356 | tempResult := tempResult + Leftstr(tempString,beginning-1);
|
---|
357 | tempString := Rightstr(tempString,length(tempString)-beginning-HTMLBEGINNINGTAGLEN+1);
|
---|
358 | ending := pos(HTMLENDINGTAG, tempString);
|
---|
359 | tempResult := tempResult + Leftstr(tempString,ending-1);
|
---|
360 | tempString := Rightstr(tempString,length(tempString)-ending);
|
---|
361 | beginning := pos(HTMLBEGINNINGTAG, tempString);
|
---|
362 | // tempString := Midstr(Txt,i,HTMLBEGINNINGTAGLEN);
|
---|
363 | end;
|
---|
364 | Result := tempResult + tempString;
|
---|
365 | end;
|
---|
366 | end;
|
---|
367 |
|
---|
368 | procedure CheckBoilerplate4Fields(SL: TStrings; const CaptionText: string = ''; PreviewMode: boolean = FALSE);
|
---|
369 | begin
|
---|
370 | while(HasTemplateField(SL.Text)) do
|
---|
371 | begin
|
---|
372 | if (BoilerplateTemplateFieldsOK(SL.Text)) then
|
---|
373 | begin
|
---|
374 | SL[SL.Count-1] := SL[SL.Count-1] + DlgPropMarker + '00100;0;-1;;0' + ObjMarker;
|
---|
375 | DoTemplateDialog(SL, CaptionText, PreviewMode);
|
---|
376 | end
|
---|
377 | else
|
---|
378 | SL.Clear;
|
---|
379 | end;
|
---|
380 | end;
|
---|
381 |
|
---|
382 | procedure CheckBoilerplate4Fields(var AText: string; const CaptionText: string = ''; PreviewMode: boolean = FALSE);
|
---|
383 | var
|
---|
384 | tmp: TStringList;
|
---|
385 |
|
---|
386 | begin
|
---|
387 | tmp := TStringList.Create;
|
---|
388 | try
|
---|
389 | if uTemplates.bUsingHTMLMode then begin //elh 01/04/10
|
---|
390 | tmp.text := FormatHTMLTags(AText);
|
---|
391 | end else begin
|
---|
392 | tmp.text := RemoveHTMLTags(AText);
|
---|
393 | end;
|
---|
394 | //elh tmp.text := AText;
|
---|
395 | CheckBoilerplate4Fields(tmp, CaptionText, PreviewMode);
|
---|
396 | AText := tmp.text;
|
---|
397 | finally
|
---|
398 | tmp.free;
|
---|
399 | end;
|
---|
400 | end;
|
---|
401 |
|
---|
402 | procedure TfrmTemplateDialog.SetAnswerHTMLTag(Value : string);
|
---|
403 | //kt 12/28/09 Added entire function
|
---|
404 | begin
|
---|
405 | if Value='' then begin
|
---|
406 | FAnswerOpenTag :='';
|
---|
407 | FAnswerCloseTag := '';
|
---|
408 | end else begin
|
---|
409 | if Pos('<',Value)>0 then Value := Piece(Value,'<',2);
|
---|
410 | if Pos('>',Value)>0 then Value := Piece(Value,'>',1);
|
---|
411 | if Pos('/',Value)>0 then Value := Piece(Value,'/',2);
|
---|
412 | FAnswerOpenTag :='<'+Value+'>';
|
---|
413 | FAnswerCloseTag := '</' + Value + '>';
|
---|
414 | end;
|
---|
415 | end;
|
---|
416 |
|
---|
417 | procedure TfrmTemplateDialog.ChkAll(Chk: boolean);
|
---|
418 | var
|
---|
419 | i: integer;
|
---|
420 |
|
---|
421 | begin
|
---|
422 | for i := 0 to sbMain.ControlCount-1 do
|
---|
423 | begin
|
---|
424 | if(sbMain.Controls[i] is TORCheckBox) then
|
---|
425 | TORCheckBox(sbMain.Controls[i]).Checked := Chk;
|
---|
426 | end;
|
---|
427 | end;
|
---|
428 |
|
---|
429 | procedure TfrmTemplateDialog.btnAllClick(Sender: TObject);
|
---|
430 | begin
|
---|
431 | ChkAll(TRUE);
|
---|
432 | end;
|
---|
433 |
|
---|
434 | procedure TfrmTemplateDialog.btnNoneClick(Sender: TObject);
|
---|
435 | begin
|
---|
436 | ChkAll(FALSE);
|
---|
437 | end;
|
---|
438 |
|
---|
439 | function TfrmTemplateDialog.GetObjectID( Control: TControl): string;
|
---|
440 | var
|
---|
441 | idx, idx2: integer;
|
---|
442 | begin
|
---|
443 | result := '';
|
---|
444 | if Assigned(Control) then
|
---|
445 | begin
|
---|
446 | idx := Control.Tag;
|
---|
447 | if(idx > 0) then
|
---|
448 | begin
|
---|
449 | idx2 := BuildIdx.IndexOfObject(TObject(idx));
|
---|
450 | if idx2 >= 0 then
|
---|
451 | result := BuildIdx[idx2]
|
---|
452 | else
|
---|
453 | result := Piece(Piece(Piece(Index, U, idx),'~',3), ';', 3);
|
---|
454 | end;
|
---|
455 | end;
|
---|
456 | end;
|
---|
457 |
|
---|
458 | function TfrmTemplateDialog.GetParentID( Control: TControl): string;
|
---|
459 | var
|
---|
460 | idx: integer;
|
---|
461 | begin
|
---|
462 | result := '';
|
---|
463 | if Assigned(Control) then
|
---|
464 | begin
|
---|
465 | idx := Control.Tag;
|
---|
466 | if(idx > 0) then
|
---|
467 | result := Piece(Piece(Piece(Index, U, idx),'~',3), ';', 4);
|
---|
468 | end;
|
---|
469 | end;
|
---|
470 |
|
---|
471 | function TfrmTemplateDialog.FindObjectByID( id: string): TControl;
|
---|
472 | var
|
---|
473 | i: integer;
|
---|
474 | ObjID: string;
|
---|
475 | begin
|
---|
476 | result := nil;
|
---|
477 | if ID <> '' then
|
---|
478 | begin
|
---|
479 | for i := 0 to sbMain.ControlCount-1 do
|
---|
480 | begin
|
---|
481 | ObjID := GetObjectID(sbMain.Controls[i]);
|
---|
482 | if(ObjID = ID) then
|
---|
483 | begin
|
---|
484 | result := sbMain.Controls[i];
|
---|
485 | break;
|
---|
486 | end;
|
---|
487 | end;
|
---|
488 | end;
|
---|
489 | end;
|
---|
490 |
|
---|
491 | function TfrmTemplateDialog.IsAncestor( OldID: string; NewID: string): boolean;
|
---|
492 | begin
|
---|
493 | if (OldID = '') or (NewID = '') then
|
---|
494 | result := False
|
---|
495 | else if OldID = NewID then
|
---|
496 | result := True
|
---|
497 | else
|
---|
498 | result := IsAncestor(OldID, GetParentID(FindObjectByID(NewID)));
|
---|
499 | end;
|
---|
500 |
|
---|
501 | procedure TfrmTemplateDialog.BuildCB(CBidx: integer; var Y: integer; FirstTime: boolean);
|
---|
502 | var
|
---|
503 | bGap, Indent, i, idx, p1, p2: integer;
|
---|
504 | EID, ID, PID, DlgProps, tmp, txt, tmpID: string;
|
---|
505 | pctrl, ctrl: TControl;
|
---|
506 | pnl: TPanel;
|
---|
507 | KillCtrl, doHint, dsp, noTextParent: boolean;
|
---|
508 | Entry: TTemplateDialogEntry;
|
---|
509 | StringIn, StringOut: string;
|
---|
510 |
|
---|
511 | procedure NextTabCtrl(ACtrl: TControl);
|
---|
512 | begin
|
---|
513 | if(ACtrl is TWinControl) then
|
---|
514 | begin
|
---|
515 | inc(FTabPos);
|
---|
516 | TWinControl(ACtrl).TabOrder := FTabPos;
|
---|
517 | end;
|
---|
518 | end;
|
---|
519 |
|
---|
520 | begin
|
---|
521 | tmp := Piece(Index, U, CBidx);
|
---|
522 | p1 := StrToInt(Piece(tmp,'~',1));
|
---|
523 | p2 := StrToInt(Piece(tmp,'~',2));
|
---|
524 | DlgProps := Piece(tmp,'~',3);
|
---|
525 | ID := Piece(DlgProps, ';', 3);
|
---|
526 | PID := Piece(DlgProps, ';', 4);
|
---|
527 |
|
---|
528 | ctrl := nil;
|
---|
529 | pctrl := nil;
|
---|
530 | if(PID <> '') then
|
---|
531 | noTextParent := (NoTextID.IndexOf(PID) < 0)
|
---|
532 | else
|
---|
533 | noTextParent := TRUE;
|
---|
534 | if not FirstTime then
|
---|
535 | ctrl := FindObjectByID(ID);
|
---|
536 | if noTextParent and (PID <> '') then
|
---|
537 | pctrl := FindObjectByID(PID);
|
---|
538 | if(PID = '') then
|
---|
539 | KillCtrl := FALSE
|
---|
540 | else
|
---|
541 | begin
|
---|
542 | if(assigned(pctrl)) then
|
---|
543 | begin
|
---|
544 | if(not (pctrl is TORCheckBox)) or
|
---|
545 | (copy(DlgProps,3,1) = BOOLCHAR[TRUE]) then // show if parent is unchecked
|
---|
546 | KillCtrl := FALSE
|
---|
547 | else
|
---|
548 | KillCtrl := (not TORCheckBox(pctrl).Checked);
|
---|
549 | end
|
---|
550 | else
|
---|
551 | KillCtrl := noTextParent;
|
---|
552 | end;
|
---|
553 | if KillCtrl then
|
---|
554 | begin
|
---|
555 | if(assigned(ctrl)) then
|
---|
556 | begin
|
---|
557 | if(ctrl is TORCheckBox) and (assigned(TORCheckBox(ctrl).Associate)) then
|
---|
558 | TORCheckBox(ctrl).Associate.Hide;
|
---|
559 | idx := BuildIdx.IndexOfObject(TObject(ctrl.Tag));
|
---|
560 | if idx >= 0 then
|
---|
561 | BuildIdx.delete(idx);
|
---|
562 | ctrl.Free;
|
---|
563 | end;
|
---|
564 | exit;
|
---|
565 | end;
|
---|
566 | tmp := copy(SL.Text, p1, p2);
|
---|
567 | tmp := RemoveHTMLTags(tmp);
|
---|
568 | if(copy(tmp, length(tmp)-1, 2) = CRLF) then
|
---|
569 | delete(tmp, length(tmp)-1, 2);
|
---|
570 | bGap := StrToIntDef(copy(DlgProps,5,1),0);
|
---|
571 | while bGap > 0 do
|
---|
572 | begin
|
---|
573 | if(copy(tmp, 1, 2) = CRLF) then
|
---|
574 | begin
|
---|
575 | delete(tmp, 1, 2);
|
---|
576 | dec(bGap);
|
---|
577 | end
|
---|
578 | else
|
---|
579 | bGap := 0;
|
---|
580 | end;
|
---|
581 | if(tmp = NoTextMarker) then
|
---|
582 | begin
|
---|
583 | if(NoTextID.IndexOf(ID) < 0) then
|
---|
584 | NoTextID.Add(ID);
|
---|
585 | exit;
|
---|
586 | end;
|
---|
587 | if(not assigned(ctrl)) then
|
---|
588 | begin
|
---|
589 | dsp := (copy(DlgProps,1,1)=BOOLCHAR[TRUE]);
|
---|
590 | EID := 'DLG' + IntToStr(CBIdx);
|
---|
591 | idx := Entries.IndexOf(EID);
|
---|
592 | doHint := FALSE;
|
---|
593 | txt := tmp;
|
---|
594 | if(idx < 0) then
|
---|
595 | begin
|
---|
596 | if(copy(DlgProps,2,1)=BOOLCHAR[TRUE]) then // First Line Only
|
---|
597 | begin
|
---|
598 | i := pos(CRLF, tmp);
|
---|
599 | if(i > 0) then
|
---|
600 | begin
|
---|
601 | dec(i);
|
---|
602 | if i > 70 then
|
---|
603 | begin
|
---|
604 | i := 71;
|
---|
605 | while (i > 0) and (tmp[i] <> ' ') do dec(i);
|
---|
606 | if i = 0 then
|
---|
607 | i := 70
|
---|
608 | else
|
---|
609 | dec(i);
|
---|
610 | end;
|
---|
611 | doHint := TRUE;
|
---|
612 | tmp := copy(tmp, 1, i) + ' ...';
|
---|
613 | end;
|
---|
614 | end;
|
---|
615 | Entry := GetDialogEntry(sbMain, EID, tmp);
|
---|
616 | Entry.AutoDestroyOnPanelFree := TRUE;
|
---|
617 | Entry.OnDestroy := EntryDestroyed;
|
---|
618 | Entries.AddObject(EID, Entry);
|
---|
619 | end
|
---|
620 | else
|
---|
621 | Entry := TTemplateDialogEntry(Entries.Objects[idx]);
|
---|
622 |
|
---|
623 | pnl := Entry.GetPanel(FMaxPnlWidth, sbMain);
|
---|
624 | pnl.Show;
|
---|
625 | if(doHint and (not pnl.ShowHint)) then
|
---|
626 | begin
|
---|
627 | pnl.ShowHint := TRUE;
|
---|
628 | Entry.Obj := pnl;
|
---|
629 | Entry.Text := txt;
|
---|
630 | pnl.hint := Entry.GetText;
|
---|
631 | Entry.OnChange := FieldChanged;
|
---|
632 | end;
|
---|
633 | if(dsp or OneOnly) then
|
---|
634 | ctrl := pnl
|
---|
635 | else
|
---|
636 | begin
|
---|
637 | ctrl := TORCheckBox.Create(Self);
|
---|
638 | ctrl.Parent := sbMain;
|
---|
639 |
|
---|
640 | TORCheckbox(ctrl).OnEnter := frmTemplateDialog.ParentCBEnter;
|
---|
641 | TORCheckbox(ctrl).OnExit := frmTemplateDialog.ParentCBExit;
|
---|
642 |
|
---|
643 | TORCheckBox(ctrl).Height := TORCheckBox(ctrl).Height + 5;
|
---|
644 | TORCheckBox(ctrl).Width := 17;
|
---|
645 |
|
---|
646 | {Insert next line when focus fixed}
|
---|
647 | // ctrl.Width := IndentGap;
|
---|
648 | {Remove next line when focus fixed}
|
---|
649 | TORCheckBox(ctrl).AutoSize := false;
|
---|
650 | TORCheckBox(ctrl).Associate := pnl;
|
---|
651 | tmpID := copy(ID, 1, (pos('.', ID) - 1)); {copy the ID without the decimal place}
|
---|
652 | if Templates.IndexOf(tmpID) > -1 then
|
---|
653 | // StringIn := 'Sub-Template: ' + TTemplate(Templates.Objects[Templates.IndexOf(tmpID)]).PrintName <-- original line. //kt 8/8/2007
|
---|
654 | StringIn := DKLangConstW('fTemplateDialog_SubxTemplatex') + TTemplate(Templates.Objects[Templates.IndexOf(tmpID)]).PrintName //kt added 8/8/2007
|
---|
655 | else
|
---|
656 | // StringIn := 'Sub-Template:'; <-- original line. //kt 8/8/2007
|
---|
657 | StringIn := DKLangConstW('fTemplateDialog_SubxTemplatex'); //kt added 8/8/2007
|
---|
658 | StringOut := StringReplace(StringIn, '&', '&&', [rfReplaceAll]);
|
---|
659 | TORCheckBox(ctrl).Caption := StringOut;
|
---|
660 |
|
---|
661 | end;
|
---|
662 | ctrl.Tag := CBIdx;
|
---|
663 |
|
---|
664 | Indent := StrToIntDef(Piece(DlgProps, ';', 5),0) - FirstIndent;
|
---|
665 | if dsp then inc(Indent);
|
---|
666 | ctrl.Left := Gap + (Indent * IndentGap);
|
---|
667 | //ctrl.Width := sbMain.ClientWidth - Gap - ctrl.Left - ScrollBarWidth;
|
---|
668 | if(ctrl is TORCheckBox) then
|
---|
669 | pnl.Left := ctrl.Left + IndentGap;
|
---|
670 |
|
---|
671 | if(ctrl is TORCheckBox) then with TORCheckBox(ctrl) do
|
---|
672 | begin
|
---|
673 | GroupIndex := StrToIntDef(Piece(DlgProps, ';', 2),0);
|
---|
674 | if(GroupIndex <> 0) then
|
---|
675 | RadioStyle := TRUE;
|
---|
676 | OnClick := ItemChecked;
|
---|
677 | StringData := DlgProps;
|
---|
678 | end;
|
---|
679 | if BuildIdx.IndexOfObject(TObject(CBIdx)) < 0 then
|
---|
680 | BuildIdx.AddObject(Piece(Piece(Piece(Index, U, CBIdx),'~',3), ';', 3), TObject(CBIdx));
|
---|
681 | end;
|
---|
682 | ctrl.Top := Y;
|
---|
683 | NextTabCtrl(ctrl);
|
---|
684 | if(ctrl is TORCheckBox) then
|
---|
685 | begin
|
---|
686 | TORCheckBox(ctrl).Associate.Top := Y;
|
---|
687 | NextTabCtrl(TORCheckBox(ctrl).Associate);
|
---|
688 | inc(Y, TORCheckBox(ctrl).Associate.Height+1);
|
---|
689 | end
|
---|
690 | else
|
---|
691 | inc(Y, ctrl.Height+1);
|
---|
692 | end;
|
---|
693 |
|
---|
694 | procedure TfrmTemplateDialog.ParentCBEnter(Sender: TObject);
|
---|
695 | begin
|
---|
696 | (Sender as TORCheckbox).FocusOnBox := true;
|
---|
697 | end;
|
---|
698 |
|
---|
699 | procedure TfrmTemplateDialog.ParentCBExit(Sender: TObject);
|
---|
700 | begin
|
---|
701 | (Sender as TORCheckbox).FocusOnBox := false;
|
---|
702 |
|
---|
703 | end;
|
---|
704 |
|
---|
705 | procedure TfrmTemplateDialog.ItemChecked(Sender: TObject);
|
---|
706 | begin
|
---|
707 | if(copy(TORCheckBox(Sender).StringData,4,1) = '1') then
|
---|
708 | begin
|
---|
709 | RepaintBuild := TRUE;
|
---|
710 | Invalidate;
|
---|
711 | end;
|
---|
712 | end;
|
---|
713 |
|
---|
714 | procedure TfrmTemplateDialog.BuildAllControls;
|
---|
715 | var
|
---|
716 | i, Y: integer;
|
---|
717 | FirstTime: boolean;
|
---|
718 |
|
---|
719 | begin
|
---|
720 | if FBuilding then exit;
|
---|
721 | FBuilding := TRUE;
|
---|
722 | try
|
---|
723 | FTabPos := 0;
|
---|
724 | FirstTime := (sbMain.ControlCount = 0);
|
---|
725 | NoTextID.Clear;
|
---|
726 | Y := Gap - sbMain.VertScrollBar.Position;
|
---|
727 | for i := 1 to Count do
|
---|
728 | BuildCB(i, Y, FirstTime);
|
---|
729 | finally
|
---|
730 | FBuilding := FALSE;
|
---|
731 | end;
|
---|
732 | end;
|
---|
733 |
|
---|
734 | procedure TfrmTemplateDialog.FormPaint(Sender: TObject);
|
---|
735 | begin
|
---|
736 | if RepaintBuild then
|
---|
737 | begin
|
---|
738 | RepaintBuild := FALSE;
|
---|
739 | BuildAllControls;
|
---|
740 | end;
|
---|
741 | end;
|
---|
742 |
|
---|
743 | procedure TfrmTemplateDialog.FormCreate(Sender: TObject);
|
---|
744 | begin
|
---|
745 | FHTMLMode := false; //kt added 12/28/09
|
---|
746 | BuildIdx := TStringList.Create;
|
---|
747 | Entries := TStringList.Create;
|
---|
748 | NoTextID := TStringList.Create;
|
---|
749 | FOldHintEvent := Application.OnShowHint;
|
---|
750 | Application.OnShowHint := AppShowHint;
|
---|
751 | ResizeAnchoredFormToFont(Self);
|
---|
752 | FMaxPnlWidth := FontWidthPixel(sbMain.Font.Handle) * MAX_ENTRY_WIDTH; //AGP change Template Dialog to wrap at 80 instead of 74
|
---|
753 | SetFormPosition(Self);
|
---|
754 | SizeFormToCancelBtn();
|
---|
755 | end;
|
---|
756 |
|
---|
757 | procedure TfrmTemplateDialog.AppShowHint(var HintStr: string;
|
---|
758 | var CanShow: Boolean; var HintInfo: THintInfo);
|
---|
759 | const
|
---|
760 | HistHintDelay = 1200000; // 20 minutes
|
---|
761 |
|
---|
762 | begin
|
---|
763 | // if(HintInfo.HintControl.Parent = sbMain) then
|
---|
764 | HintInfo.HideTimeout := HistHintDelay;
|
---|
765 | if(assigned(FOldHintEvent)) then
|
---|
766 | FOldHintEvent(HintStr, CanShow, HintInfo);
|
---|
767 | end;
|
---|
768 |
|
---|
769 | procedure TfrmTemplateDialog.FormDestroy(Sender: TObject);
|
---|
770 | begin
|
---|
771 | //Application.OnShowHint := FOldHintEvent; v22.11f - RV - moved to OnClose
|
---|
772 | NoTextID.Free;
|
---|
773 | FreeEntries(Entries);
|
---|
774 | Entries.Free;
|
---|
775 | BuildIdx.Free;
|
---|
776 | end;
|
---|
777 |
|
---|
778 | procedure TfrmTemplateDialog.FieldChanged(Sender: TObject);
|
---|
779 | begin
|
---|
780 | with TTemplateDialogEntry(Sender) do
|
---|
781 | TPanel(Obj).hint := GetText;
|
---|
782 | end;
|
---|
783 |
|
---|
784 | procedure TfrmTemplateDialog.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
---|
785 | var
|
---|
786 | Txt, tmp: string;
|
---|
787 | i, p1, p2: integer;
|
---|
788 | Save: boolean;
|
---|
789 |
|
---|
790 | begin
|
---|
791 | CanClose := TRUE;
|
---|
792 | if FCheck4Required then
|
---|
793 | begin
|
---|
794 | FCheck4Required := FALSE;
|
---|
795 | Txt := SL.Text;
|
---|
796 | for i := 0 to sbMain.ControlCount-1 do
|
---|
797 | begin
|
---|
798 | Save := FALSE;
|
---|
799 | if(sbMain.Controls[i] is TORCheckBox) and
|
---|
800 | (TORCheckBox(sbMain.Controls[i]).Checked) then
|
---|
801 | Save := TRUE
|
---|
802 | else
|
---|
803 | if(OneOnly and (sbMain.Controls[i] is TPanel)) then
|
---|
804 | Save := TRUE;
|
---|
805 | if(Save) then
|
---|
806 | begin
|
---|
807 | tmp := Piece(Index,U,sbMain.Controls[i].Tag);
|
---|
808 | p1 := StrToInt(Piece(tmp,'~',1));
|
---|
809 | p2 := StrToInt(Piece(tmp,'~',2));
|
---|
810 | if AreTemplateFieldsRequired(Copy(Txt,p1,p2)) then
|
---|
811 | CanClose := FALSE;
|
---|
812 | end;
|
---|
813 | if not CanClose then
|
---|
814 | begin
|
---|
815 | ShowMessage(MissingFieldsTxt);
|
---|
816 | break;
|
---|
817 | end;
|
---|
818 | end;
|
---|
819 | end;
|
---|
820 | end;
|
---|
821 |
|
---|
822 | procedure TfrmTemplateDialog.btnOKClick(Sender: TObject);
|
---|
823 | begin
|
---|
824 | FCheck4Required := TRUE;
|
---|
825 | end;
|
---|
826 |
|
---|
827 | procedure TfrmTemplateDialog.btnPreviewClick(Sender: TObject);
|
---|
828 | var
|
---|
829 | TmpSL: TStringList;
|
---|
830 |
|
---|
831 | begin
|
---|
832 | TmpSL := TStringList.Create;
|
---|
833 | try
|
---|
834 | TmpSL.Assign(SL);
|
---|
835 | GetText(TmpSL, FALSE); {FALSE = Do not include embedded fields}
|
---|
836 | // ReportBox(TmpSL, 'Dialog Preview', FALSE); <-- original line. //kt 8/8/2007
|
---|
837 | ReportBox(TmpSL, DKLangConstW('fTemplateDialog_Dialog_Preview'), FALSE); //kt added 8/8/2007
|
---|
838 | finally
|
---|
839 | TmpSL.Free;
|
---|
840 | end;
|
---|
841 | end;
|
---|
842 |
|
---|
843 | procedure TfrmTemplateDialog.EntryDestroyed(Sender: TObject);
|
---|
844 | var
|
---|
845 | idx: integer;
|
---|
846 |
|
---|
847 | begin
|
---|
848 | idx := Entries.IndexOf(TTemplateDialogEntry(Sender).ID);
|
---|
849 | if idx >= 0 then
|
---|
850 | Entries.delete(idx);
|
---|
851 | end;
|
---|
852 |
|
---|
853 | procedure TfrmTemplateDialog.FormClose(Sender: TObject;
|
---|
854 | var Action: TCloseAction);
|
---|
855 | begin
|
---|
856 | Application.OnShowHint := FOldHintEvent;
|
---|
857 | SaveUserBounds(Self);
|
---|
858 | end;
|
---|
859 |
|
---|
860 | procedure TfrmTemplateDialog.SizeFormToCancelBtn;
|
---|
861 | const
|
---|
862 | RIGHT_MARGIN = 12;
|
---|
863 | var
|
---|
864 | minWidth : integer;
|
---|
865 | begin
|
---|
866 | minWidth := btnCancel.Left + btnCancel.Width + RIGHT_MARGIN;
|
---|
867 | if minWidth > Self.Width then
|
---|
868 | Self.Width := minWidth;
|
---|
869 | end;
|
---|
870 |
|
---|
871 | end.
|
---|
872 |
|
---|