Protect images in RichViewEdit

General TRichView support forum. Please post your questions here
Post Reply
charles.lambert
Posts: 26
Joined: Mon Jul 05, 2010 7:44 pm

Protect images in RichViewEdit

Post 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
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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);
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

If you need to protect the whole document, you can assign SRichViewEdit.ReadOnly := True;
charles.lambert
Posts: 26
Joined: Mon Jul 05, 2010 7:44 pm

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You can protect the whole paragraph by including rvpaoReadOnly, rvpaoStyleProtect, rvpaoDoNotWantReturns in Options of its paragraph style.
charles.lambert
Posts: 26
Joined: Mon Jul 05, 2010 7:44 pm

Post 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
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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)
Post Reply