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

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

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

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

Post 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.
Martian
Posts: 95
Joined: Sun Apr 03, 2011 7:32 pm

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

Post 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?
Martian
Posts: 95
Joined: Sun Apr 03, 2011 7:32 pm

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

Post by Sergey Tkachenko »

I added an option to download images when accepting d&d URLs.
It will be uploaded with the next update.
Martian
Posts: 95
Joined: Sun Apr 03, 2011 7:32 pm

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

Post by Sergey Tkachenko »

TRichViewEdit and TSRichViewEdit.
We plan to upload this update in the next week.
Sergey Tkachenko
Site Admin
Posts: 17571
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

This feature is implemented in TRichView 16.11, available for registered users.
Martian
Posts: 95
Joined: Sun Apr 03, 2011 7:32 pm

Post 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);
Martian
Posts: 95
Joined: Sun Apr 03, 2011 7:32 pm

Post by Martian »

Any help?
Sergey Tkachenko
Site Admin
Posts: 17571
Joined: Sat Aug 27, 2005 10:28 am
Contact:

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

Post by Sergey Tkachenko »

Implemented in TRichView 16.12, available for registered users.
Martian
Posts: 95
Joined: Sun Apr 03, 2011 7:32 pm

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

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