Cursor in text with rvprDoNotAutoSwitch in his protection

General TRichView support forum. Please post your questions here
Post Reply
Bjoern
Posts: 21
Joined: Tue May 11, 2010 4:05 pm

Cursor in text with rvprDoNotAutoSwitch in his protection

Post by Bjoern »

In a TDBRichViewEdit I have user-entered text and automatically inserted text.
The automatically inserted text is inserted with

Code: Select all

TextStyle.Protection := [rvprModifyProtect,rvprConcateProtect,rvprDoNotAutoSwitch,rvprStyleProtect,rvprStyleSplitProtect];
TextStyle.Color := clGray;
TextStyle.BackColor := clbtnface;
Now I need to know, when the user hits a button, if the cursor is on user entered text (unprotected) or auto-inserted text (protected).

I tried

Code: Select all

if (rvprModifyProtect in TDBRichViewEdit(ActiveControl).Style.TextStyles[TDBRichViewEdit(Mainform.ActiveControl).CurTextStyleNo].protection) then
but due to rvprDoNotAutoSwitch the text style does not change when the user moves the cursor into the protected area.

Is there a way to check if I am in a protected or unprotected text when the text has rvprDoNotAutoSwitch in its protection?

Best regards
Bjoern
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Cursor in text with rvprDoNotAutoSwitch in his protection

Post by Sergey Tkachenko »

If you have an editor RichViewEdit1, get the top level editor as:

Code: Select all

rve := RichViewEdit1.TopLevelEditor;
(it may be RichViewEdit1 itself, or a cell inplace editor).

Now, you can get the item index at the position of the caret:

Code: Select all

CurItemNo := rve.CurItemNo;
Now, you can get the item type:

Code: Select all

StyleNo := rve.GetItemStyle(CurItemNo);
If it is zero or positive, this is a text item, and you can get its style as rve.Style.TextStyles[StyleNo].

But you can also check the exact position of the caret,

Code: Select all

CurOffs := rve.OffsetInCurItem;
If CurOffs = rve.GetOffsBeforeItem(CurItemNo), the caret is before this item (if CurItemNo = 0, the caret is at the beginning; otherwise, it is between the items CurItemNo-1 and CurItemNo).

If CurOffs = rve.GetOffAfterItem(CurItemNo), the caret is after this item (if CurItemNo = rve.ItemCount-1, the caret is at the end; otherwise, it is between the items CurItemNo and CurItemNo+1).
Post Reply