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