source: cprs/branches/tmg-cprs/CPRS-Chart/Templates/fTemplateDialog.pas@ 654

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

Added HTML templating

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