Page 1 of 1

Replace picture with double click, keeping object properties

Posted: Fri Jan 17, 2014 12:47 pm
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?

Posted: Fri Jan 17, 2014 2:45 pm
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.

Posted: Fri Jan 17, 2014 2:51 pm
by mverbeek
Sergey

Thanks for the quick reply!

Do have some sample code (I am new to RichView)
NB I use ScaleRichViewEdit....

Posted: Sat Jan 25, 2014 9:24 am
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+)

Posted: Mon Jan 27, 2014 8:50 am
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;