From "examples and demos": d&d of images

General TRichView support forum. Please post your questions here
Martian
Posts: 82
Joined: Sun Apr 03, 2011 7:32 pm

Post by Martian » Mon Dec 26, 2016 7:39 pm

Just checked everything carefully.
I was confused why RichViewActionTest inserts image from Firefox without downloading (no interfaces even assigned) and tried with Chrome and Edge:
  • Firefox sends local file as \Temp\picture.bmp
    Chrome sends just link
    Edge like everything from Microsoft works strange, sometimes inserts local picture from it's cache but almost always just link like Chrome
    Drop from IE11 wasn't even accepted by RVE
BTW I think there still a bug when you insert hot pictures. My app download normal images (starting with "http:" or "https:") but if that image is hot (contains link) it gets inserted as text URL.

And I don't use RVE download interface.

Martian
Posts: 82
Joined: Sun Apr 03, 2011 7:32 pm

Post by Martian » Mon Dec 26, 2016 8:27 pm

I found why image from Firefox appears and then downloads.

When I drag a picture from Firefox I get OnDropFile(s) event with FileName = "\Temp\randomname.bmp"
I detect it and run LoadPictureFile procedure:

Code: Select all

procedure LoadPictureFile(FileName:String);
const StoreFileName = True;
var pic :TPicture;
    gr  :TGraphic;
    rve :TCustomRichViewEdit;
    ItemName:String;
begin
  IgnoreChanges:=True;
  rve:=RichViewEdit1.TopLevelEditor;
  pic:=TPicture.Create;
  try
    pic.LoadFromFile(FileName);
    gr:=RVGraphicHandler.CreateGraphic(TGraphicClass(pic.Graphic.ClassType));
    gr.Assign(pic.Graphic);
    if StoreFileName then begin
      rve.BeginUndoGroup(rvutInsert);
      rve.SetUndoGroupMode(True);
    end;
    try
      ItemName:=ExtractFileName(FileName);
      if rve.InsertPicture(ItemName,gr,rvvaBaseline) and StoreFileName then
        rve.SetCurrentItemExtraStrProperty(rvespImageFileName,FileName,True);
    finally
      if StoreFileName then rve.SetUndoGroupMode(False);
    end;
  except
    ShowError;
  end;
  pic.Free;
  IgnoreChanges:=False;
end;

After that I get that image insterded to RVE and then I get OnImportPicture event with correct URL to that image ("http://website.com/image.jpg"). 
My image downloader detects it as correct URL replaces already inserted image with "downloading" placeholder and downloads it.
How to prevent it?
Where that URL is stored when I use LoadPictureFile?
If I don't want to forget that URL but leave it in image properties?

Sergey Tkachenko
Site Admin
Posts: 14398
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Tue Dec 27, 2016 11:24 am

Different applications provide dragged data in different formats.

Edge (and Microsoft Explorer) provides dragged images as files (in its cache). It does not provide dragged images as URLs. So you receive file names of temporal cached image files.

Chrome does not provide images as files, but it provides them as links. So, you need to download images (as it was explained before), and you receive image URL.

FireFox provides dragged images BOTH as files and as URL.
TRichViewEdit tries to insert files first. If it does not succeed, it tries another format, and inserts the image from URL.

You can modify reading image files in OnDropFile(s) events.
As I can see, you try to load images yourself, but your code does almost exactly the same work as the standard TRichViewEdit code, so I cannot see how your code can help.
OnDropFile(s) events do not allow to report file insertion as unsuccessful. If you assign DoDefault = False, the component assumes that you successfully inserted files, If you assign DoDefault = True, the component tries to load images itself. If it cannot insert an image, it treats insertion as unsuccessful (and tries to insert in other formats)

Martian
Posts: 82
Joined: Sun Apr 03, 2011 7:32 pm

Post by Martian » Wed Dec 28, 2016 12:05 am

Looks like I found the problem.
I didn't handle OnDropFile but OnDropFiles for even one file.
Now I just put DoDefault:=False in OnDropFile and everything else processed via OnDropFiles.

Post Reply