* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
-#include <config.h>
+#include "config.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#include <gdk/gdkkeysyms.h>
+
+#undef GTK_DISABLE_DEPRECATED
+
#include "gtknotebook.h"
#include "gtkmain.h"
#include "gtkmenu.h"
#include "gtkmenuitem.h"
#include "gtklabel.h"
-#include <gdk/gdkkeysyms.h>
-#include <stdio.h>
#include "gtkintl.h"
#include "gtkmarshalers.h"
#include "gtkbindings.h"
#include "gtkprivate.h"
#include "gtkdnd.h"
+#include "gtkbuildable.h"
+
#include "gtkalias.h"
#define SCROLL_DELAY_FACTOR 5
static gboolean gtk_notebook_reorder_tab (GtkNotebook *notebook,
GtkDirectionType direction_type,
gboolean move_to_last);
+static void gtk_notebook_remove_tab_label (GtkNotebook *notebook,
+ GtkNotebookPage *page);
/*** GtkObject Methods ***/
static void gtk_notebook_destroy (GtkObject *object);
GList *list,
gint direction,
gboolean find_visible);
-static GtkNotebook *gtk_notebook_create_window (GtkNotebook *notebook,
- GtkWidget *page,
- gint x,
- gint y);
+static void gtk_notebook_child_reordered (GtkNotebook *notebook,
+ GtkNotebookPage *page);
/*** GtkNotebook Drawing Functions ***/
static void gtk_notebook_paint (GtkWidget *widget,
gint x,
gint y);
+/* GtkBuildable */
+static void gtk_notebook_buildable_init (GtkBuildableIface *iface);
+static void gtk_notebook_buildable_add_child (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ GObject *child,
+ const gchar *type);
static GtkNotebookWindowCreationFunc window_creation_hook = NULL;
static gpointer window_creation_hook_data;
static guint notebook_signals[LAST_SIGNAL] = { 0 };
-G_DEFINE_TYPE (GtkNotebook, gtk_notebook, GTK_TYPE_CONTAINER)
+G_DEFINE_TYPE_WITH_CODE (GtkNotebook, gtk_notebook, GTK_TYPE_CONTAINER,
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+ gtk_notebook_buildable_init))
static void
add_tab_bindings (GtkBindingSet *binding_set,
g_param_spec_int ("page",
P_("Page"),
P_("The index of the current page"),
- 0,
+ -1,
G_MAXINT,
- 0,
+ -1,
GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_TAB_POS,
G_MAXINT,
-1,
GTK_PARAM_READWRITE));
+
+ /**
+ * GtkNotebook:group:
+ *
+ * Group for tabs drag and drop.
+ *
+ * Since: 2.12
+ */
g_object_class_install_property (gobject_class,
PROP_GROUP,
g_param_spec_pointer ("group",
g_param_spec_boolean ("tab-expand",
P_("Tab expand"),
P_("Whether to expand the child's tab or not"),
- TRUE,
+ FALSE,
GTK_PARAM_READWRITE));
gtk_container_class_install_child_property (container_class,
CHILD_PROP_TAB_FILL,
gtk_drag_dest_set_track_motion (GTK_WIDGET (notebook), TRUE);
}
+static void
+gtk_notebook_buildable_init (GtkBuildableIface *iface)
+{
+ iface->add_child = gtk_notebook_buildable_add_child;
+}
+
+static void
+gtk_notebook_buildable_add_child (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ GObject *child,
+ const gchar *type)
+{
+ GtkNotebook *notebook = GTK_NOTEBOOK (buildable);
+
+ if (type && strcmp (type, "tab") == 0)
+ {
+ GtkWidget * page;
+
+ page = gtk_notebook_get_nth_page (notebook, -1);
+ /* To set the tab label widget, we must have already a child
+ * inside the tab container. */
+ g_assert (page != NULL);
+ gtk_notebook_set_tab_label (notebook, page, GTK_WIDGET (child));
+ }
+ else if (!type)
+ gtk_notebook_append_page (notebook, GTK_WIDGET (child), NULL);
+ else
+ GTK_BUILDER_WARN_INVALID_CHILD_TYPE (notebook, type);
+}
+
static gboolean
gtk_notebook_select_page (GtkNotebook *notebook,
gboolean move_focus)
{
GtkNotebook *notebook = GTK_NOTEBOOK (object);
GtkNotebookPrivate *priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
-
+
if (notebook->menu)
gtk_notebook_popup_disable (notebook);
gtk_notebook_set_group (notebook, g_value_get_pointer (value));
break;
default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
else
gtk_widget_unparent (page->tab_label);
- gtk_widget_set_parent_window (page->tab_label, widget->window);
gtk_widget_set_parent (page->tab_label, widget);
g_object_unref (page->tab_label);
}
else
page = notebook->cur_page;
- if (!page)
+ if (!page || !page->tab_label)
return;
priv->pressed_button = -1;
element = get_drop_position (notebook, page->pack);
old_page_num = g_list_position (notebook->children, notebook->focus_tab);
page_num = reorder_tab (notebook, element, notebook->focus_tab);
-
+ gtk_notebook_child_reordered (notebook, page);
+
if (priv->has_scrolled || old_page_num != page_num)
g_signal_emit (notebook,
notebook_signals[PAGE_REORDERED], 0,
case CHILD_PROP_TAB_LABEL:
label = gtk_notebook_get_tab_label (notebook, child);
- if (label && GTK_IS_LABEL (label))
+ if (GTK_IS_LABEL (label))
g_value_set_string (value, GTK_LABEL (label)->label);
else
g_value_set_string (value, NULL);
case CHILD_PROP_MENU_LABEL:
label = gtk_notebook_get_menu_label (notebook, child);
- if (label && GTK_IS_LABEL (label))
+ if (GTK_IS_LABEL (label))
g_value_set_string (value, GTK_LABEL (label)->label);
else
g_value_set_string (value, NULL);
gtk_widget_freeze_child_notify (child);
- page = g_new0 (GtkNotebookPage, 1);
+ page = g_slice_new0 (GtkNotebookPage);
page->child = child;
nchildren = g_list_length (notebook->children);
GtkNotebookPage *page;
GList * next_list;
gint need_resize = FALSE;
+ GtkWidget *tab_label;
gboolean destroying;
priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
destroying = GTK_OBJECT_FLAGS (notebook) & GTK_IN_DESTRUCTION;
- next_list = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
+ next_list = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
if (!next_list)
- next_list = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE);
+ next_list = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE);
+
+ notebook->children = g_list_remove_link (notebook->children, list);
if (notebook->cur_page == list->data)
{
gtk_widget_unparent (page->child);
- gtk_notebook_remove_tab_label (notebook, page);
-
+ tab_label = page->tab_label;
+ if (tab_label)
+ {
+ g_object_ref (tab_label);
+ gtk_notebook_remove_tab_label (notebook, page);
+ if (destroying)
+ gtk_widget_destroy (tab_label);
+ g_object_unref (tab_label);
+ }
+
if (notebook->menu)
{
gtk_container_remove (GTK_CONTAINER (notebook->menu),
if (!page->default_menu)
g_object_unref (page->menu_label);
- notebook->children = g_list_remove_link (notebook->children, list);
g_list_free (list);
if (page->last_focus_child)
page->last_focus_child = NULL;
}
- g_free (page);
+ g_slice_free (GtkNotebookPage, page);
gtk_notebook_update_labels (notebook);
if (need_resize)
gchar string[32];
gint page_num = 1;
+ if (!notebook->show_tabs && !notebook->menu)
+ return;
+
for (list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, FALSE);
list;
list = gtk_notebook_search_page (notebook, list, STEP_NEXT, FALSE))
}
if (notebook->menu && page->default_menu)
{
- if (page->tab_label && GTK_IS_LABEL (page->tab_label))
+ if (GTK_IS_LABEL (page->tab_label))
gtk_label_set_text (GTK_LABEL (page->menu_label),
- GTK_LABEL (page->tab_label)->label);
+ GTK_LABEL (page->tab_label)->label);
else
gtk_label_set_text (GTK_LABEL (page->menu_label), string);
}
page = list->data;
if (page->default_menu)
{
- if (page->tab_label && GTK_IS_LABEL (page->tab_label))
+ if (GTK_IS_LABEL (page->tab_label))
page->menu_label = gtk_label_new (GTK_LABEL (page->tab_label)->label);
else
page->menu_label = gtk_label_new ("");
* Retrieves the text of the tab label for the page containing
* @child.
*
- * Returns value: the text of the tab label, or %NULL if the
- * tab label widget is not a #GtkLabel. The
- * string is owned by the widget and must not
- * be freed.
+ * Return value: the text of the tab label, or %NULL if the
+ * tab label widget is not a #GtkLabel. The
+ * string is owned by the widget and must not
+ * be freed.
**/
G_CONST_RETURN gchar *
gtk_notebook_get_tab_label_text (GtkNotebook *notebook,
tab_label = gtk_notebook_get_tab_label (notebook, child);
- if (tab_label && GTK_IS_LABEL (tab_label))
+ if (GTK_IS_LABEL (tab_label))
return gtk_label_get_text (GTK_LABEL (tab_label));
else
return NULL;
* Retrieves the text of the menu label for the page containing
* @child.
*
- * Returns value: the text of the tab label, or %NULL if the
- * widget does not have a menu label other than
- * the default menu label, or the menu label widget
- * is not a #GtkLabel. The string is owned by
- * the widget and must not be freed.
+ * Return value: the text of the tab label, or %NULL if the
+ * widget does not have a menu label other than
+ * the default menu label, or the menu label widget
+ * is not a #GtkLabel. The string is owned by
+ * the widget and must not be freed.
**/
G_CONST_RETURN gchar *
gtk_notebook_get_menu_label_text (GtkNotebook *notebook,
menu_label = gtk_notebook_get_menu_label (notebook, child);
- if (menu_label && GTK_IS_LABEL (menu_label))
+ if (GTK_IS_LABEL (menu_label))
return gtk_label_get_text (GTK_LABEL (menu_label));
else
return NULL;
* not be able to exchange tabs with any other notebook.
*
* Since: 2.10
- * Deprecated:2.12: use gtk_notebook_set_group() instead.
+ * Deprecated: 2.12: use gtk_notebook_set_group() instead.
*/
void
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.
+ * Deprecated: 2.12: use gtk_notebook_get_group() instead.
*/
gint
gtk_notebook_get_group_id (GtkNotebook *notebook)
priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
/* substract 1 to get rid of the -1/NULL difference */
- return GPOINTER_TO_INT (priv->group - 1);
+ return GPOINTER_TO_INT (priv->group) - 1;
}
/**
* destination and accept the target "GTK_NOTEBOOK_TAB". The notebook
* will fill the selection with a GtkWidget** pointing to the child
* widget that corresponds to the dropped tab.
- *
- * <informalexample><programlisting>
+ * |[
* static void
* on_drop_zone_drag_data_received (GtkWidget *widget,
* GdkDragContext *context,
* process_widget (*child);
* gtk_container_remove (GTK_CONTAINER (notebook), *child);
* }
- * </programlisting></informalexample>
+ * ]|
*
* If you want a notebook to accept drags from other widgets,
* you will have to set your own DnD code to do it.