From 3c19eea34b192ac4a4a8bf22506cf29360cc0c2f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 24 Sep 2010 11:13:30 -0400 Subject: [PATCH] GtkNotebook: replace group by group_name Dealing with bare pointers is problematic for language bindings, using interned strings is much more straightforward and more than good enough for what is needed here. http://bugzilla.gnome.org/show_bug.cgi?id=630521 --- docs/reference/gtk/gtk3-sections.txt | 4 +- gtk/gtk.symbols | 4 +- gtk/gtknotebook.c | 87 ++++++++++++++-------------- gtk/gtknotebook.h | 6 +- tests/testnotebookdnd.c | 12 ++-- 5 files changed, 57 insertions(+), 56 deletions(-) diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt index c739b3cef4..3e074882a7 100644 --- a/docs/reference/gtk/gtk3-sections.txt +++ b/docs/reference/gtk/gtk3-sections.txt @@ -2222,8 +2222,8 @@ gtk_notebook_get_tab_detachable gtk_notebook_get_tab_hborder gtk_notebook_get_tab_vborder gtk_notebook_set_current_page -gtk_notebook_set_group -gtk_notebook_get_group +gtk_notebook_set_group_name +gtk_notebook_get_group_name gtk_notebook_set_action_widget gtk_notebook_get_action_widget diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index bf535584e0..dd5b1df1ab 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -2066,8 +2066,8 @@ gtk_notebook_set_tab_label_text gtk_notebook_set_tab_pos gtk_notebook_get_tab_hborder gtk_notebook_get_tab_vborder -gtk_notebook_get_group -gtk_notebook_set_group +gtk_notebook_get_group_name +gtk_notebook_set_group_name gtk_notebook_get_tab_reorderable gtk_notebook_set_tab_reorderable gtk_notebook_get_tab_detachable diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c index f696906dea..ec62d458f5 100644 --- a/gtk/gtknotebook.c +++ b/gtk/gtknotebook.c @@ -94,7 +94,7 @@ struct _GtkNotebookPrivate gint mouse_y; gint pressed_button; - gpointer group; + GQuark group; guint dnd_timer; guint switch_tab_timer; @@ -173,7 +173,7 @@ enum { PROP_SCROLLABLE, PROP_PAGE, PROP_ENABLE_POPUP, - PROP_GROUP, + PROP_GROUP_NAME }; enum { @@ -639,18 +639,17 @@ gtk_notebook_class_init (GtkNotebookClass *class) GTK_PARAM_READWRITE)); /** - * GtkNotebook:group: - * - * Group for tabs drag and drop. + * GtkNotebook:group-name: * - * Since: 2.12 - */ + * Group name for tab drag and drop. + */ g_object_class_install_property (gobject_class, - PROP_GROUP, - g_param_spec_pointer ("group", - P_("Group"), - P_("Group for tabs drag and drop"), - GTK_PARAM_READWRITE)); + PROP_GROUP_NAME, + g_param_spec_string ("group-name", + P_("Group Name"), + P_("Group name for tab drag and drop"), + NULL, + GTK_PARAM_READWRITE)); gtk_container_class_install_child_property (container_class, CHILD_PROP_TAB_LABEL, @@ -1073,7 +1072,7 @@ gtk_notebook_init (GtkNotebook *notebook) priv->has_after_previous = 0; priv->has_after_next = 1; - priv->group = NULL; + priv->group = 0; priv->pressed_button = -1; priv->dnd_timer = 0; priv->switch_tab_timer = 0; @@ -1517,8 +1516,8 @@ gtk_notebook_set_property (GObject *object, case PROP_TAB_POS: gtk_notebook_set_tab_pos (notebook, g_value_get_enum (value)); break; - case PROP_GROUP: - gtk_notebook_set_group (notebook, g_value_get_pointer (value)); + case PROP_GROUP_NAME: + gtk_notebook_set_group_name (notebook, g_value_get_string (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -1555,8 +1554,8 @@ gtk_notebook_get_property (GObject *object, case PROP_TAB_POS: g_value_set_enum (value, priv->tab_pos); break; - case PROP_GROUP: - g_value_set_pointer (value, priv->group); + case PROP_GROUP_NAME: + g_value_set_string (value, gtk_notebook_get_group_name (notebook)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -3451,19 +3450,19 @@ gtk_notebook_drag_motion (GtkWidget *widget, if (target == tab_target) { - gpointer widget_group, source_widget_group; - GtkWidget *source_widget; + GQuark group, source_group; + GtkNotebook *source; + GtkWidget *source_child; - source_widget = gtk_drag_get_source_widget (context); - g_assert (source_widget); + source = GTK_NOTEBOOK (gtk_drag_get_source_widget (context)); + source_child = source->priv->cur_page->child; - widget_group = gtk_notebook_get_group (notebook); - source_widget_group = gtk_notebook_get_group (GTK_NOTEBOOK (source_widget)); + group = notebook->priv->group; + source_group = source->priv->group; - if (widget_group && source_widget_group && - widget_group == source_widget_group && - !(widget == GTK_NOTEBOOK (source_widget)->priv->cur_page->child || - gtk_widget_is_ancestor (widget, GTK_NOTEBOOK (source_widget)->priv->cur_page->child))) + if (group != 0 && group == source_group && + !(widget == source_child || + gtk_widget_is_ancestor (widget, source_child))) { gdk_drag_status (context, GDK_ACTION_MOVE, time); return TRUE; @@ -7585,51 +7584,53 @@ gtk_notebook_reorder_child (GtkNotebook *notebook, } /** - * gtk_notebook_set_group: + * gtk_notebook_set_group_name: * @notebook: a #GtkNotebook - * @group: (allow-none): a pointer to identify the notebook group, or %NULL to unset it + * @name: (allow-none): the name of the notebook group, or %NULL to unset it * - * Sets a group identificator pointer for @notebook, notebooks sharing - * the same group identificator pointer will be able to exchange tabs - * via drag and drop. A notebook with a %NULL group identificator will + * Sets a group name for @notebook. + * + * Notebooks with the same name will be able to exchange tabs + * via drag and drop. A notebook with a %NULL group name will * not be able to exchange tabs with any other notebook. - * - * Since: 2.12 */ void -gtk_notebook_set_group (GtkNotebook *notebook, - gpointer group) +gtk_notebook_set_group_name (GtkNotebook *notebook, + const gchar *group_name) { GtkNotebookPrivate *priv; + GQuark *group; g_return_if_fail (GTK_IS_NOTEBOOK (notebook)); priv = notebook->priv; + group = g_quark_from_string (group_name); + if (priv->group != group) { priv->group = group; - g_object_notify (G_OBJECT (notebook), "group"); + g_object_notify (G_OBJECT (notebook), "group-name"); } } /** - * gtk_notebook_get_group: + * gtk_notebook_get_group_name: * @notebook: a #GtkNotebook * - * Gets the current group identificator pointer for @notebook. + * Gets the current group name for @notebook. * - * Return Value: (transfer none): the group identificator, + * Return Value: (transfer none): the group name, * or %NULL if none is set. * * Since: 2.12 **/ -gpointer -gtk_notebook_get_group (GtkNotebook *notebook) +const gchar * +gtk_notebook_get_group_name (GtkNotebook *notebook) { g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL); - return notebook->priv->group; + return g_quark_to_string (notebook->priv->group); } /** diff --git a/gtk/gtknotebook.h b/gtk/gtknotebook.h index efbb6274db..553a4840d9 100644 --- a/gtk/gtknotebook.h +++ b/gtk/gtknotebook.h @@ -136,9 +136,9 @@ void gtk_notebook_remove_page (GtkNotebook *notebook, * Tabs drag and drop * ***********************************************************/ -void gtk_notebook_set_group (GtkNotebook *notebook, - gpointer group); -gpointer gtk_notebook_get_group (GtkNotebook *notebook); +void gtk_notebook_set_group_name (GtkNotebook *notebook, + const gchar *group_name); +const gchar *gtk_notebook_get_group_name (GtkNotebook *notebook); diff --git a/tests/testnotebookdnd.c b/tests/testnotebookdnd.c index 04a4aef5dc..6c760dbae6 100644 --- a/tests/testnotebookdnd.c +++ b/tests/testnotebookdnd.c @@ -79,8 +79,8 @@ window_creation_function (GtkNotebook *source_notebook, window = gtk_window_new (GTK_WINDOW_TOPLEVEL); notebook = gtk_notebook_new (); - gtk_notebook_set_group (GTK_NOTEBOOK (notebook), - gtk_notebook_get_group (source_notebook)); + gtk_notebook_set_group_name (GTK_NOTEBOOK (notebook), + gtk_notebook_get_group_name (source_notebook)); gtk_container_add (GTK_CONTAINER (window), notebook); @@ -142,7 +142,7 @@ on_button_drag_data_received (GtkWidget *widget, static GtkWidget* create_notebook (gchar **labels, - gpointer group, + const gchar *group, gint packing, GtkPositionType pos) { @@ -154,7 +154,7 @@ create_notebook (gchar **labels, gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), pos); gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE); gtk_container_set_border_width (GTK_CONTAINER (notebook), 6); - gtk_notebook_set_group (GTK_NOTEBOOK (notebook), group); + gtk_notebook_set_group_name (GTK_NOTEBOOK (notebook), group); while (*labels) { @@ -184,7 +184,7 @@ create_notebook (gchar **labels, static GtkWidget* create_notebook_with_notebooks (gchar **labels, - gpointer group, + const gchar *group, gint packing, GtkPositionType pos) { @@ -196,7 +196,7 @@ create_notebook_with_notebooks (gchar **labels, gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), pos); gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE); gtk_container_set_border_width (GTK_CONTAINER (notebook), 6); - gtk_notebook_set_group (GTK_NOTEBOOK (notebook), group); + gtk_notebook_set_group_name (GTK_NOTEBOOK (notebook), group); while (*labels) {