[kazehakase-svn] [3253] * src/kz-notebook.c, src/bookmarks/kz-bookmark-bar. c: Workaround for

Back to archive index

svnno****@sourc***** svnno****@sourc*****
Wed Oct 3 15:50:39 JST 2007


Revision: 3253
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=kazehakase&view=rev&rev=3253
Author:   ikezoe
Date:     2007-10-03 15:50:39 +0900 (Wed, 03 Oct 2007)

Log Message:
-----------
* src/kz-notebook.c, src/bookmarks/kz-bookmark-bar.c: Workaround for
obtaining URI of dropped tab label from GtkNotebook.

Modified Paths:
--------------
    kazehakase/trunk/ChangeLog
    kazehakase/trunk/src/bookmarks/kz-bookmark-bar.c
    kazehakase/trunk/src/kz-notebook.c

Modified: kazehakase/trunk/ChangeLog
===================================================================
--- kazehakase/trunk/ChangeLog	2007-10-03 03:36:40 UTC (rev 3252)
+++ kazehakase/trunk/ChangeLog	2007-10-03 06:50:39 UTC (rev 3253)
@@ -12,6 +12,8 @@
 	* src/utils/kz-base64.[ch]: Removed.
 	* src/net/kz-http.c: Use g_base64_encode() instead of
 	kz_base64_encode().
+	* src/kz-notebook.c, src/bookmarks/kz-bookmark-bar.c: Workaround for
+	obtaining URI of dropped tab label from GtkNotebook.
 
 2007-09-29  Kouhei Sutou  <kou****@cozmi*****>
 

Modified: kazehakase/trunk/src/bookmarks/kz-bookmark-bar.c
===================================================================
--- kazehakase/trunk/src/bookmarks/kz-bookmark-bar.c	2007-10-03 03:36:40 UTC (rev 3252)
+++ kazehakase/trunk/src/bookmarks/kz-bookmark-bar.c	2007-10-03 06:50:39 UTC (rev 3253)
@@ -53,6 +53,7 @@
 };
 
 enum {
+	TARGET_GTK_NOTEBOOK_TAB,
 	TARGET_KAZEHAKASE_BOOKMARKS,
 	TARGET_NETSCAPE_URL,
 	TARGET_TEXT_URI_LIST
@@ -60,6 +61,7 @@
 
 static GtkTargetEntry url_drag_types [] = 
 {
+	{"GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, TARGET_GTK_NOTEBOOK_TAB},
 	{"_KAZEHAKASE_BOOKMARKS", 0, TARGET_KAZEHAKASE_BOOKMARKS},
         { "_NETSCAPE_URL",        0, TARGET_NETSCAPE_URL},
 	{ "text/uri-list",        0, TARGET_TEXT_URI_LIST}
@@ -441,6 +443,7 @@
 	 	break;
 	 case TARGET_NETSCAPE_URL:
 	 case TARGET_TEXT_URI_LIST:
+	 case TARGET_GTK_NOTEBOOK_TAB:
 		if (data->length < 0) return;
 		strings = g_strsplit((const gchar*)data->data, "\n", 2);
 		if (!strings) return;

Modified: kazehakase/trunk/src/kz-notebook.c
===================================================================
--- kazehakase/trunk/src/kz-notebook.c	2007-10-03 03:36:40 UTC (rev 3252)
+++ kazehakase/trunk/src/kz-notebook.c	2007-10-03 06:50:39 UTC (rev 3253)
@@ -32,23 +32,6 @@
 	PROP_KZ_WINDOW
 };
 
-enum {
-	TARGET_GTK_NOTEBOOK_TAB,
-	TARGET_NETSCAPE_URL,
-	TARGET_TEXT_URI_LIST,
-	TARGET_TEXT_PLAIN,
-	TARGET_STRING
-};
-
-static GtkTargetEntry url_drag_types [] =
-{
-        { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP,  TARGET_GTK_NOTEBOOK_TAB},
-        { "_NETSCAPE_URL",    GTK_TARGET_OTHER_APP, TARGET_NETSCAPE_URL},
-	{ "text/uri-list",    GTK_TARGET_OTHER_APP, TARGET_TEXT_URI_LIST},
-	{ "text/plain",       GTK_TARGET_OTHER_APP, TARGET_TEXT_PLAIN},
-	{ "STRING",           GTK_TARGET_OTHER_APP, TARGET_STRING}
-};
-
 typedef struct _KzNotebookPrivate	KzNotebookPrivate;
 struct _KzNotebookPrivate
 {
@@ -57,6 +40,8 @@
 	/* tabs */
 	GList *open_hist;
 	GList *view_hist;
+
+	GtkWidget *dragged_page;
 };
 
 #define KZ_NOTEBOOK_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), KZ_TYPE_NOTEBOOK, KzNotebookPrivate))
@@ -74,6 +59,15 @@
 static gboolean scroll_event (GtkWidget       *widget,
 			      GdkEventScroll  *event);
 
+static void	drag_begin    (GtkWidget *widget,
+			       GdkDragContext *context);
+static void	drag_end      (GtkWidget *widget,
+			       GdkDragContext *context);
+static void	drag_data_get (GtkWidget *widget,
+			       GdkDragContext *context,
+			       GtkSelectionData *seldata,
+			       guint info,
+			       guint time);
 static void     drag_data_received
 			     (GtkWidget *widget,
 			      GdkDragContext *context,
@@ -110,6 +104,9 @@
 	gobject_class->get_property = get_property;
 
 	widget_class->scroll_event       = scroll_event;
+	widget_class->drag_begin         = drag_begin;
+	widget_class->drag_end           = drag_end;
+	widget_class->drag_data_get      = drag_data_get;
 	widget_class->drag_data_received = drag_data_received;
 
 	notebook_class->switch_page = switch_page;
@@ -127,7 +124,6 @@
 	g_type_class_add_private (gobject_class, sizeof(KzNotebookPrivate));
 }
 
-
 static void
 kz_notebook_init (KzNotebook *notebook)
 {
@@ -136,11 +132,8 @@
 	priv->kz        = NULL;
 	priv->open_hist = NULL;
 	priv->view_hist = NULL;
+	priv->dragged_page = NULL;
 
-	gtk_drag_dest_set(GTK_WIDGET(notebook),
-			  GTK_DEST_DEFAULT_ALL,
-			  url_drag_types, G_N_ELEMENTS(url_drag_types),
-			  GDK_ACTION_MOVE);
 	g_signal_connect(notebook, "page-reordered", 
 			 G_CALLBACK(cb_page_reordered), NULL);
 }
@@ -216,6 +209,11 @@
 		g_list_free(priv->view_hist);
 		priv->view_hist = NULL;
 	}
+	if (priv->dragged_page)
+	{
+		g_object_unref(priv->dragged_page);
+		priv->dragged_page = NULL;
+	}
 
 	if (G_OBJECT_CLASS(kz_notebook_parent_class)->dispose)
 		G_OBJECT_CLASS(kz_notebook_parent_class)->dispose(object);
@@ -239,52 +237,117 @@
 }
 
 static void
+drag_begin (GtkWidget *widget, GdkDragContext *context)
+{
+	gint current_page_num;
+	GtkWidget *current_page;
+	KzNotebookPrivate *priv = KZ_NOTEBOOK_GET_PRIVATE(widget);
+
+	current_page_num = gtk_notebook_get_current_page(GTK_NOTEBOOK(widget));
+
+	if (current_page_num < 0)
+		return;
+
+	current_page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(widget), current_page_num);
+	if (current_page)
+		priv->dragged_page = g_object_ref(current_page);
+
+	if (GTK_WIDGET_CLASS(kz_notebook_parent_class)->drag_begin)
+		GTK_WIDGET_CLASS(kz_notebook_parent_class)->drag_begin(widget, context);
+}
+
+static void
+drag_end (GtkWidget *widget, GdkDragContext *context)
+{
+	KzNotebookPrivate *priv = KZ_NOTEBOOK_GET_PRIVATE(widget);
+
+	if (priv->dragged_page)
+		g_object_unref(priv->dragged_page);
+	priv->dragged_page = NULL;
+
+	if (GTK_WIDGET_CLASS(kz_notebook_parent_class)->drag_end)
+		GTK_WIDGET_CLASS(kz_notebook_parent_class)->drag_end(widget, context);
+}
+
+static void
+drag_data_get (GtkWidget *widget,
+	       GdkDragContext *context,
+	       GtkSelectionData *seldata,
+	       guint info,
+	       guint time)
+{
+	KzEmbed *kzembed;
+	const gchar *uri, *title;
+	KzNotebookPrivate *priv = KZ_NOTEBOOK_GET_PRIVATE(widget);
+
+	if (!priv->dragged_page)
+		return;
+
+	g_return_if_fail (KZ_IS_EMBED(priv->dragged_page));
+
+	kzembed = KZ_EMBED(priv->dragged_page);
+	uri   = kz_embed_get_location(kzembed);
+	title = kz_embed_get_title(kzembed);
+	if (!uri || !*uri) return;
+
+	if (seldata->target == gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB"))
+	{
+		gchar *str;
+		if (title && *title)
+		{
+			gchar *title_locale;
+			gsize bytes_read, bytes_written;
+			GError *error = NULL;
+
+			title_locale = g_locale_from_utf8(title, -1,
+					&bytes_read,
+					&bytes_written,
+					&error);
+			if (error)
+			{
+				g_warning("kz_tab_label_drag_data_get(): %s",
+						error->message);
+				g_error_free(error);
+			}
+			if (title_locale && *title_locale)
+			{
+				str = g_strconcat(uri, "\n", title_locale,
+						NULL);
+				g_free(title_locale);
+			}
+			else
+			{
+				str = g_strdup (uri);
+			}
+		}
+		else
+		{
+			str = g_strdup (uri);
+		}
+		gtk_selection_data_set(seldata, seldata->target,
+				8, (const guchar*)str, strlen(str));
+		g_free(str);
+	}
+}
+
+
+static void
 drag_data_received (GtkWidget *widget,
                     GdkDragContext *context,
                     gint x, gint y,
-                    GtkSelectionData *data,
+                    GtkSelectionData *seldata,
                     guint info,
                     guint time)
 {
-	KzWindow *kz;
-	g_return_if_fail(KZ_IS_NOTEBOOK(widget));
-
-	kz = KZ_NOTEBOOK_GET_PRIVATE(widget)->kz;
-	switch (info)
+	if (seldata->target == gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB"))
 	{
-	case TARGET_GTK_NOTEBOOK_TAB:
-	{
 		GtkWidget *src_notebook;
 		GtkWidget **child;
 
 		src_notebook = gtk_drag_get_source_widget(context);
-		child = (void*) data->data;
+		child = (void*) seldata->data;
 		gtk_container_remove(GTK_CONTAINER(src_notebook), *child);
-		break;
 	}
-
-	case TARGET_NETSCAPE_URL:
-	case TARGET_TEXT_URI_LIST:
-	case TARGET_TEXT_PLAIN:
-	case TARGET_STRING:
-	{
-		gchar *string, **strings;
-
-		if (data->length < 0) return;
-		string = g_alloca (data->length + 1);
-
-		memcpy (string, data->data, data->length);
-		string[data->length] = '\0';
-
-		strings = g_strsplit(string, "\n", 2);
-		kz_window_open_new_tab(kz, strings[0]);
-		g_strfreev(strings);
-		break;
-
-	}
-	default:
-		break;
-	}
 }
 
 static gboolean




More information about the Kazehakase-cvs mailing list
Back to archive index