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

## Functions

#define | fm_dnd_src_add_targets()
FmDndSrc * | fm_dnd_src_new ()
void | fm_dnd_src_set_file ()
void | fm_dnd_src_set_files ()
void | fm_dnd_src_set_widget ()

## Signals

void | data-get | Run First

## Types and Values

struct | FmDndSrc
struct | FmDndSrcClass
enum | FmDndSrcTarget

## Object Hierarchy

        GObject
        ╰── FmDndSrc

## 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.

## Functions

### 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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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

Since: 0.1.0

## Types and Values

### struct FmDndSrc

    struct FmDndSrc;

### struct FmDndSrcClass

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

#### Members

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

### enum FmDndSrcTarget

default targets of drag source

#### Members

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 |

## Signal Details

### The `“data-get”` signal

    void
    user_function (FmDndSrc *object,
                   gpointer  user_data)

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.

#### Parameters

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

Flags: Run First

Since: 0.1.0