gcolorsel DnD patch



I've added DnD support to gcolorsel, the diff is attached.

As well as the normal left drag I've added support for middle dragging as
well which uses GDK_ACTION_ASK instead of GDK_ACTION_COPY. 
(I wanted the ability to ask what to do for use in Screem)

I've also added a close button, as was mentioned in the TODO file.



David

-- 
The superior man understands what is right;
the inferior man understands what will sell.
		-- Confucius
--- gcolorsel.c	Fri Jun 11 02:24:40 1999
+++ gcolorsel.c	Fri Jun 11 04:47:58 1999
@@ -25,6 +25,16 @@
                     NULL
 };
 
+enum {
+	TARGET_COLOUR
+};
+
+static const GtkTargetEntry drag_types[] = {
+        { "application/x-color", 0, TARGET_COLOUR },
+};
+static const gint n_drag_types = sizeof(drag_types) / sizeof(drag_types[0]);
+
+
 GtkWidget *window, *clist;
 GdkGC *gc;
 GdkColor black;
@@ -41,6 +51,18 @@
 			      gint column,
 			      GdkEventButton *event,
 			      gpointer data);
+static void button_press_cb(GtkWidget *widget,
+			    GdkEventButton *event,
+			    gpointer data );
+static void drag_data_get_cb(GtkWidget *widget,
+			     GdkDragContext *context,
+			     GtkSelectionData *selection_data,
+			     guint info,
+			     guint time,
+			     gpointer data);
+static void drag_begin_cb(GtkWidget *widget, 
+			  GdkDragContext *context, 
+			  gpointer data);
 void 		menu_item_cb(GtkWidget *menuitem, gpointer data);
 void make_menus(GnomeApp *app);
 
@@ -55,6 +77,7 @@
     GtkWidget *menu, *dropdown;
     GtkWidget *label, *sw;
     GtkWidget *name_e, *value_e;
+    GtkWidget *button;
 
 #ifdef ENABLE_NLS
     bindtextdomain(PACKAGE, GNOMELOCALEDIR);
@@ -113,6 +136,12 @@
     /* some silly stuff to avoid too many globals */
     gtk_object_set_data(GTK_OBJECT(clist), "name_entry", name_e);
     gtk_object_set_data(GTK_OBJECT(clist), "value_entry", value_e);
+
+    /* close button */
+    button = gnome_stock_button(GNOME_STOCK_BUTTON_CLOSE);
+    gtk_signal_connect(GTK_OBJECT(button), "clicked", 
+		       GTK_SIGNAL_FUNC(delete_event), NULL);
+    gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 2);
 	
     gnome_app_set_contents(GNOME_APP(window), vbox);
 	
@@ -141,6 +170,65 @@
     gtk_entry_set_text(GTK_ENTRY(name_e), tmp);
 }	        
 
+static void button_press_cb(GtkWidget *widget,
+			    GdkEventButton *event,
+			    gpointer data )
+{
+	gint row = -1;
+	gint col;
+
+	gtk_clist_get_selection_info(GTK_CLIST(widget), event->x, event->y,
+				     &row, &col);
+
+	gtk_object_set_data(GTK_OBJECT(widget), "drag_start", (gpointer*)row);
+}
+
+static void drag_data_get_cb(GtkWidget *widget,
+			     GdkDragContext *context,
+			     GtkSelectionData *selection_data,
+			     guint info,
+			     guint time,
+			     gpointer data)
+{
+	RGBColor *c;
+	gint row;
+    	guint16 rgb[ 4 ];
+
+	if ( !GTK_CLIST(widget)->selection )
+		return;
+
+	row = (gint)gtk_object_get_data(GTK_OBJECT(widget), "drag_start");
+
+	if (row == -1)
+		return;
+
+	c = gtk_clist_get_row_data(GTK_CLIST(widget), row);
+	rgb[0] = (c->r)*256;
+	rgb[1] = (c->g)*256;
+	rgb[2] = (c->b)*256;
+	rgb[3] = 0;
+
+	switch ( info ) {
+	case TARGET_COLOUR:
+		gtk_selection_data_set( selection_data, selection_data->target,
+					8, (guchar*)rgb, 8 );
+		break;
+	}
+
+}
+
+static void drag_begin_cb(GtkWidget *widget, 
+			  GdkDragContext *context, 
+			  gpointer data)
+{
+	gint row;
+
+	row = (gint)gtk_object_get_data(GTK_OBJECT(widget), "drag_start");
+
+	if ( row != -1 )
+		gtk_clist_select_row(GTK_CLIST(widget), row, 1);
+}
+
 static GtkWidget *create_clist(void)
 {
     GdkColormap *colormap;
@@ -157,6 +245,17 @@
     gtk_clist_set_column_title(GTK_CLIST(clist), 2, _("Name"));
     gtk_clist_column_titles_show(GTK_CLIST(clist));
 
+    /* set drag source */
+    gtk_drag_source_set(clist, GDK_BUTTON1_MASK|GDK_BUTTON2_MASK,
+			drag_types, n_drag_types,
+			GDK_ACTION_COPY | GDK_ACTION_ASK);
+    /* connect drag signals */
+    gtk_signal_connect(GTK_OBJECT(clist), "button_press_event",
+		       GTK_SIGNAL_FUNC(button_press_cb), NULL);
+    gtk_signal_connect(GTK_OBJECT(clist), "drag_data_get",
+		       GTK_SIGNAL_FUNC(drag_data_get_cb), NULL);
+    gtk_signal_connect(GTK_OBJECT(clist), "drag_begin",
+		       GTK_SIGNAL_FUNC(drag_begin_cb), NULL);
     gtk_signal_connect(GTK_OBJECT(clist), "select_row", 
 		       GTK_SIGNAL_FUNC(select_row_cb), NULL);
 


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