Index: cprs/branches/HealthSevak-CPRS/CPRS-Chart/fHunSpell.pas
===================================================================
--- cprs/branches/HealthSevak-CPRS/CPRS-Chart/fHunSpell.pas	(revision 1700)
+++ cprs/branches/HealthSevak-CPRS/CPRS-Chart/fHunSpell.pas	(revision 1719)
@@ -45,5 +45,5 @@
     OpenDialog1: TOpenDialog;
     SpellCheck1: TskaHunSpellChecker;
-    Edit1: TEdit;
+    edtDictionary: TEdit;
     btnSelectDict: TBitBtn;
     lblOpenMedURL: TLabel;
@@ -54,5 +54,5 @@
     lstSuggestions: TListBox;
     Label4: TLabel;
-    Edit2: TEdit;
+    edtMisSpelt: TEdit;
     btnReplaceWith: TButton;
     btnChangeAll: TButton;
@@ -61,9 +61,11 @@
     btnIgnoreAll: TButton;
     btnIgnoreOnce: TButton;
-    btnCancel: TButton;
+    btnAbort: TButton;
     btnAbout: TButton;
     pnlAbout: TPanel;
     Button1: TButton;
     btnUndo: TButton;
+    cbIgnoreAllCaps: TCheckBox;
+    cbIgnoreDigit: TCheckBox;
     procedure FormCreate(Sender: TObject);
     procedure btnIgnoreOnceClick(Sender: TObject);
@@ -74,10 +76,10 @@
     procedure FormActivate(Sender: TObject);
     procedure btnSelectDictClick(Sender: TObject);
-    procedure Edit1Enter(Sender: TObject);
+    procedure edtDictionaryEnter(Sender: TObject);
     procedure btnReplaceWithClick(Sender: TObject);
     procedure btnAddToDictionaryClick(Sender: TObject);
     procedure FormShow(Sender: TObject);
     procedure FormClose(Sender: TObject; var Action: TCloseAction);
-    procedure btnCancelClick(Sender: TObject);
+    procedure btnAbortClick(Sender: TObject);
     procedure lblOpenMedURLClick(Sender: TObject);
     procedure btnAboutClick(Sender: TObject);
@@ -88,10 +90,18 @@
     procedure RichEdit1KeyDown(Sender: TObject; var Key: Word;
       Shift: TShiftState);
+    procedure lstSuggestionsDblClick(Sender: TObject);
+    procedure SpellCheck1StateChange(const Sender: TObject;
+      const State: TSpellState);
+    procedure SpellCheck1Abort(Sender: TObject);
+    procedure SpellCheck1Start(Sender: TObject);
+    procedure cbIgnoreAllCapsClick(Sender: TObject);
+    procedure cbIgnoreDigitClick(Sender: TObject);
+    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
   private
     { Private declarations }
     NoEngineOpted: Boolean;
     FSourceControl: TCustomMemo;
-    WaitForUser: Boolean;
     procedure GoToURL(const aURL: String);
+    procedure UpdateGUI;
   public
     { Public declarations }
@@ -104,4 +114,18 @@
   end;
 
+  Resourcestring
+    TX_AFF_NOT_FOUND      = 'Correspong AFF file named not found!'
+                          + #13
+                          + '  Specify dictionary file whose *.aff is also '
+                          + 'present in same directory.' ;
+    TX_DIC_FILE_NOT_FOUND = 'Dictionary File for SpellCheck Engine not found!';
+    TX_SPELL_COMPLETE     = 'Spell Check Complete';
+    TX_SPELL_CANCELLED    = 'Spell Check Aborted'
+                          + #13
+                          + 'No Changes applied to the original text!';
+
+ Const
+   DefaultDicFile =  'dict\en-US-OpenMedSpel.dic';
+
  var
   frmHunSpell: TfrmHunSpell;
@@ -130,12 +154,10 @@
  procedure TfrmHunSpell.FormShow(Sender: TObject);
 begin
- if SpellCheck1.SpellCheckState = ssNotStarted then
+ if SpellCheck1.SpellCheckState = ssReady then
    SpellCheck1.CheckSpelling;
