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/.
35 #include "gtktoolbar.h"
40 #include <gdk/gdkkeysyms.h>
43 #include "gtkbindings.h"
48 #include "gtkmarshalers.h"
50 #include "gtkorientable.h"
51 #include "gtkradiobutton.h"
52 #include "gtkradiotoolbutton.h"
53 #include "gtkseparatormenuitem.h"
54 #include "gtkseparatortoolitem.h"
56 #include "gtktoolshell.h"
58 #include "gtkprivate.h"
64 * @Short_description: Create bars of buttons and other widgets
66 * @See_also: #GtkToolItem
68 * A toolbar is created with a call to gtk_toolbar_new().
70 * A toolbar can contain instances of a subclass of #GtkToolItem. To add
71 * a #GtkToolItem to the a toolbar, use gtk_toolbar_insert(). To remove
72 * an item from the toolbar use gtk_container_remove(). To add a button
73 * to the toolbar, add an instance of #GtkToolButton.
75 * Toolbar items can be visually grouped by adding instances of
76 * #GtkSeparatorToolItem to the toolbar. If the GtkToolbar child property
77 * "expand" is #TRUE and the property #GtkSeparatorToolItem:draw is set to
78 * #FALSE, the effect is to force all following items to the end of the toolbar.
80 * Creating a context menu for the toolbar can be done by connecting to
81 * the #GtkToolbar::popup-context-menu signal.
85 typedef struct _ToolbarContent ToolbarContent;
87 #define DEFAULT_IPADDING 0
89 #define DEFAULT_SPACE_SIZE 12
90 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
91 #define SPACE_LINE_DIVISION 10.0
92 #define SPACE_LINE_START 2.0
93 #define SPACE_LINE_END 8.0
95 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
96 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
97 #define DEFAULT_ANIMATION_STATE TRUE
99 #define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
100 * in the homogeneous game. In units of
101 * pango_font_get_estimated_char_width().
103 #define SLIDE_SPEED 600.0 /* How fast the items slide, in pixels per second */
104 #define ACCEL_THRESHOLD 0.18 /* After how much time in seconds will items start speeding up */
107 struct _GtkToolbarPrivate
109 GtkIconSize icon_size;
111 GtkOrientation orientation;
112 GtkSettings *settings;
113 GtkToolbarStyle style;
114 GtkToolItem *highlight_tool_item;
116 GtkWidget *arrow_button;
118 GdkWindow *event_window;
126 gint button_maxw; /* maximum width of homogeneous children */
127 gint button_maxh; /* maximum height of homogeneous children */
128 gint max_homogeneous_pixels;
131 gulong settings_connection;
134 guint icon_size_set : 1;
135 guint is_sliding : 1;
136 guint need_rebuild : 1; /* whether the overflow menu should be regenerated */
138 guint show_arrow : 1;
153 /* Child properties */
157 CHILD_PROP_HOMOGENEOUS
177 static void gtk_toolbar_set_property (GObject *object,
181 static void gtk_toolbar_get_property (GObject *object,
185 static gint gtk_toolbar_draw (GtkWidget *widget,
187 static void gtk_toolbar_realize (GtkWidget *widget);
188 static void gtk_toolbar_unrealize (GtkWidget *widget);
189 static void gtk_toolbar_size_request (GtkWidget *widget,
190 GtkRequisition *requisition);
191 static void gtk_toolbar_size_allocate (GtkWidget *widget,
192 GtkAllocation *allocation);
193 static void gtk_toolbar_style_set (GtkWidget *widget,
194 GtkStyle *prev_style);
195 static gboolean gtk_toolbar_focus (GtkWidget *widget,
196 GtkDirectionType dir);
197 static void gtk_toolbar_move_focus (GtkWidget *widget,
198 GtkDirectionType dir);
199 static void gtk_toolbar_screen_changed (GtkWidget *widget,
200 GdkScreen *previous_screen);
201 static void gtk_toolbar_map (GtkWidget *widget);
202 static void gtk_toolbar_unmap (GtkWidget *widget);
203 static void gtk_toolbar_set_child_property (GtkContainer *container,
208 static void gtk_toolbar_get_child_property (GtkContainer *container,
213 static void gtk_toolbar_finalize (GObject *object);
214 static void gtk_toolbar_show_all (GtkWidget *widget);
215 static void gtk_toolbar_add (GtkContainer *container,
217 static void gtk_toolbar_remove (GtkContainer *container,
219 static void gtk_toolbar_forall (GtkContainer *container,
220 gboolean include_internals,
221 GtkCallback callback,
222 gpointer callback_data);
223 static GType gtk_toolbar_child_type (GtkContainer *container);
224 static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
225 GtkOrientation orientation);
226 static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
227 GtkToolbarStyle style);
228 static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
229 gboolean focus_home);
230 static gboolean gtk_toolbar_button_press (GtkWidget *toolbar,
231 GdkEventButton *event);
232 static gboolean gtk_toolbar_arrow_button_press (GtkWidget *button,
233 GdkEventButton *event,
234 GtkToolbar *toolbar);
235 static void gtk_toolbar_arrow_button_clicked (GtkWidget *button,
236 GtkToolbar *toolbar);
237 static void gtk_toolbar_update_button_relief (GtkToolbar *toolbar);
238 static gboolean gtk_toolbar_popup_menu (GtkWidget *toolbar);
239 static void gtk_toolbar_reconfigured (GtkToolbar *toolbar);
241 static GtkReliefStyle get_button_relief (GtkToolbar *toolbar);
242 static gint get_internal_padding (GtkToolbar *toolbar);
243 static gint get_max_child_expand (GtkToolbar *toolbar);
244 static GtkShadowType get_shadow_type (GtkToolbar *toolbar);
246 /* methods on ToolbarContent 'class' */
247 static ToolbarContent *toolbar_content_new_tool_item (GtkToolbar *toolbar,
249 gboolean is_placeholder,
251 static void toolbar_content_remove (ToolbarContent *content,
252 GtkToolbar *toolbar);
253 static void toolbar_content_free (ToolbarContent *content);
254 static void toolbar_content_draw (ToolbarContent *content,
255 GtkContainer *container,
257 static gboolean toolbar_content_visible (ToolbarContent *content,
258 GtkToolbar *toolbar);
259 static void toolbar_content_size_request (ToolbarContent *content,
261 GtkRequisition *requisition);
262 static gboolean toolbar_content_is_homogeneous (ToolbarContent *content,
263 GtkToolbar *toolbar);
264 static gboolean toolbar_content_is_placeholder (ToolbarContent *content);
265 static gboolean toolbar_content_disappearing (ToolbarContent *content);
266 static ItemState toolbar_content_get_state (ToolbarContent *content);
267 static gboolean toolbar_content_child_visible (ToolbarContent *content);
268 static void toolbar_content_get_goal_allocation (ToolbarContent *content,
269 GtkAllocation *allocation);
270 static void toolbar_content_get_allocation (ToolbarContent *content,
271 GtkAllocation *allocation);
272 static void toolbar_content_set_start_allocation (ToolbarContent *content,
273 GtkAllocation *new_start_allocation);
274 static void toolbar_content_get_start_allocation (ToolbarContent *content,
275 GtkAllocation *start_allocation);
276 static gboolean toolbar_content_get_expand (ToolbarContent *content);
277 static void toolbar_content_set_goal_allocation (ToolbarContent *content,
278 GtkAllocation *allocation);
279 static void toolbar_content_set_child_visible (ToolbarContent *content,
282 static void toolbar_content_size_allocate (ToolbarContent *content,
283 GtkAllocation *allocation);
284 static void toolbar_content_set_state (ToolbarContent *content,
285 ItemState new_state);
286 static GtkWidget * toolbar_content_get_widget (ToolbarContent *content);
287 static void toolbar_content_set_disappearing (ToolbarContent *content,
288 gboolean disappearing);
289 static void toolbar_content_set_size_request (ToolbarContent *content,
292 static void toolbar_content_toolbar_reconfigured (ToolbarContent *content,
293 GtkToolbar *toolbar);
294 static GtkWidget * toolbar_content_retrieve_menu_item (ToolbarContent *content);
295 static gboolean toolbar_content_has_proxy_menu_item (ToolbarContent *content);
296 static gboolean toolbar_content_is_separator (ToolbarContent *content);
297 static void toolbar_content_show_all (ToolbarContent *content);
298 static void toolbar_content_set_expand (ToolbarContent *content,
301 static void toolbar_tool_shell_iface_init (GtkToolShellIface *iface);
302 static GtkIconSize toolbar_get_icon_size (GtkToolShell *shell);
303 static GtkOrientation toolbar_get_orientation (GtkToolShell *shell);
304 static GtkToolbarStyle toolbar_get_style (GtkToolShell *shell);
305 static GtkReliefStyle toolbar_get_relief_style (GtkToolShell *shell);
306 static void toolbar_rebuild_menu (GtkToolShell *shell);
309 G_DEFINE_TYPE_WITH_CODE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER,
310 G_IMPLEMENT_INTERFACE (GTK_TYPE_TOOL_SHELL,
311 toolbar_tool_shell_iface_init)
312 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
315 static guint toolbar_signals[LAST_SIGNAL] = { 0 };
319 add_arrow_bindings (GtkBindingSet *binding_set,
321 GtkDirectionType dir)
323 guint keypad_keysym = keysym - GDK_KEY_Left + GDK_KEY_KP_Left;
325 gtk_binding_entry_add_signal (binding_set, keysym, 0,
327 GTK_TYPE_DIRECTION_TYPE, dir);
328 gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
330 GTK_TYPE_DIRECTION_TYPE, dir);
334 add_ctrl_tab_bindings (GtkBindingSet *binding_set,
335 GdkModifierType modifiers,
336 GtkDirectionType direction)
338 gtk_binding_entry_add_signal (binding_set,
339 GDK_KEY_Tab, GDK_CONTROL_MASK | modifiers,
341 GTK_TYPE_DIRECTION_TYPE, direction);
342 gtk_binding_entry_add_signal (binding_set,
343 GDK_KEY_KP_Tab, GDK_CONTROL_MASK | modifiers,
345 GTK_TYPE_DIRECTION_TYPE, direction);
349 gtk_toolbar_class_init (GtkToolbarClass *klass)
351 GObjectClass *gobject_class;
352 GtkWidgetClass *widget_class;
353 GtkContainerClass *container_class;
354 GtkBindingSet *binding_set;
356 gobject_class = (GObjectClass *)klass;
357 widget_class = (GtkWidgetClass *)klass;
358 container_class = (GtkContainerClass *)klass;
360 gobject_class->set_property = gtk_toolbar_set_property;
361 gobject_class->get_property = gtk_toolbar_get_property;
362 gobject_class->finalize = gtk_toolbar_finalize;
364 widget_class->button_press_event = gtk_toolbar_button_press;
365 widget_class->draw = gtk_toolbar_draw;
366 widget_class->size_request = gtk_toolbar_size_request;
367 widget_class->size_allocate = gtk_toolbar_size_allocate;
368 widget_class->style_set = gtk_toolbar_style_set;
369 widget_class->focus = gtk_toolbar_focus;
371 /* need to override the base class function via override_class_handler,
372 * because the signal slot is not available in GtkWidgetClass
374 g_signal_override_class_handler ("move-focus",
376 G_CALLBACK (gtk_toolbar_move_focus));
378 widget_class->screen_changed = gtk_toolbar_screen_changed;
379 widget_class->realize = gtk_toolbar_realize;
380 widget_class->unrealize = gtk_toolbar_unrealize;
381 widget_class->map = gtk_toolbar_map;
382 widget_class->unmap = gtk_toolbar_unmap;
383 widget_class->popup_menu = gtk_toolbar_popup_menu;
384 widget_class->show_all = gtk_toolbar_show_all;
386 container_class->add = gtk_toolbar_add;
387 container_class->remove = gtk_toolbar_remove;
388 container_class->forall = gtk_toolbar_forall;
389 container_class->child_type = gtk_toolbar_child_type;
390 container_class->get_child_property = gtk_toolbar_get_child_property;
391 container_class->set_child_property = gtk_toolbar_set_child_property;
393 klass->orientation_changed = gtk_toolbar_orientation_changed;
394 klass->style_changed = gtk_toolbar_real_style_changed;
397 * GtkToolbar::orientation-changed:
398 * @toolbar: the object which emitted the signal
399 * @orientation: the new #GtkOrientation of the toolbar
401 * Emitted when the orientation of the toolbar changes.
403 toolbar_signals[ORIENTATION_CHANGED] =
404 g_signal_new (I_("orientation-changed"),
405 G_OBJECT_CLASS_TYPE (klass),
407 G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
409 g_cclosure_marshal_VOID__ENUM,
411 GTK_TYPE_ORIENTATION);
413 * GtkToolbar::style-changed:
414 * @toolbar: The #GtkToolbar which emitted the signal
415 * @style: the new #GtkToolbarStyle of the toolbar
417 * Emitted when the style of the toolbar changes.
419 toolbar_signals[STYLE_CHANGED] =
420 g_signal_new (I_("style-changed"),
421 G_OBJECT_CLASS_TYPE (klass),
423 G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
425 g_cclosure_marshal_VOID__ENUM,
427 GTK_TYPE_TOOLBAR_STYLE);
429 * GtkToolbar::popup-context-menu:
430 * @toolbar: the #GtkToolbar which emitted the signal
431 * @x: the x coordinate of the point where the menu should appear
432 * @y: the y coordinate of the point where the menu should appear
433 * @button: the mouse button the user pressed, or -1
435 * Emitted when the user right-clicks the toolbar or uses the
436 * keybinding to display a popup menu.
438 * Application developers should handle this signal if they want
439 * to display a context menu on the toolbar. The context-menu should
440 * appear at the coordinates given by @x and @y. The mouse button
441 * number is given by the @button parameter. If the menu was popped
442 * up using the keybaord, @button is -1.
444 * Return value: return %TRUE if the signal was handled, %FALSE if not
446 toolbar_signals[POPUP_CONTEXT_MENU] =
447 g_signal_new (I_("popup-context-menu"),
448 G_OBJECT_CLASS_TYPE (klass),
450 G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
451 _gtk_boolean_handled_accumulator, NULL,
452 _gtk_marshal_BOOLEAN__INT_INT_INT,
454 G_TYPE_INT, G_TYPE_INT,
458 * GtkToolbar::focus-home-or-end:
459 * @toolbar: the #GtkToolbar which emitted the signal
460 * @focus_home: %TRUE if the first item should be focused
462 * A keybinding signal used internally by GTK+. This signal can't
463 * be used in application code
465 * Return value: %TRUE if the signal was handled, %FALSE if not
467 toolbar_signals[FOCUS_HOME_OR_END] =
468 g_signal_new_class_handler (I_("focus-home-or-end"),
469 G_OBJECT_CLASS_TYPE (klass),
470 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
471 G_CALLBACK (gtk_toolbar_focus_home_or_end),
473 _gtk_marshal_BOOLEAN__BOOLEAN,
478 g_object_class_override_property (gobject_class,
482 g_object_class_install_property (gobject_class,
484 g_param_spec_enum ("toolbar-style",
486 P_("How to draw the toolbar"),
487 GTK_TYPE_TOOLBAR_STYLE,
488 DEFAULT_TOOLBAR_STYLE,
489 GTK_PARAM_READWRITE));
490 g_object_class_install_property (gobject_class,
492 g_param_spec_boolean ("show-arrow",
494 P_("If an arrow should be shown if the toolbar doesn't fit"),
496 GTK_PARAM_READWRITE));
499 * GtkToolbar:icon-size:
501 * The size of the icons in a toolbar is normally determined by
502 * the toolbar-icon-size setting. When this property is set, it
503 * overrides the setting.
505 * This should only be used for special-purpose toolbars, normal
506 * application toolbars should respect the user preferences for the
511 g_object_class_install_property (gobject_class,
513 g_param_spec_int ("icon-size",
515 P_("Size of icons in this toolbar"),
518 GTK_PARAM_READWRITE));
521 * GtkToolbar:icon-size-set:
523 * Is %TRUE if the icon-size property has been set.
527 g_object_class_install_property (gobject_class,
529 g_param_spec_boolean ("icon-size-set",
531 P_("Whether the icon-size property has been set"),
533 GTK_PARAM_READWRITE));
535 /* child properties */
536 gtk_container_class_install_child_property (container_class,
538 g_param_spec_boolean ("expand",
540 P_("Whether the item should receive extra space when the toolbar grows"),
542 GTK_PARAM_READWRITE));
544 gtk_container_class_install_child_property (container_class,
545 CHILD_PROP_HOMOGENEOUS,
546 g_param_spec_boolean ("homogeneous",
548 P_("Whether the item should be the same size as other homogeneous items"),
550 GTK_PARAM_READWRITE));
552 /* style properties */
553 gtk_widget_class_install_style_property (widget_class,
554 g_param_spec_int ("space-size",
556 P_("Size of spacers"),
560 GTK_PARAM_READABLE));
562 gtk_widget_class_install_style_property (widget_class,
563 g_param_spec_int ("internal-padding",
564 P_("Internal padding"),
565 P_("Amount of border space between the toolbar shadow and the buttons"),
569 GTK_PARAM_READABLE));
571 gtk_widget_class_install_style_property (widget_class,
572 g_param_spec_int ("max-child-expand",
573 P_("Maximum child expand"),
574 P_("Maximum amount of space an expandable item will be given"),
578 GTK_PARAM_READABLE));
580 gtk_widget_class_install_style_property (widget_class,
581 g_param_spec_enum ("space-style",
583 P_("Whether spacers are vertical lines or just blank"),
584 GTK_TYPE_TOOLBAR_SPACE_STYLE,
586 GTK_PARAM_READABLE));
588 gtk_widget_class_install_style_property (widget_class,
589 g_param_spec_enum ("button-relief",
591 P_("Type of bevel around toolbar buttons"),
592 GTK_TYPE_RELIEF_STYLE,
594 GTK_PARAM_READABLE));
595 gtk_widget_class_install_style_property (widget_class,
596 g_param_spec_enum ("shadow-type",
598 P_("Style of bevel around the toolbar"),
599 GTK_TYPE_SHADOW_TYPE,
601 GTK_PARAM_READABLE));
603 binding_set = gtk_binding_set_by_class (klass);
605 add_arrow_bindings (binding_set, GDK_KEY_Left, GTK_DIR_LEFT);
606 add_arrow_bindings (binding_set, GDK_KEY_Right, GTK_DIR_RIGHT);
607 add_arrow_bindings (binding_set, GDK_KEY_Up, GTK_DIR_UP);
608 add_arrow_bindings (binding_set, GDK_KEY_Down, GTK_DIR_DOWN);
610 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Home, 0,
611 "focus-home-or-end", 1,
612 G_TYPE_BOOLEAN, TRUE);
613 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Home, 0,
614 "focus-home-or-end", 1,
615 G_TYPE_BOOLEAN, TRUE);
616 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_End, 0,
617 "focus-home-or-end", 1,
618 G_TYPE_BOOLEAN, FALSE);
619 gtk_binding_entry_add_signal (binding_set, GDK_KEY_End, 0,
620 "focus-home-or-end", 1,
621 G_TYPE_BOOLEAN, FALSE);
623 add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
624 add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
626 g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));
630 toolbar_tool_shell_iface_init (GtkToolShellIface *iface)
632 iface->get_icon_size = toolbar_get_icon_size;
633 iface->get_orientation = toolbar_get_orientation;
634 iface->get_style = toolbar_get_style;
635 iface->get_relief_style = toolbar_get_relief_style;
636 iface->rebuild_menu = toolbar_rebuild_menu;
640 gtk_toolbar_init (GtkToolbar *toolbar)
642 GtkToolbarPrivate *priv;
644 toolbar->priv = G_TYPE_INSTANCE_GET_PRIVATE (toolbar,
647 priv = toolbar->priv;
649 gtk_widget_set_can_focus (GTK_WIDGET (toolbar), FALSE);
650 gtk_widget_set_has_window (GTK_WIDGET (toolbar), FALSE);
652 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
653 priv->style = DEFAULT_TOOLBAR_STYLE;
654 priv->icon_size = DEFAULT_ICON_SIZE;
655 priv->animation = DEFAULT_ANIMATION_STATE;
657 priv->arrow_button = gtk_toggle_button_new ();
658 g_signal_connect (priv->arrow_button, "button-press-event",
659 G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar);
660 g_signal_connect (priv->arrow_button, "clicked",
661 G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar);
662 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
663 get_button_relief (toolbar));
665 gtk_button_set_focus_on_click (GTK_BUTTON (priv->arrow_button), FALSE);
667 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
668 gtk_widget_set_name (priv->arrow, "gtk-toolbar-arrow");
669 gtk_widget_show (priv->arrow);
670 gtk_container_add (GTK_CONTAINER (priv->arrow_button), priv->arrow);
672 gtk_widget_set_parent (priv->arrow_button, GTK_WIDGET (toolbar));
674 /* which child position a drop will occur at */
676 priv->show_arrow = TRUE;
677 priv->settings = NULL;
679 priv->max_homogeneous_pixels = -1;
681 priv->timer = g_timer_new ();
685 gtk_toolbar_set_property (GObject *object,
690 GtkToolbar *toolbar = GTK_TOOLBAR (object);
691 GtkToolbarPrivate *priv = toolbar->priv;
695 case PROP_ORIENTATION:
696 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0,
697 g_value_get_enum (value));
699 case PROP_TOOLBAR_STYLE:
700 gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
702 case PROP_SHOW_ARROW:
703 gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
706 gtk_toolbar_set_icon_size (toolbar, g_value_get_int (value));
708 case PROP_ICON_SIZE_SET:
709 if (g_value_get_boolean (value))
710 priv->icon_size_set = TRUE;
712 gtk_toolbar_unset_icon_size (toolbar);
715 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
721 gtk_toolbar_get_property (GObject *object,
726 GtkToolbar *toolbar = GTK_TOOLBAR (object);
727 GtkToolbarPrivate *priv = toolbar->priv;
731 case PROP_ORIENTATION:
732 g_value_set_enum (value, priv->orientation);
734 case PROP_TOOLBAR_STYLE:
735 g_value_set_enum (value, priv->style);
737 case PROP_SHOW_ARROW:
738 g_value_set_boolean (value, priv->show_arrow);
741 g_value_set_int (value, gtk_toolbar_get_icon_size (toolbar));
743 case PROP_ICON_SIZE_SET:
744 g_value_set_boolean (value, priv->icon_size_set);
747 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
753 gtk_toolbar_map (GtkWidget *widget)
755 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
756 GtkToolbarPrivate *priv = toolbar->priv;
758 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->map (widget);
760 if (priv->event_window)
761 gdk_window_show_unraised (priv->event_window);
765 gtk_toolbar_unmap (GtkWidget *widget)
767 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
768 GtkToolbarPrivate *priv = toolbar->priv;
770 if (priv->event_window)
771 gdk_window_hide (priv->event_window);
773 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unmap (widget);
777 gtk_toolbar_realize (GtkWidget *widget)
779 GtkAllocation allocation;
780 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
781 GtkToolbarPrivate *priv = toolbar->priv;
783 GdkWindowAttr attributes;
784 gint attributes_mask;
787 gtk_widget_set_realized (widget, TRUE);
789 gtk_widget_get_allocation (widget, &allocation);
790 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
792 attributes.wclass = GDK_INPUT_ONLY;
793 attributes.window_type = GDK_WINDOW_CHILD;
794 attributes.x = allocation.x + border_width;
795 attributes.y = allocation.y + border_width;
796 attributes.width = allocation.width - border_width * 2;
797 attributes.height = allocation.height - border_width * 2;
798 attributes.event_mask = gtk_widget_get_events (widget);
799 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
800 GDK_BUTTON_RELEASE_MASK |
801 GDK_ENTER_NOTIFY_MASK |
802 GDK_LEAVE_NOTIFY_MASK);
804 attributes_mask = GDK_WA_X | GDK_WA_Y;
806 window = gtk_widget_get_parent_window (widget);
807 gtk_widget_set_window (widget, window);
808 g_object_ref (window);
810 gtk_widget_style_attach (widget);
812 priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
813 &attributes, attributes_mask);
814 gdk_window_set_user_data (priv->event_window, toolbar);
818 gtk_toolbar_unrealize (GtkWidget *widget)
820 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
821 GtkToolbarPrivate *priv = toolbar->priv;
823 if (priv->event_window)
825 gdk_window_set_user_data (priv->event_window, NULL);
826 gdk_window_destroy (priv->event_window);
827 priv->event_window = NULL;
830 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize (widget);
834 gtk_toolbar_draw (GtkWidget *widget,
837 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
838 GtkToolbarPrivate *priv = toolbar->priv;
842 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
844 gtk_paint_box (gtk_widget_get_style (widget),
846 gtk_widget_get_state (widget),
847 get_shadow_type (toolbar),
851 gtk_widget_get_allocated_width (widget) - 2 * border_width,
852 gtk_widget_get_allocated_height (widget) - 2 * border_width);
854 for (list = priv->content; list != NULL; list = list->next)
856 ToolbarContent *content = list->data;
858 toolbar_content_draw (content, GTK_CONTAINER (widget), cr);
861 gtk_container_propagate_draw (GTK_CONTAINER (widget),
869 gtk_toolbar_size_request (GtkWidget *widget,
870 GtkRequisition *requisition)
872 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
873 GtkToolbarPrivate *priv = toolbar->priv;
875 gint max_child_height;
876 gint max_child_width;
877 gint max_homogeneous_child_width;
878 gint max_homogeneous_child_height;
879 gint homogeneous_size;
881 gint pack_front_size;
884 GtkRequisition arrow_requisition;
886 max_homogeneous_child_width = 0;
887 max_homogeneous_child_height = 0;
889 max_child_height = 0;
890 for (list = priv->content; list != NULL; list = list->next)
892 GtkRequisition requisition;
893 ToolbarContent *content = list->data;
895 if (!toolbar_content_visible (content, toolbar))
898 toolbar_content_size_request (content, toolbar, &requisition);
900 max_child_width = MAX (max_child_width, requisition.width);
901 max_child_height = MAX (max_child_height, requisition.height);
903 if (toolbar_content_is_homogeneous (content, toolbar))
905 max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
906 max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
910 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
911 homogeneous_size = max_homogeneous_child_width;
913 homogeneous_size = max_homogeneous_child_height;
916 for (list = priv->content; list != NULL; list = list->next)
918 ToolbarContent *content = list->data;
921 if (!toolbar_content_visible (content, toolbar))
924 if (toolbar_content_is_homogeneous (content, toolbar))
926 size = homogeneous_size;
930 GtkRequisition requisition;
932 toolbar_content_size_request (content, toolbar, &requisition);
934 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
935 size = requisition.width;
937 size = requisition.height;
940 pack_front_size += size;
943 if (priv->show_arrow)
945 gtk_widget_get_preferred_size (priv->arrow_button,
946 &arrow_requisition, NULL);
948 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
949 long_req = arrow_requisition.width;
951 long_req = arrow_requisition.height;
953 /* There is no point requesting space for the arrow if that would take
954 * up more space than all the items combined
956 long_req = MIN (long_req, pack_front_size);
960 arrow_requisition.height = 0;
961 arrow_requisition.width = 0;
963 long_req = pack_front_size;
966 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
968 requisition->width = long_req;
969 requisition->height = MAX (max_child_height, arrow_requisition.height);
973 requisition->height = long_req;
974 requisition->width = MAX (max_child_width, arrow_requisition.width);
978 ipadding = get_internal_padding (toolbar);
980 border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
981 requisition->width += 2 * (ipadding + border_width);
982 requisition->height += 2 * (ipadding + border_width);
984 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
988 style = gtk_widget_get_style (widget);
989 requisition->width += 2 * style->xthickness;
990 requisition->height += 2 * style->ythickness;
993 priv->button_maxw = max_homogeneous_child_width;
994 priv->button_maxh = max_homogeneous_child_height;
998 position (GtkToolbar *toolbar,
1003 GtkToolbarPrivate *priv = toolbar->priv;
1006 if (!priv->animation)
1009 if (elapsed <= ACCEL_THRESHOLD)
1011 n_pixels = SLIDE_SPEED * elapsed;
1015 /* The formula is a second degree polynomial in
1016 * @elapsed that has the line SLIDE_SPEED * @elapsed
1017 * as tangent for @elapsed == ACCEL_THRESHOLD.
1018 * This makes @n_pixels a smooth function of elapsed time.
1020 n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
1021 SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
1025 return MIN (from + n_pixels, to);
1027 return MAX (from - n_pixels, to);
1031 compute_intermediate_allocation (GtkToolbar *toolbar,
1032 const GtkAllocation *start,
1033 const GtkAllocation *goal,
1034 GtkAllocation *intermediate)
1036 GtkToolbarPrivate *priv = toolbar->priv;
1037 gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
1039 intermediate->x = position (toolbar, start->x, goal->x, elapsed);
1040 intermediate->y = position (toolbar, start->y, goal->y, elapsed);
1041 intermediate->width = position (toolbar, start->x + start->width,
1042 goal->x + goal->width,
1043 elapsed) - intermediate->x;
1044 intermediate->height = position (toolbar, start->y + start->height,
1045 goal->y + goal->height,
1046 elapsed) - intermediate->y;
1050 fixup_allocation_for_rtl (gint total_size,
1051 GtkAllocation *allocation)
1053 allocation->x += (total_size - (2 * allocation->x + allocation->width));
1057 fixup_allocation_for_vertical (GtkAllocation *allocation)
1061 tmp = allocation->x;
1062 allocation->x = allocation->y;
1063 allocation->y = tmp;
1065 tmp = allocation->width;
1066 allocation->width = allocation->height;
1067 allocation->height = tmp;
1071 get_item_size (GtkToolbar *toolbar,
1072 ToolbarContent *content)
1074 GtkToolbarPrivate *priv = toolbar->priv;
1075 GtkRequisition requisition;
1077 toolbar_content_size_request (content, toolbar, &requisition);
1079 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1081 if (toolbar_content_is_homogeneous (content, toolbar))
1082 return priv->button_maxw;
1084 return requisition.width;
1088 if (toolbar_content_is_homogeneous (content, toolbar))
1089 return priv->button_maxh;
1091 return requisition.height;
1096 slide_idle_handler (gpointer data)
1098 GtkToolbar *toolbar = GTK_TOOLBAR (data);
1099 GtkToolbarPrivate *priv = toolbar->priv;
1102 if (priv->need_sync)
1105 priv->need_sync = FALSE;
1108 for (list = priv->content; list != NULL; list = list->next)
1110 ToolbarContent *content = list->data;
1112 GtkAllocation goal_allocation;
1113 GtkAllocation allocation;
1116 state = toolbar_content_get_state (content);
1117 toolbar_content_get_goal_allocation (content, &goal_allocation);
1118 toolbar_content_get_allocation (content, &allocation);
1122 if (state == NOT_ALLOCATED)
1124 /* an unallocated item means that size allocate has to
1125 * called at least once more
1130 /* An invisible item with a goal allocation of
1131 * 0 is already at its goal.
1133 if ((state == NORMAL || state == OVERFLOWN) &&
1134 ((goal_allocation.width != 0 &&
1135 goal_allocation.height != 0) ||
1136 toolbar_content_child_visible (content)))
1138 if ((goal_allocation.x != allocation.x ||
1139 goal_allocation.y != allocation.y ||
1140 goal_allocation.width != allocation.width ||
1141 goal_allocation.height != allocation.height))
1143 /* An item is not in its right position yet. Note
1144 * that OVERFLOWN items do get an allocation in
1145 * gtk_toolbar_size_allocate(). This way you can see
1146 * them slide back in when you drag an item off the
1153 if (toolbar_content_is_placeholder (content) &&
1154 toolbar_content_disappearing (content) &&
1155 toolbar_content_child_visible (content))
1157 /* A disappearing placeholder is still visible.
1165 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1171 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1173 priv->is_sliding = FALSE;
1180 rect_within (GtkAllocation *a1,
1183 return (a1->x >= a2->x &&
1184 a1->x + a1->width <= a2->x + a2->width &&
1186 a1->y + a1->height <= a2->y + a2->height);
1190 gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
1192 GtkAllocation allocation;
1193 GtkWidget *widget = GTK_WIDGET (toolbar);
1194 GtkToolbarPrivate *priv = toolbar->priv;
1203 /* Start the sliding. This function copies the allocation of every
1204 * item into content->start_allocation. For items that haven't
1205 * been allocated yet, we calculate their position and save that
1206 * in start_allocatino along with zero width and zero height.
1208 * FIXME: It would be nice if we could share this code with
1209 * the equivalent in gtk_widget_size_allocate().
1211 priv->is_sliding = TRUE;
1214 priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
1216 gtk_widget_get_allocation (widget, &allocation);
1217 style = gtk_widget_get_style (widget);
1219 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1220 vertical = (priv->orientation == GTK_ORIENTATION_VERTICAL);
1221 border_width = get_internal_padding (toolbar) + gtk_container_get_border_width (GTK_CONTAINER (toolbar));
1225 cur_x = allocation.width - border_width - style->xthickness;
1226 cur_y = allocation.height - border_width - style->ythickness;
1230 cur_x = border_width + style->xthickness;
1231 cur_y = border_width + style->ythickness;
1234 cur_x += allocation.x;
1235 cur_y += allocation.y;
1237 for (list = priv->content; list != NULL; list = list->next)
1239 ToolbarContent *content = list->data;
1240 GtkAllocation new_start_allocation;
1241 GtkAllocation item_allocation;
1244 state = toolbar_content_get_state (content);
1245 toolbar_content_get_allocation (content, &item_allocation);
1247 if ((state == NORMAL &&
1248 rect_within (&item_allocation, &allocation)) ||
1251 new_start_allocation = item_allocation;
1255 new_start_allocation.x = cur_x;
1256 new_start_allocation.y = cur_y;
1260 new_start_allocation.width = allocation.width -
1261 2 * border_width - 2 * style->xthickness;
1262 new_start_allocation.height = 0;
1266 new_start_allocation.width = 0;
1267 new_start_allocation.height = allocation.height -
1268 2 * border_width - 2 * style->ythickness;
1273 cur_y = new_start_allocation.y + new_start_allocation.height;
1275 cur_x = new_start_allocation.x;
1277 cur_x = new_start_allocation.x + new_start_allocation.width;
1279 toolbar_content_set_start_allocation (content, &new_start_allocation);
1282 /* This resize will run before the first idle handler. This
1283 * will make sure that items get the right goal allocation
1284 * so that the idle handler will not immediately return
1287 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1288 g_timer_reset (priv->timer);
1292 gtk_toolbar_stop_sliding (GtkToolbar *toolbar)
1294 GtkToolbarPrivate *priv = toolbar->priv;
1296 if (priv->is_sliding)
1300 priv->is_sliding = FALSE;
1304 g_source_remove (priv->idle_id);
1308 list = priv->content;
1311 ToolbarContent *content = list->data;
1314 if (toolbar_content_is_placeholder (content))
1316 toolbar_content_remove (content, toolbar);
1317 toolbar_content_free (content);
1321 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1326 remove_item (GtkWidget *menu_item,
1329 gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (menu_item)),
1334 menu_deactivated (GtkWidget *menu,
1335 GtkToolbar *toolbar)
1337 GtkToolbarPrivate *priv = toolbar->priv;
1339 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->arrow_button), FALSE);
1343 menu_detached (GtkWidget *widget,
1346 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1347 GtkToolbarPrivate *priv = toolbar->priv;
1353 rebuild_menu (GtkToolbar *toolbar)
1355 GtkToolbarPrivate *priv = toolbar->priv;
1356 GList *list, *children;
1360 priv->menu = GTK_MENU (gtk_menu_new());
1361 gtk_menu_attach_to_widget (priv->menu,
1362 GTK_WIDGET (toolbar),
1365 g_signal_connect (priv->menu, "deactivate",
1366 G_CALLBACK (menu_deactivated), toolbar);
1369 gtk_container_foreach (GTK_CONTAINER (priv->menu), remove_item, NULL);
1371 for (list = priv->content; list != NULL; list = list->next)
1373 ToolbarContent *content = list->data;
1375 if (toolbar_content_get_state (content) == OVERFLOWN &&
1376 !toolbar_content_is_placeholder (content))
1378 GtkWidget *menu_item = toolbar_content_retrieve_menu_item (content);
1382 g_assert (GTK_IS_MENU_ITEM (menu_item));
1383 gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item);
1388 /* Remove leading and trailing separator items */
1389 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1392 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1394 GtkWidget *child = list->data;
1396 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1399 g_list_free (children);
1401 /* Regenerate the list of children so we don't try to remove items twice */
1402 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1404 list = g_list_last (children);
1405 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1407 GtkWidget *child = list->data;
1409 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1412 g_list_free (children);
1414 priv->need_rebuild = FALSE;
1418 gtk_toolbar_size_allocate (GtkWidget *widget,
1419 GtkAllocation *allocation)
1421 GtkAllocation widget_allocation;
1422 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1423 GtkToolbarPrivate *priv = toolbar->priv;
1424 GtkAllocation *allocations;
1425 ItemState *new_states;
1426 GtkAllocation arrow_allocation;
1429 gint size, pos, short_size;
1432 gboolean need_arrow;
1433 gint n_expand_items;
1435 gint available_size;
1438 GtkRequisition arrow_requisition;
1439 gboolean overflowing;
1440 gboolean size_changed;
1442 GtkAllocation item_area;
1443 GtkShadowType shadow_type;
1445 style = gtk_widget_get_style (widget);
1447 gtk_widget_get_allocation (widget, &widget_allocation);
1448 size_changed = FALSE;
1449 if (widget_allocation.x != allocation->x ||
1450 widget_allocation.y != allocation->y ||
1451 widget_allocation.width != allocation->width ||
1452 widget_allocation.height != allocation->height)
1454 size_changed = TRUE;
1458 gtk_toolbar_stop_sliding (toolbar);
1460 gtk_widget_set_allocation (widget, allocation);
1462 border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
1464 if (gtk_widget_get_realized (widget))
1466 gdk_window_move_resize (priv->event_window,
1467 allocation->x + border_width,
1468 allocation->y + border_width,
1469 allocation->width - border_width * 2,
1470 allocation->height - border_width * 2);
1473 border_width += get_internal_padding (toolbar);
1475 gtk_widget_get_preferred_size (priv->arrow_button,
1476 &arrow_requisition, NULL);
1478 shadow_type = get_shadow_type (toolbar);
1480 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1482 available_size = size = allocation->width - 2 * border_width;
1483 short_size = allocation->height - 2 * border_width;
1484 arrow_size = arrow_requisition.width;
1486 if (shadow_type != GTK_SHADOW_NONE)
1488 available_size -= 2 * style->xthickness;
1489 short_size -= 2 * style->ythickness;
1494 available_size = size = allocation->height - 2 * border_width;
1495 short_size = allocation->width - 2 * border_width;
1496 arrow_size = arrow_requisition.height;
1498 if (shadow_type != GTK_SHADOW_NONE)
1500 available_size -= 2 * style->ythickness;
1501 short_size -= 2 * style->xthickness;
1505 n_items = g_list_length (priv->content);
1506 allocations = g_new0 (GtkAllocation, n_items);
1507 new_states = g_new0 (ItemState, n_items);
1511 for (list = priv->content; list != NULL; list = list->next)
1513 ToolbarContent *content = list->data;
1515 if (toolbar_content_visible (content, toolbar))
1517 needed_size += get_item_size (toolbar, content);
1519 /* Do we need an arrow?
1521 * Assume we don't, and see if any non-separator item with a
1522 * proxy menu item is then going to overflow.
1524 if (needed_size > available_size &&
1527 toolbar_content_has_proxy_menu_item (content) &&
1528 !toolbar_content_is_separator (content))
1536 size = available_size - arrow_size;
1538 size = available_size;
1540 /* calculate widths and states of items */
1541 overflowing = FALSE;
1542 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1544 ToolbarContent *content = list->data;
1547 if (!toolbar_content_visible (content, toolbar))
1549 new_states[i] = HIDDEN;
1553 item_size = get_item_size (toolbar, content);
1554 if (item_size <= size && !overflowing)
1557 allocations[i].width = item_size;
1558 new_states[i] = NORMAL;
1563 new_states[i] = OVERFLOWN;
1564 allocations[i].width = item_size;
1568 /* calculate width of arrow */
1571 arrow_allocation.width = arrow_size;
1572 arrow_allocation.height = MAX (short_size, 1);
1575 /* expand expandable items */
1577 /* We don't expand when there is an overflow menu, because that leads to
1578 * weird jumps when items get moved to the overflow menu and the expanding
1579 * items suddenly get a lot of extra space
1583 gint max_child_expand;
1586 for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
1588 ToolbarContent *content = list->data;
1590 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1594 max_child_expand = get_max_child_expand (toolbar);
1595 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1597 ToolbarContent *content = list->data;
1599 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1601 gint extra = size / n_expand_items;
1602 if (size % n_expand_items != 0)
1605 if (extra > max_child_expand)
1606 extra = max_child_expand;
1608 allocations[i].width += extra;
1614 g_assert (n_expand_items == 0);
1617 /* position items */
1619 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1621 /* both NORMAL and OVERFLOWN items get a position. This ensures
1622 * that sliding will work for OVERFLOWN items too
1624 if (new_states[i] == NORMAL ||
1625 new_states[i] == OVERFLOWN)
1627 allocations[i].x = pos;
1628 allocations[i].y = border_width;
1629 allocations[i].height = short_size;
1631 pos += allocations[i].width;
1635 /* position arrow */
1638 arrow_allocation.x = available_size - border_width - arrow_allocation.width;
1639 arrow_allocation.y = border_width;
1642 item_area.x = border_width;
1643 item_area.y = border_width;
1644 item_area.width = available_size - (need_arrow? arrow_size : 0);
1645 item_area.height = short_size;
1647 /* fix up allocations in the vertical or RTL cases */
1648 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
1650 for (i = 0; i < n_items; ++i)
1651 fixup_allocation_for_vertical (&(allocations[i]));
1654 fixup_allocation_for_vertical (&arrow_allocation);
1656 fixup_allocation_for_vertical (&item_area);
1658 else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1660 for (i = 0; i < n_items; ++i)
1661 fixup_allocation_for_rtl (available_size, &(allocations[i]));
1664 fixup_allocation_for_rtl (available_size, &arrow_allocation);
1666 fixup_allocation_for_rtl (available_size, &item_area);
1669 /* translate the items by allocation->(x,y) */
1670 for (i = 0; i < n_items; ++i)
1672 allocations[i].x += allocation->x;
1673 allocations[i].y += allocation->y;
1675 if (shadow_type != GTK_SHADOW_NONE)
1677 allocations[i].x += style->xthickness;
1678 allocations[i].y += style->ythickness;
1684 arrow_allocation.x += allocation->x;
1685 arrow_allocation.y += allocation->y;
1687 if (shadow_type != GTK_SHADOW_NONE)
1689 arrow_allocation.x += style->xthickness;
1690 arrow_allocation.y += style->ythickness;
1694 item_area.x += allocation->x;
1695 item_area.y += allocation->y;
1696 if (shadow_type != GTK_SHADOW_NONE)
1698 item_area.x += style->xthickness;
1699 item_area.y += style->ythickness;
1702 /* did anything change? */
1703 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1705 ToolbarContent *content = list->data;
1707 if (toolbar_content_get_state (content) == NORMAL &&
1708 new_states[i] != NORMAL)
1710 /* an item disappeared and we didn't change size, so begin sliding */
1712 gtk_toolbar_begin_sliding (toolbar);
1716 /* finally allocate the items */
1717 if (priv->is_sliding)
1719 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1721 ToolbarContent *content = list->data;
1723 toolbar_content_set_goal_allocation (content, &(allocations[i]));
1727 elapsed = g_timer_elapsed (priv->timer, NULL);
1728 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1730 ToolbarContent *content = list->data;
1732 if (new_states[i] == OVERFLOWN ||
1733 new_states[i] == NORMAL)
1735 GtkAllocation alloc;
1736 GtkAllocation start_allocation = { 0, };
1737 GtkAllocation goal_allocation;
1739 if (priv->is_sliding)
1741 toolbar_content_get_start_allocation (content, &start_allocation);
1742 toolbar_content_get_goal_allocation (content, &goal_allocation);
1744 compute_intermediate_allocation (toolbar,
1749 priv->need_sync = TRUE;
1753 alloc = allocations[i];
1756 if (alloc.width <= 0 || alloc.height <= 0)
1758 toolbar_content_set_child_visible (content, toolbar, FALSE);
1762 if (!rect_within (&alloc, &item_area))
1764 toolbar_content_set_child_visible (content, toolbar, FALSE);
1765 toolbar_content_size_allocate (content, &alloc);
1769 toolbar_content_set_child_visible (content, toolbar, TRUE);
1770 toolbar_content_size_allocate (content, &alloc);
1776 toolbar_content_set_child_visible (content, toolbar, FALSE);
1779 toolbar_content_set_state (content, new_states[i]);
1782 if (priv->menu && priv->need_rebuild)
1783 rebuild_menu (toolbar);
1787 gtk_widget_size_allocate (GTK_WIDGET (priv->arrow_button),
1789 gtk_widget_show (GTK_WIDGET (priv->arrow_button));
1793 gtk_widget_hide (GTK_WIDGET (priv->arrow_button));
1795 if (priv->menu && gtk_widget_get_visible (GTK_WIDGET (priv->menu)))
1796 gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
1799 g_free (allocations);
1800 g_free (new_states);
1804 gtk_toolbar_update_button_relief (GtkToolbar *toolbar)
1806 GtkToolbarPrivate *priv = toolbar->priv;
1807 GtkReliefStyle relief;
1809 relief = get_button_relief (toolbar);
1811 if (relief != gtk_button_get_relief (GTK_BUTTON (priv->arrow_button)))
1813 gtk_toolbar_reconfigured (toolbar);
1815 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), relief);
1820 gtk_toolbar_style_set (GtkWidget *widget,
1821 GtkStyle *prev_style)
1823 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1824 GtkToolbarPrivate *priv = toolbar->priv;
1826 priv->max_homogeneous_pixels = -1;
1828 if (gtk_widget_get_realized (widget))
1829 gtk_style_set_background (gtk_widget_get_style (widget),
1830 gtk_widget_get_window (widget),
1831 gtk_widget_get_state (widget));
1834 gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
1838 gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
1839 GtkDirectionType dir)
1841 GtkToolbarPrivate *priv = toolbar->priv;
1842 GList *result = NULL;
1846 /* generate list of children in reverse logical order */
1848 for (list = priv->content; list != NULL; list = list->next)
1850 ToolbarContent *content = list->data;
1853 widget = toolbar_content_get_widget (content);
1856 result = g_list_prepend (result, widget);
1859 result = g_list_prepend (result, priv->arrow_button);
1861 rtl = (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL);
1863 /* move in logical order when
1865 * - dir is TAB_FORWARD
1867 * - in RTL mode and moving left or up
1869 * - in LTR mode and moving right or down
1871 if (dir == GTK_DIR_TAB_FORWARD ||
1872 (rtl && (dir == GTK_DIR_UP || dir == GTK_DIR_LEFT)) ||
1873 (!rtl && (dir == GTK_DIR_DOWN || dir == GTK_DIR_RIGHT)))
1875 result = g_list_reverse (result);
1882 gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
1883 gboolean focus_home)
1885 GList *children, *list;
1886 GtkDirectionType dir = focus_home? GTK_DIR_RIGHT : GTK_DIR_LEFT;
1888 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1890 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1892 children = g_list_reverse (children);
1894 dir = (dir == GTK_DIR_RIGHT)? GTK_DIR_LEFT : GTK_DIR_RIGHT;
1897 for (list = children; list != NULL; list = list->next)
1899 GtkWidget *child = list->data;
1901 if (gtk_container_get_focus_child (GTK_CONTAINER (toolbar)) == child)
1904 if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1908 g_list_free (children);
1913 /* Keybinding handler. This function is called when the user presses
1914 * Ctrl TAB or an arrow key.
1917 gtk_toolbar_move_focus (GtkWidget *widget,
1918 GtkDirectionType dir)
1920 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1921 GtkContainer *container = GTK_CONTAINER (toolbar);
1922 GtkWidget *focus_child;
1924 gboolean try_focus = FALSE;
1927 focus_child = gtk_container_get_focus_child (container);
1929 if (focus_child && gtk_widget_child_focus (focus_child, dir))
1932 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1934 for (list = children; list != NULL; list = list->next)
1936 GtkWidget *child = list->data;
1938 if (try_focus && gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1941 if (child == focus_child)
1945 g_list_free (children);
1948 /* The focus handler for the toolbar. It called when the user presses
1949 * TAB or otherwise tries to focus the toolbar.
1952 gtk_toolbar_focus (GtkWidget *widget,
1953 GtkDirectionType dir)
1955 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1956 GList *children, *list;
1957 gboolean result = FALSE;
1959 /* if focus is already somewhere inside the toolbar then return FALSE.
1960 * The only way focus can stay inside the toolbar is when the user presses
1961 * arrow keys or Ctrl TAB (both of which are handled by the
1962 * gtk_toolbar_move_focus() keybinding function.
1964 if (gtk_container_get_focus_child (GTK_CONTAINER (widget)))
1967 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1969 for (list = children; list != NULL; list = list->next)
1971 GtkWidget *child = list->data;
1973 if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1980 g_list_free (children);
1985 static GtkSettings *
1986 toolbar_get_settings (GtkToolbar *toolbar)
1988 return toolbar->priv->settings;
1992 style_change_notify (GtkToolbar *toolbar)
1994 GtkToolbarPrivate *priv = toolbar->priv;
1996 if (!priv->style_set)
1998 /* pretend it was set, then unset, thus reverting to new default */
1999 priv->style_set = TRUE;
2000 gtk_toolbar_unset_style (toolbar);
2005 icon_size_change_notify (GtkToolbar *toolbar)
2007 GtkToolbarPrivate *priv = toolbar->priv;
2009 if (!priv->icon_size_set)
2011 /* pretend it was set, then unset, thus reverting to new default */
2012 priv->icon_size_set = TRUE;
2013 gtk_toolbar_unset_icon_size (toolbar);
2018 animation_change_notify (GtkToolbar *toolbar)
2020 GtkToolbarPrivate *priv = toolbar->priv;
2021 GtkSettings *settings = toolbar_get_settings (toolbar);
2025 g_object_get (settings,
2026 "gtk-enable-animations", &animation,
2029 animation = DEFAULT_ANIMATION_STATE;
2031 priv->animation = animation;
2035 settings_change_notify (GtkSettings *settings,
2036 const GParamSpec *pspec,
2037 GtkToolbar *toolbar)
2039 if (! strcmp (pspec->name, "gtk-toolbar-style"))
2040 style_change_notify (toolbar);
2041 else if (! strcmp (pspec->name, "gtk-toolbar-icon-size"))
2042 icon_size_change_notify (toolbar);
2043 else if (! strcmp (pspec->name, "gtk-enable-animations"))
2044 animation_change_notify (toolbar);
2048 gtk_toolbar_screen_changed (GtkWidget *widget,
2049 GdkScreen *previous_screen)
2051 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2052 GtkToolbarPrivate *priv = toolbar->priv;
2053 GtkSettings *old_settings = toolbar_get_settings (toolbar);
2054 GtkSettings *settings;
2056 if (gtk_widget_has_screen (GTK_WIDGET (toolbar)))
2057 settings = gtk_widget_get_settings (GTK_WIDGET (toolbar));
2061 if (settings == old_settings)
2066 g_signal_handler_disconnect (old_settings, priv->settings_connection);
2068 g_object_unref (old_settings);
2073 priv->settings_connection =
2074 g_signal_connect (settings, "notify",
2075 G_CALLBACK (settings_change_notify),
2078 priv->settings = g_object_ref (settings);
2081 priv->settings = NULL;
2083 style_change_notify (toolbar);
2084 icon_size_change_notify (toolbar);
2085 animation_change_notify (toolbar);
2089 find_drop_index (GtkToolbar *toolbar,
2093 GtkToolbarPrivate *priv = toolbar->priv;
2094 GList *interesting_content;
2096 GtkOrientation orientation;
2097 GtkTextDirection direction;
2098 gint best_distance = G_MAXINT;
2102 ToolbarContent *best_content;
2103 GtkAllocation allocation;
2105 /* list items we care about wrt. drag and drop */
2106 interesting_content = NULL;
2107 for (list = priv->content; list != NULL; list = list->next)
2109 ToolbarContent *content = list->data;
2111 if (toolbar_content_get_state (content) == NORMAL)
2112 interesting_content = g_list_prepend (interesting_content, content);
2114 interesting_content = g_list_reverse (interesting_content);
2116 if (!interesting_content)
2119 orientation = priv->orientation;
2120 direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
2122 /* distance to first interesting item */
2123 best_content = interesting_content->data;
2124 toolbar_content_get_allocation (best_content, &allocation);
2126 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2130 if (direction == GTK_TEXT_DIR_LTR)
2133 pos = allocation.x + allocation.width;
2141 best_content = NULL;
2142 best_distance = ABS (pos - cursor);
2144 /* distance to far end of each item */
2145 for (list = interesting_content; list != NULL; list = list->next)
2147 ToolbarContent *content = list->data;
2149 toolbar_content_get_allocation (content, &allocation);
2151 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2153 if (direction == GTK_TEXT_DIR_LTR)
2154 pos = allocation.x + allocation.width;
2160 pos = allocation.y + allocation.height;
2163 distance = ABS (pos - cursor);
2165 if (distance < best_distance)
2167 best_distance = distance;
2168 best_content = content;
2172 g_list_free (interesting_content);
2177 return g_list_index (priv->content, best_content) + 1;
2181 reset_all_placeholders (GtkToolbar *toolbar)
2183 GtkToolbarPrivate *priv = toolbar->priv;
2186 for (list = priv->content; list != NULL; list = list->next)
2188 ToolbarContent *content = list->data;
2189 if (toolbar_content_is_placeholder (content))
2190 toolbar_content_set_disappearing (content, TRUE);
2195 physical_to_logical (GtkToolbar *toolbar,
2198 GtkToolbarPrivate *priv = toolbar->priv;
2202 g_assert (physical >= 0);
2205 for (list = priv->content; list && physical > 0; list = list->next)
2207 ToolbarContent *content = list->data;
2209 if (!toolbar_content_is_placeholder (content))
2214 g_assert (physical == 0);
2220 logical_to_physical (GtkToolbar *toolbar,
2223 GtkToolbarPrivate *priv = toolbar->priv;
2227 g_assert (logical >= 0);
2230 for (list = priv->content; list; list = list->next)
2232 ToolbarContent *content = list->data;
2234 if (!toolbar_content_is_placeholder (content))
2244 g_assert (logical == 0);
2250 * gtk_toolbar_set_drop_highlight_item:
2251 * @toolbar: a #GtkToolbar
2252 * @tool_item: (allow-none): a #GtkToolItem, or %NULL to turn of highlighting
2253 * @index_: a position on @toolbar
2255 * Highlights @toolbar to give an idea of what it would look like
2256 * if @item was added to @toolbar at the position indicated by @index_.
2257 * If @item is %NULL, highlighting is turned off. In that case @index_
2260 * The @tool_item passed to this function must not be part of any widget
2261 * hierarchy. When an item is set as drop highlight item it can not
2262 * added to any widget hierarchy or used as highlight item for another
2268 gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar,
2269 GtkToolItem *tool_item,
2272 ToolbarContent *content;
2273 GtkToolbarPrivate *priv;
2275 GtkRequisition requisition;
2276 GtkRequisition old_requisition;
2277 gboolean restart_sliding;
2279 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2280 g_return_if_fail (tool_item == NULL || GTK_IS_TOOL_ITEM (tool_item));
2282 priv = toolbar->priv;
2286 if (priv->highlight_tool_item)
2288 gtk_widget_unparent (GTK_WIDGET (priv->highlight_tool_item));
2289 g_object_unref (priv->highlight_tool_item);
2290 priv->highlight_tool_item = NULL;
2293 reset_all_placeholders (toolbar);
2294 gtk_toolbar_begin_sliding (toolbar);
2298 n_items = gtk_toolbar_get_n_items (toolbar);
2299 if (index_ < 0 || index_ > n_items)
2302 if (tool_item != priv->highlight_tool_item)
2304 if (priv->highlight_tool_item)
2305 g_object_unref (priv->highlight_tool_item);
2307 g_object_ref_sink (tool_item);
2309 priv->highlight_tool_item = tool_item;
2311 gtk_widget_set_parent (GTK_WIDGET (priv->highlight_tool_item),
2312 GTK_WIDGET (toolbar));
2315 index_ = logical_to_physical (toolbar, index_);
2317 content = g_list_nth_data (priv->content, index_);
2321 ToolbarContent *prev_content;
2323 prev_content = g_list_nth_data (priv->content, index_ - 1);
2325 if (prev_content && toolbar_content_is_placeholder (prev_content))
2326 content = prev_content;
2329 if (!content || !toolbar_content_is_placeholder (content))
2331 GtkWidget *placeholder;
2333 placeholder = GTK_WIDGET (gtk_separator_tool_item_new ());
2335 content = toolbar_content_new_tool_item (toolbar,
2336 GTK_TOOL_ITEM (placeholder),
2338 gtk_widget_show (placeholder);
2342 g_assert (toolbar_content_is_placeholder (content));
2344 gtk_widget_get_preferred_size (GTK_WIDGET (priv->highlight_tool_item),
2345 &requisition, NULL);
2347 toolbar_content_set_expand (content, gtk_tool_item_get_expand (tool_item));
2349 restart_sliding = FALSE;
2350 toolbar_content_size_request (content, toolbar, &old_requisition);
2351 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2353 requisition.height = -1;
2354 if (requisition.width != old_requisition.width)
2355 restart_sliding = TRUE;
2359 requisition.width = -1;
2360 if (requisition.height != old_requisition.height)
2361 restart_sliding = TRUE;
2364 if (toolbar_content_disappearing (content))
2365 restart_sliding = TRUE;
2367 reset_all_placeholders (toolbar);
2368 toolbar_content_set_disappearing (content, FALSE);
2370 toolbar_content_set_size_request (content,
2371 requisition.width, requisition.height);
2373 if (restart_sliding)
2374 gtk_toolbar_begin_sliding (toolbar);
2378 gtk_toolbar_get_child_property (GtkContainer *container,
2384 GtkToolItem *item = GTK_TOOL_ITEM (child);
2386 switch (property_id)
2388 case CHILD_PROP_HOMOGENEOUS:
2389 g_value_set_boolean (value, gtk_tool_item_get_homogeneous (item));
2392 case CHILD_PROP_EXPAND:
2393 g_value_set_boolean (value, gtk_tool_item_get_expand (item));
2397 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2403 gtk_toolbar_set_child_property (GtkContainer *container,
2406 const GValue *value,
2409 switch (property_id)
2411 case CHILD_PROP_HOMOGENEOUS:
2412 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2415 case CHILD_PROP_EXPAND:
2416 gtk_tool_item_set_expand (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2420 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2426 gtk_toolbar_show_all (GtkWidget *widget)
2428 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2429 GtkToolbarPrivate *priv = toolbar->priv;
2432 for (list = priv->content; list != NULL; list = list->next)
2434 ToolbarContent *content = list->data;
2436 toolbar_content_show_all (content);
2439 gtk_widget_show (widget);
2443 gtk_toolbar_add (GtkContainer *container,
2446 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2448 gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
2452 gtk_toolbar_remove (GtkContainer *container,
2455 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2456 GtkToolbarPrivate *priv = toolbar->priv;
2457 ToolbarContent *content_to_remove;
2460 content_to_remove = NULL;
2461 for (list = priv->content; list != NULL; list = list->next)
2463 ToolbarContent *content = list->data;
2466 child = toolbar_content_get_widget (content);
2467 if (child && child == widget)
2469 content_to_remove = content;
2474 g_return_if_fail (content_to_remove != NULL);
2476 toolbar_content_remove (content_to_remove, toolbar);
2477 toolbar_content_free (content_to_remove);
2481 gtk_toolbar_forall (GtkContainer *container,
2482 gboolean include_internals,
2483 GtkCallback callback,
2484 gpointer callback_data)
2486 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2487 GtkToolbarPrivate *priv = toolbar->priv;
2490 g_return_if_fail (callback != NULL);
2492 list = priv->content;
2495 ToolbarContent *content = list->data;
2496 GList *next = list->next;
2498 if (include_internals || !toolbar_content_is_placeholder (content))
2500 GtkWidget *child = toolbar_content_get_widget (content);
2503 callback (child, callback_data);
2509 if (include_internals)
2510 callback (priv->arrow_button, callback_data);
2514 gtk_toolbar_child_type (GtkContainer *container)
2516 return GTK_TYPE_TOOL_ITEM;
2520 gtk_toolbar_reconfigured (GtkToolbar *toolbar)
2522 GtkToolbarPrivate *priv = toolbar->priv;
2525 list = priv->content;
2528 ToolbarContent *content = list->data;
2529 GList *next = list->next;
2531 toolbar_content_toolbar_reconfigured (content, toolbar);
2538 gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
2539 GtkOrientation orientation)
2541 GtkToolbarPrivate *priv = toolbar->priv;
2543 if (priv->orientation != orientation)
2545 priv->orientation = orientation;
2547 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2548 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2550 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2552 gtk_toolbar_reconfigured (toolbar);
2554 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2555 g_object_notify (G_OBJECT (toolbar), "orientation");
2560 gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
2561 GtkToolbarStyle style)
2563 GtkToolbarPrivate *priv = toolbar->priv;
2565 if (priv->style != style)
2567 priv->style = style;
2569 gtk_toolbar_reconfigured (toolbar);
2571 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2572 g_object_notify (G_OBJECT (toolbar), "toolbar-style");
2577 menu_position_func (GtkMenu *menu,
2583 GtkAllocation allocation;
2584 GtkToolbar *toolbar = GTK_TOOLBAR (user_data);
2585 GtkToolbarPrivate *priv = toolbar->priv;
2587 GtkRequisition menu_req;
2588 GdkRectangle monitor;
2592 gtk_widget_get_preferred_size (priv->arrow_button,
2594 gtk_widget_get_preferred_size (GTK_WIDGET (menu),
2597 screen = gtk_widget_get_screen (GTK_WIDGET (menu));
2598 monitor_num = gdk_screen_get_monitor_at_window (screen,
2599 gtk_widget_get_window (priv->arrow_button));
2600 if (monitor_num < 0)
2602 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2604 gtk_widget_get_allocation (priv->arrow_button, &allocation);
2606 gdk_window_get_origin (gtk_button_get_event_window (GTK_BUTTON (priv->arrow_button)), x, y);
2607 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2609 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2610 *x += allocation.width - req.width;
2612 *x += req.width - menu_req.width;
2614 if ((*y + allocation.height + menu_req.height) <= monitor.y + monitor.height)
2615 *y += allocation.height;
2616 else if ((*y - menu_req.height) >= monitor.y)
2617 *y -= menu_req.height;
2618 else if (monitor.y + monitor.height - (*y + allocation.height) > *y)
2619 *y += allocation.height;
2621 *y -= menu_req.height;
2625 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2626 *x += allocation.width;
2628 *x -= menu_req.width;
2630 if (*y + menu_req.height > monitor.y + monitor.height &&
2631 *y + allocation.height - monitor.y > monitor.y + monitor.height - *y)
2632 *y += allocation.height - menu_req.height;
2639 show_menu (GtkToolbar *toolbar,
2640 GdkEventButton *event)
2642 GtkToolbarPrivate *priv = toolbar->priv;
2644 rebuild_menu (toolbar);
2646 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2648 gtk_menu_popup (priv->menu, NULL, NULL,
2649 menu_position_func, toolbar,
2650 event? event->button : 0,
2651 event? event->time : gtk_get_current_event_time());
2655 gtk_toolbar_arrow_button_clicked (GtkWidget *button,
2656 GtkToolbar *toolbar)
2658 GtkToolbarPrivate *priv = toolbar->priv;
2660 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) &&
2661 (!priv->menu || !gtk_widget_get_visible (GTK_WIDGET (priv->menu))))
2663 /* We only get here when the button is clicked with the keyboard,
2664 * because mouse button presses result in the menu being shown so
2665 * that priv->menu would be non-NULL and visible.
2667 show_menu (toolbar, NULL);
2668 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
2673 gtk_toolbar_arrow_button_press (GtkWidget *button,
2674 GdkEventButton *event,
2675 GtkToolbar *toolbar)
2677 show_menu (toolbar, event);
2678 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
2684 gtk_toolbar_button_press (GtkWidget *toolbar,
2685 GdkEventButton *event)
2689 if (event->button == 3)
2691 gboolean return_value;
2693 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2694 (int)event->x_root, (int)event->y_root, event->button,
2697 return return_value;
2700 window = gtk_widget_get_toplevel (toolbar);
2704 gboolean window_drag = FALSE;
2706 gtk_widget_style_get (toolbar,
2707 "window-dragging", &window_drag,
2712 gtk_window_begin_move_drag (GTK_WINDOW (window),
2726 gtk_toolbar_popup_menu (GtkWidget *toolbar)
2728 gboolean return_value;
2729 /* This function is the handler for the "popup menu" keybinding,
2730 * ie., it is called when the user presses Shift F10
2732 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2733 -1, -1, -1, &return_value);
2735 return return_value;
2741 * Creates a new toolbar.
2743 * Return Value: the newly-created toolbar.
2746 gtk_toolbar_new (void)
2748 GtkToolbar *toolbar;
2750 toolbar = g_object_new (GTK_TYPE_TOOLBAR, NULL);
2752 return GTK_WIDGET (toolbar);
2756 * gtk_toolbar_insert:
2757 * @toolbar: a #GtkToolbar
2758 * @item: a #GtkToolItem
2759 * @pos: the position of the new item
2761 * Insert a #GtkToolItem into the toolbar at position @pos. If @pos is
2762 * 0 the item is prepended to the start of the toolbar. If @pos is
2763 * negative, the item is appended to the end of the toolbar.
2768 gtk_toolbar_insert (GtkToolbar *toolbar,
2772 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2773 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
2776 pos = logical_to_physical (toolbar, pos);
2778 toolbar_content_new_tool_item (toolbar, item, FALSE, pos);
2782 * gtk_toolbar_get_item_index:
2783 * @toolbar: a #GtkToolbar
2784 * @item: a #GtkToolItem that is a child of @toolbar
2786 * Returns the position of @item on the toolbar, starting from 0.
2787 * It is an error if @item is not a child of the toolbar.
2789 * Return value: the position of item on the toolbar.
2794 gtk_toolbar_get_item_index (GtkToolbar *toolbar,
2797 GtkToolbarPrivate *priv;
2801 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2802 g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
2803 g_return_val_if_fail (gtk_widget_get_parent (GTK_WIDGET (item)) == GTK_WIDGET (toolbar), -1);
2805 priv = toolbar->priv;
2808 for (list = priv->content; list != NULL; list = list->next)
2810 ToolbarContent *content = list->data;
2813 widget = toolbar_content_get_widget (content);
2815 if (item == GTK_TOOL_ITEM (widget))
2821 return physical_to_logical (toolbar, n);
2825 * gtk_toolbar_set_style:
2826 * @toolbar: a #GtkToolbar.
2827 * @style: the new style for @toolbar.
2829 * Alters the view of @toolbar to display either icons only, text only, or both.
2832 gtk_toolbar_set_style (GtkToolbar *toolbar,
2833 GtkToolbarStyle style)
2835 GtkToolbarPrivate *priv;
2837 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2839 priv = toolbar->priv;
2841 priv->style_set = TRUE;
2842 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2846 * gtk_toolbar_get_style:
2847 * @toolbar: a #GtkToolbar
2849 * Retrieves whether the toolbar has text, icons, or both . See
2850 * gtk_toolbar_set_style().
2852 * Return value: the current style of @toolbar
2855 gtk_toolbar_get_style (GtkToolbar *toolbar)
2857 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_TOOLBAR_STYLE);
2859 return toolbar->priv->style;
2863 * gtk_toolbar_unset_style:
2864 * @toolbar: a #GtkToolbar
2866 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that
2867 * user preferences will be used to determine the toolbar style.
2870 gtk_toolbar_unset_style (GtkToolbar *toolbar)
2872 GtkToolbarPrivate *priv;
2873 GtkToolbarStyle style;
2875 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2877 priv = toolbar->priv;
2879 if (priv->style_set)
2881 GtkSettings *settings = toolbar_get_settings (toolbar);
2884 g_object_get (settings,
2885 "gtk-toolbar-style", &style,
2888 style = DEFAULT_TOOLBAR_STYLE;
2890 if (style != priv->style)
2891 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2893 priv->style_set = FALSE;
2898 * gtk_toolbar_get_n_items:
2899 * @toolbar: a #GtkToolbar
2901 * Returns the number of items on the toolbar.
2903 * Return value: the number of items on the toolbar
2908 gtk_toolbar_get_n_items (GtkToolbar *toolbar)
2910 GtkToolbarPrivate *priv;
2912 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2914 priv = toolbar->priv;
2916 return physical_to_logical (toolbar, g_list_length (priv->content));
2920 * gtk_toolbar_get_nth_item:
2921 * @toolbar: a #GtkToolbar
2922 * @n: A position on the toolbar
2924 * Returns the @n<!-- -->'th item on @toolbar, or %NULL if the
2925 * toolbar does not contain an @n<!-- -->'th item.
2927 * Return value: (transfer none): The @n<!-- -->'th #GtkToolItem on @toolbar,
2928 * or %NULL if there isn't an @n<!-- -->'th item.
2933 gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
2936 GtkToolbarPrivate *priv;
2937 ToolbarContent *content;
2940 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
2942 priv = toolbar->priv;
2944 n_items = gtk_toolbar_get_n_items (toolbar);
2946 if (n < 0 || n >= n_items)
2949 content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
2952 g_assert (!toolbar_content_is_placeholder (content));
2954 return GTK_TOOL_ITEM (toolbar_content_get_widget (content));
2958 * gtk_toolbar_get_icon_size:
2959 * @toolbar: a #GtkToolbar
2961 * Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size().
2963 * Return value: (type int): the current icon size for the icons on
2967 gtk_toolbar_get_icon_size (GtkToolbar *toolbar)
2969 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_ICON_SIZE);
2971 return toolbar->priv->icon_size;
2975 * gtk_toolbar_get_relief_style:
2976 * @toolbar: a #GtkToolbar
2978 * Returns the relief style of buttons on @toolbar. See
2979 * gtk_button_set_relief().
2981 * Return value: The relief style of buttons on @toolbar.
2986 gtk_toolbar_get_relief_style (GtkToolbar *toolbar)
2988 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_RELIEF_NONE);
2990 return get_button_relief (toolbar);
2994 * gtk_toolbar_set_show_arrow:
2995 * @toolbar: a #GtkToolbar
2996 * @show_arrow: Whether to show an overflow menu
2998 * Sets whether to show an overflow menu when
2999 * @toolbar doesn't have room for all items on it. If %TRUE,
3000 * items that there are not room are available through an
3006 gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
3007 gboolean show_arrow)
3009 GtkToolbarPrivate *priv;
3011 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3013 priv = toolbar->priv;
3015 show_arrow = show_arrow != FALSE;
3017 if (priv->show_arrow != show_arrow)
3019 priv->show_arrow = show_arrow;
3021 if (!priv->show_arrow)
3022 gtk_widget_hide (priv->arrow_button);
3024 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3025 g_object_notify (G_OBJECT (toolbar), "show-arrow");
3030 * gtk_toolbar_get_show_arrow:
3031 * @toolbar: a #GtkToolbar
3033 * Returns whether the toolbar has an overflow menu.
3034 * See gtk_toolbar_set_show_arrow().
3036 * Return value: %TRUE if the toolbar has an overflow menu.
3041 gtk_toolbar_get_show_arrow (GtkToolbar *toolbar)
3043 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
3045 return toolbar->priv->show_arrow;
3049 * gtk_toolbar_get_drop_index:
3050 * @toolbar: a #GtkToolbar
3051 * @x: x coordinate of a point on the toolbar
3052 * @y: y coordinate of a point on the toolbar
3054 * Returns the position corresponding to the indicated point on
3055 * @toolbar. This is useful when dragging items to the toolbar:
3056 * this function returns the position a new item should be
3059 * @x and @y are in @toolbar coordinates.
3061 * Return value: The position corresponding to the point (@x, @y) on the toolbar.
3066 gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
3070 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
3072 return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
3076 gtk_toolbar_finalize (GObject *object)
3079 GtkToolbar *toolbar = GTK_TOOLBAR (object);
3080 GtkToolbarPrivate *priv = toolbar->priv;
3082 if (priv->arrow_button)
3083 gtk_widget_unparent (priv->arrow_button);
3085 for (list = priv->content; list != NULL; list = list->next)
3087 ToolbarContent *content = list->data;
3089 toolbar_content_free (content);
3092 g_list_free (priv->content);
3093 g_list_free (priv->children);
3095 g_timer_destroy (priv->timer);
3098 gtk_widget_destroy (GTK_WIDGET (priv->menu));
3101 g_source_remove (priv->idle_id);
3103 G_OBJECT_CLASS (gtk_toolbar_parent_class)->finalize (object);
3107 * gtk_toolbar_set_icon_size:
3108 * @toolbar: A #GtkToolbar
3109 * @icon_size: (type int): The #GtkIconSize that stock icons in the
3110 * toolbar shall have.
3112 * This function sets the size of stock icons in the toolbar. You
3113 * can call it both before you add the icons and after they've been
3114 * added. The size you set will override user preferences for the default
3117 * This should only be used for special-purpose toolbars, normal
3118 * application toolbars should respect the user preferences for the
3122 gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
3123 GtkIconSize icon_size)
3125 GtkToolbarPrivate *priv;
3127 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3128 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
3130 priv = toolbar->priv;
3132 if (!priv->icon_size_set)
3134 priv->icon_size_set = TRUE;
3135 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3138 if (priv->icon_size == icon_size)
3141 priv->icon_size = icon_size;
3142 g_object_notify (G_OBJECT (toolbar), "icon-size");
3144 gtk_toolbar_reconfigured (toolbar);
3146 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3150 * gtk_toolbar_unset_icon_size:
3151 * @toolbar: a #GtkToolbar
3153 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that
3154 * user preferences will be used to determine the icon size.
3157 gtk_toolbar_unset_icon_size (GtkToolbar *toolbar)
3159 GtkToolbarPrivate *priv;
3162 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3164 priv = toolbar->priv;
3166 if (priv->icon_size_set)
3168 GtkSettings *settings = toolbar_get_settings (toolbar);
3172 g_object_get (settings,
3173 "gtk-toolbar-icon-size", &size,
3177 size = DEFAULT_ICON_SIZE;
3179 if (size != priv->icon_size)
3181 gtk_toolbar_set_icon_size (toolbar, size);
3182 g_object_notify (G_OBJECT (toolbar), "icon-size");
3185 priv->icon_size_set = FALSE;
3186 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3191 * ToolbarContent methods
3199 struct _ToolbarContent
3204 GtkAllocation start_allocation;
3205 GtkAllocation goal_allocation;
3206 guint is_placeholder : 1;
3207 guint disappearing : 1;
3211 static ToolbarContent *
3212 toolbar_content_new_tool_item (GtkToolbar *toolbar,
3214 gboolean is_placeholder,
3217 GtkToolbarPrivate *priv = toolbar->priv;
3218 ToolbarContent *content;
3220 content = g_slice_new0 (ToolbarContent);
3222 content->state = NOT_ALLOCATED;
3223 content->item = item;
3224 content->is_placeholder = is_placeholder;
3226 gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
3228 priv->content = g_list_insert (priv->content, content, pos);
3230 if (!is_placeholder)
3232 priv->num_children++;
3234 gtk_toolbar_stop_sliding (toolbar);
3237 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3238 priv->need_rebuild = TRUE;
3244 toolbar_content_remove (ToolbarContent *content,
3245 GtkToolbar *toolbar)
3247 GtkToolbarPrivate *priv = toolbar->priv;
3249 gtk_widget_unparent (GTK_WIDGET (content->item));
3251 priv->content = g_list_remove (priv->content, content);
3253 if (!toolbar_content_is_placeholder (content))
3254 priv->num_children--;
3256 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3257 priv->need_rebuild = TRUE;
3261 toolbar_content_free (ToolbarContent *content)
3263 g_slice_free (ToolbarContent, content);
3267 calculate_max_homogeneous_pixels (GtkWidget *widget)
3269 PangoContext *context;
3270 PangoFontMetrics *metrics;
3273 context = gtk_widget_get_pango_context (widget);
3274 metrics = pango_context_get_metrics (context,
3275 gtk_widget_get_style (widget)->font_desc,
3276 pango_context_get_language (context));
3277 char_width = pango_font_metrics_get_approximate_char_width (metrics);
3278 pango_font_metrics_unref (metrics);
3280 return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
3284 toolbar_content_draw (ToolbarContent *content,
3285 GtkContainer *container,
3290 if (content->is_placeholder)
3293 widget = GTK_WIDGET (content->item);
3296 gtk_container_propagate_draw (container, widget, cr);
3300 toolbar_content_visible (ToolbarContent *content,
3301 GtkToolbar *toolbar)
3303 GtkToolbarPrivate *priv = toolbar->priv;
3306 item = content->item;
3308 if (!gtk_widget_get_visible (GTK_WIDGET (item)))
3311 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
3312 gtk_tool_item_get_visible_horizontal (item))
3315 if (priv->orientation == GTK_ORIENTATION_VERTICAL &&
3316 gtk_tool_item_get_visible_vertical (item))
3323 toolbar_content_size_request (ToolbarContent *content,
3324 GtkToolbar *toolbar,
3325 GtkRequisition *requisition)
3327 gtk_widget_get_preferred_size (GTK_WIDGET (content->item),
3329 if (content->is_placeholder &&
3330 content->disappearing)
3332 requisition->width = 0;
3333 requisition->height = 0;
3338 toolbar_content_is_homogeneous (ToolbarContent *content,
3339 GtkToolbar *toolbar)
3341 GtkToolbarPrivate *priv = toolbar->priv;
3342 GtkRequisition requisition;
3345 if (priv->max_homogeneous_pixels < 0)
3347 priv->max_homogeneous_pixels =
3348 calculate_max_homogeneous_pixels (GTK_WIDGET (toolbar));
3351 toolbar_content_size_request (content, toolbar, &requisition);
3353 if (requisition.width > priv->max_homogeneous_pixels)
3356 result = gtk_tool_item_get_homogeneous (content->item) &&
3357 !GTK_IS_SEPARATOR_TOOL_ITEM (content->item);
3359 if (gtk_tool_item_get_is_important (content->item) &&
3360 priv->style == GTK_TOOLBAR_BOTH_HORIZ &&
3361 priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3370 toolbar_content_is_placeholder (ToolbarContent *content)
3372 if (content->is_placeholder)
3379 toolbar_content_disappearing (ToolbarContent *content)
3381 if (content->disappearing)
3388 toolbar_content_get_state (ToolbarContent *content)
3390 return content->state;
3394 toolbar_content_child_visible (ToolbarContent *content)
3396 return gtk_widget_get_child_visible (GTK_WIDGET (content->item));
3400 toolbar_content_get_goal_allocation (ToolbarContent *content,
3401 GtkAllocation *allocation)
3403 *allocation = content->goal_allocation;
3407 toolbar_content_get_allocation (ToolbarContent *content,
3408 GtkAllocation *allocation)
3410 gtk_widget_get_allocation (GTK_WIDGET (content->item), allocation);
3414 toolbar_content_set_start_allocation (ToolbarContent *content,
3415 GtkAllocation *allocation)
3417 content->start_allocation = *allocation;
3421 toolbar_content_get_expand (ToolbarContent *content)
3423 if (!content->disappearing &&
3424 gtk_tool_item_get_expand (content->item))
3431 toolbar_content_set_goal_allocation (ToolbarContent *content,
3432 GtkAllocation *allocation)
3434 content->goal_allocation = *allocation;
3438 toolbar_content_set_child_visible (ToolbarContent *content,
3439 GtkToolbar *toolbar,
3442 gtk_widget_set_child_visible (GTK_WIDGET (content->item),
3447 toolbar_content_get_start_allocation (ToolbarContent *content,
3448 GtkAllocation *start_allocation)
3450 *start_allocation = content->start_allocation;
3454 toolbar_content_size_allocate (ToolbarContent *content,
3455 GtkAllocation *allocation)
3457 gtk_widget_size_allocate (GTK_WIDGET (content->item),
3462 toolbar_content_set_state (ToolbarContent *content,
3465 content->state = state;
3469 toolbar_content_get_widget (ToolbarContent *content)
3471 return GTK_WIDGET (content->item);
3476 toolbar_content_set_disappearing (ToolbarContent *content,
3477 gboolean disappearing)
3479 content->disappearing = disappearing;
3483 toolbar_content_set_size_request (ToolbarContent *content,
3487 gtk_widget_set_size_request (GTK_WIDGET (content->item),
3492 toolbar_content_toolbar_reconfigured (ToolbarContent *content,
3493 GtkToolbar *toolbar)
3495 gtk_tool_item_toolbar_reconfigured (content->item);
3499 toolbar_content_retrieve_menu_item (ToolbarContent *content)
3501 return gtk_tool_item_retrieve_proxy_menu_item (content->item);
3505 toolbar_content_has_proxy_menu_item (ToolbarContent *content)
3507 GtkWidget *menu_item;
3509 if (content->has_menu == YES)
3511 else if (content->has_menu == NO)
3514 menu_item = toolbar_content_retrieve_menu_item (content);
3516 content->has_menu = menu_item? YES : NO;
3518 return menu_item != NULL;
3522 toolbar_content_set_unknown_menu_status (ToolbarContent *content)
3524 content->has_menu = UNKNOWN;
3528 toolbar_content_is_separator (ToolbarContent *content)
3530 return GTK_IS_SEPARATOR_TOOL_ITEM (content->item);
3534 toolbar_content_set_expand (ToolbarContent *content,
3537 gtk_tool_item_set_expand (content->item, expand);
3541 toolbar_content_show_all (ToolbarContent *content)
3545 widget = toolbar_content_get_widget (content);
3547 gtk_widget_show_all (widget);
3553 static GtkReliefStyle
3554 get_button_relief (GtkToolbar *toolbar)
3556 GtkReliefStyle button_relief = GTK_RELIEF_NORMAL;
3558 gtk_widget_ensure_style (GTK_WIDGET (toolbar));
3560 gtk_widget_style_get (GTK_WIDGET (toolbar),
3561 "button-relief", &button_relief,
3564 return button_relief;
3568 get_internal_padding (GtkToolbar *toolbar)
3572 gtk_widget_style_get (GTK_WIDGET (toolbar),
3573 "internal-padding", &ipadding,
3580 get_max_child_expand (GtkToolbar *toolbar)
3582 gint mexpand = G_MAXINT;
3584 gtk_widget_style_get (GTK_WIDGET (toolbar),
3585 "max-child-expand", &mexpand,
3590 static GtkShadowType
3591 get_shadow_type (GtkToolbar *toolbar)
3593 GtkShadowType shadow_type;
3595 gtk_widget_style_get (GTK_WIDGET (toolbar),
3596 "shadow-type", &shadow_type,
3602 /* GTK+ internal methods */
3605 _gtk_toolbar_get_default_space_size (void)
3607 return DEFAULT_SPACE_SIZE;
3611 _gtk_toolbar_paint_space_line (GtkWidget *widget,
3612 GtkToolbar *toolbar,
3615 GtkToolbarPrivate *priv = toolbar->priv;
3616 GtkOrientation orientation;
3621 const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
3622 const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
3624 g_return_if_fail (GTK_IS_WIDGET (widget));
3626 orientation = toolbar? priv->orientation : GTK_ORIENTATION_HORIZONTAL;
3628 style = gtk_widget_get_style (widget);
3629 window = gtk_widget_get_window (widget);
3630 state = gtk_widget_get_state (widget);
3631 width = gtk_widget_get_allocated_width (widget);
3632 height = gtk_widget_get_allocated_height (widget);
3634 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3636 gboolean wide_separators;
3637 gint separator_width;
3639 gtk_widget_style_get (widget,
3640 "wide-separators", &wide_separators,
3641 "separator-width", &separator_width,
3644 if (wide_separators)
3645 gtk_paint_box (style, cr,
3646 state, GTK_SHADOW_ETCHED_OUT,
3647 widget, "vseparator",
3648 (width - separator_width) / 2,
3649 height * start_fraction,
3651 height * (end_fraction - start_fraction));
3653 gtk_paint_vline (style, cr,
3656 height * start_fraction,
3657 height * end_fraction,
3658 (width - style->xthickness) / 2);
3662 gboolean wide_separators;
3663 gint separator_height;
3665 gtk_widget_style_get (widget,
3666 "wide-separators", &wide_separators,
3667 "separator-height", &separator_height,
3670 if (wide_separators)
3671 gtk_paint_box (style, cr,
3672 state, GTK_SHADOW_ETCHED_OUT,
3673 widget, "hseparator",
3674 width * start_fraction,
3675 (height - separator_height) / 2,
3676 width * (end_fraction - start_fraction),
3679 gtk_paint_hline (style, cr,
3682 width * start_fraction,
3683 width * end_fraction,
3684 (height - style->ythickness) / 2);
3689 _gtk_toolbar_elide_underscores (const gchar *original)
3692 const gchar *p, *end;
3694 gboolean last_underscore;
3699 len = strlen (original);
3700 q = result = g_malloc (len + 1);
3701 last_underscore = FALSE;
3703 end = original + len;
3704 for (p = original; p < end; p++)
3706 if (!last_underscore && *p == '_')
3707 last_underscore = TRUE;
3710 last_underscore = FALSE;
3711 if (original + 2 <= p && p + 1 <= end &&
3712 p[-2] == '(' && p[-1] == '_' && p[0] != '_' && p[1] == ')')
3723 if (last_underscore)
3732 toolbar_get_icon_size (GtkToolShell *shell)
3734 GtkToolbar *toolbar = GTK_TOOLBAR (shell);
3735 GtkToolbarPrivate *priv = toolbar->priv;
3737 return priv->icon_size;
3740 static GtkOrientation
3741 toolbar_get_orientation (GtkToolShell *shell)
3743 GtkToolbar *toolbar = GTK_TOOLBAR (shell);
3744 GtkToolbarPrivate *priv = toolbar->priv;
3746 return priv->orientation;
3749 static GtkToolbarStyle
3750 toolbar_get_style (GtkToolShell *shell)
3752 GtkToolbar *toolbar = GTK_TOOLBAR (shell);
3753 GtkToolbarPrivate *priv = toolbar->priv;
3758 static GtkReliefStyle
3759 toolbar_get_relief_style (GtkToolShell *shell)
3761 return get_button_relief (GTK_TOOLBAR (shell));
3765 toolbar_rebuild_menu (GtkToolShell *shell)
3767 GtkToolbar *toolbar = GTK_TOOLBAR (shell);
3768 GtkToolbarPrivate *priv = toolbar->priv;
3771 priv->need_rebuild = TRUE;
3773 for (list = priv->content; list != NULL; list = list->next)
3775 ToolbarContent *content = list->data;
3777 toolbar_content_set_unknown_menu_status (content);
3780 gtk_widget_queue_resize (GTK_WIDGET (shell));