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
36 #include "gtktoolbar.h"
37 #include "gtktoolshell.h"
38 #include "gtkradiotoolbutton.h"
39 #include "gtkseparatortoolitem.h"
41 #include "gtkradiobutton.h"
42 #include "gtktoolbar.h"
43 #include "gtkbindings.h"
44 #include <gdk/gdkkeysyms.h>
45 #include "gtkmarshalers.h"
49 #include "gtkprivate.h"
55 #include "gtkseparatormenuitem.h"
59 typedef struct _ToolbarContent ToolbarContent;
61 #define DEFAULT_IPADDING 0
63 #define DEFAULT_SPACE_SIZE 12
64 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
65 #define SPACE_LINE_DIVISION 10.0
66 #define SPACE_LINE_START 2.0
67 #define SPACE_LINE_END 8.0
69 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
70 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
71 #define DEFAULT_ANIMATION_STATE TRUE
73 #define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
74 * in the homogeneous game. In units of
75 * pango_font_get_estimated_char_width().
77 #define SLIDE_SPEED 600.0 /* How fast the items slide, in pixels per second */
78 #define ACCEL_THRESHOLD 0.18 /* After how much time in seconds will items start speeding up */
80 #define MIXED_API_WARNING \
81 "Mixing deprecated and non-deprecated GtkToolbar API is not allowed"
95 /* Child properties */
99 CHILD_PROP_HOMOGENEOUS
130 struct _GtkToolbarPrivate
135 GtkWidget * arrow_button;
138 GdkWindow * event_window;
140 GtkSettings * settings;
142 GtkToolItem * highlight_tool_item;
143 gint max_homogeneous_pixels;
147 gulong settings_connection;
149 guint show_arrow : 1;
151 guint is_sliding : 1;
152 guint need_rebuild : 1; /* whether the overflow menu should be regenerated */
156 static void gtk_toolbar_set_property (GObject *object,
160 static void gtk_toolbar_get_property (GObject *object,
164 static gint gtk_toolbar_expose (GtkWidget *widget,
165 GdkEventExpose *event);
166 static void gtk_toolbar_realize (GtkWidget *widget);
167 static void gtk_toolbar_unrealize (GtkWidget *widget);
168 static void gtk_toolbar_size_request (GtkWidget *widget,
169 GtkRequisition *requisition);
170 static void gtk_toolbar_size_allocate (GtkWidget *widget,
171 GtkAllocation *allocation);
172 static void gtk_toolbar_style_set (GtkWidget *widget,
173 GtkStyle *prev_style);
174 static gboolean gtk_toolbar_focus (GtkWidget *widget,
175 GtkDirectionType dir);
176 static void gtk_toolbar_move_focus (GtkWidget *widget,
177 GtkDirectionType dir);
178 static void gtk_toolbar_screen_changed (GtkWidget *widget,
179 GdkScreen *previous_screen);
180 static void gtk_toolbar_map (GtkWidget *widget);
181 static void gtk_toolbar_unmap (GtkWidget *widget);
182 static void gtk_toolbar_set_child_property (GtkContainer *container,
187 static void gtk_toolbar_get_child_property (GtkContainer *container,
192 static void gtk_toolbar_finalize (GObject *object);
193 static void gtk_toolbar_show_all (GtkWidget *widget);
194 static void gtk_toolbar_hide_all (GtkWidget *widget);
195 static void gtk_toolbar_add (GtkContainer *container,
197 static void gtk_toolbar_remove (GtkContainer *container,
199 static void gtk_toolbar_forall (GtkContainer *container,
200 gboolean include_internals,
201 GtkCallback callback,
202 gpointer callback_data);
203 static GType gtk_toolbar_child_type (GtkContainer *container);
204 static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
205 GtkOrientation orientation);
206 static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
207 GtkToolbarStyle style);
208 static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
209 gboolean focus_home);
210 static gboolean gtk_toolbar_button_press (GtkWidget *toolbar,
211 GdkEventButton *event);
212 static gboolean gtk_toolbar_arrow_button_press (GtkWidget *button,
213 GdkEventButton *event,
214 GtkToolbar *toolbar);
215 static void gtk_toolbar_arrow_button_clicked (GtkWidget *button,
216 GtkToolbar *toolbar);
217 static void gtk_toolbar_update_button_relief (GtkToolbar *toolbar);
218 static gboolean gtk_toolbar_popup_menu (GtkWidget *toolbar);
219 static GtkWidget *internal_insert_element (GtkToolbar *toolbar,
220 GtkToolbarChildType type,
223 const char *tooltip_text,
224 const char *tooltip_private_text,
230 static void gtk_toolbar_reconfigured (GtkToolbar *toolbar);
231 static gboolean gtk_toolbar_check_new_api (GtkToolbar *toolbar);
232 static gboolean gtk_toolbar_check_old_api (GtkToolbar *toolbar);
234 static GtkReliefStyle get_button_relief (GtkToolbar *toolbar);
235 static gint get_internal_padding (GtkToolbar *toolbar);
236 static gint get_max_child_expand (GtkToolbar *toolbar);
237 static GtkShadowType get_shadow_type (GtkToolbar *toolbar);
238 static gint get_space_size (GtkToolbar *toolbar);
239 static GtkToolbarSpaceStyle get_space_style (GtkToolbar *toolbar);
241 /* methods on ToolbarContent 'class' */
242 static ToolbarContent *toolbar_content_new_tool_item (GtkToolbar *toolbar,
244 gboolean is_placeholder,
246 static ToolbarContent *toolbar_content_new_compatibility (GtkToolbar *toolbar,
247 GtkToolbarChildType type,
252 static void toolbar_content_remove (ToolbarContent *content,
253 GtkToolbar *toolbar);
254 static void toolbar_content_free (ToolbarContent *content);
255 static void toolbar_content_expose (ToolbarContent *content,
256 GtkContainer *container,
257 GdkEventExpose *expose);
258 static gboolean toolbar_content_visible (ToolbarContent *content,
259 GtkToolbar *toolbar);
260 static void toolbar_content_size_request (ToolbarContent *content,
262 GtkRequisition *requisition);
263 static gboolean toolbar_content_is_homogeneous (ToolbarContent *content,
264 GtkToolbar *toolbar);
265 static gboolean toolbar_content_is_placeholder (ToolbarContent *content);
266 static gboolean toolbar_content_disappearing (ToolbarContent *content);
267 static ItemState toolbar_content_get_state (ToolbarContent *content);
268 static gboolean toolbar_content_child_visible (ToolbarContent *content);
269 static void toolbar_content_get_goal_allocation (ToolbarContent *content,
270 GtkAllocation *allocation);
271 static void toolbar_content_get_allocation (ToolbarContent *content,
272 GtkAllocation *allocation);
273 static void toolbar_content_set_start_allocation (ToolbarContent *content,
274 GtkAllocation *new_start_allocation);
275 static void toolbar_content_get_start_allocation (ToolbarContent *content,
276 GtkAllocation *start_allocation);
277 static gboolean toolbar_content_get_expand (ToolbarContent *content);
278 static void toolbar_content_set_goal_allocation (ToolbarContent *content,
279 GtkAllocation *allocation);
280 static void toolbar_content_set_child_visible (ToolbarContent *content,
283 static void toolbar_content_size_allocate (ToolbarContent *content,
284 GtkAllocation *allocation);
285 static void toolbar_content_set_state (ToolbarContent *content,
286 ItemState new_state);
287 static GtkWidget * toolbar_content_get_widget (ToolbarContent *content);
288 static void toolbar_content_set_disappearing (ToolbarContent *content,
289 gboolean disappearing);
290 static void toolbar_content_set_size_request (ToolbarContent *content,
293 static void toolbar_content_toolbar_reconfigured (ToolbarContent *content,
294 GtkToolbar *toolbar);
295 static GtkWidget * toolbar_content_retrieve_menu_item (ToolbarContent *content);
296 static gboolean toolbar_content_has_proxy_menu_item (ToolbarContent *content);
297 static gboolean toolbar_content_is_separator (ToolbarContent *content);
298 static void toolbar_content_show_all (ToolbarContent *content);
299 static void toolbar_content_hide_all (ToolbarContent *content);
300 static void toolbar_content_set_expand (ToolbarContent *content,
303 static void toolbar_tool_shell_iface_init (GtkToolShellIface *iface);
304 static GtkIconSize toolbar_get_icon_size (GtkToolShell *shell);
305 static GtkOrientation toolbar_get_orientation (GtkToolShell *shell);
306 static GtkToolbarStyle toolbar_get_style (GtkToolShell *shell);
307 static GtkReliefStyle toolbar_get_relief_style (GtkToolShell *shell);
308 static void toolbar_rebuild_menu (GtkToolShell *shell);
310 #define GTK_TOOLBAR_GET_PRIVATE(o) \
311 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOLBAR, GtkToolbarPrivate))
313 static guint toolbar_signals [LAST_SIGNAL] = { 0 };
315 G_DEFINE_TYPE_WITH_CODE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER,
316 G_IMPLEMENT_INTERFACE (GTK_TYPE_TOOL_SHELL, toolbar_tool_shell_iface_init))
319 add_arrow_bindings (GtkBindingSet *binding_set,
321 GtkDirectionType dir)
323 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
325 gtk_binding_entry_add_signal (binding_set, keysym, 0,
327 GTK_TYPE_DIRECTION_TYPE, dir);
328 gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
330 GTK_TYPE_DIRECTION_TYPE, dir);
334 add_ctrl_tab_bindings (GtkBindingSet *binding_set,
335 GdkModifierType modifiers,
336 GtkDirectionType direction)
338 gtk_binding_entry_add_signal (binding_set,
339 GDK_Tab, GDK_CONTROL_MASK | modifiers,
341 GTK_TYPE_DIRECTION_TYPE, direction);
342 gtk_binding_entry_add_signal (binding_set,
343 GDK_KP_Tab, GDK_CONTROL_MASK | modifiers,
345 GTK_TYPE_DIRECTION_TYPE, direction);
349 toolbar_tool_shell_iface_init (GtkToolShellIface *iface)
351 iface->get_icon_size = toolbar_get_icon_size;
352 iface->get_orientation = toolbar_get_orientation;
353 iface->get_style = toolbar_get_style;
354 iface->get_relief_style = toolbar_get_relief_style;
355 iface->rebuild_menu = toolbar_rebuild_menu;
359 gtk_toolbar_class_init (GtkToolbarClass *klass)
361 GObjectClass *gobject_class;
362 GtkWidgetClass *widget_class;
363 GtkContainerClass *container_class;
364 GtkBindingSet *binding_set;
366 gobject_class = (GObjectClass *)klass;
367 widget_class = (GtkWidgetClass *)klass;
368 container_class = (GtkContainerClass *)klass;
370 gobject_class->set_property = gtk_toolbar_set_property;
371 gobject_class->get_property = gtk_toolbar_get_property;
372 gobject_class->finalize = gtk_toolbar_finalize;
374 widget_class->button_press_event = gtk_toolbar_button_press;
375 widget_class->expose_event = gtk_toolbar_expose;
376 widget_class->size_request = gtk_toolbar_size_request;
377 widget_class->size_allocate = gtk_toolbar_size_allocate;
378 widget_class->style_set = gtk_toolbar_style_set;
379 widget_class->focus = gtk_toolbar_focus;
381 /* need to override the base class function via override_class_handler,
382 * because the signal slot is not available in GtkWidgetClass
384 g_signal_override_class_handler ("move-focus",
386 G_CALLBACK (gtk_toolbar_move_focus));
388 widget_class->screen_changed = gtk_toolbar_screen_changed;
389 widget_class->realize = gtk_toolbar_realize;
390 widget_class->unrealize = gtk_toolbar_unrealize;
391 widget_class->map = gtk_toolbar_map;
392 widget_class->unmap = gtk_toolbar_unmap;
393 widget_class->popup_menu = gtk_toolbar_popup_menu;
394 widget_class->show_all = gtk_toolbar_show_all;
395 widget_class->hide_all = gtk_toolbar_hide_all;
397 container_class->add = gtk_toolbar_add;
398 container_class->remove = gtk_toolbar_remove;
399 container_class->forall = gtk_toolbar_forall;
400 container_class->child_type = gtk_toolbar_child_type;
401 container_class->get_child_property = gtk_toolbar_get_child_property;
402 container_class->set_child_property = gtk_toolbar_set_child_property;
404 klass->orientation_changed = gtk_toolbar_orientation_changed;
405 klass->style_changed = gtk_toolbar_real_style_changed;
408 * GtkToolbar::orientation-changed:
409 * @toolbar: the object which emitted the signal
410 * @orientation: the new #GtkOrientation of the toolbar
412 * Emitted when the orientation of the toolbar changes.
414 toolbar_signals[ORIENTATION_CHANGED] =
415 g_signal_new (I_("orientation-changed"),
416 G_OBJECT_CLASS_TYPE (klass),
418 G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
420 g_cclosure_marshal_VOID__ENUM,
422 GTK_TYPE_ORIENTATION);
424 * GtkToolbar::style-changed:
425 * @toolbar: The #GtkToolbar which emitted the signal
426 * @style: the new #GtkToolbarStyle of the toolbar
428 * Emitted when the style of the toolbar changes.
430 toolbar_signals[STYLE_CHANGED] =
431 g_signal_new (I_("style-changed"),
432 G_OBJECT_CLASS_TYPE (klass),
434 G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
436 g_cclosure_marshal_VOID__ENUM,
438 GTK_TYPE_TOOLBAR_STYLE);
440 * GtkToolbar::popup-context-menu:
441 * @toolbar: the #GtkToolbar which emitted the signal
442 * @x: the x coordinate of the point where the menu should appear
443 * @y: the y coordinate of the point where the menu should appear
444 * @button: the mouse button the user pressed, or -1
446 * Emitted when the user right-clicks the toolbar or uses the
447 * keybinding to display a popup menu.
449 * Application developers should handle this signal if they want
450 * to display a context menu on the toolbar. The context-menu should
451 * appear at the coordinates given by @x and @y. The mouse button
452 * number is given by the @button parameter. If the menu was popped
453 * up using the keybaord, @button is -1.
455 * Return value: return %TRUE if the signal was handled, %FALSE if not
457 toolbar_signals[POPUP_CONTEXT_MENU] =
458 g_signal_new (I_("popup-context-menu"),
459 G_OBJECT_CLASS_TYPE (klass),
461 G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
462 _gtk_boolean_handled_accumulator, NULL,
463 _gtk_marshal_BOOLEAN__INT_INT_INT,
465 G_TYPE_INT, G_TYPE_INT,
469 * GtkToolbar::focus-home-or-end:
470 * @toolbar: the #GtkToolbar which emitted the signal
471 * @focus_home: %TRUE if the first item should be focused
473 * A keybinding signal used internally by GTK+. This signal can't
474 * be used in application code
476 * Return value: %TRUE if the signal was handled, %FALSE if not
478 toolbar_signals[FOCUS_HOME_OR_END] =
479 g_signal_new_class_handler (I_("focus-home-or-end"),
480 G_OBJECT_CLASS_TYPE (klass),
481 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
482 G_CALLBACK (gtk_toolbar_focus_home_or_end),
484 _gtk_marshal_BOOLEAN__BOOLEAN,
489 g_object_class_install_property (gobject_class,
491 g_param_spec_enum ("orientation",
493 P_("The orientation of the toolbar"),
494 GTK_TYPE_ORIENTATION,
495 GTK_ORIENTATION_HORIZONTAL,
496 GTK_PARAM_READWRITE));
498 g_object_class_install_property (gobject_class,
500 g_param_spec_enum ("toolbar-style",
502 P_("How to draw the toolbar"),
503 GTK_TYPE_TOOLBAR_STYLE,
504 DEFAULT_TOOLBAR_STYLE,
505 GTK_PARAM_READWRITE));
506 g_object_class_install_property (gobject_class,
508 g_param_spec_boolean ("show-arrow",
510 P_("If an arrow should be shown if the toolbar doesn't fit"),
512 GTK_PARAM_READWRITE));
516 * GtkToolbar:tooltips:
518 * If the tooltips of the toolbar should be active or not.
522 g_object_class_install_property (gobject_class,
524 g_param_spec_boolean ("tooltips",
526 P_("If the tooltips of the toolbar should be active or not"),
528 GTK_PARAM_READWRITE));
532 * GtkToolbar:icon-size:
534 * The size of the icons in a toolbar is normally determined by
535 * the toolbar-icon-size setting. When this property is set, it
536 * overrides the setting.
538 * This should only be used for special-purpose toolbars, normal
539 * application toolbars should respect the user preferences for the
544 g_object_class_install_property (gobject_class,
546 g_param_spec_enum ("icon-size",
548 P_("Size of icons in this toolbar"),
551 GTK_PARAM_READWRITE));
554 * GtkToolbar:icon-size-set:
556 * Is %TRUE if the icon-size property has been set.
560 g_object_class_install_property (gobject_class,
562 g_param_spec_boolean ("icon-size-set",
564 P_("Whether the icon-size property has been set"),
566 GTK_PARAM_READWRITE));
568 /* child properties */
569 gtk_container_class_install_child_property (container_class,
571 g_param_spec_boolean ("expand",
573 P_("Whether the item should receive extra space when the toolbar grows"),
575 GTK_PARAM_READWRITE));
577 gtk_container_class_install_child_property (container_class,
578 CHILD_PROP_HOMOGENEOUS,
579 g_param_spec_boolean ("homogeneous",
581 P_("Whether the item should be the same size as other homogeneous items"),
583 GTK_PARAM_READWRITE));
585 /* style properties */
586 gtk_widget_class_install_style_property (widget_class,
587 g_param_spec_int ("space-size",
589 P_("Size of spacers"),
593 GTK_PARAM_READABLE));
595 gtk_widget_class_install_style_property (widget_class,
596 g_param_spec_int ("internal-padding",
597 P_("Internal padding"),
598 P_("Amount of border space between the toolbar shadow and the buttons"),
602 GTK_PARAM_READABLE));
604 gtk_widget_class_install_style_property (widget_class,
605 g_param_spec_int ("max-child-expand",
606 P_("Maximum child expand"),
607 P_("Maximum amount of space an expandable item will be given"),
611 GTK_PARAM_READABLE));
613 gtk_widget_class_install_style_property (widget_class,
614 g_param_spec_enum ("space-style",
616 P_("Whether spacers are vertical lines or just blank"),
617 GTK_TYPE_TOOLBAR_SPACE_STYLE,
619 GTK_PARAM_READABLE));
621 gtk_widget_class_install_style_property (widget_class,
622 g_param_spec_enum ("button-relief",
624 P_("Type of bevel around toolbar buttons"),
625 GTK_TYPE_RELIEF_STYLE,
627 GTK_PARAM_READABLE));
628 gtk_widget_class_install_style_property (widget_class,
629 g_param_spec_enum ("shadow-type",
631 P_("Style of bevel around the toolbar"),
632 GTK_TYPE_SHADOW_TYPE,
634 GTK_PARAM_READABLE));
636 gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-style",
638 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
639 GTK_TYPE_TOOLBAR_STYLE,
640 DEFAULT_TOOLBAR_STYLE,
641 GTK_PARAM_READWRITE));
643 gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-icon-size",
644 P_("Toolbar icon size"),
645 P_("Size of icons in default toolbars"),
648 GTK_PARAM_READWRITE));
650 binding_set = gtk_binding_set_by_class (klass);
652 add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
653 add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
654 add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
655 add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
657 gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, 0,
658 "focus-home-or-end", 1,
659 G_TYPE_BOOLEAN, TRUE);
660 gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
661 "focus-home-or-end", 1,
662 G_TYPE_BOOLEAN, TRUE);
663 gtk_binding_entry_add_signal (binding_set, GDK_KP_End, 0,
664 "focus-home-or-end", 1,
665 G_TYPE_BOOLEAN, FALSE);
666 gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
667 "focus-home-or-end", 1,
668 G_TYPE_BOOLEAN, FALSE);
670 add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
671 add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
673 g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));
677 gtk_toolbar_init (GtkToolbar *toolbar)
679 GtkToolbarPrivate *priv;
681 GTK_WIDGET_UNSET_FLAGS (toolbar, GTK_CAN_FOCUS);
682 GTK_WIDGET_SET_FLAGS (toolbar, GTK_NO_WINDOW);
684 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
686 toolbar->orientation = GTK_ORIENTATION_HORIZONTAL;
687 toolbar->style = DEFAULT_TOOLBAR_STYLE;
688 toolbar->icon_size = DEFAULT_ICON_SIZE;
689 priv->animation = DEFAULT_ANIMATION_STATE;
690 toolbar->tooltips = gtk_tooltips_new ();
691 g_object_ref_sink (toolbar->tooltips);
693 priv->arrow_button = gtk_toggle_button_new ();
694 g_signal_connect (priv->arrow_button, "button-press-event",
695 G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar);
696 g_signal_connect (priv->arrow_button, "clicked",
697 G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar);
698 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
699 get_button_relief (toolbar));
701 priv->api_mode = DONT_KNOW;
703 gtk_button_set_focus_on_click (GTK_BUTTON (priv->arrow_button), FALSE);
705 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
706 gtk_widget_set_name (priv->arrow, "gtk-toolbar-arrow");
707 gtk_widget_show (priv->arrow);
708 gtk_container_add (GTK_CONTAINER (priv->arrow_button), priv->arrow);
710 gtk_widget_set_parent (priv->arrow_button, GTK_WIDGET (toolbar));
712 /* which child position a drop will occur at */
714 priv->show_arrow = TRUE;
715 priv->settings = NULL;
717 priv->max_homogeneous_pixels = -1;
719 priv->timer = g_timer_new ();
723 gtk_toolbar_set_property (GObject *object,
728 GtkToolbar *toolbar = GTK_TOOLBAR (object);
732 case PROP_ORIENTATION:
733 gtk_toolbar_set_orientation (toolbar, g_value_get_enum (value));
735 case PROP_TOOLBAR_STYLE:
736 gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
738 case PROP_SHOW_ARROW:
739 gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
742 gtk_toolbar_set_tooltips (toolbar, g_value_get_boolean (value));
745 gtk_toolbar_set_icon_size (toolbar, g_value_get_enum (value));
747 case PROP_ICON_SIZE_SET:
748 if (g_value_get_boolean (value))
749 toolbar->icon_size_set = TRUE;
751 gtk_toolbar_unset_icon_size (toolbar);
754 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
760 gtk_toolbar_get_property (GObject *object,
765 GtkToolbar *toolbar = GTK_TOOLBAR (object);
766 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
770 case PROP_ORIENTATION:
771 g_value_set_enum (value, toolbar->orientation);
773 case PROP_TOOLBAR_STYLE:
774 g_value_set_enum (value, toolbar->style);
776 case PROP_SHOW_ARROW:
777 g_value_set_boolean (value, priv->show_arrow);
780 g_value_set_boolean (value, gtk_toolbar_get_tooltips (toolbar));
783 g_value_set_enum (value, gtk_toolbar_get_icon_size (toolbar));
785 case PROP_ICON_SIZE_SET:
786 g_value_set_boolean (value, toolbar->icon_size_set);
789 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
795 gtk_toolbar_map (GtkWidget *widget)
797 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
799 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->map (widget);
801 if (priv->event_window)
802 gdk_window_show_unraised (priv->event_window);
806 gtk_toolbar_unmap (GtkWidget *widget)
808 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
810 if (priv->event_window)
811 gdk_window_hide (priv->event_window);
813 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unmap (widget);
817 gtk_toolbar_realize (GtkWidget *widget)
819 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
820 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
822 GdkWindowAttr attributes;
823 gint attributes_mask;
826 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
828 border_width = GTK_CONTAINER (widget)->border_width;
830 attributes.wclass = GDK_INPUT_ONLY;
831 attributes.window_type = GDK_WINDOW_CHILD;
832 attributes.x = widget->allocation.x + border_width;
833 attributes.y = widget->allocation.y + border_width;
834 attributes.width = widget->allocation.width - border_width * 2;
835 attributes.height = widget->allocation.height - border_width * 2;
836 attributes.event_mask = gtk_widget_get_events (widget);
837 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
838 GDK_BUTTON_RELEASE_MASK |
839 GDK_ENTER_NOTIFY_MASK |
840 GDK_LEAVE_NOTIFY_MASK);
842 attributes_mask = GDK_WA_X | GDK_WA_Y;
844 widget->window = gtk_widget_get_parent_window (widget);
845 g_object_ref (widget->window);
846 widget->style = gtk_style_attach (widget->style, widget->window);
848 priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
849 &attributes, attributes_mask);
850 gdk_window_set_user_data (priv->event_window, toolbar);
854 gtk_toolbar_unrealize (GtkWidget *widget)
856 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
858 if (priv->event_window)
860 gdk_window_set_user_data (priv->event_window, NULL);
861 gdk_window_destroy (priv->event_window);
862 priv->event_window = NULL;
865 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize (widget);
869 gtk_toolbar_expose (GtkWidget *widget,
870 GdkEventExpose *event)
872 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
873 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
878 border_width = GTK_CONTAINER (widget)->border_width;
880 if (GTK_WIDGET_DRAWABLE (widget))
882 gtk_paint_box (widget->style,
884 GTK_WIDGET_STATE (widget),
885 get_shadow_type (toolbar),
886 &event->area, widget, "toolbar",
887 border_width + widget->allocation.x,
888 border_width + widget->allocation.y,
889 widget->allocation.width - 2 * border_width,
890 widget->allocation.height - 2 * border_width);
893 for (list = priv->content; list != NULL; list = list->next)
895 ToolbarContent *content = list->data;
897 toolbar_content_expose (content, GTK_CONTAINER (widget), event);
900 gtk_container_propagate_expose (GTK_CONTAINER (widget),
908 gtk_toolbar_size_request (GtkWidget *widget,
909 GtkRequisition *requisition)
911 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
912 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
914 gint max_child_height;
915 gint max_child_width;
916 gint max_homogeneous_child_width;
917 gint max_homogeneous_child_height;
918 gint homogeneous_size;
920 gint pack_front_size;
922 GtkRequisition arrow_requisition;
924 max_homogeneous_child_width = 0;
925 max_homogeneous_child_height = 0;
927 max_child_height = 0;
928 for (list = priv->content; list != NULL; list = list->next)
930 GtkRequisition requisition;
931 ToolbarContent *content = list->data;
933 if (!toolbar_content_visible (content, toolbar))
936 toolbar_content_size_request (content, toolbar, &requisition);
938 max_child_width = MAX (max_child_width, requisition.width);
939 max_child_height = MAX (max_child_height, requisition.height);
941 if (toolbar_content_is_homogeneous (content, toolbar))
943 max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
944 max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
948 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
949 homogeneous_size = max_homogeneous_child_width;
951 homogeneous_size = max_homogeneous_child_height;
954 for (list = priv->content; list != NULL; list = list->next)
956 ToolbarContent *content = list->data;
959 if (!toolbar_content_visible (content, toolbar))
962 if (toolbar_content_is_homogeneous (content, toolbar))
964 size = homogeneous_size;
968 GtkRequisition requisition;
970 toolbar_content_size_request (content, toolbar, &requisition);
972 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
973 size = requisition.width;
975 size = requisition.height;
978 pack_front_size += size;
981 if (priv->show_arrow && priv->api_mode == NEW_API)
983 gtk_widget_size_request (priv->arrow_button, &arrow_requisition);
985 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
986 long_req = arrow_requisition.width;
988 long_req = arrow_requisition.height;
990 /* There is no point requesting space for the arrow if that would take
991 * up more space than all the items combined
993 long_req = MIN (long_req, pack_front_size);
997 arrow_requisition.height = 0;
998 arrow_requisition.width = 0;
1000 long_req = pack_front_size;
1003 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1005 requisition->width = long_req;
1006 requisition->height = MAX (max_child_height, arrow_requisition.height);
1010 requisition->height = long_req;
1011 requisition->width = MAX (max_child_width, arrow_requisition.width);
1015 ipadding = get_internal_padding (toolbar);
1017 requisition->width += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
1018 requisition->height += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
1020 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1022 requisition->width += 2 * widget->style->xthickness;
1023 requisition->height += 2 * widget->style->ythickness;
1026 toolbar->button_maxw = max_homogeneous_child_width;
1027 toolbar->button_maxh = max_homogeneous_child_height;
1031 position (GtkToolbar *toolbar,
1038 if (! GTK_TOOLBAR_GET_PRIVATE (toolbar)->animation)
1041 if (elapsed <= ACCEL_THRESHOLD)
1043 n_pixels = SLIDE_SPEED * elapsed;
1047 /* The formula is a second degree polynomial in
1048 * @elapsed that has the line SLIDE_SPEED * @elapsed
1049 * as tangent for @elapsed == ACCEL_THRESHOLD.
1050 * This makes @n_pixels a smooth function of elapsed time.
1052 n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
1053 SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
1057 return MIN (from + n_pixels, to);
1059 return MAX (from - n_pixels, to);
1063 compute_intermediate_allocation (GtkToolbar *toolbar,
1064 const GtkAllocation *start,
1065 const GtkAllocation *goal,
1066 GtkAllocation *intermediate)
1068 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1069 gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
1071 intermediate->x = position (toolbar, start->x, goal->x, elapsed);
1072 intermediate->y = position (toolbar, start->y, goal->y, elapsed);
1073 intermediate->width = position (toolbar, start->x + start->width,
1074 goal->x + goal->width,
1075 elapsed) - intermediate->x;
1076 intermediate->height = position (toolbar, start->y + start->height,
1077 goal->y + goal->height,
1078 elapsed) - intermediate->y;
1082 fixup_allocation_for_rtl (gint total_size,
1083 GtkAllocation *allocation)
1085 allocation->x += (total_size - (2 * allocation->x + allocation->width));
1089 fixup_allocation_for_vertical (GtkAllocation *allocation)
1093 tmp = allocation->x;
1094 allocation->x = allocation->y;
1095 allocation->y = tmp;
1097 tmp = allocation->width;
1098 allocation->width = allocation->height;
1099 allocation->height = tmp;
1103 get_item_size (GtkToolbar *toolbar,
1104 ToolbarContent *content)
1106 GtkRequisition requisition;
1108 toolbar_content_size_request (content, toolbar, &requisition);
1110 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1112 if (toolbar_content_is_homogeneous (content, toolbar))
1113 return toolbar->button_maxw;
1115 return requisition.width;
1119 if (toolbar_content_is_homogeneous (content, toolbar))
1120 return toolbar->button_maxh;
1122 return requisition.height;
1127 slide_idle_handler (gpointer data)
1129 GtkToolbar *toolbar = data;
1130 GtkToolbarPrivate *priv;
1133 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1135 if (priv->need_sync)
1138 priv->need_sync = FALSE;
1141 for (list = priv->content; list != NULL; list = list->next)
1143 ToolbarContent *content = list->data;
1145 GtkAllocation goal_allocation;
1146 GtkAllocation allocation;
1149 state = toolbar_content_get_state (content);
1150 toolbar_content_get_goal_allocation (content, &goal_allocation);
1151 toolbar_content_get_allocation (content, &allocation);
1155 if (state == NOT_ALLOCATED)
1157 /* an unallocated item means that size allocate has to
1158 * called at least once more
1163 /* An invisible item with a goal allocation of
1164 * 0 is already at its goal.
1166 if ((state == NORMAL || state == OVERFLOWN) &&
1167 ((goal_allocation.width != 0 &&
1168 goal_allocation.height != 0) ||
1169 toolbar_content_child_visible (content)))
1171 if ((goal_allocation.x != allocation.x ||
1172 goal_allocation.y != allocation.y ||
1173 goal_allocation.width != allocation.width ||
1174 goal_allocation.height != allocation.height))
1176 /* An item is not in its right position yet. Note
1177 * that OVERFLOWN items do get an allocation in
1178 * gtk_toolbar_size_allocate(). This way you can see
1179 * them slide back in when you drag an item off the
1186 if (toolbar_content_is_placeholder (content) &&
1187 toolbar_content_disappearing (content) &&
1188 toolbar_content_child_visible (content))
1190 /* A disappearing placeholder is still visible.
1198 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1204 priv->is_sliding = FALSE;
1211 rect_within (GtkAllocation *a1,
1214 return (a1->x >= a2->x &&
1215 a1->x + a1->width <= a2->x + a2->width &&
1217 a1->y + a1->height <= a2->y + a2->height);
1221 gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
1223 GtkWidget *widget = GTK_WIDGET (toolbar);
1224 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1232 /* Start the sliding. This function copies the allocation of every
1233 * item into content->start_allocation. For items that haven't
1234 * been allocated yet, we calculate their position and save that
1235 * in start_allocatino along with zero width and zero height.
1237 * FIXME: It would be nice if we could share this code with
1238 * the equivalent in gtk_widget_size_allocate().
1240 priv->is_sliding = TRUE;
1243 priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
1245 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1246 vertical = (toolbar->orientation == GTK_ORIENTATION_VERTICAL);
1247 border_width = get_internal_padding (toolbar) + GTK_CONTAINER (toolbar)->border_width;
1251 cur_x = widget->allocation.width - border_width - widget->style->xthickness;
1252 cur_y = widget->allocation.height - border_width - widget->style->ythickness;
1256 cur_x = border_width + widget->style->xthickness;
1257 cur_y = border_width + widget->style->ythickness;
1260 cur_x += widget->allocation.x;
1261 cur_y += widget->allocation.y;
1263 for (list = priv->content; list != NULL; list = list->next)
1265 ToolbarContent *content = list->data;
1266 GtkAllocation new_start_allocation;
1267 GtkAllocation item_allocation;
1270 state = toolbar_content_get_state (content);
1271 toolbar_content_get_allocation (content, &item_allocation);
1273 if ((state == NORMAL &&
1274 rect_within (&item_allocation, &(widget->allocation))) ||
1277 new_start_allocation = item_allocation;
1281 new_start_allocation.x = cur_x;
1282 new_start_allocation.y = cur_y;
1286 new_start_allocation.width = widget->allocation.width -
1287 2 * border_width - 2 * widget->style->xthickness;
1288 new_start_allocation.height = 0;
1292 new_start_allocation.width = 0;
1293 new_start_allocation.height = widget->allocation.height -
1294 2 * border_width - 2 * widget->style->ythickness;
1299 cur_y = new_start_allocation.y + new_start_allocation.height;
1301 cur_x = new_start_allocation.x;
1303 cur_x = new_start_allocation.x + new_start_allocation.width;
1305 toolbar_content_set_start_allocation (content, &new_start_allocation);
1308 /* This resize will run before the first idle handler. This
1309 * will make sure that items get the right goal allocation
1310 * so that the idle handler will not immediately return
1313 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1314 g_timer_reset (priv->timer);
1318 gtk_toolbar_stop_sliding (GtkToolbar *toolbar)
1320 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1322 if (priv->is_sliding)
1326 priv->is_sliding = FALSE;
1330 g_source_remove (priv->idle_id);
1334 list = priv->content;
1337 ToolbarContent *content = list->data;
1340 if (toolbar_content_is_placeholder (content))
1342 toolbar_content_remove (content, toolbar);
1343 toolbar_content_free (content);
1347 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1352 remove_item (GtkWidget *menu_item,
1355 gtk_container_remove (GTK_CONTAINER (menu_item->parent), menu_item);
1359 menu_deactivated (GtkWidget *menu,
1360 GtkToolbar *toolbar)
1362 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1363 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->arrow_button), FALSE);
1367 menu_detached (GtkWidget *toolbar,
1370 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1375 rebuild_menu (GtkToolbar *toolbar)
1377 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1378 GList *list, *children;
1382 priv->menu = GTK_MENU (gtk_menu_new());
1383 gtk_menu_attach_to_widget (priv->menu,
1384 GTK_WIDGET (toolbar),
1387 g_signal_connect (priv->menu, "deactivate",
1388 G_CALLBACK (menu_deactivated), toolbar);
1391 gtk_container_foreach (GTK_CONTAINER (priv->menu), remove_item, NULL);
1393 for (list = priv->content; list != NULL; list = list->next)
1395 ToolbarContent *content = list->data;
1397 if (toolbar_content_get_state (content) == OVERFLOWN &&
1398 !toolbar_content_is_placeholder (content))
1400 GtkWidget *menu_item = toolbar_content_retrieve_menu_item (content);
1404 g_assert (GTK_IS_MENU_ITEM (menu_item));
1405 gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item);
1410 /* Remove leading and trailing separator items */
1411 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1414 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1416 GtkWidget *child = list->data;
1418 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1421 g_list_free (children);
1423 /* Regenerate the list of children so we don't try to remove items twice */
1424 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1426 list = g_list_last (children);
1427 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1429 GtkWidget *child = list->data;
1431 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1434 g_list_free (children);
1436 priv->need_rebuild = FALSE;
1440 gtk_toolbar_size_allocate (GtkWidget *widget,
1441 GtkAllocation *allocation)
1443 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1444 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1445 GtkAllocation *allocations;
1446 ItemState *new_states;
1447 GtkAllocation arrow_allocation;
1449 gint size, pos, short_size;
1452 gboolean need_arrow;
1453 gint n_expand_items;
1455 gint available_size;
1458 GtkRequisition arrow_requisition;
1459 gboolean overflowing;
1460 gboolean size_changed;
1462 GtkAllocation item_area;
1463 GtkShadowType shadow_type;
1465 size_changed = FALSE;
1466 if (widget->allocation.x != allocation->x ||
1467 widget->allocation.y != allocation->y ||
1468 widget->allocation.width != allocation->width ||
1469 widget->allocation.height != allocation->height)
1471 size_changed = TRUE;
1475 gtk_toolbar_stop_sliding (toolbar);
1477 widget->allocation = *allocation;
1479 border_width = GTK_CONTAINER (toolbar)->border_width;
1481 if (GTK_WIDGET_REALIZED (widget))
1483 gdk_window_move_resize (priv->event_window,
1484 allocation->x + border_width,
1485 allocation->y + border_width,
1486 allocation->width - border_width * 2,
1487 allocation->height - border_width * 2);
1490 border_width += get_internal_padding (toolbar);
1492 gtk_widget_get_child_requisition (GTK_WIDGET (priv->arrow_button),
1493 &arrow_requisition);
1495 shadow_type = get_shadow_type (toolbar);
1497 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1499 available_size = size = allocation->width - 2 * border_width;
1500 short_size = allocation->height - 2 * border_width;
1501 arrow_size = arrow_requisition.width;
1503 if (shadow_type != GTK_SHADOW_NONE)
1505 available_size -= 2 * widget->style->xthickness;
1506 short_size -= 2 * widget->style->ythickness;
1511 available_size = size = allocation->height - 2 * border_width;
1512 short_size = allocation->width - 2 * border_width;
1513 arrow_size = arrow_requisition.height;
1515 if (shadow_type != GTK_SHADOW_NONE)
1517 available_size -= 2 * widget->style->ythickness;
1518 short_size -= 2 * widget->style->xthickness;
1522 n_items = g_list_length (priv->content);
1523 allocations = g_new0 (GtkAllocation, n_items);
1524 new_states = g_new0 (ItemState, n_items);
1528 for (list = priv->content; list != NULL; list = list->next)
1530 ToolbarContent *content = list->data;
1532 if (toolbar_content_visible (content, toolbar))
1534 needed_size += get_item_size (toolbar, content);
1536 /* Do we need an arrow?
1538 * Assume we don't, and see if any non-separator item with a
1539 * proxy menu item is then going to overflow.
1541 if (needed_size > available_size &&
1544 priv->api_mode == NEW_API &&
1545 toolbar_content_has_proxy_menu_item (content) &&
1546 !toolbar_content_is_separator (content))
1554 size = available_size - arrow_size;
1556 size = available_size;
1558 /* calculate widths and states of items */
1559 overflowing = FALSE;
1560 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1562 ToolbarContent *content = list->data;
1565 if (!toolbar_content_visible (content, toolbar))
1567 new_states[i] = HIDDEN;
1571 item_size = get_item_size (toolbar, content);
1572 if (item_size <= size && !overflowing)
1575 allocations[i].width = item_size;
1576 new_states[i] = NORMAL;
1581 new_states[i] = OVERFLOWN;
1582 allocations[i].width = item_size;
1586 /* calculate width of arrow */
1589 arrow_allocation.width = arrow_size;
1590 arrow_allocation.height = MAX (short_size, 1);
1593 /* expand expandable items */
1595 /* We don't expand when there is an overflow menu, because that leads to
1596 * weird jumps when items get moved to the overflow menu and the expanding
1597 * items suddenly get a lot of extra space
1601 gint max_child_expand;
1604 for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
1606 ToolbarContent *content = list->data;
1608 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1612 max_child_expand = get_max_child_expand (toolbar);
1613 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1615 ToolbarContent *content = list->data;
1617 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1619 gint extra = size / n_expand_items;
1620 if (size % n_expand_items != 0)
1623 if (extra > max_child_expand)
1624 extra = max_child_expand;
1626 allocations[i].width += extra;
1632 g_assert (n_expand_items == 0);
1635 /* position items */
1637 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1639 /* both NORMAL and OVERFLOWN items get a position. This ensures
1640 * that sliding will work for OVERFLOWN items too
1642 if (new_states[i] == NORMAL ||
1643 new_states[i] == OVERFLOWN)
1645 allocations[i].x = pos;
1646 allocations[i].y = border_width;
1647 allocations[i].height = short_size;
1649 pos += allocations[i].width;
1653 /* position arrow */
1656 arrow_allocation.x = available_size - border_width - arrow_allocation.width;
1657 arrow_allocation.y = border_width;
1660 item_area.x = border_width;
1661 item_area.y = border_width;
1662 item_area.width = available_size - (need_arrow? arrow_size : 0);
1663 item_area.height = short_size;
1665 /* fix up allocations in the vertical or RTL cases */
1666 if (toolbar->orientation == GTK_ORIENTATION_VERTICAL)
1668 for (i = 0; i < n_items; ++i)
1669 fixup_allocation_for_vertical (&(allocations[i]));
1672 fixup_allocation_for_vertical (&arrow_allocation);
1674 fixup_allocation_for_vertical (&item_area);
1676 else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1678 for (i = 0; i < n_items; ++i)
1679 fixup_allocation_for_rtl (available_size, &(allocations[i]));
1682 fixup_allocation_for_rtl (available_size, &arrow_allocation);
1684 fixup_allocation_for_rtl (available_size, &item_area);
1687 /* translate the items by allocation->(x,y) */
1688 for (i = 0; i < n_items; ++i)
1690 allocations[i].x += allocation->x;
1691 allocations[i].y += allocation->y;
1693 if (shadow_type != GTK_SHADOW_NONE)
1695 allocations[i].x += widget->style->xthickness;
1696 allocations[i].y += widget->style->ythickness;
1702 arrow_allocation.x += allocation->x;
1703 arrow_allocation.y += allocation->y;
1705 if (shadow_type != GTK_SHADOW_NONE)
1707 arrow_allocation.x += widget->style->xthickness;
1708 arrow_allocation.y += widget->style->ythickness;
1712 item_area.x += allocation->x;
1713 item_area.y += allocation->y;
1714 if (shadow_type != GTK_SHADOW_NONE)
1716 item_area.x += widget->style->xthickness;
1717 item_area.y += widget->style->ythickness;
1720 /* did anything change? */
1721 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1723 ToolbarContent *content = list->data;
1725 if (toolbar_content_get_state (content) == NORMAL &&
1726 new_states[i] != NORMAL)
1728 /* an item disappeared and we didn't change size, so begin sliding */
1729 if (!size_changed && priv->api_mode == NEW_API)
1730 gtk_toolbar_begin_sliding (toolbar);
1734 /* finally allocate the items */
1735 if (priv->is_sliding)
1737 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1739 ToolbarContent *content = list->data;
1741 toolbar_content_set_goal_allocation (content, &(allocations[i]));
1745 elapsed = g_timer_elapsed (priv->timer, NULL);
1746 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1748 ToolbarContent *content = list->data;
1750 if (new_states[i] == OVERFLOWN ||
1751 new_states[i] == NORMAL)
1753 GtkAllocation alloc;
1754 GtkAllocation start_allocation = { 0, };
1755 GtkAllocation goal_allocation;
1757 if (priv->is_sliding)
1759 toolbar_content_get_start_allocation (content, &start_allocation);
1760 toolbar_content_get_goal_allocation (content, &goal_allocation);
1762 compute_intermediate_allocation (toolbar,
1767 priv->need_sync = TRUE;
1771 alloc = allocations[i];
1774 if (alloc.width <= 0 || alloc.height <= 0)
1776 toolbar_content_set_child_visible (content, toolbar, FALSE);
1780 if (!rect_within (&alloc, &item_area))
1782 toolbar_content_set_child_visible (content, toolbar, FALSE);
1783 toolbar_content_size_allocate (content, &alloc);
1787 toolbar_content_set_child_visible (content, toolbar, TRUE);
1788 toolbar_content_size_allocate (content, &alloc);
1794 toolbar_content_set_child_visible (content, toolbar, FALSE);
1797 toolbar_content_set_state (content, new_states[i]);
1800 if (priv->menu && priv->need_rebuild)
1801 rebuild_menu (toolbar);
1805 gtk_widget_size_allocate (GTK_WIDGET (priv->arrow_button),
1807 gtk_widget_show (GTK_WIDGET (priv->arrow_button));
1811 gtk_widget_hide (GTK_WIDGET (priv->arrow_button));
1813 if (priv->menu && GTK_WIDGET_VISIBLE (priv->menu))
1814 gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
1817 g_free (allocations);
1818 g_free (new_states);
1822 gtk_toolbar_update_button_relief (GtkToolbar *toolbar)
1824 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1825 GtkReliefStyle relief;
1827 relief = get_button_relief (toolbar);
1829 if (relief != gtk_button_get_relief (GTK_BUTTON (priv->arrow_button)))
1831 gtk_toolbar_reconfigured (toolbar);
1833 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), relief);
1838 gtk_toolbar_style_set (GtkWidget *widget,
1839 GtkStyle *prev_style)
1841 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
1843 priv->max_homogeneous_pixels = -1;
1845 if (GTK_WIDGET_REALIZED (widget))
1846 gtk_style_set_background (widget->style, widget->window, widget->state);
1849 gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
1853 gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
1854 GtkDirectionType dir)
1856 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1857 GList *result = NULL;
1861 /* generate list of children in reverse logical order */
1863 for (list = priv->content; list != NULL; list = list->next)
1865 ToolbarContent *content = list->data;
1868 widget = toolbar_content_get_widget (content);
1871 result = g_list_prepend (result, widget);
1874 result = g_list_prepend (result, priv->arrow_button);
1876 rtl = (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL);
1878 /* move in logical order when
1880 * - dir is TAB_FORWARD
1882 * - in RTL mode and moving left or up
1884 * - in LTR mode and moving right or down
1886 if (dir == GTK_DIR_TAB_FORWARD ||
1887 (rtl && (dir == GTK_DIR_UP || dir == GTK_DIR_LEFT)) ||
1888 (!rtl && (dir == GTK_DIR_DOWN || dir == GTK_DIR_RIGHT)))
1890 result = g_list_reverse (result);
1897 gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
1898 gboolean focus_home)
1900 GList *children, *list;
1901 GtkDirectionType dir = focus_home? GTK_DIR_RIGHT : GTK_DIR_LEFT;
1903 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1905 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1907 children = g_list_reverse (children);
1909 dir = (dir == GTK_DIR_RIGHT)? GTK_DIR_LEFT : GTK_DIR_RIGHT;
1912 for (list = children; list != NULL; list = list->next)
1914 GtkWidget *child = list->data;
1916 if (GTK_CONTAINER (toolbar)->focus_child == child)
1919 if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1923 g_list_free (children);
1928 /* Keybinding handler. This function is called when the user presses
1929 * Ctrl TAB or an arrow key.
1932 gtk_toolbar_move_focus (GtkWidget *widget,
1933 GtkDirectionType dir)
1935 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1936 GtkContainer *container = GTK_CONTAINER (toolbar);
1938 gboolean try_focus = FALSE;
1941 if (container->focus_child &&
1942 gtk_widget_child_focus (container->focus_child, dir))
1947 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1949 for (list = children; list != NULL; list = list->next)
1951 GtkWidget *child = list->data;
1953 if (try_focus && GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1956 if (child == GTK_CONTAINER (toolbar)->focus_child)
1960 g_list_free (children);
1963 /* The focus handler for the toolbar. It called when the user presses
1964 * TAB or otherwise tries to focus the toolbar.
1967 gtk_toolbar_focus (GtkWidget *widget,
1968 GtkDirectionType dir)
1970 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1971 GList *children, *list;
1972 gboolean result = FALSE;
1974 /* if focus is already somewhere inside the toolbar then return FALSE.
1975 * The only way focus can stay inside the toolbar is when the user presses
1976 * arrow keys or Ctrl TAB (both of which are handled by the
1977 * gtk_toolbar_move_focus() keybinding function.
1979 if (GTK_CONTAINER (widget)->focus_child)
1982 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1984 for (list = children; list != NULL; list = list->next)
1986 GtkWidget *child = list->data;
1988 if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1995 g_list_free (children);
2000 static GtkSettings *
2001 toolbar_get_settings (GtkToolbar *toolbar)
2003 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2004 return priv->settings;
2008 style_change_notify (GtkToolbar *toolbar)
2010 if (!toolbar->style_set)
2012 /* pretend it was set, then unset, thus reverting to new default */
2013 toolbar->style_set = TRUE;
2014 gtk_toolbar_unset_style (toolbar);
2019 icon_size_change_notify (GtkToolbar *toolbar)
2021 if (!toolbar->icon_size_set)
2023 /* pretend it was set, then unset, thus reverting to new default */
2024 toolbar->icon_size_set = TRUE;
2025 gtk_toolbar_unset_icon_size (toolbar);
2030 animation_change_notify (GtkToolbar *toolbar)
2032 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2033 GtkSettings *settings = toolbar_get_settings (toolbar);
2037 g_object_get (settings,
2038 "gtk-enable-animations", &animation,
2041 animation = DEFAULT_ANIMATION_STATE;
2043 priv->animation = animation;
2047 settings_change_notify (GtkSettings *settings,
2048 const GParamSpec *pspec,
2049 GtkToolbar *toolbar)
2051 if (! strcmp (pspec->name, "gtk-toolbar-style"))
2052 style_change_notify (toolbar);
2053 else if (! strcmp (pspec->name, "gtk-toolbar-icon-size"))
2054 icon_size_change_notify (toolbar);
2055 else if (! strcmp (pspec->name, "gtk-enable-animations"))
2056 animation_change_notify (toolbar);
2060 gtk_toolbar_screen_changed (GtkWidget *widget,
2061 GdkScreen *previous_screen)
2063 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2064 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2065 GtkSettings *old_settings = toolbar_get_settings (toolbar);
2066 GtkSettings *settings;
2068 if (gtk_widget_has_screen (GTK_WIDGET (toolbar)))
2069 settings = gtk_widget_get_settings (GTK_WIDGET (toolbar));
2073 if (settings == old_settings)
2078 g_signal_handler_disconnect (old_settings, priv->settings_connection);
2080 g_object_unref (old_settings);
2085 priv->settings_connection =
2086 g_signal_connect (settings, "notify",
2087 G_CALLBACK (settings_change_notify),
2090 priv->settings = g_object_ref (settings);
2093 priv->settings = NULL;
2095 style_change_notify (toolbar);
2096 icon_size_change_notify (toolbar);
2097 animation_change_notify (toolbar);
2101 find_drop_index (GtkToolbar *toolbar,
2105 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2106 GList *interesting_content;
2108 GtkOrientation orientation;
2109 GtkTextDirection direction;
2110 gint best_distance = G_MAXINT;
2114 ToolbarContent *best_content;
2115 GtkAllocation allocation;
2117 /* list items we care about wrt. drag and drop */
2118 interesting_content = NULL;
2119 for (list = priv->content; list != NULL; list = list->next)
2121 ToolbarContent *content = list->data;
2123 if (toolbar_content_get_state (content) == NORMAL)
2124 interesting_content = g_list_prepend (interesting_content, content);
2126 interesting_content = g_list_reverse (interesting_content);
2128 if (!interesting_content)
2131 orientation = toolbar->orientation;
2132 direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
2134 /* distance to first interesting item */
2135 best_content = interesting_content->data;
2136 toolbar_content_get_allocation (best_content, &allocation);
2138 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2142 if (direction == GTK_TEXT_DIR_LTR)
2145 pos = allocation.x + allocation.width;
2153 best_content = NULL;
2154 best_distance = ABS (pos - cursor);
2156 /* distance to far end of each item */
2157 for (list = interesting_content; list != NULL; list = list->next)
2159 ToolbarContent *content = list->data;
2161 toolbar_content_get_allocation (content, &allocation);
2163 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2165 if (direction == GTK_TEXT_DIR_LTR)
2166 pos = allocation.x + allocation.width;
2172 pos = allocation.y + allocation.height;
2175 distance = ABS (pos - cursor);
2177 if (distance < best_distance)
2179 best_distance = distance;
2180 best_content = content;
2184 g_list_free (interesting_content);
2189 return g_list_index (priv->content, best_content) + 1;
2193 reset_all_placeholders (GtkToolbar *toolbar)
2195 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2198 for (list = priv->content; list != NULL; list = list->next)
2200 ToolbarContent *content = list->data;
2201 if (toolbar_content_is_placeholder (content))
2202 toolbar_content_set_disappearing (content, TRUE);
2207 physical_to_logical (GtkToolbar *toolbar,
2210 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2214 g_assert (physical >= 0);
2217 for (list = priv->content; list && physical > 0; list = list->next)
2219 ToolbarContent *content = list->data;
2221 if (!toolbar_content_is_placeholder (content))
2226 g_assert (physical == 0);
2232 logical_to_physical (GtkToolbar *toolbar,
2235 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2239 g_assert (logical >= 0);
2242 for (list = priv->content; list; list = list->next)
2244 ToolbarContent *content = list->data;
2246 if (!toolbar_content_is_placeholder (content))
2256 g_assert (logical == 0);
2262 * gtk_toolbar_set_drop_highlight_item:
2263 * @toolbar: a #GtkToolbar
2264 * @tool_item: a #GtkToolItem, or %NULL to turn of highlighting
2265 * @index_: a position on @toolbar
2267 * Highlights @toolbar to give an idea of what it would look like
2268 * if @item was added to @toolbar at the position indicated by @index_.
2269 * If @item is %NULL, highlighting is turned off. In that case @index_
2272 * The @tool_item passed to this function must not be part of any widget
2273 * hierarchy. When an item is set as drop highlight item it can not
2274 * added to any widget hierarchy or used as highlight item for another
2280 gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar,
2281 GtkToolItem *tool_item,
2284 ToolbarContent *content;
2285 GtkToolbarPrivate *priv;
2287 GtkRequisition requisition;
2288 GtkRequisition old_requisition;
2289 gboolean restart_sliding;
2291 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2292 g_return_if_fail (tool_item == NULL || GTK_IS_TOOL_ITEM (tool_item));
2294 gtk_toolbar_check_new_api (toolbar);
2296 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2300 if (priv->highlight_tool_item)
2302 gtk_widget_unparent (GTK_WIDGET (priv->highlight_tool_item));
2303 g_object_unref (priv->highlight_tool_item);
2304 priv->highlight_tool_item = NULL;
2307 reset_all_placeholders (toolbar);
2308 gtk_toolbar_begin_sliding (toolbar);
2312 n_items = gtk_toolbar_get_n_items (toolbar);
2313 if (index_ < 0 || index_ > n_items)
2316 if (tool_item != priv->highlight_tool_item)
2318 if (priv->highlight_tool_item)
2319 g_object_unref (priv->highlight_tool_item);
2321 g_object_ref_sink (tool_item);
2323 priv->highlight_tool_item = tool_item;
2325 gtk_widget_set_parent (GTK_WIDGET (priv->highlight_tool_item),
2326 GTK_WIDGET (toolbar));
2329 index_ = logical_to_physical (toolbar, index_);
2331 content = g_list_nth_data (priv->content, index_);
2335 ToolbarContent *prev_content;
2337 prev_content = g_list_nth_data (priv->content, index_ - 1);
2339 if (prev_content && toolbar_content_is_placeholder (prev_content))
2340 content = prev_content;
2343 if (!content || !toolbar_content_is_placeholder (content))
2345 GtkWidget *placeholder;
2347 placeholder = GTK_WIDGET (gtk_separator_tool_item_new ());
2349 content = toolbar_content_new_tool_item (toolbar,
2350 GTK_TOOL_ITEM (placeholder),
2352 gtk_widget_show (placeholder);
2356 g_assert (toolbar_content_is_placeholder (content));
2358 gtk_widget_size_request (GTK_WIDGET (priv->highlight_tool_item),
2361 toolbar_content_set_expand (content, gtk_tool_item_get_expand (tool_item));
2363 restart_sliding = FALSE;
2364 toolbar_content_size_request (content, toolbar, &old_requisition);
2365 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2367 requisition.height = -1;
2368 if (requisition.width != old_requisition.width)
2369 restart_sliding = TRUE;
2373 requisition.width = -1;
2374 if (requisition.height != old_requisition.height)
2375 restart_sliding = TRUE;
2378 if (toolbar_content_disappearing (content))
2379 restart_sliding = TRUE;
2381 reset_all_placeholders (toolbar);
2382 toolbar_content_set_disappearing (content, FALSE);
2384 toolbar_content_set_size_request (content,
2385 requisition.width, requisition.height);
2387 if (restart_sliding)
2388 gtk_toolbar_begin_sliding (toolbar);
2392 gtk_toolbar_get_child_property (GtkContainer *container,
2398 GtkToolItem *item = GTK_TOOL_ITEM (child);
2400 switch (property_id)
2402 case CHILD_PROP_HOMOGENEOUS:
2403 g_value_set_boolean (value, gtk_tool_item_get_homogeneous (item));
2406 case CHILD_PROP_EXPAND:
2407 g_value_set_boolean (value, gtk_tool_item_get_expand (item));
2411 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2417 gtk_toolbar_set_child_property (GtkContainer *container,
2420 const GValue *value,
2423 switch (property_id)
2425 case CHILD_PROP_HOMOGENEOUS:
2426 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2429 case CHILD_PROP_EXPAND:
2430 gtk_tool_item_set_expand (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2434 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2440 gtk_toolbar_show_all (GtkWidget *widget)
2442 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2445 for (list = priv->content; list != NULL; list = list->next)
2447 ToolbarContent *content = list->data;
2449 toolbar_content_show_all (content);
2452 gtk_widget_show (widget);
2456 gtk_toolbar_hide_all (GtkWidget *widget)
2458 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2461 for (list = priv->content; list != NULL; list = list->next)
2463 ToolbarContent *content = list->data;
2465 toolbar_content_hide_all (content);
2468 gtk_widget_hide (widget);
2472 gtk_toolbar_add (GtkContainer *container,
2475 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2477 if (GTK_IS_TOOL_ITEM (widget))
2478 gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
2480 gtk_toolbar_append_widget (toolbar, widget, NULL, NULL);
2484 gtk_toolbar_remove (GtkContainer *container,
2487 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2488 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2489 ToolbarContent *content_to_remove;
2492 content_to_remove = NULL;
2493 for (list = priv->content; list != NULL; list = list->next)
2495 ToolbarContent *content = list->data;
2498 child = toolbar_content_get_widget (content);
2499 if (child && child == widget)
2501 content_to_remove = content;
2506 g_return_if_fail (content_to_remove != NULL);
2508 toolbar_content_remove (content_to_remove, toolbar);
2509 toolbar_content_free (content_to_remove);
2513 gtk_toolbar_forall (GtkContainer *container,
2514 gboolean include_internals,
2515 GtkCallback callback,
2516 gpointer callback_data)
2518 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2519 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2522 g_return_if_fail (callback != NULL);
2524 list = priv->content;
2527 ToolbarContent *content = list->data;
2528 GList *next = list->next;
2530 if (include_internals || !toolbar_content_is_placeholder (content))
2532 GtkWidget *child = toolbar_content_get_widget (content);
2535 callback (child, callback_data);
2541 if (include_internals)
2542 callback (priv->arrow_button, callback_data);
2546 gtk_toolbar_child_type (GtkContainer *container)
2548 return GTK_TYPE_TOOL_ITEM;
2552 gtk_toolbar_reconfigured (GtkToolbar *toolbar)
2554 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2557 list = priv->content;
2560 ToolbarContent *content = list->data;
2561 GList *next = list->next;
2563 toolbar_content_toolbar_reconfigured (content, toolbar);
2570 gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
2571 GtkOrientation orientation)
2573 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2574 if (toolbar->orientation != orientation)
2576 toolbar->orientation = orientation;
2578 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2579 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2581 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2583 gtk_toolbar_reconfigured (toolbar);
2585 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2586 g_object_notify (G_OBJECT (toolbar), "orientation");
2591 gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
2592 GtkToolbarStyle style)
2594 if (toolbar->style != style)
2596 toolbar->style = style;
2598 gtk_toolbar_reconfigured (toolbar);
2600 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2601 g_object_notify (G_OBJECT (toolbar), "toolbar-style");
2606 menu_position_func (GtkMenu *menu,
2612 GtkToolbar *toolbar = GTK_TOOLBAR (user_data);
2613 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2615 GtkRequisition menu_req;
2616 GdkRectangle monitor;
2620 gtk_widget_size_request (priv->arrow_button, &req);
2621 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2623 screen = gtk_widget_get_screen (GTK_WIDGET (menu));
2624 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->arrow_button->window);
2625 if (monitor_num < 0)
2627 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2629 gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
2630 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2632 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2633 *x += priv->arrow_button->allocation.width - req.width;
2635 *x += req.width - menu_req.width;
2637 if ((*y + priv->arrow_button->allocation.height + menu_req.height) <= monitor.y + monitor.height)
2638 *y += priv->arrow_button->allocation.height;
2639 else if ((*y - menu_req.height) >= monitor.y)
2640 *y -= menu_req.height;
2641 else if (monitor.y + monitor.height - (*y + priv->arrow_button->allocation.height) > *y)
2642 *y += priv->arrow_button->allocation.height;
2644 *y -= menu_req.height;
2648 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2649 *x += priv->arrow_button->allocation.width;
2651 *x -= menu_req.width;
2653 if (*y + menu_req.height > monitor.y + monitor.height &&
2654 *y + priv->arrow_button->allocation.height - monitor.y > monitor.y + monitor.height - *y)
2655 *y += priv->arrow_button->allocation.height - menu_req.height;
2662 show_menu (GtkToolbar *toolbar,
2663 GdkEventButton *event)
2665 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2667 rebuild_menu (toolbar);
2669 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2671 gtk_menu_popup (priv->menu, NULL, NULL,
2672 menu_position_func, toolbar,
2673 event? event->button : 0,
2674 event? event->time : gtk_get_current_event_time());
2678 gtk_toolbar_arrow_button_clicked (GtkWidget *button,
2679 GtkToolbar *toolbar)
2681 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2683 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) &&
2684 (!priv->menu || !GTK_WIDGET_VISIBLE (priv->menu)))
2686 /* We only get here when the button is clicked with the keyboard,
2687 * because mouse button presses result in the menu being shown so
2688 * that priv->menu would be non-NULL and visible.
2690 show_menu (toolbar, NULL);
2691 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
2696 gtk_toolbar_arrow_button_press (GtkWidget *button,
2697 GdkEventButton *event,
2698 GtkToolbar *toolbar)
2700 show_menu (toolbar, event);
2701 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
2707 gtk_toolbar_button_press (GtkWidget *toolbar,
2708 GdkEventButton *event)
2710 if (event->button == 3)
2712 gboolean return_value;
2714 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2715 (int)event->x_root, (int)event->y_root, event->button,
2718 return return_value;
2725 gtk_toolbar_popup_menu (GtkWidget *toolbar)
2727 gboolean return_value;
2728 /* This function is the handler for the "popup menu" keybinding,
2729 * ie., it is called when the user presses Shift F10
2731 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2732 -1, -1, -1, &return_value);
2734 return return_value;
2740 * Creates a new toolbar.
2742 * Return Value: the newly-created toolbar.
2745 gtk_toolbar_new (void)
2747 GtkToolbar *toolbar;
2749 toolbar = g_object_new (GTK_TYPE_TOOLBAR, NULL);
2751 return GTK_WIDGET (toolbar);
2755 * gtk_toolbar_insert:
2756 * @toolbar: a #GtkToolbar
2757 * @item: a #GtkToolItem
2758 * @pos: the position of the new item
2760 * Insert a #GtkToolItem into the toolbar at position @pos. If @pos is
2761 * 0 the item is prepended to the start of the toolbar. If @pos is
2762 * negative, the item is appended to the end of the toolbar.
2767 gtk_toolbar_insert (GtkToolbar *toolbar,
2771 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2772 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
2774 if (!gtk_toolbar_check_new_api (toolbar))
2778 pos = logical_to_physical (toolbar, pos);
2780 toolbar_content_new_tool_item (toolbar, item, FALSE, pos);
2784 * gtk_toolbar_get_item_index:
2785 * @toolbar: a #GtkToolbar
2786 * @item: a #GtkToolItem that is a child of @toolbar
2788 * Returns the position of @item on the toolbar, starting from 0.
2789 * It is an error if @item is not a child of the toolbar.
2791 * Return value: the position of item on the toolbar.
2796 gtk_toolbar_get_item_index (GtkToolbar *toolbar,
2799 GtkToolbarPrivate *priv;
2803 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2804 g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
2805 g_return_val_if_fail (GTK_WIDGET (item)->parent == GTK_WIDGET (toolbar), -1);
2807 if (!gtk_toolbar_check_new_api (toolbar))
2810 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2813 for (list = priv->content; list != NULL; list = list->next)
2815 ToolbarContent *content = list->data;
2818 widget = toolbar_content_get_widget (content);
2820 if (item == GTK_TOOL_ITEM (widget))
2826 return physical_to_logical (toolbar, n);
2830 * gtk_toolbar_set_orientation:
2831 * @toolbar: a #GtkToolbar.
2832 * @orientation: a new #GtkOrientation.
2834 * Sets whether a toolbar should appear horizontally or vertically.
2837 gtk_toolbar_set_orientation (GtkToolbar *toolbar,
2838 GtkOrientation orientation)
2840 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2842 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0, orientation);
2846 * gtk_toolbar_get_orientation:
2847 * @toolbar: a #GtkToolbar
2849 * Retrieves the current orientation of the toolbar. See
2850 * gtk_toolbar_set_orientation().
2852 * Return value: the orientation
2855 gtk_toolbar_get_orientation (GtkToolbar *toolbar)
2857 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_ORIENTATION_HORIZONTAL);
2859 return toolbar->orientation;
2863 * gtk_toolbar_set_style:
2864 * @toolbar: a #GtkToolbar.
2865 * @style: the new style for @toolbar.
2867 * Alters the view of @toolbar to display either icons only, text only, or both.
2870 gtk_toolbar_set_style (GtkToolbar *toolbar,
2871 GtkToolbarStyle style)
2873 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2875 toolbar->style_set = TRUE;
2876 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2880 * gtk_toolbar_get_style:
2881 * @toolbar: a #GtkToolbar
2883 * Retrieves whether the toolbar has text, icons, or both . See
2884 * gtk_toolbar_set_style().
2886 * Return value: the current style of @toolbar
2889 gtk_toolbar_get_style (GtkToolbar *toolbar)
2891 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_TOOLBAR_STYLE);
2893 return toolbar->style;
2897 * gtk_toolbar_unset_style:
2898 * @toolbar: a #GtkToolbar
2900 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that
2901 * user preferences will be used to determine the toolbar style.
2904 gtk_toolbar_unset_style (GtkToolbar *toolbar)
2906 GtkToolbarStyle style;
2908 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2910 if (toolbar->style_set)
2912 GtkSettings *settings = toolbar_get_settings (toolbar);
2915 g_object_get (settings,
2916 "gtk-toolbar-style", &style,
2919 style = DEFAULT_TOOLBAR_STYLE;
2921 if (style != toolbar->style)
2922 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2924 toolbar->style_set = FALSE;
2929 * gtk_toolbar_set_tooltips:
2930 * @toolbar: a #GtkToolbar.
2931 * @enable: set to %FALSE to disable the tooltips, or %TRUE to enable them.
2933 * Sets if the tooltips of a toolbar should be active or not.
2935 * Deprecated: 2.14: The toolkit-wide #GtkSettings:gtk-enable-tooltips property
2936 * is now used instead.
2939 gtk_toolbar_set_tooltips (GtkToolbar *toolbar,
2942 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2945 gtk_tooltips_enable (toolbar->tooltips);
2947 gtk_tooltips_disable (toolbar->tooltips);
2949 g_object_notify (G_OBJECT (toolbar), "tooltips");
2953 * gtk_toolbar_get_tooltips:
2954 * @toolbar: a #GtkToolbar
2956 * Retrieves whether tooltips are enabled. See
2957 * gtk_toolbar_set_tooltips().
2959 * Return value: %TRUE if tooltips are enabled
2961 * Deprecated: 2.14: The toolkit-wide #GtkSettings:gtk-enable-tooltips property
2962 * is now used instead.
2965 gtk_toolbar_get_tooltips (GtkToolbar *toolbar)
2967 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
2973 * gtk_toolbar_get_n_items:
2974 * @toolbar: a #GtkToolbar
2976 * Returns the number of items on the toolbar.
2978 * Return value: the number of items on the toolbar
2983 gtk_toolbar_get_n_items (GtkToolbar *toolbar)
2985 GtkToolbarPrivate *priv;
2987 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2989 if (!gtk_toolbar_check_new_api (toolbar))
2992 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2994 return physical_to_logical (toolbar, g_list_length (priv->content));
2998 * gtk_toolbar_get_nth_item:
2999 * @toolbar: a #GtkToolbar
3000 * @n: A position on the toolbar
3002 * Returns the @n<!-- -->'th item on @toolbar, or %NULL if the
3003 * toolbar does not contain an @n<!-- -->'th item.
3005 * Return value: The @n<!-- -->'th #GtkToolItem on @toolbar, or %NULL if there
3006 * isn't an @n<!-- -->'th item.
3011 gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
3014 GtkToolbarPrivate *priv;
3015 ToolbarContent *content;
3018 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
3020 if (!gtk_toolbar_check_new_api (toolbar))
3023 n_items = gtk_toolbar_get_n_items (toolbar);
3025 if (n < 0 || n >= n_items)
3028 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3030 content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
3033 g_assert (!toolbar_content_is_placeholder (content));
3035 return GTK_TOOL_ITEM (toolbar_content_get_widget (content));
3039 * gtk_toolbar_get_icon_size:
3040 * @toolbar: a #GtkToolbar
3042 * Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size().
3044 * Return value: the current icon size for the icons on the toolbar.
3047 gtk_toolbar_get_icon_size (GtkToolbar *toolbar)
3049 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_ICON_SIZE);
3051 return toolbar->icon_size;
3055 * gtk_toolbar_get_relief_style:
3056 * @toolbar: a #GtkToolbar
3058 * Returns the relief style of buttons on @toolbar. See
3059 * gtk_button_set_relief().
3061 * Return value: The relief style of buttons on @toolbar.
3066 gtk_toolbar_get_relief_style (GtkToolbar *toolbar)
3068 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_RELIEF_NONE);
3070 return get_button_relief (toolbar);
3074 * gtk_toolbar_set_show_arrow:
3075 * @toolbar: a #GtkToolbar
3076 * @show_arrow: Whether to show an overflow menu
3078 * Sets whether to show an overflow menu when
3079 * @toolbar doesn't have room for all items on it. If %TRUE,
3080 * items that there are not room are available through an
3086 gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
3087 gboolean show_arrow)
3089 GtkToolbarPrivate *priv;
3091 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3093 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3094 show_arrow = show_arrow != FALSE;
3096 if (priv->show_arrow != show_arrow)
3098 priv->show_arrow = show_arrow;
3100 if (!priv->show_arrow)
3101 gtk_widget_hide (priv->arrow_button);
3103 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3104 g_object_notify (G_OBJECT (toolbar), "show-arrow");
3109 * gtk_toolbar_get_show_arrow:
3110 * @toolbar: a #GtkToolbar
3112 * Returns whether the toolbar has an overflow menu.
3113 * See gtk_toolbar_set_show_arrow().
3115 * Return value: %TRUE if the toolbar has an overflow menu.
3120 gtk_toolbar_get_show_arrow (GtkToolbar *toolbar)
3122 GtkToolbarPrivate *priv;
3124 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
3126 if (!gtk_toolbar_check_new_api (toolbar))
3129 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3131 return priv->show_arrow;
3135 * gtk_toolbar_get_drop_index:
3136 * @toolbar: a #GtkToolbar
3137 * @x: x coordinate of a point on the toolbar
3138 * @y: y coordinate of a point on the toolbar
3140 * Returns the position corresponding to the indicated point on
3141 * @toolbar. This is useful when dragging items to the toolbar:
3142 * this function returns the position a new item should be
3145 * @x and @y are in @toolbar coordinates.
3147 * Return value: The position corresponding to the point (@x, @y) on the toolbar.
3152 gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
3156 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
3158 if (!gtk_toolbar_check_new_api (toolbar))
3161 return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
3165 gtk_toolbar_finalize (GObject *object)
3168 GtkToolbar *toolbar = GTK_TOOLBAR (object);
3169 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3171 if (toolbar->tooltips)
3172 g_object_unref (toolbar->tooltips);
3174 if (priv->arrow_button)
3175 gtk_widget_unparent (priv->arrow_button);
3177 for (list = priv->content; list != NULL; list = list->next)
3179 ToolbarContent *content = list->data;
3181 toolbar_content_free (content);
3184 g_list_free (priv->content);
3185 g_list_free (toolbar->children);
3187 g_timer_destroy (priv->timer);
3190 gtk_widget_destroy (GTK_WIDGET (priv->menu));
3193 g_source_remove (priv->idle_id);
3195 G_OBJECT_CLASS (gtk_toolbar_parent_class)->finalize (object);
3199 * gtk_toolbar_set_icon_size:
3200 * @toolbar: A #GtkToolbar
3201 * @icon_size: The #GtkIconSize that stock icons in the toolbar shall have.
3203 * This function sets the size of stock icons in the toolbar. You
3204 * can call it both before you add the icons and after they've been
3205 * added. The size you set will override user preferences for the default
3208 * This should only be used for special-purpose toolbars, normal
3209 * application toolbars should respect the user preferences for the
3213 gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
3214 GtkIconSize icon_size)
3216 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3217 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
3219 if (!toolbar->icon_size_set)
3221 toolbar->icon_size_set = TRUE;
3222 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3225 if (toolbar->icon_size == icon_size)
3228 toolbar->icon_size = icon_size;
3229 g_object_notify (G_OBJECT (toolbar), "icon-size");
3231 gtk_toolbar_reconfigured (toolbar);
3233 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3237 * gtk_toolbar_unset_icon_size:
3238 * @toolbar: a #GtkToolbar
3240 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that
3241 * user preferences will be used to determine the icon size.
3244 gtk_toolbar_unset_icon_size (GtkToolbar *toolbar)
3248 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3250 if (toolbar->icon_size_set)
3252 GtkSettings *settings = toolbar_get_settings (toolbar);
3256 g_object_get (settings,
3257 "gtk-toolbar-icon-size", &size,
3261 size = DEFAULT_ICON_SIZE;
3263 if (size != toolbar->icon_size)
3265 gtk_toolbar_set_icon_size (toolbar, size);
3266 g_object_notify (G_OBJECT (toolbar), "icon-size");
3269 toolbar->icon_size_set = FALSE;
3270 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3279 * gtk_toolbar_append_item:
3280 * @toolbar: a #GtkToolbar.
3281 * @text: give your toolbar button a label.
3282 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3283 * @tooltip_private_text: use with #GtkTipsQuery.
3284 * @icon: a #GtkWidget that should be used as the button's icon.
3285 * @callback: the function to be executed when the button is pressed.
3286 * @user_data: a pointer to any data you wish to be passed to the callback.
3288 * Inserts a new item into the toolbar. You must specify the position
3289 * in the toolbar where it will be inserted.
3291 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3292 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3294 * Return value: the new toolbar item as a #GtkWidget.
3296 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3299 gtk_toolbar_append_item (GtkToolbar *toolbar,
3301 const char *tooltip_text,
3302 const char *tooltip_private_text,
3307 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3309 tooltip_text, tooltip_private_text,
3310 icon, callback, user_data,
3311 toolbar->num_children);
3315 * gtk_toolbar_prepend_item:
3316 * @toolbar: a #GtkToolbar.
3317 * @text: give your toolbar button a label.
3318 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3319 * @tooltip_private_text: use with #GtkTipsQuery.
3320 * @icon: a #GtkWidget that should be used as the button's icon.
3321 * @callback: the function to be executed when the button is pressed.
3322 * @user_data: a pointer to any data you wish to be passed to the callback.
3324 * Adds a new button to the beginning (top or left edges) of the given toolbar.
3326 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3327 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3329 * Return value: the new toolbar item as a #GtkWidget.
3331 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3334 gtk_toolbar_prepend_item (GtkToolbar *toolbar,
3336 const char *tooltip_text,
3337 const char *tooltip_private_text,
3342 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3344 tooltip_text, tooltip_private_text,
3345 icon, callback, user_data,
3350 * gtk_toolbar_insert_item:
3351 * @toolbar: a #GtkToolbar.
3352 * @text: give your toolbar button a label.
3353 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3354 * @tooltip_private_text: use with #GtkTipsQuery.
3355 * @icon: a #GtkWidget that should be used as the button's icon.
3356 * @callback: the function to be executed when the button is pressed.
3357 * @user_data: a pointer to any data you wish to be passed to the callback.
3358 * @position: the number of widgets to insert this item after.
3360 * Inserts a new item into the toolbar. You must specify the position in the
3361 * toolbar where it will be inserted.
3363 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3364 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3366 * Return value: the new toolbar item as a #GtkWidget.
3368 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3371 gtk_toolbar_insert_item (GtkToolbar *toolbar,
3373 const char *tooltip_text,
3374 const char *tooltip_private_text,
3380 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3382 tooltip_text, tooltip_private_text,
3383 icon, callback, user_data,
3388 * gtk_toolbar_insert_stock:
3389 * @toolbar: A #GtkToolbar
3390 * @stock_id: The id of the stock item you want to insert
3391 * @tooltip_text: The text in the tooltip of the toolbar button
3392 * @tooltip_private_text: The private text of the tooltip
3393 * @callback: The callback called when the toolbar button is clicked.
3394 * @user_data: user data passed to callback
3395 * @position: The position the button shall be inserted at.
3396 * -1 means at the end.
3398 * Inserts a stock item at the specified position of the toolbar. If
3399 * @stock_id is not a known stock item ID, it's inserted verbatim,
3400 * except that underscores used to mark mnemonics are removed.
3402 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3403 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3405 * Returns: the inserted widget
3407 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3410 gtk_toolbar_insert_stock (GtkToolbar *toolbar,
3411 const gchar *stock_id,
3412 const char *tooltip_text,
3413 const char *tooltip_private_text,
3418 return internal_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3420 tooltip_text, tooltip_private_text,
3421 NULL, callback, user_data,
3426 * gtk_toolbar_append_space:
3427 * @toolbar: a #GtkToolbar.
3429 * Adds a new space to the end of the toolbar.
3431 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3434 gtk_toolbar_append_space (GtkToolbar *toolbar)
3436 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3440 toolbar->num_children);
3444 * gtk_toolbar_prepend_space:
3445 * @toolbar: a #GtkToolbar.
3447 * Adds a new space to the beginning of the toolbar.
3449 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3452 gtk_toolbar_prepend_space (GtkToolbar *toolbar)
3454 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3462 * gtk_toolbar_insert_space:
3463 * @toolbar: a #GtkToolbar
3464 * @position: the number of widgets after which a space should be inserted.
3466 * Inserts a new space in the toolbar at the specified position.
3468 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3471 gtk_toolbar_insert_space (GtkToolbar *toolbar,
3474 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3482 * gtk_toolbar_remove_space:
3483 * @toolbar: a #GtkToolbar.
3484 * @position: the index of the space to remove.
3486 * Removes a space from the specified position.
3488 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3491 gtk_toolbar_remove_space (GtkToolbar *toolbar,
3494 GtkToolbarPrivate *priv;
3495 ToolbarContent *content;
3497 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3499 if (!gtk_toolbar_check_old_api (toolbar))
3502 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3504 content = g_list_nth_data (priv->content, position);
3508 g_warning ("Toolbar position %d doesn't exist", position);
3512 if (!toolbar_content_is_separator (content))
3514 g_warning ("Toolbar position %d is not a space", position);
3518 toolbar_content_remove (content, toolbar);
3519 toolbar_content_free (content);
3523 * gtk_toolbar_append_widget:
3524 * @toolbar: a #GtkToolbar.
3525 * @widget: a #GtkWidget to add to the toolbar.
3526 * @tooltip_text: the element's tooltip.
3527 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3529 * Adds a widget to the end of the given toolbar.
3531 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3534 gtk_toolbar_append_widget (GtkToolbar *toolbar,
3536 const gchar *tooltip_text,
3537 const gchar *tooltip_private_text)
3539 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3541 tooltip_text, tooltip_private_text,
3543 toolbar->num_children);
3547 * gtk_toolbar_prepend_widget:
3548 * @toolbar: a #GtkToolbar.
3549 * @widget: a #GtkWidget to add to the toolbar.
3550 * @tooltip_text: the element's tooltip.
3551 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3553 * Adds a widget to the beginning of the given toolbar.
3555 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3558 gtk_toolbar_prepend_widget (GtkToolbar *toolbar,
3560 const gchar *tooltip_text,
3561 const gchar *tooltip_private_text)
3563 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3565 tooltip_text, tooltip_private_text,
3571 * gtk_toolbar_insert_widget:
3572 * @toolbar: a #GtkToolbar.
3573 * @widget: a #GtkWidget to add to the toolbar.
3574 * @tooltip_text: the element's tooltip.
3575 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3576 * @position: the number of widgets to insert this widget after.
3578 * Inserts a widget in the toolbar at the given position.
3580 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3583 gtk_toolbar_insert_widget (GtkToolbar *toolbar,
3585 const char *tooltip_text,
3586 const char *tooltip_private_text,
3589 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3591 tooltip_text, tooltip_private_text,
3597 * gtk_toolbar_append_element:
3598 * @toolbar: a #GtkToolbar.
3599 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3600 * @widget: a #GtkWidget, or %NULL.
3601 * @text: the element's label.
3602 * @tooltip_text: the element's tooltip.
3603 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3604 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3605 * @callback: the function to be executed when the button is pressed.
3606 * @user_data: any data you wish to pass to the callback.
3608 * Adds a new element to the end of a toolbar.
3610 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3611 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3612 * the radio group for the new element. In all other cases, @widget must
3615 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3616 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3618 * Return value: the new toolbar element as a #GtkWidget.
3620 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3623 gtk_toolbar_append_element (GtkToolbar *toolbar,
3624 GtkToolbarChildType type,
3627 const char *tooltip_text,
3628 const char *tooltip_private_text,
3633 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3634 tooltip_text, tooltip_private_text,
3635 icon, callback, user_data,
3636 toolbar->num_children);
3640 * gtk_toolbar_prepend_element:
3641 * @toolbar: a #GtkToolbar.
3642 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3643 * @widget: a #GtkWidget, or %NULL
3644 * @text: the element's label.
3645 * @tooltip_text: the element's tooltip.
3646 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3647 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3648 * @callback: the function to be executed when the button is pressed.
3649 * @user_data: any data you wish to pass to the callback.
3651 * Adds a new element to the beginning of a toolbar.
3653 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3654 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3655 * the radio group for the new element. In all other cases, @widget must
3658 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3659 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3661 * Return value: the new toolbar element as a #GtkWidget.
3663 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3666 gtk_toolbar_prepend_element (GtkToolbar *toolbar,
3667 GtkToolbarChildType type,
3670 const char *tooltip_text,
3671 const char *tooltip_private_text,
3676 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3677 tooltip_text, tooltip_private_text,
3678 icon, callback, user_data, 0);
3682 * gtk_toolbar_insert_element:
3683 * @toolbar: a #GtkToolbar.
3684 * @type: a value of type #GtkToolbarChildType that determines what @widget
3686 * @widget: a #GtkWidget, or %NULL.
3687 * @text: the element's label.
3688 * @tooltip_text: the element's tooltip.
3689 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3690 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3691 * @callback: the function to be executed when the button is pressed.
3692 * @user_data: any data you wish to pass to the callback.
3693 * @position: the number of widgets to insert this element after.
3695 * Inserts a new element in the toolbar at the given position.
3697 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3698 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3699 * the radio group for the new element. In all other cases, @widget must
3702 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3703 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3705 * Return value: the new toolbar element as a #GtkWidget.
3707 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3710 gtk_toolbar_insert_element (GtkToolbar *toolbar,
3711 GtkToolbarChildType type,
3714 const char *tooltip_text,
3715 const char *tooltip_private_text,
3721 return internal_insert_element (toolbar, type, widget, text,
3722 tooltip_text, tooltip_private_text,
3723 icon, callback, user_data, position, FALSE);
3727 set_child_packing_and_visibility(GtkToolbar *toolbar,
3728 GtkToolbarChild *child)
3733 box = gtk_bin_get_child (GTK_BIN (child->widget));
3735 g_return_if_fail (GTK_IS_BOX (box));
3739 expand = (toolbar->style != GTK_TOOLBAR_BOTH);
3741 gtk_box_set_child_packing (GTK_BOX (box), child->label,
3742 expand, expand, 0, GTK_PACK_END);
3744 if (toolbar->style != GTK_TOOLBAR_ICONS)
3745 gtk_widget_show (child->label);
3747 gtk_widget_hide (child->label);
3752 expand = (toolbar->style != GTK_TOOLBAR_BOTH_HORIZ);
3754 gtk_box_set_child_packing (GTK_BOX (box), child->icon,
3755 expand, expand, 0, GTK_PACK_END);
3757 if (toolbar->style != GTK_TOOLBAR_TEXT)
3758 gtk_widget_show (child->icon);
3760 gtk_widget_hide (child->icon);
3765 internal_insert_element (GtkToolbar *toolbar,
3766 GtkToolbarChildType type,
3769 const char *tooltip_text,
3770 const char *tooltip_private_text,
3778 ToolbarContent *content;
3779 char *free_me = NULL;
3781 GtkWidget *child_widget;
3782 GtkWidget *child_label;
3783 GtkWidget *child_icon;
3785 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
3786 if (type == GTK_TOOLBAR_CHILD_WIDGET)
3787 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3788 else if (type != GTK_TOOLBAR_CHILD_RADIOBUTTON)
3789 g_return_val_if_fail (widget == NULL, NULL);
3790 if (GTK_IS_TOOL_ITEM (widget))
3791 g_warning (MIXED_API_WARNING);
3793 if (!gtk_toolbar_check_old_api (toolbar))
3796 child_widget = NULL;
3802 case GTK_TOOLBAR_CHILD_SPACE:
3805 case GTK_TOOLBAR_CHILD_WIDGET:
3806 child_widget = widget;
3809 case GTK_TOOLBAR_CHILD_BUTTON:
3810 case GTK_TOOLBAR_CHILD_TOGGLEBUTTON:
3811 case GTK_TOOLBAR_CHILD_RADIOBUTTON:
3812 if (type == GTK_TOOLBAR_CHILD_BUTTON)
3814 child_widget = gtk_button_new ();
3816 else if (type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
3818 child_widget = gtk_toggle_button_new ();
3819 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3821 else /* type == GTK_TOOLBAR_CHILD_RADIOBUTTON */
3823 GSList *group = NULL;
3826 group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
3828 child_widget = gtk_radio_button_new (group);
3829 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3832 gtk_button_set_relief (GTK_BUTTON (child_widget), get_button_relief (toolbar));
3833 gtk_button_set_focus_on_click (GTK_BUTTON (child_widget), FALSE);
3837 g_signal_connect (child_widget, "clicked",
3838 callback, user_data);
3841 if (toolbar->style == GTK_TOOLBAR_BOTH_HORIZ)
3842 box = gtk_hbox_new (FALSE, 0);
3844 box = gtk_vbox_new (FALSE, 0);
3846 gtk_container_add (GTK_CONTAINER (child_widget), box);
3847 gtk_widget_show (box);
3849 if (text && use_stock)
3851 GtkStockItem stock_item;
3852 if (gtk_stock_lookup (text, &stock_item))
3855 icon = gtk_image_new_from_stock (text, toolbar->icon_size);
3857 text = free_me = _gtk_toolbar_elide_underscores (stock_item.label);
3863 child_label = gtk_label_new (text);
3865 gtk_container_add (GTK_CONTAINER (box), child_label);
3870 child_icon = GTK_WIDGET (icon);
3871 gtk_container_add (GTK_CONTAINER (box), child_icon);
3874 gtk_widget_show (child_widget);
3878 g_assert_not_reached ();
3882 if ((type != GTK_TOOLBAR_CHILD_SPACE) && tooltip_text)
3884 gtk_tooltips_set_tip (toolbar->tooltips, child_widget,
3885 tooltip_text, tooltip_private_text);
3888 content = toolbar_content_new_compatibility (toolbar, type, child_widget,
3889 child_icon, child_label, position);
3893 return child_widget;
3897 * ToolbarContent methods
3905 struct _ToolbarContent
3915 GtkAllocation start_allocation;
3916 GtkAllocation goal_allocation;
3917 guint is_placeholder : 1;
3918 guint disappearing : 1;
3924 GtkToolbarChild child;
3925 GtkAllocation space_allocation;
3926 guint space_visible : 1;
3931 static ToolbarContent *
3932 toolbar_content_new_tool_item (GtkToolbar *toolbar,
3934 gboolean is_placeholder,
3937 ToolbarContent *content;
3938 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3940 content = g_slice_new0 (ToolbarContent);
3942 content->type = TOOL_ITEM;
3943 content->state = NOT_ALLOCATED;
3944 content->u.tool_item.item = item;
3945 content->u.tool_item.is_placeholder = is_placeholder;
3947 gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
3949 priv->content = g_list_insert (priv->content, content, pos);
3951 if (!is_placeholder)
3953 toolbar->num_children++;
3955 gtk_toolbar_stop_sliding (toolbar);
3958 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3959 priv->need_rebuild = TRUE;
3964 static ToolbarContent *
3965 toolbar_content_new_compatibility (GtkToolbar *toolbar,
3966 GtkToolbarChildType type,
3972 ToolbarContent *content;
3973 GtkToolbarChild *child;
3974 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3976 content = g_slice_new0 (ToolbarContent);
3978 child = &(content->u.compatibility.child);
3980 content->type = COMPATIBILITY;
3982 child->widget = widget;
3984 child->label = label;
3986 if (type != GTK_TOOLBAR_CHILD_SPACE)
3988 gtk_widget_set_parent (child->widget, GTK_WIDGET (toolbar));
3992 content->u.compatibility.space_visible = TRUE;
3993 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3996 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
3997 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
3998 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
4000 set_child_packing_and_visibility (toolbar, child);
4003 priv->content = g_list_insert (priv->content, content, pos);
4004 toolbar->children = g_list_insert (toolbar->children, child, pos);
4005 priv->need_rebuild = TRUE;
4007 toolbar->num_children++;
4013 toolbar_content_remove (ToolbarContent *content,
4014 GtkToolbar *toolbar)
4016 GtkToolbarChild *child;
4017 GtkToolbarPrivate *priv;
4019 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4021 switch (content->type)
4024 gtk_widget_unparent (GTK_WIDGET (content->u.tool_item.item));
4028 child = &(content->u.compatibility.child);
4030 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4032 g_object_ref (child->widget);
4033 gtk_widget_unparent (child->widget);
4034 gtk_widget_destroy (child->widget);
4035 g_object_unref (child->widget);
4038 toolbar->children = g_list_remove (toolbar->children, child);
4042 priv->content = g_list_remove (priv->content, content);
4044 if (!toolbar_content_is_placeholder (content))
4045 toolbar->num_children--;
4047 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
4048 priv->need_rebuild = TRUE;
4052 toolbar_content_free (ToolbarContent *content)
4054 g_slice_free (ToolbarContent, content);
4058 calculate_max_homogeneous_pixels (GtkWidget *widget)
4060 PangoContext *context;
4061 PangoFontMetrics *metrics;
4064 context = gtk_widget_get_pango_context (widget);
4065 metrics = pango_context_get_metrics (context,
4066 widget->style->font_desc,
4067 pango_context_get_language (context));
4068 char_width = pango_font_metrics_get_approximate_char_width (metrics);
4069 pango_font_metrics_unref (metrics);
4071 return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
4075 toolbar_content_expose (ToolbarContent *content,
4076 GtkContainer *container,
4077 GdkEventExpose *expose)
4079 GtkToolbar *toolbar = GTK_TOOLBAR (container);
4080 GtkToolbarChild *child;
4081 GtkWidget *widget = NULL; /* quiet gcc */
4083 switch (content->type)
4086 if (!content->u.tool_item.is_placeholder)
4087 widget = GTK_WIDGET (content->u.tool_item.item);
4091 child = &(content->u.compatibility.child);
4093 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
4095 if (content->u.compatibility.space_visible &&
4096 get_space_style (toolbar) == GTK_TOOLBAR_SPACE_LINE)
4097 _gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), toolbar,
4099 &content->u.compatibility.space_allocation);
4103 widget = child->widget;
4108 gtk_container_propagate_expose (container, widget, expose);
4112 toolbar_content_visible (ToolbarContent *content,
4113 GtkToolbar *toolbar)
4117 switch (content->type)
4120 item = content->u.tool_item.item;
4122 if (!GTK_WIDGET_VISIBLE (item))
4125 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL &&
4126 gtk_tool_item_get_visible_horizontal (item))
4129 if ((toolbar->orientation == GTK_ORIENTATION_VERTICAL &&
4130 gtk_tool_item_get_visible_vertical (item)))
4137 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4138 return GTK_WIDGET_VISIBLE (content->u.compatibility.child.widget);
4144 g_assert_not_reached ();
4149 toolbar_content_size_request (ToolbarContent *content,
4150 GtkToolbar *toolbar,
4151 GtkRequisition *requisition)
4155 switch (content->type)
4158 gtk_widget_size_request (GTK_WIDGET (content->u.tool_item.item),
4160 if (content->u.tool_item.is_placeholder &&
4161 content->u.tool_item.disappearing)
4163 requisition->width = 0;
4164 requisition->height = 0;
4169 space_size = get_space_size (toolbar);
4171 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4173 gtk_widget_size_request (content->u.compatibility.child.widget,
4178 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
4180 requisition->width = space_size;
4181 requisition->height = 0;
4185 requisition->height = space_size;
4186 requisition->width = 0;
4195 toolbar_content_is_homogeneous (ToolbarContent *content,
4196 GtkToolbar *toolbar)
4198 gboolean result = FALSE; /* quiet gcc */
4199 GtkRequisition requisition;
4200 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4202 if (priv->max_homogeneous_pixels < 0)
4204 priv->max_homogeneous_pixels =
4205 calculate_max_homogeneous_pixels (GTK_WIDGET (toolbar));
4208 toolbar_content_size_request (content, toolbar, &requisition);
4210 if (requisition.width > priv->max_homogeneous_pixels)
4213 switch (content->type)
4216 result = gtk_tool_item_get_homogeneous (content->u.tool_item.item) &&
4217 !GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4219 if (gtk_tool_item_get_is_important (content->u.tool_item.item) &&
4220 toolbar->style == GTK_TOOLBAR_BOTH_HORIZ &&
4221 toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
4228 if (content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_BUTTON ||
4229 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4230 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4245 toolbar_content_is_placeholder (ToolbarContent *content)
4247 if (content->type == TOOL_ITEM && content->u.tool_item.is_placeholder)
4254 toolbar_content_disappearing (ToolbarContent *content)
4256 if (content->type == TOOL_ITEM && content->u.tool_item.disappearing)
4263 toolbar_content_get_state (ToolbarContent *content)
4265 return content->state;
4269 toolbar_content_child_visible (ToolbarContent *content)
4271 switch (content->type)
4274 return GTK_WIDGET_CHILD_VISIBLE (content->u.tool_item.item);
4278 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4280 return GTK_WIDGET_CHILD_VISIBLE (content->u.compatibility.child.widget);
4284 return content->u.compatibility.space_visible;
4289 return FALSE; /* quiet gcc */
4293 toolbar_content_get_goal_allocation (ToolbarContent *content,
4294 GtkAllocation *allocation)
4296 switch (content->type)
4299 *allocation = content->u.tool_item.goal_allocation;
4303 /* Goal allocations are only relevant when we are
4304 * using the new API, so we should never get here
4306 g_assert_not_reached ();
4312 toolbar_content_get_allocation (ToolbarContent *content,
4313 GtkAllocation *allocation)
4315 GtkToolbarChild *child;
4317 switch (content->type)
4320 *allocation = GTK_WIDGET (content->u.tool_item.item)->allocation;
4324 child = &(content->u.compatibility.child);
4326 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
4327 *allocation = content->u.compatibility.space_allocation;
4329 *allocation = child->widget->allocation;
4335 toolbar_content_set_start_allocation (ToolbarContent *content,
4336 GtkAllocation *allocation)
4338 switch (content->type)
4341 content->u.tool_item.start_allocation = *allocation;
4345 /* start_allocation is only relevant when using the new API */
4346 g_assert_not_reached ();
4352 toolbar_content_get_expand (ToolbarContent *content)
4354 if (content->type == TOOL_ITEM &&
4355 gtk_tool_item_get_expand (content->u.tool_item.item) &&
4356 !content->u.tool_item.disappearing)
4365 toolbar_content_set_goal_allocation (ToolbarContent *content,
4366 GtkAllocation *allocation)
4368 switch (content->type)
4371 content->u.tool_item.goal_allocation = *allocation;
4375 /* Only relevant when using new API */
4376 g_assert_not_reached ();
4382 toolbar_content_set_child_visible (ToolbarContent *content,
4383 GtkToolbar *toolbar,
4386 GtkToolbarChild *child;
4388 switch (content->type)
4391 gtk_widget_set_child_visible (GTK_WIDGET (content->u.tool_item.item),
4396 child = &(content->u.compatibility.child);
4398 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4400 gtk_widget_set_child_visible (child->widget, visible);
4404 if (content->u.compatibility.space_visible != visible)
4406 content->u.compatibility.space_visible = visible;
4407 gtk_widget_queue_draw (GTK_WIDGET (toolbar));
4415 toolbar_content_get_start_allocation (ToolbarContent *content,
4416 GtkAllocation *start_allocation)
4418 switch (content->type)
4421 *start_allocation = content->u.tool_item.start_allocation;
4425 /* Only relevant for new API */
4426 g_assert_not_reached ();
4432 toolbar_content_size_allocate (ToolbarContent *content,
4433 GtkAllocation *allocation)
4435 switch (content->type)
4438 gtk_widget_size_allocate (GTK_WIDGET (content->u.tool_item.item),
4443 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4445 gtk_widget_size_allocate (content->u.compatibility.child.widget,
4450 content->u.compatibility.space_allocation = *allocation;
4457 toolbar_content_set_state (ToolbarContent *content,
4460 content->state = state;
4464 toolbar_content_get_widget (ToolbarContent *content)
4466 GtkToolbarChild *child;
4468 switch (content->type)
4471 return GTK_WIDGET (content->u.tool_item.item);
4475 child = &(content->u.compatibility.child);
4476 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4477 return child->widget;
4487 toolbar_content_set_disappearing (ToolbarContent *content,
4488 gboolean disappearing)
4490 switch (content->type)
4493 content->u.tool_item.disappearing = disappearing;
4497 /* Only relevant for new API */
4498 g_assert_not_reached ();
4504 toolbar_content_set_size_request (ToolbarContent *content,
4508 switch (content->type)
4511 gtk_widget_set_size_request (GTK_WIDGET (content->u.tool_item.item),
4516 /* Setting size requests only happens with sliding,
4517 * so not relevant here
4519 g_assert_not_reached ();
4525 toolbar_child_reconfigure (GtkToolbar *toolbar,
4526 GtkToolbarChild *child)
4530 GtkToolbarStyle style;
4531 GtkIconSize icon_size;
4532 GtkReliefStyle relief;
4535 style = gtk_toolbar_get_style (toolbar);
4536 icon_size = gtk_toolbar_get_icon_size (toolbar);
4537 relief = gtk_toolbar_get_relief_style (toolbar);
4540 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4541 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4542 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4544 box = gtk_bin_get_child (GTK_BIN (child->widget));
4546 if (style == GTK_TOOLBAR_BOTH && GTK_IS_HBOX (box))
4550 vbox = gtk_vbox_new (FALSE, 0);
4553 gtk_widget_reparent (child->label, vbox);
4555 gtk_widget_reparent (child->icon, vbox);
4557 gtk_widget_destroy (box);
4558 gtk_container_add (GTK_CONTAINER (child->widget), vbox);
4560 gtk_widget_show (vbox);
4562 else if (style == GTK_TOOLBAR_BOTH_HORIZ && GTK_IS_VBOX (box))
4566 hbox = gtk_hbox_new (FALSE, 0);
4569 gtk_widget_reparent (child->label, hbox);
4571 gtk_widget_reparent (child->icon, hbox);
4573 gtk_widget_destroy (box);
4574 gtk_container_add (GTK_CONTAINER (child->widget), hbox);
4576 gtk_widget_show (hbox);
4579 set_child_packing_and_visibility (toolbar, child);
4584 if ((child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4585 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4586 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON) &&
4587 GTK_IS_IMAGE (child->icon))
4589 image = GTK_IMAGE (child->icon);
4590 if (gtk_image_get_storage_type (image) == GTK_IMAGE_STOCK)
4592 gtk_image_get_stock (image, &stock_id, NULL);
4593 stock_id = g_strdup (stock_id);
4594 gtk_image_set_from_stock (image,
4602 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4603 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4604 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4606 gtk_button_set_relief (GTK_BUTTON (child->widget), relief);
4611 toolbar_content_toolbar_reconfigured (ToolbarContent *content,
4612 GtkToolbar *toolbar)
4614 switch (content->type)
4617 gtk_tool_item_toolbar_reconfigured (content->u.tool_item.item);
4621 toolbar_child_reconfigure (toolbar, &(content->u.compatibility.child));
4627 toolbar_content_retrieve_menu_item (ToolbarContent *content)
4629 if (content->type == TOOL_ITEM)
4630 return gtk_tool_item_retrieve_proxy_menu_item (content->u.tool_item.item);
4632 /* FIXME - we might actually be able to do something meaningful here */
4637 toolbar_content_has_proxy_menu_item (ToolbarContent *content)
4639 if (content->type == TOOL_ITEM)
4641 GtkWidget *menu_item;
4643 if (content->u.tool_item.has_menu == YES)
4645 else if (content->u.tool_item.has_menu == NO)
4648 menu_item = toolbar_content_retrieve_menu_item (content);
4650 content->u.tool_item.has_menu = menu_item? YES : NO;
4652 return menu_item != NULL;
4661 toolbar_content_set_unknown_menu_status (ToolbarContent *content)
4663 if (content->type == TOOL_ITEM)
4664 content->u.tool_item.has_menu = UNKNOWN;
4668 toolbar_content_is_separator (ToolbarContent *content)
4670 GtkToolbarChild *child;
4672 switch (content->type)
4675 return GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4679 child = &(content->u.compatibility.child);
4680 return (child->type == GTK_TOOLBAR_CHILD_SPACE);
4688 toolbar_content_set_expand (ToolbarContent *content,
4691 if (content->type == TOOL_ITEM)
4692 gtk_tool_item_set_expand (content->u.tool_item.item, expand);
4696 ignore_show_and_hide_all (ToolbarContent *content)
4698 if (content->type == COMPATIBILITY)
4700 GtkToolbarChildType type = content->u.compatibility.child.type;
4702 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
4703 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4704 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
4714 toolbar_content_show_all (ToolbarContent *content)
4718 if (ignore_show_and_hide_all (content))
4721 widget = toolbar_content_get_widget (content);
4723 gtk_widget_show_all (widget);
4727 toolbar_content_hide_all (ToolbarContent *content)
4731 if (ignore_show_and_hide_all (content))
4734 widget = toolbar_content_get_widget (content);
4736 gtk_widget_hide_all (widget);
4743 get_space_size (GtkToolbar *toolbar)
4745 gint space_size = DEFAULT_SPACE_SIZE;
4749 gtk_widget_style_get (GTK_WIDGET (toolbar),
4750 "space-size", &space_size,
4757 static GtkToolbarSpaceStyle
4758 get_space_style (GtkToolbar *toolbar)
4760 GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
4764 gtk_widget_style_get (GTK_WIDGET (toolbar),
4765 "space-style", &space_style,
4772 static GtkReliefStyle
4773 get_button_relief (GtkToolbar *toolbar)
4775 GtkReliefStyle button_relief = GTK_RELIEF_NORMAL;
4777 gtk_widget_ensure_style (GTK_WIDGET (toolbar));
4779 gtk_widget_style_get (GTK_WIDGET (toolbar),
4780 "button-relief", &button_relief,
4783 return button_relief;
4787 get_internal_padding (GtkToolbar *toolbar)
4791 gtk_widget_style_get (GTK_WIDGET (toolbar),
4792 "internal-padding", &ipadding,
4799 get_max_child_expand (GtkToolbar *toolbar)
4801 gint mexpand = G_MAXINT;
4803 gtk_widget_style_get (GTK_WIDGET (toolbar),
4804 "max-child-expand", &mexpand,
4809 static GtkShadowType
4810 get_shadow_type (GtkToolbar *toolbar)
4812 GtkShadowType shadow_type;
4814 gtk_widget_style_get (GTK_WIDGET (toolbar),
4815 "shadow-type", &shadow_type,
4825 gtk_toolbar_check_old_api (GtkToolbar *toolbar)
4827 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4829 if (priv->api_mode == NEW_API)
4831 g_warning (MIXED_API_WARNING);
4835 priv->api_mode = OLD_API;
4840 gtk_toolbar_check_new_api (GtkToolbar *toolbar)
4842 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4844 if (priv->api_mode == OLD_API)
4846 g_warning (MIXED_API_WARNING);
4850 priv->api_mode = NEW_API;
4854 /* GTK+ internal methods */
4857 _gtk_toolbar_get_default_space_size (void)
4859 return DEFAULT_SPACE_SIZE;
4863 _gtk_toolbar_paint_space_line (GtkWidget *widget,
4864 GtkToolbar *toolbar,
4865 const GdkRectangle *area,
4866 const GtkAllocation *allocation)
4868 const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
4869 const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
4871 GtkOrientation orientation;
4873 g_return_if_fail (GTK_IS_WIDGET (widget));
4875 orientation = toolbar? toolbar->orientation : GTK_ORIENTATION_HORIZONTAL;
4877 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4879 gboolean wide_separators;
4880 gint separator_width;
4882 gtk_widget_style_get (widget,
4883 "wide-separators", &wide_separators,
4884 "separator-width", &separator_width,
4887 if (wide_separators)
4888 gtk_paint_box (widget->style, widget->window,
4889 GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
4890 area, widget, "vseparator",
4891 allocation->x + (allocation->width - separator_width) / 2,
4892 allocation->y + allocation->height * start_fraction,
4894 allocation->height * (end_fraction - start_fraction));
4896 gtk_paint_vline (widget->style, widget->window,
4897 GTK_WIDGET_STATE (widget), area, widget,
4899 allocation->y + allocation->height * start_fraction,
4900 allocation->y + allocation->height * end_fraction,
4901 allocation->x + (allocation->width - widget->style->xthickness) / 2);
4905 gboolean wide_separators;
4906 gint separator_height;
4908 gtk_widget_style_get (widget,
4909 "wide-separators", &wide_separators,
4910 "separator-height", &separator_height,
4913 if (wide_separators)
4914 gtk_paint_box (widget->style, widget->window,
4915 GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
4916 area, widget, "hseparator",
4917 allocation->x + allocation->width * start_fraction,
4918 allocation->y + (allocation->height - separator_height) / 2,
4919 allocation->width * (end_fraction - start_fraction),
4922 gtk_paint_hline (widget->style, widget->window,
4923 GTK_WIDGET_STATE (widget), area, widget,
4925 allocation->x + allocation->width * start_fraction,
4926 allocation->x + allocation->width * end_fraction,
4927 allocation->y + (allocation->height - widget->style->ythickness) / 2);
4932 _gtk_toolbar_elide_underscores (const gchar *original)
4935 const gchar *p, *end;
4937 gboolean last_underscore;
4942 len = strlen (original);
4943 q = result = g_malloc (len + 1);
4944 last_underscore = FALSE;
4946 end = original + len;
4947 for (p = original; p < end; p++)
4949 if (!last_underscore && *p == '_')
4950 last_underscore = TRUE;
4953 last_underscore = FALSE;
4954 if (original + 2 <= p && p + 1 <= end &&
4955 p[-2] == '(' && p[-1] == '_' && p[0] != '_' && p[1] == ')')
4966 if (last_underscore)
4975 toolbar_get_icon_size (GtkToolShell *shell)
4977 return GTK_TOOLBAR (shell)->icon_size;
4980 static GtkOrientation
4981 toolbar_get_orientation (GtkToolShell *shell)
4983 return GTK_TOOLBAR (shell)->orientation;
4986 static GtkToolbarStyle
4987 toolbar_get_style (GtkToolShell *shell)
4989 return GTK_TOOLBAR (shell)->style;
4992 static GtkReliefStyle
4993 toolbar_get_relief_style (GtkToolShell *shell)
4995 return get_button_relief (GTK_TOOLBAR (shell));
4999 toolbar_rebuild_menu (GtkToolShell *shell)
5001 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (shell);
5004 priv->need_rebuild = TRUE;
5006 for (list = priv->content; list != NULL; list = list->next)
5008 ToolbarContent *content = list->data;
5010 toolbar_content_set_unknown_menu_status (content);
5013 gtk_widget_queue_resize (GTK_WIDGET (shell));
5016 #define __GTK_TOOLBAR_C__
5017 #include "gtkaliasdef.c"