Page 1 of 1

Context reaction depending on item type

Posted: Wed Nov 01, 2023 12:15 pm
by Jim Knopf
How can I cause a popup menu to pop up when right-clicking (without first left-clicking the item) on a text item, and a graphics edit window to pop up on a graphics item?

It works with the solution I show below sometimes, but sometimes the image editing window opens even though it's a text.

Following windows used for the same text:
1. rv - TRichviewEdit in normal mode
2. rv - the same TRichviewEdit in puristic mode (different look for revision)
3. srv - TSRichViewEdit
(see image below)

Here is how I have tried to solve it so far:

Code: Select all

procedure TfMain.rvMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var RVData: TCustomRVFormattedData;
    ItemNo, Offs: Integer;
begin
  . . .
  // Popup menu text or graphic
  FPicItemNo := -1;
  if Pages then // = TSRichViewEdit
    srv.GetItemAt(X, Y, RVData, ItemNo, Offs, False)
  else
    rv.GetItemAt(X, Y, RVData, ItemNo, Offs, False);
  if CurrRV.GetItem(ItemNo) is TRVGraphicItemInfo then
    FPicItemNo := ItemNo;
  . . .
end;

Code: Select all

procedure TfMain.rvRVMouseDown(Sender: TCustomRichView; Button: TMouseButton; Shift: TShiftState; ItemNo, X, Y: Integer);
var RVData: TCustomRVFormattedData;
    ItemNo, Offs: Integer;
begin
  if (Button = mbRight) and (FPicItemNo <> -1) then
  begin
    CurrRV.SetSelectionBounds(FPicItemNo, 1, FPicItemNo, 1);
    EditImage;
  end;
end;
3 versions:

Image

Re: Context reaction depending on item type

Posted: Wed Nov 01, 2023 1:19 pm
by Sergey Tkachenko
The simplest solution is to process PopupMenu's OnPopup event.

Code: Select all

if srv.ActiveEditor.CurItemNo in [rvsPicture, rvsHotPicture) then 
begin
  srv.ActiveEditor.GetCurrentPictureInfo(...);
  <display your popup>
  abort; // prevent displaying the popup menu
end;

Re: Context reaction depending on item type

Posted: Wed Nov 01, 2023 2:06 pm
by Jim Knopf
Thanks Sergey, I didn't know that you can prevent the menu from being created in OnPopUp. This is of course a very easy way!

Small correction, because the values of the set must be positive only (If maybe someone else has this problem too):

Code: Select all

  if (CurrRV.CurItemStyle = rvsPicture) or (CurrRV.CurItemStyle = rvsHotPicture) then
  begin
    EditImage;
    Abort; // prevent displaying the popup menu
  end;

Re: Context reaction depending on item type

Posted: Thu Nov 02, 2023 10:19 am
by Sergey Tkachenko
Well, actually, there is a better place for this code: OnContextPopup event.
It has Handled parameter, so no need to call Abort.