Page 1 of 1

Marking the whole table row and the whole table column of a focused table cell

Posted: Thu Dec 19, 2019 12:17 pm
by j&b
Hello,

my code for marking the whole table row and the whole table column of a focused table cell works as long as I put the code into a panel (.sbTabZeilefaerbenClick (Sender: TObject)).

But if I set it in .memoRVDblClick (Sender: TCustomRichView; ClickedWord: TRVUnicodeString; Style: Integer) I get an 'Abstract Error'.

What can I do - when I click on a cell - the whole table row and the whole table column of the focused cell are highlighted in yellow?

Jürgen
(D7 and TRichViewEdit 17.6)


// Code is OK (I must first focus the cell, then click below panel-button):

procedure TForm1.sbTabZeilefaerbenClick (Sender: TObject);
var i, j, h color: integer;
cs, rs, itemNo, Data: integer; // Color the entire font background
begin // This procedure is wg. an abstract error if the content is captured elsewhere

// Does table have the cursor?
if (not memo.CanChange) or (not memo.GetCurrentItemEx (TRVTableItemInfo, rve,
TCustomRVItemInfo (rveTable))) then begin
ShowMessage ('This option is intended to provide better orientation in a table,' + # 10 +
'by using the focused line u. Column turns yellow (discolored). '+ # 10);
exit;
end;

try
ItemNo: = rveTable.GetMyItemNo;
memo.BeginUndoGroup (rvutModifyItem);
memo.SetUndoGroupMode (True);
memo.BeginItemModify (ItemNo, Data);

// Determine the focused line here
cs: = - 1; rs: = - 1;
rveTable.GetNormalizedSelectionBounds (true, rveTzeile1, rveTspalte1, CS, RS);
if (cs = -1) and (rs = -1) then exit;

// Determine the focused cell color
hColor: = rveTable.cells [rveTzeile1, rveTspalte1] .color;
if hFarbe = clWhite then hFarbe: = 11993087 else hFarbe: = clWhite;

// Color all cells in the table white
For j: = 0 to rveTable.Rows.Count-1 do
for i: = 0 to rveTable.Rows [rveTzeile1] .Count-1 do
rveTable.SetCellColor (clWhite, j, i);

// Color focused cells in a row
for j: = 0 to rveTable.Rows [rveTzeile1] .Count-1 do
rveTable.SetCellColor (hFarbe, rveTzeile1, j);

// Color focused cells in a column
for j: = 0 to rveTable.Rows.Count-1 do
rveTable.SetCellColor (hFarbe, j, rveTspalte1);

finally
memo.EndItemModify (ItemNo, Data);
memo.SetUndoGroupMode (False);
memo.Change;
if memo.GetCurrentItemEx (TRVTableItemInfo, rve, TCustomRVItemInfo (rveTable)) then rveTable.EditCell (rveTzeile1, rveTspalte1);
end;
end; // of .sbTabZeilefaerbenClick


procedure TForm1.memoRVDblClick(Sender: TCustomRichView; ClickedWord: TRVUnicodeString; Style: Integer);
begin //Wenn memo.onDblClick vorliegt, wird dies Procedure nicht mehr durchlaufen
if Screen.Cursor=crHandPoint then begin
HyperlinkInfo;
HyperlinkAusfuehren;
end;

//sbTabZeilefaerbenClick (Self); //abstract error - Delphi ist frozen
end;

Re: Marking the whole table row and the whole table column of a focused table cell

Posted: Sat Dec 21, 2019 6:33 pm
by j&b
Does really nobody know what a solution could look like, if you click in a rveTabelle (rve: RichViewEdit) to get the 'cross' - in the intersection of which the focused cell is located?

My solution requires 2 steps:
1. Click on the cell
2. Click the switch '.sbTabZeilefaerbenClick'.

Re: Marking the whole table row and the whole table column of a focused table cell

Posted: Sat Dec 21, 2019 9:02 pm
by Sergey Tkachenko
Sorry for the delay.

When a cell is being edited, TRichViewEdit creates a special editor for this cell (cell inplace editor).
It is created you start edit cell, and it is destroyed when you move the caret from this cell.

There is a problem: you cannot destroy an inplace editor from inside its keyboard/mouse/drag events, because of VCL design.
Workaround: use PostMessage.
Example can be found in TRichView\Demos\DelphiUnicode\Assorted\Graphics\DragImg\
This demo uses PostMessage to move the caret in OnDragOver event.

Re: Marking the whole table row and the whole table column of a focused table cell

Posted: Sun Dec 22, 2019 10:27 am
by j&b
First Thanks.

The example in
TRichView\Demos\DelphiUnicode\Assorted\Graphics\DragImg\
is dragging a TImage to TRichViewEdit.
This does not fit my circumstances.

I want to have a row and column that intersect in the focused cell.

Re: Marking the whole table row and the whole table column of a focused table cell

Posted: Sun Dec 22, 2019 3:36 pm
by Sergey Tkachenko
That demo shows how to solve your problem: running from inside mouse/drag event a code that cannot be executed inside this event.
But ok, I'll make a project for you tomorrow.

Re: Marking the whole table row and the whole table column of a focused table cell

Posted: Mon Dec 23, 2019 8:50 pm
by Sergey Tkachenko
Attached.

I used OnRVMouseDown (with ssDouble in Shift check) instead of OnRVDblClick, because OnRVDblClick is not called when users click on an empty space.
highlightcell.png
highlightcell.png (7.56 KiB) Viewed 15231 times

Re: Marking the whole table row and the whole table column of a focused table cell

Posted: Tue Dec 24, 2019 8:30 am
by j&b
Thank you very much for your effort.

Unfortunately, I must have expressed myself incorrectly.

Your solution corresponds to mine.

I need 2 steps to get the 'cross':

1. Click in wanted cell
2. Click at 'sbTabZeilefaerben' button to run code.
Result: The 'cross' is created as posted by you.

It's the same in your example:
1. Click in the wanted cell
2. Click at 'Highlight' button.

But I want the cross to be created when I double click in a cell.

Can you help me with that ?

But first celebrate and enjoy christmas in peace and rest (without looking into your email account).

I wish you a happy, relaxed and uplifting Christmas. I once more many thanks for your immeditley help.

Jürgen

Re: Marking the whole table row and the whole table column of a focused table cell

Posted: Tue Dec 24, 2019 8:37 am
by Sergey Tkachenko
In my demo, this highlighting works both when you click on the button and when you double click in the cell.

Re: Marking the whole table row and the whole table column of a focused table cell

Posted: Tue Dec 24, 2019 8:52 am
by j&b
Sorry, sorry, sorry.

Your solution is different and works perfectly. I tried your example without looking into the code enough because I saw the 'Highlight' button.
I had double-clicked in a cell, but in anticipation I forgot that I had to do Shift + double-click.
Sorry again for my hasty feedback.

Jürgen

Re: Marking the whole table row and the whole table column of a focused table cell

Posted: Tue Dec 24, 2019 6:53 pm
by Sergey Tkachenko
My example does not require to press Shift key.

The check

Code: Select all

  if ssDouble in Shift then
in OnRVMouseDown allows detecting a double click. Shift is the parameter name, not the Shift button.

To detect only left mouse button double click, the condition must be changed to:

Code: Select all

  if (Button = mbLeft) and (ssDouble in Shift) then
But I found a bug in the code. rveTable.GetNormalizedSelectionBounds must be moved before try...except, otherwise an exception may occur when the caret is to the left or right side of the table (because rveTzeile1, rveTspalte1 will not be assigned in this case).
I attached a fixed version.

Re: Marking the whole table row and the whole table column of a focused table cell

Posted: Thu Jan 09, 2020 5:34 pm
by j&b
Thanks for your help.