There are two cases possible:
1) Several cells in a table is selected.
2) Several items are selected. In this case, some of selected items may be tables.
Let we have a procedure that does something with a range of items in TRichView document, looking inside tables
Code: Select all
procedure DoSomethingUseful(RVData: TCustomRVData; FirstItemNo: Integer = 0; LastItemNo: Integer = -1);
var
i, r, c: Integer;
Table: TRVTableItemInfo;
begin
if LastItemNo < 0 then
LastItemNo := RVData.ItemCount-1;
for i := FirstItemNo to LastItemNo do
begin
<<do something with the i-th item of RVData here>>
if RVData.GetItem(i) is TRVTableItemInfo then
begin
Table := TRVTableItemInfo(RVData.GetItem(i))
for r := 0 to Table.RowCount - 1 do
for c := 0 to Table.ColCount - 1 do
if Table.Cells[r,c]<> nil then
DoSomethingUseful(Table.Cells[r,c].GetRVData);
end;
end;
end;
Now we need to use it to process selected items.
The first step is:
Code: Select all
var
rve: TCustomRichViewEdit;
rve := GRichViewEdit.TopLevelEditor;
Now rve is either GRichViewEdit, or a table cell inplace editor.
Let's check if table cells are selected. If yes, we process selected cells and exit.
Code: Select all
var
Table: TRVTableItemInfo;
r, c: Integer;
if (rve.RVData.PartialSelectedItem <> nil) and (rve.RVData.PartialSelectedItem is TRVTableItemInfo) then
begin
Table := TRVTableItemInfo(rve.RVData.PartialSelectedItem);
for r := 0 to Table.RowCount - 1 do
for c := 0 to Table.ColCount - 1 do
if (Table.Cells[r,c]<> nil) and Table.IsCellSelected(r,c) then
DoSomethingUseful(Table.Cells[r,c].GetRVData);
exit;
end;