Page 1 of 1

Hide and show a button in a table cell on RichViewEdit

Posted: Fri Mar 23, 2018 5:31 pm
by mohonko
Hello! Help me please. I write a program in which the main component is a table created in RichViewEdit. In this table, I need a button to appear when clicking on certain cells, clicking on which displays the menu, and when the cell loses focus, the button disappears. Looking for how to do it on the documentation for a week, did not understand how to achieve this. The button I added, but how to make it appeared when focus a cell and its disappearance or hide when focus is lost, is unclear.

Re: Hide and show a button in a table cell on RichViewEdit

Posted: Sat Mar 24, 2018 11:00 am
by Steku
Hi,

maybe you have to check for the current item to handle your visible/unvisible problem.
As a startting point you can have a look
here: http://www.trichview.com/help/idh_trich ... rentItemEx
or here: http://www.trichview.com/help/idh_trich ... titem.html

Greetings...

Re: Hide and show a button in a table cell on RichViewEdit

Posted: Sat Mar 24, 2018 11:14 pm
by mohonko
Thanks. This method i am used. How to make the button (rvsComponent) inserted into the table not move along with the text? How to set the cursor to enter text into a specific cell of the table in RichViewEdit?

Re: Hide and show a button in a table cell on RichViewEdit

Posted: Sun Mar 25, 2018 2:42 pm
by Sergey Tkachenko
I think that control insertion is not a good solution. As I understand, you do not need to modify document, you need just display a button.

I can suggest using a "smart popup". It is a button that can be shown next to the current item. It displays an icon and, optionally a triangle (useful if this button shows a menu) or ellipsis (useful if this button shows a dialog).
You can use this code in OnCaretMove to hide/show "smart popup":

Code: Select all

procedure TForm3.RichViewEdit1CaretMove(Sender: TObject);
begin
  // showing when the caret is in table cell
  RichViewEdit1.SmartPopupVisible := RichViewEdit1.InplaceEditor <> nil;
  // this cell can be get as:
  //  RichViewEdit1.TopLevelEditor.RVData.GetSourceRVData as TRVTableCellData
end;
The only minus: this button is positioned next to the current item (bottom right corner by default; you can specify another corner); you cannot define its coordinates.
Additional info: http://www.trichview.com/help/idh_trich ... rties.html

Re: Hide and show a button in a table cell on RichViewEdit

Posted: Mon Mar 26, 2018 11:41 am
by mohonko
Thank you very much. This mehod is good. How to disable the ability to change the external dimensions of the border with the mouse?

Re: Hide and show a button in a table cell on RichViewEdit

Posted: Mon Mar 26, 2018 3:23 pm
by Sergey Tkachenko
Do you mean disabling table resizing?
Exclude rvtoRowSizing and rvtoColSizing from table.Options

Re: Hide and show a button in a table cell on RichViewEdit

Posted: Tue Mar 27, 2018 10:07 am
by mohonko
Thank you very much. :) :) :)

Re: Hide and show a button in a table cell on RichViewEdit

Posted: Sat Mar 31, 2018 5:49 pm
by mohonko
Is there any way to determine whether the cursor is on the left or right side of the table?

Re: Hide and show a button in a table cell on RichViewEdit

Posted: Fri Apr 06, 2018 7:44 am
by Sergey Tkachenko
I am sorry for the delay.

There is a demo project that contains table and does not allow to move the caret outside of it:
http://www.trichview.com/forums/viewtop ... f=3&t=6382

Below is a code fragment from this demo showing how to implement this feature.

Code: Select all

const WM_BACKTOTABLE = WM_USER+1;

  TfrmNoteList = class(TForm)
   ...
    Moving: Boolean;
    procedure WMBackToTable(var Msg: TMessage); message WM_BACKTOTABLE;
   ...
  end;


procedure TfrmNoteList.rveCaretMove(Sender: TObject);
begin
  if not Visible or Moving then
    exit;
  if (rve.InplaceEditor=nil) and not (rvstCreatingInplace in rve.RVData.State) then begin
    PostMessage(Handle, WM_BACKTOTABLE, 0, 0);
    exit;
  end;
  if rve.InplaceEditor=nil then
    exit;
  Cell := rve.TopLevelEditor.RVData.GetSourceRVData as TRVTableCellData;
  ItemNo := rve.TopLevelEditor.CurItemNo;
  Offs := rve.TopLevelEditor.OffsetInCurItem;
end;

procedure TfrmNoteList.WMBackToTable(var Msg: TMessage);
var RVData: TCustomRVFormattedData;
begin
  if not Visible or (rve.InplaceEditor<>nil) or (Cell=nil) then
    exit;
  Moving := True;
  try
    RVData := Cell.Edit as TCustomRVFormattedData;
    RVData.SetSelectionBounds(ItemNo, Offs, ItemNo, Offs);
  finally
    Moving := False;
  end;
end;
rveCaretMove processes rve.OnCaretMove event. If the caret is outside of a table cell, it sends a message that invokes WMBackToTable procedure.
(we cannot move the caret directly inside OnCaretMove event, so we cannot directly call WMBackToTable, we need to use PostMessage)
Additionally, if we are inside a table cell, we storing this cell and the caret position in it.
In WMBackToTable, we starting editing cell and moving the caret to the last position in it. So, when the user tries to move the caret outside the table, it is immediately moves back.

This demo assumes that this table and cells inside it cannot be deleted. Otherwise, we need to intercept these operations and assign nil to Cell.

Re: Hide and show a button in a table cell on RichViewEdit

Posted: Fri Apr 06, 2018 12:46 pm
by Sergey Tkachenko
Sorry if the information above does not answer to your question. I believe your initial question was about not allowing placing the caret outside of the table.

As for this question:
Is there any way to determine whether the cursor is on the left or right side of the table?

Code: Select all

if RichViewEdit1.InplaceEditor <> nil then
  exit; // the caret is inside a table
if not (RichViewEdit1.GetCurrentItem is TRVTableItemInfo) then
  exit; // the caret is not near the table
if RichViewEdit1.OffsetInCurItem = 0 then
  <before table>
else
  <after table>

Re: Hide and show a button in a table cell on RichViewEdit

Posted: Sat Jul 28, 2018 10:32 am
by Josepherny
Thank you very much. This mehod is good. How to disable the ability to change the external dimensions of the border with the mouse?

Re: Hide and show a button in a table cell on RichViewEdit

Posted: Sat Jul 28, 2018 10:42 am
by Sergey Tkachenko
Do you mean resizing images or resizing table columns and mouse?