Context reaction depending on item type

General TRichView support forum. Please post your questions here
Post Reply
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

Context reaction depending on item type

Post 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
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Context reaction depending on item type

Post 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;
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

Re: Context reaction depending on item type

Post 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;
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Context reaction depending on item type

Post 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.
Post Reply