How to drag/drop non-string data?



I'm trying to drag and drop unsigned integers from one tree view to
another, but from what I can see the API only supports dragging of
guchar *.  From what I understand about drag and drop I need to store
the data to be dragged in GtkSelectionData with gtk_selection_data_set()
in the drag_data_get signal handler function.  But it only accepts
guchar * parameters.  I found an example somewhere that said you could
put a pointer to whatever you want in place of the guchar *data
parameter (like in my example below), but I can only get it to transfer
integers in the guchar range (0-255).  Thanks for any help you can
provide!

Jeremy


/* "drag_data_get" signal handler */
int
indexGetData(GtkWidget *sourceView, GdkDragContext *context,
GtkSelectionData *seldata, 
             guint info, guint time, gpointer *data)
{
  GtkTreeModel *indexModel;
  GtkTreeIter iter;
  GtkTreeSelection *indexSelection;
  guint index_id;
  guint *pindex_id;

  pindex_id = &index_id; 

  indexModel = gtk_tree_view_get_model(GTK_TREE_VIEW(sourceView));

  indexSelection =
gtk_tree_view_get_selection(GTK_TREE_VIEW(sourceView));

  if (gtk_tree_selection_get_selected(indexSelection, &indexModel,
&iter));
  {
    gtk_tree_model_get (indexStore, &iter, 0, &index_id, -1);
    gtk_selection_data_set(seldata,
                         GDK_SELECTION_TYPE_INTEGER,
                         sizeof (guint32)*8,
                         pindex_id,
                         sizeof (guint32));

    g_printf("word: %i\n", *seldata->data);
    /* only works if number to be stored is between 0-255 */
  }
}

...
/* source widget set-up */
  static GtkTargetEntry targetentries[] =
  {
    { "index id", GTK_TARGET_SAME_APP, TARGET_INDEX_ID }
  };

  gtk_drag_source_set (GTK_WIDGET(indexTreeView), GDK_BUTTON1_MASK,
targetentries, 1, GDK_ACTION_COPY);

  g_signal_connect (GTK_WIDGET(indexTreeView), "drag_data_get",
G_CALLBACK(indexGetData), NULL);
...





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]