Table Context

General TRichView support forum. Please post your questions here
Post Reply
cychia_n2n
Posts: 16
Joined: Mon May 09, 2016 9:16 am

Table Context

Post by cychia_n2n »

I have a Ribbon Context Tab for Table, whenever caret is in table, the Table Tab will be visible.

I try these to check if caret in a table

1. Result := (rve.InplaceEditor <> nil);
2. Result := rve.GetCurrentItemEx(TRVTableItemInfo, rve, ItemInfo);
3.
begin
Result := rve.GetCurrentItemEx(TRVTableItemInfo, rve, ItemInfo);
if Result then
begin
table := TRVTableItemInfo(ItemInfo);
Result := table.GetNormalizedSelectionBounds(True, R, c, cs, rs);
end;
end;

But all of them cannot meet my requirement. When caret in one of the cell, the above solutions is working, but when multiple cells are selected, i will get false.
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

The second solution must be ok.
GetCurrentItemEx must return True if the caret is in a table cell, or if multiple cells are selected, or if the caret is to the right and to the left of the table.
cychia_n2n
Posts: 16
Joined: Mon May 09, 2016 9:16 am

Post by cychia_n2n »

when the caret on left or right of the table, I do not want to show the Table tab, how can I achieve that?

Thanks
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

If you use RichViewActions for table operations, I suggest to consider showing the tab when the caret is to the left/right of the table, to make your application consistent.
Because, all RichViewActions working with tables (if they do not require selected cells), are applied to the table when the caret is to the left/right of it.
It is especially important for nested tables: when the caret is to the left/right of the nested table, actions are applied to the nested table, not to the parent table.

But of course, if you implement table operations yourself, you can implement your own logic.

Your code in (3) is almost ok.
It must return True if there is a table having a multicell selection or an edited cell.
It has only one problem: it's possible, that table is nested in a cell of a parent table. In this case, the tab should be displayed, and operations must be performed on the parent table.

Code: Select all

Result := rve.GetCurrentItemEx(TRVTableItemInfo, [color=red]rve2[/color], ItemInfo); 
if Result then 
begin 
   table := TRVTableItemInfo(ItemInfo); 
   Result := table.GetNormalizedSelectionBounds(True, R, c, cs, rs); 
[color=red]   if not Result then
     Result := rve2 <> rve;[/color]
end;
(if the editor contained the table (rve2) is not equal to the root editor (rve), this is an inplace editor of a parent table; this table can be get as
(rve2.RVData.GetSourceRVData as TRVTableCellData).GetTable)
cychia_n2n
Posts: 16
Joined: Mon May 09, 2016 9:16 am

Post by cychia_n2n »

I recall why cannot use second method, because when in my table cell, when there is an image, my Table Tab will be hidden
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Sorry, I do not understand. Images and other content must not affect the result.
Only the caret position relative to the table matters.
Post Reply