dannym wrote:

Hi,

Am Dienstag, den 03.01.2006, 22:17 +0000 schrieb C Western:
You might be interested in the attached fragment, which I posted to the mailing list a while back. It simulates the windows file Drag and drop calls using gtk calls. I would supply a patch to put it in the LCL, only I am not sure where to put it.
Colin

function DroppedFiles(var Message: TMessage):TStringList;
var
 i: Integer;
begin
 Result := TStringList.Create;
 try
   Result.Text := PChar(Message.lParam);
   for i := 0 to Result.Count-1 do
     if Pos('file://', Result[i]) = 1 then
       Result[i] := Copy(Result[i], 8, Length(Result[i]));

dnd urls look like:

file://foo.bar.com/path/to/file/on/local/disk

You put into the string list:
foo.bar.com/path/to/file/on/local/disk
The string I get begins file:///home/..., i.e. does not include the hostname

And, are you sure you want to keep the hostname in? I'd do something
like check if it matches fqdn (or is empty to support broken clients)
and if not, set a failed flag, but if so, strip the hostname off (since
no pascal function can handle file paths like that anyways :))


You forgot to call gtk_drag_finish in the DropCallBack (or I'm blind :))
I set GTK_DEST_DEFAULT_ALL in DragAccept files, and my reading of the documentation suggests this means that gtk calls gtk_drag_finish automatically

Note that selection data can contain _multiple_ urls. so split on (I
think) #13#10 (or whatever it is) and handle all.
This is handled by the string list assignment:
Result.Text := PChar(Message.lParam);
which does the split correctly.

And what does the loop over the targets do in DropCallBack ? the target
item doesn't seem to be used for anything in that function ^^
It does look odd - I think the intent was to look for a type that could be handled.

Note also that accepting "text/plain" and "STRING" targets is a horrible
workaround to support broken clients (after all, it could just be text -
and if it is pasted from a edit box, it's "UTF8_STRING", I think), and
there should be a comment which says so (since you never know, all
broken clients could vanish one day ;) yeah, as if....)
The text does have to begin with file://, which random text will not.

I'd call the DragAcceptFiles "RegisterDragAcceptFiles" or so :)
DragAcceptFiles is the Windows equivalent - the calls mirror the Windows equivalent pretty much exactly.

Colin

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to