1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 * GtkToolbar copyright (C) Federico Mena
5 * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
6 * Copyright (C) 2002 James Henstridge <james@daa.com.au>
7 * Copyright (C) 2003, 2004 Soeren Sandmann <sandmann@daimi.au.dk>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
26 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
27 * file for a list of people on the GTK+ Team. See the ChangeLog
28 * files for a list of changes. These files are distributed with
29 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
32 #undef GTK_DISABLE_DEPRECATED
39 #include <gdk/gdkkeysyms.h>
42 #include "gtkbindings.h"
47 #include "gtkmarshalers.h"
49 #include "gtkorientable.h"
50 #include "gtkradiobutton.h"
51 #include "gtkradiotoolbutton.h"
52 #include "gtkseparatormenuitem.h"
53 #include "gtkseparatortoolitem.h"
55 #include "gtktoolbar.h"
56 #include "gtktoolshell.h"
58 #include "gtkprivate.h"
62 typedef struct _ToolbarContent ToolbarContent;
64 #define DEFAULT_IPADDING 0
66 #define DEFAULT_SPACE_SIZE 12
67 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
68 #define SPACE_LINE_DIVISION 10.0
69 #define SPACE_LINE_START 2.0
70 #define SPACE_LINE_END 8.0
72 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
73 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
74 #define DEFAULT_ANIMATION_STATE TRUE
76 #define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
77 * in the homogeneous game. In units of
78 * pango_font_get_estimated_char_width().
80 #define SLIDE_SPEED 600.0 /* How fast the items slide, in pixels per second */
81 #define ACCEL_THRESHOLD 0.18 /* After how much time in seconds will items start speeding up */
83 #define MIXED_API_WARNING \
84 "Mixing deprecated and non-deprecated GtkToolbar API is not allowed"
98 /* Child properties */
102 CHILD_PROP_HOMOGENEOUS
133 struct _GtkToolbarPrivate
138 GtkWidget * arrow_button;
141 GdkWindow * event_window;
143 GtkSettings * settings;
145 GtkToolItem * highlight_tool_item;
146 gint max_homogeneous_pixels;
150 gulong settings_connection;
152 guint show_arrow : 1;
154 guint is_sliding : 1;
155 guint need_rebuild : 1; /* whether the overflow menu should be regenerated */
159 static void gtk_toolbar_set_property (GObject *object,
163 static void gtk_toolbar_get_property (GObject *object,
167 static gint gtk_toolbar_expose (GtkWidget *widget,
168 GdkEventExpose *event);
169 static void gtk_toolbar_realize (GtkWidget *widget);
170 static void gtk_toolbar_unrealize (GtkWidget *widget);
171 static void gtk_toolbar_size_request (GtkWidget *widget,
172 GtkRequisition *requisition);
173 static void gtk_toolbar_size_allocate (GtkWidget *widget,
174 GtkAllocation *allocation);
175 static void gtk_toolbar_style_set (GtkWidget *widget,
176 GtkStyle *prev_style);
177 static gboolean gtk_toolbar_focus (GtkWidget *widget,
178 GtkDirectionType dir);
179 static void gtk_toolbar_move_focus (GtkWidget *widget,
180 GtkDirectionType dir);
181 static void gtk_toolbar_screen_changed (GtkWidget *widget,
182 GdkScreen *previous_screen);
183 static void gtk_toolbar_map (GtkWidget *widget);
184 static void gtk_toolbar_unmap (GtkWidget *widget);
185 static void gtk_toolbar_set_child_property (GtkContainer *container,
190 static void gtk_toolbar_get_child_property (GtkContainer *container,
195 static void gtk_toolbar_finalize (GObject *object);
196 static void gtk_toolbar_show_all (GtkWidget *widget);
197 static void gtk_toolbar_hide_all (GtkWidget *widget);
198 static void gtk_toolbar_add (GtkContainer *container,
200 static void gtk_toolbar_remove (GtkContainer *container,
202 static void gtk_toolbar_forall (GtkContainer *container,
203 gboolean include_internals,
204 GtkCallback callback,
205 gpointer callback_data);
206 static GType gtk_toolbar_child_type (GtkContainer *container);
207 static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
208 GtkOrientation orientation);
209 static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
210 GtkToolbarStyle style);
211 static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
212 gboolean focus_home);
213 static gboolean gtk_toolbar_button_press (GtkWidget *toolbar,
214 GdkEventButton *event);
215 static gboolean gtk_toolbar_arrow_button_press (GtkWidget *button,
216 GdkEventButton *event,
217 GtkToolbar *toolbar);
218 static void gtk_toolbar_arrow_button_clicked (GtkWidget *button,
219 GtkToolbar *toolbar);
220 static void gtk_toolbar_update_button_relief (GtkToolbar *toolbar);
221 static gboolean gtk_toolbar_popup_menu (GtkWidget *toolbar);
222 static GtkWidget *internal_insert_element (GtkToolbar *toolbar,
223 GtkToolbarChildType type,
226 const char *tooltip_text,
227 const char *tooltip_private_text,
233 static void gtk_toolbar_reconfigured (GtkToolbar *toolbar);
234 static gboolean gtk_toolbar_check_new_api (GtkToolbar *toolbar);
235 static gboolean gtk_toolbar_check_old_api (GtkToolbar *toolbar);
237 static GtkReliefStyle get_button_relief (GtkToolbar *toolbar);
238 static gint get_internal_padding (GtkToolbar *toolbar);
239 static gint get_max_child_expand (GtkToolbar *toolbar);
240 static GtkShadowType get_shadow_type (GtkToolbar *toolbar);
241 static gint get_space_size (GtkToolbar *toolbar);
242 static GtkToolbarSpaceStyle get_space_style (GtkToolbar *toolbar);
244 /* methods on ToolbarContent 'class' */
245 static ToolbarContent *toolbar_content_new_tool_item (GtkToolbar *toolbar,
247 gboolean is_placeholder,
249 static ToolbarContent *toolbar_content_new_compatibility (GtkToolbar *toolbar,
250 GtkToolbarChildType type,
255 static void toolbar_content_remove (ToolbarContent *content,
256 GtkToolbar *toolbar);
257 static void toolbar_content_free (ToolbarContent *content);
258 static void toolbar_content_expose (ToolbarContent *content,
259 GtkContainer *container,
260 GdkEventExpose *expose);
261 static gboolean toolbar_content_visible (ToolbarContent *content,
262 GtkToolbar *toolbar);
263 static void toolbar_content_size_request (ToolbarContent *content,
265 GtkRequisition *requisition);
266 static gboolean toolbar_content_is_homogeneous (ToolbarContent *content,
267 GtkToolbar *toolbar);
268 static gboolean toolbar_content_is_placeholder (ToolbarContent *content);
269 static gboolean toolbar_content_disappearing (ToolbarContent *content);
270 static ItemState toolbar_content_get_state (ToolbarContent *content);
271 static gboolean toolbar_content_child_visible (ToolbarContent *content);
272 static void toolbar_content_get_goal_allocation (ToolbarContent *content,
273 GtkAllocation *allocation);
274 static void toolbar_content_get_allocation (ToolbarContent *content,
275 GtkAllocation *allocation);
276 static void toolbar_content_set_start_allocation (ToolbarContent *content,
277 GtkAllocation *new_start_allocation);
278 static void toolbar_content_get_start_allocation (ToolbarContent *content,
279 GtkAllocation *start_allocation);
280 static gboolean toolbar_content_get_expand (ToolbarContent *content);
281 static void toolbar_content_set_goal_allocation (ToolbarContent *content,
282 GtkAllocation *allocation);
283 static void toolbar_content_set_child_visible (ToolbarContent *content,
286 static void toolbar_content_size_allocate (ToolbarContent *content,
287 GtkAllocation *allocation);
288 static void toolbar_content_set_state (ToolbarContent *content,
289 ItemState new_state);
290 static GtkWidget * toolbar_content_get_widget (ToolbarContent *content);
291 static void toolbar_content_set_disappearing (ToolbarContent *content,
292 gboolean disappearing);
293 static void toolbar_content_set_size_request (ToolbarContent *content,
296 static void toolbar_content_toolbar_reconfigured (ToolbarContent *content,
297 GtkToolbar *toolbar);
298 static GtkWidget * toolbar_content_retrieve_menu_item (ToolbarContent *content);
299 static gboolean toolbar_content_has_proxy_menu_item (ToolbarContent *content);
300 static gboolean toolbar_content_is_separator (ToolbarContent *content);
301 static void toolbar_content_show_all (ToolbarContent *content);
302 static void toolbar_content_hide_all (ToolbarContent *content);
303 static void toolbar_content_set_expand (ToolbarContent *content,
306 static void toolbar_tool_shell_iface_init (GtkToolShellIface *iface);
307 static GtkIconSize toolbar_get_icon_size (GtkToolShell *shell);
308 static GtkOrientation toolbar_get_orientation (GtkToolShell *shell);
309 static GtkToolbarStyle toolbar_get_style (GtkToolShell *shell);
310 static GtkReliefStyle toolbar_get_relief_style (GtkToolShell *shell);
311 static void toolbar_rebuild_menu (GtkToolShell *shell);
313 #define GTK_TOOLBAR_GET_PRIVATE(o) \
314 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOLBAR, GtkToolbarPrivate))
317 G_DEFINE_TYPE_WITH_CODE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER,
318 G_IMPLEMENT_INTERFACE (GTK_TYPE_TOOL_SHELL,
319 toolbar_tool_shell_iface_init)
320 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
323 static guint toolbar_signals[LAST_SIGNAL] = { 0 };
327 add_arrow_bindings (GtkBindingSet *binding_set,
329 GtkDirectionType dir)
331 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
333 gtk_binding_entry_add_signal (binding_set, keysym, 0,
335 GTK_TYPE_DIRECTION_TYPE, dir);
336 gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
338 GTK_TYPE_DIRECTION_TYPE, dir);
342 add_ctrl_tab_bindings (GtkBindingSet *binding_set,
343 GdkModifierType modifiers,
344 GtkDirectionType direction)
346 gtk_binding_entry_add_signal (binding_set,
347 GDK_Tab, GDK_CONTROL_MASK | modifiers,
349 GTK_TYPE_DIRECTION_TYPE, direction);
350 gtk_binding_entry_add_signal (binding_set,
351 GDK_KP_Tab, GDK_CONTROL_MASK | modifiers,
353 GTK_TYPE_DIRECTION_TYPE, direction);
357 gtk_toolbar_class_init (GtkToolbarClass *klass)
359 GObjectClass *gobject_class;
360 GtkWidgetClass *widget_class;
361 GtkContainerClass *container_class;
362 GtkBindingSet *binding_set;
364 gobject_class = (GObjectClass *)klass;
365 widget_class = (GtkWidgetClass *)klass;
366 container_class = (GtkContainerClass *)klass;
368 gobject_class->set_property = gtk_toolbar_set_property;
369 gobject_class->get_property = gtk_toolbar_get_property;
370 gobject_class->finalize = gtk_toolbar_finalize;
372 widget_class->button_press_event = gtk_toolbar_button_press;
373 widget_class->expose_event = gtk_toolbar_expose;
374 widget_class->size_request = gtk_toolbar_size_request;
375 widget_class->size_allocate = gtk_toolbar_size_allocate;
376 widget_class->style_set = gtk_toolbar_style_set;
377 widget_class->focus = gtk_toolbar_focus;
379 /* need to override the base class function via override_class_handler,
380 * because the signal slot is not available in GtkWidgetClass
382 g_signal_override_class_handler ("move-focus",
384 G_CALLBACK (gtk_toolbar_move_focus));
386 widget_class->screen_changed = gtk_toolbar_screen_changed;
387 widget_class->realize = gtk_toolbar_realize;
388 widget_class->unrealize = gtk_toolbar_unrealize;
389 widget_class->map = gtk_toolbar_map;
390 widget_class->unmap = gtk_toolbar_unmap;
391 widget_class->popup_menu = gtk_toolbar_popup_menu;
392 widget_class->show_all = gtk_toolbar_show_all;
393 widget_class->hide_all = gtk_toolbar_hide_all;
395 container_class->add = gtk_toolbar_add;
396 container_class->remove = gtk_toolbar_remove;
397 container_class->forall = gtk_toolbar_forall;
398 container_class->child_type = gtk_toolbar_child_type;
399 container_class->get_child_property = gtk_toolbar_get_child_property;
400 container_class->set_child_property = gtk_toolbar_set_child_property;
402 klass->orientation_changed = gtk_toolbar_orientation_changed;
403 klass->style_changed = gtk_toolbar_real_style_changed;
406 * GtkToolbar::orientation-changed:
407 * @toolbar: the object which emitted the signal
408 * @orientation: the new #GtkOrientation of the toolbar
410 * Emitted when the orientation of the toolbar changes.
412 toolbar_signals[ORIENTATION_CHANGED] =
413 g_signal_new (I_("orientation-changed"),
414 G_OBJECT_CLASS_TYPE (klass),
416 G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
418 g_cclosure_marshal_VOID__ENUM,
420 GTK_TYPE_ORIENTATION);
422 * GtkToolbar::style-changed:
423 * @toolbar: The #GtkToolbar which emitted the signal
424 * @style: the new #GtkToolbarStyle of the toolbar
426 * Emitted when the style of the toolbar changes.
428 toolbar_signals[STYLE_CHANGED] =
429 g_signal_new (I_("style-changed"),
430 G_OBJECT_CLASS_TYPE (klass),
432 G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
434 g_cclosure_marshal_VOID__ENUM,
436 GTK_TYPE_TOOLBAR_STYLE);
438 * GtkToolbar::popup-context-menu:
439 * @toolbar: the #GtkToolbar which emitted the signal
440 * @x: the x coordinate of the point where the menu should appear
441 * @y: the y coordinate of the point where the menu should appear
442 * @button: the mouse button the user pressed, or -1
444 * Emitted when the user right-clicks the toolbar or uses the
445 * keybinding to display a popup menu.
447 * Application developers should handle this signal if they want
448 * to display a context menu on the toolbar. The context-menu should
449 * appear at the coordinates given by @x and @y. The mouse button
450 * number is given by the @button parameter. If the menu was popped
451 * up using the keybaord, @button is -1.
453 * Return value: return %TRUE if the signal was handled, %FALSE if not
455 toolbar_signals[POPUP_CONTEXT_MENU] =
456 g_signal_new (I_("popup-context-menu"),
457 G_OBJECT_CLASS_TYPE (klass),
459 G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
460 _gtk_boolean_handled_accumulator, NULL,
461 _gtk_marshal_BOOLEAN__INT_INT_INT,
463 G_TYPE_INT, G_TYPE_INT,
467 * GtkToolbar::focus-home-or-end:
468 * @toolbar: the #GtkToolbar which emitted the signal
469 * @focus_home: %TRUE if the first item should be focused
471 * A keybinding signal used internally by GTK+. This signal can't
472 * be used in application code
474 * Return value: %TRUE if the signal was handled, %FALSE if not
476 toolbar_signals[FOCUS_HOME_OR_END] =
477 g_signal_new_class_handler (I_("focus-home-or-end"),
478 G_OBJECT_CLASS_TYPE (klass),
479 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
480 G_CALLBACK (gtk_toolbar_focus_home_or_end),
482 _gtk_marshal_BOOLEAN__BOOLEAN,
487 g_object_class_override_property (gobject_class,
491 g_object_class_install_property (gobject_class,
493 g_param_spec_enum ("toolbar-style",
495 P_("How to draw the toolbar"),
496 GTK_TYPE_TOOLBAR_STYLE,
497 DEFAULT_TOOLBAR_STYLE,
498 GTK_PARAM_READWRITE));
499 g_object_class_install_property (gobject_class,
501 g_param_spec_boolean ("show-arrow",
503 P_("If an arrow should be shown if the toolbar doesn't fit"),
505 GTK_PARAM_READWRITE));
509 * GtkToolbar:tooltips:
511 * If the tooltips of the toolbar should be active or not.
515 g_object_class_install_property (gobject_class,
517 g_param_spec_boolean ("tooltips",
519 P_("If the tooltips of the toolbar should be active or not"),
521 GTK_PARAM_READWRITE));
525 * GtkToolbar:icon-size:
527 * The size of the icons in a toolbar is normally determined by
528 * the toolbar-icon-size setting. When this property is set, it
529 * overrides the setting.
531 * This should only be used for special-purpose toolbars, normal
532 * application toolbars should respect the user preferences for the
537 g_object_class_install_property (gobject_class,
539 g_param_spec_int ("icon-size",
541 P_("Size of icons in this toolbar"),
544 GTK_PARAM_READWRITE));
547 * GtkToolbar:icon-size-set:
549 * Is %TRUE if the icon-size property has been set.
553 g_object_class_install_property (gobject_class,
555 g_param_spec_boolean ("icon-size-set",
557 P_("Whether the icon-size property has been set"),
559 GTK_PARAM_READWRITE));
561 /* child properties */
562 gtk_container_class_install_child_property (container_class,
564 g_param_spec_boolean ("expand",
566 P_("Whether the item should receive extra space when the toolbar grows"),
568 GTK_PARAM_READWRITE));
570 gtk_container_class_install_child_property (container_class,
571 CHILD_PROP_HOMOGENEOUS,
572 g_param_spec_boolean ("homogeneous",
574 P_("Whether the item should be the same size as other homogeneous items"),
576 GTK_PARAM_READWRITE));
578 /* style properties */
579 gtk_widget_class_install_style_property (widget_class,
580 g_param_spec_int ("space-size",
582 P_("Size of spacers"),
586 GTK_PARAM_READABLE));
588 gtk_widget_class_install_style_property (widget_class,
589 g_param_spec_int ("internal-padding",
590 P_("Internal padding"),
591 P_("Amount of border space between the toolbar shadow and the buttons"),
595 GTK_PARAM_READABLE));
597 gtk_widget_class_install_style_property (widget_class,
598 g_param_spec_int ("max-child-expand",
599 P_("Maximum child expand"),
600 P_("Maximum amount of space an expandable item will be given"),
604 GTK_PARAM_READABLE));
606 gtk_widget_class_install_style_property (widget_class,
607 g_param_spec_enum ("space-style",
609 P_("Whether spacers are vertical lines or just blank"),
610 GTK_TYPE_TOOLBAR_SPACE_STYLE,
612 GTK_PARAM_READABLE));
614 gtk_widget_class_install_style_property (widget_class,
615 g_param_spec_enum ("button-relief",
617 P_("Type of bevel around toolbar buttons"),
618 GTK_TYPE_RELIEF_STYLE,
620 GTK_PARAM_READABLE));
621 gtk_widget_class_install_style_property (widget_class,
622 g_param_spec_enum ("shadow-type",
624 P_("Style of bevel around the toolbar"),
625 GTK_TYPE_SHADOW_TYPE,
627 GTK_PARAM_READABLE));
629 gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-style",
631 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
632 GTK_TYPE_TOOLBAR_STYLE,
633 DEFAULT_TOOLBAR_STYLE,
634 GTK_PARAM_READWRITE));
636 gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-icon-size",
637 P_("Toolbar icon size"),
638 P_("Size of icons in default toolbars"),
641 GTK_PARAM_READWRITE));
643 binding_set = gtk_binding_set_by_class (klass);
645 add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
646 add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
647 add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
648 add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
650 gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, 0,
651 "focus-home-or-end", 1,
652 G_TYPE_BOOLEAN, TRUE);
653 gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
654 "focus-home-or-end", 1,
655 G_TYPE_BOOLEAN, TRUE);
656 gtk_binding_entry_add_signal (binding_set, GDK_KP_End, 0,
657 "focus-home-or-end", 1,
658 G_TYPE_BOOLEAN, FALSE);
659 gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
660 "focus-home-or-end", 1,
661 G_TYPE_BOOLEAN, FALSE);
663 add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
664 add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
666 g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));
670 toolbar_tool_shell_iface_init (GtkToolShellIface *iface)
672 iface->get_icon_size = toolbar_get_icon_size;
673 iface->get_orientation = toolbar_get_orientation;
674 iface->get_style = toolbar_get_style;
675 iface->get_relief_style = toolbar_get_relief_style;
676 iface->rebuild_menu = toolbar_rebuild_menu;
680 gtk_toolbar_init (GtkToolbar *toolbar)
682 GtkToolbarPrivate *priv;
684 GTK_WIDGET_UNSET_FLAGS (toolbar, GTK_CAN_FOCUS);
685 GTK_WIDGET_SET_FLAGS (toolbar, GTK_NO_WINDOW);
687 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
689 toolbar->orientation = GTK_ORIENTATION_HORIZONTAL;
690 toolbar->style = DEFAULT_TOOLBAR_STYLE;
691 toolbar->icon_size = DEFAULT_ICON_SIZE;
692 priv->animation = DEFAULT_ANIMATION_STATE;
693 toolbar->tooltips = gtk_tooltips_new ();
694 g_object_ref_sink (toolbar->tooltips);
696 priv->arrow_button = gtk_toggle_button_new ();
697 g_signal_connect (priv->arrow_button, "button-press-event",
698 G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar);
699 g_signal_connect (priv->arrow_button, "clicked",
700 G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar);
701 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
702 get_button_relief (toolbar));
704 priv->api_mode = DONT_KNOW;
706 gtk_button_set_focus_on_click (GTK_BUTTON (priv->arrow_button), FALSE);
708 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
709 gtk_widget_set_name (priv->arrow, "gtk-toolbar-arrow");
710 gtk_widget_show (priv->arrow);
711 gtk_container_add (GTK_CONTAINER (priv->arrow_button), priv->arrow);
713 gtk_widget_set_parent (priv->arrow_button, GTK_WIDGET (toolbar));
715 /* which child position a drop will occur at */
717 priv->show_arrow = TRUE;
718 priv->settings = NULL;
720 priv->max_homogeneous_pixels = -1;
722 priv->timer = g_timer_new ();
726 gtk_toolbar_set_property (GObject *object,
731 GtkToolbar *toolbar = GTK_TOOLBAR (object);
735 case PROP_ORIENTATION:
736 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0,
737 g_value_get_enum (value));
739 case PROP_TOOLBAR_STYLE:
740 gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
742 case PROP_SHOW_ARROW:
743 gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
746 gtk_toolbar_set_tooltips (toolbar, g_value_get_boolean (value));
749 gtk_toolbar_set_icon_size (toolbar, g_value_get_int (value));
751 case PROP_ICON_SIZE_SET:
752 if (g_value_get_boolean (value))
753 toolbar->icon_size_set = TRUE;
755 gtk_toolbar_unset_icon_size (toolbar);
758 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
764 gtk_toolbar_get_property (GObject *object,
769 GtkToolbar *toolbar = GTK_TOOLBAR (object);
770 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
774 case PROP_ORIENTATION:
775 g_value_set_enum (value, toolbar->orientation);
777 case PROP_TOOLBAR_STYLE:
778 g_value_set_enum (value, toolbar->style);
780 case PROP_SHOW_ARROW:
781 g_value_set_boolean (value, priv->show_arrow);
784 g_value_set_boolean (value, gtk_toolbar_get_tooltips (toolbar));
787 g_value_set_int (value, gtk_toolbar_get_icon_size (toolbar));
789 case PROP_ICON_SIZE_SET:
790 g_value_set_boolean (value, toolbar->icon_size_set);
793 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
799 gtk_toolbar_map (GtkWidget *widget)
801 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
803 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->map (widget);
805 if (priv->event_window)
806 gdk_window_show_unraised (priv->event_window);
810 gtk_toolbar_unmap (GtkWidget *widget)
812 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
814 if (priv->event_window)
815 gdk_window_hide (priv->event_window);
817 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unmap (widget);
821 gtk_toolbar_realize (GtkWidget *widget)
823 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
824 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
826 GdkWindowAttr attributes;
827 gint attributes_mask;
830 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
832 border_width = GTK_CONTAINER (widget)->border_width;
834 attributes.wclass = GDK_INPUT_ONLY;
835 attributes.window_type = GDK_WINDOW_CHILD;
836 attributes.x = widget->allocation.x + border_width;
837 attributes.y = widget->allocation.y + border_width;
838 attributes.width = widget->allocation.width - border_width * 2;
839 attributes.height = widget->allocation.height - border_width * 2;
840 attributes.event_mask = gtk_widget_get_events (widget);
841 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
842 GDK_BUTTON_RELEASE_MASK |
843 GDK_ENTER_NOTIFY_MASK |
844 GDK_LEAVE_NOTIFY_MASK);
846 attributes_mask = GDK_WA_X | GDK_WA_Y;
848 widget->window = gtk_widget_get_parent_window (widget);
849 g_object_ref (widget->window);
850 widget->style = gtk_style_attach (widget->style, widget->window);
852 priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
853 &attributes, attributes_mask);
854 gdk_window_set_user_data (priv->event_window, toolbar);
858 gtk_toolbar_unrealize (GtkWidget *widget)
860 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
862 if (priv->event_window)
864 gdk_window_set_user_data (priv->event_window, NULL);
865 gdk_window_destroy (priv->event_window);
866 priv->event_window = NULL;
869 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize (widget);
873 gtk_toolbar_expose (GtkWidget *widget,
874 GdkEventExpose *event)
876 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
877 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
882 border_width = GTK_CONTAINER (widget)->border_width;
884 if (GTK_WIDGET_DRAWABLE (widget))
886 gtk_paint_box (widget->style,
888 GTK_WIDGET_STATE (widget),
889 get_shadow_type (toolbar),
890 &event->area, widget, "toolbar",
891 border_width + widget->allocation.x,
892 border_width + widget->allocation.y,
893 widget->allocation.width - 2 * border_width,
894 widget->allocation.height - 2 * border_width);
897 for (list = priv->content; list != NULL; list = list->next)
899 ToolbarContent *content = list->data;
901 toolbar_content_expose (content, GTK_CONTAINER (widget), event);
904 gtk_container_propagate_expose (GTK_CONTAINER (widget),
912 gtk_toolbar_size_request (GtkWidget *widget,
913 GtkRequisition *requisition)
915 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
916 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
918 gint max_child_height;
919 gint max_child_width;
920 gint max_homogeneous_child_width;
921 gint max_homogeneous_child_height;
922 gint homogeneous_size;
924 gint pack_front_size;
926 GtkRequisition arrow_requisition;
928 max_homogeneous_child_width = 0;
929 max_homogeneous_child_height = 0;
931 max_child_height = 0;
932 for (list = priv->content; list != NULL; list = list->next)
934 GtkRequisition requisition;
935 ToolbarContent *content = list->data;
937 if (!toolbar_content_visible (content, toolbar))
940 toolbar_content_size_request (content, toolbar, &requisition);
942 max_child_width = MAX (max_child_width, requisition.width);
943 max_child_height = MAX (max_child_height, requisition.height);
945 if (toolbar_content_is_homogeneous (content, toolbar))
947 max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
948 max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
952 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
953 homogeneous_size = max_homogeneous_child_width;
955 homogeneous_size = max_homogeneous_child_height;
958 for (list = priv->content; list != NULL; list = list->next)
960 ToolbarContent *content = list->data;
963 if (!toolbar_content_visible (content, toolbar))
966 if (toolbar_content_is_homogeneous (content, toolbar))
968 size = homogeneous_size;
972 GtkRequisition requisition;
974 toolbar_content_size_request (content, toolbar, &requisition);
976 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
977 size = requisition.width;
979 size = requisition.height;
982 pack_front_size += size;
985 if (priv->show_arrow && priv->api_mode == NEW_API)
987 gtk_widget_size_request (priv->arrow_button, &arrow_requisition);
989 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
990 long_req = arrow_requisition.width;
992 long_req = arrow_requisition.height;
994 /* There is no point requesting space for the arrow if that would take
995 * up more space than all the items combined
997 long_req = MIN (long_req, pack_front_size);
1001 arrow_requisition.height = 0;
1002 arrow_requisition.width = 0;
1004 long_req = pack_front_size;
1007 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1009 requisition->width = long_req;
1010 requisition->height = MAX (max_child_height, arrow_requisition.height);
1014 requisition->height = long_req;
1015 requisition->width = MAX (max_child_width, arrow_requisition.width);
1019 ipadding = get_internal_padding (toolbar);
1021 requisition->width += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
1022 requisition->height += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
1024 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1026 requisition->width += 2 * widget->style->xthickness;
1027 requisition->height += 2 * widget->style->ythickness;
1030 toolbar->button_maxw = max_homogeneous_child_width;
1031 toolbar->button_maxh = max_homogeneous_child_height;
1035 position (GtkToolbar *toolbar,
1042 if (! GTK_TOOLBAR_GET_PRIVATE (toolbar)->animation)
1045 if (elapsed <= ACCEL_THRESHOLD)
1047 n_pixels = SLIDE_SPEED * elapsed;
1051 /* The formula is a second degree polynomial in
1052 * @elapsed that has the line SLIDE_SPEED * @elapsed
1053 * as tangent for @elapsed == ACCEL_THRESHOLD.
1054 * This makes @n_pixels a smooth function of elapsed time.
1056 n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
1057 SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
1061 return MIN (from + n_pixels, to);
1063 return MAX (from - n_pixels, to);
1067 compute_intermediate_allocation (GtkToolbar *toolbar,
1068 const GtkAllocation *start,
1069 const GtkAllocation *goal,
1070 GtkAllocation *intermediate)
1072 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1073 gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
1075 intermediate->x = position (toolbar, start->x, goal->x, elapsed);
1076 intermediate->y = position (toolbar, start->y, goal->y, elapsed);
1077 intermediate->width = position (toolbar, start->x + start->width,
1078 goal->x + goal->width,
1079 elapsed) - intermediate->x;
1080 intermediate->height = position (toolbar, start->y + start->height,
1081 goal->y + goal->height,
1082 elapsed) - intermediate->y;
1086 fixup_allocation_for_rtl (gint total_size,
1087 GtkAllocation *allocation)
1089 allocation->x += (total_size - (2 * allocation->x + allocation->width));
1093 fixup_allocation_for_vertical (GtkAllocation *allocation)
1097 tmp = allocation->x;
1098 allocation->x = allocation->y;
1099 allocation->y = tmp;
1101 tmp = allocation->width;
1102 allocation->width = allocation->height;
1103 allocation->height = tmp;
1107 get_item_size (GtkToolbar *toolbar,
1108 ToolbarContent *content)
1110 GtkRequisition requisition;
1112 toolbar_content_size_request (content, toolbar, &requisition);
1114 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1116 if (toolbar_content_is_homogeneous (content, toolbar))
1117 return toolbar->button_maxw;
1119 return requisition.width;
1123 if (toolbar_content_is_homogeneous (content, toolbar))
1124 return toolbar->button_maxh;
1126 return requisition.height;
1131 slide_idle_handler (gpointer data)
1133 GtkToolbar *toolbar = data;
1134 GtkToolbarPrivate *priv;
1137 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1139 if (priv->need_sync)
1142 priv->need_sync = FALSE;
1145 for (list = priv->content; list != NULL; list = list->next)
1147 ToolbarContent *content = list->data;
1149 GtkAllocation goal_allocation;
1150 GtkAllocation allocation;
1153 state = toolbar_content_get_state (content);
1154 toolbar_content_get_goal_allocation (content, &goal_allocation);
1155 toolbar_content_get_allocation (content, &allocation);
1159 if (state == NOT_ALLOCATED)
1161 /* an unallocated item means that size allocate has to
1162 * called at least once more
1167 /* An invisible item with a goal allocation of
1168 * 0 is already at its goal.
1170 if ((state == NORMAL || state == OVERFLOWN) &&
1171 ((goal_allocation.width != 0 &&
1172 goal_allocation.height != 0) ||
1173 toolbar_content_child_visible (content)))
1175 if ((goal_allocation.x != allocation.x ||
1176 goal_allocation.y != allocation.y ||
1177 goal_allocation.width != allocation.width ||
1178 goal_allocation.height != allocation.height))
1180 /* An item is not in its right position yet. Note
1181 * that OVERFLOWN items do get an allocation in
1182 * gtk_toolbar_size_allocate(). This way you can see
1183 * them slide back in when you drag an item off the
1190 if (toolbar_content_is_placeholder (content) &&
1191 toolbar_content_disappearing (content) &&
1192 toolbar_content_child_visible (content))
1194 /* A disappearing placeholder is still visible.
1202 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1208 priv->is_sliding = FALSE;
1215 rect_within (GtkAllocation *a1,
1218 return (a1->x >= a2->x &&
1219 a1->x + a1->width <= a2->x + a2->width &&
1221 a1->y + a1->height <= a2->y + a2->height);
1225 gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
1227 GtkWidget *widget = GTK_WIDGET (toolbar);
1228 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1236 /* Start the sliding. This function copies the allocation of every
1237 * item into content->start_allocation. For items that haven't
1238 * been allocated yet, we calculate their position and save that
1239 * in start_allocatino along with zero width and zero height.
1241 * FIXME: It would be nice if we could share this code with
1242 * the equivalent in gtk_widget_size_allocate().
1244 priv->is_sliding = TRUE;
1247 priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
1249 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1250 vertical = (toolbar->orientation == GTK_ORIENTATION_VERTICAL);
1251 border_width = get_internal_padding (toolbar) + GTK_CONTAINER (toolbar)->border_width;
1255 cur_x = widget->allocation.width - border_width - widget->style->xthickness;
1256 cur_y = widget->allocation.height - border_width - widget->style->ythickness;
1260 cur_x = border_width + widget->style->xthickness;
1261 cur_y = border_width + widget->style->ythickness;
1264 cur_x += widget->allocation.x;
1265 cur_y += widget->allocation.y;
1267 for (list = priv->content; list != NULL; list = list->next)
1269 ToolbarContent *content = list->data;
1270 GtkAllocation new_start_allocation;
1271 GtkAllocation item_allocation;
1274 state = toolbar_content_get_state (content);
1275 toolbar_content_get_allocation (content, &item_allocation);
1277 if ((state == NORMAL &&
1278 rect_within (&item_allocation, &(widget->allocation))) ||
1281 new_start_allocation = item_allocation;
1285 new_start_allocation.x = cur_x;
1286 new_start_allocation.y = cur_y;
1290 new_start_allocation.width = widget->allocation.width -
1291 2 * border_width - 2 * widget->style->xthickness;
1292 new_start_allocation.height = 0;
1296 new_start_allocation.width = 0;
1297 new_start_allocation.height = widget->allocation.height -
1298 2 * border_width - 2 * widget->style->ythickness;
1303 cur_y = new_start_allocation.y + new_start_allocation.height;
1305 cur_x = new_start_allocation.x;
1307 cur_x = new_start_allocation.x + new_start_allocation.width;
1309 toolbar_content_set_start_allocation (content, &new_start_allocation);
1312 /* This resize will run before the first idle handler. This
1313 * will make sure that items get the right goal allocation
1314 * so that the idle handler will not immediately return
1317 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1318 g_timer_reset (priv->timer);
1322 gtk_toolbar_stop_sliding (GtkToolbar *toolbar)
1324 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1326 if (priv->is_sliding)
1330 priv->is_sliding = FALSE;
1334 g_source_remove (priv->idle_id);
1338 list = priv->content;
1341 ToolbarContent *content = list->data;
1344 if (toolbar_content_is_placeholder (content))
1346 toolbar_content_remove (content, toolbar);
1347 toolbar_content_free (content);
1351 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1356 remove_item (GtkWidget *menu_item,
1359 gtk_container_remove (GTK_CONTAINER (menu_item->parent), menu_item);
1363 menu_deactivated (GtkWidget *menu,
1364 GtkToolbar *toolbar)
1366 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1367 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->arrow_button), FALSE);
1371 menu_detached (GtkWidget *toolbar,
1374 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1379 rebuild_menu (GtkToolbar *toolbar)
1381 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1382 GList *list, *children;
1386 priv->menu = GTK_MENU (gtk_menu_new());
1387 gtk_menu_attach_to_widget (priv->menu,
1388 GTK_WIDGET (toolbar),
1391 g_signal_connect (priv->menu, "deactivate",
1392 G_CALLBACK (menu_deactivated), toolbar);
1395 gtk_container_foreach (GTK_CONTAINER (priv->menu), remove_item, NULL);
1397 for (list = priv->content; list != NULL; list = list->next)
1399 ToolbarContent *content = list->data;
1401 if (toolbar_content_get_state (content) == OVERFLOWN &&
1402 !toolbar_content_is_placeholder (content))
1404 GtkWidget *menu_item = toolbar_content_retrieve_menu_item (content);
1408 g_assert (GTK_IS_MENU_ITEM (menu_item));
1409 gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item);
1414 /* Remove leading and trailing separator items */
1415 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1418 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1420 GtkWidget *child = list->data;
1422 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1425 g_list_free (children);
1427 /* Regenerate the list of children so we don't try to remove items twice */
1428 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1430 list = g_list_last (children);
1431 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1433 GtkWidget *child = list->data;
1435 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1438 g_list_free (children);
1440 priv->need_rebuild = FALSE;
1444 gtk_toolbar_size_allocate (GtkWidget *widget,
1445 GtkAllocation *allocation)
1447 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1448 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1449 GtkAllocation *allocations;
1450 ItemState *new_states;
1451 GtkAllocation arrow_allocation;
1453 gint size, pos, short_size;
1456 gboolean need_arrow;
1457 gint n_expand_items;
1459 gint available_size;
1462 GtkRequisition arrow_requisition;
1463 gboolean overflowing;
1464 gboolean size_changed;
1466 GtkAllocation item_area;
1467 GtkShadowType shadow_type;
1469 size_changed = FALSE;
1470 if (widget->allocation.x != allocation->x ||
1471 widget->allocation.y != allocation->y ||
1472 widget->allocation.width != allocation->width ||
1473 widget->allocation.height != allocation->height)
1475 size_changed = TRUE;
1479 gtk_toolbar_stop_sliding (toolbar);
1481 widget->allocation = *allocation;
1483 border_width = GTK_CONTAINER (toolbar)->border_width;
1485 if (GTK_WIDGET_REALIZED (widget))
1487 gdk_window_move_resize (priv->event_window,
1488 allocation->x + border_width,
1489 allocation->y + border_width,
1490 allocation->width - border_width * 2,
1491 allocation->height - border_width * 2);
1494 border_width += get_internal_padding (toolbar);
1496 gtk_widget_get_child_requisition (GTK_WIDGET (priv->arrow_button),
1497 &arrow_requisition);
1499 shadow_type = get_shadow_type (toolbar);
1501 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1503 available_size = size = allocation->width - 2 * border_width;
1504 short_size = allocation->height - 2 * border_width;
1505 arrow_size = arrow_requisition.width;
1507 if (shadow_type != GTK_SHADOW_NONE)
1509 available_size -= 2 * widget->style->xthickness;
1510 short_size -= 2 * widget->style->ythickness;
1515 available_size = size = allocation->height - 2 * border_width;
1516 short_size = allocation->width - 2 * border_width;
1517 arrow_size = arrow_requisition.height;
1519 if (shadow_type != GTK_SHADOW_NONE)
1521 available_size -= 2 * widget->style->ythickness;
1522 short_size -= 2 * widget->style->xthickness;
1526 n_items = g_list_length (priv->content);
1527 allocations = g_new0 (GtkAllocation, n_items);
1528 new_states = g_new0 (ItemState, n_items);
1532 for (list = priv->content; list != NULL; list = list->next)
1534 ToolbarContent *content = list->data;
1536 if (toolbar_content_visible (content, toolbar))
1538 needed_size += get_item_size (toolbar, content);
1540 /* Do we need an arrow?
1542 * Assume we don't, and see if any non-separator item with a
1543 * proxy menu item is then going to overflow.
1545 if (needed_size > available_size &&
1548 priv->api_mode == NEW_API &&
1549 toolbar_content_has_proxy_menu_item (content) &&
1550 !toolbar_content_is_separator (content))
1558 size = available_size - arrow_size;
1560 size = available_size;
1562 /* calculate widths and states of items */
1563 overflowing = FALSE;
1564 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1566 ToolbarContent *content = list->data;
1569 if (!toolbar_content_visible (content, toolbar))
1571 new_states[i] = HIDDEN;
1575 item_size = get_item_size (toolbar, content);
1576 if (item_size <= size && !overflowing)
1579 allocations[i].width = item_size;
1580 new_states[i] = NORMAL;
1585 new_states[i] = OVERFLOWN;
1586 allocations[i].width = item_size;
1590 /* calculate width of arrow */
1593 arrow_allocation.width = arrow_size;
1594 arrow_allocation.height = MAX (short_size, 1);
1597 /* expand expandable items */
1599 /* We don't expand when there is an overflow menu, because that leads to
1600 * weird jumps when items get moved to the overflow menu and the expanding
1601 * items suddenly get a lot of extra space
1605 gint max_child_expand;
1608 for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
1610 ToolbarContent *content = list->data;
1612 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1616 max_child_expand = get_max_child_expand (toolbar);
1617 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1619 ToolbarContent *content = list->data;
1621 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1623 gint extra = size / n_expand_items;
1624 if (size % n_expand_items != 0)
1627 if (extra > max_child_expand)
1628 extra = max_child_expand;
1630 allocations[i].width += extra;
1636 g_assert (n_expand_items == 0);
1639 /* position items */
1641 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1643 /* both NORMAL and OVERFLOWN items get a position. This ensures
1644 * that sliding will work for OVERFLOWN items too
1646 if (new_states[i] == NORMAL ||
1647 new_states[i] == OVERFLOWN)
1649 allocations[i].x = pos;
1650 allocations[i].y = border_width;
1651 allocations[i].height = short_size;
1653 pos += allocations[i].width;
1657 /* position arrow */
1660 arrow_allocation.x = available_size - border_width - arrow_allocation.width;
1661 arrow_allocation.y = border_width;
1664 item_area.x = border_width;
1665 item_area.y = border_width;
1666 item_area.width = available_size - (need_arrow? arrow_size : 0);
1667 item_area.height = short_size;
1669 /* fix up allocations in the vertical or RTL cases */
1670 if (toolbar->orientation == GTK_ORIENTATION_VERTICAL)
1672 for (i = 0; i < n_items; ++i)
1673 fixup_allocation_for_vertical (&(allocations[i]));
1676 fixup_allocation_for_vertical (&arrow_allocation);
1678 fixup_allocation_for_vertical (&item_area);
1680 else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1682 for (i = 0; i < n_items; ++i)
1683 fixup_allocation_for_rtl (available_size, &(allocations[i]));
1686 fixup_allocation_for_rtl (available_size, &arrow_allocation);
1688 fixup_allocation_for_rtl (available_size, &item_area);
1691 /* translate the items by allocation->(x,y) */
1692 for (i = 0; i < n_items; ++i)
1694 allocations[i].x += allocation->x;
1695 allocations[i].y += allocation->y;
1697 if (shadow_type != GTK_SHADOW_NONE)
1699 allocations[i].x += widget->style->xthickness;
1700 allocations[i].y += widget->style->ythickness;
1706 arrow_allocation.x += allocation->x;
1707 arrow_allocation.y += allocation->y;
1709 if (shadow_type != GTK_SHADOW_NONE)
1711 arrow_allocation.x += widget->style->xthickness;
1712 arrow_allocation.y += widget->style->ythickness;
1716 item_area.x += allocation->x;
1717 item_area.y += allocation->y;
1718 if (shadow_type != GTK_SHADOW_NONE)
1720 item_area.x += widget->style->xthickness;
1721 item_area.y += widget->style->ythickness;
1724 /* did anything change? */
1725 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1727 ToolbarContent *content = list->data;
1729 if (toolbar_content_get_state (content) == NORMAL &&
1730 new_states[i] != NORMAL)
1732 /* an item disappeared and we didn't change size, so begin sliding */
1733 if (!size_changed && priv->api_mode == NEW_API)
1734 gtk_toolbar_begin_sliding (toolbar);
1738 /* finally allocate the items */
1739 if (priv->is_sliding)
1741 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1743 ToolbarContent *content = list->data;
1745 toolbar_content_set_goal_allocation (content, &(allocations[i]));
1749 elapsed = g_timer_elapsed (priv->timer, NULL);
1750 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1752 ToolbarContent *content = list->data;
1754 if (new_states[i] == OVERFLOWN ||
1755 new_states[i] == NORMAL)
1757 GtkAllocation alloc;
1758 GtkAllocation start_allocation = { 0, };
1759 GtkAllocation goal_allocation;
1761 if (priv->is_sliding)
1763 toolbar_content_get_start_allocation (content, &start_allocation);
1764 toolbar_content_get_goal_allocation (content, &goal_allocation);
1766 compute_intermediate_allocation (toolbar,
1771 priv->need_sync = TRUE;
1775 alloc = allocations[i];
1778 if (alloc.width <= 0 || alloc.height <= 0)
1780 toolbar_content_set_child_visible (content, toolbar, FALSE);
1784 if (!rect_within (&alloc, &item_area))
1786 toolbar_content_set_child_visible (content, toolbar, FALSE);
1787 toolbar_content_size_allocate (content, &alloc);
1791 toolbar_content_set_child_visible (content, toolbar, TRUE);
1792 toolbar_content_size_allocate (content, &alloc);
1798 toolbar_content_set_child_visible (content, toolbar, FALSE);
1801 toolbar_content_set_state (content, new_states[i]);
1804 if (priv->menu && priv->need_rebuild)
1805 rebuild_menu (toolbar);
1809 gtk_widget_size_allocate (GTK_WIDGET (priv->arrow_button),
1811 gtk_widget_show (GTK_WIDGET (priv->arrow_button));
1815 gtk_widget_hide (GTK_WIDGET (priv->arrow_button));
1817 if (priv->menu && GTK_WIDGET_VISIBLE (priv->menu))
1818 gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
1821 g_free (allocations);
1822 g_free (new_states);
1826 gtk_toolbar_update_button_relief (GtkToolbar *toolbar)
1828 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1829 GtkReliefStyle relief;
1831 relief = get_button_relief (toolbar);
1833 if (relief != gtk_button_get_relief (GTK_BUTTON (priv->arrow_button)))
1835 gtk_toolbar_reconfigured (toolbar);
1837 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), relief);
1842 gtk_toolbar_style_set (GtkWidget *widget,
1843 GtkStyle *prev_style)
1845 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
1847 priv->max_homogeneous_pixels = -1;
1849 if (GTK_WIDGET_REALIZED (widget))
1850 gtk_style_set_background (widget->style, widget->window, widget->state);
1853 gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
1857 gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
1858 GtkDirectionType dir)
1860 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1861 GList *result = NULL;
1865 /* generate list of children in reverse logical order */
1867 for (list = priv->content; list != NULL; list = list->next)
1869 ToolbarContent *content = list->data;
1872 widget = toolbar_content_get_widget (content);
1875 result = g_list_prepend (result, widget);
1878 result = g_list_prepend (result, priv->arrow_button);
1880 rtl = (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL);
1882 /* move in logical order when
1884 * - dir is TAB_FORWARD
1886 * - in RTL mode and moving left or up
1888 * - in LTR mode and moving right or down
1890 if (dir == GTK_DIR_TAB_FORWARD ||
1891 (rtl && (dir == GTK_DIR_UP || dir == GTK_DIR_LEFT)) ||
1892 (!rtl && (dir == GTK_DIR_DOWN || dir == GTK_DIR_RIGHT)))
1894 result = g_list_reverse (result);
1901 gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
1902 gboolean focus_home)
1904 GList *children, *list;
1905 GtkDirectionType dir = focus_home? GTK_DIR_RIGHT : GTK_DIR_LEFT;
1907 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1909 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1911 children = g_list_reverse (children);
1913 dir = (dir == GTK_DIR_RIGHT)? GTK_DIR_LEFT : GTK_DIR_RIGHT;
1916 for (list = children; list != NULL; list = list->next)
1918 GtkWidget *child = list->data;
1920 if (GTK_CONTAINER (toolbar)->focus_child == child)
1923 if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1927 g_list_free (children);
1932 /* Keybinding handler. This function is called when the user presses
1933 * Ctrl TAB or an arrow key.
1936 gtk_toolbar_move_focus (GtkWidget *widget,
1937 GtkDirectionType dir)
1939 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1940 GtkContainer *container = GTK_CONTAINER (toolbar);
1942 gboolean try_focus = FALSE;
1945 if (container->focus_child &&
1946 gtk_widget_child_focus (container->focus_child, dir))
1951 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1953 for (list = children; list != NULL; list = list->next)
1955 GtkWidget *child = list->data;
1957 if (try_focus && GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1960 if (child == GTK_CONTAINER (toolbar)->focus_child)
1964 g_list_free (children);
1967 /* The focus handler for the toolbar. It called when the user presses
1968 * TAB or otherwise tries to focus the toolbar.
1971 gtk_toolbar_focus (GtkWidget *widget,
1972 GtkDirectionType dir)
1974 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1975 GList *children, *list;
1976 gboolean result = FALSE;
1978 /* if focus is already somewhere inside the toolbar then return FALSE.
1979 * The only way focus can stay inside the toolbar is when the user presses
1980 * arrow keys or Ctrl TAB (both of which are handled by the
1981 * gtk_toolbar_move_focus() keybinding function.
1983 if (GTK_CONTAINER (widget)->focus_child)
1986 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1988 for (list = children; list != NULL; list = list->next)
1990 GtkWidget *child = list->data;
1992 if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1999 g_list_free (children);
2004 static GtkSettings *
2005 toolbar_get_settings (GtkToolbar *toolbar)
2007 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2008 return priv->settings;
2012 style_change_notify (GtkToolbar *toolbar)
2014 if (!toolbar->style_set)
2016 /* pretend it was set, then unset, thus reverting to new default */
2017 toolbar->style_set = TRUE;
2018 gtk_toolbar_unset_style (toolbar);
2023 icon_size_change_notify (GtkToolbar *toolbar)
2025 if (!toolbar->icon_size_set)
2027 /* pretend it was set, then unset, thus reverting to new default */
2028 toolbar->icon_size_set = TRUE;
2029 gtk_toolbar_unset_icon_size (toolbar);
2034 animation_change_notify (GtkToolbar *toolbar)
2036 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2037 GtkSettings *settings = toolbar_get_settings (toolbar);
2041 g_object_get (settings,
2042 "gtk-enable-animations", &animation,
2045 animation = DEFAULT_ANIMATION_STATE;
2047 priv->animation = animation;
2051 settings_change_notify (GtkSettings *settings,
2052 const GParamSpec *pspec,
2053 GtkToolbar *toolbar)
2055 if (! strcmp (pspec->name, "gtk-toolbar-style"))
2056 style_change_notify (toolbar);
2057 else if (! strcmp (pspec->name, "gtk-toolbar-icon-size"))
2058 icon_size_change_notify (toolbar);
2059 else if (! strcmp (pspec->name, "gtk-enable-animations"))
2060 animation_change_notify (toolbar);
2064 gtk_toolbar_screen_changed (GtkWidget *widget,
2065 GdkScreen *previous_screen)
2067 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2068 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2069 GtkSettings *old_settings = toolbar_get_settings (toolbar);
2070 GtkSettings *settings;
2072 if (gtk_widget_has_screen (GTK_WIDGET (toolbar)))
2073 settings = gtk_widget_get_settings (GTK_WIDGET (toolbar));
2077 if (settings == old_settings)
2082 g_signal_handler_disconnect (old_settings, priv->settings_connection);
2084 g_object_unref (old_settings);
2089 priv->settings_connection =
2090 g_signal_connect (settings, "notify",
2091 G_CALLBACK (settings_change_notify),
2094 priv->settings = g_object_ref (settings);
2097 priv->settings = NULL;
2099 style_change_notify (toolbar);
2100 icon_size_change_notify (toolbar);
2101 animation_change_notify (toolbar);
2105 find_drop_index (GtkToolbar *toolbar,
2109 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2110 GList *interesting_content;
2112 GtkOrientation orientation;
2113 GtkTextDirection direction;
2114 gint best_distance = G_MAXINT;
2118 ToolbarContent *best_content;
2119 GtkAllocation allocation;
2121 /* list items we care about wrt. drag and drop */
2122 interesting_content = NULL;
2123 for (list = priv->content; list != NULL; list = list->next)
2125 ToolbarContent *content = list->data;
2127 if (toolbar_content_get_state (content) == NORMAL)
2128 interesting_content = g_list_prepend (interesting_content, content);
2130 interesting_content = g_list_reverse (interesting_content);
2132 if (!interesting_content)
2135 orientation = toolbar->orientation;
2136 direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
2138 /* distance to first interesting item */
2139 best_content = interesting_content->data;
2140 toolbar_content_get_allocation (best_content, &allocation);
2142 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2146 if (direction == GTK_TEXT_DIR_LTR)
2149 pos = allocation.x + allocation.width;
2157 best_content = NULL;
2158 best_distance = ABS (pos - cursor);
2160 /* distance to far end of each item */
2161 for (list = interesting_content; list != NULL; list = list->next)
2163 ToolbarContent *content = list->data;
2165 toolbar_content_get_allocation (content, &allocation);
2167 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2169 if (direction == GTK_TEXT_DIR_LTR)
2170 pos = allocation.x + allocation.width;
2176 pos = allocation.y + allocation.height;
2179 distance = ABS (pos - cursor);
2181 if (distance < best_distance)
2183 best_distance = distance;
2184 best_content = content;
2188 g_list_free (interesting_content);
2193 return g_list_index (priv->content, best_content) + 1;
2197 reset_all_placeholders (GtkToolbar *toolbar)
2199 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2202 for (list = priv->content; list != NULL; list = list->next)
2204 ToolbarContent *content = list->data;
2205 if (toolbar_content_is_placeholder (content))
2206 toolbar_content_set_disappearing (content, TRUE);
2211 physical_to_logical (GtkToolbar *toolbar,
2214 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2218 g_assert (physical >= 0);
2221 for (list = priv->content; list && physical > 0; list = list->next)
2223 ToolbarContent *content = list->data;
2225 if (!toolbar_content_is_placeholder (content))
2230 g_assert (physical == 0);
2236 logical_to_physical (GtkToolbar *toolbar,
2239 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2243 g_assert (logical >= 0);
2246 for (list = priv->content; list; list = list->next)
2248 ToolbarContent *content = list->data;
2250 if (!toolbar_content_is_placeholder (content))
2260 g_assert (logical == 0);
2266 * gtk_toolbar_set_drop_highlight_item:
2267 * @toolbar: a #GtkToolbar
2268 * @tool_item: a #GtkToolItem, or %NULL to turn of highlighting
2269 * @index_: a position on @toolbar
2271 * Highlights @toolbar to give an idea of what it would look like
2272 * if @item was added to @toolbar at the position indicated by @index_.
2273 * If @item is %NULL, highlighting is turned off. In that case @index_
2276 * The @tool_item passed to this function must not be part of any widget
2277 * hierarchy. When an item is set as drop highlight item it can not
2278 * added to any widget hierarchy or used as highlight item for another
2284 gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar,
2285 GtkToolItem *tool_item,
2288 ToolbarContent *content;
2289 GtkToolbarPrivate *priv;
2291 GtkRequisition requisition;
2292 GtkRequisition old_requisition;
2293 gboolean restart_sliding;
2295 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2296 g_return_if_fail (tool_item == NULL || GTK_IS_TOOL_ITEM (tool_item));
2298 gtk_toolbar_check_new_api (toolbar);
2300 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2304 if (priv->highlight_tool_item)
2306 gtk_widget_unparent (GTK_WIDGET (priv->highlight_tool_item));
2307 g_object_unref (priv->highlight_tool_item);
2308 priv->highlight_tool_item = NULL;
2311 reset_all_placeholders (toolbar);
2312 gtk_toolbar_begin_sliding (toolbar);
2316 n_items = gtk_toolbar_get_n_items (toolbar);
2317 if (index_ < 0 || index_ > n_items)
2320 if (tool_item != priv->highlight_tool_item)
2322 if (priv->highlight_tool_item)
2323 g_object_unref (priv->highlight_tool_item);
2325 g_object_ref_sink (tool_item);
2327 priv->highlight_tool_item = tool_item;
2329 gtk_widget_set_parent (GTK_WIDGET (priv->highlight_tool_item),
2330 GTK_WIDGET (toolbar));
2333 index_ = logical_to_physical (toolbar, index_);
2335 content = g_list_nth_data (priv->content, index_);
2339 ToolbarContent *prev_content;
2341 prev_content = g_list_nth_data (priv->content, index_ - 1);
2343 if (prev_content && toolbar_content_is_placeholder (prev_content))
2344 content = prev_content;
2347 if (!content || !toolbar_content_is_placeholder (content))
2349 GtkWidget *placeholder;
2351 placeholder = GTK_WIDGET (gtk_separator_tool_item_new ());
2353 content = toolbar_content_new_tool_item (toolbar,
2354 GTK_TOOL_ITEM (placeholder),
2356 gtk_widget_show (placeholder);
2360 g_assert (toolbar_content_is_placeholder (content));
2362 gtk_widget_size_request (GTK_WIDGET (priv->highlight_tool_item),
2365 toolbar_content_set_expand (content, gtk_tool_item_get_expand (tool_item));
2367 restart_sliding = FALSE;
2368 toolbar_content_size_request (content, toolbar, &old_requisition);
2369 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2371 requisition.height = -1;
2372 if (requisition.width != old_requisition.width)
2373 restart_sliding = TRUE;
2377 requisition.width = -1;
2378 if (requisition.height != old_requisition.height)
2379 restart_sliding = TRUE;
2382 if (toolbar_content_disappearing (content))
2383 restart_sliding = TRUE;
2385 reset_all_placeholders (toolbar);
2386 toolbar_content_set_disappearing (content, FALSE);
2388 toolbar_content_set_size_request (content,
2389 requisition.width, requisition.height);
2391 if (restart_sliding)
2392 gtk_toolbar_begin_sliding (toolbar);
2396 gtk_toolbar_get_child_property (GtkContainer *container,
2402 GtkToolItem *item = GTK_TOOL_ITEM (child);
2404 switch (property_id)
2406 case CHILD_PROP_HOMOGENEOUS:
2407 g_value_set_boolean (value, gtk_tool_item_get_homogeneous (item));
2410 case CHILD_PROP_EXPAND:
2411 g_value_set_boolean (value, gtk_tool_item_get_expand (item));
2415 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2421 gtk_toolbar_set_child_property (GtkContainer *container,
2424 const GValue *value,
2427 switch (property_id)
2429 case CHILD_PROP_HOMOGENEOUS:
2430 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2433 case CHILD_PROP_EXPAND:
2434 gtk_tool_item_set_expand (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2438 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2444 gtk_toolbar_show_all (GtkWidget *widget)
2446 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2449 for (list = priv->content; list != NULL; list = list->next)
2451 ToolbarContent *content = list->data;
2453 toolbar_content_show_all (content);
2456 gtk_widget_show (widget);
2460 gtk_toolbar_hide_all (GtkWidget *widget)
2462 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2465 for (list = priv->content; list != NULL; list = list->next)
2467 ToolbarContent *content = list->data;
2469 toolbar_content_hide_all (content);
2472 gtk_widget_hide (widget);
2476 gtk_toolbar_add (GtkContainer *container,
2479 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2481 if (GTK_IS_TOOL_ITEM (widget))
2482 gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
2484 gtk_toolbar_append_widget (toolbar, widget, NULL, NULL);
2488 gtk_toolbar_remove (GtkContainer *container,
2491 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2492 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2493 ToolbarContent *content_to_remove;
2496 content_to_remove = NULL;
2497 for (list = priv->content; list != NULL; list = list->next)
2499 ToolbarContent *content = list->data;
2502 child = toolbar_content_get_widget (content);
2503 if (child && child == widget)
2505 content_to_remove = content;
2510 g_return_if_fail (content_to_remove != NULL);
2512 toolbar_content_remove (content_to_remove, toolbar);
2513 toolbar_content_free (content_to_remove);
2517 gtk_toolbar_forall (GtkContainer *container,
2518 gboolean include_internals,
2519 GtkCallback callback,
2520 gpointer callback_data)
2522 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2523 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2526 g_return_if_fail (callback != NULL);
2528 list = priv->content;
2531 ToolbarContent *content = list->data;
2532 GList *next = list->next;
2534 if (include_internals || !toolbar_content_is_placeholder (content))
2536 GtkWidget *child = toolbar_content_get_widget (content);
2539 callback (child, callback_data);
2545 if (include_internals)
2546 callback (priv->arrow_button, callback_data);
2550 gtk_toolbar_child_type (GtkContainer *container)
2552 return GTK_TYPE_TOOL_ITEM;
2556 gtk_toolbar_reconfigured (GtkToolbar *toolbar)
2558 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2561 list = priv->content;
2564 ToolbarContent *content = list->data;
2565 GList *next = list->next;
2567 toolbar_content_toolbar_reconfigured (content, toolbar);
2574 gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
2575 GtkOrientation orientation)
2577 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2578 if (toolbar->orientation != orientation)
2580 toolbar->orientation = orientation;
2582 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2583 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2585 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2587 gtk_toolbar_reconfigured (toolbar);
2589 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2590 g_object_notify (G_OBJECT (toolbar), "orientation");
2595 gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
2596 GtkToolbarStyle style)
2598 if (toolbar->style != style)
2600 toolbar->style = style;
2602 gtk_toolbar_reconfigured (toolbar);
2604 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2605 g_object_notify (G_OBJECT (toolbar), "toolbar-style");
2610 menu_position_func (GtkMenu *menu,
2616 GtkToolbar *toolbar = GTK_TOOLBAR (user_data);
2617 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2619 GtkRequisition menu_req;
2620 GdkRectangle monitor;
2624 gtk_widget_size_request (priv->arrow_button, &req);
2625 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2627 screen = gtk_widget_get_screen (GTK_WIDGET (menu));
2628 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->arrow_button->window);
2629 if (monitor_num < 0)
2631 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2633 gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
2634 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2636 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2637 *x += priv->arrow_button->allocation.width - req.width;
2639 *x += req.width - menu_req.width;
2641 if ((*y + priv->arrow_button->allocation.height + menu_req.height) <= monitor.y + monitor.height)
2642 *y += priv->arrow_button->allocation.height;
2643 else if ((*y - menu_req.height) >= monitor.y)
2644 *y -= menu_req.height;
2645 else if (monitor.y + monitor.height - (*y + priv->arrow_button->allocation.height) > *y)
2646 *y += priv->arrow_button->allocation.height;
2648 *y -= menu_req.height;
2652 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2653 *x += priv->arrow_button->allocation.width;
2655 *x -= menu_req.width;
2657 if (*y + menu_req.height > monitor.y + monitor.height &&
2658 *y + priv->arrow_button->allocation.height - monitor.y > monitor.y + monitor.height - *y)
2659 *y += priv->arrow_button->allocation.height - menu_req.height;
2666 show_menu (GtkToolbar *toolbar,
2667 GdkEventButton *event)
2669 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2671 rebuild_menu (toolbar);
2673 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2675 gtk_menu_popup (priv->menu, NULL, NULL,
2676 menu_position_func, toolbar,
2677 event? event->button : 0,
2678 event? event->time : gtk_get_current_event_time());
2682 gtk_toolbar_arrow_button_clicked (GtkWidget *button,
2683 GtkToolbar *toolbar)
2685 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2687 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) &&
2688 (!priv->menu || !GTK_WIDGET_VISIBLE (priv->menu)))
2690 /* We only get here when the button is clicked with the keyboard,
2691 * because mouse button presses result in the menu being shown so
2692 * that priv->menu would be non-NULL and visible.
2694 show_menu (toolbar, NULL);
2695 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
2700 gtk_toolbar_arrow_button_press (GtkWidget *button,
2701 GdkEventButton *event,
2702 GtkToolbar *toolbar)
2704 show_menu (toolbar, event);
2705 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
2711 gtk_toolbar_button_press (GtkWidget *toolbar,
2712 GdkEventButton *event)
2714 if (event->button == 3)
2716 gboolean return_value;
2718 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2719 (int)event->x_root, (int)event->y_root, event->button,
2722 return return_value;
2729 gtk_toolbar_popup_menu (GtkWidget *toolbar)
2731 gboolean return_value;
2732 /* This function is the handler for the "popup menu" keybinding,
2733 * ie., it is called when the user presses Shift F10
2735 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2736 -1, -1, -1, &return_value);
2738 return return_value;
2744 * Creates a new toolbar.
2746 * Return Value: the newly-created toolbar.
2749 gtk_toolbar_new (void)
2751 GtkToolbar *toolbar;
2753 toolbar = g_object_new (GTK_TYPE_TOOLBAR, NULL);
2755 return GTK_WIDGET (toolbar);
2759 * gtk_toolbar_insert:
2760 * @toolbar: a #GtkToolbar
2761 * @item: a #GtkToolItem
2762 * @pos: the position of the new item
2764 * Insert a #GtkToolItem into the toolbar at position @pos. If @pos is
2765 * 0 the item is prepended to the start of the toolbar. If @pos is
2766 * negative, the item is appended to the end of the toolbar.
2771 gtk_toolbar_insert (GtkToolbar *toolbar,
2775 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2776 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
2778 if (!gtk_toolbar_check_new_api (toolbar))
2782 pos = logical_to_physical (toolbar, pos);
2784 toolbar_content_new_tool_item (toolbar, item, FALSE, pos);
2788 * gtk_toolbar_get_item_index:
2789 * @toolbar: a #GtkToolbar
2790 * @item: a #GtkToolItem that is a child of @toolbar
2792 * Returns the position of @item on the toolbar, starting from 0.
2793 * It is an error if @item is not a child of the toolbar.
2795 * Return value: the position of item on the toolbar.
2800 gtk_toolbar_get_item_index (GtkToolbar *toolbar,
2803 GtkToolbarPrivate *priv;
2807 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2808 g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
2809 g_return_val_if_fail (GTK_WIDGET (item)->parent == GTK_WIDGET (toolbar), -1);
2811 if (!gtk_toolbar_check_new_api (toolbar))
2814 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2817 for (list = priv->content; list != NULL; list = list->next)
2819 ToolbarContent *content = list->data;
2822 widget = toolbar_content_get_widget (content);
2824 if (item == GTK_TOOL_ITEM (widget))
2830 return physical_to_logical (toolbar, n);
2834 * gtk_toolbar_set_orientation:
2835 * @toolbar: a #GtkToolbar.
2836 * @orientation: a new #GtkOrientation.
2838 * Sets whether a toolbar should appear horizontally or vertically.
2840 * Deprecated: 2.16: Use gtk_orientable_set_orientation() instead.
2843 gtk_toolbar_set_orientation (GtkToolbar *toolbar,
2844 GtkOrientation orientation)
2846 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2848 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0, orientation);
2852 * gtk_toolbar_get_orientation:
2853 * @toolbar: a #GtkToolbar
2855 * Retrieves the current orientation of the toolbar. See
2856 * gtk_toolbar_set_orientation().
2858 * Return value: the orientation
2860 * Deprecated: 2.16: Use gtk_orientable_get_orientation() instead.
2863 gtk_toolbar_get_orientation (GtkToolbar *toolbar)
2865 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_ORIENTATION_HORIZONTAL);
2867 return toolbar->orientation;
2871 * gtk_toolbar_set_style:
2872 * @toolbar: a #GtkToolbar.
2873 * @style: the new style for @toolbar.
2875 * Alters the view of @toolbar to display either icons only, text only, or both.
2878 gtk_toolbar_set_style (GtkToolbar *toolbar,
2879 GtkToolbarStyle style)
2881 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2883 toolbar->style_set = TRUE;
2884 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2888 * gtk_toolbar_get_style:
2889 * @toolbar: a #GtkToolbar
2891 * Retrieves whether the toolbar has text, icons, or both . See
2892 * gtk_toolbar_set_style().
2894 * Return value: the current style of @toolbar
2897 gtk_toolbar_get_style (GtkToolbar *toolbar)
2899 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_TOOLBAR_STYLE);
2901 return toolbar->style;
2905 * gtk_toolbar_unset_style:
2906 * @toolbar: a #GtkToolbar
2908 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that
2909 * user preferences will be used to determine the toolbar style.
2912 gtk_toolbar_unset_style (GtkToolbar *toolbar)
2914 GtkToolbarStyle style;
2916 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2918 if (toolbar->style_set)
2920 GtkSettings *settings = toolbar_get_settings (toolbar);
2923 g_object_get (settings,
2924 "gtk-toolbar-style", &style,
2927 style = DEFAULT_TOOLBAR_STYLE;
2929 if (style != toolbar->style)
2930 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2932 toolbar->style_set = FALSE;
2937 * gtk_toolbar_set_tooltips:
2938 * @toolbar: a #GtkToolbar.
2939 * @enable: set to %FALSE to disable the tooltips, or %TRUE to enable them.
2941 * Sets if the tooltips of a toolbar should be active or not.
2943 * Deprecated: 2.14: The toolkit-wide #GtkSettings:gtk-enable-tooltips property
2944 * is now used instead.
2947 gtk_toolbar_set_tooltips (GtkToolbar *toolbar,
2950 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2953 gtk_tooltips_enable (toolbar->tooltips);
2955 gtk_tooltips_disable (toolbar->tooltips);
2957 g_object_notify (G_OBJECT (toolbar), "tooltips");
2961 * gtk_toolbar_get_tooltips:
2962 * @toolbar: a #GtkToolbar
2964 * Retrieves whether tooltips are enabled. See
2965 * gtk_toolbar_set_tooltips().
2967 * Return value: %TRUE if tooltips are enabled
2969 * Deprecated: 2.14: The toolkit-wide #GtkSettings:gtk-enable-tooltips property
2970 * is now used instead.
2973 gtk_toolbar_get_tooltips (GtkToolbar *toolbar)
2975 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
2981 * gtk_toolbar_get_n_items:
2982 * @toolbar: a #GtkToolbar
2984 * Returns the number of items on the toolbar.
2986 * Return value: the number of items on the toolbar
2991 gtk_toolbar_get_n_items (GtkToolbar *toolbar)
2993 GtkToolbarPrivate *priv;
2995 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2997 if (!gtk_toolbar_check_new_api (toolbar))
3000 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3002 return physical_to_logical (toolbar, g_list_length (priv->content));
3006 * gtk_toolbar_get_nth_item:
3007 * @toolbar: a #GtkToolbar
3008 * @n: A position on the toolbar
3010 * Returns the @n<!-- -->'th item on @toolbar, or %NULL if the
3011 * toolbar does not contain an @n<!-- -->'th item.
3013 * Return value: The @n<!-- -->'th #GtkToolItem on @toolbar, or %NULL if there
3014 * isn't an @n<!-- -->'th item.
3019 gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
3022 GtkToolbarPrivate *priv;
3023 ToolbarContent *content;
3026 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
3028 if (!gtk_toolbar_check_new_api (toolbar))
3031 n_items = gtk_toolbar_get_n_items (toolbar);
3033 if (n < 0 || n >= n_items)
3036 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3038 content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
3041 g_assert (!toolbar_content_is_placeholder (content));
3043 return GTK_TOOL_ITEM (toolbar_content_get_widget (content));
3047 * gtk_toolbar_get_icon_size:
3048 * @toolbar: a #GtkToolbar
3050 * Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size().
3052 * Return value: the current icon size for the icons on the toolbar.
3055 gtk_toolbar_get_icon_size (GtkToolbar *toolbar)
3057 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_ICON_SIZE);
3059 return toolbar->icon_size;
3063 * gtk_toolbar_get_relief_style:
3064 * @toolbar: a #GtkToolbar
3066 * Returns the relief style of buttons on @toolbar. See
3067 * gtk_button_set_relief().
3069 * Return value: The relief style of buttons on @toolbar.
3074 gtk_toolbar_get_relief_style (GtkToolbar *toolbar)
3076 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_RELIEF_NONE);
3078 return get_button_relief (toolbar);
3082 * gtk_toolbar_set_show_arrow:
3083 * @toolbar: a #GtkToolbar
3084 * @show_arrow: Whether to show an overflow menu
3086 * Sets whether to show an overflow menu when
3087 * @toolbar doesn't have room for all items on it. If %TRUE,
3088 * items that there are not room are available through an
3094 gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
3095 gboolean show_arrow)
3097 GtkToolbarPrivate *priv;
3099 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3101 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3102 show_arrow = show_arrow != FALSE;
3104 if (priv->show_arrow != show_arrow)
3106 priv->show_arrow = show_arrow;
3108 if (!priv->show_arrow)
3109 gtk_widget_hide (priv->arrow_button);
3111 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3112 g_object_notify (G_OBJECT (toolbar), "show-arrow");
3117 * gtk_toolbar_get_show_arrow:
3118 * @toolbar: a #GtkToolbar
3120 * Returns whether the toolbar has an overflow menu.
3121 * See gtk_toolbar_set_show_arrow().
3123 * Return value: %TRUE if the toolbar has an overflow menu.
3128 gtk_toolbar_get_show_arrow (GtkToolbar *toolbar)
3130 GtkToolbarPrivate *priv;
3132 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
3134 if (!gtk_toolbar_check_new_api (toolbar))
3137 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3139 return priv->show_arrow;
3143 * gtk_toolbar_get_drop_index:
3144 * @toolbar: a #GtkToolbar
3145 * @x: x coordinate of a point on the toolbar
3146 * @y: y coordinate of a point on the toolbar
3148 * Returns the position corresponding to the indicated point on
3149 * @toolbar. This is useful when dragging items to the toolbar:
3150 * this function returns the position a new item should be
3153 * @x and @y are in @toolbar coordinates.
3155 * Return value: The position corresponding to the point (@x, @y) on the toolbar.
3160 gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
3164 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
3166 if (!gtk_toolbar_check_new_api (toolbar))
3169 return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
3173 gtk_toolbar_finalize (GObject *object)
3176 GtkToolbar *toolbar = GTK_TOOLBAR (object);
3177 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3179 if (toolbar->tooltips)
3180 g_object_unref (toolbar->tooltips);
3182 if (priv->arrow_button)
3183 gtk_widget_unparent (priv->arrow_button);
3185 for (list = priv->content; list != NULL; list = list->next)
3187 ToolbarContent *content = list->data;
3189 toolbar_content_free (content);
3192 g_list_free (priv->content);
3193 g_list_free (toolbar->children);
3195 g_timer_destroy (priv->timer);
3198 gtk_widget_destroy (GTK_WIDGET (priv->menu));
3201 g_source_remove (priv->idle_id);
3203 G_OBJECT_CLASS (gtk_toolbar_parent_class)->finalize (object);
3207 * gtk_toolbar_set_icon_size:
3208 * @toolbar: A #GtkToolbar
3209 * @icon_size: The #GtkIconSize that stock icons in the toolbar shall have.
3211 * This function sets the size of stock icons in the toolbar. You
3212 * can call it both before you add the icons and after they've been
3213 * added. The size you set will override user preferences for the default
3216 * This should only be used for special-purpose toolbars, normal
3217 * application toolbars should respect the user preferences for the
3221 gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
3222 GtkIconSize icon_size)
3224 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3225 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
3227 if (!toolbar->icon_size_set)
3229 toolbar->icon_size_set = TRUE;
3230 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3233 if (toolbar->icon_size == icon_size)
3236 toolbar->icon_size = icon_size;
3237 g_object_notify (G_OBJECT (toolbar), "icon-size");
3239 gtk_toolbar_reconfigured (toolbar);
3241 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3245 * gtk_toolbar_unset_icon_size:
3246 * @toolbar: a #GtkToolbar
3248 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that
3249 * user preferences will be used to determine the icon size.
3252 gtk_toolbar_unset_icon_size (GtkToolbar *toolbar)
3256 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3258 if (toolbar->icon_size_set)
3260 GtkSettings *settings = toolbar_get_settings (toolbar);
3264 g_object_get (settings,
3265 "gtk-toolbar-icon-size", &size,
3269 size = DEFAULT_ICON_SIZE;
3271 if (size != toolbar->icon_size)
3273 gtk_toolbar_set_icon_size (toolbar, size);
3274 g_object_notify (G_OBJECT (toolbar), "icon-size");
3277 toolbar->icon_size_set = FALSE;
3278 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3287 * gtk_toolbar_append_item:
3288 * @toolbar: a #GtkToolbar.
3289 * @text: give your toolbar button a label.
3290 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3291 * @tooltip_private_text: use with #GtkTipsQuery.
3292 * @icon: a #GtkWidget that should be used as the button's icon.
3293 * @callback: the function to be executed when the button is pressed.
3294 * @user_data: a pointer to any data you wish to be passed to the callback.
3296 * Inserts a new item into the toolbar. You must specify the position
3297 * in the toolbar where it will be inserted.
3299 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3300 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3302 * Return value: the new toolbar item as a #GtkWidget.
3304 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3307 gtk_toolbar_append_item (GtkToolbar *toolbar,
3309 const char *tooltip_text,
3310 const char *tooltip_private_text,
3315 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3317 tooltip_text, tooltip_private_text,
3318 icon, callback, user_data,
3319 toolbar->num_children);
3323 * gtk_toolbar_prepend_item:
3324 * @toolbar: a #GtkToolbar.
3325 * @text: give your toolbar button a label.
3326 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3327 * @tooltip_private_text: use with #GtkTipsQuery.
3328 * @icon: a #GtkWidget that should be used as the button's icon.
3329 * @callback: the function to be executed when the button is pressed.
3330 * @user_data: a pointer to any data you wish to be passed to the callback.
3332 * Adds a new button to the beginning (top or left edges) of the given toolbar.
3334 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3335 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3337 * Return value: the new toolbar item as a #GtkWidget.
3339 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3342 gtk_toolbar_prepend_item (GtkToolbar *toolbar,
3344 const char *tooltip_text,
3345 const char *tooltip_private_text,
3350 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3352 tooltip_text, tooltip_private_text,
3353 icon, callback, user_data,
3358 * gtk_toolbar_insert_item:
3359 * @toolbar: a #GtkToolbar.
3360 * @text: give your toolbar button a label.
3361 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3362 * @tooltip_private_text: use with #GtkTipsQuery.
3363 * @icon: a #GtkWidget that should be used as the button's icon.
3364 * @callback: the function to be executed when the button is pressed.
3365 * @user_data: a pointer to any data you wish to be passed to the callback.
3366 * @position: the number of widgets to insert this item after.
3368 * Inserts a new item into the toolbar. You must specify the position in the
3369 * toolbar where it will be inserted.
3371 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3372 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3374 * Return value: the new toolbar item as a #GtkWidget.
3376 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3379 gtk_toolbar_insert_item (GtkToolbar *toolbar,
3381 const char *tooltip_text,
3382 const char *tooltip_private_text,
3388 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3390 tooltip_text, tooltip_private_text,
3391 icon, callback, user_data,
3396 * gtk_toolbar_insert_stock:
3397 * @toolbar: A #GtkToolbar
3398 * @stock_id: The id of the stock item you want to insert
3399 * @tooltip_text: The text in the tooltip of the toolbar button
3400 * @tooltip_private_text: The private text of the tooltip
3401 * @callback: The callback called when the toolbar button is clicked.
3402 * @user_data: user data passed to callback
3403 * @position: The position the button shall be inserted at.
3404 * -1 means at the end.
3406 * Inserts a stock item at the specified position of the toolbar. If
3407 * @stock_id is not a known stock item ID, it's inserted verbatim,
3408 * except that underscores used to mark mnemonics are removed.
3410 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3411 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3413 * Returns: the inserted widget
3415 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3418 gtk_toolbar_insert_stock (GtkToolbar *toolbar,
3419 const gchar *stock_id,
3420 const char *tooltip_text,
3421 const char *tooltip_private_text,
3426 return internal_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3428 tooltip_text, tooltip_private_text,
3429 NULL, callback, user_data,
3434 * gtk_toolbar_append_space:
3435 * @toolbar: a #GtkToolbar.
3437 * Adds a new space to the end of the toolbar.
3439 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3442 gtk_toolbar_append_space (GtkToolbar *toolbar)
3444 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3448 toolbar->num_children);
3452 * gtk_toolbar_prepend_space:
3453 * @toolbar: a #GtkToolbar.
3455 * Adds a new space to the beginning of the toolbar.
3457 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3460 gtk_toolbar_prepend_space (GtkToolbar *toolbar)
3462 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3470 * gtk_toolbar_insert_space:
3471 * @toolbar: a #GtkToolbar
3472 * @position: the number of widgets after which a space should be inserted.
3474 * Inserts a new space in the toolbar at the specified position.
3476 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3479 gtk_toolbar_insert_space (GtkToolbar *toolbar,
3482 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3490 * gtk_toolbar_remove_space:
3491 * @toolbar: a #GtkToolbar.
3492 * @position: the index of the space to remove.
3494 * Removes a space from the specified position.
3496 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3499 gtk_toolbar_remove_space (GtkToolbar *toolbar,
3502 GtkToolbarPrivate *priv;
3503 ToolbarContent *content;
3505 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3507 if (!gtk_toolbar_check_old_api (toolbar))
3510 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3512 content = g_list_nth_data (priv->content, position);
3516 g_warning ("Toolbar position %d doesn't exist", position);
3520 if (!toolbar_content_is_separator (content))
3522 g_warning ("Toolbar position %d is not a space", position);
3526 toolbar_content_remove (content, toolbar);
3527 toolbar_content_free (content);
3531 * gtk_toolbar_append_widget:
3532 * @toolbar: a #GtkToolbar.
3533 * @widget: a #GtkWidget to add to the toolbar.
3534 * @tooltip_text: the element's tooltip.
3535 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3537 * Adds a widget to the end of the given toolbar.
3539 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3542 gtk_toolbar_append_widget (GtkToolbar *toolbar,
3544 const gchar *tooltip_text,
3545 const gchar *tooltip_private_text)
3547 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3549 tooltip_text, tooltip_private_text,
3551 toolbar->num_children);
3555 * gtk_toolbar_prepend_widget:
3556 * @toolbar: a #GtkToolbar.
3557 * @widget: a #GtkWidget to add to the toolbar.
3558 * @tooltip_text: the element's tooltip.
3559 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3561 * Adds a widget to the beginning of the given toolbar.
3563 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3566 gtk_toolbar_prepend_widget (GtkToolbar *toolbar,
3568 const gchar *tooltip_text,
3569 const gchar *tooltip_private_text)
3571 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3573 tooltip_text, tooltip_private_text,
3579 * gtk_toolbar_insert_widget:
3580 * @toolbar: a #GtkToolbar.
3581 * @widget: a #GtkWidget to add to the toolbar.
3582 * @tooltip_text: the element's tooltip.
3583 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3584 * @position: the number of widgets to insert this widget after.
3586 * Inserts a widget in the toolbar at the given position.
3588 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3591 gtk_toolbar_insert_widget (GtkToolbar *toolbar,
3593 const char *tooltip_text,
3594 const char *tooltip_private_text,
3597 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3599 tooltip_text, tooltip_private_text,
3605 * gtk_toolbar_append_element:
3606 * @toolbar: a #GtkToolbar.
3607 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3608 * @widget: a #GtkWidget, or %NULL.
3609 * @text: the element's label.
3610 * @tooltip_text: the element's tooltip.
3611 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3612 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3613 * @callback: the function to be executed when the button is pressed.
3614 * @user_data: any data you wish to pass to the callback.
3616 * Adds a new element to the end of a toolbar.
3618 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3619 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3620 * the radio group for the new element. In all other cases, @widget must
3623 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3624 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3626 * Return value: the new toolbar element as a #GtkWidget.
3628 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3631 gtk_toolbar_append_element (GtkToolbar *toolbar,
3632 GtkToolbarChildType type,
3635 const char *tooltip_text,
3636 const char *tooltip_private_text,
3641 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3642 tooltip_text, tooltip_private_text,
3643 icon, callback, user_data,
3644 toolbar->num_children);
3648 * gtk_toolbar_prepend_element:
3649 * @toolbar: a #GtkToolbar.
3650 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3651 * @widget: a #GtkWidget, or %NULL
3652 * @text: the element's label.
3653 * @tooltip_text: the element's tooltip.
3654 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3655 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3656 * @callback: the function to be executed when the button is pressed.
3657 * @user_data: any data you wish to pass to the callback.
3659 * Adds a new element to the beginning of a toolbar.
3661 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3662 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3663 * the radio group for the new element. In all other cases, @widget must
3666 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3667 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3669 * Return value: the new toolbar element as a #GtkWidget.
3671 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3674 gtk_toolbar_prepend_element (GtkToolbar *toolbar,
3675 GtkToolbarChildType type,
3678 const char *tooltip_text,
3679 const char *tooltip_private_text,
3684 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3685 tooltip_text, tooltip_private_text,
3686 icon, callback, user_data, 0);
3690 * gtk_toolbar_insert_element:
3691 * @toolbar: a #GtkToolbar.
3692 * @type: a value of type #GtkToolbarChildType that determines what @widget
3694 * @widget: a #GtkWidget, or %NULL.
3695 * @text: the element's label.
3696 * @tooltip_text: the element's tooltip.
3697 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3698 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3699 * @callback: the function to be executed when the button is pressed.
3700 * @user_data: any data you wish to pass to the callback.
3701 * @position: the number of widgets to insert this element after.
3703 * Inserts a new element in the toolbar at the given position.
3705 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3706 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3707 * the radio group for the new element. In all other cases, @widget must
3710 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3711 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3713 * Return value: the new toolbar element as a #GtkWidget.
3715 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3718 gtk_toolbar_insert_element (GtkToolbar *toolbar,
3719 GtkToolbarChildType type,
3722 const char *tooltip_text,
3723 const char *tooltip_private_text,
3729 return internal_insert_element (toolbar, type, widget, text,
3730 tooltip_text, tooltip_private_text,
3731 icon, callback, user_data, position, FALSE);
3735 set_child_packing_and_visibility(GtkToolbar *toolbar,
3736 GtkToolbarChild *child)
3741 box = gtk_bin_get_child (GTK_BIN (child->widget));
3743 g_return_if_fail (GTK_IS_BOX (box));
3747 expand = (toolbar->style != GTK_TOOLBAR_BOTH);
3749 gtk_box_set_child_packing (GTK_BOX (box), child->label,
3750 expand, expand, 0, GTK_PACK_END);
3752 if (toolbar->style != GTK_TOOLBAR_ICONS)
3753 gtk_widget_show (child->label);
3755 gtk_widget_hide (child->label);
3760 expand = (toolbar->style != GTK_TOOLBAR_BOTH_HORIZ);
3762 gtk_box_set_child_packing (GTK_BOX (box), child->icon,
3763 expand, expand, 0, GTK_PACK_END);
3765 if (toolbar->style != GTK_TOOLBAR_TEXT)
3766 gtk_widget_show (child->icon);
3768 gtk_widget_hide (child->icon);
3773 internal_insert_element (GtkToolbar *toolbar,
3774 GtkToolbarChildType type,
3777 const char *tooltip_text,
3778 const char *tooltip_private_text,
3786 ToolbarContent *content;
3787 char *free_me = NULL;
3789 GtkWidget *child_widget;
3790 GtkWidget *child_label;
3791 GtkWidget *child_icon;
3793 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
3794 if (type == GTK_TOOLBAR_CHILD_WIDGET)
3795 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3796 else if (type != GTK_TOOLBAR_CHILD_RADIOBUTTON)
3797 g_return_val_if_fail (widget == NULL, NULL);
3798 if (GTK_IS_TOOL_ITEM (widget))
3799 g_warning (MIXED_API_WARNING);
3801 if (!gtk_toolbar_check_old_api (toolbar))
3804 child_widget = NULL;
3810 case GTK_TOOLBAR_CHILD_SPACE:
3813 case GTK_TOOLBAR_CHILD_WIDGET:
3814 child_widget = widget;
3817 case GTK_TOOLBAR_CHILD_BUTTON:
3818 case GTK_TOOLBAR_CHILD_TOGGLEBUTTON:
3819 case GTK_TOOLBAR_CHILD_RADIOBUTTON:
3820 if (type == GTK_TOOLBAR_CHILD_BUTTON)
3822 child_widget = gtk_button_new ();
3824 else if (type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
3826 child_widget = gtk_toggle_button_new ();
3827 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3829 else /* type == GTK_TOOLBAR_CHILD_RADIOBUTTON */
3831 GSList *group = NULL;
3834 group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
3836 child_widget = gtk_radio_button_new (group);
3837 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3840 gtk_button_set_relief (GTK_BUTTON (child_widget), get_button_relief (toolbar));
3841 gtk_button_set_focus_on_click (GTK_BUTTON (child_widget), FALSE);
3845 g_signal_connect (child_widget, "clicked",
3846 callback, user_data);
3849 if (toolbar->style == GTK_TOOLBAR_BOTH_HORIZ)
3850 box = gtk_hbox_new (FALSE, 0);
3852 box = gtk_vbox_new (FALSE, 0);
3854 gtk_container_add (GTK_CONTAINER (child_widget), box);
3855 gtk_widget_show (box);
3857 if (text && use_stock)
3859 GtkStockItem stock_item;
3860 if (gtk_stock_lookup (text, &stock_item))
3863 icon = gtk_image_new_from_stock (text, toolbar->icon_size);
3865 text = free_me = _gtk_toolbar_elide_underscores (stock_item.label);
3871 child_label = gtk_label_new (text);
3873 gtk_container_add (GTK_CONTAINER (box), child_label);
3878 child_icon = GTK_WIDGET (icon);
3879 gtk_container_add (GTK_CONTAINER (box), child_icon);
3882 gtk_widget_show (child_widget);
3886 g_assert_not_reached ();
3890 if ((type != GTK_TOOLBAR_CHILD_SPACE) && tooltip_text)
3892 gtk_tooltips_set_tip (toolbar->tooltips, child_widget,
3893 tooltip_text, tooltip_private_text);
3896 content = toolbar_content_new_compatibility (toolbar, type, child_widget,
3897 child_icon, child_label, position);
3901 return child_widget;
3905 * ToolbarContent methods
3913 struct _ToolbarContent
3923 GtkAllocation start_allocation;
3924 GtkAllocation goal_allocation;
3925 guint is_placeholder : 1;
3926 guint disappearing : 1;
3932 GtkToolbarChild child;
3933 GtkAllocation space_allocation;
3934 guint space_visible : 1;
3939 static ToolbarContent *
3940 toolbar_content_new_tool_item (GtkToolbar *toolbar,
3942 gboolean is_placeholder,
3945 ToolbarContent *content;
3946 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3948 content = g_slice_new0 (ToolbarContent);
3950 content->type = TOOL_ITEM;
3951 content->state = NOT_ALLOCATED;
3952 content->u.tool_item.item = item;
3953 content->u.tool_item.is_placeholder = is_placeholder;
3955 gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
3957 priv->content = g_list_insert (priv->content, content, pos);
3959 if (!is_placeholder)
3961 toolbar->num_children++;
3963 gtk_toolbar_stop_sliding (toolbar);
3966 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3967 priv->need_rebuild = TRUE;
3972 static ToolbarContent *
3973 toolbar_content_new_compatibility (GtkToolbar *toolbar,
3974 GtkToolbarChildType type,
3980 ToolbarContent *content;
3981 GtkToolbarChild *child;
3982 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3984 content = g_slice_new0 (ToolbarContent);
3986 child = &(content->u.compatibility.child);
3988 content->type = COMPATIBILITY;
3990 child->widget = widget;
3992 child->label = label;
3994 if (type != GTK_TOOLBAR_CHILD_SPACE)
3996 gtk_widget_set_parent (child->widget, GTK_WIDGET (toolbar));
4000 content->u.compatibility.space_visible = TRUE;
4001 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
4004 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
4005 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4006 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
4008 set_child_packing_and_visibility (toolbar, child);
4011 priv->content = g_list_insert (priv->content, content, pos);
4012 toolbar->children = g_list_insert (toolbar->children, child, pos);
4013 priv->need_rebuild = TRUE;
4015 toolbar->num_children++;
4021 toolbar_content_remove (ToolbarContent *content,
4022 GtkToolbar *toolbar)
4024 GtkToolbarChild *child;
4025 GtkToolbarPrivate *priv;
4027 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4029 switch (content->type)
4032 gtk_widget_unparent (GTK_WIDGET (content->u.tool_item.item));
4036 child = &(content->u.compatibility.child);
4038 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4040 g_object_ref (child->widget);
4041 gtk_widget_unparent (child->widget);
4042 gtk_widget_destroy (child->widget);
4043 g_object_unref (child->widget);
4046 toolbar->children = g_list_remove (toolbar->children, child);
4050 priv->content = g_list_remove (priv->content, content);
4052 if (!toolbar_content_is_placeholder (content))
4053 toolbar->num_children--;
4055 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
4056 priv->need_rebuild = TRUE;
4060 toolbar_content_free (ToolbarContent *content)
4062 g_slice_free (ToolbarContent, content);
4066 calculate_max_homogeneous_pixels (GtkWidget *widget)
4068 PangoContext *context;
4069 PangoFontMetrics *metrics;
4072 context = gtk_widget_get_pango_context (widget);
4073 metrics = pango_context_get_metrics (context,
4074 widget->style->font_desc,
4075 pango_context_get_language (context));
4076 char_width = pango_font_metrics_get_approximate_char_width (metrics);
4077 pango_font_metrics_unref (metrics);
4079 return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
4083 toolbar_content_expose (ToolbarContent *content,
4084 GtkContainer *container,
4085 GdkEventExpose *expose)
4087 GtkToolbar *toolbar = GTK_TOOLBAR (container);
4088 GtkToolbarChild *child;
4089 GtkWidget *widget = NULL; /* quiet gcc */
4091 switch (content->type)
4094 if (!content->u.tool_item.is_placeholder)
4095 widget = GTK_WIDGET (content->u.tool_item.item);
4099 child = &(content->u.compatibility.child);
4101 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
4103 if (content->u.compatibility.space_visible &&
4104 get_space_style (toolbar) == GTK_TOOLBAR_SPACE_LINE)
4105 _gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), toolbar,
4107 &content->u.compatibility.space_allocation);
4111 widget = child->widget;
4116 gtk_container_propagate_expose (container, widget, expose);
4120 toolbar_content_visible (ToolbarContent *content,
4121 GtkToolbar *toolbar)
4125 switch (content->type)
4128 item = content->u.tool_item.item;
4130 if (!GTK_WIDGET_VISIBLE (item))
4133 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL &&
4134 gtk_tool_item_get_visible_horizontal (item))
4137 if ((toolbar->orientation == GTK_ORIENTATION_VERTICAL &&
4138 gtk_tool_item_get_visible_vertical (item)))
4145 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4146 return GTK_WIDGET_VISIBLE (content->u.compatibility.child.widget);
4152 g_assert_not_reached ();
4157 toolbar_content_size_request (ToolbarContent *content,
4158 GtkToolbar *toolbar,
4159 GtkRequisition *requisition)
4163 switch (content->type)
4166 gtk_widget_size_request (GTK_WIDGET (content->u.tool_item.item),
4168 if (content->u.tool_item.is_placeholder &&
4169 content->u.tool_item.disappearing)
4171 requisition->width = 0;
4172 requisition->height = 0;
4177 space_size = get_space_size (toolbar);
4179 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4181 gtk_widget_size_request (content->u.compatibility.child.widget,
4186 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
4188 requisition->width = space_size;
4189 requisition->height = 0;
4193 requisition->height = space_size;
4194 requisition->width = 0;
4203 toolbar_content_is_homogeneous (ToolbarContent *content,
4204 GtkToolbar *toolbar)
4206 gboolean result = FALSE; /* quiet gcc */
4207 GtkRequisition requisition;
4208 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4210 if (priv->max_homogeneous_pixels < 0)
4212 priv->max_homogeneous_pixels =
4213 calculate_max_homogeneous_pixels (GTK_WIDGET (toolbar));
4216 toolbar_content_size_request (content, toolbar, &requisition);
4218 if (requisition.width > priv->max_homogeneous_pixels)
4221 switch (content->type)
4224 result = gtk_tool_item_get_homogeneous (content->u.tool_item.item) &&
4225 !GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4227 if (gtk_tool_item_get_is_important (content->u.tool_item.item) &&
4228 toolbar->style == GTK_TOOLBAR_BOTH_HORIZ &&
4229 toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
4236 if (content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_BUTTON ||
4237 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4238 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4253 toolbar_content_is_placeholder (ToolbarContent *content)
4255 if (content->type == TOOL_ITEM && content->u.tool_item.is_placeholder)
4262 toolbar_content_disappearing (ToolbarContent *content)
4264 if (content->type == TOOL_ITEM && content->u.tool_item.disappearing)
4271 toolbar_content_get_state (ToolbarContent *content)
4273 return content->state;
4277 toolbar_content_child_visible (ToolbarContent *content)
4279 switch (content->type)
4282 return GTK_WIDGET_CHILD_VISIBLE (content->u.tool_item.item);
4286 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4288 return GTK_WIDGET_CHILD_VISIBLE (content->u.compatibility.child.widget);
4292 return content->u.compatibility.space_visible;
4297 return FALSE; /* quiet gcc */
4301 toolbar_content_get_goal_allocation (ToolbarContent *content,
4302 GtkAllocation *allocation)
4304 switch (content->type)
4307 *allocation = content->u.tool_item.goal_allocation;
4311 /* Goal allocations are only relevant when we are
4312 * using the new API, so we should never get here
4314 g_assert_not_reached ();
4320 toolbar_content_get_allocation (ToolbarContent *content,
4321 GtkAllocation *allocation)
4323 GtkToolbarChild *child;
4325 switch (content->type)
4328 *allocation = GTK_WIDGET (content->u.tool_item.item)->allocation;
4332 child = &(content->u.compatibility.child);
4334 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
4335 *allocation = content->u.compatibility.space_allocation;
4337 *allocation = child->widget->allocation;
4343 toolbar_content_set_start_allocation (ToolbarContent *content,
4344 GtkAllocation *allocation)
4346 switch (content->type)
4349 content->u.tool_item.start_allocation = *allocation;
4353 /* start_allocation is only relevant when using the new API */
4354 g_assert_not_reached ();
4360 toolbar_content_get_expand (ToolbarContent *content)
4362 if (content->type == TOOL_ITEM &&
4363 gtk_tool_item_get_expand (content->u.tool_item.item) &&
4364 !content->u.tool_item.disappearing)
4373 toolbar_content_set_goal_allocation (ToolbarContent *content,
4374 GtkAllocation *allocation)
4376 switch (content->type)
4379 content->u.tool_item.goal_allocation = *allocation;
4383 /* Only relevant when using new API */
4384 g_assert_not_reached ();
4390 toolbar_content_set_child_visible (ToolbarContent *content,
4391 GtkToolbar *toolbar,
4394 GtkToolbarChild *child;
4396 switch (content->type)
4399 gtk_widget_set_child_visible (GTK_WIDGET (content->u.tool_item.item),
4404 child = &(content->u.compatibility.child);
4406 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4408 gtk_widget_set_child_visible (child->widget, visible);
4412 if (content->u.compatibility.space_visible != visible)
4414 content->u.compatibility.space_visible = visible;
4415 gtk_widget_queue_draw (GTK_WIDGET (toolbar));
4423 toolbar_content_get_start_allocation (ToolbarContent *content,
4424 GtkAllocation *start_allocation)
4426 switch (content->type)
4429 *start_allocation = content->u.tool_item.start_allocation;
4433 /* Only relevant for new API */
4434 g_assert_not_reached ();
4440 toolbar_content_size_allocate (ToolbarContent *content,
4441 GtkAllocation *allocation)
4443 switch (content->type)
4446 gtk_widget_size_allocate (GTK_WIDGET (content->u.tool_item.item),
4451 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4453 gtk_widget_size_allocate (content->u.compatibility.child.widget,
4458 content->u.compatibility.space_allocation = *allocation;
4465 toolbar_content_set_state (ToolbarContent *content,
4468 content->state = state;
4472 toolbar_content_get_widget (ToolbarContent *content)
4474 GtkToolbarChild *child;
4476 switch (content->type)
4479 return GTK_WIDGET (content->u.tool_item.item);
4483 child = &(content->u.compatibility.child);
4484 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4485 return child->widget;
4495 toolbar_content_set_disappearing (ToolbarContent *content,
4496 gboolean disappearing)
4498 switch (content->type)
4501 content->u.tool_item.disappearing = disappearing;
4505 /* Only relevant for new API */
4506 g_assert_not_reached ();
4512 toolbar_content_set_size_request (ToolbarContent *content,
4516 switch (content->type)
4519 gtk_widget_set_size_request (GTK_WIDGET (content->u.tool_item.item),
4524 /* Setting size requests only happens with sliding,
4525 * so not relevant here
4527 g_assert_not_reached ();
4533 toolbar_child_reconfigure (GtkToolbar *toolbar,
4534 GtkToolbarChild *child)
4538 GtkToolbarStyle style;
4539 GtkIconSize icon_size;
4540 GtkReliefStyle relief;
4543 style = gtk_toolbar_get_style (toolbar);
4544 icon_size = gtk_toolbar_get_icon_size (toolbar);
4545 relief = gtk_toolbar_get_relief_style (toolbar);
4548 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4549 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4550 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4552 box = gtk_bin_get_child (GTK_BIN (child->widget));
4554 if (style == GTK_TOOLBAR_BOTH && GTK_IS_HBOX (box))
4558 vbox = gtk_vbox_new (FALSE, 0);
4561 gtk_widget_reparent (child->label, vbox);
4563 gtk_widget_reparent (child->icon, vbox);
4565 gtk_widget_destroy (box);
4566 gtk_container_add (GTK_CONTAINER (child->widget), vbox);
4568 gtk_widget_show (vbox);
4570 else if (style == GTK_TOOLBAR_BOTH_HORIZ && GTK_IS_VBOX (box))
4574 hbox = gtk_hbox_new (FALSE, 0);
4577 gtk_widget_reparent (child->label, hbox);
4579 gtk_widget_reparent (child->icon, hbox);
4581 gtk_widget_destroy (box);
4582 gtk_container_add (GTK_CONTAINER (child->widget), hbox);
4584 gtk_widget_show (hbox);
4587 set_child_packing_and_visibility (toolbar, child);
4592 if ((child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4593 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4594 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON) &&
4595 GTK_IS_IMAGE (child->icon))
4597 image = GTK_IMAGE (child->icon);
4598 if (gtk_image_get_storage_type (image) == GTK_IMAGE_STOCK)
4600 gtk_image_get_stock (image, &stock_id, NULL);
4601 stock_id = g_strdup (stock_id);
4602 gtk_image_set_from_stock (image,
4610 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4611 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4612 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4614 gtk_button_set_relief (GTK_BUTTON (child->widget), relief);
4619 toolbar_content_toolbar_reconfigured (ToolbarContent *content,
4620 GtkToolbar *toolbar)
4622 switch (content->type)
4625 gtk_tool_item_toolbar_reconfigured (content->u.tool_item.item);
4629 toolbar_child_reconfigure (toolbar, &(content->u.compatibility.child));
4635 toolbar_content_retrieve_menu_item (ToolbarContent *content)
4637 if (content->type == TOOL_ITEM)
4638 return gtk_tool_item_retrieve_proxy_menu_item (content->u.tool_item.item);
4640 /* FIXME - we might actually be able to do something meaningful here */
4645 toolbar_content_has_proxy_menu_item (ToolbarContent *content)
4647 if (content->type == TOOL_ITEM)
4649 GtkWidget *menu_item;
4651 if (content->u.tool_item.has_menu == YES)
4653 else if (content->u.tool_item.has_menu == NO)
4656 menu_item = toolbar_content_retrieve_menu_item (content);
4658 content->u.tool_item.has_menu = menu_item? YES : NO;
4660 return menu_item != NULL;
4669 toolbar_content_set_unknown_menu_status (ToolbarContent *content)
4671 if (content->type == TOOL_ITEM)
4672 content->u.tool_item.has_menu = UNKNOWN;
4676 toolbar_content_is_separator (ToolbarContent *content)
4678 GtkToolbarChild *child;
4680 switch (content->type)
4683 return GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4687 child = &(content->u.compatibility.child);
4688 return (child->type == GTK_TOOLBAR_CHILD_SPACE);
4696 toolbar_content_set_expand (ToolbarContent *content,
4699 if (content->type == TOOL_ITEM)
4700 gtk_tool_item_set_expand (content->u.tool_item.item, expand);
4704 ignore_show_and_hide_all (ToolbarContent *content)
4706 if (content->type == COMPATIBILITY)
4708 GtkToolbarChildType type = content->u.compatibility.child.type;
4710 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
4711 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4712 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
4722 toolbar_content_show_all (ToolbarContent *content)
4726 if (ignore_show_and_hide_all (content))
4729 widget = toolbar_content_get_widget (content);
4731 gtk_widget_show_all (widget);
4735 toolbar_content_hide_all (ToolbarContent *content)
4739 if (ignore_show_and_hide_all (content))
4742 widget = toolbar_content_get_widget (content);
4744 gtk_widget_hide_all (widget);
4751 get_space_size (GtkToolbar *toolbar)
4753 gint space_size = DEFAULT_SPACE_SIZE;
4757 gtk_widget_style_get (GTK_WIDGET (toolbar),
4758 "space-size", &space_size,
4765 static GtkToolbarSpaceStyle
4766 get_space_style (GtkToolbar *toolbar)
4768 GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
4772 gtk_widget_style_get (GTK_WIDGET (toolbar),
4773 "space-style", &space_style,
4780 static GtkReliefStyle
4781 get_button_relief (GtkToolbar *toolbar)
4783 GtkReliefStyle button_relief = GTK_RELIEF_NORMAL;
4785 gtk_widget_ensure_style (GTK_WIDGET (toolbar));
4787 gtk_widget_style_get (GTK_WIDGET (toolbar),
4788 "button-relief", &button_relief,
4791 return button_relief;
4795 get_internal_padding (GtkToolbar *toolbar)
4799 gtk_widget_style_get (GTK_WIDGET (toolbar),
4800 "internal-padding", &ipadding,
4807 get_max_child_expand (GtkToolbar *toolbar)
4809 gint mexpand = G_MAXINT;
4811 gtk_widget_style_get (GTK_WIDGET (toolbar),
4812 "max-child-expand", &mexpand,
4817 static GtkShadowType
4818 get_shadow_type (GtkToolbar *toolbar)
4820 GtkShadowType shadow_type;
4822 gtk_widget_style_get (GTK_WIDGET (toolbar),
4823 "shadow-type", &shadow_type,
4833 gtk_toolbar_check_old_api (GtkToolbar *toolbar)
4835 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4837 if (priv->api_mode == NEW_API)
4839 g_warning (MIXED_API_WARNING);
4843 priv->api_mode = OLD_API;
4848 gtk_toolbar_check_new_api (GtkToolbar *toolbar)
4850 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4852 if (priv->api_mode == OLD_API)
4854 g_warning (MIXED_API_WARNING);
4858 priv->api_mode = NEW_API;
4862 /* GTK+ internal methods */
4865 _gtk_toolbar_get_default_space_size (void)
4867 return DEFAULT_SPACE_SIZE;
4871 _gtk_toolbar_paint_space_line (GtkWidget *widget,
4872 GtkToolbar *toolbar,
4873 const GdkRectangle *area,
4874 const GtkAllocation *allocation)
4876 const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
4877 const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
4879 GtkOrientation orientation;
4881 g_return_if_fail (GTK_IS_WIDGET (widget));
4883 orientation = toolbar? toolbar->orientation : GTK_ORIENTATION_HORIZONTAL;
4885 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4887 gboolean wide_separators;
4888 gint separator_width;
4890 gtk_widget_style_get (widget,
4891 "wide-separators", &wide_separators,
4892 "separator-width", &separator_width,
4895 if (wide_separators)
4896 gtk_paint_box (widget->style, widget->window,
4897 GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
4898 area, widget, "vseparator",
4899 allocation->x + (allocation->width - separator_width) / 2,
4900 allocation->y + allocation->height * start_fraction,
4902 allocation->height * (end_fraction - start_fraction));
4904 gtk_paint_vline (widget->style, widget->window,
4905 GTK_WIDGET_STATE (widget), area, widget,
4907 allocation->y + allocation->height * start_fraction,
4908 allocation->y + allocation->height * end_fraction,
4909 allocation->x + (allocation->width - widget->style->xthickness) / 2);
4913 gboolean wide_separators;
4914 gint separator_height;
4916 gtk_widget_style_get (widget,
4917 "wide-separators", &wide_separators,
4918 "separator-height", &separator_height,
4921 if (wide_separators)
4922 gtk_paint_box (widget->style, widget->window,
4923 GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
4924 area, widget, "hseparator",
4925 allocation->x + allocation->width * start_fraction,
4926 allocation->y + (allocation->height - separator_height) / 2,
4927 allocation->width * (end_fraction - start_fraction),
4930 gtk_paint_hline (widget->style, widget->window,
4931 GTK_WIDGET_STATE (widget), area, widget,
4933 allocation->x + allocation->width * start_fraction,
4934 allocation->x + allocation->width * end_fraction,
4935 allocation->y + (allocation->height - widget->style->ythickness) / 2);
4940 _gtk_toolbar_elide_underscores (const gchar *original)
4943 const gchar *p, *end;
4945 gboolean last_underscore;
4950 len = strlen (original);
4951 q = result = g_malloc (len + 1);
4952 last_underscore = FALSE;
4954 end = original + len;
4955 for (p = original; p < end; p++)
4957 if (!last_underscore && *p == '_')
4958 last_underscore = TRUE;
4961 last_underscore = FALSE;
4962 if (original + 2 <= p && p + 1 <= end &&
4963 p[-2] == '(' && p[-1] == '_' && p[0] != '_' && p[1] == ')')
4974 if (last_underscore)
4983 toolbar_get_icon_size (GtkToolShell *shell)
4985 return GTK_TOOLBAR (shell)->icon_size;
4988 static GtkOrientation
4989 toolbar_get_orientation (GtkToolShell *shell)
4991 return GTK_TOOLBAR (shell)->orientation;
4994 static GtkToolbarStyle
4995 toolbar_get_style (GtkToolShell *shell)
4997 return GTK_TOOLBAR (shell)->style;
5000 static GtkReliefStyle
5001 toolbar_get_relief_style (GtkToolShell *shell)
5003 return get_button_relief (GTK_TOOLBAR (shell));
5007 toolbar_rebuild_menu (GtkToolShell *shell)
5009 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (shell);
5012 priv->need_rebuild = TRUE;
5014 for (list = priv->content; list != NULL; list = list->next)
5016 ToolbarContent *content = list->data;
5018 toolbar_content_set_unknown_menu_status (content);
5021 gtk_widget_queue_resize (GTK_WIDGET (shell));
5024 #define __GTK_TOOLBAR_C__
5025 #include "gtkaliasdef.c"