X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtktoolbar.c;h=7b6f4a38f1692a0386e0c1d5e609acd09cb27ab2;hb=165fd5903f997879f703e206d6457761ed1daea4;hp=0dd959d9a5eb445b151d0341baaa968ede77ea00;hpb=07e7719441f5927bc3c482717fc53f8529186e3a;p=~andy%2Fgtk diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c index 0dd959d9a..7b6f4a38f 100644 --- a/gtk/gtktoolbar.c +++ b/gtk/gtktoolbar.c @@ -5,7 +5,7 @@ * Copyright (C) 2002 Anders Carlsson * Copyright (C) 2002 James Henstridge * Copyright (C) 2003, 2004 Soeren Sandmann - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either @@ -26,33 +26,38 @@ * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS * file for a list of people on the GTK+ Team. See the ChangeLog * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. + * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ #undef GTK_DISABLE_DEPRECATED -#include +#include "config.h" + +#include +#include + +#include + #include "gtkarrow.h" -#include "gtktoolbar.h" -#include "gtkradiotoolbutton.h" -#include "gtkseparatortoolitem.h" -#include "gtkmenu.h" -#include "gtkradiobutton.h" #include "gtkbindings.h" -#include -#include "gtkmarshalers.h" +#include "gtkhbox.h" +#include "gtkimage.h" +#include "gtklabel.h" #include "gtkmain.h" +#include "gtkmarshalers.h" +#include "gtkmenu.h" +#include "gtkorientable.h" +#include "gtkradiobutton.h" +#include "gtkradiotoolbutton.h" +#include "gtkseparatormenuitem.h" +#include "gtkseparatortoolitem.h" #include "gtkstock.h" -#include "gtklabel.h" +#include "gtktoolbar.h" +#include "gtktoolshell.h" +#include "gtkvbox.h" #include "gtkprivate.h" #include "gtkintl.h" -#include -#include "gtkhbox.h" -#include "gtkvbox.h" -#include "gtkimage.h" -#include "gtkseparatormenuitem.h" #include "gtkalias.h" -#include typedef struct _ToolbarContent ToolbarContent; @@ -102,7 +107,6 @@ enum { ORIENTATION_CHANGED, STYLE_CHANGED, POPUP_CONTEXT_MENU, - MOVE_FOCUS, FOCUS_HOME_OR_END, LAST_SIGNAL }; @@ -172,6 +176,8 @@ static void gtk_toolbar_style_set (GtkWidget *widget, GtkStyle *prev_style); static gboolean gtk_toolbar_focus (GtkWidget *widget, GtkDirectionType dir); +static void gtk_toolbar_move_focus (GtkWidget *widget, + GtkDirectionType dir); static void gtk_toolbar_screen_changed (GtkWidget *widget, GdkScreen *previous_screen); static void gtk_toolbar_map (GtkWidget *widget); @@ -202,8 +208,6 @@ static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar GtkOrientation orientation); static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar, GtkToolbarStyle style); -static gboolean gtk_toolbar_move_focus (GtkToolbar *toolbar, - GtkDirectionType dir); static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar, gboolean focus_home); static gboolean gtk_toolbar_button_press (GtkWidget *toolbar, @@ -222,7 +226,7 @@ static GtkWidget *internal_insert_element (GtkToolbar *toolbar const char *tooltip_text, const char *tooltip_private_text, GtkWidget *icon, - GtkSignalFunc callback, + GCallback callback, gpointer user_data, gint position, gboolean use_stock); @@ -242,6 +246,12 @@ static ToolbarContent *toolbar_content_new_tool_item (GtkToolbar GtkToolItem *item, gboolean is_placeholder, gint pos); +static ToolbarContent *toolbar_content_new_compatibility (GtkToolbar *toolbar, + GtkToolbarChildType type, + GtkWidget *widget, + GtkWidget *icon, + GtkWidget *label, + gint pos); static void toolbar_content_remove (ToolbarContent *content, GtkToolbar *toolbar); static void toolbar_content_free (ToolbarContent *content); @@ -293,12 +303,25 @@ static void toolbar_content_hide_all (ToolbarContent static void toolbar_content_set_expand (ToolbarContent *content, gboolean expand); +static void toolbar_tool_shell_iface_init (GtkToolShellIface *iface); +static GtkIconSize toolbar_get_icon_size (GtkToolShell *shell); +static GtkOrientation toolbar_get_orientation (GtkToolShell *shell); +static GtkToolbarStyle toolbar_get_style (GtkToolShell *shell); +static GtkReliefStyle toolbar_get_relief_style (GtkToolShell *shell); +static void toolbar_rebuild_menu (GtkToolShell *shell); + #define GTK_TOOLBAR_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOLBAR, GtkToolbarPrivate)) -static guint toolbar_signals [LAST_SIGNAL] = { 0 }; -G_DEFINE_TYPE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER) +G_DEFINE_TYPE_WITH_CODE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER, + G_IMPLEMENT_INTERFACE (GTK_TYPE_TOOL_SHELL, + toolbar_tool_shell_iface_init) + G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, + NULL)) + +static guint toolbar_signals[LAST_SIGNAL] = { 0 }; + static void add_arrow_bindings (GtkBindingSet *binding_set, @@ -308,10 +331,10 @@ add_arrow_bindings (GtkBindingSet *binding_set, guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left; gtk_binding_entry_add_signal (binding_set, keysym, 0, - "move_focus", 1, + "move-focus", 1, GTK_TYPE_DIRECTION_TYPE, dir); gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0, - "move_focus", 1, + "move-focus", 1, GTK_TYPE_DIRECTION_TYPE, dir); } @@ -322,11 +345,11 @@ add_ctrl_tab_bindings (GtkBindingSet *binding_set, { gtk_binding_entry_add_signal (binding_set, GDK_Tab, GDK_CONTROL_MASK | modifiers, - "move_focus", 1, + "move-focus", 1, GTK_TYPE_DIRECTION_TYPE, direction); gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, GDK_CONTROL_MASK | modifiers, - "move_focus", 1, + "move-focus", 1, GTK_TYPE_DIRECTION_TYPE, direction); } @@ -352,6 +375,14 @@ gtk_toolbar_class_init (GtkToolbarClass *klass) widget_class->size_allocate = gtk_toolbar_size_allocate; widget_class->style_set = gtk_toolbar_style_set; widget_class->focus = gtk_toolbar_focus; + + /* need to override the base class function via override_class_handler, + * because the signal slot is not available in GtkWidgetClass + */ + g_signal_override_class_handler ("move-focus", + GTK_TYPE_TOOLBAR, + G_CALLBACK (gtk_toolbar_move_focus)); + widget_class->screen_changed = gtk_toolbar_screen_changed; widget_class->realize = gtk_toolbar_realize; widget_class->unrealize = gtk_toolbar_unrealize; @@ -422,7 +453,7 @@ gtk_toolbar_class_init (GtkToolbarClass *klass) * Return value: return %TRUE if the signal was handled, %FALSE if not */ toolbar_signals[POPUP_CONTEXT_MENU] = - g_signal_new (I_("popup_context_menu"), + g_signal_new (I_("popup-context-menu"), G_OBJECT_CLASS_TYPE (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu), @@ -431,25 +462,7 @@ gtk_toolbar_class_init (GtkToolbarClass *klass) G_TYPE_BOOLEAN, 3, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT); - /** - * GtkToolbar::move-focus: - * @toolbar: the #GtkToolbar which emitted the signal - * @dir: a #GtkDirection - * - * A keybinding signal used internally by GTK+. This signal can't - * be used in application code. - * - * Return value: %TRUE if the signal was handled, %FALSE if not - */ - toolbar_signals[MOVE_FOCUS] = - _gtk_binding_signal_new (I_("move_focus"), - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_CALLBACK (gtk_toolbar_move_focus), - NULL, NULL, - _gtk_marshal_BOOLEAN__ENUM, - G_TYPE_BOOLEAN, 1, - GTK_TYPE_DIRECTION_TYPE); + /** * GtkToolbar::focus-home-or-end: * @toolbar: the #GtkToolbar which emitted the signal @@ -461,32 +474,27 @@ gtk_toolbar_class_init (GtkToolbarClass *klass) * Return value: %TRUE if the signal was handled, %FALSE if not */ toolbar_signals[FOCUS_HOME_OR_END] = - _gtk_binding_signal_new (I_("focus_home_or_end"), - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_CALLBACK (gtk_toolbar_focus_home_or_end), - NULL, NULL, - _gtk_marshal_BOOLEAN__BOOLEAN, - G_TYPE_BOOLEAN, 1, - G_TYPE_BOOLEAN); - + g_signal_new_class_handler (I_("focus-home-or-end"), + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_CALLBACK (gtk_toolbar_focus_home_or_end), + NULL, NULL, + _gtk_marshal_BOOLEAN__BOOLEAN, + G_TYPE_BOOLEAN, 1, + G_TYPE_BOOLEAN); + /* properties */ - g_object_class_install_property (gobject_class, - PROP_ORIENTATION, - g_param_spec_enum ("orientation", - P_("Orientation"), - P_("The orientation of the toolbar"), - GTK_TYPE_ORIENTATION, - GTK_ORIENTATION_HORIZONTAL, - GTK_PARAM_READWRITE)); - + g_object_class_override_property (gobject_class, + PROP_ORIENTATION, + "orientation"); + g_object_class_install_property (gobject_class, PROP_TOOLBAR_STYLE, g_param_spec_enum ("toolbar-style", P_("Toolbar Style"), P_("How to draw the toolbar"), GTK_TYPE_TOOLBAR_STYLE, - GTK_TOOLBAR_ICONS, + DEFAULT_TOOLBAR_STYLE, GTK_PARAM_READWRITE)); g_object_class_install_property (gobject_class, PROP_SHOW_ARROW, @@ -495,23 +503,6 @@ gtk_toolbar_class_init (GtkToolbarClass *klass) P_("If an arrow should be shown if the toolbar doesn't fit"), TRUE, GTK_PARAM_READWRITE)); - - - /** - * GtkToolbar:tooltips: - * - * If the tooltips of the toolbar should be active or not. - * - * Since: 2.8 - */ - g_object_class_install_property (gobject_class, - PROP_TOOLTIPS, - g_param_spec_boolean ("tooltips", - P_("Tooltips"), - P_("If the tooltips of the toolbar should be active or not"), - TRUE, - GTK_PARAM_READWRITE)); - /** * GtkToolbar:icon-size: @@ -528,12 +519,12 @@ gtk_toolbar_class_init (GtkToolbarClass *klass) */ g_object_class_install_property (gobject_class, PROP_ICON_SIZE, - g_param_spec_enum ("icon-size", - P_("Icon size"), - P_("Size of icons in this toolbar"), - GTK_TYPE_ICON_SIZE, - DEFAULT_ICON_SIZE, - GTK_PARAM_READWRITE)); + g_param_spec_int ("icon-size", + P_("Icon size"), + P_("Size of icons in this toolbar"), + 0, G_MAXINT, + DEFAULT_ICON_SIZE, + GTK_PARAM_READWRITE)); /** * GtkToolbar:icon-size-set: @@ -556,7 +547,7 @@ gtk_toolbar_class_init (GtkToolbarClass *klass) g_param_spec_boolean ("expand", P_("Expand"), P_("Whether the item should receive extra space when the toolbar grows"), - TRUE, + FALSE, GTK_PARAM_READWRITE)); gtk_container_class_install_child_property (container_class, @@ -564,7 +555,7 @@ gtk_toolbar_class_init (GtkToolbarClass *klass) g_param_spec_boolean ("homogeneous", P_("Homogeneous"), P_("Whether the item should be the same size as other homogeneous items"), - TRUE, + FALSE, GTK_PARAM_READWRITE)); /* style properties */ @@ -617,20 +608,6 @@ gtk_toolbar_class_init (GtkToolbarClass *klass) GTK_TYPE_SHADOW_TYPE, GTK_SHADOW_OUT, GTK_PARAM_READABLE)); - - gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-style", - P_("Toolbar style"), - P_("Whether default toolbars have text only, text and icons, icons only, etc."), - GTK_TYPE_TOOLBAR_STYLE, - DEFAULT_TOOLBAR_STYLE, - GTK_PARAM_READWRITE)); - - gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-icon-size", - P_("Toolbar icon size"), - P_("Size of icons in default toolbars"), - GTK_TYPE_ICON_SIZE, - DEFAULT_ICON_SIZE, - GTK_PARAM_READWRITE)); binding_set = gtk_binding_set_by_class (klass); @@ -640,16 +617,16 @@ gtk_toolbar_class_init (GtkToolbarClass *klass) add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN); gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, 0, - "focus_home_or_end", 1, + "focus-home-or-end", 1, G_TYPE_BOOLEAN, TRUE); gtk_binding_entry_add_signal (binding_set, GDK_Home, 0, - "focus_home_or_end", 1, + "focus-home-or-end", 1, G_TYPE_BOOLEAN, TRUE); gtk_binding_entry_add_signal (binding_set, GDK_KP_End, 0, - "focus_home_or_end", 1, + "focus-home-or-end", 1, G_TYPE_BOOLEAN, FALSE); gtk_binding_entry_add_signal (binding_set, GDK_End, 0, - "focus_home_or_end", 1, + "focus-home-or-end", 1, G_TYPE_BOOLEAN, FALSE); add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD); @@ -658,13 +635,23 @@ gtk_toolbar_class_init (GtkToolbarClass *klass) g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate)); } +static void +toolbar_tool_shell_iface_init (GtkToolShellIface *iface) +{ + iface->get_icon_size = toolbar_get_icon_size; + iface->get_orientation = toolbar_get_orientation; + iface->get_style = toolbar_get_style; + iface->get_relief_style = toolbar_get_relief_style; + iface->rebuild_menu = toolbar_rebuild_menu; +} + static void gtk_toolbar_init (GtkToolbar *toolbar) { GtkToolbarPrivate *priv; - GTK_WIDGET_UNSET_FLAGS (toolbar, GTK_CAN_FOCUS); - GTK_WIDGET_SET_FLAGS (toolbar, GTK_NO_WINDOW); + gtk_widget_set_can_focus (GTK_WIDGET (toolbar), FALSE); + gtk_widget_set_has_window (GTK_WIDGET (toolbar), FALSE); priv = GTK_TOOLBAR_GET_PRIVATE (toolbar); @@ -672,11 +659,10 @@ gtk_toolbar_init (GtkToolbar *toolbar) toolbar->style = DEFAULT_TOOLBAR_STYLE; toolbar->icon_size = DEFAULT_ICON_SIZE; priv->animation = DEFAULT_ANIMATION_STATE; - toolbar->tooltips = gtk_tooltips_new (); - g_object_ref_sink (toolbar->tooltips); + toolbar->tooltips = NULL; /* FIXME: Remove this */ priv->arrow_button = gtk_toggle_button_new (); - g_signal_connect (priv->arrow_button, "button_press_event", + g_signal_connect (priv->arrow_button, "button-press-event", G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar); g_signal_connect (priv->arrow_button, "clicked", G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar); @@ -715,7 +701,8 @@ gtk_toolbar_set_property (GObject *object, switch (prop_id) { case PROP_ORIENTATION: - gtk_toolbar_set_orientation (toolbar, g_value_get_enum (value)); + g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0, + g_value_get_enum (value)); break; case PROP_TOOLBAR_STYLE: gtk_toolbar_set_style (toolbar, g_value_get_enum (value)); @@ -723,11 +710,8 @@ gtk_toolbar_set_property (GObject *object, case PROP_SHOW_ARROW: gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value)); break; - case PROP_TOOLTIPS: - gtk_toolbar_set_tooltips (toolbar, g_value_get_boolean (value)); - break; case PROP_ICON_SIZE: - gtk_toolbar_set_icon_size (toolbar, g_value_get_enum (value)); + gtk_toolbar_set_icon_size (toolbar, g_value_get_int (value)); break; case PROP_ICON_SIZE_SET: if (g_value_get_boolean (value)) @@ -761,11 +745,8 @@ gtk_toolbar_get_property (GObject *object, case PROP_SHOW_ARROW: g_value_set_boolean (value, priv->show_arrow); break; - case PROP_TOOLTIPS: - g_value_set_boolean (value, gtk_toolbar_get_tooltips (toolbar)); - break; case PROP_ICON_SIZE: - g_value_set_enum (value, gtk_toolbar_get_icon_size (toolbar)); + g_value_set_int (value, gtk_toolbar_get_icon_size (toolbar)); break; case PROP_ICON_SIZE_SET: g_value_set_boolean (value, toolbar->icon_size_set); @@ -808,7 +789,7 @@ gtk_toolbar_realize (GtkWidget *widget) gint attributes_mask; gint border_width; - GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); + gtk_widget_set_realized (widget, TRUE); border_width = GTK_CONTAINER (widget)->border_width; @@ -846,9 +827,8 @@ gtk_toolbar_unrealize (GtkWidget *widget) gdk_window_destroy (priv->event_window); priv->event_window = NULL; } - - if (GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize) - (* GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize) (widget); + + GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize (widget); } static gint @@ -863,11 +843,11 @@ gtk_toolbar_expose (GtkWidget *widget, border_width = GTK_CONTAINER (widget)->border_width; - if (GTK_WIDGET_DRAWABLE (widget)) + if (gtk_widget_is_drawable (widget)) { gtk_paint_box (widget->style, widget->window, - GTK_WIDGET_STATE (widget), + gtk_widget_get_state (widget), get_shadow_type (toolbar), &event->area, widget, "toolbar", border_width + widget->allocation.x, @@ -1116,8 +1096,6 @@ slide_idle_handler (gpointer data) GtkToolbarPrivate *priv; GList *list; - GDK_THREADS_ENTER (); - priv = GTK_TOOLBAR_GET_PRIVATE (toolbar); if (priv->need_sync) @@ -1185,15 +1163,15 @@ slide_idle_handler (gpointer data) { gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar)); - GDK_THREADS_LEAVE (); return TRUE; } } + gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar)); + priv->is_sliding = FALSE; priv->idle_id = 0; - GDK_THREADS_LEAVE(); return FALSE; } @@ -1230,7 +1208,7 @@ gtk_toolbar_begin_sliding (GtkToolbar *toolbar) priv->is_sliding = TRUE; if (!priv->idle_id) - priv->idle_id = g_idle_add (slide_idle_handler, toolbar); + priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar); rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL); vertical = (toolbar->orientation == GTK_ORIENTATION_VERTICAL); @@ -1374,7 +1352,8 @@ rebuild_menu (GtkToolbar *toolbar) GTK_WIDGET (toolbar), menu_detached); - g_signal_connect (priv->menu, "deactivate", G_CALLBACK (menu_deactivated), toolbar); + g_signal_connect (priv->menu, "deactivate", + G_CALLBACK (menu_deactivated), toolbar); } gtk_container_foreach (GTK_CONTAINER (priv->menu), remove_item, NULL); @@ -1447,7 +1426,9 @@ gtk_toolbar_size_allocate (GtkWidget *widget, GtkRequisition arrow_requisition; gboolean overflowing; gboolean size_changed; + gdouble elapsed; GtkAllocation item_area; + GtkShadowType shadow_type; size_changed = FALSE; if (widget->allocation.x != allocation->x || @@ -1465,7 +1446,7 @@ gtk_toolbar_size_allocate (GtkWidget *widget, border_width = GTK_CONTAINER (toolbar)->border_width; - if (GTK_WIDGET_REALIZED (widget)) + if (gtk_widget_get_realized (widget)) { gdk_window_move_resize (priv->event_window, allocation->x + border_width, @@ -1479,13 +1460,15 @@ gtk_toolbar_size_allocate (GtkWidget *widget, gtk_widget_get_child_requisition (GTK_WIDGET (priv->arrow_button), &arrow_requisition); + shadow_type = get_shadow_type (toolbar); + if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL) { available_size = size = allocation->width - 2 * border_width; short_size = allocation->height - 2 * border_width; arrow_size = arrow_requisition.width; - if (get_shadow_type (toolbar) != GTK_SHADOW_NONE) + if (shadow_type != GTK_SHADOW_NONE) { available_size -= 2 * widget->style->xthickness; short_size -= 2 * widget->style->ythickness; @@ -1497,7 +1480,7 @@ gtk_toolbar_size_allocate (GtkWidget *widget, short_size = allocation->width - 2 * border_width; arrow_size = arrow_requisition.height; - if (get_shadow_type (toolbar) != GTK_SHADOW_NONE) + if (shadow_type != GTK_SHADOW_NONE) { available_size -= 2 * widget->style->ythickness; short_size -= 2 * widget->style->xthickness; @@ -1675,7 +1658,7 @@ gtk_toolbar_size_allocate (GtkWidget *widget, allocations[i].x += allocation->x; allocations[i].y += allocation->y; - if (get_shadow_type (toolbar) != GTK_SHADOW_NONE) + if (shadow_type != GTK_SHADOW_NONE) { allocations[i].x += widget->style->xthickness; allocations[i].y += widget->style->ythickness; @@ -1687,7 +1670,7 @@ gtk_toolbar_size_allocate (GtkWidget *widget, arrow_allocation.x += allocation->x; arrow_allocation.y += allocation->y; - if (get_shadow_type (toolbar) != GTK_SHADOW_NONE) + if (shadow_type != GTK_SHADOW_NONE) { arrow_allocation.x += widget->style->xthickness; arrow_allocation.y += widget->style->ythickness; @@ -1696,7 +1679,7 @@ gtk_toolbar_size_allocate (GtkWidget *widget, item_area.x += allocation->x; item_area.y += allocation->y; - if (get_shadow_type (toolbar) != GTK_SHADOW_NONE) + if (shadow_type != GTK_SHADOW_NONE) { item_area.x += widget->style->xthickness; item_area.y += widget->style->ythickness; @@ -1727,6 +1710,7 @@ gtk_toolbar_size_allocate (GtkWidget *widget, } } + elapsed = g_timer_elapsed (priv->timer, NULL); for (list = priv->content, i = 0; list != NULL; list = list->next, ++i) { ToolbarContent *content = list->data; @@ -1794,7 +1778,7 @@ gtk_toolbar_size_allocate (GtkWidget *widget, { gtk_widget_hide (GTK_WIDGET (priv->arrow_button)); - if (priv->menu && GTK_WIDGET_VISIBLE (priv->menu)) + if (priv->menu && gtk_widget_get_visible (GTK_WIDGET (priv->menu))) gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu)); } @@ -1806,10 +1790,16 @@ static void gtk_toolbar_update_button_relief (GtkToolbar *toolbar) { GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar); + GtkReliefStyle relief; + + relief = get_button_relief (toolbar); + + if (relief != gtk_button_get_relief (GTK_BUTTON (priv->arrow_button))) + { + gtk_toolbar_reconfigured (toolbar); - gtk_toolbar_reconfigured (toolbar); - - gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), get_button_relief (toolbar)); + gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), relief); + } } static void @@ -1819,8 +1809,8 @@ gtk_toolbar_style_set (GtkWidget *widget, GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget); priv->max_homogeneous_pixels = -1; - - if (GTK_WIDGET_REALIZED (widget)) + + if (gtk_widget_get_realized (widget)) gtk_style_set_background (widget->style, widget->window, widget->state); if (prev_style) @@ -1894,7 +1884,7 @@ gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar, if (GTK_CONTAINER (toolbar)->focus_child == child) break; - if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir)) + if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir)) break; } @@ -1906,19 +1896,20 @@ gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar, /* Keybinding handler. This function is called when the user presses * Ctrl TAB or an arrow key. */ -static gboolean -gtk_toolbar_move_focus (GtkToolbar *toolbar, +static void +gtk_toolbar_move_focus (GtkWidget *widget, GtkDirectionType dir) { + GtkToolbar *toolbar = GTK_TOOLBAR (widget); + GtkContainer *container = GTK_CONTAINER (toolbar); GList *list; gboolean try_focus = FALSE; GList *children; - GtkContainer *container = GTK_CONTAINER (toolbar); - + if (container->focus_child && gtk_widget_child_focus (container->focus_child, dir)) { - return TRUE; + return; } children = gtk_toolbar_list_children_in_focus_order (toolbar, dir); @@ -1927,7 +1918,7 @@ gtk_toolbar_move_focus (GtkToolbar *toolbar, { GtkWidget *child = list->data; - if (try_focus && GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir)) + if (try_focus && gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir)) break; if (child == GTK_CONTAINER (toolbar)->focus_child) @@ -1935,8 +1926,6 @@ gtk_toolbar_move_focus (GtkToolbar *toolbar, } g_list_free (children); - - return FALSE; } /* The focus handler for the toolbar. It called when the user presses @@ -1964,7 +1953,7 @@ gtk_toolbar_focus (GtkWidget *widget, { GtkWidget *child = list->data; - if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir)) + if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir)) { result = TRUE; break; @@ -2240,11 +2229,11 @@ logical_to_physical (GtkToolbar *toolbar, /** * gtk_toolbar_set_drop_highlight_item: * @toolbar: a #GtkToolbar - * @tool_item: a #GtkToolItem, or %NULL to turn of highlighting + * @tool_item: (allow-none): a #GtkToolItem, or %NULL to turn of highlighting * @index_: a position on @toolbar - * + * * Highlights @toolbar to give an idea of what it would look like - * if @item was added to @toolbar at the position indicated by @index_. + * if @item was added to @toolbar at the position indicated by @index_. * If @item is %NULL, highlighting is turned off. In that case @index_ * is ignored. * @@ -2451,34 +2440,20 @@ static void gtk_toolbar_add (GtkContainer *container, GtkWidget *widget) { - GtkToolbar *toolbar; - - g_return_if_fail (GTK_IS_TOOLBAR (container)); - g_return_if_fail (widget != NULL); - - toolbar = GTK_TOOLBAR (container); - - if (GTK_IS_TOOL_ITEM (widget)) - gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1); - else - gtk_toolbar_append_widget (toolbar, widget, NULL, NULL); + GtkToolbar *toolbar = GTK_TOOLBAR (container); + + gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1); } static void gtk_toolbar_remove (GtkContainer *container, GtkWidget *widget) { - GtkToolbar *toolbar; - GtkToolbarPrivate *priv; + GtkToolbar *toolbar = GTK_TOOLBAR (container); + GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar); ToolbarContent *content_to_remove; GList *list; - - g_return_if_fail (GTK_IS_TOOLBAR (container)); - g_return_if_fail (GTK_IS_WIDGET (widget)); - - toolbar = GTK_TOOLBAR (container); - priv = GTK_TOOLBAR_GET_PRIVATE (toolbar); - + content_to_remove = NULL; for (list = priv->content; list != NULL; list = list->next) { @@ -2522,14 +2497,14 @@ gtk_toolbar_forall (GtkContainer *container, GtkWidget *child = toolbar_content_get_widget (content); if (child) - (*callback) (child, callback_data); + callback (child, callback_data); } list = next; } if (include_internals) - (* callback) (priv->arrow_button, callback_data); + callback (priv->arrow_button, callback_data); } static GType @@ -2671,7 +2646,7 @@ gtk_toolbar_arrow_button_clicked (GtkWidget *button, GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) && - (!priv->menu || !GTK_WIDGET_VISIBLE (priv->menu))) + (!priv->menu || !gtk_widget_get_visible (GTK_WIDGET (priv->menu)))) { /* We only get here when the button is clicked with the keyboard, * because mouse button presses result in the menu being shown so @@ -2816,39 +2791,6 @@ gtk_toolbar_get_item_index (GtkToolbar *toolbar, return physical_to_logical (toolbar, n); } -/** - * gtk_toolbar_set_orientation: - * @toolbar: a #GtkToolbar. - * @orientation: a new #GtkOrientation. - * - * Sets whether a toolbar should appear horizontally or vertically. - **/ -void -gtk_toolbar_set_orientation (GtkToolbar *toolbar, - GtkOrientation orientation) -{ - g_return_if_fail (GTK_IS_TOOLBAR (toolbar)); - - g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0, orientation); -} - -/** - * gtk_toolbar_get_orientation: - * @toolbar: a #GtkToolbar - * - * Retrieves the current orientation of the toolbar. See - * gtk_toolbar_set_orientation(). - * - * Return value: the orientation - **/ -GtkOrientation -gtk_toolbar_get_orientation (GtkToolbar *toolbar) -{ - g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_ORIENTATION_HORIZONTAL); - - return toolbar->orientation; -} - /** * gtk_toolbar_set_style: * @toolbar: a #GtkToolbar. @@ -2915,44 +2857,6 @@ gtk_toolbar_unset_style (GtkToolbar *toolbar) } } -/** - * gtk_toolbar_set_tooltips: - * @toolbar: a #GtkToolbar. - * @enable: set to %FALSE to disable the tooltips, or %TRUE to enable them. - * - * Sets if the tooltips of a toolbar should be active or not. - **/ -void -gtk_toolbar_set_tooltips (GtkToolbar *toolbar, - gboolean enable) -{ - g_return_if_fail (GTK_IS_TOOLBAR (toolbar)); - - if (enable) - gtk_tooltips_enable (toolbar->tooltips); - else - gtk_tooltips_disable (toolbar->tooltips); - - g_object_notify (G_OBJECT (toolbar), "tooltips"); -} - -/** - * gtk_toolbar_get_tooltips: - * @toolbar: a #GtkToolbar - * - * Retrieves whether tooltips are enabled. See - * gtk_toolbar_set_tooltips(). - * - * Return value: %TRUE if tooltips are enabled - **/ -gboolean -gtk_toolbar_get_tooltips (GtkToolbar *toolbar) -{ - g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE); - - return toolbar->tooltips->enabled; -} - /** * gtk_toolbar_get_n_items: * @toolbar: a #GtkToolbar @@ -3025,7 +2929,8 @@ gtk_toolbar_get_nth_item (GtkToolbar *toolbar, * * Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size(). * - * Return value: the current icon size for the icons on the toolbar. + * Return value: (type int): the current icon size for the icons on + * the toolbar. **/ GtkIconSize gtk_toolbar_get_icon_size (GtkToolbar *toolbar) @@ -3152,9 +3057,6 @@ gtk_toolbar_finalize (GObject *object) GtkToolbar *toolbar = GTK_TOOLBAR (object); GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar); - if (toolbar->tooltips) - g_object_unref (toolbar->tooltips); - if (priv->arrow_button) gtk_widget_unparent (priv->arrow_button); @@ -3182,7 +3084,8 @@ gtk_toolbar_finalize (GObject *object) /** * gtk_toolbar_set_icon_size: * @toolbar: A #GtkToolbar - * @icon_size: The #GtkIconSize that stock icons in the toolbar shall have. + * @icon_size: (type int): The #GtkIconSize that stock icons in the + * toolbar shall have. * * This function sets the size of stock icons in the toolbar. You * can call it both before you add the icons and after they've been @@ -3255,430 +3158,6 @@ gtk_toolbar_unset_icon_size (GtkToolbar *toolbar) } } -/* - * Deprecated API - */ - -/** - * gtk_toolbar_append_item: - * @toolbar: a #GtkToolbar. - * @text: give your toolbar button a label. - * @tooltip_text: a string that appears when the user holds the mouse over this item. - * @tooltip_private_text: use with #GtkTipsQuery. - * @icon: a #GtkWidget that should be used as the button's icon. - * @callback: the function to be executed when the button is pressed. - * @user_data: a pointer to any data you wish to be passed to the callback. - * - * Inserts a new item into the toolbar. You must specify the position - * in the toolbar where it will be inserted. - * - * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as - * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc. - * - * Return value: the new toolbar item as a #GtkWidget. - **/ -GtkWidget * -gtk_toolbar_append_item (GtkToolbar *toolbar, - const char *text, - const char *tooltip_text, - const char *tooltip_private_text, - GtkWidget *icon, - GtkSignalFunc callback, - gpointer user_data) -{ - return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON, - NULL, text, - tooltip_text, tooltip_private_text, - icon, callback, user_data, - toolbar->num_children); -} - -/** - * gtk_toolbar_prepend_item: - * @toolbar: a #GtkToolbar. - * @text: give your toolbar button a label. - * @tooltip_text: a string that appears when the user holds the mouse over this item. - * @tooltip_private_text: use with #GtkTipsQuery. - * @icon: a #GtkWidget that should be used as the button's icon. - * @callback: the function to be executed when the button is pressed. - * @user_data: a pointer to any data you wish to be passed to the callback. - * - * Adds a new button to the beginning (top or left edges) of the given toolbar. - * - * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as - * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc. - * - * Return value: the new toolbar item as a #GtkWidget. - **/ -GtkWidget * -gtk_toolbar_prepend_item (GtkToolbar *toolbar, - const char *text, - const char *tooltip_text, - const char *tooltip_private_text, - GtkWidget *icon, - GtkSignalFunc callback, - gpointer user_data) -{ - return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON, - NULL, text, - tooltip_text, tooltip_private_text, - icon, callback, user_data, - 0); -} - -/** - * gtk_toolbar_insert_item: - * @toolbar: a #GtkToolbar. - * @text: give your toolbar button a label. - * @tooltip_text: a string that appears when the user holds the mouse over this item. - * @tooltip_private_text: use with #GtkTipsQuery. - * @icon: a #GtkWidget that should be used as the button's icon. - * @callback: the function to be executed when the button is pressed. - * @user_data: a pointer to any data you wish to be passed to the callback. - * @position: the number of widgets to insert this item after. - * - * Inserts a new item into the toolbar. You must specify the position in the - * toolbar where it will be inserted. - * - * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as - * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc. - * - * Return value: the new toolbar item as a #GtkWidget. - **/ -GtkWidget * -gtk_toolbar_insert_item (GtkToolbar *toolbar, - const char *text, - const char *tooltip_text, - const char *tooltip_private_text, - GtkWidget *icon, - GtkSignalFunc callback, - gpointer user_data, - gint position) -{ - return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON, - NULL, text, - tooltip_text, tooltip_private_text, - icon, callback, user_data, - position); -} - -/** - * gtk_toolbar_insert_stock: - * @toolbar: A #GtkToolbar - * @stock_id: The id of the stock item you want to insert - * @tooltip_text: The text in the tooltip of the toolbar button - * @tooltip_private_text: The private text of the tooltip - * @callback: The callback called when the toolbar button is clicked. - * @user_data: user data passed to callback - * @position: The position the button shall be inserted at. - * -1 means at the end. - * - * Inserts a stock item at the specified position of the toolbar. If - * @stock_id is not a known stock item ID, it's inserted verbatim, - * except that underscores used to mark mnemonics are removed. - * - * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as - * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc. - * - * Returns: the inserted widget - */ -GtkWidget* -gtk_toolbar_insert_stock (GtkToolbar *toolbar, - const gchar *stock_id, - const char *tooltip_text, - const char *tooltip_private_text, - GtkSignalFunc callback, - gpointer user_data, - gint position) -{ - return internal_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON, - NULL, stock_id, - tooltip_text, tooltip_private_text, - NULL, callback, user_data, - position, TRUE); -} - -/** - * gtk_toolbar_append_space: - * @toolbar: a #GtkToolbar. - * - * Adds a new space to the end of the toolbar. - **/ -void -gtk_toolbar_append_space (GtkToolbar *toolbar) -{ - gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE, - NULL, NULL, - NULL, NULL, - NULL, NULL, NULL, - toolbar->num_children); -} - -/** - * gtk_toolbar_prepend_space: - * @toolbar: a #GtkToolbar. - * - * Adds a new space to the beginning of the toolbar. - **/ -void -gtk_toolbar_prepend_space (GtkToolbar *toolbar) -{ - gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE, - NULL, NULL, - NULL, NULL, - NULL, NULL, NULL, - 0); -} - -/** - * gtk_toolbar_insert_space: - * @toolbar: a #GtkToolbar - * @position: the number of widgets after which a space should be inserted. - * - * Inserts a new space in the toolbar at the specified position. - **/ -void -gtk_toolbar_insert_space (GtkToolbar *toolbar, - gint position) -{ - gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE, - NULL, NULL, - NULL, NULL, - NULL, NULL, NULL, - position); -} - -/** - * gtk_toolbar_remove_space: - * @toolbar: a #GtkToolbar. - * @position: the index of the space to remove. - * - * Removes a space from the specified position. - **/ -void -gtk_toolbar_remove_space (GtkToolbar *toolbar, - gint position) -{ - GtkToolbarPrivate *priv; - ToolbarContent *content; - - g_return_if_fail (GTK_IS_TOOLBAR (toolbar)); - - if (!gtk_toolbar_check_old_api (toolbar)) - return; - - priv = GTK_TOOLBAR_GET_PRIVATE (toolbar); - - content = g_list_nth_data (priv->content, position); - - if (!content) - { - g_warning ("Toolbar position %d doesn't exist", position); - return; - } - - if (!toolbar_content_is_separator (content)) - { - g_warning ("Toolbar position %d is not a space", position); - return; - } - - toolbar_content_remove (content, toolbar); - toolbar_content_free (content); -} - -/** - * gtk_toolbar_append_widget: - * @toolbar: a #GtkToolbar. - * @widget: a #GtkWidget to add to the toolbar. - * @tooltip_text: the element's tooltip. - * @tooltip_private_text: used for context-sensitive help about this toolbar element. - * - * Adds a widget to the end of the given toolbar. - **/ -void -gtk_toolbar_append_widget (GtkToolbar *toolbar, - GtkWidget *widget, - const gchar *tooltip_text, - const gchar *tooltip_private_text) -{ - gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET, - widget, NULL, - tooltip_text, tooltip_private_text, - NULL, NULL, NULL, - toolbar->num_children); -} - -/** - * gtk_toolbar_prepend_widget: - * @toolbar: a #GtkToolbar. - * @widget: a #GtkWidget to add to the toolbar. - * @tooltip_text: the element's tooltip. - * @tooltip_private_text: used for context-sensitive help about this toolbar element. - * - * Adds a widget to the beginning of the given toolbar. - **/ -void -gtk_toolbar_prepend_widget (GtkToolbar *toolbar, - GtkWidget *widget, - const gchar *tooltip_text, - const gchar *tooltip_private_text) -{ - gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET, - widget, NULL, - tooltip_text, tooltip_private_text, - NULL, NULL, NULL, - 0); -} - -/** - * gtk_toolbar_insert_widget: - * @toolbar: a #GtkToolbar. - * @widget: a #GtkWidget to add to the toolbar. - * @tooltip_text: the element's tooltip. - * @tooltip_private_text: used for context-sensitive help about this toolbar element. - * @position: the number of widgets to insert this widget after. - * - * Inserts a widget in the toolbar at the given position. - **/ -void -gtk_toolbar_insert_widget (GtkToolbar *toolbar, - GtkWidget *widget, - const char *tooltip_text, - const char *tooltip_private_text, - gint position) -{ - gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET, - widget, NULL, - tooltip_text, tooltip_private_text, - NULL, NULL, NULL, - position); -} - -/** - * gtk_toolbar_append_element: - * @toolbar: a #GtkToolbar. - * @type: a value of type #GtkToolbarChildType that determines what @widget will be. - * @widget: a #GtkWidget, or %NULL. - * @text: the element's label. - * @tooltip_text: the element's tooltip. - * @tooltip_private_text: used for context-sensitive help about this toolbar element. - * @icon: a #GtkWidget that provides pictorial representation of the element's function. - * @callback: the function to be executed when the button is pressed. - * @user_data: any data you wish to pass to the callback. - * - * Adds a new element to the end of a toolbar. - * - * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element. - * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine - * the radio group for the new element. In all other cases, @widget must - * be %NULL. - * - * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as - * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc. - * - * Return value: the new toolbar element as a #GtkWidget. - **/ -GtkWidget* -gtk_toolbar_append_element (GtkToolbar *toolbar, - GtkToolbarChildType type, - GtkWidget *widget, - const char *text, - const char *tooltip_text, - const char *tooltip_private_text, - GtkWidget *icon, - GtkSignalFunc callback, - gpointer user_data) -{ - return gtk_toolbar_insert_element (toolbar, type, widget, text, - tooltip_text, tooltip_private_text, - icon, callback, user_data, - toolbar->num_children); -} - -/** - * gtk_toolbar_prepend_element: - * @toolbar: a #GtkToolbar. - * @type: a value of type #GtkToolbarChildType that determines what @widget will be. - * @widget: a #GtkWidget, or %NULL - * @text: the element's label. - * @tooltip_text: the element's tooltip. - * @tooltip_private_text: used for context-sensitive help about this toolbar element. - * @icon: a #GtkWidget that provides pictorial representation of the element's function. - * @callback: the function to be executed when the button is pressed. - * @user_data: any data you wish to pass to the callback. - * - * Adds a new element to the beginning of a toolbar. - * - * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element. - * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine - * the radio group for the new element. In all other cases, @widget must - * be %NULL. - * - * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as - * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc. - * - * Return value: the new toolbar element as a #GtkWidget. - **/ -GtkWidget * -gtk_toolbar_prepend_element (GtkToolbar *toolbar, - GtkToolbarChildType type, - GtkWidget *widget, - const char *text, - const char *tooltip_text, - const char *tooltip_private_text, - GtkWidget *icon, - GtkSignalFunc callback, - gpointer user_data) -{ - return gtk_toolbar_insert_element (toolbar, type, widget, text, - tooltip_text, tooltip_private_text, - icon, callback, user_data, 0); -} - -/** - * gtk_toolbar_insert_element: - * @toolbar: a #GtkToolbar. - * @type: a value of type #GtkToolbarChildType that determines what @widget - * will be. - * @widget: a #GtkWidget, or %NULL. - * @text: the element's label. - * @tooltip_text: the element's tooltip. - * @tooltip_private_text: used for context-sensitive help about this toolbar element. - * @icon: a #GtkWidget that provides pictorial representation of the element's function. - * @callback: the function to be executed when the button is pressed. - * @user_data: any data you wish to pass to the callback. - * @position: the number of widgets to insert this element after. - * - * Inserts a new element in the toolbar at the given position. - * - * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element. - * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine - * the radio group for the new element. In all other cases, @widget must - * be %NULL. - * - * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as - * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc. - * - * Return value: the new toolbar element as a #GtkWidget. - **/ -GtkWidget * -gtk_toolbar_insert_element (GtkToolbar *toolbar, - GtkToolbarChildType type, - GtkWidget *widget, - const char *text, - const char *tooltip_text, - const char *tooltip_private_text, - GtkWidget *icon, - GtkSignalFunc callback, - gpointer user_data, - gint position) -{ - return internal_insert_element (toolbar, type, widget, text, - tooltip_text, tooltip_private_text, - icon, callback, user_data, position, FALSE); -} - static void set_child_packing_and_visibility(GtkToolbar *toolbar, GtkToolbarChild *child) @@ -3725,12 +3204,13 @@ internal_insert_element (GtkToolbar *toolbar, const char *tooltip_text, const char *tooltip_private_text, GtkWidget *icon, - GtkSignalFunc callback, + GCallback callback, gpointer user_data, gint position, gboolean use_stock) { GtkWidget *box; + ToolbarContent *content; char *free_me = NULL; GtkWidget *child_widget; @@ -3836,12 +3316,13 @@ internal_insert_element (GtkToolbar *toolbar, if ((type != GTK_TOOLBAR_CHILD_SPACE) && tooltip_text) { - gtk_tooltips_set_tip (toolbar->tooltips, child_widget, - tooltip_text, tooltip_private_text); + gtk_widget_set_tooltip_text (child_widget, tooltip_text); } - if (free_me) - g_free (free_me); + content = toolbar_content_new_compatibility (toolbar, type, child_widget, + child_icon, child_label, position); + + g_free (free_me); return child_widget; } @@ -3852,7 +3333,7 @@ internal_insert_element (GtkToolbar *toolbar, typedef enum { UNKNOWN, YES, - NO, + NO } TriState; struct _ToolbarContent @@ -3869,7 +3350,7 @@ struct _ToolbarContent GtkAllocation goal_allocation; guint is_placeholder : 1; guint disappearing : 1; - TriState has_menu : 2; + guint has_menu : 2; } tool_item; struct @@ -3890,7 +3371,7 @@ toolbar_content_new_tool_item (GtkToolbar *toolbar, ToolbarContent *content; GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar); - content = g_new0 (ToolbarContent, 1); + content = g_slice_new0 (ToolbarContent); content->type = TOOL_ITEM; content->state = NOT_ALLOCATED; @@ -3914,6 +3395,54 @@ toolbar_content_new_tool_item (GtkToolbar *toolbar, return content; } +static ToolbarContent * +toolbar_content_new_compatibility (GtkToolbar *toolbar, + GtkToolbarChildType type, + GtkWidget *widget, + GtkWidget *icon, + GtkWidget *label, + gint pos) +{ + ToolbarContent *content; + GtkToolbarChild *child; + GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar); + + content = g_slice_new0 (ToolbarContent); + + child = &(content->u.compatibility.child); + + content->type = COMPATIBILITY; + child->type = type; + child->widget = widget; + child->icon = icon; + child->label = label; + + if (type != GTK_TOOLBAR_CHILD_SPACE) + { + gtk_widget_set_parent (child->widget, GTK_WIDGET (toolbar)); + } + else + { + content->u.compatibility.space_visible = TRUE; + gtk_widget_queue_resize (GTK_WIDGET (toolbar)); + } + + if (type == GTK_TOOLBAR_CHILD_BUTTON || + type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON || + type == GTK_TOOLBAR_CHILD_RADIOBUTTON) + { + set_child_packing_and_visibility (toolbar, child); + } + + priv->content = g_list_insert (priv->content, content, pos); + toolbar->children = g_list_insert (toolbar->children, child, pos); + priv->need_rebuild = TRUE; + + toolbar->num_children++; + + return content; +} + static void toolbar_content_remove (ToolbarContent *content, GtkToolbar *toolbar) @@ -3956,7 +3485,7 @@ toolbar_content_remove (ToolbarContent *content, static void toolbar_content_free (ToolbarContent *content) { - g_free (content); + g_slice_free (ToolbarContent, content); } static gint @@ -3997,13 +3526,11 @@ toolbar_content_expose (ToolbarContent *content, if (child->type == GTK_TOOLBAR_CHILD_SPACE) { - if (get_space_style (toolbar) == GTK_TOOLBAR_SPACE_LINE && - content->u.compatibility.space_visible) - { - _gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), toolbar, - &expose->area, - &content->u.compatibility.space_allocation); - } + if (content->u.compatibility.space_visible && + get_space_style (toolbar) == GTK_TOOLBAR_SPACE_LINE) + _gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), toolbar, + &expose->area, + &content->u.compatibility.space_allocation); return; } @@ -4026,27 +3553,23 @@ toolbar_content_visible (ToolbarContent *content, case TOOL_ITEM: item = content->u.tool_item.item; - if (!GTK_WIDGET_VISIBLE (item)) + if (!gtk_widget_get_visible (GTK_WIDGET (item))) return FALSE; if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL && gtk_tool_item_get_visible_horizontal (item)) - { - return TRUE; - } + return TRUE; if ((toolbar->orientation == GTK_ORIENTATION_VERTICAL && gtk_tool_item_get_visible_vertical (item))) - { - return TRUE; - } + return TRUE; return FALSE; break; case COMPATIBILITY: if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE) - return GTK_WIDGET_VISIBLE (content->u.compatibility.child.widget); + return gtk_widget_get_visible (content->u.compatibility.child.widget); else return TRUE; break; @@ -4216,6 +3739,10 @@ toolbar_content_get_goal_allocation (ToolbarContent *content, */ g_assert_not_reached (); break; + + default: + g_assert_not_reached (); + break; } } @@ -4224,7 +3751,7 @@ toolbar_content_get_allocation (ToolbarContent *content, GtkAllocation *allocation) { GtkToolbarChild *child; - + switch (content->type) { case TOOL_ITEM: @@ -4239,6 +3766,10 @@ toolbar_content_get_allocation (ToolbarContent *content, else *allocation = child->widget->allocation; break; + + default: + g_assert_not_reached (); + break; } } @@ -4525,7 +4056,7 @@ toolbar_content_toolbar_reconfigured (ToolbarContent *content, switch (content->type) { case TOOL_ITEM: - _gtk_tool_item_toolbar_reconfigured (content->u.tool_item.item); + gtk_tool_item_toolbar_reconfigured (content->u.tool_item.item); break; case COMPATIBILITY: @@ -4771,10 +4302,10 @@ _gtk_toolbar_get_default_space_size (void) } void -_gtk_toolbar_paint_space_line (GtkWidget *widget, - GtkToolbar *toolbar, - GdkRectangle *area, - GtkAllocation *allocation) +_gtk_toolbar_paint_space_line (GtkWidget *widget, + GtkToolbar *toolbar, + const GdkRectangle *area, + const GtkAllocation *allocation) { const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION); const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION); @@ -4797,7 +4328,7 @@ _gtk_toolbar_paint_space_line (GtkWidget *widget, if (wide_separators) gtk_paint_box (widget->style, widget->window, - GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT, + gtk_widget_get_state (widget), GTK_SHADOW_ETCHED_OUT, area, widget, "vseparator", allocation->x + (allocation->width - separator_width) / 2, allocation->y + allocation->height * start_fraction, @@ -4805,7 +4336,7 @@ _gtk_toolbar_paint_space_line (GtkWidget *widget, allocation->height * (end_fraction - start_fraction)); else gtk_paint_vline (widget->style, widget->window, - GTK_WIDGET_STATE (widget), area, widget, + gtk_widget_get_state (widget), area, widget, "toolbar", allocation->y + allocation->height * start_fraction, allocation->y + allocation->height * end_fraction, @@ -4823,7 +4354,7 @@ _gtk_toolbar_paint_space_line (GtkWidget *widget, if (wide_separators) gtk_paint_box (widget->style, widget->window, - GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT, + gtk_widget_get_state (widget), GTK_SHADOW_ETCHED_OUT, area, widget, "hseparator", allocation->x + allocation->width * start_fraction, allocation->y + (allocation->height - separator_height) / 2, @@ -4831,7 +4362,7 @@ _gtk_toolbar_paint_space_line (GtkWidget *widget, separator_height); else gtk_paint_hline (widget->style, widget->window, - GTK_WIDGET_STATE (widget), area, widget, + gtk_widget_get_state (widget), area, widget, "toolbar", allocation->x + allocation->width * start_fraction, allocation->x + allocation->width * end_fraction, @@ -4862,7 +4393,8 @@ _gtk_toolbar_elide_underscores (const gchar *original) else { last_underscore = FALSE; - if (*p != '_' && original + 2 <= p && p + 1 <= end && p[-2] == '(' && p[1] == ')') + if (original + 2 <= p && p + 1 <= end && + p[-2] == '(' && p[-1] == '_' && p[0] != '_' && p[1] == ')') { q--; *q = '\0'; @@ -4881,10 +4413,34 @@ _gtk_toolbar_elide_underscores (const gchar *original) return result; } -void -_gtk_toolbar_rebuild_menu (GtkToolbar *toolbar) +static GtkIconSize +toolbar_get_icon_size (GtkToolShell *shell) { - GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar); + return GTK_TOOLBAR (shell)->icon_size; +} + +static GtkOrientation +toolbar_get_orientation (GtkToolShell *shell) +{ + return GTK_TOOLBAR (shell)->orientation; +} + +static GtkToolbarStyle +toolbar_get_style (GtkToolShell *shell) +{ + return GTK_TOOLBAR (shell)->style; +} + +static GtkReliefStyle +toolbar_get_relief_style (GtkToolShell *shell) +{ + return get_button_relief (GTK_TOOLBAR (shell)); +} + +static void +toolbar_rebuild_menu (GtkToolShell *shell) +{ + GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (shell); GList *list; priv->need_rebuild = TRUE; @@ -4896,7 +4452,7 @@ _gtk_toolbar_rebuild_menu (GtkToolbar *toolbar) toolbar_content_set_unknown_menu_status (content); } - gtk_widget_queue_resize (GTK_WIDGET (toolbar)); + gtk_widget_queue_resize (GTK_WIDGET (shell)); } #define __GTK_TOOLBAR_C__