Replace picture with double click, keeping object properties

General TRichView support forum. Please post your questions here
Post Reply
mverbeek
Posts: 4
Joined: Fri Jan 17, 2014 11:42 am

Replace picture with double click, keeping object properties

Post by mverbeek »

I have a .RVF-file with a (temporary) picture. I want the end-user to replace this picture by double click on the picture, keeping object properties (visible size and spacing)

It should be a short cut to the File Dialog you get by richtclick on the picture, select Object Properties and then press the button Change.
It's necessery to set the Initial Directory!

ANY SUGGESTIONS?


I have tried by using the ActionInsertPicture

srvActionsResource.rvActionInsertPicture1.OnExecute := nil;
srvActionsResource.rvActionInsertPicture1.InitialDir := 'c:\';
srvActionsResource.rvActionInsertPicture1.MaxImageSize := 100;
srvActionsResource.rvActionInsertPicture1.Spacing := 5;
srvActionsResource.rvActionInsertPicture1.Execute;
srvActionsResource.rvActionInsertPicture1.OnExecute := srvActionsResource.rvActionInsertPicture1Execute;

but then i need to get the Object Properties of the double clicked picture to set
srvActionsResource.rvActionInsertPicture1.MaxImageSize
srvActionsResource.rvActionInsertPicture1.Spacing

I can not find out how

ANY SUGGESTIONS?
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I do not recommend using rvActionInsertPicture, because, as you noticed, it does not keep existing properties.
I suggest using your own TOpenPictureDialog and SetCurrentPictureInfo method.
mverbeek
Posts: 4
Joined: Fri Jan 17, 2014 11:42 am

Post by mverbeek »

Sergey

Thanks for the quick reply!

Do have some sample code (I am new to RichView)
NB I use ScaleRichViewEdit....
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Sorry for the delay.

It's simple, because a double-clicked item becomes current, so you can use CurItemStyle, GetCurrentPictureInfo and SetCurrentPictureInfo methods.

Code: Select all

procedure TForm3.SRichViewEdit1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var Gr: TGraphic;
    VAlign: TRVVAlign;
    Name: TRVAnsiString;
    Tag: TRVTag;
begin

  if (ssDouble in Shift) and
    ((SRichViewEdit1.ActiveEditor.CurItemStyle=rvsPicture) or
     (SRichViewEdit1.ActiveEditor.CurItemStyle=rvsHotPicture)) then begin
     SRichViewEdit1.ActiveEditor.GetCurrentPictureInfo(Name, Gr, VAlign, Tag);
     if OpenPictureDialog1.Execute then begin
       Gr := RVGraphicHandler.LoadFromFile(OpenPictureDialog1.FileName);
       if Gr=nil then
         Application.MessageBox('File loading error', 'Error', MB_OK or MB_ICONSTOP)
       else
         SRichViewEdit1.ActiveEditor.SetCurrentPictureInfo(Name, Gr, VAlign, Tag);
     end;
  end;
end;
RVGraphicHandler is defined in RVFuncs unit (for TRichView versions prior to 14.13) or in RVGrHandler unit (for TRichView 14.13+)
mverbeek
Posts: 4
Joined: Fri Jan 17, 2014 11:42 am

Post by mverbeek »

Sergey,

Thanks for the reply!

I accomplished it. Below the source, maybe handy for other users....

Best regards!


Code: Select all

procedure TFrmEditor.SRichViewEdit1RVDblClick(Sender: TCustomRichView;
  ClickedWord: TRVRawByteString; Style: Integer);
var
    AName: TRVAnsiString;
    Agr, Agr2: TGraphic;  AVAlign: TRVVAlign;  ATag: TRVTag  ;
    directory: String;
    setWidth, setHeight, orgWidth, orgHeight: Integer;
    setFactor: double;
begin
  if (Style = rvsPicture) then
    begin
    if pPernumb > 0 then
     begin
       directory  := PATIENTEN + GetPatientDir(IntToStr(pPernumb));
       OpenPictureDialog.InitialDir := directory;
     end
    else
      begin
      directory  := TEMPLATES;
      OpenPictureDialog.InitialDir := directory;
      end;

    if OpenPictureDialog.Execute then
      begin
      SRichViewEdit1.ActiveEditor.GetCurrentPictureInfo(  AName, Agr, AVAlign, ATag );
      SRichViewEdit1.ActiveEditor.GetCurrentItemExtraIntProperty( rvepImageWidth , setWidth);
      Agr2 := RVGraphicHandler.LoadFromFile(OpenPictureDialog.FileName);
      orgWidth  := Agr2.Width;
      orgHeight := Agr2.Height;
      setFactor := orgHeight /orgWidth ;
      setHeight := Round(setFactor * setWidth) ;
      SRichViewEdit1.ActiveEditor.SetCurrentPictureInfo(  AName, Agr2, AVAlign, ATag );

      SRichViewEdit1.ActiveEditor.SetCurrentItemExtraIntProperty( rvepImageWidth , setWidth, true);
      SRichViewEdit1.ActiveEditor.SetCurrentItemExtraIntProperty( rvepImageHeight , setHeight, true);
      end;
    end;
end;
Post Reply