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