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

Last change on this file since 730 was 729, checked in by Kevin Toppenberg, 15 years ago

Added functions to Templates, and Images tab

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