Page 1 of 2

string underlined like in spelling

Posted: Tue Jul 01, 2008 3:25 pm
by Cosmin3
Hi.
I want to use some of the spelling code so I can underline some strings in ScaleRichView. This strings can contain any character.
I can't use the code as it is because:
1. It has to work for any "delimiters".
2. The spelling is not using Unicode.

I just want to find the (wide)strings in visible area and underline them.
I found TRVWordMisspellPainter.Draw in RVWordPaint.pas but I don't know how to use it.

Can you help me, please?
Thanks.

Posted: Tue Jul 01, 2008 3:58 pm
by Sergey Tkachenko
This functionality is not supported. You can try to implement it, but with not guarantees. I know some users tried to use it, even created their new word painters, using different drawing method (not wavy underlines).

Generally, it should work like this:

Code: Select all

function GetWordPaintList(RVData: TCustomRVFormattedData; ItemNo: Integer): TRVWordPainterList; 
var 
  Item: TCustomRVItemInfo; 
begin 
  Item := RVData.GetItem(ItemNo); 
  if not Assigned(Item.WordPaintList) then 
    Item.WordPaintList := TRVWordPainterList.Create; 
  Result := Item.WordPaintList; 
end;
Adding underlines to the ItemNo-th item in RVData, between characters specified with StartOffs and Length:

Code: Select all

GetWordPaintList(RVData, ItemNo).Add(TRVWordMisspellPainter.Create(StartOffs, Length)) 

Posted: Tue Jul 01, 2008 6:33 pm
by Cosmin3
Thank you.

Posted: Sat Jul 05, 2008 7:37 am
by Cosmin3
I intend to make a separate thread in which the text from ScaleRichView will be scanned and some strings underlined.
Are there any special precautions I should take with ScaleRichView/RichViewEdit or I can make a standard thread?

Posted: Sun Jul 13, 2008 9:24 am
by Cosmin3
I have 2 suggestions for a future version:
1. Ability to underline tab items as well;
2. In RVData.GetItem(ItemNo).WordPaintList to be able to set underline color for each item. I mention this because I use underline not just for spelling and I want, for example, to underline in the same time words with red and something else with orange.

And 2 bugs to report:
1. For a text in a table cell: when the last line is close to the down border cell then the underline is not visible.
2. In a ScaleRichView page if the last text line is right before the dot line then the underline is visible on the next page.

I hope you'll implement/fix these as soon as possible.
Thank you.

Posted: Mon Jul 14, 2008 7:22 am
by proxy3d
You can send me example RVF of the document for the first bug?

Posted: Tue Jul 15, 2008 9:45 am
by Cosmin3
Sorry for the delayed reply; my internet connection was down for almost 2 days.
The text file is not a rvf; it's a rtf. It's created with WordXP and modified with Wordpad.
It's easy to make one. But if you stil want me to send you the file, I will send it...
Here is a link to a screen capture with both situations: with or without a new line between undelined text and border cell
http://img134.imageshack.us/my.php?image=capturens2.png
You can clearly notice that most of the red line is not visible. It's not easy for the user to see that is underlined.

Posted: Fri Jul 18, 2008 9:52 am
by Cosmin3
A problem with InvalidateDrawItem.
It's a RichViewEdit function, I know, but I think the problem may be connected with ScaleRichView also.
When I use it in a separate thread it doesn't always repaint the item (Spacing parameter is 3). But if I use Spacing 1000 (!) it works.
This happens sometimes only when I edit the item. Other methods of changing the text, like Paste, work fine.
For example if in a text line I have "Line2" (underlined) and I insert a space between "Line" and "2" then "Line" continues to be underlined.
But if I Insert a space using Paste then "Line" is not underlined anymore.
In both cases TCustomRVFormattedData(CurRVData.GetRVData).InvalidateDrawItem(ItemNo, 3) is executed exactly the same.
After the editing operation if I "force" a RePaint (for example if I minimize then restore the application) then the red underline is erased.

The thread is stopped in a safe place at OnChanging event, at OnItemTextEdit event RVData.GetItem(ItemNo).ItemState is set to [] and then at OnChange event the thread is restarted. After 200 ms it rescans the hole text line in which the modified item is and calls InvalidateDrawItem for each item (from the text line).

A similar problem is with the code from LiveSpelling.
In OnSpellingCheck event I wrote "if AWord = 'Misspelledtext' then Misspelled := True;". In a text line in editor I wrote "Misspelledtext". It's underlined.
I insert a space between "Misspelled" and "text". The underline is gone.
I remove the space using only Delete/Backspace. "Misspelledtext" is not underlined. Only if I move the text cursor or if I force a RePaint the underline is drawn.
Strange, if I select the space then I press Delete then the underline is drawn immediately.

Please help me solve the problem.
Thank you.

Posted: Tue Jul 22, 2008 3:05 pm
by Sergey Tkachenko
Strange, I cannot reproduce the problem with not updating live spelling underlines.
I added the following code in OnSpellingCheck:
Misspelled := Pos('a', AWord)<>0;
and played with it.
It worked as expected, when I added space and deleted it by backspace (both in 'aaabbb' and in 'bbbaaa').

Do you use the latest version of ScaleRichView?

Posted: Tue Jul 22, 2008 3:50 pm
by Cosmin3
Yes, I'm using the latest version.

The problem is not from my code - I just now tried with ActionTest Demo.
I wrote "Misspelledtext" in a new line at the beginning in readme.rvf, I saved and then I closed the application.
I opened it again; "Misspelledtext" is not underlined. Only if I edit the file anywhere else then it's underlined.
Afterward is behaving exactly like I said: insert a space between "Misspelled" and "text" + delete it with backspace = "Misspelledtext" not underlined (until I move the text cursor).
I said in my previous post "This happens sometimes only when I edit the item".
This means that for some words in text it works, for others it doesn't.

If you want I will send you this modified version (even the exe file if you want to).

PS: the difference between my test and your test is that when you insert a space one of the two new words is underlined. In my case neither of them are underlined. This has an influence on how is underlined when the space is deleted with backspace.

Posted: Tue Jul 22, 2008 6:19 pm
by Sergey Tkachenko
I understand. It is not underlined because this word is considered as being edited. Such words are not underlined until you move the caret.

MS Word works in the same way, even more strictly (the edited word is not underlined until you move the caret outside of it. In TRichViewEdit/TSRichViewEdit, any caret movement causes rechecking the edited word).

Posted: Tue Jul 22, 2008 6:45 pm
by Cosmin3
Ok, but now what can I do with the (related I think) problem in my thread? Do I have to set Spacing parameter at 1000 in InvalidateDrawItem so it could work?

Posted: Tue Jul 22, 2008 6:49 pm
by Sergey Tkachenko
Spacing=1000 invalidates 1000 pixels around this item, i.e. usually the full window.
Can you test your code on TRichViewEdit? I am not sure where the problem is - in TRichViewEdit itself or in ScaleRichView.

Posted: Tue Jul 22, 2008 6:56 pm
by Cosmin3
I believe it's happening only in ScaleRichView.
But to make sure I will test also in TRichViewEdit.

Later edit: Hmm, looks like I was wrong. It does the same in RVEditDemo.
If you want I will send you this modified demo so you can debug the problem more easily...

Posted: Wed Jul 23, 2008 5:05 pm
by Sergey Tkachenko
Yes, send the demo (as simple as possible, with TRichViewEdit) to svt@trichview.com