FmDndSrc

## FmDndSrc FmDndSrc — Libfm support for drag&drop source. |

## Synopsis

    struct              FmDndSrc;
    struct              FmDndSrcClass;
    enum                FmDndSrcTarget;
    #define             fm_dnd_src_add_targets              (widget,
                                                             targets,
                                                             n)
    FmDndSrc *          fm_dnd_src_new                      (GtkWidget *w);
    void                fm_dnd_src_set_file                 (FmDndSrc *ds,
                                                             FmFileInfo *file);
    void                fm_dnd_src_set_files                (FmDndSrc *ds,
                                                             FmFileInfoList *files);
    void                fm_dnd_src_set_widget               (FmDndSrc *ds,
                                                             GtkWidget *w);

## Object Hierarchy

      GObject
       +----FmDndSrc

## Signals

      "data-get"                                       : Run First

## Description

`include`: libfm/fm-gtk.h

The FmDndSrc can be used by some widget to provide support for drag operations on FmFileInfo objects that are represented in that widget.

To use FmDndSrc the widget should create it with `fm_dnd_src_new()` and connect to the "data-get" signal of the created FmDndSrc object.

Example 5. Sample Usage

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    {
       widget->ds = fm_dnd_src_new(widget);
       g_signal_connect(widget->ds, "data-get", G_CALLBACK(on_data_get), widget);

       ...
    }

    static void on_object_finalize(MyWidget *widget)
    {
       ...

       g_signal_handlers_disconnect_by_data(widget->ds, widget);
       g_object_unref(G_OBJECT(widget->ds));
    }

    static void on_data_get(FmDndSrc *ds, MyWidget *widget)
    {
       FmFileInfo *file = widget->selected_file;

       fm_dnd_src_set_file(ds, file);
    }

The FmDndSrc will set drag activation for the widget by left mouse button so if widget wants to use mouse movement with left button pressed for something else (rubberbanding for example) then it should disable Gtk drag handlers when needs (by blocking handlers that match object data "gtk-site-data" usually).

If widget wants to handle some types of data other than FmFileInfo objects it should do it the usual way by connecting handlers for the "drag-data-get", "drag-begin", and "drag-end" signals and adding own targets to widget's drag source target list. To exclude conflicts the widget's specific handlers should use info indices starting from N_FM_DND_SRC_DEFAULT_TARGETS.

## Details

### struct FmDndSrc

    struct FmDndSrc;

### struct FmDndSrcClass

    struct FmDndSrcClass {
    	GObjectClass parent_class;
    	void (*data_get)(FmDndSrc*);
    };

GObjectClass `parent_class`; | the parent class
`data_get` () | the class closure for the "data-get" signal

### enum FmDndSrcTarget

    typedef enum {
        FM_DND_SRC_TARGET_FM_LIST = 1,
        FM_DND_SRC_TARGET_URI_LIST,
        FM_DND_SRC_TARGET_TEXT,
        N_FM_DND_SRC_DEFAULT_TARGETS
    } FmDndSrcTarget;

default targets of drag source

`FM_DND_SRC_TARGET_FM_LIST` | direct pointer of FmList
`FM_DND_SRC_TARGET_URI_LIST` | "text/uri-list"
`FM_DND_SRC_TARGET_TEXT` | Gtk+ default text targets
`N_FM_DND_SRC_DEFAULT_TARGETS` | widget's target indices should start from this

### fm_dnd_src_add_targets()

    #define             fm_dnd_src_add_targets(widget,targets,n)

Adds drag source targets to existing list for `widget`. Convenience API.

`widget` : | GtkWidget to add targets
`targets` : | pointer to array of GtkTargetEntry to add
`n` : | number of targets to add

Since 1.0.1

### fm_dnd_src_new ()

    FmDndSrc *          fm_dnd_src_new                      (GtkWidget *w);

Creates new drag source descriptor.

Before 1.0.1 this API didn't update drag source on widget so caller should set it itself. Since access to fm_default_dnd_src_targets outside of this API considered unsecure, that behavior was changed.

`w` : | the widget where source files are selected. [allow-none]
Returns : | a new FmDndSrc object. [transfer full]

Since 0.1.0

### fm_dnd_src_set_file ()

    void                fm_dnd_src_set_file                 (FmDndSrc *ds,
                                                             FmFileInfo *file);

Sets `file` as selection in the source descriptor.

`ds` : | the drag source descriptor
`file` : | files to set

Since 0.1.0

### fm_dnd_src_set_files ()

    void                fm_dnd_src_set_files                (FmDndSrc *ds,
                                                             FmFileInfoList *files);

Sets `files` as selection list in the source descriptor.

`ds` : | the drag source descriptor
`files` : | list of files to set

Since 0.1.0

### fm_dnd_src_set_widget ()

    void                fm_dnd_src_set_widget               (FmDndSrc *ds,
                                                             GtkWidget *w);

Resets drag source widget in `ds`.

Before 1.0.1 this API didn't update drag source on widget so caller should set and unset it itself. Access to fm_default_dnd_src_targets outside of this API considered unsecure so that behavior was changed.

`ds` : | the drag source descriptor
`w` : | the widget where source files are selected. [allow-none]

Since 0.1.0

## Signal Details

### The `"data-get"` signal

    void                user_function                      (FmDndSrc *object,
                                                            gpointer  user_data)      : Run First

The "data-get" signal is emitted when information of source files is needed. Handler of the signal should then call `fm_dnd_src_set_files()` to provide info of dragged source files.

`object` : | the object which emitted the signal
`user_data` : | user data set when the signal handler was connected.

Since 0.1.0