1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 * GtkToolbar copyright (C) Federico Mena
5 * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
6 * Copyright (C) 2002 James Henstridge <james@daa.com.au>
7 * Copyright (C) 2003, 2004 Soeren Sandmann <sandmann@daimi.au.dk>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
26 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
27 * file for a list of people on the GTK+ Team. See the ChangeLog
28 * files for a list of changes. These files are distributed with
29 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
32 #undef GTK_DISABLE_DEPRECATED
39 #include <gdk/gdkkeysyms.h>
42 #include "gtkbindings.h"
47 #include "gtkmarshalers.h"
49 #include "gtkorientable.h"
50 #include "gtkradiobutton.h"
51 #include "gtkradiotoolbutton.h"
52 #include "gtkseparatormenuitem.h"
53 #include "gtkseparatortoolitem.h"
55 #include "gtktoolbar.h"
56 #include "gtktoolshell.h"
58 #include "gtkprivate.h"
62 typedef struct _ToolbarContent ToolbarContent;
64 #define DEFAULT_IPADDING 0
66 #define DEFAULT_SPACE_SIZE 12
67 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
68 #define SPACE_LINE_DIVISION 10.0
69 #define SPACE_LINE_START 2.0
70 #define SPACE_LINE_END 8.0
72 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
73 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
74 #define DEFAULT_ANIMATION_STATE TRUE
76 #define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
77 * in the homogeneous game. In units of
78 * pango_font_get_estimated_char_width().
80 #define SLIDE_SPEED 600.0 /* How fast the items slide, in pixels per second */
81 #define ACCEL_THRESHOLD 0.18 /* After how much time in seconds will items start speeding up */
83 #define MIXED_API_WARNING \
84 "Mixing deprecated and non-deprecated GtkToolbar API is not allowed"
98 /* Child properties */
102 CHILD_PROP_HOMOGENEOUS
133 struct _GtkToolbarPrivate
138 GtkWidget * arrow_button;
141 GdkWindow * event_window;
143 GtkSettings * settings;
145 GtkToolItem * highlight_tool_item;
146 gint max_homogeneous_pixels;
150 gulong settings_connection;
152 guint show_arrow : 1;
154 guint is_sliding : 1;
155 guint need_rebuild : 1; /* whether the overflow menu should be regenerated */
159 static void gtk_toolbar_set_property (GObject *object,
163 static void gtk_toolbar_get_property (GObject *object,
167 static gint gtk_toolbar_expose (GtkWidget *widget,
168 GdkEventExpose *event);
169 static void gtk_toolbar_realize (GtkWidget *widget);
170 static void gtk_toolbar_unrealize (GtkWidget *widget);
171 static void gtk_toolbar_size_request (GtkWidget *widget,
172 GtkRequisition *requisition);
173 static void gtk_toolbar_size_allocate (GtkWidget *widget,
174 GtkAllocation *allocation);
175 static void gtk_toolbar_style_set (GtkWidget *widget,
176 GtkStyle *prev_style);
177 static gboolean gtk_toolbar_focus (GtkWidget *widget,
178 GtkDirectionType dir);
179 static void gtk_toolbar_move_focus (GtkWidget *widget,
180 GtkDirectionType dir);
181 static void gtk_toolbar_screen_changed (GtkWidget *widget,
182 GdkScreen *previous_screen);
183 static void gtk_toolbar_map (GtkWidget *widget);
184 static void gtk_toolbar_unmap (GtkWidget *widget);
185 static void gtk_toolbar_set_child_property (GtkContainer *container,
190 static void gtk_toolbar_get_child_property (GtkContainer *container,
195 static void gtk_toolbar_finalize (GObject *object);
196 static void gtk_toolbar_show_all (GtkWidget *widget);
197 static void gtk_toolbar_hide_all (GtkWidget *widget);
198 static void gtk_toolbar_add (GtkContainer *container,
200 static void gtk_toolbar_remove (GtkContainer *container,
202 static void gtk_toolbar_forall (GtkContainer *container,
203 gboolean include_internals,
204 GtkCallback callback,
205 gpointer callback_data);
206 static GType gtk_toolbar_child_type (GtkContainer *container);
207 static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
208 GtkOrientation orientation);
209 static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
210 GtkToolbarStyle style);
211 static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
212 gboolean focus_home);
213 static gboolean gtk_toolbar_button_press (GtkWidget *toolbar,
214 GdkEventButton *event);
215 static gboolean gtk_toolbar_arrow_button_press (GtkWidget *button,
216 GdkEventButton *event,
217 GtkToolbar *toolbar);
218 static void gtk_toolbar_arrow_button_clicked (GtkWidget *button,
219 GtkToolbar *toolbar);
220 static void gtk_toolbar_update_button_relief (GtkToolbar *toolbar);
221 static gboolean gtk_toolbar_popup_menu (GtkWidget *toolbar);
222 static GtkWidget *internal_insert_element (GtkToolbar *toolbar,
223 GtkToolbarChildType type,
226 const char *tooltip_text,
227 const char *tooltip_private_text,
233 static void gtk_toolbar_reconfigured (GtkToolbar *toolbar);
234 static gboolean gtk_toolbar_check_new_api (GtkToolbar *toolbar);
235 static gboolean gtk_toolbar_check_old_api (GtkToolbar *toolbar);
237 static GtkReliefStyle get_button_relief (GtkToolbar *toolbar);
238 static gint get_internal_padding (GtkToolbar *toolbar);
239 static gint get_max_child_expand (GtkToolbar *toolbar);
240 static GtkShadowType get_shadow_type (GtkToolbar *toolbar);
241 static gint get_space_size (GtkToolbar *toolbar);
242 static GtkToolbarSpaceStyle get_space_style (GtkToolbar *toolbar);
244 /* methods on ToolbarContent 'class' */
245 static ToolbarContent *toolbar_content_new_tool_item (GtkToolbar *toolbar,
247 gboolean is_placeholder,
249 static ToolbarContent *toolbar_content_new_compatibility (GtkToolbar *toolbar,
250 GtkToolbarChildType type,
255 static void toolbar_content_remove (ToolbarContent *content,
256 GtkToolbar *toolbar);
257 static void toolbar_content_free (ToolbarContent *content);
258 static void toolbar_content_expose (ToolbarContent *content,
259 GtkContainer *container,
260 GdkEventExpose *expose);
261 static gboolean toolbar_content_visible (ToolbarContent *content,
262 GtkToolbar *toolbar);
263 static void toolbar_content_size_request (ToolbarContent *content,
265 GtkRequisition *requisition);
266 static gboolean toolbar_content_is_homogeneous (ToolbarContent *content,
267 GtkToolbar *toolbar);
268 static gboolean toolbar_content_is_placeholder (ToolbarContent *content);
269 static gboolean toolbar_content_disappearing (ToolbarContent *content);
270 static ItemState toolbar_content_get_state (ToolbarContent *content);
271 static gboolean toolbar_content_child_visible (ToolbarContent *content);
272 static void toolbar_content_get_goal_allocation (ToolbarContent *content,
273 GtkAllocation *allocation);
274 static void toolbar_content_get_allocation (ToolbarContent *content,
275 GtkAllocation *allocation);
276 static void toolbar_content_set_start_allocation (ToolbarContent *content,
277 GtkAllocation *new_start_allocation);
278 static void toolbar_content_get_start_allocation (ToolbarContent *content,
279 GtkAllocation *start_allocation);
280 static gboolean toolbar_content_get_expand (ToolbarContent *content);
281 static void toolbar_content_set_goal_allocation (ToolbarContent *content,
282 GtkAllocation *allocation);
283 static void toolbar_content_set_child_visible (ToolbarContent *content,
286 static void toolbar_content_size_allocate (ToolbarContent *content,
287 GtkAllocation *allocation);
288 static void toolbar_content_set_state (ToolbarContent *content,
289 ItemState new_state);
290 static GtkWidget * toolbar_content_get_widget (ToolbarContent *content);
291 static void toolbar_content_set_disappearing (ToolbarContent *content,
292 gboolean disappearing);
293 static void toolbar_content_set_size_request (ToolbarContent *content,
296 static void toolbar_content_toolbar_reconfigured (ToolbarContent *content,
297 GtkToolbar *toolbar);
298 static GtkWidget * toolbar_content_retrieve_menu_item (ToolbarContent *content);
299 static gboolean toolbar_content_has_proxy_menu_item (ToolbarContent *content);
300 static gboolean toolbar_content_is_separator (ToolbarContent *content);
301 static void toolbar_content_show_all (ToolbarContent *content);
302 static void toolbar_content_hide_all (ToolbarContent *content);
303 static void toolbar_content_set_expand (ToolbarContent *content,
306 static void toolbar_tool_shell_iface_init (GtkToolShellIface *iface);
307 static GtkIconSize toolbar_get_icon_size (GtkToolShell *shell);
308 static GtkOrientation toolbar_get_orientation (GtkToolShell *shell);
309 static GtkToolbarStyle toolbar_get_style (GtkToolShell *shell);
310 static GtkReliefStyle toolbar_get_relief_style (GtkToolShell *shell);
311 static void toolbar_rebuild_menu (GtkToolShell *shell);
313 #define GTK_TOOLBAR_GET_PRIVATE(o) \
314 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOLBAR, GtkToolbarPrivate))
317 G_DEFINE_TYPE_WITH_CODE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER,
318 G_IMPLEMENT_INTERFACE (GTK_TYPE_TOOL_SHELL,
319 toolbar_tool_shell_iface_init)
320 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
323 static guint toolbar_signals[LAST_SIGNAL] = { 0 };
327 add_arrow_bindings (GtkBindingSet *binding_set,
329 GtkDirectionType dir)
331 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
333 gtk_binding_entry_add_signal (binding_set, keysym, 0,
335 GTK_TYPE_DIRECTION_TYPE, dir);
336 gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
338 GTK_TYPE_DIRECTION_TYPE, dir);
342 add_ctrl_tab_bindings (GtkBindingSet *binding_set,
343 GdkModifierType modifiers,
344 GtkDirectionType direction)
346 gtk_binding_entry_add_signal (binding_set,
347 GDK_Tab, GDK_CONTROL_MASK | modifiers,
349 GTK_TYPE_DIRECTION_TYPE, direction);
350 gtk_binding_entry_add_signal (binding_set,
351 GDK_KP_Tab, GDK_CONTROL_MASK | modifiers,
353 GTK_TYPE_DIRECTION_TYPE, direction);
357 gtk_toolbar_class_init (GtkToolbarClass *klass)
359 GObjectClass *gobject_class;
360 GtkWidgetClass *widget_class;
361 GtkContainerClass *container_class;
362 GtkBindingSet *binding_set;
364 gobject_class = (GObjectClass *)klass;
365 widget_class = (GtkWidgetClass *)klass;
366 container_class = (GtkContainerClass *)klass;
368 gobject_class->set_property = gtk_toolbar_set_property;
369 gobject_class->get_property = gtk_toolbar_get_property;
370 gobject_class->finalize = gtk_toolbar_finalize;
372 widget_class->button_press_event = gtk_toolbar_button_press;
373 widget_class->expose_event = gtk_toolbar_expose;
374 widget_class->size_request = gtk_toolbar_size_request;
375 widget_class->size_allocate = gtk_toolbar_size_allocate;
376 widget_class->style_set = gtk_toolbar_style_set;
377 widget_class->focus = gtk_toolbar_focus;
379 /* need to override the base class function via override_class_handler,
380 * because the signal slot is not available in GtkWidgetClass
382 g_signal_override_class_handler ("move-focus",
384 G_CALLBACK (gtk_toolbar_move_focus));
386 widget_class->screen_changed = gtk_toolbar_screen_changed;
387 widget_class->realize = gtk_toolbar_realize;
388 widget_class->unrealize = gtk_toolbar_unrealize;
389 widget_class->map = gtk_toolbar_map;
390 widget_class->unmap = gtk_toolbar_unmap;
391 widget_class->popup_menu = gtk_toolbar_popup_menu;
392 widget_class->show_all = gtk_toolbar_show_all;
393 widget_class->hide_all = gtk_toolbar_hide_all;
395 container_class->add = gtk_toolbar_add;
396 container_class->remove = gtk_toolbar_remove;
397 container_class->forall = gtk_toolbar_forall;
398 container_class->child_type = gtk_toolbar_child_type;
399 container_class->get_child_property = gtk_toolbar_get_child_property;
400 container_class->set_child_property = gtk_toolbar_set_child_property;
402 klass->orientation_changed = gtk_toolbar_orientation_changed;
403 klass->style_changed = gtk_toolbar_real_style_changed;
406 * GtkToolbar::orientation-changed:
407 * @toolbar: the object which emitted the signal
408 * @orientation: the new #GtkOrientation of the toolbar
410 * Emitted when the orientation of the toolbar changes.
412 toolbar_signals[ORIENTATION_CHANGED] =
413 g_signal_new (I_("orientation-changed"),
414 G_OBJECT_CLASS_TYPE (klass),
416 G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
418 g_cclosure_marshal_VOID__ENUM,
420 GTK_TYPE_ORIENTATION);
422 * GtkToolbar::style-changed:
423 * @toolbar: The #GtkToolbar which emitted the signal
424 * @style: the new #GtkToolbarStyle of the toolbar
426 * Emitted when the style of the toolbar changes.
428 toolbar_signals[STYLE_CHANGED] =
429 g_signal_new (I_("style-changed"),
430 G_OBJECT_CLASS_TYPE (klass),
432 G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
434 g_cclosure_marshal_VOID__ENUM,
436 GTK_TYPE_TOOLBAR_STYLE);
438 * GtkToolbar::popup-context-menu:
439 * @toolbar: the #GtkToolbar which emitted the signal
440 * @x: the x coordinate of the point where the menu should appear
441 * @y: the y coordinate of the point where the menu should appear
442 * @button: the mouse button the user pressed, or -1
444 * Emitted when the user right-clicks the toolbar or uses the
445 * keybinding to display a popup menu.
447 * Application developers should handle this signal if they want
448 * to display a context menu on the toolbar. The context-menu should
449 * appear at the coordinates given by @x and @y. The mouse button
450 * number is given by the @button parameter. If the menu was popped
451 * up using the keybaord, @button is -1.
453 * Return value: return %TRUE if the signal was handled, %FALSE if not
455 toolbar_signals[POPUP_CONTEXT_MENU] =
456 g_signal_new (I_("popup-context-menu"),
457 G_OBJECT_CLASS_TYPE (klass),
459 G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
460 _gtk_boolean_handled_accumulator, NULL,
461 _gtk_marshal_BOOLEAN__INT_INT_INT,
463 G_TYPE_INT, G_TYPE_INT,
467 * GtkToolbar::focus-home-or-end:
468 * @toolbar: the #GtkToolbar which emitted the signal
469 * @focus_home: %TRUE if the first item should be focused
471 * A keybinding signal used internally by GTK+. This signal can't
472 * be used in application code
474 * Return value: %TRUE if the signal was handled, %FALSE if not
476 toolbar_signals[FOCUS_HOME_OR_END] =
477 g_signal_new_class_handler (I_("focus-home-or-end"),
478 G_OBJECT_CLASS_TYPE (klass),
479 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
480 G_CALLBACK (gtk_toolbar_focus_home_or_end),
482 _gtk_marshal_BOOLEAN__BOOLEAN,
487 g_object_class_override_property (gobject_class,
491 g_object_class_install_property (gobject_class,
493 g_param_spec_enum ("toolbar-style",
495 P_("How to draw the toolbar"),
496 GTK_TYPE_TOOLBAR_STYLE,
497 DEFAULT_TOOLBAR_STYLE,
498 GTK_PARAM_READWRITE));
499 g_object_class_install_property (gobject_class,
501 g_param_spec_boolean ("show-arrow",
503 P_("If an arrow should be shown if the toolbar doesn't fit"),
505 GTK_PARAM_READWRITE));
509 * GtkToolbar:tooltips:
511 * If the tooltips of the toolbar should be active or not.
515 g_object_class_install_property (gobject_class,
517 g_param_spec_boolean ("tooltips",
519 P_("If the tooltips of the toolbar should be active or not"),
521 GTK_PARAM_READWRITE));
525 * GtkToolbar:icon-size:
527 * The size of the icons in a toolbar is normally determined by
528 * the toolbar-icon-size setting. When this property is set, it
529 * overrides the setting.
531 * This should only be used for special-purpose toolbars, normal
532 * application toolbars should respect the user preferences for the
537 g_object_class_install_property (gobject_class,
539 g_param_spec_int ("icon-size",
541 P_("Size of icons in this toolbar"),
544 GTK_PARAM_READWRITE));
547 * GtkToolbar:icon-size-set:
549 * Is %TRUE if the icon-size property has been set.
553 g_object_class_install_property (gobject_class,
555 g_param_spec_boolean ("icon-size-set",
557 P_("Whether the icon-size property has been set"),
559 GTK_PARAM_READWRITE));
561 /* child properties */
562 gtk_container_class_install_child_property (container_class,
564 g_param_spec_boolean ("expand",
566 P_("Whether the item should receive extra space when the toolbar grows"),
568 GTK_PARAM_READWRITE));
570 gtk_container_class_install_child_property (container_class,
571 CHILD_PROP_HOMOGENEOUS,
572 g_param_spec_boolean ("homogeneous",
574 P_("Whether the item should be the same size as other homogeneous items"),
576 GTK_PARAM_READWRITE));
578 /* style properties */
579 gtk_widget_class_install_style_property (widget_class,
580 g_param_spec_int ("space-size",
582 P_("Size of spacers"),
586 GTK_PARAM_READABLE));
588 gtk_widget_class_install_style_property (widget_class,
589 g_param_spec_int ("internal-padding",
590 P_("Internal padding"),
591 P_("Amount of border space between the toolbar shadow and the buttons"),
595 GTK_PARAM_READABLE));
597 gtk_widget_class_install_style_property (widget_class,
598 g_param_spec_int ("max-child-expand",
599 P_("Maximum child expand"),
600 P_("Maximum amount of space an expandable item will be given"),
604 GTK_PARAM_READABLE));
606 gtk_widget_class_install_style_property (widget_class,
607 g_param_spec_enum ("space-style",
609 P_("Whether spacers are vertical lines or just blank"),
610 GTK_TYPE_TOOLBAR_SPACE_STYLE,
612 GTK_PARAM_READABLE));
614 gtk_widget_class_install_style_property (widget_class,
615 g_param_spec_enum ("button-relief",
617 P_("Type of bevel around toolbar buttons"),
618 GTK_TYPE_RELIEF_STYLE,
620 GTK_PARAM_READABLE));
621 gtk_widget_class_install_style_property (widget_class,
622 g_param_spec_enum ("shadow-type",
624 P_("Style of bevel around the toolbar"),
625 GTK_TYPE_SHADOW_TYPE,
627 GTK_PARAM_READABLE));
629 binding_set = gtk_binding_set_by_class (klass);
631 add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
632 add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
633 add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
634 add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
636 gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, 0,
637 "focus-home-or-end", 1,
638 G_TYPE_BOOLEAN, TRUE);
639 gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
640 "focus-home-or-end", 1,
641 G_TYPE_BOOLEAN, TRUE);
642 gtk_binding_entry_add_signal (binding_set, GDK_KP_End, 0,
643 "focus-home-or-end", 1,
644 G_TYPE_BOOLEAN, FALSE);
645 gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
646 "focus-home-or-end", 1,
647 G_TYPE_BOOLEAN, FALSE);
649 add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
650 add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
652 g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));
656 toolbar_tool_shell_iface_init (GtkToolShellIface *iface)
658 iface->get_icon_size = toolbar_get_icon_size;
659 iface->get_orientation = toolbar_get_orientation;
660 iface->get_style = toolbar_get_style;
661 iface->get_relief_style = toolbar_get_relief_style;
662 iface->rebuild_menu = toolbar_rebuild_menu;
666 gtk_toolbar_init (GtkToolbar *toolbar)
668 GtkToolbarPrivate *priv;
670 gtk_widget_set_can_focus (GTK_WIDGET (toolbar), FALSE);
671 GTK_WIDGET_SET_FLAGS (toolbar, GTK_NO_WINDOW);
673 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
675 toolbar->orientation = GTK_ORIENTATION_HORIZONTAL;
676 toolbar->style = DEFAULT_TOOLBAR_STYLE;
677 toolbar->icon_size = DEFAULT_ICON_SIZE;
678 priv->animation = DEFAULT_ANIMATION_STATE;
679 toolbar->tooltips = gtk_tooltips_new ();
680 g_object_ref_sink (toolbar->tooltips);
682 priv->arrow_button = gtk_toggle_button_new ();
683 g_signal_connect (priv->arrow_button, "button-press-event",
684 G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar);
685 g_signal_connect (priv->arrow_button, "clicked",
686 G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar);
687 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
688 get_button_relief (toolbar));
690 priv->api_mode = DONT_KNOW;
692 gtk_button_set_focus_on_click (GTK_BUTTON (priv->arrow_button), FALSE);
694 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
695 gtk_widget_set_name (priv->arrow, "gtk-toolbar-arrow");
696 gtk_widget_show (priv->arrow);
697 gtk_container_add (GTK_CONTAINER (priv->arrow_button), priv->arrow);
699 gtk_widget_set_parent (priv->arrow_button, GTK_WIDGET (toolbar));
701 /* which child position a drop will occur at */
703 priv->show_arrow = TRUE;
704 priv->settings = NULL;
706 priv->max_homogeneous_pixels = -1;
708 priv->timer = g_timer_new ();
712 gtk_toolbar_set_property (GObject *object,
717 GtkToolbar *toolbar = GTK_TOOLBAR (object);
721 case PROP_ORIENTATION:
722 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0,
723 g_value_get_enum (value));
725 case PROP_TOOLBAR_STYLE:
726 gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
728 case PROP_SHOW_ARROW:
729 gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
732 gtk_toolbar_set_tooltips (toolbar, g_value_get_boolean (value));
735 gtk_toolbar_set_icon_size (toolbar, g_value_get_int (value));
737 case PROP_ICON_SIZE_SET:
738 if (g_value_get_boolean (value))
739 toolbar->icon_size_set = TRUE;
741 gtk_toolbar_unset_icon_size (toolbar);
744 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
750 gtk_toolbar_get_property (GObject *object,
755 GtkToolbar *toolbar = GTK_TOOLBAR (object);
756 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
760 case PROP_ORIENTATION:
761 g_value_set_enum (value, toolbar->orientation);
763 case PROP_TOOLBAR_STYLE:
764 g_value_set_enum (value, toolbar->style);
766 case PROP_SHOW_ARROW:
767 g_value_set_boolean (value, priv->show_arrow);
770 g_value_set_boolean (value, gtk_toolbar_get_tooltips (toolbar));
773 g_value_set_int (value, gtk_toolbar_get_icon_size (toolbar));
775 case PROP_ICON_SIZE_SET:
776 g_value_set_boolean (value, toolbar->icon_size_set);
779 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
785 gtk_toolbar_map (GtkWidget *widget)
787 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
789 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->map (widget);
791 if (priv->event_window)
792 gdk_window_show_unraised (priv->event_window);
796 gtk_toolbar_unmap (GtkWidget *widget)
798 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
800 if (priv->event_window)
801 gdk_window_hide (priv->event_window);
803 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unmap (widget);
807 gtk_toolbar_realize (GtkWidget *widget)
809 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
810 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
812 GdkWindowAttr attributes;
813 gint attributes_mask;
816 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
818 border_width = GTK_CONTAINER (widget)->border_width;
820 attributes.wclass = GDK_INPUT_ONLY;
821 attributes.window_type = GDK_WINDOW_CHILD;
822 attributes.x = widget->allocation.x + border_width;
823 attributes.y = widget->allocation.y + border_width;
824 attributes.width = widget->allocation.width - border_width * 2;
825 attributes.height = widget->allocation.height - border_width * 2;
826 attributes.event_mask = gtk_widget_get_events (widget);
827 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
828 GDK_BUTTON_RELEASE_MASK |
829 GDK_ENTER_NOTIFY_MASK |
830 GDK_LEAVE_NOTIFY_MASK);
832 attributes_mask = GDK_WA_X | GDK_WA_Y;
834 widget->window = gtk_widget_get_parent_window (widget);
835 g_object_ref (widget->window);
836 widget->style = gtk_style_attach (widget->style, widget->window);
838 priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
839 &attributes, attributes_mask);
840 gdk_window_set_user_data (priv->event_window, toolbar);
844 gtk_toolbar_unrealize (GtkWidget *widget)
846 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
848 if (priv->event_window)
850 gdk_window_set_user_data (priv->event_window, NULL);
851 gdk_window_destroy (priv->event_window);
852 priv->event_window = NULL;
855 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize (widget);
859 gtk_toolbar_expose (GtkWidget *widget,
860 GdkEventExpose *event)
862 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
863 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
868 border_width = GTK_CONTAINER (widget)->border_width;
870 if (gtk_widget_is_drawable (widget))
872 gtk_paint_box (widget->style,
874 GTK_WIDGET_STATE (widget),
875 get_shadow_type (toolbar),
876 &event->area, widget, "toolbar",
877 border_width + widget->allocation.x,
878 border_width + widget->allocation.y,
879 widget->allocation.width - 2 * border_width,
880 widget->allocation.height - 2 * border_width);
883 for (list = priv->content; list != NULL; list = list->next)
885 ToolbarContent *content = list->data;
887 toolbar_content_expose (content, GTK_CONTAINER (widget), event);
890 gtk_container_propagate_expose (GTK_CONTAINER (widget),
898 gtk_toolbar_size_request (GtkWidget *widget,
899 GtkRequisition *requisition)
901 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
902 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
904 gint max_child_height;
905 gint max_child_width;
906 gint max_homogeneous_child_width;
907 gint max_homogeneous_child_height;
908 gint homogeneous_size;
910 gint pack_front_size;
912 GtkRequisition arrow_requisition;
914 max_homogeneous_child_width = 0;
915 max_homogeneous_child_height = 0;
917 max_child_height = 0;
918 for (list = priv->content; list != NULL; list = list->next)
920 GtkRequisition requisition;
921 ToolbarContent *content = list->data;
923 if (!toolbar_content_visible (content, toolbar))
926 toolbar_content_size_request (content, toolbar, &requisition);
928 max_child_width = MAX (max_child_width, requisition.width);
929 max_child_height = MAX (max_child_height, requisition.height);
931 if (toolbar_content_is_homogeneous (content, toolbar))
933 max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
934 max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
938 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
939 homogeneous_size = max_homogeneous_child_width;
941 homogeneous_size = max_homogeneous_child_height;
944 for (list = priv->content; list != NULL; list = list->next)
946 ToolbarContent *content = list->data;
949 if (!toolbar_content_visible (content, toolbar))
952 if (toolbar_content_is_homogeneous (content, toolbar))
954 size = homogeneous_size;
958 GtkRequisition requisition;
960 toolbar_content_size_request (content, toolbar, &requisition);
962 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
963 size = requisition.width;
965 size = requisition.height;
968 pack_front_size += size;
971 if (priv->show_arrow && priv->api_mode == NEW_API)
973 gtk_widget_size_request (priv->arrow_button, &arrow_requisition);
975 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
976 long_req = arrow_requisition.width;
978 long_req = arrow_requisition.height;
980 /* There is no point requesting space for the arrow if that would take
981 * up more space than all the items combined
983 long_req = MIN (long_req, pack_front_size);
987 arrow_requisition.height = 0;
988 arrow_requisition.width = 0;
990 long_req = pack_front_size;
993 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
995 requisition->width = long_req;
996 requisition->height = MAX (max_child_height, arrow_requisition.height);
1000 requisition->height = long_req;
1001 requisition->width = MAX (max_child_width, arrow_requisition.width);
1005 ipadding = get_internal_padding (toolbar);
1007 requisition->width += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
1008 requisition->height += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
1010 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1012 requisition->width += 2 * widget->style->xthickness;
1013 requisition->height += 2 * widget->style->ythickness;
1016 toolbar->button_maxw = max_homogeneous_child_width;
1017 toolbar->button_maxh = max_homogeneous_child_height;
1021 position (GtkToolbar *toolbar,
1028 if (! GTK_TOOLBAR_GET_PRIVATE (toolbar)->animation)
1031 if (elapsed <= ACCEL_THRESHOLD)
1033 n_pixels = SLIDE_SPEED * elapsed;
1037 /* The formula is a second degree polynomial in
1038 * @elapsed that has the line SLIDE_SPEED * @elapsed
1039 * as tangent for @elapsed == ACCEL_THRESHOLD.
1040 * This makes @n_pixels a smooth function of elapsed time.
1042 n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
1043 SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
1047 return MIN (from + n_pixels, to);
1049 return MAX (from - n_pixels, to);
1053 compute_intermediate_allocation (GtkToolbar *toolbar,
1054 const GtkAllocation *start,
1055 const GtkAllocation *goal,
1056 GtkAllocation *intermediate)
1058 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1059 gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
1061 intermediate->x = position (toolbar, start->x, goal->x, elapsed);
1062 intermediate->y = position (toolbar, start->y, goal->y, elapsed);
1063 intermediate->width = position (toolbar, start->x + start->width,
1064 goal->x + goal->width,
1065 elapsed) - intermediate->x;
1066 intermediate->height = position (toolbar, start->y + start->height,
1067 goal->y + goal->height,
1068 elapsed) - intermediate->y;
1072 fixup_allocation_for_rtl (gint total_size,
1073 GtkAllocation *allocation)
1075 allocation->x += (total_size - (2 * allocation->x + allocation->width));
1079 fixup_allocation_for_vertical (GtkAllocation *allocation)
1083 tmp = allocation->x;
1084 allocation->x = allocation->y;
1085 allocation->y = tmp;
1087 tmp = allocation->width;
1088 allocation->width = allocation->height;
1089 allocation->height = tmp;
1093 get_item_size (GtkToolbar *toolbar,
1094 ToolbarContent *content)
1096 GtkRequisition requisition;
1098 toolbar_content_size_request (content, toolbar, &requisition);
1100 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1102 if (toolbar_content_is_homogeneous (content, toolbar))
1103 return toolbar->button_maxw;
1105 return requisition.width;
1109 if (toolbar_content_is_homogeneous (content, toolbar))
1110 return toolbar->button_maxh;
1112 return requisition.height;
1117 slide_idle_handler (gpointer data)
1119 GtkToolbar *toolbar = data;
1120 GtkToolbarPrivate *priv;
1123 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1125 if (priv->need_sync)
1128 priv->need_sync = FALSE;
1131 for (list = priv->content; list != NULL; list = list->next)
1133 ToolbarContent *content = list->data;
1135 GtkAllocation goal_allocation;
1136 GtkAllocation allocation;
1139 state = toolbar_content_get_state (content);
1140 toolbar_content_get_goal_allocation (content, &goal_allocation);
1141 toolbar_content_get_allocation (content, &allocation);
1145 if (state == NOT_ALLOCATED)
1147 /* an unallocated item means that size allocate has to
1148 * called at least once more
1153 /* An invisible item with a goal allocation of
1154 * 0 is already at its goal.
1156 if ((state == NORMAL || state == OVERFLOWN) &&
1157 ((goal_allocation.width != 0 &&
1158 goal_allocation.height != 0) ||
1159 toolbar_content_child_visible (content)))
1161 if ((goal_allocation.x != allocation.x ||
1162 goal_allocation.y != allocation.y ||
1163 goal_allocation.width != allocation.width ||
1164 goal_allocation.height != allocation.height))
1166 /* An item is not in its right position yet. Note
1167 * that OVERFLOWN items do get an allocation in
1168 * gtk_toolbar_size_allocate(). This way you can see
1169 * them slide back in when you drag an item off the
1176 if (toolbar_content_is_placeholder (content) &&
1177 toolbar_content_disappearing (content) &&
1178 toolbar_content_child_visible (content))
1180 /* A disappearing placeholder is still visible.
1188 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1194 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1196 priv->is_sliding = FALSE;
1203 rect_within (GtkAllocation *a1,
1206 return (a1->x >= a2->x &&
1207 a1->x + a1->width <= a2->x + a2->width &&
1209 a1->y + a1->height <= a2->y + a2->height);
1213 gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
1215 GtkWidget *widget = GTK_WIDGET (toolbar);
1216 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1224 /* Start the sliding. This function copies the allocation of every
1225 * item into content->start_allocation. For items that haven't
1226 * been allocated yet, we calculate their position and save that
1227 * in start_allocatino along with zero width and zero height.
1229 * FIXME: It would be nice if we could share this code with
1230 * the equivalent in gtk_widget_size_allocate().
1232 priv->is_sliding = TRUE;
1235 priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
1237 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1238 vertical = (toolbar->orientation == GTK_ORIENTATION_VERTICAL);
1239 border_width = get_internal_padding (toolbar) + GTK_CONTAINER (toolbar)->border_width;
1243 cur_x = widget->allocation.width - border_width - widget->style->xthickness;
1244 cur_y = widget->allocation.height - border_width - widget->style->ythickness;
1248 cur_x = border_width + widget->style->xthickness;
1249 cur_y = border_width + widget->style->ythickness;
1252 cur_x += widget->allocation.x;
1253 cur_y += widget->allocation.y;
1255 for (list = priv->content; list != NULL; list = list->next)
1257 ToolbarContent *content = list->data;
1258 GtkAllocation new_start_allocation;
1259 GtkAllocation item_allocation;
1262 state = toolbar_content_get_state (content);
1263 toolbar_content_get_allocation (content, &item_allocation);
1265 if ((state == NORMAL &&
1266 rect_within (&item_allocation, &(widget->allocation))) ||
1269 new_start_allocation = item_allocation;
1273 new_start_allocation.x = cur_x;
1274 new_start_allocation.y = cur_y;
1278 new_start_allocation.width = widget->allocation.width -
1279 2 * border_width - 2 * widget->style->xthickness;
1280 new_start_allocation.height = 0;
1284 new_start_allocation.width = 0;
1285 new_start_allocation.height = widget->allocation.height -
1286 2 * border_width - 2 * widget->style->ythickness;
1291 cur_y = new_start_allocation.y + new_start_allocation.height;
1293 cur_x = new_start_allocation.x;
1295 cur_x = new_start_allocation.x + new_start_allocation.width;
1297 toolbar_content_set_start_allocation (content, &new_start_allocation);
1300 /* This resize will run before the first idle handler. This
1301 * will make sure that items get the right goal allocation
1302 * so that the idle handler will not immediately return
1305 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1306 g_timer_reset (priv->timer);
1310 gtk_toolbar_stop_sliding (GtkToolbar *toolbar)
1312 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1314 if (priv->is_sliding)
1318 priv->is_sliding = FALSE;
1322 g_source_remove (priv->idle_id);
1326 list = priv->content;
1329 ToolbarContent *content = list->data;
1332 if (toolbar_content_is_placeholder (content))
1334 toolbar_content_remove (content, toolbar);
1335 toolbar_content_free (content);
1339 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1344 remove_item (GtkWidget *menu_item,
1347 gtk_container_remove (GTK_CONTAINER (menu_item->parent), menu_item);
1351 menu_deactivated (GtkWidget *menu,
1352 GtkToolbar *toolbar)
1354 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1355 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->arrow_button), FALSE);
1359 menu_detached (GtkWidget *toolbar,
1362 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1367 rebuild_menu (GtkToolbar *toolbar)
1369 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1370 GList *list, *children;
1374 priv->menu = GTK_MENU (gtk_menu_new());
1375 gtk_menu_attach_to_widget (priv->menu,
1376 GTK_WIDGET (toolbar),
1379 g_signal_connect (priv->menu, "deactivate",
1380 G_CALLBACK (menu_deactivated), toolbar);
1383 gtk_container_foreach (GTK_CONTAINER (priv->menu), remove_item, NULL);
1385 for (list = priv->content; list != NULL; list = list->next)
1387 ToolbarContent *content = list->data;
1389 if (toolbar_content_get_state (content) == OVERFLOWN &&
1390 !toolbar_content_is_placeholder (content))
1392 GtkWidget *menu_item = toolbar_content_retrieve_menu_item (content);
1396 g_assert (GTK_IS_MENU_ITEM (menu_item));
1397 gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item);
1402 /* Remove leading and trailing separator items */
1403 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1406 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1408 GtkWidget *child = list->data;
1410 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1413 g_list_free (children);
1415 /* Regenerate the list of children so we don't try to remove items twice */
1416 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1418 list = g_list_last (children);
1419 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1421 GtkWidget *child = list->data;
1423 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1426 g_list_free (children);
1428 priv->need_rebuild = FALSE;
1432 gtk_toolbar_size_allocate (GtkWidget *widget,
1433 GtkAllocation *allocation)
1435 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1436 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1437 GtkAllocation *allocations;
1438 ItemState *new_states;
1439 GtkAllocation arrow_allocation;
1441 gint size, pos, short_size;
1444 gboolean need_arrow;
1445 gint n_expand_items;
1447 gint available_size;
1450 GtkRequisition arrow_requisition;
1451 gboolean overflowing;
1452 gboolean size_changed;
1454 GtkAllocation item_area;
1455 GtkShadowType shadow_type;
1457 size_changed = FALSE;
1458 if (widget->allocation.x != allocation->x ||
1459 widget->allocation.y != allocation->y ||
1460 widget->allocation.width != allocation->width ||
1461 widget->allocation.height != allocation->height)
1463 size_changed = TRUE;
1467 gtk_toolbar_stop_sliding (toolbar);
1469 widget->allocation = *allocation;
1471 border_width = GTK_CONTAINER (toolbar)->border_width;
1473 if (GTK_WIDGET_REALIZED (widget))
1475 gdk_window_move_resize (priv->event_window,
1476 allocation->x + border_width,
1477 allocation->y + border_width,
1478 allocation->width - border_width * 2,
1479 allocation->height - border_width * 2);
1482 border_width += get_internal_padding (toolbar);
1484 gtk_widget_get_child_requisition (GTK_WIDGET (priv->arrow_button),
1485 &arrow_requisition);
1487 shadow_type = get_shadow_type (toolbar);
1489 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1491 available_size = size = allocation->width - 2 * border_width;
1492 short_size = allocation->height - 2 * border_width;
1493 arrow_size = arrow_requisition.width;
1495 if (shadow_type != GTK_SHADOW_NONE)
1497 available_size -= 2 * widget->style->xthickness;
1498 short_size -= 2 * widget->style->ythickness;
1503 available_size = size = allocation->height - 2 * border_width;
1504 short_size = allocation->width - 2 * border_width;
1505 arrow_size = arrow_requisition.height;
1507 if (shadow_type != GTK_SHADOW_NONE)
1509 available_size -= 2 * widget->style->ythickness;
1510 short_size -= 2 * widget->style->xthickness;
1514 n_items = g_list_length (priv->content);
1515 allocations = g_new0 (GtkAllocation, n_items);
1516 new_states = g_new0 (ItemState, n_items);
1520 for (list = priv->content; list != NULL; list = list->next)
1522 ToolbarContent *content = list->data;
1524 if (toolbar_content_visible (content, toolbar))
1526 needed_size += get_item_size (toolbar, content);
1528 /* Do we need an arrow?
1530 * Assume we don't, and see if any non-separator item with a
1531 * proxy menu item is then going to overflow.
1533 if (needed_size > available_size &&
1536 priv->api_mode == NEW_API &&
1537 toolbar_content_has_proxy_menu_item (content) &&
1538 !toolbar_content_is_separator (content))
1546 size = available_size - arrow_size;
1548 size = available_size;
1550 /* calculate widths and states of items */
1551 overflowing = FALSE;
1552 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1554 ToolbarContent *content = list->data;
1557 if (!toolbar_content_visible (content, toolbar))
1559 new_states[i] = HIDDEN;
1563 item_size = get_item_size (toolbar, content);
1564 if (item_size <= size && !overflowing)
1567 allocations[i].width = item_size;
1568 new_states[i] = NORMAL;
1573 new_states[i] = OVERFLOWN;
1574 allocations[i].width = item_size;
1578 /* calculate width of arrow */
1581 arrow_allocation.width = arrow_size;
1582 arrow_allocation.height = MAX (short_size, 1);
1585 /* expand expandable items */
1587 /* We don't expand when there is an overflow menu, because that leads to
1588 * weird jumps when items get moved to the overflow menu and the expanding
1589 * items suddenly get a lot of extra space
1593 gint max_child_expand;
1596 for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
1598 ToolbarContent *content = list->data;
1600 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1604 max_child_expand = get_max_child_expand (toolbar);
1605 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1607 ToolbarContent *content = list->data;
1609 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1611 gint extra = size / n_expand_items;
1612 if (size % n_expand_items != 0)
1615 if (extra > max_child_expand)
1616 extra = max_child_expand;
1618 allocations[i].width += extra;
1624 g_assert (n_expand_items == 0);
1627 /* position items */
1629 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1631 /* both NORMAL and OVERFLOWN items get a position. This ensures
1632 * that sliding will work for OVERFLOWN items too
1634 if (new_states[i] == NORMAL ||
1635 new_states[i] == OVERFLOWN)
1637 allocations[i].x = pos;
1638 allocations[i].y = border_width;
1639 allocations[i].height = short_size;
1641 pos += allocations[i].width;
1645 /* position arrow */
1648 arrow_allocation.x = available_size - border_width - arrow_allocation.width;
1649 arrow_allocation.y = border_width;
1652 item_area.x = border_width;
1653 item_area.y = border_width;
1654 item_area.width = available_size - (need_arrow? arrow_size : 0);
1655 item_area.height = short_size;
1657 /* fix up allocations in the vertical or RTL cases */
1658 if (toolbar->orientation == GTK_ORIENTATION_VERTICAL)
1660 for (i = 0; i < n_items; ++i)
1661 fixup_allocation_for_vertical (&(allocations[i]));
1664 fixup_allocation_for_vertical (&arrow_allocation);
1666 fixup_allocation_for_vertical (&item_area);
1668 else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1670 for (i = 0; i < n_items; ++i)
1671 fixup_allocation_for_rtl (available_size, &(allocations[i]));
1674 fixup_allocation_for_rtl (available_size, &arrow_allocation);
1676 fixup_allocation_for_rtl (available_size, &item_area);
1679 /* translate the items by allocation->(x,y) */
1680 for (i = 0; i < n_items; ++i)
1682 allocations[i].x += allocation->x;
1683 allocations[i].y += allocation->y;
1685 if (shadow_type != GTK_SHADOW_NONE)
1687 allocations[i].x += widget->style->xthickness;
1688 allocations[i].y += widget->style->ythickness;
1694 arrow_allocation.x += allocation->x;
1695 arrow_allocation.y += allocation->y;
1697 if (shadow_type != GTK_SHADOW_NONE)
1699 arrow_allocation.x += widget->style->xthickness;
1700 arrow_allocation.y += widget->style->ythickness;
1704 item_area.x += allocation->x;
1705 item_area.y += allocation->y;
1706 if (shadow_type != GTK_SHADOW_NONE)
1708 item_area.x += widget->style->xthickness;
1709 item_area.y += widget->style->ythickness;
1712 /* did anything change? */
1713 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1715 ToolbarContent *content = list->data;
1717 if (toolbar_content_get_state (content) == NORMAL &&
1718 new_states[i] != NORMAL)
1720 /* an item disappeared and we didn't change size, so begin sliding */
1721 if (!size_changed && priv->api_mode == NEW_API)
1722 gtk_toolbar_begin_sliding (toolbar);
1726 /* finally allocate the items */
1727 if (priv->is_sliding)
1729 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1731 ToolbarContent *content = list->data;
1733 toolbar_content_set_goal_allocation (content, &(allocations[i]));
1737 elapsed = g_timer_elapsed (priv->timer, NULL);
1738 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1740 ToolbarContent *content = list->data;
1742 if (new_states[i] == OVERFLOWN ||
1743 new_states[i] == NORMAL)
1745 GtkAllocation alloc;
1746 GtkAllocation start_allocation = { 0, };
1747 GtkAllocation goal_allocation;
1749 if (priv->is_sliding)
1751 toolbar_content_get_start_allocation (content, &start_allocation);
1752 toolbar_content_get_goal_allocation (content, &goal_allocation);
1754 compute_intermediate_allocation (toolbar,
1759 priv->need_sync = TRUE;
1763 alloc = allocations[i];
1766 if (alloc.width <= 0 || alloc.height <= 0)
1768 toolbar_content_set_child_visible (content, toolbar, FALSE);
1772 if (!rect_within (&alloc, &item_area))
1774 toolbar_content_set_child_visible (content, toolbar, FALSE);
1775 toolbar_content_size_allocate (content, &alloc);
1779 toolbar_content_set_child_visible (content, toolbar, TRUE);
1780 toolbar_content_size_allocate (content, &alloc);
1786 toolbar_content_set_child_visible (content, toolbar, FALSE);
1789 toolbar_content_set_state (content, new_states[i]);
1792 if (priv->menu && priv->need_rebuild)
1793 rebuild_menu (toolbar);
1797 gtk_widget_size_allocate (GTK_WIDGET (priv->arrow_button),
1799 gtk_widget_show (GTK_WIDGET (priv->arrow_button));
1803 gtk_widget_hide (GTK_WIDGET (priv->arrow_button));
1805 if (priv->menu && gtk_widget_get_visible (GTK_WIDGET (priv->menu)))
1806 gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
1809 g_free (allocations);
1810 g_free (new_states);
1814 gtk_toolbar_update_button_relief (GtkToolbar *toolbar)
1816 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1817 GtkReliefStyle relief;
1819 relief = get_button_relief (toolbar);
1821 if (relief != gtk_button_get_relief (GTK_BUTTON (priv->arrow_button)))
1823 gtk_toolbar_reconfigured (toolbar);
1825 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), relief);
1830 gtk_toolbar_style_set (GtkWidget *widget,
1831 GtkStyle *prev_style)
1833 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
1835 priv->max_homogeneous_pixels = -1;
1837 if (GTK_WIDGET_REALIZED (widget))
1838 gtk_style_set_background (widget->style, widget->window, widget->state);
1841 gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
1845 gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
1846 GtkDirectionType dir)
1848 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1849 GList *result = NULL;
1853 /* generate list of children in reverse logical order */
1855 for (list = priv->content; list != NULL; list = list->next)
1857 ToolbarContent *content = list->data;
1860 widget = toolbar_content_get_widget (content);
1863 result = g_list_prepend (result, widget);
1866 result = g_list_prepend (result, priv->arrow_button);
1868 rtl = (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL);
1870 /* move in logical order when
1872 * - dir is TAB_FORWARD
1874 * - in RTL mode and moving left or up
1876 * - in LTR mode and moving right or down
1878 if (dir == GTK_DIR_TAB_FORWARD ||
1879 (rtl && (dir == GTK_DIR_UP || dir == GTK_DIR_LEFT)) ||
1880 (!rtl && (dir == GTK_DIR_DOWN || dir == GTK_DIR_RIGHT)))
1882 result = g_list_reverse (result);
1889 gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
1890 gboolean focus_home)
1892 GList *children, *list;
1893 GtkDirectionType dir = focus_home? GTK_DIR_RIGHT : GTK_DIR_LEFT;
1895 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1897 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1899 children = g_list_reverse (children);
1901 dir = (dir == GTK_DIR_RIGHT)? GTK_DIR_LEFT : GTK_DIR_RIGHT;
1904 for (list = children; list != NULL; list = list->next)
1906 GtkWidget *child = list->data;
1908 if (GTK_CONTAINER (toolbar)->focus_child == child)
1911 if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1915 g_list_free (children);
1920 /* Keybinding handler. This function is called when the user presses
1921 * Ctrl TAB or an arrow key.
1924 gtk_toolbar_move_focus (GtkWidget *widget,
1925 GtkDirectionType dir)
1927 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1928 GtkContainer *container = GTK_CONTAINER (toolbar);
1930 gboolean try_focus = FALSE;
1933 if (container->focus_child &&
1934 gtk_widget_child_focus (container->focus_child, dir))
1939 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1941 for (list = children; list != NULL; list = list->next)
1943 GtkWidget *child = list->data;
1945 if (try_focus && gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1948 if (child == GTK_CONTAINER (toolbar)->focus_child)
1952 g_list_free (children);
1955 /* The focus handler for the toolbar. It called when the user presses
1956 * TAB or otherwise tries to focus the toolbar.
1959 gtk_toolbar_focus (GtkWidget *widget,
1960 GtkDirectionType dir)
1962 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1963 GList *children, *list;
1964 gboolean result = FALSE;
1966 /* if focus is already somewhere inside the toolbar then return FALSE.
1967 * The only way focus can stay inside the toolbar is when the user presses
1968 * arrow keys or Ctrl TAB (both of which are handled by the
1969 * gtk_toolbar_move_focus() keybinding function.
1971 if (GTK_CONTAINER (widget)->focus_child)
1974 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1976 for (list = children; list != NULL; list = list->next)
1978 GtkWidget *child = list->data;
1980 if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1987 g_list_free (children);
1992 static GtkSettings *
1993 toolbar_get_settings (GtkToolbar *toolbar)
1995 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1996 return priv->settings;
2000 style_change_notify (GtkToolbar *toolbar)
2002 if (!toolbar->style_set)
2004 /* pretend it was set, then unset, thus reverting to new default */
2005 toolbar->style_set = TRUE;
2006 gtk_toolbar_unset_style (toolbar);
2011 icon_size_change_notify (GtkToolbar *toolbar)
2013 if (!toolbar->icon_size_set)
2015 /* pretend it was set, then unset, thus reverting to new default */
2016 toolbar->icon_size_set = TRUE;
2017 gtk_toolbar_unset_icon_size (toolbar);
2022 animation_change_notify (GtkToolbar *toolbar)
2024 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2025 GtkSettings *settings = toolbar_get_settings (toolbar);
2029 g_object_get (settings,
2030 "gtk-enable-animations", &animation,
2033 animation = DEFAULT_ANIMATION_STATE;
2035 priv->animation = animation;
2039 settings_change_notify (GtkSettings *settings,
2040 const GParamSpec *pspec,
2041 GtkToolbar *toolbar)
2043 if (! strcmp (pspec->name, "gtk-toolbar-style"))
2044 style_change_notify (toolbar);
2045 else if (! strcmp (pspec->name, "gtk-toolbar-icon-size"))
2046 icon_size_change_notify (toolbar);
2047 else if (! strcmp (pspec->name, "gtk-enable-animations"))
2048 animation_change_notify (toolbar);
2052 gtk_toolbar_screen_changed (GtkWidget *widget,
2053 GdkScreen *previous_screen)
2055 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2056 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2057 GtkSettings *old_settings = toolbar_get_settings (toolbar);
2058 GtkSettings *settings;
2060 if (gtk_widget_has_screen (GTK_WIDGET (toolbar)))
2061 settings = gtk_widget_get_settings (GTK_WIDGET (toolbar));
2065 if (settings == old_settings)
2070 g_signal_handler_disconnect (old_settings, priv->settings_connection);
2072 g_object_unref (old_settings);
2077 priv->settings_connection =
2078 g_signal_connect (settings, "notify",
2079 G_CALLBACK (settings_change_notify),
2082 priv->settings = g_object_ref (settings);
2085 priv->settings = NULL;
2087 style_change_notify (toolbar);
2088 icon_size_change_notify (toolbar);
2089 animation_change_notify (toolbar);
2093 find_drop_index (GtkToolbar *toolbar,
2097 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2098 GList *interesting_content;
2100 GtkOrientation orientation;
2101 GtkTextDirection direction;
2102 gint best_distance = G_MAXINT;
2106 ToolbarContent *best_content;
2107 GtkAllocation allocation;
2109 /* list items we care about wrt. drag and drop */
2110 interesting_content = NULL;
2111 for (list = priv->content; list != NULL; list = list->next)
2113 ToolbarContent *content = list->data;
2115 if (toolbar_content_get_state (content) == NORMAL)
2116 interesting_content = g_list_prepend (interesting_content, content);
2118 interesting_content = g_list_reverse (interesting_content);
2120 if (!interesting_content)
2123 orientation = toolbar->orientation;
2124 direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
2126 /* distance to first interesting item */
2127 best_content = interesting_content->data;
2128 toolbar_content_get_allocation (best_content, &allocation);
2130 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2134 if (direction == GTK_TEXT_DIR_LTR)
2137 pos = allocation.x + allocation.width;
2145 best_content = NULL;
2146 best_distance = ABS (pos - cursor);
2148 /* distance to far end of each item */
2149 for (list = interesting_content; list != NULL; list = list->next)
2151 ToolbarContent *content = list->data;
2153 toolbar_content_get_allocation (content, &allocation);
2155 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2157 if (direction == GTK_TEXT_DIR_LTR)
2158 pos = allocation.x + allocation.width;
2164 pos = allocation.y + allocation.height;
2167 distance = ABS (pos - cursor);
2169 if (distance < best_distance)
2171 best_distance = distance;
2172 best_content = content;
2176 g_list_free (interesting_content);
2181 return g_list_index (priv->content, best_content) + 1;
2185 reset_all_placeholders (GtkToolbar *toolbar)
2187 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2190 for (list = priv->content; list != NULL; list = list->next)
2192 ToolbarContent *content = list->data;
2193 if (toolbar_content_is_placeholder (content))
2194 toolbar_content_set_disappearing (content, TRUE);
2199 physical_to_logical (GtkToolbar *toolbar,
2202 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2206 g_assert (physical >= 0);
2209 for (list = priv->content; list && physical > 0; list = list->next)
2211 ToolbarContent *content = list->data;
2213 if (!toolbar_content_is_placeholder (content))
2218 g_assert (physical == 0);
2224 logical_to_physical (GtkToolbar *toolbar,
2227 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2231 g_assert (logical >= 0);
2234 for (list = priv->content; list; list = list->next)
2236 ToolbarContent *content = list->data;
2238 if (!toolbar_content_is_placeholder (content))
2248 g_assert (logical == 0);
2254 * gtk_toolbar_set_drop_highlight_item:
2255 * @toolbar: a #GtkToolbar
2256 * @tool_item: (allow-none): a #GtkToolItem, or %NULL to turn of highlighting
2257 * @index_: a position on @toolbar
2259 * Highlights @toolbar to give an idea of what it would look like
2260 * if @item was added to @toolbar at the position indicated by @index_.
2261 * If @item is %NULL, highlighting is turned off. In that case @index_
2264 * The @tool_item passed to this function must not be part of any widget
2265 * hierarchy. When an item is set as drop highlight item it can not
2266 * added to any widget hierarchy or used as highlight item for another
2272 gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar,
2273 GtkToolItem *tool_item,
2276 ToolbarContent *content;
2277 GtkToolbarPrivate *priv;
2279 GtkRequisition requisition;
2280 GtkRequisition old_requisition;
2281 gboolean restart_sliding;
2283 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2284 g_return_if_fail (tool_item == NULL || GTK_IS_TOOL_ITEM (tool_item));
2286 gtk_toolbar_check_new_api (toolbar);
2288 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2292 if (priv->highlight_tool_item)
2294 gtk_widget_unparent (GTK_WIDGET (priv->highlight_tool_item));
2295 g_object_unref (priv->highlight_tool_item);
2296 priv->highlight_tool_item = NULL;
2299 reset_all_placeholders (toolbar);
2300 gtk_toolbar_begin_sliding (toolbar);
2304 n_items = gtk_toolbar_get_n_items (toolbar);
2305 if (index_ < 0 || index_ > n_items)
2308 if (tool_item != priv->highlight_tool_item)
2310 if (priv->highlight_tool_item)
2311 g_object_unref (priv->highlight_tool_item);
2313 g_object_ref_sink (tool_item);
2315 priv->highlight_tool_item = tool_item;
2317 gtk_widget_set_parent (GTK_WIDGET (priv->highlight_tool_item),
2318 GTK_WIDGET (toolbar));
2321 index_ = logical_to_physical (toolbar, index_);
2323 content = g_list_nth_data (priv->content, index_);
2327 ToolbarContent *prev_content;
2329 prev_content = g_list_nth_data (priv->content, index_ - 1);
2331 if (prev_content && toolbar_content_is_placeholder (prev_content))
2332 content = prev_content;
2335 if (!content || !toolbar_content_is_placeholder (content))
2337 GtkWidget *placeholder;
2339 placeholder = GTK_WIDGET (gtk_separator_tool_item_new ());
2341 content = toolbar_content_new_tool_item (toolbar,
2342 GTK_TOOL_ITEM (placeholder),
2344 gtk_widget_show (placeholder);
2348 g_assert (toolbar_content_is_placeholder (content));
2350 gtk_widget_size_request (GTK_WIDGET (priv->highlight_tool_item),
2353 toolbar_content_set_expand (content, gtk_tool_item_get_expand (tool_item));
2355 restart_sliding = FALSE;
2356 toolbar_content_size_request (content, toolbar, &old_requisition);
2357 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2359 requisition.height = -1;
2360 if (requisition.width != old_requisition.width)
2361 restart_sliding = TRUE;
2365 requisition.width = -1;
2366 if (requisition.height != old_requisition.height)
2367 restart_sliding = TRUE;
2370 if (toolbar_content_disappearing (content))
2371 restart_sliding = TRUE;
2373 reset_all_placeholders (toolbar);
2374 toolbar_content_set_disappearing (content, FALSE);
2376 toolbar_content_set_size_request (content,
2377 requisition.width, requisition.height);
2379 if (restart_sliding)
2380 gtk_toolbar_begin_sliding (toolbar);
2384 gtk_toolbar_get_child_property (GtkContainer *container,
2390 GtkToolItem *item = GTK_TOOL_ITEM (child);
2392 switch (property_id)
2394 case CHILD_PROP_HOMOGENEOUS:
2395 g_value_set_boolean (value, gtk_tool_item_get_homogeneous (item));
2398 case CHILD_PROP_EXPAND:
2399 g_value_set_boolean (value, gtk_tool_item_get_expand (item));
2403 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2409 gtk_toolbar_set_child_property (GtkContainer *container,
2412 const GValue *value,
2415 switch (property_id)
2417 case CHILD_PROP_HOMOGENEOUS:
2418 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2421 case CHILD_PROP_EXPAND:
2422 gtk_tool_item_set_expand (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2426 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2432 gtk_toolbar_show_all (GtkWidget *widget)
2434 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2437 for (list = priv->content; list != NULL; list = list->next)
2439 ToolbarContent *content = list->data;
2441 toolbar_content_show_all (content);
2444 gtk_widget_show (widget);
2448 gtk_toolbar_hide_all (GtkWidget *widget)
2450 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2453 for (list = priv->content; list != NULL; list = list->next)
2455 ToolbarContent *content = list->data;
2457 toolbar_content_hide_all (content);
2460 gtk_widget_hide (widget);
2464 gtk_toolbar_add (GtkContainer *container,
2467 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2469 if (GTK_IS_TOOL_ITEM (widget))
2470 gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
2472 gtk_toolbar_append_widget (toolbar, widget, NULL, NULL);
2476 gtk_toolbar_remove (GtkContainer *container,
2479 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2480 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2481 ToolbarContent *content_to_remove;
2484 content_to_remove = NULL;
2485 for (list = priv->content; list != NULL; list = list->next)
2487 ToolbarContent *content = list->data;
2490 child = toolbar_content_get_widget (content);
2491 if (child && child == widget)
2493 content_to_remove = content;
2498 g_return_if_fail (content_to_remove != NULL);
2500 toolbar_content_remove (content_to_remove, toolbar);
2501 toolbar_content_free (content_to_remove);
2505 gtk_toolbar_forall (GtkContainer *container,
2506 gboolean include_internals,
2507 GtkCallback callback,
2508 gpointer callback_data)
2510 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2511 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2514 g_return_if_fail (callback != NULL);
2516 list = priv->content;
2519 ToolbarContent *content = list->data;
2520 GList *next = list->next;
2522 if (include_internals || !toolbar_content_is_placeholder (content))
2524 GtkWidget *child = toolbar_content_get_widget (content);
2527 callback (child, callback_data);
2533 if (include_internals)
2534 callback (priv->arrow_button, callback_data);
2538 gtk_toolbar_child_type (GtkContainer *container)
2540 return GTK_TYPE_TOOL_ITEM;
2544 gtk_toolbar_reconfigured (GtkToolbar *toolbar)
2546 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2549 list = priv->content;
2552 ToolbarContent *content = list->data;
2553 GList *next = list->next;
2555 toolbar_content_toolbar_reconfigured (content, toolbar);
2562 gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
2563 GtkOrientation orientation)
2565 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2566 if (toolbar->orientation != orientation)
2568 toolbar->orientation = orientation;
2570 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2571 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2573 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2575 gtk_toolbar_reconfigured (toolbar);
2577 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2578 g_object_notify (G_OBJECT (toolbar), "orientation");
2583 gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
2584 GtkToolbarStyle style)
2586 if (toolbar->style != style)
2588 toolbar->style = style;
2590 gtk_toolbar_reconfigured (toolbar);
2592 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2593 g_object_notify (G_OBJECT (toolbar), "toolbar-style");
2598 menu_position_func (GtkMenu *menu,
2604 GtkToolbar *toolbar = GTK_TOOLBAR (user_data);
2605 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2607 GtkRequisition menu_req;
2608 GdkRectangle monitor;
2612 gtk_widget_size_request (priv->arrow_button, &req);
2613 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2615 screen = gtk_widget_get_screen (GTK_WIDGET (menu));
2616 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->arrow_button->window);
2617 if (monitor_num < 0)
2619 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2621 gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
2622 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2624 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2625 *x += priv->arrow_button->allocation.width - req.width;
2627 *x += req.width - menu_req.width;
2629 if ((*y + priv->arrow_button->allocation.height + menu_req.height) <= monitor.y + monitor.height)
2630 *y += priv->arrow_button->allocation.height;
2631 else if ((*y - menu_req.height) >= monitor.y)
2632 *y -= menu_req.height;
2633 else if (monitor.y + monitor.height - (*y + priv->arrow_button->allocation.height) > *y)
2634 *y += priv->arrow_button->allocation.height;
2636 *y -= menu_req.height;
2640 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2641 *x += priv->arrow_button->allocation.width;
2643 *x -= menu_req.width;
2645 if (*y + menu_req.height > monitor.y + monitor.height &&
2646 *y + priv->arrow_button->allocation.height - monitor.y > monitor.y + monitor.height - *y)
2647 *y += priv->arrow_button->allocation.height - menu_req.height;
2654 show_menu (GtkToolbar *toolbar,
2655 GdkEventButton *event)
2657 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2659 rebuild_menu (toolbar);
2661 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2663 gtk_menu_popup (priv->menu, NULL, NULL,
2664 menu_position_func, toolbar,
2665 event? event->button : 0,
2666 event? event->time : gtk_get_current_event_time());
2670 gtk_toolbar_arrow_button_clicked (GtkWidget *button,
2671 GtkToolbar *toolbar)
2673 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2675 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) &&
2676 (!priv->menu || !gtk_widget_get_visible (GTK_WIDGET (priv->menu))))
2678 /* We only get here when the button is clicked with the keyboard,
2679 * because mouse button presses result in the menu being shown so
2680 * that priv->menu would be non-NULL and visible.
2682 show_menu (toolbar, NULL);
2683 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
2688 gtk_toolbar_arrow_button_press (GtkWidget *button,
2689 GdkEventButton *event,
2690 GtkToolbar *toolbar)
2692 show_menu (toolbar, event);
2693 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
2699 gtk_toolbar_button_press (GtkWidget *toolbar,
2700 GdkEventButton *event)
2702 if (event->button == 3)
2704 gboolean return_value;
2706 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2707 (int)event->x_root, (int)event->y_root, event->button,
2710 return return_value;
2717 gtk_toolbar_popup_menu (GtkWidget *toolbar)
2719 gboolean return_value;
2720 /* This function is the handler for the "popup menu" keybinding,
2721 * ie., it is called when the user presses Shift F10
2723 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2724 -1, -1, -1, &return_value);
2726 return return_value;
2732 * Creates a new toolbar.
2734 * Return Value: the newly-created toolbar.
2737 gtk_toolbar_new (void)
2739 GtkToolbar *toolbar;
2741 toolbar = g_object_new (GTK_TYPE_TOOLBAR, NULL);
2743 return GTK_WIDGET (toolbar);
2747 * gtk_toolbar_insert:
2748 * @toolbar: a #GtkToolbar
2749 * @item: a #GtkToolItem
2750 * @pos: the position of the new item
2752 * Insert a #GtkToolItem into the toolbar at position @pos. If @pos is
2753 * 0 the item is prepended to the start of the toolbar. If @pos is
2754 * negative, the item is appended to the end of the toolbar.
2759 gtk_toolbar_insert (GtkToolbar *toolbar,
2763 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2764 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
2766 if (!gtk_toolbar_check_new_api (toolbar))
2770 pos = logical_to_physical (toolbar, pos);
2772 toolbar_content_new_tool_item (toolbar, item, FALSE, pos);
2776 * gtk_toolbar_get_item_index:
2777 * @toolbar: a #GtkToolbar
2778 * @item: a #GtkToolItem that is a child of @toolbar
2780 * Returns the position of @item on the toolbar, starting from 0.
2781 * It is an error if @item is not a child of the toolbar.
2783 * Return value: the position of item on the toolbar.
2788 gtk_toolbar_get_item_index (GtkToolbar *toolbar,
2791 GtkToolbarPrivate *priv;
2795 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2796 g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
2797 g_return_val_if_fail (GTK_WIDGET (item)->parent == GTK_WIDGET (toolbar), -1);
2799 if (!gtk_toolbar_check_new_api (toolbar))
2802 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2805 for (list = priv->content; list != NULL; list = list->next)
2807 ToolbarContent *content = list->data;
2810 widget = toolbar_content_get_widget (content);
2812 if (item == GTK_TOOL_ITEM (widget))
2818 return physical_to_logical (toolbar, n);
2822 * gtk_toolbar_set_orientation:
2823 * @toolbar: a #GtkToolbar.
2824 * @orientation: a new #GtkOrientation.
2826 * Sets whether a toolbar should appear horizontally or vertically.
2828 * Deprecated: 2.16: Use gtk_orientable_set_orientation() instead.
2831 gtk_toolbar_set_orientation (GtkToolbar *toolbar,
2832 GtkOrientation orientation)
2834 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2836 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0, orientation);
2840 * gtk_toolbar_get_orientation:
2841 * @toolbar: a #GtkToolbar
2843 * Retrieves the current orientation of the toolbar. See
2844 * gtk_toolbar_set_orientation().
2846 * Return value: the orientation
2848 * Deprecated: 2.16: Use gtk_orientable_get_orientation() instead.
2851 gtk_toolbar_get_orientation (GtkToolbar *toolbar)
2853 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_ORIENTATION_HORIZONTAL);
2855 return toolbar->orientation;
2859 * gtk_toolbar_set_style:
2860 * @toolbar: a #GtkToolbar.
2861 * @style: the new style for @toolbar.
2863 * Alters the view of @toolbar to display either icons only, text only, or both.
2866 gtk_toolbar_set_style (GtkToolbar *toolbar,
2867 GtkToolbarStyle style)
2869 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2871 toolbar->style_set = TRUE;
2872 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2876 * gtk_toolbar_get_style:
2877 * @toolbar: a #GtkToolbar
2879 * Retrieves whether the toolbar has text, icons, or both . See
2880 * gtk_toolbar_set_style().
2882 * Return value: the current style of @toolbar
2885 gtk_toolbar_get_style (GtkToolbar *toolbar)
2887 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_TOOLBAR_STYLE);
2889 return toolbar->style;
2893 * gtk_toolbar_unset_style:
2894 * @toolbar: a #GtkToolbar
2896 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that
2897 * user preferences will be used to determine the toolbar style.
2900 gtk_toolbar_unset_style (GtkToolbar *toolbar)
2902 GtkToolbarStyle style;
2904 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2906 if (toolbar->style_set)
2908 GtkSettings *settings = toolbar_get_settings (toolbar);
2911 g_object_get (settings,
2912 "gtk-toolbar-style", &style,
2915 style = DEFAULT_TOOLBAR_STYLE;
2917 if (style != toolbar->style)
2918 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2920 toolbar->style_set = FALSE;
2925 * gtk_toolbar_set_tooltips:
2926 * @toolbar: a #GtkToolbar.
2927 * @enable: set to %FALSE to disable the tooltips, or %TRUE to enable them.
2929 * Sets if the tooltips of a toolbar should be active or not.
2931 * Deprecated: 2.14: The toolkit-wide #GtkSettings:gtk-enable-tooltips property
2932 * is now used instead.
2935 gtk_toolbar_set_tooltips (GtkToolbar *toolbar,
2938 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2941 gtk_tooltips_enable (toolbar->tooltips);
2943 gtk_tooltips_disable (toolbar->tooltips);
2945 g_object_notify (G_OBJECT (toolbar), "tooltips");
2949 * gtk_toolbar_get_tooltips:
2950 * @toolbar: a #GtkToolbar
2952 * Retrieves whether tooltips are enabled. See
2953 * gtk_toolbar_set_tooltips().
2955 * Return value: %TRUE if tooltips are enabled
2957 * Deprecated: 2.14: The toolkit-wide #GtkSettings:gtk-enable-tooltips property
2958 * is now used instead.
2961 gtk_toolbar_get_tooltips (GtkToolbar *toolbar)
2963 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
2969 * gtk_toolbar_get_n_items:
2970 * @toolbar: a #GtkToolbar
2972 * Returns the number of items on the toolbar.
2974 * Return value: the number of items on the toolbar
2979 gtk_toolbar_get_n_items (GtkToolbar *toolbar)
2981 GtkToolbarPrivate *priv;
2983 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2985 if (!gtk_toolbar_check_new_api (toolbar))
2988 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2990 return physical_to_logical (toolbar, g_list_length (priv->content));
2994 * gtk_toolbar_get_nth_item:
2995 * @toolbar: a #GtkToolbar
2996 * @n: A position on the toolbar
2998 * Returns the @n<!-- -->'th item on @toolbar, or %NULL if the
2999 * toolbar does not contain an @n<!-- -->'th item.
3001 * Return value: The @n<!-- -->'th #GtkToolItem on @toolbar, or %NULL if there
3002 * isn't an @n<!-- -->'th item.
3007 gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
3010 GtkToolbarPrivate *priv;
3011 ToolbarContent *content;
3014 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
3016 if (!gtk_toolbar_check_new_api (toolbar))
3019 n_items = gtk_toolbar_get_n_items (toolbar);
3021 if (n < 0 || n >= n_items)
3024 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3026 content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
3029 g_assert (!toolbar_content_is_placeholder (content));
3031 return GTK_TOOL_ITEM (toolbar_content_get_widget (content));
3035 * gtk_toolbar_get_icon_size:
3036 * @toolbar: a #GtkToolbar
3038 * Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size().
3040 * Return value: (type int): the current icon size for the icons on
3044 gtk_toolbar_get_icon_size (GtkToolbar *toolbar)
3046 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_ICON_SIZE);
3048 return toolbar->icon_size;
3052 * gtk_toolbar_get_relief_style:
3053 * @toolbar: a #GtkToolbar
3055 * Returns the relief style of buttons on @toolbar. See
3056 * gtk_button_set_relief().
3058 * Return value: The relief style of buttons on @toolbar.
3063 gtk_toolbar_get_relief_style (GtkToolbar *toolbar)
3065 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_RELIEF_NONE);
3067 return get_button_relief (toolbar);
3071 * gtk_toolbar_set_show_arrow:
3072 * @toolbar: a #GtkToolbar
3073 * @show_arrow: Whether to show an overflow menu
3075 * Sets whether to show an overflow menu when
3076 * @toolbar doesn't have room for all items on it. If %TRUE,
3077 * items that there are not room are available through an
3083 gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
3084 gboolean show_arrow)
3086 GtkToolbarPrivate *priv;
3088 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3090 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3091 show_arrow = show_arrow != FALSE;
3093 if (priv->show_arrow != show_arrow)
3095 priv->show_arrow = show_arrow;
3097 if (!priv->show_arrow)
3098 gtk_widget_hide (priv->arrow_button);
3100 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3101 g_object_notify (G_OBJECT (toolbar), "show-arrow");
3106 * gtk_toolbar_get_show_arrow:
3107 * @toolbar: a #GtkToolbar
3109 * Returns whether the toolbar has an overflow menu.
3110 * See gtk_toolbar_set_show_arrow().
3112 * Return value: %TRUE if the toolbar has an overflow menu.
3117 gtk_toolbar_get_show_arrow (GtkToolbar *toolbar)
3119 GtkToolbarPrivate *priv;
3121 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
3123 if (!gtk_toolbar_check_new_api (toolbar))
3126 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3128 return priv->show_arrow;
3132 * gtk_toolbar_get_drop_index:
3133 * @toolbar: a #GtkToolbar
3134 * @x: x coordinate of a point on the toolbar
3135 * @y: y coordinate of a point on the toolbar
3137 * Returns the position corresponding to the indicated point on
3138 * @toolbar. This is useful when dragging items to the toolbar:
3139 * this function returns the position a new item should be
3142 * @x and @y are in @toolbar coordinates.
3144 * Return value: The position corresponding to the point (@x, @y) on the toolbar.
3149 gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
3153 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
3155 if (!gtk_toolbar_check_new_api (toolbar))
3158 return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
3162 gtk_toolbar_finalize (GObject *object)
3165 GtkToolbar *toolbar = GTK_TOOLBAR (object);
3166 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3168 if (toolbar->tooltips)
3169 g_object_unref (toolbar->tooltips);
3171 if (priv->arrow_button)
3172 gtk_widget_unparent (priv->arrow_button);
3174 for (list = priv->content; list != NULL; list = list->next)
3176 ToolbarContent *content = list->data;
3178 toolbar_content_free (content);
3181 g_list_free (priv->content);
3182 g_list_free (toolbar->children);
3184 g_timer_destroy (priv->timer);
3187 gtk_widget_destroy (GTK_WIDGET (priv->menu));
3190 g_source_remove (priv->idle_id);
3192 G_OBJECT_CLASS (gtk_toolbar_parent_class)->finalize (object);
3196 * gtk_toolbar_set_icon_size:
3197 * @toolbar: A #GtkToolbar
3198 * @icon_size: (type int): The #GtkIconSize that stock icons in the
3199 * toolbar shall have.
3201 * This function sets the size of stock icons in the toolbar. You
3202 * can call it both before you add the icons and after they've been
3203 * added. The size you set will override user preferences for the default
3206 * This should only be used for special-purpose toolbars, normal
3207 * application toolbars should respect the user preferences for the
3211 gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
3212 GtkIconSize icon_size)
3214 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3215 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
3217 if (!toolbar->icon_size_set)
3219 toolbar->icon_size_set = TRUE;
3220 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3223 if (toolbar->icon_size == icon_size)
3226 toolbar->icon_size = icon_size;
3227 g_object_notify (G_OBJECT (toolbar), "icon-size");
3229 gtk_toolbar_reconfigured (toolbar);
3231 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3235 * gtk_toolbar_unset_icon_size:
3236 * @toolbar: a #GtkToolbar
3238 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that
3239 * user preferences will be used to determine the icon size.
3242 gtk_toolbar_unset_icon_size (GtkToolbar *toolbar)
3246 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3248 if (toolbar->icon_size_set)
3250 GtkSettings *settings = toolbar_get_settings (toolbar);
3254 g_object_get (settings,
3255 "gtk-toolbar-icon-size", &size,
3259 size = DEFAULT_ICON_SIZE;
3261 if (size != toolbar->icon_size)
3263 gtk_toolbar_set_icon_size (toolbar, size);
3264 g_object_notify (G_OBJECT (toolbar), "icon-size");
3267 toolbar->icon_size_set = FALSE;
3268 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3277 * gtk_toolbar_append_item:
3278 * @toolbar: a #GtkToolbar.
3279 * @text: give your toolbar button a label.
3280 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3281 * @tooltip_private_text: use with #GtkTipsQuery.
3282 * @icon: a #GtkWidget that should be used as the button's icon.
3283 * @callback: the function to be executed when the button is pressed.
3284 * @user_data: a pointer to any data you wish to be passed to the callback.
3286 * Inserts a new item into the toolbar. You must specify the position
3287 * in the toolbar where it will be inserted.
3289 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3290 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3292 * Return value: the new toolbar item as a #GtkWidget.
3294 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3297 gtk_toolbar_append_item (GtkToolbar *toolbar,
3299 const char *tooltip_text,
3300 const char *tooltip_private_text,
3305 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3307 tooltip_text, tooltip_private_text,
3308 icon, callback, user_data,
3309 toolbar->num_children);
3313 * gtk_toolbar_prepend_item:
3314 * @toolbar: a #GtkToolbar.
3315 * @text: give your toolbar button a label.
3316 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3317 * @tooltip_private_text: use with #GtkTipsQuery.
3318 * @icon: a #GtkWidget that should be used as the button's icon.
3319 * @callback: the function to be executed when the button is pressed.
3320 * @user_data: a pointer to any data you wish to be passed to the callback.
3322 * Adds a new button to the beginning (top or left edges) of the given toolbar.
3324 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3325 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3327 * Return value: the new toolbar item as a #GtkWidget.
3329 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3332 gtk_toolbar_prepend_item (GtkToolbar *toolbar,
3334 const char *tooltip_text,
3335 const char *tooltip_private_text,
3340 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3342 tooltip_text, tooltip_private_text,
3343 icon, callback, user_data,
3348 * gtk_toolbar_insert_item:
3349 * @toolbar: a #GtkToolbar.
3350 * @text: give your toolbar button a label.
3351 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3352 * @tooltip_private_text: use with #GtkTipsQuery.
3353 * @icon: a #GtkWidget that should be used as the button's icon.
3354 * @callback: the function to be executed when the button is pressed.
3355 * @user_data: a pointer to any data you wish to be passed to the callback.
3356 * @position: the number of widgets to insert this item after.
3358 * Inserts a new item into the toolbar. You must specify the position in the
3359 * toolbar where it will be inserted.
3361 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3362 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3364 * Return value: the new toolbar item as a #GtkWidget.
3366 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3369 gtk_toolbar_insert_item (GtkToolbar *toolbar,
3371 const char *tooltip_text,
3372 const char *tooltip_private_text,
3378 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3380 tooltip_text, tooltip_private_text,
3381 icon, callback, user_data,
3386 * gtk_toolbar_insert_stock:
3387 * @toolbar: A #GtkToolbar
3388 * @stock_id: The id of the stock item you want to insert
3389 * @tooltip_text: The text in the tooltip of the toolbar button
3390 * @tooltip_private_text: The private text of the tooltip
3391 * @callback: The callback called when the toolbar button is clicked.
3392 * @user_data: user data passed to callback
3393 * @position: The position the button shall be inserted at.
3394 * -1 means at the end.
3396 * Inserts a stock item at the specified position of the toolbar. If
3397 * @stock_id is not a known stock item ID, it's inserted verbatim,
3398 * except that underscores used to mark mnemonics are removed.
3400 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3401 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3403 * Returns: the inserted widget
3405 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3408 gtk_toolbar_insert_stock (GtkToolbar *toolbar,
3409 const gchar *stock_id,
3410 const char *tooltip_text,
3411 const char *tooltip_private_text,
3416 return internal_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3418 tooltip_text, tooltip_private_text,
3419 NULL, callback, user_data,
3424 * gtk_toolbar_append_space:
3425 * @toolbar: a #GtkToolbar.
3427 * Adds a new space to the end of the toolbar.
3429 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3432 gtk_toolbar_append_space (GtkToolbar *toolbar)
3434 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3438 toolbar->num_children);
3442 * gtk_toolbar_prepend_space:
3443 * @toolbar: a #GtkToolbar.
3445 * Adds a new space to the beginning of the toolbar.
3447 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3450 gtk_toolbar_prepend_space (GtkToolbar *toolbar)
3452 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3460 * gtk_toolbar_insert_space:
3461 * @toolbar: a #GtkToolbar
3462 * @position: the number of widgets after which a space should be inserted.
3464 * Inserts a new space in the toolbar at the specified position.
3466 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3469 gtk_toolbar_insert_space (GtkToolbar *toolbar,
3472 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3480 * gtk_toolbar_remove_space:
3481 * @toolbar: a #GtkToolbar.
3482 * @position: the index of the space to remove.
3484 * Removes a space from the specified position.
3486 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3489 gtk_toolbar_remove_space (GtkToolbar *toolbar,
3492 GtkToolbarPrivate *priv;
3493 ToolbarContent *content;
3495 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3497 if (!gtk_toolbar_check_old_api (toolbar))
3500 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3502 content = g_list_nth_data (priv->content, position);
3506 g_warning ("Toolbar position %d doesn't exist", position);
3510 if (!toolbar_content_is_separator (content))
3512 g_warning ("Toolbar position %d is not a space", position);
3516 toolbar_content_remove (content, toolbar);
3517 toolbar_content_free (content);
3521 * gtk_toolbar_append_widget:
3522 * @toolbar: a #GtkToolbar.
3523 * @widget: a #GtkWidget to add to the toolbar.
3524 * @tooltip_text: (allow-none): the element's tooltip.
3525 * @tooltip_private_text: (allow-none): used for context-sensitive help about this toolbar element.
3527 * Adds a widget to the end of the given toolbar.
3529 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3532 gtk_toolbar_append_widget (GtkToolbar *toolbar,
3534 const gchar *tooltip_text,
3535 const gchar *tooltip_private_text)
3537 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3539 tooltip_text, tooltip_private_text,
3541 toolbar->num_children);
3545 * gtk_toolbar_prepend_widget:
3546 * @toolbar: a #GtkToolbar.
3547 * @widget: a #GtkWidget to add to the toolbar.
3548 * @tooltip_text: (allow-none): the element's tooltip.
3549 * @tooltip_private_text: (allow-none): used for context-sensitive help about this toolbar element.
3551 * Adds a widget to the beginning of the given toolbar.
3553 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3556 gtk_toolbar_prepend_widget (GtkToolbar *toolbar,
3558 const gchar *tooltip_text,
3559 const gchar *tooltip_private_text)
3561 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3563 tooltip_text, tooltip_private_text,
3569 * gtk_toolbar_insert_widget:
3570 * @toolbar: a #GtkToolbar.
3571 * @widget: a #GtkWidget to add to the toolbar.
3572 * @tooltip_text: (allow-none): the element's tooltip.
3573 * @tooltip_private_text: (allow-none): used for context-sensitive help about this toolbar element.
3574 * @position: the number of widgets to insert this widget after.
3576 * Inserts a widget in the toolbar at the given position.
3578 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3581 gtk_toolbar_insert_widget (GtkToolbar *toolbar,
3583 const char *tooltip_text,
3584 const char *tooltip_private_text,
3587 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3589 tooltip_text, tooltip_private_text,
3595 * gtk_toolbar_append_element:
3596 * @toolbar: a #GtkToolbar.
3597 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3598 * @widget: (allow-none): a #GtkWidget, or %NULL.
3599 * @text: the element's label.
3600 * @tooltip_text: the element's tooltip.
3601 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3602 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3603 * @callback: the function to be executed when the button is pressed.
3604 * @user_data: any data you wish to pass to the callback.
3606 * Adds a new element to the end of a toolbar.
3608 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3609 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3610 * the radio group for the new element. In all other cases, @widget must
3613 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3614 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3616 * Return value: the new toolbar element as a #GtkWidget.
3618 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3621 gtk_toolbar_append_element (GtkToolbar *toolbar,
3622 GtkToolbarChildType type,
3625 const char *tooltip_text,
3626 const char *tooltip_private_text,
3631 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3632 tooltip_text, tooltip_private_text,
3633 icon, callback, user_data,
3634 toolbar->num_children);
3638 * gtk_toolbar_prepend_element:
3639 * @toolbar: a #GtkToolbar.
3640 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3641 * @widget: (allow-none): a #GtkWidget, or %NULL
3642 * @text: the element's label.
3643 * @tooltip_text: the element's tooltip.
3644 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3645 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3646 * @callback: the function to be executed when the button is pressed.
3647 * @user_data: any data you wish to pass to the callback.
3649 * Adds a new element to the beginning of a toolbar.
3651 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3652 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3653 * the radio group for the new element. In all other cases, @widget must
3656 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3657 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3659 * Return value: the new toolbar element as a #GtkWidget.
3661 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3664 gtk_toolbar_prepend_element (GtkToolbar *toolbar,
3665 GtkToolbarChildType type,
3668 const char *tooltip_text,
3669 const char *tooltip_private_text,
3674 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3675 tooltip_text, tooltip_private_text,
3676 icon, callback, user_data, 0);
3680 * gtk_toolbar_insert_element:
3681 * @toolbar: a #GtkToolbar.
3682 * @type: a value of type #GtkToolbarChildType that determines what @widget
3684 * @widget: (allow-none): a #GtkWidget, or %NULL.
3685 * @text: the element's label.
3686 * @tooltip_text: the element's tooltip.
3687 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3688 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3689 * @callback: the function to be executed when the button is pressed.
3690 * @user_data: any data you wish to pass to the callback.
3691 * @position: the number of widgets to insert this element after.
3693 * Inserts a new element in the toolbar at the given position.
3695 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3696 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3697 * the radio group for the new element. In all other cases, @widget must
3700 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3701 * arguments. Use G_CALLBACK() to cast the function to #GCallback.
3703 * Return value: the new toolbar element as a #GtkWidget.
3705 * Deprecated: 2.4: Use gtk_toolbar_insert() instead.
3708 gtk_toolbar_insert_element (GtkToolbar *toolbar,
3709 GtkToolbarChildType type,
3712 const char *tooltip_text,
3713 const char *tooltip_private_text,
3719 return internal_insert_element (toolbar, type, widget, text,
3720 tooltip_text, tooltip_private_text,
3721 icon, callback, user_data, position, FALSE);
3725 set_child_packing_and_visibility(GtkToolbar *toolbar,
3726 GtkToolbarChild *child)
3731 box = gtk_bin_get_child (GTK_BIN (child->widget));
3733 g_return_if_fail (GTK_IS_BOX (box));
3737 expand = (toolbar->style != GTK_TOOLBAR_BOTH);
3739 gtk_box_set_child_packing (GTK_BOX (box), child->label,
3740 expand, expand, 0, GTK_PACK_END);
3742 if (toolbar->style != GTK_TOOLBAR_ICONS)
3743 gtk_widget_show (child->label);
3745 gtk_widget_hide (child->label);
3750 expand = (toolbar->style != GTK_TOOLBAR_BOTH_HORIZ);
3752 gtk_box_set_child_packing (GTK_BOX (box), child->icon,
3753 expand, expand, 0, GTK_PACK_END);
3755 if (toolbar->style != GTK_TOOLBAR_TEXT)
3756 gtk_widget_show (child->icon);
3758 gtk_widget_hide (child->icon);
3763 internal_insert_element (GtkToolbar *toolbar,
3764 GtkToolbarChildType type,
3767 const char *tooltip_text,
3768 const char *tooltip_private_text,
3776 ToolbarContent *content;
3777 char *free_me = NULL;
3779 GtkWidget *child_widget;
3780 GtkWidget *child_label;
3781 GtkWidget *child_icon;
3783 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
3784 if (type == GTK_TOOLBAR_CHILD_WIDGET)
3785 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3786 else if (type != GTK_TOOLBAR_CHILD_RADIOBUTTON)
3787 g_return_val_if_fail (widget == NULL, NULL);
3788 if (GTK_IS_TOOL_ITEM (widget))
3789 g_warning (MIXED_API_WARNING);
3791 if (!gtk_toolbar_check_old_api (toolbar))
3794 child_widget = NULL;
3800 case GTK_TOOLBAR_CHILD_SPACE:
3803 case GTK_TOOLBAR_CHILD_WIDGET:
3804 child_widget = widget;
3807 case GTK_TOOLBAR_CHILD_BUTTON:
3808 case GTK_TOOLBAR_CHILD_TOGGLEBUTTON:
3809 case GTK_TOOLBAR_CHILD_RADIOBUTTON:
3810 if (type == GTK_TOOLBAR_CHILD_BUTTON)
3812 child_widget = gtk_button_new ();
3814 else if (type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
3816 child_widget = gtk_toggle_button_new ();
3817 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3819 else /* type == GTK_TOOLBAR_CHILD_RADIOBUTTON */
3821 GSList *group = NULL;
3824 group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
3826 child_widget = gtk_radio_button_new (group);
3827 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3830 gtk_button_set_relief (GTK_BUTTON (child_widget), get_button_relief (toolbar));
3831 gtk_button_set_focus_on_click (GTK_BUTTON (child_widget), FALSE);
3835 g_signal_connect (child_widget, "clicked",
3836 callback, user_data);
3839 if (toolbar->style == GTK_TOOLBAR_BOTH_HORIZ)
3840 box = gtk_hbox_new (FALSE, 0);
3842 box = gtk_vbox_new (FALSE, 0);
3844 gtk_container_add (GTK_CONTAINER (child_widget), box);
3845 gtk_widget_show (box);
3847 if (text && use_stock)
3849 GtkStockItem stock_item;
3850 if (gtk_stock_lookup (text, &stock_item))
3853 icon = gtk_image_new_from_stock (text, toolbar->icon_size);
3855 text = free_me = _gtk_toolbar_elide_underscores (stock_item.label);
3861 child_label = gtk_label_new (text);
3863 gtk_container_add (GTK_CONTAINER (box), child_label);
3868 child_icon = GTK_WIDGET (icon);
3869 gtk_container_add (GTK_CONTAINER (box), child_icon);
3872 gtk_widget_show (child_widget);
3876 g_assert_not_reached ();
3880 if ((type != GTK_TOOLBAR_CHILD_SPACE) && tooltip_text)
3882 gtk_tooltips_set_tip (toolbar->tooltips, child_widget,
3883 tooltip_text, tooltip_private_text);
3886 content = toolbar_content_new_compatibility (toolbar, type, child_widget,
3887 child_icon, child_label, position);
3891 return child_widget;
3895 * ToolbarContent methods
3903 struct _ToolbarContent
3913 GtkAllocation start_allocation;
3914 GtkAllocation goal_allocation;
3915 guint is_placeholder : 1;
3916 guint disappearing : 1;
3922 GtkToolbarChild child;
3923 GtkAllocation space_allocation;
3924 guint space_visible : 1;
3929 static ToolbarContent *
3930 toolbar_content_new_tool_item (GtkToolbar *toolbar,
3932 gboolean is_placeholder,
3935 ToolbarContent *content;
3936 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3938 content = g_slice_new0 (ToolbarContent);
3940 content->type = TOOL_ITEM;
3941 content->state = NOT_ALLOCATED;
3942 content->u.tool_item.item = item;
3943 content->u.tool_item.is_placeholder = is_placeholder;
3945 gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
3947 priv->content = g_list_insert (priv->content, content, pos);
3949 if (!is_placeholder)
3951 toolbar->num_children++;
3953 gtk_toolbar_stop_sliding (toolbar);
3956 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3957 priv->need_rebuild = TRUE;
3962 static ToolbarContent *
3963 toolbar_content_new_compatibility (GtkToolbar *toolbar,
3964 GtkToolbarChildType type,
3970 ToolbarContent *content;
3971 GtkToolbarChild *child;
3972 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3974 content = g_slice_new0 (ToolbarContent);
3976 child = &(content->u.compatibility.child);
3978 content->type = COMPATIBILITY;
3980 child->widget = widget;
3982 child->label = label;
3984 if (type != GTK_TOOLBAR_CHILD_SPACE)
3986 gtk_widget_set_parent (child->widget, GTK_WIDGET (toolbar));
3990 content->u.compatibility.space_visible = TRUE;
3991 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3994 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
3995 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
3996 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
3998 set_child_packing_and_visibility (toolbar, child);
4001 priv->content = g_list_insert (priv->content, content, pos);
4002 toolbar->children = g_list_insert (toolbar->children, child, pos);
4003 priv->need_rebuild = TRUE;
4005 toolbar->num_children++;
4011 toolbar_content_remove (ToolbarContent *content,
4012 GtkToolbar *toolbar)
4014 GtkToolbarChild *child;
4015 GtkToolbarPrivate *priv;
4017 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4019 switch (content->type)
4022 gtk_widget_unparent (GTK_WIDGET (content->u.tool_item.item));
4026 child = &(content->u.compatibility.child);
4028 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4030 g_object_ref (child->widget);
4031 gtk_widget_unparent (child->widget);
4032 gtk_widget_destroy (child->widget);
4033 g_object_unref (child->widget);
4036 toolbar->children = g_list_remove (toolbar->children, child);
4040 priv->content = g_list_remove (priv->content, content);
4042 if (!toolbar_content_is_placeholder (content))
4043 toolbar->num_children--;
4045 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
4046 priv->need_rebuild = TRUE;
4050 toolbar_content_free (ToolbarContent *content)
4052 g_slice_free (ToolbarContent, content);
4056 calculate_max_homogeneous_pixels (GtkWidget *widget)
4058 PangoContext *context;
4059 PangoFontMetrics *metrics;
4062 context = gtk_widget_get_pango_context (widget);
4063 metrics = pango_context_get_metrics (context,
4064 widget->style->font_desc,
4065 pango_context_get_language (context));
4066 char_width = pango_font_metrics_get_approximate_char_width (metrics);
4067 pango_font_metrics_unref (metrics);
4069 return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
4073 toolbar_content_expose (ToolbarContent *content,
4074 GtkContainer *container,
4075 GdkEventExpose *expose)
4077 GtkToolbar *toolbar = GTK_TOOLBAR (container);
4078 GtkToolbarChild *child;
4079 GtkWidget *widget = NULL; /* quiet gcc */
4081 switch (content->type)
4084 if (!content->u.tool_item.is_placeholder)
4085 widget = GTK_WIDGET (content->u.tool_item.item);
4089 child = &(content->u.compatibility.child);
4091 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
4093 if (content->u.compatibility.space_visible &&
4094 get_space_style (toolbar) == GTK_TOOLBAR_SPACE_LINE)
4095 _gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), toolbar,
4097 &content->u.compatibility.space_allocation);
4101 widget = child->widget;
4106 gtk_container_propagate_expose (container, widget, expose);
4110 toolbar_content_visible (ToolbarContent *content,
4111 GtkToolbar *toolbar)
4115 switch (content->type)
4118 item = content->u.tool_item.item;
4120 if (!gtk_widget_get_visible (GTK_WIDGET (item)))
4123 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL &&
4124 gtk_tool_item_get_visible_horizontal (item))
4127 if ((toolbar->orientation == GTK_ORIENTATION_VERTICAL &&
4128 gtk_tool_item_get_visible_vertical (item)))
4135 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4136 return gtk_widget_get_visible (content->u.compatibility.child.widget);
4142 g_assert_not_reached ();
4147 toolbar_content_size_request (ToolbarContent *content,
4148 GtkToolbar *toolbar,
4149 GtkRequisition *requisition)
4153 switch (content->type)
4156 gtk_widget_size_request (GTK_WIDGET (content->u.tool_item.item),
4158 if (content->u.tool_item.is_placeholder &&
4159 content->u.tool_item.disappearing)
4161 requisition->width = 0;
4162 requisition->height = 0;
4167 space_size = get_space_size (toolbar);
4169 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4171 gtk_widget_size_request (content->u.compatibility.child.widget,
4176 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
4178 requisition->width = space_size;
4179 requisition->height = 0;
4183 requisition->height = space_size;
4184 requisition->width = 0;
4193 toolbar_content_is_homogeneous (ToolbarContent *content,
4194 GtkToolbar *toolbar)
4196 gboolean result = FALSE; /* quiet gcc */
4197 GtkRequisition requisition;
4198 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4200 if (priv->max_homogeneous_pixels < 0)
4202 priv->max_homogeneous_pixels =
4203 calculate_max_homogeneous_pixels (GTK_WIDGET (toolbar));
4206 toolbar_content_size_request (content, toolbar, &requisition);
4208 if (requisition.width > priv->max_homogeneous_pixels)
4211 switch (content->type)
4214 result = gtk_tool_item_get_homogeneous (content->u.tool_item.item) &&
4215 !GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4217 if (gtk_tool_item_get_is_important (content->u.tool_item.item) &&
4218 toolbar->style == GTK_TOOLBAR_BOTH_HORIZ &&
4219 toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
4226 if (content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_BUTTON ||
4227 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4228 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4243 toolbar_content_is_placeholder (ToolbarContent *content)
4245 if (content->type == TOOL_ITEM && content->u.tool_item.is_placeholder)
4252 toolbar_content_disappearing (ToolbarContent *content)
4254 if (content->type == TOOL_ITEM && content->u.tool_item.disappearing)
4261 toolbar_content_get_state (ToolbarContent *content)
4263 return content->state;
4267 toolbar_content_child_visible (ToolbarContent *content)
4269 switch (content->type)
4272 return GTK_WIDGET_CHILD_VISIBLE (content->u.tool_item.item);
4276 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4278 return GTK_WIDGET_CHILD_VISIBLE (content->u.compatibility.child.widget);
4282 return content->u.compatibility.space_visible;
4287 return FALSE; /* quiet gcc */
4291 toolbar_content_get_goal_allocation (ToolbarContent *content,
4292 GtkAllocation *allocation)
4294 switch (content->type)
4297 *allocation = content->u.tool_item.goal_allocation;
4301 /* Goal allocations are only relevant when we are
4302 * using the new API, so we should never get here
4304 g_assert_not_reached ();
4310 toolbar_content_get_allocation (ToolbarContent *content,
4311 GtkAllocation *allocation)
4313 GtkToolbarChild *child;
4315 switch (content->type)
4318 *allocation = GTK_WIDGET (content->u.tool_item.item)->allocation;
4322 child = &(content->u.compatibility.child);
4324 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
4325 *allocation = content->u.compatibility.space_allocation;
4327 *allocation = child->widget->allocation;
4333 toolbar_content_set_start_allocation (ToolbarContent *content,
4334 GtkAllocation *allocation)
4336 switch (content->type)
4339 content->u.tool_item.start_allocation = *allocation;
4343 /* start_allocation is only relevant when using the new API */
4344 g_assert_not_reached ();
4350 toolbar_content_get_expand (ToolbarContent *content)
4352 if (content->type == TOOL_ITEM &&
4353 gtk_tool_item_get_expand (content->u.tool_item.item) &&
4354 !content->u.tool_item.disappearing)
4363 toolbar_content_set_goal_allocation (ToolbarContent *content,
4364 GtkAllocation *allocation)
4366 switch (content->type)
4369 content->u.tool_item.goal_allocation = *allocation;
4373 /* Only relevant when using new API */
4374 g_assert_not_reached ();
4380 toolbar_content_set_child_visible (ToolbarContent *content,
4381 GtkToolbar *toolbar,
4384 GtkToolbarChild *child;
4386 switch (content->type)
4389 gtk_widget_set_child_visible (GTK_WIDGET (content->u.tool_item.item),
4394 child = &(content->u.compatibility.child);
4396 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4398 gtk_widget_set_child_visible (child->widget, visible);
4402 if (content->u.compatibility.space_visible != visible)
4404 content->u.compatibility.space_visible = visible;
4405 gtk_widget_queue_draw (GTK_WIDGET (toolbar));
4413 toolbar_content_get_start_allocation (ToolbarContent *content,
4414 GtkAllocation *start_allocation)
4416 switch (content->type)
4419 *start_allocation = content->u.tool_item.start_allocation;
4423 /* Only relevant for new API */
4424 g_assert_not_reached ();
4430 toolbar_content_size_allocate (ToolbarContent *content,
4431 GtkAllocation *allocation)
4433 switch (content->type)
4436 gtk_widget_size_allocate (GTK_WIDGET (content->u.tool_item.item),
4441 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4443 gtk_widget_size_allocate (content->u.compatibility.child.widget,
4448 content->u.compatibility.space_allocation = *allocation;
4455 toolbar_content_set_state (ToolbarContent *content,
4458 content->state = state;
4462 toolbar_content_get_widget (ToolbarContent *content)
4464 GtkToolbarChild *child;
4466 switch (content->type)
4469 return GTK_WIDGET (content->u.tool_item.item);
4473 child = &(content->u.compatibility.child);
4474 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4475 return child->widget;
4485 toolbar_content_set_disappearing (ToolbarContent *content,
4486 gboolean disappearing)
4488 switch (content->type)
4491 content->u.tool_item.disappearing = disappearing;
4495 /* Only relevant for new API */
4496 g_assert_not_reached ();
4502 toolbar_content_set_size_request (ToolbarContent *content,
4506 switch (content->type)
4509 gtk_widget_set_size_request (GTK_WIDGET (content->u.tool_item.item),
4514 /* Setting size requests only happens with sliding,
4515 * so not relevant here
4517 g_assert_not_reached ();
4523 toolbar_child_reconfigure (GtkToolbar *toolbar,
4524 GtkToolbarChild *child)
4528 GtkToolbarStyle style;
4529 GtkIconSize icon_size;
4530 GtkReliefStyle relief;
4533 style = gtk_toolbar_get_style (toolbar);
4534 icon_size = gtk_toolbar_get_icon_size (toolbar);
4535 relief = gtk_toolbar_get_relief_style (toolbar);
4538 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4539 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4540 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4542 box = gtk_bin_get_child (GTK_BIN (child->widget));
4544 if (style == GTK_TOOLBAR_BOTH && GTK_IS_HBOX (box))
4548 vbox = gtk_vbox_new (FALSE, 0);
4551 gtk_widget_reparent (child->label, vbox);
4553 gtk_widget_reparent (child->icon, vbox);
4555 gtk_widget_destroy (box);
4556 gtk_container_add (GTK_CONTAINER (child->widget), vbox);
4558 gtk_widget_show (vbox);
4560 else if (style == GTK_TOOLBAR_BOTH_HORIZ && GTK_IS_VBOX (box))
4564 hbox = gtk_hbox_new (FALSE, 0);
4567 gtk_widget_reparent (child->label, hbox);
4569 gtk_widget_reparent (child->icon, hbox);
4571 gtk_widget_destroy (box);
4572 gtk_container_add (GTK_CONTAINER (child->widget), hbox);
4574 gtk_widget_show (hbox);
4577 set_child_packing_and_visibility (toolbar, child);
4582 if ((child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4583 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4584 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON) &&
4585 GTK_IS_IMAGE (child->icon))
4587 image = GTK_IMAGE (child->icon);
4588 if (gtk_image_get_storage_type (image) == GTK_IMAGE_STOCK)
4590 gtk_image_get_stock (image, &stock_id, NULL);
4591 stock_id = g_strdup (stock_id);
4592 gtk_image_set_from_stock (image,
4600 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4601 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4602 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4604 gtk_button_set_relief (GTK_BUTTON (child->widget), relief);
4609 toolbar_content_toolbar_reconfigured (ToolbarContent *content,
4610 GtkToolbar *toolbar)
4612 switch (content->type)
4615 gtk_tool_item_toolbar_reconfigured (content->u.tool_item.item);
4619 toolbar_child_reconfigure (toolbar, &(content->u.compatibility.child));
4625 toolbar_content_retrieve_menu_item (ToolbarContent *content)
4627 if (content->type == TOOL_ITEM)
4628 return gtk_tool_item_retrieve_proxy_menu_item (content->u.tool_item.item);
4630 /* FIXME - we might actually be able to do something meaningful here */
4635 toolbar_content_has_proxy_menu_item (ToolbarContent *content)
4637 if (content->type == TOOL_ITEM)
4639 GtkWidget *menu_item;
4641 if (content->u.tool_item.has_menu == YES)
4643 else if (content->u.tool_item.has_menu == NO)
4646 menu_item = toolbar_content_retrieve_menu_item (content);
4648 content->u.tool_item.has_menu = menu_item? YES : NO;
4650 return menu_item != NULL;
4659 toolbar_content_set_unknown_menu_status (ToolbarContent *content)
4661 if (content->type == TOOL_ITEM)
4662 content->u.tool_item.has_menu = UNKNOWN;
4666 toolbar_content_is_separator (ToolbarContent *content)
4668 GtkToolbarChild *child;
4670 switch (content->type)
4673 return GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4677 child = &(content->u.compatibility.child);
4678 return (child->type == GTK_TOOLBAR_CHILD_SPACE);
4686 toolbar_content_set_expand (ToolbarContent *content,
4689 if (content->type == TOOL_ITEM)
4690 gtk_tool_item_set_expand (content->u.tool_item.item, expand);
4694 ignore_show_and_hide_all (ToolbarContent *content)
4696 if (content->type == COMPATIBILITY)
4698 GtkToolbarChildType type = content->u.compatibility.child.type;
4700 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
4701 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4702 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
4712 toolbar_content_show_all (ToolbarContent *content)
4716 if (ignore_show_and_hide_all (content))
4719 widget = toolbar_content_get_widget (content);
4721 gtk_widget_show_all (widget);
4725 toolbar_content_hide_all (ToolbarContent *content)
4729 if (ignore_show_and_hide_all (content))
4732 widget = toolbar_content_get_widget (content);
4734 gtk_widget_hide_all (widget);
4741 get_space_size (GtkToolbar *toolbar)
4743 gint space_size = DEFAULT_SPACE_SIZE;
4747 gtk_widget_style_get (GTK_WIDGET (toolbar),
4748 "space-size", &space_size,
4755 static GtkToolbarSpaceStyle
4756 get_space_style (GtkToolbar *toolbar)
4758 GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
4762 gtk_widget_style_get (GTK_WIDGET (toolbar),
4763 "space-style", &space_style,
4770 static GtkReliefStyle
4771 get_button_relief (GtkToolbar *toolbar)
4773 GtkReliefStyle button_relief = GTK_RELIEF_NORMAL;
4775 gtk_widget_ensure_style (GTK_WIDGET (toolbar));
4777 gtk_widget_style_get (GTK_WIDGET (toolbar),
4778 "button-relief", &button_relief,
4781 return button_relief;
4785 get_internal_padding (GtkToolbar *toolbar)
4789 gtk_widget_style_get (GTK_WIDGET (toolbar),
4790 "internal-padding", &ipadding,
4797 get_max_child_expand (GtkToolbar *toolbar)
4799 gint mexpand = G_MAXINT;
4801 gtk_widget_style_get (GTK_WIDGET (toolbar),
4802 "max-child-expand", &mexpand,
4807 static GtkShadowType
4808 get_shadow_type (GtkToolbar *toolbar)
4810 GtkShadowType shadow_type;
4812 gtk_widget_style_get (GTK_WIDGET (toolbar),
4813 "shadow-type", &shadow_type,
4823 gtk_toolbar_check_old_api (GtkToolbar *toolbar)
4825 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4827 if (priv->api_mode == NEW_API)
4829 g_warning (MIXED_API_WARNING);
4833 priv->api_mode = OLD_API;
4838 gtk_toolbar_check_new_api (GtkToolbar *toolbar)
4840 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4842 if (priv->api_mode == OLD_API)
4844 g_warning (MIXED_API_WARNING);
4848 priv->api_mode = NEW_API;
4852 /* GTK+ internal methods */
4855 _gtk_toolbar_get_default_space_size (void)
4857 return DEFAULT_SPACE_SIZE;
4861 _gtk_toolbar_paint_space_line (GtkWidget *widget,
4862 GtkToolbar *toolbar,
4863 const GdkRectangle *area,
4864 const GtkAllocation *allocation)
4866 const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
4867 const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
4869 GtkOrientation orientation;
4871 g_return_if_fail (GTK_IS_WIDGET (widget));
4873 orientation = toolbar? toolbar->orientation : GTK_ORIENTATION_HORIZONTAL;
4875 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4877 gboolean wide_separators;
4878 gint separator_width;
4880 gtk_widget_style_get (widget,
4881 "wide-separators", &wide_separators,
4882 "separator-width", &separator_width,
4885 if (wide_separators)
4886 gtk_paint_box (widget->style, widget->window,
4887 GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
4888 area, widget, "vseparator",
4889 allocation->x + (allocation->width - separator_width) / 2,
4890 allocation->y + allocation->height * start_fraction,
4892 allocation->height * (end_fraction - start_fraction));
4894 gtk_paint_vline (widget->style, widget->window,
4895 GTK_WIDGET_STATE (widget), area, widget,
4897 allocation->y + allocation->height * start_fraction,
4898 allocation->y + allocation->height * end_fraction,
4899 allocation->x + (allocation->width - widget->style->xthickness) / 2);
4903 gboolean wide_separators;
4904 gint separator_height;
4906 gtk_widget_style_get (widget,
4907 "wide-separators", &wide_separators,
4908 "separator-height", &separator_height,
4911 if (wide_separators)
4912 gtk_paint_box (widget->style, widget->window,
4913 GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
4914 area, widget, "hseparator",
4915 allocation->x + allocation->width * start_fraction,
4916 allocation->y + (allocation->height - separator_height) / 2,
4917 allocation->width * (end_fraction - start_fraction),
4920 gtk_paint_hline (widget->style, widget->window,
4921 GTK_WIDGET_STATE (widget), area, widget,
4923 allocation->x + allocation->width * start_fraction,
4924 allocation->x + allocation->width * end_fraction,
4925 allocation->y + (allocation->height - widget->style->ythickness) / 2);
4930 _gtk_toolbar_elide_underscores (const gchar *original)
4933 const gchar *p, *end;
4935 gboolean last_underscore;
4940 len = strlen (original);
4941 q = result = g_malloc (len + 1);
4942 last_underscore = FALSE;
4944 end = original + len;
4945 for (p = original; p < end; p++)
4947 if (!last_underscore && *p == '_')
4948 last_underscore = TRUE;
4951 last_underscore = FALSE;
4952 if (original + 2 <= p && p + 1 <= end &&
4953 p[-2] == '(' && p[-1] == '_' && p[0] != '_' && p[1] == ')')
4964 if (last_underscore)
4973 toolbar_get_icon_size (GtkToolShell *shell)
4975 return GTK_TOOLBAR (shell)->icon_size;
4978 static GtkOrientation
4979 toolbar_get_orientation (GtkToolShell *shell)
4981 return GTK_TOOLBAR (shell)->orientation;
4984 static GtkToolbarStyle
4985 toolbar_get_style (GtkToolShell *shell)
4987 return GTK_TOOLBAR (shell)->style;
4990 static GtkReliefStyle
4991 toolbar_get_relief_style (GtkToolShell *shell)
4993 return get_button_relief (GTK_TOOLBAR (shell));
4997 toolbar_rebuild_menu (GtkToolShell *shell)
4999 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (shell);
5002 priv->need_rebuild = TRUE;
5004 for (list = priv->content; list != NULL; list = list->next)
5006 ToolbarContent *content = list->data;
5008 toolbar_content_set_unknown_menu_status (content);
5011 gtk_widget_queue_resize (GTK_WIDGET (shell));
5014 #define __GTK_TOOLBAR_C__
5015 #include "gtkaliasdef.c"