Page 1 of 2

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

Posted: Wed Nov 30, 2016 2:41 am
by Martian
Can you update this demo to show how to process image dragged from browser?
When you drag some image from Firefox for example it sends only link to that image but not image itself.
I know how to download and insert image into RVE but I'm not sure about the better way to do it.
When you import HTML you get OnImportPicture event but when you drag some image from another app RVE fires OnOleDragDrop (the hard way) and OnReadHyperlink (this one should be used as I think).

The problem is if I insert picture in OnReadHyperlink event (and set StyleNo:=rvsPicture) I get new item and all current item data are not valid.
Please help.

BTW I use CleverComponents for image downloading so simple code for image downloading is enough:
clDownloader.URL:='...url.png';
clDownloader.Start(False);

Posted: Wed Nov 30, 2016 8:18 am
by Sergey Tkachenko
When dragging from a browser, the browser provides data in multiple formats, and TRichViewEdit chooses from available formats.
So, when dragging an image:
- from Edge, TRichViewEdit inserts a plain text (the image URL),
- from Chrome/FireFox, TRichViewEdit inserts a hyperlink (to the image URL).

Currently, TRichViewEdit chooses formats in the following order:
1) RVF
2) RTF
3) hyperlink
4) plain text
5) bitmap
6) metafile
7) files

Well, I think files must be moved higher, between RTF and hyperlink. It will be included in the next update.
It solves the problem with Edge (and I believe, in Internet Explorer too): it provides data as an image file in the browser cache.

But, as I can see, FireFox/Chrome does not provide data as an image, neither as bitmap/metafile nor as a file. So TRichView continues inserting it as URL.

Well, of course, TRichViewEdit can check if the dropped link is a link to a picture, download this picture and insert, but I believe it should not do it. No other editor does it. For example, MS Word inserts this image as a hyperlink too.

Posted: Wed Nov 30, 2016 10:00 pm
by Martian
Sergey Tkachenko wrote:Well, of course, TRichViewEdit can check if the dropped link is a link to a picture, download this picture and insert, but I believe it should not do it.
This is exactly what I want to implement.

If you drag image from firefox or chrome to windows explorer it will save this image, not URL. I want to do the same.
When you drag image from the browser to RVE who needs it's URL? Right - nobody. Everyone want to see that image.

Please help to implement it. I will check dropped link if it's URL to an image and download it manually.

Posted: Thu Dec 01, 2016 6:44 am
by Sergey Tkachenko
The problem is: the editor does not know the source application. I has only a data object, containing data in several formats, including URL.
How could it know that the user does not need the URL but needs a picture?

Posted: Thu Dec 01, 2016 7:18 am
by Martian
By picture extension at the end (like http://www.web.com/pic.png)
In my case real picture is most important than it's link.
Anyway I would like to implement it. What is the better way?

Posted: Thu Dec 01, 2016 5:21 pm
by Sergey Tkachenko
I added an option to download images when accepting d&d URLs.
It will be uploaded with the next update.

Posted: Fri Dec 02, 2016 6:02 am
by Martian
Sergey Tkachenko wrote:I added an option to download images when accepting d&d URLs.
You mean RichViewEdit?
When we can expect this update?

Posted: Fri Dec 02, 2016 8:05 am
by Sergey Tkachenko
TRichViewEdit and TSRichViewEdit.
We plan to upload this update in the next week.

Posted: Wed Dec 21, 2016 9:41 am
by Sergey Tkachenko
This feature is implemented in TRichView 16.11, available for registered users.

Posted: Thu Dec 22, 2016 7:05 am
by Martian
Ok it almost works but my ChangePicture procedure cannot find that image to replace placeholder because there is no URL attached to placeholder.
Where should I check for it?

When I import from HTML all imported images come with ItemURL set.

Code: Select all

RVData.GetItemExtraStrProperty(i, rvespImageFileName, ItemURL);

Posted: Fri Dec 23, 2016 2:36 am
by Martian
Any help?

Posted: Fri Dec 23, 2016 6:55 am
by Sergey Tkachenko
In the next update (probably today), we will add a new option in TRichView.Options: rvoAssignImageFileNames.
If you include it, file names will be assigned to images imported from files (local or HTTP) while pasting, drag&drop, reading RTF, HTML, using RichViewActions.

Posted: Sun Dec 25, 2016 8:46 am
by Sergey Tkachenko
Implemented in TRichView 16.12, available for registered users.

Posted: Mon Dec 26, 2016 7:55 am
by Martian
Ok, works now but looks like RichViewActionTest doesn't redownloads dragged image. Do you have a demo how?
Even rvoAssignImageFileNames is not enabled there.
Do I still need to download that image?
Because right now it inserts image (as I can see) then changes it to a placeholder image and then my app downloads it again.
I'm a bit confused.

Posted: Mon Dec 26, 2016 5:58 pm
by Sergey Tkachenko
The image should be downloaded one time.

1) You need to define a downloader.
Place on the form:
- RVAControlPanel1: TRVAControlPanel*
- RVAIndyDownloadInterface1: TRVAIndyDownloadInterface
- IdHttp1: TIdHttp,
Assign:
- RVAIndyDownloadInterface1.IdHttp = IdHttp1
- RVAControlPanel1.DownloadInterface = RVAIndyDownloadInterface1

2) Process TRichViewEdit.OnBeforeOleDrop and OnAfterOleDrop events to enable image downloading for drag&drop. The code can be found in the help file, in the topic about these events.

---

Note *: there should be a single TRVAControlPanel in an application (if you use multiple control panels, you need to assign them to actions and combo boxes manually)