- Timestamp:
- Jun 25, 2015, 1:28:09 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cprs/branches/HealthSevak-CPRS/CPRS-Lib/Hans SpellCheck/Demo/fHunSpell.pas
r1718 r1725 36 36 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 37 37 StdCtrls, ComCtrls, RichEdit, Buttons, ExtCtrls, ShellAPI, 38 skaSpellCheck ;38 skaSpellCheck, jpeg; 39 39 40 40 type 41 41 TfrmHunSpell = class(TForm) 42 lblDictionary: TLabel;43 42 btnClose: TButton; 44 43 OpenDialog1: TOpenDialog; … … 46 45 edtDictionary: TEdit; 47 46 btnSelectDict: TBitBtn; 48 lblDictionariesURL: TLabel;49 47 RichEdit1: TRichEdit; 50 btnStart: TButton;51 48 pnlMisSpelled: TPanel; 52 49 Label1: TLabel; 50 lstSuggestions: TListBox; 53 51 Label4: TLabel; 54 lstSuggestions: TListBox; 55 edtMisSpeltWordForExtraHint: TEdit; //required for screenreaders which are MOSTLY colour blind 52 edtMisSpelt: TEdit; 56 53 btnReplaceWith: TButton; 57 54 btnChangeAll: TButton; … … 61 58 btnIgnoreOnce: TButton; 62 59 btnAbort: TButton; 60 btnAbout: TButton; 61 pnlAbout: TPanel; 62 btnHideAbout: TButton; 63 63 btnUndo: TButton; 64 64 cbIgnoreAllCaps: TCheckBox; 65 65 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; 66 82 procedure FormCreate(Sender: TObject); 67 83 procedure btnIgnoreOnceClick(Sender: TObject); … … 75 91 procedure btnReplaceWithClick(Sender: TObject); 76 92 procedure btnAddToDictionaryClick(Sender: TObject); 93 procedure FormShow(Sender: TObject); 77 94 procedure FormClose(Sender: TObject; var Action: TCloseAction); 78 95 procedure btnAbortClick(Sender: TObject); 79 procedure btnStartClick(Sender: TObject); 96 procedure lblOpenMedURLClick(Sender: TObject); 97 procedure btnAboutClick(Sender: TObject); 98 procedure btnHideAboutClick(Sender: TObject); 80 99 procedure btnUndoClick(Sender: TObject); 81 100 procedure RichEdit1KeyUp(Sender: TObject; var Key: Word; … … 83 102 procedure RichEdit1KeyDown(Sender: TObject; var Key: Word; 84 103 Shift: TShiftState); 85 procedure UpdateGUI; 104 procedure lstSuggestionsDblClick(Sender: TObject); 105 procedure SpellCheck1StateChange(const Sender: TObject; 106 const State: TSpellState); 86 107 procedure SpellCheck1Abort(Sender: TObject); 87 108 procedure SpellCheck1Start(Sender: TObject); 88 procedure SpellCheck1StateChange(const Sender: TObject;89 const State: TSpellState);90 procedure lblDictionariesURLClick(Sender: TObject);91 procedure lstSuggestionsDblClick(Sender: TObject);92 109 procedure cbIgnoreAllCapsClick(Sender: TObject); 93 110 procedure cbIgnoreDigitClick(Sender: TObject); 94 111 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); 95 117 private 96 118 { Private declarations } … … 98 120 FSourceControl: TCustomMemo; 99 121 procedure GoToURL(const aURL: String); 122 procedure UpdateGUI; 100 123 public 101 124 { Public declarations } … … 105 128 OldRichEditWndProc: {integer}pointer; 106 129 PRichEditWndProc:pointer; 107 class function DoHunSpellCheck(AnEditControl: TCustomMemo): TModalResult; 108 static; 130 class function DoHunSpellCheck(AnEditControl: TCustomMemo): TModalResult; static; 109 131 end; 110 132 … … 121 143 122 144 Const 123 DefaultDicFile = 'dict\en_GB.dic';// 'dict\en-US-OpenMedSpel.dic'; 145 DefaultDicFile = '\dict\en_US-large.dic'; 146 124 147 var 125 148 frmHunSpell: TfrmHunSpell; … … 129 152 130 153 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} 154 class function TfrmHunSpell.DoHunSpellCheck(AnEditControl: TCustomMemo): TModalResult; 135 155 var 136 156 frm: TfrmHunSpell; … … 148 168 149 169 {************ HighLight ***********888} 150 procedure TfrmHunSpell.GoToURL(const aURL: String); 170 procedure TfrmHunSpell.FormShow(Sender: TObject); 171 begin 172 if SpellCheck1.SpellCheckState = ssReady then 173 SpellCheck1.CheckSpelling; 174 try 175 if lstSuggestions.Count > 0 then 176 btnChange.SetFocus; 177 except 178 end; 179 end; 180 181 procedure TfrmHunSpell.GoToURL(const aURL: String); 151 182 begin 152 183 if length(trim(aURL)) > 4 then … … 154 185 end; 155 186 156 procedure TfrmHunSpell.lblDictionariesURLClick(Sender: TObject); 157 begin 187 procedure TfrmHunSpell.Image1Click(Sender: TObject); 188 begin 189 inherited; 190 GoToURL('http://www.healthsevak.com'); 191 end; 192 193 procedure TfrmHunSpell.Label6Click(Sender: TObject); 194 begin 195 inherited; 196 GoToURL('mailto: digitiger@gmail.com'); 197 end; 198 199 procedure TfrmHunSpell.lblOpenMedURLClick(Sender: TObject); 200 begin 201 inherited; 158 202 GoToURL(TLabel(sender).Caption); 159 203 end; … … 161 205 procedure TfrmHunSpell.lstSuggestionsDblClick(Sender: TObject); 162 206 begin 163 if lstSuggestions.ItemIndex >= 0 then 164 btnChangeClick(Self);207 inherited; 208 btnChangeClick(sender); 165 209 end; 166 210 … … 168 212 Shift: TShiftState); 169 213 begin 214 inherited; 170 215 if SpellCheck1.SpellCheckState = ssChecking then 171 216 SpellCheck1.ManualChangeStart; … … 175 220 Shift: TShiftState); 176 221 begin 177 if SpellCheck1.SpellCheckState in [ssCancelled, ssCompleted] then 222 inherited; 223 if SpellCheck1.SpellCheckState in [ssCancelled, ssCompleted] then 178 224 SpellCheck1.Reopen; 179 225 180 226 if SpellCheck1.SpellCheckState = ssChecking then 181 227 SpellCheck1.ManualChangeDone; … … 184 230 procedure TfrmHunSpell.SpellCheck1Abort(Sender: TObject); 185 231 begin 232 inherited; 186 233 UpdateGUI; 187 234 end; … … 189 236 procedure TfrmHunSpell.SpellCheck1Start(Sender: TObject); 190 237 begin 238 inherited; 191 239 UpdateGUI; 192 240 end; … … 195 243 const State: TSpellState); 196 244 begin 245 inherited; 197 246 if State = ssCompleted then 198 247 ShowMessage(TX_SPELL_COMPLETE); … … 204 253 Checking: Boolean; 205 254 begin 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; 211 257 Checking := SpellCheck1.SpellCheckState = ssChecking; 212 258 pnlMisSpelled.Visible := Checking; … … 216 262 217 263 {************* 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; 264 procedure TfrmHunSpell.btnAboutClick(Sender: TObject); 265 begin 266 inherited; 267 pnlAbout.Show; 268 pnlAbout.BringToFront; 226 269 end; 227 270 … … 236 279 end; 237 280 281 procedure TfrmHunSpell.btnRestatClick(Sender: TObject); 282 begin 283 inherited; 284 SpellCheck1.ReStart 285 end; 286 238 287 procedure TfrmHunSpell.btnAbortClick(Sender: TObject); 239 288 begin 240 if SpellCheck1.AbortSpellCheck(False) then 241 UpdateGUI; 289 if SpellCheck1.AbortSpellCheck(True) then 242 290 end; 243 291 … … 254 302 procedure TfrmHunSpell.btnCloseClick(Sender: TObject); 255 303 begin 256 close;304 close; 257 305 end; 258 306 … … 301 349 end; 302 350 351 procedure TfrmHunSpell.btnHideAboutClick(Sender: TObject); 352 begin 353 inherited; 354 pnlAbout.hide; 355 end; 356 357 procedure TfrmHunSpell.cbHyphenatedWordClick(Sender: TObject); 358 begin 359 inherited; 360 if SpellCheck1.HyphenatedWords <> cbHyphenatedWord.Checked then 361 SpellCheck1.HyphenatedWords := cbHyphenatedWord.Checked; 362 363 if SpellCheck1.SpellCheckState = ssChecking then 364 SpellCheck1.ReStart; 365 end; 366 303 367 procedure TfrmHunSpell.cbIgnoreAllCapsClick(Sender: TObject); 304 368 begin 369 inherited; 305 370 if SpellCheck1.IgnoreAllCaps <> cbIgnoreAllCaps.Checked then 306 371 SpellCheck1.IgnoreAllCaps := cbIgnoreAllCaps.Checked; 372 373 if SpellCheck1.SpellCheckState = ssChecking then 374 SpellCheck1.ReStart; 307 375 end; 308 376 309 377 procedure TfrmHunSpell.cbIgnoreDigitClick(Sender: TObject); 310 378 begin 379 inherited; 311 380 if SpellCheck1.IgnoreWordWithDigits <> cbIgnoreDigit.Checked then 312 381 SpellCheck1.IgnoreWordWithDigits := cbIgnoreDigit.Checked; 382 383 if SpellCheck1.SpellCheckState = ssChecking then 384 SpellCheck1.ReStart; 313 385 end; 314 386 … … 320 392 procedure TfrmHunSpell.FormActivate(Sender: TObject); 321 393 begin 322 if ( not SpellCheck1.Active) and (not NoEngineOpted) then394 if ( not btnRestat.Enabled) and (not NoEngineOpted) then 323 395 begin 324 396 btnSelectDictClick(self); 325 397 NoEngineOpted := True; 326 398 end; 327 328 399 if cbIgnoreAllCaps.Checked <> SpellCheck1.IgnoreAllCaps then 329 400 cbIgnoreAllCaps.Checked := SpellCheck1.IgnoreAllCaps; … … 331 402 if cbIgnoreDigit.Checked <> SpellCheck1.IgnoreWordWithDigits then 332 403 cbIgnoreDigit.Checked := SpellCheck1.IgnoreWordWithDigits; 404 405 if cbHyphenatedWord.Checked <> SpellCheck1.HyphenatedWords then 406 cbHyphenatedWord.Checked := SpellCheck1.HyphenatedWords; 333 407 end; 334 408 335 409 procedure TfrmHunSpell.FormClose(Sender: TObject; var Action: TCloseAction); 336 410 begin 337 {if SpellCheck1.SpellCheckState = ssCompleted then411 if SpellCheck1.SpellCheckState = ssCompleted then 338 412 begin 339 ShowMessage(TX_SPELL_COMPLETE) ;413 // ShowMsg(TX_SPELL_COMPLETE, TShow508MessageIcon(1), smbOK) ; 340 414 if Assigned(FSourceControl) then 341 415 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) ;} 345 420 end; 346 421 347 422 procedure TfrmHunSpell.FormCloseQuery(Sender: TObject; var CanClose: Boolean); 348 423 begin 424 inherited; 425 349 426 CanClose := (SpellCheck1.SpellCheckState <> ssChecking) 350 427 or (SpellCheck1.AbortSpellCheck(True)); … … 361 438 end; 362 439 begin 363 if (SpellCheck1.DictionaryFileName <> '') then 364 dicFile := SpellCheck1.DictionaryFileName 365 else 366 dicFile := ExtractFilePath(Application.ExeName)+ DefaultDicFile; 440 dicFile := ExtractFilePath(Application.ExeName)+ DefaultDicFile; 367 441 368 442 if (FileExists(dicFile)) and (FileExists(affFile)) then 369 443 begin 370 444 SpellCheck1.AffixFileName := affFile; 371 edtDictionary.Text := SpellCheck1.DictionaryFileName; 445 SpellCheck1.DictionaryFileName := dicFile; 446 edtDictionary.Text := dicFile; 372 447 end 373 448 else … … 376 451 if edtDictionary.Text = TX_Dic_File_Not_Found then 377 452 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 <> '') 382 458 and FileExists(dicFile); 383 UpdateGUI; 384 end; 385 386 459 end; 460 461 462 463 procedure TfrmHunSpell.FormKeyUp(Sender: TObject; var Key: Word; 464 Shift: TShiftState); 465 begin 466 if (key = 27) and (pnlAbout.Showing) then 467 btnHideAboutClick(self); 468 end; 387 469 388 470 end. 389
Note:
See TracChangeset
for help on using the changeset viewer.