Drag and Drop.



Hello.

I am trying to implement some drag and drop in my app. I'd like to drag from
one ctree to another. The data should _not_ be deleted in the source ctree. THere
are two kinds of data: Folders (node data: char*) and Files (node data: struct file_t*).
Is this a correct and good solution (pseudo code):

callback drag_begin(...) {
  if (folder)
    g_dataset_set_data (drag_context, "drag-source-folder", (char*)foldername);
  else
    g_dataset_set_data (drag_context, "drag-source-file", (struct file_t*)file);
}

callback drag_data_get(...) {
  char* folder;
  struct file_t* file;

  folder = g_dataset_get_data (drag_context, "drag-source-folder");
  file = g_dataset_get_data (drag_context, "drag-source-file");

  /* now my problems:
     1. gtk_selection_data_set() copies the data, but i dont want to do
        that, i just need a link to the data.
     2. after the selection_data_set() i dont have to information whether it
        is a file or a folder any longer. (i dont want to use a struct with
        a type field and a datapointer in it) */
  if (folder)
    gtk_selection_data_set (data, data->target, GTK_TYPE_POINTER,
                            folder, sizeof(?what?));
  if (file)
    gtk_selection_data_set (data, data->target, GTK_TYPE_POINTER,
                            file, sizeof(?what?));
}

callback drag_data_received(...) {
  void* data_pointer;

  data_pointer = selection_data->data;
  /* but now i dont know, whether it is a file or a folder..*/  
  
}

Anyone can help me out, or is there any good example?

Markus.




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