|
Rank: Member
Groups: Registered
Joined: 1/4/2011 Posts: 42
|
We are considering using the Keyoti WPF spell check. Some questions though:
Can I replace the wavy underline with a yellow highlight?
Are you considering implementing using the MS-word custom dict in the future? That would help the our users to maintain only one custom dic. Or can I simple use the MS-word custom dic already?
Thanks
|
|
Rank: Advanced Member
Groups: Administrators, Registered
Joined: 8/13/2004 Posts: 2,669 Location: Canada
|
quote:
Can I replace the wavy underline with a yellow highlight?
You can change the UnderlineColor property in the control, but it sounds like maybe you want to paint your own adorner (like a box or something) instead? I expect there may be a way but want to be sure before I delve into that for you. quote:
Are you considering implementing using the MS-word custom dict in the future? That would help the our users to maintain only one custom dic. Or can I simple use the MS-word custom dic already?
Yes the 'custom' dictionary in Word (the user's dictionary) is just a text file, as is our 'user' dictionary - so yes you should be able to just point to the user's own dictionary from Word, in the UserDictionaryFile property, and use it directly. Best Jim -your feedback is helpful to other users, thank you!Evaluation Downloads - http://keyoti.com/products-your feedback is helpful to other users, thank you!
|
|
Rank: Member
Groups: Registered
Joined: 1/4/2011 Posts: 42
|
Thanks for the quick answer.
On the wavy underline. Yes, we would like to replace that with highlighting the misspelled words. So replace the underline with a higlight of a certain color.
Could you investigate if that is possible?
|
|
Rank: Advanced Member
Groups: Administrators, Registered
Joined: 8/13/2004 Posts: 2,669 Location: Canada
|
Sure, sorry I should have asked, do you want the example in C# or VB? -your feedback is helpful to other users, thank you!Evaluation Downloads - http://keyoti.com/products-your feedback is helpful to other users, thank you!
|
|
Rank: Member
Groups: Registered
Joined: 1/4/2011 Posts: 42
|
C# please. Thx! quote: Originally posted by Jim
Sure, sorry I should have asked, do you want the example in C# or VB?
-your feedback is helpful to other users, thank you!
Evaluation Downloads - http://keyoti.com/products
|
|
Rank: Advanced Member
Groups: Administrators, Registered
Joined: 8/13/2004 Posts: 2,669 Location: Canada
|
Unfortunately some tweaks had to be made to the DLL (some private fields needed to be made protected) - this change will be in all future versions, please download here http://keyoti.com/downlo...-2.0.11.104-Release.zip
If you're referencing that DLL then you can use the code below; 1. Copy these classes to your project Code:
class CustomWpfRichTextBoxAdapter : Keyoti.RapidSpell.Wpf.WpfRichTextBoxAdapter { public CustomWpfRichTextBoxAdapter(System.Windows.Controls.RichTextBox textBox, bool createCutCopyPasteReplacement) : base(textBox, createCutCopyPasteReplacement) { } public override Keyoti.RapidSpell.Wpf.ErrorAdornerBase CreateErrorAdorner(int start, int end, Keyoti.RapidSpell.Wpf.UnderlineStyle u, Color c) { return new CustomRichAdorner(this.theWrappedTextBox as RichTextBox, start, end, this, u, c); } }
class CustomWpfPlainTextBoxAdapter : Keyoti.RapidSpell.Wpf.WpfTextBoxAdapter { public CustomWpfPlainTextBoxAdapter(System.Windows.Controls.TextBox textBox, bool createCutCopyPasteReplacement) : base(textBox, createCutCopyPasteReplacement) { } public override Keyoti.RapidSpell.Wpf.ErrorAdornerBase CreateErrorAdorner(int start, int end, Keyoti.RapidSpell.Wpf.UnderlineStyle u, Color c) { return new CustomPlainAdorner(this.theWrappedTextBox as TextBox, start, end, this, u, c); } }
class CustomRichAdorner : Keyoti.RapidSpell.Wpf.RichErrorAdorner { public CustomRichAdorner(RichTextBox adornedElement, int start, int end, Keyoti.RapidSpell.Wpf.IAYTTextBox iayt, Keyoti.RapidSpell.Wpf.UnderlineStyle u, System.Windows.Media.Color c) : base(adornedElement, start, end, iayt, u, c) { IsHitTestVisible = false; }
protected override void OnRender(DrawingContext drawingContext) { if (!startP.HasValidLayout || !endP.HasValidLayout) { OnRenderImpossible(); return; } if (!active) return; Rect selectionStartPos_scr = new Rect(0, 0, 0, 0), selectionEndPos_scr = new Rect(0, 0, 0, 0);
selectionStartPos_scr = startP.GetCharacterRect(LogicalDirection.Forward); selectionEndPos_scr = endP.GetCharacterRect(LogicalDirection.Forward);
selectionEndPos_scr.Union(selectionStartPos_scr); drawingContext.DrawRectangle(HighlightFillBrush, HighlightLinePen, selectionEndPos_scr); } }
class CustomPlainAdorner : Keyoti.RapidSpell.Wpf.ErrorAdorner { public CustomPlainAdorner(TextBox adornedElement, int start, int end, Keyoti.RapidSpell.Wpf.IAYTTextBox iayt, Keyoti.RapidSpell.Wpf.UnderlineStyle u, System.Windows.Media.Color c) : base(adornedElement, start, end, iayt, u, c) { IsHitTestVisible = false; }
protected override void OnRender(DrawingContext drawingContext) { if (!active) return; Rect selectionStartPos_scr = new Rect(0, 0, 0, 0), selectionEndPos_scr = new Rect(0, 0, 0, 0);
int tL = tb.Text.Length; if (start < tL && end <= tL) { selectionStartPos_scr = tb.GetRectFromCharacterIndex(start); selectionEndPos_scr = tb.GetRectFromCharacterIndex(end);
if (selectionStartPos_scr.IsEmpty) { OnRenderImpossible(); return; } selectionEndPos_scr.Union(selectionStartPos_scr); drawingContext.DrawRectangle(HighlightFillBrush, HighlightLinePen, selectionEndPos_scr); } } }
Painting is done in OnRender of course. Then to use these adorners instead of the default you need to specify the TextComponent to check like this For rich text boxes: Code: rapidSpellAsYouType1.AddTextComponent(new CustomWpfRichTextBoxAdapter(richTextBox1, true));
For plain text boxes: Code: rapidSpellAsYouType1.AddTextComponent(new CustomWpfPlainTextBoxAdapter( textBox2, true));
Please let us know how it goes. Jim -your feedback is helpful to other users, thank you!Evaluation Downloads - http://keyoti.com/products-your feedback is helpful to other users, thank you!
|
|
Rank: Member
Groups: Registered
Joined: 1/4/2011 Posts: 42
|
Thx!! That is very good service!
|
|
Rank: Member
Groups: Registered
Joined: 1/4/2011 Posts: 42
|
Hi, I applied your code and it worked perfect. However I have two requests. Can we instead of putting a rectangle on top of the error text, set the background color of the text to yellow? It's ok if this will only work for RichTextBoxes.
The other thing is that our clients have black listed words that people are not allowed to use. These words need to have a different color background. How can we do that?
Sorry for asking all these questions.But it really help speeds things along pretty quickly.
|
|
Rank: Advanced Member
Groups: Administrators, Registered
Joined: 8/13/2004 Posts: 2,669 Location: Canada
|
Sure, just change both instances of drawingContext.DrawRectangle(HighlightFillBrush, HighlightLinePen, selectionEndPos_scr); this is basic WPF painting, the 1st and 2nd args define the border and fill, so just use a different brush. quote:
The other thing is that our clients have black listed words that people are not allowed to use. These words need to have a different color background. How can we do that?
I believe you can get to the word being highlighted like this (from the render method) string badWord = iayt.Text.Substring(start, end-start); then you can look up if that's black listed and use a different brush. I should point out that unfortunately iayt.Text is going to slow things down for you because it's mapping to plain text. EDIT scratch the above, there's a better way to get the word which I'll post shortly. -your feedback is helpful to other users, thank you!Evaluation Downloads - http://keyoti.com/products-your feedback is helpful to other users, thank you!
|
|
Rank: Advanced Member
Groups: Administrators, Registered
Joined: 8/13/2004 Posts: 2,669 Location: Canada
|
From render, do this (for RichTextBox) TextRange r = new TextRange(startP, endP); string badWord = r.Text; should be pretty swift. For plain text boxes no pointers are needed just do string badWord = iayt.Text.Substring(start, end-start); Jim -your feedback is helpful to other users, thank you!Evaluation Downloads - http://keyoti.com/products-your feedback is helpful to other users, thank you!
|
|
Rank: Member
Groups: Registered
Joined: 1/4/2011 Posts: 42
|
Thx Jim. Yeah, I tried the different brushes before but it makes the text dim because the box is painted on top. Any hooks available so we can set easily the background of the text?
|
|
Rank: Member
Groups: Registered
Joined: 1/4/2011 Posts: 42
|
Hey Jim, I only have the ErrorAdorner available to me. The black listed words are normal words but these words are not allowed by the Firm. For example "shit". It's a normal word but not something you want to see in a text. Is there a "NormalAdorner" or an event/override that gives me the currently parsed word and allows me to set the background?
|
|
Rank: Advanced Member
Groups: Administrators, Registered
Joined: 8/13/2004 Posts: 2,669 Location: Canada
|
According to what I've just been reading adorners are always on top http://www.eggheadcafe.c...98/adorner-z-order.aspx
There's a hack in there, if you're really motivated, it requires putting the text boxes inside an adornerelement and then, I'd need to give you a new build that would allow you to specify your adorner element as the place to put the adorners instead of in the textbox's adorner layer. quote:
The black listed words are normal words but these words are not allowed by the Firm
Oh, of course - I didn't put 2+2 together. Add this Code: class CRS : Keyoti.RapidSpell.Wpf.RapidSpellChecker { protected override bool LookUpMainDictionary(string query) { if (query == "badword") return false; else return base.LookUpMainDictionary(query); } }
obviously lookup your black list instead of =="badword". To use that code, just do rapidSpellAsYouType.RapidSpellChecker = new CRS(); Doing that will make the blacklist words into misspellings. Otherwise, you could start using the .dict file dictionary and then use the Dict Manager tool to take out the black list. -your feedback is helpful to other users, thank you!Evaluation Downloads - http://keyoti.com/products-your feedback is helpful to other users, thank you!
|
|
Rank: Member
Groups: Registered
Joined: 1/4/2011 Posts: 42
|
Thx again! I think the blacklisted approach will work excellent. I'm currently implementing it.
The other one for setting the background. What I can do, I think, is in the CustomRichAdorner get the TextRange span and set the background of the text. However when the bad word is later succesfully replaced, then I need to reset it to the normal color. There must be hook where you remove the red error Box. If I can use that hook and that hook also gives me access to the RichTextBox, then I can reset the background color. Is there such a hook available?
|
|
Rank: Member
Groups: Registered
Joined: 1/4/2011 Posts: 42
|
Ok, I got the background color set when the word is in error. Now I just need a hook to reset the background when the word is corrected.
|
|
Rank: Advanced Member
Groups: Administrators, Registered
Joined: 8/13/2004 Posts: 2,669 Location: Canada
|
You could try handling the Unloaded event in the adorner, I think that would be called when we remove the adorner from the text box. -your feedback is helpful to other users, thank you!Evaluation Downloads - http://keyoti.com/products-your feedback is helpful to other users, thank you!
|
|
Rank: Member
Groups: Registered
Joined: 1/4/2011 Posts: 42
|
The ardorner bit worked. However I have a very flaky behavior with using a custom Wpf.RapidSpellChecker. First it seemed to work, however now with all the other customizations, it does not want to work anymore. Everything else works, expect when I assign the new custom spellchecker, all of the spellchecking stops. Even right click menus don't work anymore. Any Idea? I can send you the project if you want. It's your example project enhanced with all the customizations
|
|
Rank: Member
Groups: Registered
Joined: 1/4/2011 Posts: 42
|
no worries. got it to work. Had to put it after everything was initialized
|
|