[Lazarus] GTK2: Drag files to other applications (to the file manager, Thunar, Nautilus, etc)

Bernd prof7bit at gmail.com
Mon Aug 20 21:51:10 CEST 2012


2012/8/20 Hans-Peter Diettrich <DrDiettrich1 at aol.com>:
> Bernd schrieb:
>
>> I am making progress. The handle is indeed a PGTKWidget but there are
>> always multiple widgets nested inside each other, for example a
>> TButton is really a GTKLabel inside a GTKButton inside a GTKEventBox,
>> so I have to recursively go through all the child widgets and set up
>> drag&drop for them all.
>
>
> Please clarify what you *really* want to achieve. DragDrop of *files* is
> very different from DragDrop of *components*.

I want to drag files, I *don't* want to drag the components
themselves. I don't want to interfere with or do anything docking
related.

I want to put the mouse cursor over one of my controls that represents
one or more files (for example the current selection of a list view
that represents files that either exist already somewhere in the file
system or can be extracted from a database on demand), press the mouse
button, drag it *outside* the application and drop it onto another
application (for example a file manager or the desktop) so that the
receiving application can then do what it usually does when files get
dropped onto it.

for this (at least on GTK2) I need to declare one of the GTK widgets
the "drag source" that will then fire various signals during the drag
operation. in GTK this is done with gtk_drag_source_set() and the
signals are connected with g_signal_connect() just like all the other
signals too.

My initial problem in Post #1 was that the LCL TButton.Handle actually
represents a GTKEventBox and only *inside* this as a child widget is
the actual GTKButton. This is why it did not work initially, I
registered the invisible GTKEventBox as drag source but could not
actually click it because I should have used the GTKButton instead
which is not directly exposed by the LCL. Similar with most other
controls too, they are all represented by more than one GTK widget.
Therefore I now made it simply recursively register and connect the
widget and *all* its contained sub-widgets, knowing that the one that
is actually exposed to the mouse and can fire drag-* signals must be
among them.

> Dragging *files* across applications is a matter of the platform, requiring
> different procedures for *sending* and *receiving*. I don't see how the
> widgetset is involved here,

The widgetset *is* the platform! (at least as far as file dragging is
concerned, no need to access any other API)




More information about the Lazarus mailing list