I working on something like html editor that uses predefined templates. I'm using TRichViewEdit that displays couple of nested tables that are generated by code with certain sizes/background images/etc.
The editor should allow user to edit only some of the cells chosen by the program.
I would like to:
1) Prevent user from selecting cells and/or (sub)tables by mouse (making them gray).
2) Protect the whole layout built using tables from deletion and resizing by mouse
3) Allow user to edit/select/delete/do whatever ONLY INSIDE the "editable" cells.
4) Prevent user from clicking (meaning: moving caret) to anywhere else than "editable" cells. [I mean that the caret can only be moved between the editable "fields"; if user clicks i.e. outside the whole layout, the caret should stay in the last proper place]
The best solution would be to use TRichView to display the whole layout (read only) and use TRichViewEdits as cells that can be edited by user normally - but perhaps it's not possible to mix the two components, is it???
Thanks in advance for the reply,
Mateo
Protecting cells in a table
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Exclude the following options from table.Options:
[rvtoRowSizing, rvtoColSizing, rvtoRowSelect, rvtoColSelect]
Unfortunately, there is no option to prevent multicell selection.
Protect the table's paragraph (RVStyle.ParaStyles[table.ParaNo], include the following options in the Options property of paragraph style:
[rvpaoReadOnly, rvpaoStyleProtect, rvpaoDoNotWantReturns]
As for (4), process OnCaretMove event. If the caret is in wrong place, use PostMessage to post your message to the form. In responce on this message, move the caret to the closest allowed cell.
Search this forum for "PostMessage", you should find some examples.
[rvtoRowSizing, rvtoColSizing, rvtoRowSelect, rvtoColSelect]
Unfortunately, there is no option to prevent multicell selection.
Protect the table's paragraph (RVStyle.ParaStyles[table.ParaNo], include the following options in the Options property of paragraph style:
[rvpaoReadOnly, rvpaoStyleProtect, rvpaoDoNotWantReturns]
As for (4), process OnCaretMove event. If the caret is in wrong place, use PostMessage to post your message to the form. In responce on this message, move the caret to the closest allowed cell.
Search this forum for "PostMessage", you should find some examples.
-
- Posts: 164
- Joined: Tue Nov 08, 2011 5:11 pm
I tried this, but I'm not sure I did it right. I created a new ParaStyle at design-time in the TRVStyle connected to my TRichViewEdit, and set the options of the style as indicated above.Sergey Tkachenko wrote:Exclude the following options from table.Options:
[rvtoRowSizing, rvtoColSizing, rvtoRowSelect, rvtoColSelect]
Protect the table's paragraph (RVStyle.ParaStyles[table.ParaNo], include the following options in the Options property of paragraph style:
[rvpaoReadOnly, rvpaoStyleProtect, rvpaoDoNotWantReturns]
I have a two column table with "labels" in the first column. I only want the user to edit cells in the second column. So I added my "labels" like this:
Code: Select all
table.Cells[0,0].GetRVData.AddTextNL('Label1:', 0, 1, -1);
table.Cells[1,0].GetRVData.AddTextNL('Label2:', 0, 1, -1);
Based on the Help, this is how I think I'm supposed to add text to a table that is being added to a TRichViewEdit. But I'm not sure I'm doing this correctly. Changing the table options and paragraph style alone seemed to provide zero protection.
I implemented OnCellChanging, which allows me to set AllowEdit, which works. I'm just wondering what I've done wrong above.
Thanks!
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
I tried, this code works:
Code: Select all
var table: TRVTableItemInfo;
begin
RVStyle1.ParaStyles.Clear;
RVStyle1.ParaStyles.Add;
RVStyle1.ParaStyles.Add.Options := [rvpaoReadOnly, rvpaoStyleProtect, rvpaoDoNotWantReturns];
table := TRVTableItemInfo.CreateEx(1, 2, RichViewEdit1.RVData);
table.Cells[0,0].Clear;
table.Cells[0,0].AddNL('Protected', 0, 1);
table.Cells[0,1].Clear;
table.Cells[0,1].AddNL('Editable', 0, 0);
RichViewEdit1.Clear;
RichViewEdit1.AddItem('', table);
RichViewEdit1.Format;
end;
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
However, while read-only paragraphs cannot be modified, they can be deleted as a whole (for example, by selecting the cells completely and pressing Delete).
It least one undeletable item must be in a readonly paragraph to solve this problem:
It least one undeletable item must be in a readonly paragraph to solve this problem:
Code: Select all
var table: TRVTableItemInfo;
begin
RVStyle1.ParaStyles.Clear;
RVStyle1.ParaStyles.Add;
RVStyle1.ParaStyles.Add.Options := [rvpaoReadOnly, rvpaoStyleProtect, rvpaoDoNotWantReturns];
RVStyle1.TextStyles.Clear;
RVStyle1.TextStyles.Add;
RVStyle1.TextStyles.Add.Protection := [rvprDeleteProtect, rvprStyleProtect];
table := TRVTableItemInfo.CreateEx(1, 2, RichViewEdit1.RVData);
table.Cells[0,0].Clear;
table.Cells[0,0].AddNL('Protected', 1, 1);
table.Cells[0,1].Clear;
table.Cells[0,1].AddNL('Editable', 0, 0);
RichViewEdit1.Clear;
RichViewEdit1.AddItem('', table);
RichViewEdit1.Format;
end;