Index: cprs/trunk/CPRS-Chart/Templates/fTemplateFields.pas
===================================================================
--- cprs/trunk/CPRS-Chart/Templates/fTemplateFields.pas	(revision 456)
+++ cprs/trunk/CPRS-Chart/Templates/fTemplateFields.pas	(revision 829)
@@ -5,14 +5,21 @@
 uses
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
-  ORCtrls, ComCtrls, StdCtrls, ExtCtrls;
+  ORCtrls, ComCtrls, StdCtrls, ExtCtrls, fBase508Form, VA508AccessibilityManager;
 
 type
-  TfrmTemplateFields = class(TForm)
+  TfrmTemplateFields = class(TfrmBase508Form)
     pnlBottom: TPanel;
     btnCancel: TButton;
     cboObjects: TORComboBox;
     btnInsert: TButton;
-    lblReq: TStaticText;
     btnPreview: TButton;
+    lblReq: TVA508StaticText;
+    pnlBottomSR: TPanel;
+    lblSRCont2: TVA508StaticText;
+    lblSRCont1: TVA508StaticText;
+    lblSRStop: TVA508StaticText;
+    pnlSRIntro: TPanel;
+    lblSRIntro1: TVA508StaticText;
+    lblSRIntro2: TVA508StaticText;
     procedure FormShow(Sender: TObject);
     procedure FormCreate(Sender: TObject);
@@ -28,8 +35,12 @@
 {    Fre: TRichEdit;}
     Fre: TCustomEdit;
+    FInsertAllowed: boolean;
+    FInitialized: boolean;
     FAutoLongLines: TNotifyEvent;
     procedure InsertField;
 {    procedure Setre(const Value: TRichEdit);}
     procedure Setre(const Value: TCustomEdit);
+    function ValidPreview: boolean;
+    function ValidInsert: boolean;
   public
     procedure UpdateStatus;
@@ -47,5 +58,18 @@
 
 procedure TfrmTemplateFields.FormShow(Sender: TObject);
-begin
+var
+  i: integer;
+begin
+  if not FInitialized then
+  begin
+    with cboObjects do
+    begin
+      for i := low(ScreenReaderCodeLines) to high(ScreenReaderCodeLines) do
+        Items.Add(ScreenReaderCodeLines[i]);
+      InsertSeparator;
+      InitLongList('');
+    end;
+    FInitialized := TRUE;
+  end;
   cboObjects.SelectAll;
   cboObjects.SetFocus;
@@ -54,10 +78,10 @@
 procedure TfrmTemplateFields.FormCreate(Sender: TObject);
 begin
-  cboObjects.InitLongList('');
-  cboObjects.ItemHeight := 15;
-  ResizeAnchoredFormToFont(self);
-  //ResizeAnchoredFormToFont doesn't work right on the button positions for some reason.
-  btnCancel.Left := pnlBottom.ClientWidth - btnCancel.Width;
-  btnInsert.Left := btnCancel.Left - btnInsert.Width - 8;
+  ResizeFormToFont(self);
+  cboObjects.ItemHeight := lblReq.Height - 1;
+  FInsertAllowed := TRUE;
+  lblReq.Top := (pnlBottom.Height - lblReq.Height);
+  pnlSRIntro.Height := lblSRStop.Height;
+  pnlBottomSR.Height := lblSRCont1.Height * 4 + 5;
 end;
 
@@ -76,6 +100,11 @@
 var
   cnt: integer;
-
-begin
+  p1, p2: string;
+  check: boolean;
+  i: integer;
+
+begin
+  p1 := Piece(cboObjects.Items[cboObjects.ItemIndex],U,1);
+  if p1 = '' then exit;
   if assigned(Fre) and (not TORExposedCustomEdit(Fre).ReadOnly) and (cboObjects.ItemIndex >= 0) then
   begin
@@ -83,8 +112,24 @@
       cnt := TRichEdit(FRe).Lines.Count
     else
-      cnt :=0;
-    Fre.SelText := TemplateFieldBeginSignature +
-                   Piece(cboObjects.Items[cboObjects.ItemIndex],U,2)+
-                   TemplateFieldEndSignature;
+      cnt := 0;
+    if StrToIntDef(p1, 0) < 0 then
+    begin
+      check := true;
+      for i := low(ScreenReaderCodeIDs) to high(ScreenReaderCodeIDs) do
+      begin
+        if p1 = ScreenReaderCodeIDs[i] then
+        begin
+          p2 := ScreenReaderCodes[i];
+          check := FALSE;
+          break;
+        end;
+      end;
+    end
+    else
+      check := TRUE;
+    if check then
+      p2 := TemplateFieldBeginSignature + Piece(cboObjects.Items[cboObjects.ItemIndex],U,2) +
+            TemplateFieldEndSignature;
+    Fre.SelText := p2;
     if Fre is TRichEdit then
       if(assigned(FAutoLongLines) and (cnt <> TRichEdit(FRe).Lines.Count)) then
@@ -95,5 +140,5 @@
 procedure TfrmTemplateFields.cboObjectsDblClick(Sender: TObject);
 begin
-  if btnInsert.Enabled then
+  if ValidInsert then
     InsertField;
 end;
@@ -118,10 +163,39 @@
 procedure TfrmTemplateFields.UpdateStatus;
 begin
-  btnInsert.Enabled := (not TORExposedCustomEdit(re).ReadOnly);
+  FInsertAllowed := (not TORExposedCustomEdit(re).ReadOnly);
+  btnInsert.Enabled := ValidInsert and FInsertAllowed;
+end;
+
+function TfrmTemplateFields.ValidInsert: boolean;
+begin
+  Result := (cboObjects.ItemIndex >= 0);
+  if Result then
+    Result := (Piece(cboObjects.Items[cboObjects.ItemIndex],U,1) <> '');
+end;
+
+function TfrmTemplateFields.ValidPreview: boolean;
+var
+  i: integer;
+  code: string;
+begin
+  Result := ValidInsert;
+  if Result then
+  begin
+    code := Piece(cboObjects.Items[cboObjects.ItemIndex],U,1);
+    for I := low(ScreenReaderCodeIDs) to high(ScreenReaderCodeIDs) do
+    begin
+      if code = ScreenReaderCodeIDs[i] then
+      begin
+        Result := FALSE;
+        break;
+      end;
+    end;
+  end;
 end;
 
 procedure TfrmTemplateFields.btnInsertClick(Sender: TObject);
 begin
-  InsertField;
+  if ValidInsert then
+    InsertField;
 end;
 
@@ -147,5 +221,6 @@
 procedure TfrmTemplateFields.cboObjectsChange(Sender: TObject);
 begin
-  btnPreview.Enabled := (cboObjects.ItemIndex >= 0)
+  btnPreview.Enabled := ValidPreview;
+  btnInsert.Enabled := ValidInsert and FInsertAllowed;
 end;
 