-
  try
    if lstSuggestions.Count > 0 then
      btnChange.SetFocus;
  except
-
  end;
 end;
@@ -153,9 +175,16 @@
 end;
 
+procedure TfrmHunSpell.lstSuggestionsDblClick(Sender: TObject);
+begin
+  inherited;
+  btnChangeClick(sender);
+end;
+
 procedure TfrmHunSpell.RichEdit1KeyDown(Sender: TObject; var Key: Word;
   Shift: TShiftState);
 begin
   inherited;
-  SpellCheck1.ManualChangeStart;
+  if SpellCheck1.SpellCheckState = ssChecking then
+    SpellCheck1.ManualChangeStart;
 end;
 
@@ -164,5 +193,42 @@
 begin
   inherited;
-  SpellCheck1.ManualChangeDone;
+  if SpellCheck1.SpellCheckState in [ssCancelled, ssCompleted] then
+   SpellCheck1.Reopen;
+
+ if SpellCheck1.SpellCheckState = ssChecking then
+    SpellCheck1.ManualChangeDone;
+end;
+
+procedure TfrmHunSpell.SpellCheck1Abort(Sender: TObject);
+begin
+  inherited;
+  UpdateGUI;
+end;
+
+procedure TfrmHunSpell.SpellCheck1Start(Sender: TObject);
+begin
+  inherited;
+  UpdateGUI;
+end;
+
+procedure TfrmHunSpell.SpellCheck1StateChange(const Sender: TObject;
+  const State: TSpellState);
+begin
+  inherited;
+  if State = ssCompleted then
+    ShowMessage(TX_SPELL_COMPLETE);
+  UpdateGUI;
+end;
+
+procedure TfrmHunSpell.UpdateGUI;
+var
+  Checking: Boolean;
+begin
+  if  csDestroying in componentstate then
+     exit;
+  Checking := SpellCheck1.SpellCheckState = ssChecking;
+  pnlMisSpelled.Visible := Checking;
+  pnlMisSpelled.Enabled := Checking;
+  btnClose.Visible := not Checking;
 end;
 
@@ -185,8 +251,8 @@
 end;
 
-procedure TfrmHunSpell.btnCancelClick(Sender: TObject);
+procedure TfrmHunSpell.btnAbortClick(Sender: TObject);
 begin
 //popup 508 compliant confirmation/warning box if isModified
-  if SpellCheck1.AbortSpellCheck(False) then
+  if SpellCheck1.AbortSpellCheck(True) then
   begin
      Close;
@@ -207,5 +273,5 @@
 procedure TfrmHunSpell.btnCloseClick(Sender: TObject);
 begin
- close;
+  close;
 end;
 
@@ -232,5 +298,5 @@
     if not FileExists(aff) then
     begin
