Re: GtkCombo drag-and-drop



// I'm sorry, everybody.  I'm desperate.

#include <stdio.h>
#include <gtk/gtk.h>

#define USE_COMBO

enum
  {
  TARGET_WIDGET,
  TARGET_LAST_TARGET
  } ;

static GtkTargetEntry target_table[TARGET_LAST_TARGET] =
  {
  {"application/x-widget", 0, TARGET_WIDGET},
  } ;

static gboolean drag_drop (GtkWidget *dst_widget, GdkDragContext
*drag_context, gint x, gint y, guint time, gpointer user_data) ;

int main (int argc, char *argv[])
  {
  GtkWidget *wnd = NULL, *item = NULL, *lbl = NULL, *lst = NULL ;
#ifdef USE_COMBO
  GtkWidget *cb = NULL ;
#endif
  GList *lstItems = NULL ;

  gtk_init (&argc, &argv) ;

  wnd = gtk_window_new (GTK_WINDOW_TOPLEVEL) ;
  gtk_window_set_title (GTK_WINDOW (wnd), "DND Combo") ;

#ifdef USE_COMBO
  cb = gtk_combo_new () ;
  gtk_container_add (GTK_CONTAINER (wnd), cb) ;
  lst = GTK_COMBO (cb)->list ;
#else
  lst = gtk_list_new () ;
  gtk_container_add (GTK_CONTAINER (wnd), lst) ;
#endif

  lstItems = NULL ;
  item = gtk_list_item_new () ;
  gtk_widget_show (item) ;
  gtk_list_append_items (GTK_LIST (lst), 
    lstItems = g_list_prepend (lstItems, item)) ;
#ifdef USE_COMBO
  gtk_combo_set_item_string (GTK_COMBO (cb), 
    GTK_ITEM (item), "Label 1") ;
#endif

  gtk_drag_source_set (item, GDK_BUTTON1_MASK, target_table, 
    TARGET_LAST_TARGET,  GDK_ACTION_COPY | GDK_ACTION_MOVE);
  gtk_drag_source_set_icon_stock (item, GTK_STOCK_DND) ;
  gtk_drag_dest_set (item, GTK_DEST_DEFAULT_ALL, target_table, 
    TARGET_LAST_TARGET,  GDK_ACTION_COPY | GDK_ACTION_MOVE);
  g_signal_connect (G_OBJECT (item), "drag_drop", (GCallback)drag_drop,
    item) ;

  lbl = gtk_label_new ("Label 1") ;
  gtk_widget_show (lbl) ;
  gtk_container_add (GTK_CONTAINER (item), lbl) ;

  lstItems = NULL ;
  item = gtk_list_item_new () ;
  gtk_widget_show (item) ;
  gtk_list_append_items (GTK_LIST (lst), 
    lstItems = g_list_prepend (lstItems, item)) ;
#ifdef USE_COMBO
  gtk_combo_set_item_string (GTK_COMBO (cb), GTK_ITEM (item),
    "Label 2") ;
#endif

  gtk_drag_source_set (item, GDK_BUTTON1_MASK, target_table, 
    TARGET_LAST_TARGET,  GDK_ACTION_COPY | GDK_ACTION_MOVE);
  gtk_drag_source_set_icon_stock (item, GTK_STOCK_DND) ;
  gtk_drag_dest_set (item, GTK_DEST_DEFAULT_ALL, target_table, 
    TARGET_LAST_TARGET,  GDK_ACTION_COPY | GDK_ACTION_MOVE);
  g_signal_connect (G_OBJECT (item), "drag_drop", (GCallback)drag_drop,
    item) ;

  lbl = gtk_label_new ("Label 2") ;
  gtk_widget_show (lbl) ;
  gtk_container_add (GTK_CONTAINER (item), lbl) ;

  g_signal_connect_swapped (G_OBJECT (wnd), "delete_event", 
    G_CALLBACK(gtk_main_quit), NULL) ;

  gtk_widget_show_all (wnd) ;

  gtk_main () ;

  return 0 ;
  }

static gboolean drag_drop (GtkWidget *dst_widget, GdkDragContext
*drag_context, gint x, gint y, guint time, gpointer user_data)
  {
  fprintf (stderr, "drag_drop:Entering\n") ;
  gtk_drag_finish (drag_context, TRUE, FALSE, time) ;
  fprintf (stderr, "drag_drop:Leaving\n") ;
  return TRUE ;
  }





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