diff options
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | docs/reference/ChangeLog | 4 | ||||
-rw-r--r-- | docs/reference/gtk/gtk-sections.txt | 2 | ||||
-rw-r--r-- | gtk/gtk.symbols | 4 | ||||
-rw-r--r-- | gtk/gtknotebook.c | 97 | ||||
-rw-r--r-- | gtk/gtknotebook.h | 11 | ||||
-rw-r--r-- | tests/testnotebookdnd.c | 16 |
7 files changed, 118 insertions, 26 deletions
@@ -1,3 +1,13 @@ +2007-05-19 Matthias Clasen <mclasen@redhat.com> + + * gtk/gtk.symbols: + * gtk/gtknotebook.[hc]: Deprecate gtk_notebook_[gs]et_group_id + in favour of new functions gtk_notebook_[gs]et_group, which + takes a pointer as group identifier and makes it easier to + avoid group id collisions. (#386930, Christian Hammond) + + * tests/testnotebookdnd.c: Use new grouping api. + 2007-05-18 Matthias Clasen <mclasen@redhat.com> * gtk/gtkactiongroup.c: Warn and refuse to add actions with diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 9413dbe2ea..f1d033f80d 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,7 @@ +2007-05-19 Matthias Clasen <mclasen@redhat.com> + + * gtk/gtk-sections.txt: Add gtk_notebook_[gs]et_group + 2007-05-18 Matthias Clasen <mclasen@redhat.com> * gtk/gtk-sections.txt: Add gtk_entry_[gs]et_cursor_hadjustment. diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt index 30e367a4fe..1337eace1e 100644 --- a/docs/reference/gtk/gtk-sections.txt +++ b/docs/reference/gtk/gtk-sections.txt @@ -2415,6 +2415,8 @@ gtk_notebook_get_tab_detachable gtk_notebook_set_current_page gtk_notebook_set_group_id gtk_notebook_get_group_id +gtk_notebook_set_group +gtk_notebook_get_group GtkNotebookWindowCreationFunc gtk_notebook_set_window_creation_hook <SUBSECTION Standard> diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index ba34e5ab0a..86b985763b 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -2385,8 +2385,12 @@ gtk_notebook_set_tab_label_packing gtk_notebook_set_tab_label_text gtk_notebook_set_tab_pos gtk_notebook_set_window_creation_hook +#ifndef GTK_DISABLE_DEPRECATED gtk_notebook_get_group_id gtk_notebook_set_group_id +#endif +gtk_notebook_get_group +gtk_notebook_set_group 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 1f63bff41d..c79633cdab 100644 --- a/gtk/gtknotebook.c +++ b/gtk/gtknotebook.c @@ -102,6 +102,7 @@ enum { PROP_PAGE, PROP_ENABLE_POPUP, PROP_GROUP_ID, + PROP_GROUP, PROP_HOMOGENEOUS }; @@ -156,7 +157,7 @@ typedef struct _GtkNotebookPrivate GtkNotebookPrivate; struct _GtkNotebookPrivate { - gint group_id; + gpointer group; gint mouse_x; gint mouse_y; gint pressed_button; @@ -611,6 +612,12 @@ gtk_notebook_class_init (GtkNotebookClass *class) G_MAXINT, -1, GTK_PARAM_READWRITE)); + 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)); gtk_container_class_install_child_property (container_class, CHILD_PROP_TAB_LABEL, @@ -1000,7 +1007,7 @@ gtk_notebook_init (GtkNotebook *notebook) notebook->has_after_previous = 0; notebook->has_after_next = 1; - priv->group_id = -1; + priv->group = NULL; priv->pressed_button = -1; priv->dnd_timer = 0; priv->switch_tab_timer = 0; @@ -1410,6 +1417,9 @@ gtk_notebook_set_property (GObject *object, case PROP_GROUP_ID: gtk_notebook_set_group_id (notebook, g_value_get_int (value)); break; + case PROP_GROUP: + gtk_notebook_set_group (notebook, g_value_get_pointer (value)); + break; default: break; } @@ -1457,7 +1467,10 @@ gtk_notebook_get_property (GObject *object, g_value_set_uint (value, notebook->tab_vborder); break; case PROP_GROUP_ID: - g_value_set_int (value, priv->group_id); + g_value_set_int (value, gtk_notebook_get_group_id (notebook)); + break; + case PROP_GROUP: + g_value_set_pointer (value, priv->group); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -3145,9 +3158,10 @@ gtk_notebook_drag_failed (GtkWidget *widget, gdk_display_get_pointer (display, NULL, &x, &y, NULL); dest_notebook = (* window_creation_hook) (notebook, - priv->detached_tab->child, - x, y, - window_creation_hook_data); + priv->detached_tab->child, + x, y, + window_creation_hook_data); + if (dest_notebook) do_detach_tab (notebook, dest_notebook, priv->detached_tab->child, 0, 0); @@ -3217,17 +3231,16 @@ gtk_notebook_drag_motion (GtkWidget *widget, if (target == tab_target) { - gint widget_group, source_widget_group; + gpointer widget_group, source_widget_group; GtkWidget *source_widget; source_widget = gtk_drag_get_source_widget (context); g_assert (source_widget); - widget_group = gtk_notebook_get_group_id (notebook); - source_widget_group = gtk_notebook_get_group_id (GTK_NOTEBOOK (source_widget)); + widget_group = gtk_notebook_get_group (notebook); + source_widget_group = gtk_notebook_get_group (GTK_NOTEBOOK (source_widget)); - if (widget_group != -1 && - source_widget_group != -1 && + if (widget_group && source_widget_group && widget_group == source_widget_group && !(widget == GTK_NOTEBOOK (source_widget)->cur_page->child || gtk_widget_is_ancestor (widget, GTK_NOTEBOOK (source_widget)->cur_page->child))) @@ -7256,21 +7269,49 @@ gtk_notebook_set_window_creation_hook (GtkNotebookWindowCreationFunc func, * not be able to exchange tabs with any other notebook. * * Since: 2.10 - **/ + * Deprecated:2.12: use gtk_notebook_set_group() instead. + */ void gtk_notebook_set_group_id (GtkNotebook *notebook, gint group_id) { GtkNotebookPrivate *priv; + gpointer group; + + g_return_if_fail (GTK_IS_NOTEBOOK (notebook)); + + /* add 1 to get rid of the -1/NULL difference */ + group = GINT_TO_POINTER (group_id + 1); + gtk_notebook_set_group (notebook, group); +} + +/** + * gtk_notebook_set_group: + * @notebook: a #GtkNotebook + * @group_id: a pointer to identify 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 + * not be able to exchange tabs with any other notebook. + * + * Since: 2.12 + */ +void +gtk_notebook_set_group (GtkNotebook *notebook, + gpointer group) +{ + GtkNotebookPrivate *priv; g_return_if_fail (GTK_IS_NOTEBOOK (notebook)); priv = GTK_NOTEBOOK_GET_PRIVATE (notebook); - if (priv->group_id != group_id) + if (priv->group != group) { - priv->group_id = group_id; + priv->group = group; g_object_notify (G_OBJECT (notebook), "group-id"); + g_object_notify (G_OBJECT (notebook), "group"); } } @@ -7283,7 +7324,8 @@ gtk_notebook_set_group_id (GtkNotebook *notebook, * Return Value: the group identificator, or -1 if none is set. * * Since: 2.10 - **/ + * Deprecated:2.12: use gtk_notebook_get_group() instead. + */ gint gtk_notebook_get_group_id (GtkNotebook *notebook) { @@ -7292,7 +7334,30 @@ gtk_notebook_get_group_id (GtkNotebook *notebook) g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1); priv = GTK_NOTEBOOK_GET_PRIVATE (notebook); - return priv->group_id; + + /* substract 1 to get rid of the -1/NULL difference */ + return GPOINTER_TO_INT (priv->group - 1); +} + +/** + * gtk_notebook_get_group: + * @notebook: a #GtkNotebook + * + * Gets the current group identificator pointer for @notebook. + * + * Return Value: the group identificator, or %NULL if none is set. + * + * Since: 2.12 + **/ +gpointer +gtk_notebook_get_group (GtkNotebook *notebook) +{ + GtkNotebookPrivate *priv; + + g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL); + + priv = GTK_NOTEBOOK_GET_PRIVATE (notebook); + return priv->group; } /** diff --git a/gtk/gtknotebook.h b/gtk/gtknotebook.h index 55db1708c2..c5e648f1b2 100644 --- a/gtk/gtknotebook.h +++ b/gtk/gtknotebook.h @@ -165,12 +165,21 @@ void gtk_notebook_remove_page (GtkNotebook *notebook, void gtk_notebook_set_window_creation_hook (GtkNotebookWindowCreationFunc func, gpointer data, GDestroyNotify destroy); +#ifndef GTK_DISABLE_DEPRECATED void gtk_notebook_set_group_id (GtkNotebook *notebook, gint group_id); gint gtk_notebook_get_group_id (GtkNotebook *notebook); +#endif /* GTK_DISABLE_DEPRECATED */ + +void gtk_notebook_set_group (GtkNotebook *notebook, + gpointer group); +gpointer gtk_notebook_get_group (GtkNotebook *notebook); + + + /*********************************************************** - * query, set current NoteebookPage * + * query, set current NotebookPage * ***********************************************************/ gint gtk_notebook_get_current_page (GtkNotebook *notebook); diff --git a/tests/testnotebookdnd.c b/tests/testnotebookdnd.c index 233d9003ef..d8364455df 100644 --- a/tests/testnotebookdnd.c +++ b/tests/testnotebookdnd.c @@ -28,10 +28,8 @@ enum { PACK_ALTERNATE }; -enum { - GROUP_A, - GROUP_B -}; +static gpointer GROUP_A = "GROUP_A"; +static gpointer GROUP_B = "GROUP_B"; gchar *tabs1 [] = { "aaaaaaaaaa", @@ -144,7 +142,7 @@ on_button_drag_data_received (GtkWidget *widget, static GtkWidget* create_notebook (gchar **labels, - gint group_id, + gpointer group, gint packing, GtkPositionType pos) { @@ -156,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_id (GTK_NOTEBOOK (notebook), group_id); + gtk_notebook_set_group (GTK_NOTEBOOK (notebook), group); while (*labels) { @@ -186,7 +184,7 @@ create_notebook (gchar **labels, static GtkWidget* create_notebook_with_notebooks (gchar **labels, - gint group_id, + gpointer group, gint packing, GtkPositionType pos) { @@ -198,11 +196,11 @@ 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_id (GTK_NOTEBOOK (notebook), group_id); + gtk_notebook_set_group (GTK_NOTEBOOK (notebook), group); while (*labels) { - page = create_notebook (labels, group_id, packing, pos); + page = create_notebook (labels, group, packing, pos); title = gtk_label_new (*labels); |