1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "iconstore.h"
#include <ctk/ctk.h>

struct _IconStore
{
  CtkListStore parent;

  gint text_column;
};

struct _IconStoreClass
{
  CtkListStoreClass parent_class;
};

static void icon_store_drag_source_init (CtkTreeDragSourceIface *iface);

G_DEFINE_TYPE_WITH_CODE (IconStore, icon_store, CTK_TYPE_LIST_STORE,<--- There is an unknown macro here somewhere. Configuration is required. If G_DEFINE_TYPE_WITH_CODE is a macro then please configure it.
                         G_IMPLEMENT_INTERFACE (CTK_TYPE_TREE_DRAG_SOURCE,
                                                icon_store_drag_source_init))


static void
icon_store_init (IconStore *store)
{
  GType types[4] = { G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING };

  ctk_list_store_set_column_types (CTK_LIST_STORE (store), 4, types);

  store->text_column = ICON_STORE_NAME_COLUMN;
}

static void
icon_store_class_init (IconStoreClass *class)
{
}

static gboolean
row_draggable (CtkTreeDragSource *drag_source,
               CtkTreePath       *path)
{
  return TRUE;
}

static gboolean
drag_data_delete (CtkTreeDragSource *drag_source,
                  CtkTreePath       *path)
{
  CtkTreeIter iter;

  if (ctk_tree_model_get_iter (CTK_TREE_MODEL (drag_source), &iter, path))
    return ctk_list_store_remove (CTK_LIST_STORE (drag_source), &iter);
  return FALSE;
}

static gboolean
drag_data_get (CtkTreeDragSource *drag_source,
               CtkTreePath       *path,
               CtkSelectionData  *selection)
{
  CtkTreeIter iter;
  gchar *text;

  if (!ctk_tree_model_get_iter (CTK_TREE_MODEL (drag_source), &iter, path))
    return FALSE;

  ctk_tree_model_get (CTK_TREE_MODEL (drag_source), &iter,
                      ICON_STORE (drag_source)->text_column, &text,
                      -1);

  ctk_selection_data_set_text (selection, text, -1);

  g_free (text);

  return TRUE;
}


static void
icon_store_drag_source_init (CtkTreeDragSourceIface *iface)
{
  iface->row_draggable = row_draggable;
  iface->drag_data_delete = drag_data_delete;
  iface->drag_data_get = drag_data_get;
}

void
icon_store_set_text_column (IconStore *store, gint text_column)
{
  store->text_column = text_column;
}