-      ShowMessage('Correspong AFF file named "'+ aff + '" not found!' + #13 + '  Specify dictionary file whose *.aff is also present in same directory.');
+      ShowMessage(TX_AFF_NOT_FOUND);
       OpenDialog1.FileName := '';
       btnSelectDictClick(self);
@@ -240,10 +306,8 @@
       if SpellCheck1.SpellCheckState = ssChecking then
         SpellCheck1.AbortSpellCheck(False);
-      Edit1.Text := OpenDialog1.FileName;
-      SpellCheck1.DictionaryFileName := OpenDialog1.FileName;
+      edtDictionary.Text := OpenDialog1.FileName;
+      SpellCheck1.DictionaryFileName := edtDictionary.Text;
       SpellCheck1.AffixFileName := aff;
       SpellCheck1.Open;
-      WaitForUser := False;
-      SpellCheck1.CheckSpelling;
     end;
   end;
@@ -262,5 +326,19 @@
 end;
 
-procedure TfrmHunSpell.Edit1Enter(Sender: TObject);
+procedure TfrmHunSpell.cbIgnoreAllCapsClick(Sender: TObject);
+begin
+  inherited;
+  if SpellCheck1.IgnoreAllCaps <> cbIgnoreAllCaps.Checked then
+    SpellCheck1.IgnoreAllCaps := cbIgnoreAllCaps.Checked;
+end;
+
+procedure TfrmHunSpell.cbIgnoreDigitClick(Sender: TObject);
+begin
+  inherited;
+  if SpellCheck1.IgnoreWordWithDigits <> cbIgnoreDigit.Checked then
+    SpellCheck1.IgnoreWordWithDigits := cbIgnoreDigit.Checked;
+end;
+
+procedure TfrmHunSpell.edtDictionaryEnter(Sender: TObject);
 begin
   btnSelectDict.SetFocus;
@@ -274,4 +352,9 @@
      NoEngineOpted := True;
   end;
+  if cbIgnoreAllCaps.Checked <> SpellCheck1.IgnoreAllCaps then
+    cbIgnoreAllCaps.Checked := SpellCheck1.IgnoreAllCaps;
+
+  if cbIgnoreDigit.Checked <> SpellCheck1.IgnoreWordWithDigits then
+    cbIgnoreDigit.Checked := SpellCheck1.IgnoreWordWithDigits;
 end;
 
@@ -283,26 +366,48 @@
     if Assigned(FSourceControl) then
       FSourceControl.Text := RichEdit1.Text;
+  end;
+  {else
+  ShowMsg(TX_SPELL_CANCELLED + CRLF + TX_NO_CORRECTIONS,
+                                              TShow508MessageIcon(1), smbOK) ;}
+end;
+
+procedure TfrmHunSpell.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
+begin
+  inherited;
+
+  CanClose := (SpellCheck1.SpellCheckState <> ssChecking)
+               or (SpellCheck1.AbortSpellCheck(True));
+  if CanClose then
+     ModalResult := mrCancel;
+end;
+
+procedure TfrmHunSpell.FormCreate(Sender: TObject);
+var
+  dicFile: String;
+  function affFile: String;
+  begin
+    Result := ChangeFileExt(dicFile, '.aff');
+  end;
+begin
+  if (SpellCheck1.DictionaryFileName <>  '') then
+      dicFile := SpellCheck1.DictionaryFileName
+  else
+      dicFile := ExtractFilePath(Application.ExeName)+ DefaultDicFile;
+
+  if (FileExists(dicFile)) and (FileExists(affFile)) then
+  begin
+      SpellCheck1.AffixFileName := affFile;
+      edtDictionary.Text := SpellCheck1.DictionaryFileName;
   end
   else
-        ShowMsg(TX_SPELL_CANCELLED + CRLF + TX_NO_CORRECTIONS,TShow508MessageIcon(1), smbOK) ;
-end;
-
-procedure TfrmHunSpell.FormCreate(Sender: TObject);
-begin
-  if FileExists(ExtractFilePath(Application.ExeName)+'\dict\en-US-OpenMedSpel.dic')
-    and FileExists(ExtractFilePath(Application.ExeName)+'\dict\en-US-OpenMedSpel.aff') then
-  begin
-    SpellCheck1.AffixFileName := ExtractFilePath(Application.ExeName)+'\dict\en-US-OpenMedSpel.aff';
-    SpellCheck1.DictionaryFileName := ExtractFilePath(Application.ExeName)+'\dict\en-US-OpenMedSpel.dic';
-    Edit1.Text := SpellCheck1.DictionaryFileName;
-    SpellCheck1.Active := True;
-  end
-  else
-    Edit1.Text := 'Dictionary File for SpellCheck Engine not found!';
-    
+    edtDictionary.Text := TX_Dic_File_Not_Found;
+
+  if edtDictionary.Text = TX_Dic_File_Not_Found then
+    btnSelectDictClick(self);
   SpellCheck1.SourceTextControl := RichEdit1;
   SpellCheck1.SuggestionList := lstSuggestions;
-  SpellCheck1.MisSpeltWord := Edit2;
-  SpellCheck1.btnClose := btnClose;
+  SpellCheck1.MisSpeltWord := edtMisSpelt;
+  SpellCheck1.Active :=  (SpellCheck1.DictionaryFileName <>  '')
+                                                      and FileExists(dicFile);
 end;
 
