Page 1 of 1

Protect images in RichViewEdit

Posted: Tue Apr 05, 2011 3:18 pm
by charles.lambert
Hi,

I'm using a RichViewEdit to add text and images in it. I'd like to know how I can protect images that I paste in it.

Currently, I use this code to protect the whole text I have in the RichViewEdit and that works fine.

Code: Select all

SRichViewEdit.RichViewEdit.Controls[iNbControls]).SelectAll;

SRichViewEdit.RichViewEdit.Controls[iNbControls].GetSelectionBounds(mStartItemNo, mStartItemOffs, mEndItemNo, mEndItemOffs, True);

while ( mStartItemNo <= mEndItemNo ) do
begin
   SRichViewEdit.RichViewEdit.Controls[iNbControls].RVData.GetItem(mStartItemNo).StyleNo := 6;

   mStartItemNo := mStartItemNo + 1;
end;

The problem is when I run this function, the image I pasted in the RichViewEdit becomes invisible and I can't save this image anymore.

I'd like to know if there's any solution to my problem.

Regards,

- Charles

Posted: Tue Apr 05, 2011 3:27 pm
by Sergey Tkachenko
I do not understand what is "Controls[iNbControls])." in your code.
But apart from that, the main problem in your code is assigning a text style (6) to non-text items (items having StyleNo<0, that must not be changed).
The simplest solution for applying the 6th text style is

Code: Select all

SRichViewEdit.RichViewEdit.SelectAll;
SRichViewEdit.RichViewEdit.ApplyTextStyle(6);
This code protects all text, but does not protect non-text objects like pictures. For non-text objects, call

Code: Select all

SRichViewEdit.RichViewEdit.SetItemExtraIntProperty(i, rvepDeleteProtect, 1);
SRichViewEdit.RichViewEdit.SetItemExtraIntProperty(i, rvepResizable
, 0);

Posted: Tue Apr 05, 2011 3:28 pm
by Sergey Tkachenko
If you need to protect the whole document, you can assign SRichViewEdit.ReadOnly := True;

Posted: Wed Apr 06, 2011 1:50 pm
by charles.lambert
I've tried what you told me and that works fine except for one thing.

I apply a protected text style to the whole RichViewEdit and I protect every images and that works fine, but when I put my cursor on the right or left of an image, I can still enter some text...

Is there a way to prevent this as the property ReadOnly is not something I want to use in this specific project.

Posted: Wed Apr 06, 2011 5:16 pm
by Sergey Tkachenko
You can protect the whole paragraph by including rvpaoReadOnly, rvpaoStyleProtect, rvpaoDoNotWantReturns in Options of its paragraph style.

Posted: Wed Jun 01, 2011 3:15 pm
by charles.lambert
Those paragraph style properties work fine to prevent inserting before and after an image, but now I can't add some text to the end of that paragraph.

When I apply a textstyle without the property StickToBottom, that allows me to add some text at the end of the item, but when I apply the paragraph style I lose that possibility.

Is there a way to prevent user from inserting text before and after an image while allowing him to add some text at the end of the paragraph?

Regards,

- Charles

Posted: Wed Jun 01, 2011 4:49 pm
by Sergey Tkachenko
I am afraid no, the current version does not allow it.
(you can exclude rvpaoDoNotWantReturns, and the user will be able to add new lines by pressing Enter while at the beginning/end of the paragraph, but modifying the paragraph is still not possible)