ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 TImageEnMView / TImageEnFolderMView Drag files out
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

cpstevenc

USA
125 Posts

Posted - Apr 06 2025 :  01:37:32  Show Profile  Reply
Using D12.3 and 13.6.0

Been using TImageEnMView for years now to show thumbnails.
And way we do this is our image system for many years, has pre-generated thumbnails to load from.
We needed this for speed back in the day. As most if not all users have images on network drives.
And some do this over a client machine over VPN to their server network. So even slower.

So anyways, we populate TImageEnMView manually for thumbnails with supplied thumbnail images.
User double clicks thumbnail, right clicks on it for a popup, ect, we use the fullsize image to work with.
Via a look up table we have. Each index of the thumbnails, line up with a list that has the fullsize images.

Works great, these past 10+ years.

Well, now they want to be able to click on a thumbnail and drag it out.. to a chat system, explorer, browser, whatever target.

I saw "FileDragDrop" which seems to work, but a bit of code needed for mouse events. Plus was for TImageEnView.
Could not find an equal demo for TImageEnMView.

Then I see there is TImageEnFolderMView.

This works very similar to TImageEnMView. I virtually replaced the object type and compiled and worked.

There is an AutoDragFiles options to enable, and I did, and guess what it works.

But.. it works to well. as i populate it with our pre-generated thumbnails, that is all it knows.

I need to be able to override the filename it hooked to.

Which defeats the purpose of "AutoDrag"

So I guess, back to TImageEnMView. And getting it so it can drag out thumbnails out, but it actually be the full size image file name.

Our image system is GUID + _THUMB.JPG ... for a thumb... and no _THUMB on the file name for fullsize.

Example,

FC5A8BF5650142BD85146F52921A674D.JPG
FC5A8BF5650142BD85146F52921A674D_THUMB.JPG


So just looking for some ideas here before I try to TImageEnMView method of a drag flag, and using the mouse down events, and trying to see which thumbnail was clicked on to drag out and fill in the file name as needed that is to really be dragged and dropped.

cpstevenc

USA
125 Posts

Posted - Apr 06 2025 :  03:25:58  Show Profile  Reply
I was able to get this working. Using the TImageEnFolderMView code for some guidance and the drag and drop file demo.

Below code what I came up with to handle my situation, with the file name fixing.

Made it an object to create for this.
To help make this a bit easier to apply to other exact same situations, as I have
a number of places to apply this.

Not sure if best way to go about this, but .. it works?

unit Unit87;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  System.types,
  hyiedefs, hyieutils, iexBitmaps, iesettings, iemio, ieview, iemview, iexFolderMView,
  iexWindowsFunctions, Vcl.StdCtrls;

type

  TImageDragAndDropHelper = class
  private
    fDragging: boolean;
    fMouseClickPos: tpoint;
    fMouseClickTime: cardinal;
    fLastDragTime: cardinal;
    fDragDrop: TIEFileDragDrop;
    fImage: TImageEnMView;
  public
    constructor Create;
    destructor Destroy; override;
    procedure setMouse(Button: TMouseButton; X, Y: Integer);
    procedure CheckDrag(X, Y: Integer);
    property Image : TImageEnMView read fImage write fImage;
  end;


  TForm87 = class(TForm)
    Image_inventory: TImageEnMView;
    procedure FormCreate(Sender: TObject);
    procedure Image_inventoryMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure Image_inventoryMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  private
  public
    dragImage: TImageDragAndDropHelper;
  end;

var
  Form87: TForm87;

implementation

{$R *.dfm}

Constructor TImageDragAndDropHelper.Create;
begin
  inherited;
  fDragging := false;
  fMouseClickTime := 0;
  fLastDragTime := 0;
  fDragDrop := nil;
end;

Destructor TImageDragAndDropHelper.Destroy;
begin
  if assigned(fDragDrop) then
    fDragDrop.free;
  inherited;
end;

procedure TImageDragAndDropHelper.setMouse(Button: TMouseButton; X, Y: Integer);
begin
  fDragging := Button = mbLeft;
  fMouseClickPos := point(X, Y);
  fMouseClickTime := GetTickCount();
end;

procedure TImageDragAndDropHelper.CheckDrag(X, Y: Integer);
const
  MS_Before_Drag = 333;
var
  ssFilenames: TStringList;
  fileIDX: Integer;
  idx: Integer;
begin
  if not assigned(fImage) then // no reason to run if not assigned yet
    exit;

  idx := fImage.ImageAtPos(fMouseClickPos.X, fMouseClickPos.Y, true);
  if (fDragging) and (GetTickCount() - fMouseClickTime > MS_Before_Drag) and (idx > -1) and
       ((Abs(X - fMouseClickPos.X) >= Mouse.DragThreshold) or (Abs(Y - fMouseClickPos.Y) >= Mouse.DragThreshold)) then
  begin
    fDragging := false;
    fImage.Perform(WM_LBUTTONUP, 0, MakeLong(X, Y));
    ssFilenames := TStringList.Create;
    try
      fImage.SelectedFilenames(ssFilenames);
      if ssFilenames.Count > 0 then
      begin
        // we have image set that have pre-built thumbnails
        // we show only the thumbnail in the TImageEnMView
        // but we really want to drag the fullsize image
        // downside is, the chances the full image does not exist
        // in our production code, it populates thumbnails only if fullsize image file exists
        // so the chance it was removed since then is slim but could happen.

        for fileIDX := 0 to ssFilenames.Count - 1 do
          ssFilenames[fileIDX] := stringreplace(ssFilenames[fileIDX], '_thumb', '', [rfignorecase]);

        // if becomes a problem, can add an option to double check and remove from ssFilenames any file
        // that does not exist. Right now not going to since network drivers are slow
        // and need this to be fast
        // worse case, will add it and just have to deal with it

        if fDragDrop = nil then
          fDragDrop := TIEFileDragDrop.Create(nil); // we just need to create it. No events needed
        fDragDrop.ShowPreview := true;
        fDragDrop.PreviewWidth := fImage.ThumbWidth;
        fDragDrop.PreviewHeight := fImage.ThumbHeight;
        fDragDrop.InitiateDragging(ssFilenames, [iedaCopy, iedaMove]);
      end;
    finally
      ssFilenames.free;
    end;
  end;
end;


procedure TForm87.FormCreate(Sender: TObject);
begin
  Image_inventory.fillfromdirectory('c:\cmis\2025\2025', -1, true);
  dragImage := TImageDragAndDropHelper.Create;
  dragImage.fImage := Image_inventory;
end;

procedure TForm87.FormDestroy(Sender: TObject);
begin
  dragImage.free;
end;

procedure TForm87.Image_inventoryMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  dragImage.setMouse(Button, X, Y);
end;

procedure TForm87.Image_inventoryMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  dragImage.CheckDrag(X, Y);
end;


end.
Go to Top of Page

xequte

38923 Posts

Posted - Apr 06 2025 :  18:49:56  Show Profile  Reply
Yes, that looks like a good solution. There should really be an OnGetFilename event to allow you to supply alternative filenames for these kinds of purposes. We'll look at that for a later update.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: