[kazehakase-svn] [3245] 2007-10-03 Hiroyuki Ikezoe <poinc****@ikezo*****>

Back to archive index

svnno****@sourc***** svnno****@sourc*****
Wed Oct 3 10:41:16 JST 2007


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

Log Message:
-----------
2007-10-03  Hiroyuki Ikezoe  <poinc****@ikezo*****>

	* src/kz-notebook.c, src/kz-tab-label.c: Use DnD function of
	GtkNotebook itself.

Modified Paths:
--------------
    kazehakase/trunk/ChangeLog
    kazehakase/trunk/src/kz-notebook.c
    kazehakase/trunk/src/kz-tab-label.c

Modified: kazehakase/trunk/ChangeLog
===================================================================
--- kazehakase/trunk/ChangeLog	2007-09-29 05:24:22 UTC (rev 3244)
+++ kazehakase/trunk/ChangeLog	2007-10-03 01:41:15 UTC (rev 3245)
@@ -1,3 +1,8 @@
+2007-10-03  Hiroyuki Ikezoe  <poinc****@ikezo*****>
+
+	* src/kz-notebook.c, src/kz-tab-label.c: Use DnD function of
+	GtkNotebook itself.
+
 2007-09-29  Kouhei Sutou  <kou****@cozmi*****>
 
 	* Makefile.am: added tag target. (not tested)

Modified: kazehakase/trunk/src/kz-notebook.c
===================================================================
--- kazehakase/trunk/src/kz-notebook.c	2007-09-29 05:24:22 UTC (rev 3244)
+++ kazehakase/trunk/src/kz-notebook.c	2007-10-03 01:41:15 UTC (rev 3245)
@@ -33,7 +33,7 @@
 };
 
 enum {
-	TARGET_KAZEHAKASE_TAB,
+	TARGET_GTK_NOTEBOOK_TAB,
 	TARGET_NETSCAPE_URL,
 	TARGET_TEXT_URI_LIST,
 	TARGET_TEXT_PLAIN,
@@ -42,11 +42,11 @@
 
 static GtkTargetEntry url_drag_types [] =
 {
-        { "_KAZEHAKASE_TAB", 0, TARGET_KAZEHAKASE_TAB},
-        { "_NETSCAPE_URL",   0, TARGET_NETSCAPE_URL},
-	{ "text/uri-list",   0, TARGET_TEXT_URI_LIST},
-	{ "text/plain",      0, TARGET_TEXT_PLAIN},
-	{ "STRING",          0, TARGET_STRING}
+        { "GTK_NOTEBOOK_TAB", GTK_TARGET_OTHER_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;
@@ -86,6 +86,11 @@
 			      GtkNotebookPage *page,
 			      guint 	   page_num);
 
+static void	cb_page_reordered (GtkNotebook *notebook,
+				   GtkWidget   *child,
+				   guint        page_num,
+				   gpointer     data);
+
 G_DEFINE_TYPE (KzNotebook, kz_notebook, GTK_TYPE_NOTEBOOK)
 
 static void
@@ -136,6 +141,8 @@
 			  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);
 }
 
 
@@ -240,40 +247,19 @@
                     guint time)
 {
 	KzWindow *kz;
-	g_return_if_fail(KZ_IS_WINDOW(widget));
+	g_return_if_fail(KZ_IS_NOTEBOOK(widget));
 
 	kz = KZ_NOTEBOOK_GET_PRIVATE(widget)->kz;
 	switch (info)
 	{
-	case TARGET_KAZEHAKASE_TAB:
+	case TARGET_GTK_NOTEBOOK_TAB:
 	{
-		GtkWidget *src_widget;
-		KzWindow *src_kz;
-		KzTabLabel *src_kztab;
+		GtkWidget *src_notebook;
+		GtkWidget **child;
 
-		src_widget = gtk_drag_get_source_widget(context);
-
-		if (!KZ_IS_TAB_LABEL(src_widget)) return;
-		src_kztab = KZ_TAB_LABEL(src_widget);
-
-		src_kz = KZ_WINDOW(KZ_GET_WINDOW_FROM_TAB(GTK_WIDGET(src_kztab->kzembed)));
-		if (kz == src_kz)
-		{
-			gint n;
-
-			n = gtk_notebook_get_n_pages(GTK_NOTEBOOK(kz->notebook));
-			kz_window_reorder_tab(kz, GTK_WIDGET(src_kztab->kzembed),
-					      n - 1);
-			kz_actions_set_sensitive
-				(kz, KZ_EMBED(KZ_WINDOW_CURRENT_PAGE(kz)));
-			kz_actions_set_tab_sensitive
-				(kz, KZ_EMBED(KZ_WINDOW_CURRENT_PAGE(kz)));
-		}
-		else
-		{
-			kz_window_move_tab(kz, GTK_WIDGET(src_kztab->kzembed));
-		}
-
+		src_notebook = gtk_drag_get_source_widget(context);
+		child = (void*) data->data;
+		gtk_container_remove(GTK_CONTAINER(src_notebook), *child);
 		break;
 	}
 
@@ -354,6 +340,32 @@
 		GTK_NOTEBOOK_CLASS(kz_notebook_parent_class)->switch_page(notebook, page, page_num);
 }
 
+static void
+cb_page_reordered (GtkNotebook *notebook,
+		   GtkWidget   *child,
+		   guint        page_num,
+		   gpointer     data)
+{
+	KzTabLabel *kztab, *sibtab = NULL;
+	KzBookmark *sib_bookmark = NULL;
+	GtkWidget *sibchild = NULL;
+	KzWindow *kz = KZ_NOTEBOOK_GET_PRIVATE(notebook)->kz;
+
+	sibchild = gtk_notebook_get_nth_page(notebook, page_num + 1);
+	if (sibchild)
+		sibtab = KZ_TAB_LABEL(gtk_notebook_get_tab_label(notebook, sibchild));
+	if (sibtab)
+		sib_bookmark = sibtab->history;
+
+	kztab = KZ_TAB_LABEL(gtk_notebook_get_tab_label(notebook, child));
+	g_object_ref(kztab->history);
+	kz_bookmark_remove(kz->tabs, kztab->history);
+	kz_bookmark_insert_before(kz->tabs, 
+				  kztab->history,
+				  sib_bookmark);
+	g_object_unref(kztab->history);
+}
+
 static gint 
 get_insert_tab_position (KzNotebook *notebook)
 {
@@ -420,6 +432,9 @@
 						GTK_WIDGET(embed),
 						GTK_WIDGET(label),
 						pos);
+	gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(notebook), GTK_WIDGET(embed), TRUE);
+	gtk_notebook_set_tab_detachable(GTK_NOTEBOOK(notebook), GTK_WIDGET(embed), TRUE);
+
 	/* add to this notebook's history */
 	priv->open_hist = g_list_prepend(priv->open_hist, embed);
 

Modified: kazehakase/trunk/src/kz-tab-label.c
===================================================================
--- kazehakase/trunk/src/kz-tab-label.c	2007-09-29 05:24:22 UTC (rev 3244)
+++ kazehakase/trunk/src/kz-tab-label.c	2007-10-03 01:41:15 UTC (rev 3245)
@@ -78,22 +78,10 @@
 static void     realize        (GtkWidget        *widget);
 static gboolean button_press   (GtkWidget        *widget,
                                 GdkEventButton   *event);
-static gboolean motion_notify  (GtkWidget        *widget,
-                                GdkEventMotion   *event);
 static gboolean button_release (GtkWidget        *widget,
                                 GdkEventButton   *event);
 static gboolean scroll_event   (GtkWidget        *widget,
                                 GdkEventScroll   *event);
-static gboolean drag_motion    (GtkWidget        *widget,
-                                GdkDragContext   *drag_context,
-		   		gint              x,
-                                gint              y,
-		   		guint             time);
-static void     drag_data_get  (GtkWidget        *widget,
-                                GdkDragContext   *context,
-                                GtkSelectionData *seldata,
-                                guint             info,
-                                guint             time);
 static void     drag_data_received (GtkWidget        *widget,
                                     GdkDragContext   *drag_context,
                                     gint              x, 
@@ -103,8 +91,6 @@
                                     guint             time);
 
 static void     kz_tab_label_sync_to_profile    (KzTabLabel *kztab);
-static void     kz_tab_label_move_page          (KzTabLabel *kztab,
-						 KzTabLabel *dest_kztab);
 
 static void	kz_tab_label_set_visited        (KzTabLabel *kztab);
 
@@ -128,7 +114,6 @@
 static void make_progress_circle (GtkWidget *widget);
 
 enum {
-	TARGET_KAZEHAKASE_TAB,
 	TARGET_NETSCAPE_URL,
 	TARGET_TEXT_URI_LIST,
 	TARGET_TEXT_PLAIN,
@@ -137,7 +122,6 @@
 
 static GtkTargetEntry url_drag_types [] = 
 {
-        { "_KAZEHAKASE_TAB", 0, TARGET_KAZEHAKASE_TAB},
         { "_NETSCAPE_URL",   0, TARGET_NETSCAPE_URL},
 	{ "text/uri-list",   0, TARGET_TEXT_URI_LIST},
 	{ "text/plain",      0, TARGET_TEXT_PLAIN},
@@ -169,11 +153,9 @@
 	widget_class->button_press_event   = button_press;
 	widget_class->button_release_event = button_release;
 	widget_class->scroll_event         = scroll_event;
-	widget_class->motion_notify_event  = motion_notify;
-	widget_class->drag_motion          = drag_motion;
-	widget_class->drag_data_get        = drag_data_get;
+#if 1
 	widget_class->drag_data_received   = drag_data_received;
-
+#endif
 	g_object_class_install_property
 		(gobject_class,
 		 PROP_KZ_WINDOW,
@@ -284,21 +266,14 @@
 			   FALSE, FALSE, 0);
 
 	gtk_widget_show (kztab->close_button);
-
-	gtk_drag_source_set(GTK_WIDGET(kztab),
-			    GDK_BUTTON1_MASK |
-			    GDK_BUTTON2_MASK |
-			    GDK_BUTTON3_MASK,
-			    url_drag_types, n_url_drag_types,
-			    GDK_ACTION_ASK  | GDK_ACTION_COPY
-			    | GDK_ACTION_MOVE | GDK_ACTION_LINK);
+#if 1
 	gtk_drag_dest_set(GTK_WIDGET(kztab), 
 			  GTK_DEST_DEFAULT_HIGHLIGHT |
 			  GTK_DEST_DEFAULT_MOTION | 
 			  GTK_DEST_DEFAULT_DROP,
                           url_drag_types,n_url_drag_types,
 			  GDK_ACTION_MOVE);
-
+#endif
 	g_signal_connect(KZ_GET_GLOBAL_PROFILE, "changed::Tab",
 			 G_CALLBACK(cb_profile_changed), kztab);
 	kz_tab_label_sync_to_profile(kztab);
@@ -668,23 +643,6 @@
 }
 
 static gboolean
-motion_notify (GtkWidget *widget, GdkEventMotion *event)
-{
-	KzTabLabel *kztab = KZ_TAB_LABEL(widget);
-	KzTabLabelPrivate *priv = KZ_TAB_LABEL_GET_PRIVATE (kztab);
-
-	if (abs(event->x - priv->start_x) > 2 ||
-	    abs(event->y - priv->start_y) > 2)
-	{
-		priv->moved = TRUE;
-	}
-
-	if (GTK_WIDGET_CLASS(kz_tab_label_parent_class)->motion_notify_event)
-		return GTK_WIDGET_CLASS(kz_tab_label_parent_class)->motion_notify_event(widget, event);
-	return FALSE;
-}
-
-static gboolean
 button_release (GtkWidget *widget, GdkEventButton *event)
 {
 	KzTabLabel *kztab = KZ_TAB_LABEL(widget);
@@ -730,108 +688,7 @@
 }
 
 
-static gboolean
-drag_motion (GtkWidget *widget,
-             GdkDragContext *drag_context,
-             gint x, gint y,
-             guint time)
-{
-	KzTabLabel *kztab;
-	KzEmbed *current_kzembed;
-	gint page_num;
-
-	kztab = KZ_TAB_LABEL(widget);
-
-	g_return_val_if_fail (KZ_IS_EMBED(kztab->kzembed), FALSE);
-
-	current_kzembed = KZ_EMBED(KZ_WINDOW_CURRENT_PAGE(kztab->kz));
-
-	if (KZ_EMBED(kztab->kzembed) == current_kzembed)
-		return FALSE;
-
-	page_num = kz_notebook_page_num(KZ_NOTEBOOK(kztab->kz->notebook),
-					GTK_WIDGET(kztab->kzembed));
-	kz_notebook_set_current_page(KZ_NOTEBOOK(kztab->kz->notebook), page_num);
-
-	return FALSE;
-}
-
 static void
-drag_data_get (GtkWidget        *widget,
-               GdkDragContext   *context,
-               GtkSelectionData *data,
-               guint             info,
-               guint             time)
-{
-	KzTabLabel *kztab;
-	const gchar *uri, *title;
-
-	kztab = KZ_TAB_LABEL(widget);
-
-	g_return_if_fail (KZ_IS_EMBED(kztab->kzembed));
-
-	uri   = kz_embed_get_location(kztab->kzembed);
-	title = kz_embed_get_title(kztab->kzembed);
-
-	if (!uri || !*uri) return;
-
-	switch (info)
-	{
-	case TARGET_KAZEHAKASE_TAB:
-		gtk_selection_data_set(data, data->target,
-				       8, (const guchar*)"dummy", strlen("dummy"));
-		break;
-	case TARGET_NETSCAPE_URL:
-	{
-		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(data, data->target,
-				       8, (const guchar*)str, strlen(str));
-		g_free(str);
-		break;
-	}
-	case TARGET_TEXT_URI_LIST:
-	case TARGET_TEXT_PLAIN:
-	case TARGET_STRING:
-		gtk_selection_data_set(data, data->target,
-				       8, (const guchar*)uri, strlen(uri));
-		break;
-	default:
-		break;
-	}
-}
-
-static void
 drag_data_received (GtkWidget *widget,
                     GdkDragContext *drag_context,
                     gint x, gint y,
@@ -847,18 +704,6 @@
 
 	switch (info)
 	{
-	case TARGET_KAZEHAKASE_TAB:
-	{
-		GtkWidget *src_widget = gtk_drag_get_source_widget(drag_context);
-		KzTabLabel *src_kztab;
-
-		if (!KZ_IS_TAB_LABEL(src_widget)) return;
-		src_kztab = KZ_TAB_LABEL(src_widget);
-
-		kz_tab_label_move_page(src_kztab, kztab);
-		return;
-	}
-
 	case TARGET_NETSCAPE_URL:
 	case TARGET_TEXT_URI_LIST:
 	case TARGET_TEXT_PLAIN:
@@ -937,35 +782,7 @@
 	g_free(color);
 }
 
-/* move kztab to dest_kztab's position */
 static void
-kz_tab_label_move_page(KzTabLabel *kztab, KzTabLabel *dest_kztab)
-{
-	GtkWidget *src_page;
-	KzNotebook *notebook;
-	gint dest_pos;
-
-	g_return_if_fail(dest_kztab->kz && dest_kztab->kzembed);
-	g_return_if_fail(kztab->kz && kztab->kzembed);
-
-	notebook = KZ_NOTEBOOK(dest_kztab->kz->notebook);
-	dest_pos = kz_notebook_page_num(notebook,
-					GTK_WIDGET(dest_kztab->kzembed));
-
-	src_page = GTK_WIDGET(kztab->kzembed);
-	if (dest_kztab->kz != kztab->kz)
-		kz_window_move_tab(dest_kztab->kz, src_page);
-	
-	kz_window_reorder_tab(dest_kztab->kz, src_page, dest_pos);
-	kz_actions_set_sensitive
-		(kztab->kz, KZ_EMBED(KZ_WINDOW_CURRENT_PAGE(kztab->kz)));
-
-	if (dest_kztab->kz != kztab->kz)
-		gtk_widget_destroy(GTK_WIDGET(kztab));
-}
-
-
-static void
 make_progress_circle(GtkWidget *widget)
 {
 	GdkGC *gc;




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