| 1 |
#include "iconstore.h" |
| 2 |
#include <gtk/gtk.h> |
| 3 |
|
| 4 |
struct _IconStore |
| 5 |
{ |
| 6 |
GtkListStore parent; |
| 7 |
|
| 8 |
gint text_column; |
| 9 |
}; |
| 10 |
|
| 11 |
struct _IconStoreClass |
| 12 |
{ |
| 13 |
GtkListStoreClass parent_class; |
| 14 |
}; |
| 15 |
|
| 16 |
static void icon_store_drag_source_init (GtkTreeDragSourceIface *iface); |
| 17 |
|
| 18 |
G_DEFINE_TYPE_WITH_CODE (IconStore, icon_store, GTK_TYPE_LIST_STORE, |
| 19 |
G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE, |
| 20 |
icon_store_drag_source_init)) |
| 21 |
|
| 22 |
|
| 23 |
static void |
| 24 |
icon_store_init (IconStore *store) |
| 25 |
{ |
| 26 |
GType types[4] = { G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING }; |
| 27 |
|
| 28 |
gtk_list_store_set_column_types (GTK_LIST_STORE (store), 4, types); |
| 29 |
|
| 30 |
store->text_column = ICON_STORE_NAME_COLUMN; |
| 31 |
} |
| 32 |
|
| 33 |
static void |
| 34 |
icon_store_class_init (IconStoreClass *class) |
| 35 |
{ |
| 36 |
} |
| 37 |
|
| 38 |
static gboolean |
| 39 |
row_draggable (GtkTreeDragSource *drag_source, |
| 40 |
GtkTreePath *path) |
| 41 |
{ |
| 42 |
return TRUE; |
| 43 |
} |
| 44 |
|
| 45 |
static gboolean |
| 46 |
drag_data_delete (GtkTreeDragSource *drag_source, |
| 47 |
GtkTreePath *path) |
| 48 |
{ |
| 49 |
GtkTreeIter iter; |
| 50 |
|
| 51 |
if (gtk_tree_model_get_iter (GTK_TREE_MODEL (drag_source), &iter, path)) |
| 52 |
return gtk_list_store_remove (GTK_LIST_STORE (drag_source), &iter); |
| 53 |
return FALSE; |
| 54 |
} |
| 55 |
|
| 56 |
static gboolean |
| 57 |
drag_data_get (GtkTreeDragSource *drag_source, |
| 58 |
GtkTreePath *path, |
| 59 |
GtkSelectionData *selection) |
| 60 |
{ |
| 61 |
GtkTreeIter iter; |
| 62 |
gchar *text; |
| 63 |
|
| 64 |
if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (drag_source), &iter, path)) |
| 65 |
return FALSE; |
| 66 |
|
| 67 |
gtk_tree_model_get (GTK_TREE_MODEL (drag_source), &iter, |
| 68 |
ICON_STORE (drag_source)->text_column, &text, |
| 69 |
-1); |
| 70 |
|
| 71 |
gtk_selection_data_set_text (selection, text, -1); |
| 72 |
|
| 73 |
g_free (text); |
| 74 |
|
| 75 |
return TRUE; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
static void |
| 80 |
icon_store_drag_source_init (GtkTreeDragSourceIface *iface) |
| 81 |
{ |
| 82 |
iface->row_draggable = row_draggable; |
| 83 |
iface->drag_data_delete = drag_data_delete; |
| 84 |
iface->drag_data_get = drag_data_get; |
| 85 |
} |
| 86 |
|
| 87 |
void |
| 88 |
icon_store_set_text_column (IconStore *store, gint text_column) |
| 89 |
{ |
| 90 |
store->text_column = text_column; |
| 91 |
} |