Page 1 of 1

caret at strange position

Posted: Thu Apr 05, 2007 2:30 pm
by erikvdw
I have a form with the richviewedit. Document is loading on an initialize function of the form.
After loading the rvf document the form is shown (by calling showmodal) and the focus is set to the rveditor.
The caret should by show at de first character (or at the end) but It look like the caret is painted at the beginning of the second line.
There is some white space between the caret and first character of the second line.
When using the left key the caret is moved to the second character of the first line. So you should see the caret was before the first character but painted too low and too left.

Posted: Thu Apr 05, 2007 3:15 pm
by Sergey Tkachenko
Can you send me a demo reproducing this problem?

set caret at first position

Posted: Tue Apr 10, 2007 7:48 am
by erikvdw
What's the way to set the caret at the first position or repaint the editor?

I tried this:

with rvEditor.RVData do
SetSelectionBounds(0, GetOffsBeforeItem(0), 0, GetOffsBeforeItem(0));
rvEditor.TopLevelEditor.Invalidate;

small test

Posted: Tue Apr 10, 2007 9:04 am
by erikvdw
In a small test program with the same rvf document is seem to be working correct.
So I will search in our program which function cause this problem

Posted: Tue Apr 10, 2007 4:58 pm
by Sergey Tkachenko
Yes, your code is correct.
The simpler version is

Code: Select all

with rvEditor do begin
  SetSelectionBounds(0, GetOffsBeforeItem(0), 0, GetOffsBeforeItem(0)); 
  Invalidate;
end;
because after such SelectionBounds, rvEditor.TopLevelEditor=rvEditor.

Posted: Tue Apr 10, 2007 4:59 pm
by Sergey Tkachenko
I think this problem is because the editor was not repainted or reformatted after changes.

workaround

Posted: Thu Apr 12, 2007 8:20 am
by erikvdw
On the onshow event I implemented this code:

cmbFont.SetFocus; //some other component on the same form
Application.ProcessMessages;
rvEditor.SetFocus;
Application.ProcessMessages;

It's a workaround which works. Reformatting or invalidating didn't work.

Posted: Thu Apr 12, 2007 6:55 pm
by Sergey Tkachenko
Do you have other thirdparty editor controls in your application?

The caret is a global resource. Some another editor can try to control caret even if it is inside TRichViewEdit.