Ignore:
Timestamp:
Jun 25, 2015, 1:28:09 AM (9 years ago)
Author:
healthsevak
Message:

Cleaned little bit of glitches and added the About dialog and also synced the demo project in line with the updated component properties

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cprs/branches/HealthSevak-CPRS/CPRS-Lib/Hans SpellCheck/Demo/fHunSpell.pas

    r1718 r1725  
    3636  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    3737  StdCtrls, ComCtrls, RichEdit, Buttons, ExtCtrls, ShellAPI,
    38   skaSpellCheck;
     38  skaSpellCheck, jpeg;
    3939
    4040type
    4141  TfrmHunSpell = class(TForm)
    42     lblDictionary: TLabel;
    4342    btnClose: TButton;
    4443    OpenDialog1: TOpenDialog;
     
    4645    edtDictionary: TEdit;
    4746    btnSelectDict: TBitBtn;
    48     lblDictionariesURL: TLabel;
    4947    RichEdit1: TRichEdit;
    50     btnStart: TButton;
    5148    pnlMisSpelled: TPanel;
    5249    Label1: TLabel;
     50    lstSuggestions: TListBox;
    5351    Label4: TLabel;
    54     lstSuggestions: TListBox;
    55     edtMisSpeltWordForExtraHint: TEdit;  //required for screenreaders which are MOSTLY colour blind
     52    edtMisSpelt: TEdit;
    5653    btnReplaceWith: TButton;
    5754    btnChangeAll: TButton;
     
    6158    btnIgnoreOnce: TButton;
    6259    btnAbort: TButton;
     60    btnAbout: TButton;
     61    pnlAbout: TPanel;
     62    btnHideAbout: TButton;
    6363    btnUndo: TButton;
    6464    cbIgnoreAllCaps: TCheckBox;
    6565    cbIgnoreDigit: TCheckBox;
     66    btnRestat: TButton;
     67    cbHyphenatedWord: TCheckBox;
     68    StaticText1: TStaticText;
     69    StaticText2: TStaticText;
     70    StaticText3: TStaticText;
     71    Label2: TLabel;
     72    StaticText4: TStaticText;
     73    Label3: TLabel;
     74    StaticText5: TStaticText;
     75    StaticText6: TStaticText;
     76    Image1: TImage;
     77    lblDictionariesURL: TLabel;
     78    lblDictionary: TLabel;
     79    lblOpenMedURL: TLabel;
     80    Label5: TLabel;
     81    Label6: TLabel;
    6682    procedure FormCreate(Sender: TObject);
    6783    procedure btnIgnoreOnceClick(Sender: TObject);
     
    7591    procedure btnReplaceWithClick(Sender: TObject);
    7692    procedure btnAddToDictionaryClick(Sender: TObject);
     93    procedure FormShow(Sender: TObject);
    7794    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    7895    procedure btnAbortClick(Sender: TObject);
    79     procedure btnStartClick(Sender: TObject);
     96    procedure lblOpenMedURLClick(Sender: TObject);
     97    procedure btnAboutClick(Sender: TObject);
     98    procedure btnHideAboutClick(Sender: TObject);
    8099    procedure btnUndoClick(Sender: TObject);
    81100    procedure RichEdit1KeyUp(Sender: TObject; var Key: Word;
     
    83102    procedure RichEdit1KeyDown(Sender: TObject; var Key: Word;
    84103      Shift: TShiftState);
    85     procedure UpdateGUI;
     104    procedure lstSuggestionsDblClick(Sender: TObject);
     105    procedure SpellCheck1StateChange(const Sender: TObject;
     106      const State: TSpellState);
    86107    procedure SpellCheck1Abort(Sender: TObject);
    87108    procedure SpellCheck1Start(Sender: TObject);
    88     procedure SpellCheck1StateChange(const Sender: TObject;
    89       const State: TSpellState);
    90     procedure lblDictionariesURLClick(Sender: TObject);
    91     procedure lstSuggestionsDblClick(Sender: TObject);
    92109    procedure cbIgnoreAllCapsClick(Sender: TObject);
    93110    procedure cbIgnoreDigitClick(Sender: TObject);
    94111    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
     112    procedure btnRestatClick(Sender: TObject);
     113    procedure cbHyphenatedWordClick(Sender: TObject);
     114    procedure Image1Click(Sender: TObject);
     115    procedure Label6Click(Sender: TObject);
     116    procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    95117  private
    96118    { Private declarations }
     
    98120    FSourceControl: TCustomMemo;
    99121    procedure GoToURL(const aURL: String);
     122    procedure UpdateGUI;
    100123  public
    101124    { Public declarations }
     
    105128    OldRichEditWndProc: {integer}pointer;
    106129    PRichEditWndProc:pointer;
    107     class function DoHunSpellCheck(AnEditControl: TCustomMemo): TModalResult;
    108                                                                       static;
     130    class function DoHunSpellCheck(AnEditControl: TCustomMemo): TModalResult; static;
    109131  end;
    110132
     
    121143
    122144 Const
    123    DefaultDicFile =  'dict\en_GB.dic';//  'dict\en-US-OpenMedSpel.dic';
     145   DefaultDicFile =  '\dict\en_US-large.dic';
     146
    124147 var
    125148  frmHunSpell: TfrmHunSpell;
     
    129152
    130153
    131 class function TfrmHunSpell.DoHunSpellCheck(AnEditControl: TCustomMemo):
    132                                                                    TModalResult;
    133 {This function could be invoked from some other form by using this as modalform
    134 without creating the instance of this form in advance}
     154class function TfrmHunSpell.DoHunSpellCheck(AnEditControl: TCustomMemo): TModalResult;
    135155var
    136156  frm: TfrmHunSpell;
     
    148168
    149169 {************ HighLight ***********888}
    150  procedure TfrmHunSpell.GoToURL(const aURL: String);
     170 procedure TfrmHunSpell.FormShow(Sender: TObject);
     171begin
     172 if SpellCheck1.SpellCheckState = ssReady then
     173   SpellCheck1.CheckSpelling;
     174 try
     175   if lstSuggestions.Count > 0 then
     176     btnChange.SetFocus;
     177 except
     178 end;
     179end;
     180
     181procedure TfrmHunSpell.GoToURL(const aURL: String);
    151182begin
    152183if length(trim(aURL)) > 4 then
     
    154185end;
    155186
    156 procedure TfrmHunSpell.lblDictionariesURLClick(Sender: TObject);
    157 begin
     187procedure TfrmHunSpell.Image1Click(Sender: TObject);
     188begin
     189  inherited;
     190  GoToURL('http://www.healthsevak.com');
     191end;
     192
     193procedure TfrmHunSpell.Label6Click(Sender: TObject);
     194begin
     195  inherited;
     196   GoToURL('mailto: digitiger@gmail.com');
     197end;
     198
     199procedure TfrmHunSpell.lblOpenMedURLClick(Sender: TObject);
     200begin
     201  inherited;
    158202  GoToURL(TLabel(sender).Caption);
    159203end;
     
    161205procedure TfrmHunSpell.lstSuggestionsDblClick(Sender: TObject);
    162206begin
    163 if lstSuggestions.ItemIndex >= 0 then
    164    btnChangeClick(Self);
     207  inherited;
     208  btnChangeClick(sender);
    165209end;
    166210
     
    168212  Shift: TShiftState);
    169213begin
     214  inherited;
    170215  if SpellCheck1.SpellCheckState = ssChecking then
    171216    SpellCheck1.ManualChangeStart;
     
    175220  Shift: TShiftState);
    176221begin
    177  if SpellCheck1.SpellCheckState in [ssCancelled, ssCompleted] then
     222  inherited;
     223  if SpellCheck1.SpellCheckState in [ssCancelled, ssCompleted] then
    178224   SpellCheck1.Reopen;
    179    
     225
    180226 if SpellCheck1.SpellCheckState = ssChecking then
    181227    SpellCheck1.ManualChangeDone;
     
    184230procedure TfrmHunSpell.SpellCheck1Abort(Sender: TObject);
    185231begin
     232  inherited;
    186233  UpdateGUI;
    187234end;
     
    189236procedure TfrmHunSpell.SpellCheck1Start(Sender: TObject);
    190237begin
     238  inherited;
    191239  UpdateGUI;
    192240end;
     
    195243  const State: TSpellState);
    196244begin
     245  inherited;
    197246  if State = ssCompleted then
    198247    ShowMessage(TX_SPELL_COMPLETE);
     
    204253  Checking: Boolean;
    205254begin
    206  if  csDestroying in componentstate then
    207    exit;
    208   btnStart.Enabled := (SpellCheck1.SpellCheckState in [ssReady, ssCancelled])
    209                       and (trim(RichEdit1.Text) <> '');
    210 
     255  if  csDestroying in componentstate then
     256     exit;
    211257  Checking := SpellCheck1.SpellCheckState = ssChecking;
    212258  pnlMisSpelled.Visible := Checking;
     
    216262
    217263{************* FormCreate **********}
    218 procedure TfrmHunSpell.btnStartClick(Sender: TObject);
    219 begin
    220   if SpellCheck1.SpellCheckState <> ssChecking then
    221    SpellCheck1.CheckSpelling;
    222 
    223   UpdateGUI;
    224   if (lstSuggestions.Count > 0) and btnChange.Visible and btnChange.Enabled then
    225       btnChange.SetFocus;
     264procedure TfrmHunSpell.btnAboutClick(Sender: TObject);
     265begin
     266  inherited;
     267  pnlAbout.Show;
     268  pnlAbout.BringToFront;
    226269end;
    227270
     
    236279end;
    237280
     281procedure TfrmHunSpell.btnRestatClick(Sender: TObject);
     282begin
     283  inherited;
     284    SpellCheck1.ReStart
     285end;
     286
    238287procedure TfrmHunSpell.btnAbortClick(Sender: TObject);
    239288begin
    240   if SpellCheck1.AbortSpellCheck(False) then
    241     UpdateGUI;
     289  if SpellCheck1.AbortSpellCheck(True) then
    242290end;
    243291
     
    254302procedure TfrmHunSpell.btnCloseClick(Sender: TObject);
    255303begin
    256  close;
     304  close;
    257305end;
    258306
     
    301349end;
    302350
     351procedure TfrmHunSpell.btnHideAboutClick(Sender: TObject);
     352begin
     353  inherited;
     354  pnlAbout.hide;
     355end;
     356
     357procedure TfrmHunSpell.cbHyphenatedWordClick(Sender: TObject);
     358begin
     359  inherited;
     360    if SpellCheck1.HyphenatedWords <> cbHyphenatedWord.Checked then
     361    SpellCheck1.HyphenatedWords := cbHyphenatedWord.Checked;
     362
     363    if SpellCheck1.SpellCheckState = ssChecking then
     364      SpellCheck1.ReStart;
     365end;
     366
    303367procedure TfrmHunSpell.cbIgnoreAllCapsClick(Sender: TObject);
    304368begin
     369  inherited;
    305370  if SpellCheck1.IgnoreAllCaps <> cbIgnoreAllCaps.Checked then
    306371    SpellCheck1.IgnoreAllCaps := cbIgnoreAllCaps.Checked;
     372
     373  if SpellCheck1.SpellCheckState = ssChecking then
     374      SpellCheck1.ReStart;
    307375end;
    308376
    309377procedure TfrmHunSpell.cbIgnoreDigitClick(Sender: TObject);
    310378begin
     379  inherited;
    311380  if SpellCheck1.IgnoreWordWithDigits <> cbIgnoreDigit.Checked then
    312381    SpellCheck1.IgnoreWordWithDigits := cbIgnoreDigit.Checked;
     382
     383  if SpellCheck1.SpellCheckState = ssChecking then
     384      SpellCheck1.ReStart;
    313385end;
    314386
     
    320392procedure TfrmHunSpell.FormActivate(Sender: TObject);
    321393begin
    322   if ( not SpellCheck1.Active) and (not NoEngineOpted) then
     394  if ( not btnRestat.Enabled) and (not NoEngineOpted) then
    323395  begin
    324396     btnSelectDictClick(self);
    325397     NoEngineOpted := True;
    326398  end;
    327 
    328399  if cbIgnoreAllCaps.Checked <> SpellCheck1.IgnoreAllCaps then
    329400    cbIgnoreAllCaps.Checked := SpellCheck1.IgnoreAllCaps;
     
    331402  if cbIgnoreDigit.Checked <> SpellCheck1.IgnoreWordWithDigits then
    332403    cbIgnoreDigit.Checked := SpellCheck1.IgnoreWordWithDigits;
     404
     405  if cbHyphenatedWord.Checked <> SpellCheck1.HyphenatedWords then
     406    cbHyphenatedWord.Checked := SpellCheck1.HyphenatedWords;
    333407end;
    334408
    335409procedure TfrmHunSpell.FormClose(Sender: TObject; var Action: TCloseAction);
    336410begin
    337  { if SpellCheck1.SpellCheckState = ssCompleted then
     411  if SpellCheck1.SpellCheckState = ssCompleted then
    338412  begin
    339     ShowMessage(TX_SPELL_COMPLETE) ;
     413   // ShowMsg(TX_SPELL_COMPLETE, TShow508MessageIcon(1), smbOK) ;
    340414    if Assigned(FSourceControl) then
    341415      FSourceControl.Text := RichEdit1.Text;
    342   end
    343   else
    344         ShowMessage(TX_SPELL_CANCELLED) ;  }
     416  end;
     417  {else
     418  ShowMsg(TX_SPELL_CANCELLED + CRLF + TX_NO_CORRECTIONS,
     419                                              TShow508MessageIcon(1), smbOK) ;}
    345420end;
    346421
    347422procedure TfrmHunSpell.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    348423begin
     424  inherited;
     425
    349426  CanClose := (SpellCheck1.SpellCheckState <> ssChecking)
    350427               or (SpellCheck1.AbortSpellCheck(True));
     
    361438  end;
    362439begin
    363   if (SpellCheck1.DictionaryFileName <>  '') then
    364       dicFile := SpellCheck1.DictionaryFileName
    365   else
    366       dicFile := ExtractFilePath(Application.ExeName)+ DefaultDicFile;
     440  dicFile := ExtractFilePath(Application.ExeName)+ DefaultDicFile;
    367441
    368442  if (FileExists(dicFile)) and (FileExists(affFile)) then
    369443  begin
    370444      SpellCheck1.AffixFileName := affFile;
    371       edtDictionary.Text := SpellCheck1.DictionaryFileName;
     445      SpellCheck1.DictionaryFileName := dicFile;
     446      edtDictionary.Text := dicFile;
    372447  end
    373448  else
     
    376451  if edtDictionary.Text = TX_Dic_File_Not_Found then
    377452    btnSelectDictClick(self);
    378  // SpellCheck1.SourceTextControl := RichEdit1;
    379  // SpellCheck1.SuggestionList := lstSuggestions;
    380   //SpellCheck1.MisSpeltWord := Edit2;
    381   SpellCheck1.Active :=  (SpellCheck1.DictionaryFileName <>  '')
     453   
     454  SpellCheck1.SourceTextControl := RichEdit1;
     455  SpellCheck1.SuggestionList := lstSuggestions;
     456  SpellCheck1.MisSpeltWord := edtMisSpelt;
     457  btnRestat.Enabled :=  (SpellCheck1.DictionaryFileName <>  '')
    382458                                                      and FileExists(dicFile);
    383   UpdateGUI;
    384 end;
    385 
    386 
     459end;
     460
     461
     462
     463procedure TfrmHunSpell.FormKeyUp(Sender: TObject; var Key: Word;
     464  Shift: TShiftState);
     465begin
     466  if (key = 27) and (pnlAbout.Showing) then
     467    btnHideAboutClick(self);
     468end;
    387469
    388470end.
    389 
Note: See TracChangeset for help on using the changeset viewer.