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_get_preferred_width (GtkWidget *widget,
192 static void gtk_toolbar_get_preferred_height (GtkWidget *widget,
196 static void gtk_toolbar_size_allocate (GtkWidget *widget,
197 GtkAllocation *allocation);
198 static void gtk_toolbar_style_set (GtkWidget *widget,
199 GtkStyle *prev_style);
200 static gboolean gtk_toolbar_focus (GtkWidget *widget,
201 GtkDirectionType dir);
202 static void gtk_toolbar_move_focus (GtkWidget *widget,
203 GtkDirectionType dir);
204 static void gtk_toolbar_screen_changed (GtkWidget *widget,
205 GdkScreen *previous_screen);
206 static void gtk_toolbar_map (GtkWidget *widget);
207 static void gtk_toolbar_unmap (GtkWidget *widget);
208 static void gtk_toolbar_set_child_property (GtkContainer *container,
213 static void gtk_toolbar_get_child_property (GtkContainer *container,
218 static void gtk_toolbar_finalize (GObject *object);
219 static void gtk_toolbar_show_all (GtkWidget *widget);
220 static void gtk_toolbar_add (GtkContainer *container,
222 static void gtk_toolbar_remove (GtkContainer *container,
224 static void gtk_toolbar_forall (GtkContainer *container,
225 gboolean include_internals,
226 GtkCallback callback,
227 gpointer callback_data);
228 static GType gtk_toolbar_child_type (GtkContainer *container);
229 static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
230 GtkOrientation orientation);
231 static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
232 GtkToolbarStyle style);
233 static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
234 gboolean focus_home);
235 static gboolean gtk_toolbar_button_press (GtkWidget *toolbar,
236 GdkEventButton *event);
237 static gboolean gtk_toolbar_arrow_button_press (GtkWidget *button,
238 GdkEventButton *event,
239 GtkToolbar *toolbar);
240 static void gtk_toolbar_arrow_button_clicked (GtkWidget *button,
241 GtkToolbar *toolbar);
242 static void gtk_toolbar_update_button_relief (GtkToolbar *toolbar);
243 static gboolean gtk_toolbar_popup_menu (GtkWidget *toolbar);
244 static void gtk_toolbar_reconfigured (GtkToolbar *toolbar);
246 static GtkReliefStyle get_button_relief (GtkToolbar *toolbar);
247 static gint get_internal_padding (GtkToolbar *toolbar);
248 static gint get_max_child_expand (GtkToolbar *toolbar);
249 static GtkShadowType get_shadow_type (GtkToolbar *toolbar);
251 /* methods on ToolbarContent 'class' */
252 static ToolbarContent *toolbar_content_new_tool_item (GtkToolbar *toolbar,
254 gboolean is_placeholder,
256 static void toolbar_content_remove (ToolbarContent *content,
257 GtkToolbar *toolbar);
258 static void toolbar_content_free (ToolbarContent *content);
259 static void toolbar_content_draw (ToolbarContent *content,
260 GtkContainer *container,
262 static gboolean toolbar_content_visible (ToolbarContent *content,
263 GtkToolbar *toolbar);
264 static void toolbar_content_size_request (ToolbarContent *content,
266 GtkRequisition *requisition);
267 static gboolean toolbar_content_is_homogeneous (ToolbarContent *content,
268 GtkToolbar *toolbar);
269 static gboolean toolbar_content_is_placeholder (ToolbarContent *content);
270 static gboolean toolbar_content_disappearing (ToolbarContent *content);
271 static ItemState toolbar_content_get_state (ToolbarContent *content);
272 static gboolean toolbar_content_child_visible (ToolbarContent *content);
273 static void toolbar_content_get_goal_allocation (ToolbarContent *content,
274 GtkAllocation *allocation);
275 static void toolbar_content_get_allocation (ToolbarContent *content,
276 GtkAllocation *allocation);
277 static void toolbar_content_set_start_allocation (ToolbarContent *content,
278 GtkAllocation *new_start_allocation);
279 static void toolbar_content_get_start_allocation (ToolbarContent *content,
280 GtkAllocation *start_allocation);
281 static gboolean toolbar_content_get_expand (ToolbarContent *content);
282 static void toolbar_content_set_goal_allocation (ToolbarContent *content,
283 GtkAllocation *allocation);
284 static void toolbar_content_set_child_visible (ToolbarContent *content,
287 static void toolbar_content_size_allocate (ToolbarContent *content,
288 GtkAllocation *allocation);
289 static void toolbar_content_set_state (ToolbarContent *content,
290 ItemState new_state);
291 static GtkWidget * toolbar_content_get_widget (ToolbarContent *content);
292 static void toolbar_content_set_disappearing (ToolbarContent *content,
293 gboolean disappearing);
294 static void toolbar_content_set_size_request (ToolbarContent *content,
297 static void toolbar_content_toolbar_reconfigured (ToolbarContent *content,
298 GtkToolbar *toolbar);
299 static GtkWidget * toolbar_content_retrieve_menu_item (ToolbarContent *content);
300 static gboolean toolbar_content_has_proxy_menu_item (ToolbarContent *content);
301 static gboolean toolbar_content_is_separator (ToolbarContent *content);
302 static void toolbar_content_show_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);
314 G_DEFINE_TYPE_WITH_CODE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER,
315 G_IMPLEMENT_INTERFACE (GTK_TYPE_TOOL_SHELL,
316 toolbar_tool_shell_iface_init)
317 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
320 static guint toolbar_signals[LAST_SIGNAL] = { 0 };
324 add_arrow_bindings (GtkBindingSet *binding_set,
326 GtkDirectionType dir)
328 guint keypad_keysym = keysym - GDK_KEY_Left + GDK_KEY_KP_Left;
330 gtk_binding_entry_add_signal (binding_set, keysym, 0,
332 GTK_TYPE_DIRECTION_TYPE, dir);
333 gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
335 GTK_TYPE_DIRECTION_TYPE, dir);
339 add_ctrl_tab_bindings (GtkBindingSet *binding_set,
340 GdkModifierType modifiers,
341 GtkDirectionType direction)
343 gtk_binding_entry_add_signal (binding_set,
344 GDK_KEY_Tab, GDK_CONTROL_MASK | modifiers,
346 GTK_TYPE_DIRECTION_TYPE, direction);
347 gtk_binding_entry_add_signal (binding_set,
348 GDK_KEY_KP_Tab, GDK_CONTROL_MASK | modifiers,
350 GTK_TYPE_DIRECTION_TYPE, direction);
354 gtk_toolbar_class_init (GtkToolbarClass *klass)
356 GObjectClass *gobject_class;
357 GtkWidgetClass *widget_class;
358 GtkContainerClass *container_class;
359 GtkBindingSet *binding_set;
361 gobject_class = (GObjectClass *)klass;
362 widget_class = (GtkWidgetClass *)klass;
363 container_class = (GtkContainerClass *)klass;
365 gobject_class->set_property = gtk_toolbar_set_property;
366 gobject_class->get_property = gtk_toolbar_get_property;
367 gobject_class->finalize = gtk_toolbar_finalize;
369 widget_class->button_press_event = gtk_toolbar_button_press;
370 widget_class->draw = gtk_toolbar_draw;
371 widget_class->get_preferred_width = gtk_toolbar_get_preferred_width;
372 widget_class->get_preferred_height = gtk_toolbar_get_preferred_height;
373 widget_class->size_allocate = gtk_toolbar_size_allocate;
374 widget_class->style_set = gtk_toolbar_style_set;
375 widget_class->focus = gtk_toolbar_focus;
377 /* need to override the base class function via override_class_handler,
378 * because the signal slot is not available in GtkWidgetClass
380 g_signal_override_class_handler ("move-focus",
382 G_CALLBACK (gtk_toolbar_move_focus));
384 widget_class->screen_changed = gtk_toolbar_screen_changed;
385 widget_class->realize = gtk_toolbar_realize;
386 widget_class->unrealize = gtk_toolbar_unrealize;
387 widget_class->map = gtk_toolbar_map;
388 widget_class->unmap = gtk_toolbar_unmap;
389 widget_class->popup_menu = gtk_toolbar_popup_menu;
390 widget_class->show_all = gtk_toolbar_show_all;
392 container_class->add = gtk_toolbar_add;
393 container_class->remove = gtk_toolbar_remove;
394 container_class->forall = gtk_toolbar_forall;
395 container_class->child_type = gtk_toolbar_child_type;
396 container_class->get_child_property = gtk_toolbar_get_child_property;
397 container_class->set_child_property = gtk_toolbar_set_child_property;
399 klass->orientation_changed = gtk_toolbar_orientation_changed;
400 klass->style_changed = gtk_toolbar_real_style_changed;
403 * GtkToolbar::orientation-changed:
404 * @toolbar: the object which emitted the signal
405 * @orientation: the new #GtkOrientation of the toolbar
407 * Emitted when the orientation of the toolbar changes.
409 toolbar_signals[ORIENTATION_CHANGED] =
410 g_signal_new (I_("orientation-changed"),
411 G_OBJECT_CLASS_TYPE (klass),
413 G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
415 g_cclosure_marshal_VOID__ENUM,
417 GTK_TYPE_ORIENTATION);
419 * GtkToolbar::style-changed:
420 * @toolbar: The #GtkToolbar which emitted the signal
421 * @style: the new #GtkToolbarStyle of the toolbar
423 * Emitted when the style of the toolbar changes.
425 toolbar_signals[STYLE_CHANGED] =
426 g_signal_new (I_("style-changed"),
427 G_OBJECT_CLASS_TYPE (klass),
429 G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
431 g_cclosure_marshal_VOID__ENUM,
433 GTK_TYPE_TOOLBAR_STYLE);
435 * GtkToolbar::popup-context-menu:
436 * @toolbar: the #GtkToolbar which emitted the signal
437 * @x: the x coordinate of the point where the menu should appear
438 * @y: the y coordinate of the point where the menu should appear
439 * @button: the mouse button the user pressed, or -1
441 * Emitted when the user right-clicks the toolbar or uses the
442 * keybinding to display a popup menu.
444 * Application developers should handle this signal if they want
445 * to display a context menu on the toolbar. The context-menu should
446 * appear at the coordinates given by @x and @y. The mouse button
447 * number is given by the @button parameter. If the menu was popped
448 * up using the keybaord, @button is -1.
450 * Return value: return %TRUE if the signal was handled, %FALSE if not
452 toolbar_signals[POPUP_CONTEXT_MENU] =
453 g_signal_new (I_("popup-context-menu"),
454 G_OBJECT_CLASS_TYPE (klass),
456 G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
457 _gtk_boolean_handled_accumulator, NULL,
458 _gtk_marshal_BOOLEAN__INT_INT_INT,
460 G_TYPE_INT, G_TYPE_INT,
464 * GtkToolbar::focus-home-or-end:
465 * @toolbar: the #GtkToolbar which emitted the signal
466 * @focus_home: %TRUE if the first item should be focused
468 * A keybinding signal used internally by GTK+. This signal can't
469 * be used in application code
471 * Return value: %TRUE if the signal was handled, %FALSE if not
473 toolbar_signals[FOCUS_HOME_OR_END] =
474 g_signal_new_class_handler (I_("focus-home-or-end"),
475 G_OBJECT_CLASS_TYPE (klass),
476 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
477 G_CALLBACK (gtk_toolbar_focus_home_or_end),
479 _gtk_marshal_BOOLEAN__BOOLEAN,
484 g_object_class_override_property (gobject_class,
488 g_object_class_install_property (gobject_class,
490 g_param_spec_enum ("toolbar-style",
492 P_("How to draw the toolbar"),
493 GTK_TYPE_TOOLBAR_STYLE,
494 DEFAULT_TOOLBAR_STYLE,
495 GTK_PARAM_READWRITE));
496 g_object_class_install_property (gobject_class,
498 g_param_spec_boolean ("show-arrow",
500 P_("If an arrow should be shown if the toolbar doesn't fit"),
502 GTK_PARAM_READWRITE));
505 * GtkToolbar:icon-size:
507 * The size of the icons in a toolbar is normally determined by
508 * the toolbar-icon-size setting. When this property is set, it
509 * overrides the setting.
511 * This should only be used for special-purpose toolbars, normal
512 * application toolbars should respect the user preferences for the
517 g_object_class_install_property (gobject_class,
519 g_param_spec_int ("icon-size",
521 P_("Size of icons in this toolbar"),
524 GTK_PARAM_READWRITE));
527 * GtkToolbar:icon-size-set:
529 * Is %TRUE if the icon-size property has been set.
533 g_object_class_install_property (gobject_class,
535 g_param_spec_boolean ("icon-size-set",
537 P_("Whether the icon-size property has been set"),
539 GTK_PARAM_READWRITE));
541 /* child properties */
542 gtk_container_class_install_child_property (container_class,
544 g_param_spec_boolean ("expand",
546 P_("Whether the item should receive extra space when the toolbar grows"),
548 GTK_PARAM_READWRITE));
550 gtk_container_class_install_child_property (container_class,
551 CHILD_PROP_HOMOGENEOUS,
552 g_param_spec_boolean ("homogeneous",
554 P_("Whether the item should be the same size as other homogeneous items"),
556 GTK_PARAM_READWRITE));
558 /* style properties */
559 gtk_widget_class_install_style_property (widget_class,
560 g_param_spec_int ("space-size",
562 P_("Size of spacers"),
566 GTK_PARAM_READABLE));
568 gtk_widget_class_install_style_property (widget_class,
569 g_param_spec_int ("internal-padding",
570 P_("Internal padding"),
571 P_("Amount of border space between the toolbar shadow and the buttons"),
575 GTK_PARAM_READABLE));
577 gtk_widget_class_install_style_property (widget_class,
578 g_param_spec_int ("max-child-expand",
579 P_("Maximum child expand"),
580 P_("Maximum amount of space an expandable item will be given"),
584 GTK_PARAM_READABLE));
586 gtk_widget_class_install_style_property (widget_class,
587 g_param_spec_enum ("space-style",
589 P_("Whether spacers are vertical lines or just blank"),
590 GTK_TYPE_TOOLBAR_SPACE_STYLE,
592 GTK_PARAM_READABLE));
594 gtk_widget_class_install_style_property (widget_class,
595 g_param_spec_enum ("button-relief",
597 P_("Type of bevel around toolbar buttons"),
598 GTK_TYPE_RELIEF_STYLE,
600 GTK_PARAM_READABLE));
601 gtk_widget_class_install_style_property (widget_class,
602 g_param_spec_enum ("shadow-type",
604 P_("Style of bevel around the toolbar"),
605 GTK_TYPE_SHADOW_TYPE,
607 GTK_PARAM_READABLE));
609 binding_set = gtk_binding_set_by_class (klass);
611 add_arrow_bindings (binding_set, GDK_KEY_Left, GTK_DIR_LEFT);
612 add_arrow_bindings (binding_set, GDK_KEY_Right, GTK_DIR_RIGHT);
613 add_arrow_bindings (binding_set, GDK_KEY_Up, GTK_DIR_UP);
614 add_arrow_bindings (binding_set, GDK_KEY_Down, GTK_DIR_DOWN);
616 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Home, 0,
617 "focus-home-or-end", 1,
618 G_TYPE_BOOLEAN, TRUE);
619 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Home, 0,
620 "focus-home-or-end", 1,
621 G_TYPE_BOOLEAN, TRUE);
622 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_End, 0,
623 "focus-home-or-end", 1,
624 G_TYPE_BOOLEAN, FALSE);
625 gtk_binding_entry_add_signal (binding_set, GDK_KEY_End, 0,
626 "focus-home-or-end", 1,
627 G_TYPE_BOOLEAN, FALSE);
629 add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
630 add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
632 g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));
636 toolbar_tool_shell_iface_init (GtkToolShellIface *iface)
638 iface->get_icon_size = toolbar_get_icon_size;
639 iface->get_orientation = toolbar_get_orientation;
640 iface->get_style = toolbar_get_style;
641 iface->get_relief_style = toolbar_get_relief_style;
642 iface->rebuild_menu = toolbar_rebuild_menu;
646 gtk_toolbar_init (GtkToolbar *toolbar)
648 GtkToolbarPrivate *priv;
650 toolbar->priv = G_TYPE_INSTANCE_GET_PRIVATE (toolbar,
653 priv = toolbar->priv;
655 gtk_widget_set_can_focus (GTK_WIDGET (toolbar), FALSE);
656 gtk_widget_set_has_window (GTK_WIDGET (toolbar), FALSE);
658 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
659 priv->style = DEFAULT_TOOLBAR_STYLE;
660 priv->icon_size = DEFAULT_ICON_SIZE;
661 priv->animation = DEFAULT_ANIMATION_STATE;
663 priv->arrow_button = gtk_toggle_button_new ();
664 g_signal_connect (priv->arrow_button, "button-press-event",
665 G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar);
666 g_signal_connect (priv->arrow_button, "clicked",
667 G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar);
668 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
669 get_button_relief (toolbar));
671 gtk_button_set_focus_on_click (GTK_BUTTON (priv->arrow_button), FALSE);
673 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
674 gtk_widget_set_name (priv->arrow, "gtk-toolbar-arrow");
675 gtk_widget_show (priv->arrow);
676 gtk_container_add (GTK_CONTAINER (priv->arrow_button), priv->arrow);
678 gtk_widget_set_parent (priv->arrow_button, GTK_WIDGET (toolbar));
680 /* which child position a drop will occur at */
682 priv->show_arrow = TRUE;
683 priv->settings = NULL;
685 priv->max_homogeneous_pixels = -1;
687 priv->timer = g_timer_new ();
691 gtk_toolbar_set_property (GObject *object,
696 GtkToolbar *toolbar = GTK_TOOLBAR (object);
697 GtkToolbarPrivate *priv = toolbar->priv;
701 case PROP_ORIENTATION:
702 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0,
703 g_value_get_enum (value));
705 case PROP_TOOLBAR_STYLE:
706 gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
708 case PROP_SHOW_ARROW:
709 gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
712 gtk_toolbar_set_icon_size (toolbar, g_value_get_int (value));
714 case PROP_ICON_SIZE_SET:
715 if (g_value_get_boolean (value))
716 priv->icon_size_set = TRUE;
718 gtk_toolbar_unset_icon_size (toolbar);
721 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
727 gtk_toolbar_get_property (GObject *object,
732 GtkToolbar *toolbar = GTK_TOOLBAR (object);
733 GtkToolbarPrivate *priv = toolbar->priv;
737 case PROP_ORIENTATION:
738 g_value_set_enum (value, priv->orientation);
740 case PROP_TOOLBAR_STYLE:
741 g_value_set_enum (value, priv->style);
743 case PROP_SHOW_ARROW:
744 g_value_set_boolean (value, priv->show_arrow);
747 g_value_set_int (value, gtk_toolbar_get_icon_size (toolbar));
749 case PROP_ICON_SIZE_SET:
750 g_value_set_boolean (value, priv->icon_size_set);
753 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
759 gtk_toolbar_map (GtkWidget *widget)
761 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
762 GtkToolbarPrivate *priv = toolbar->priv;
764 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->map (widget);
766 if (priv->event_window)
767 gdk_window_show_unraised (priv->event_window);
771 gtk_toolbar_unmap (GtkWidget *widget)
773 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
774 GtkToolbarPrivate *priv = toolbar->priv;
776 if (priv->event_window)
777 gdk_window_hide (priv->event_window);
779 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unmap (widget);
783 gtk_toolbar_realize (GtkWidget *widget)
785 GtkAllocation allocation;
786 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
787 GtkToolbarPrivate *priv = toolbar->priv;
789 GdkWindowAttr attributes;
790 gint attributes_mask;
793 gtk_widget_set_realized (widget, TRUE);
795 gtk_widget_get_allocation (widget, &allocation);
796 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
798 attributes.wclass = GDK_INPUT_ONLY;
799 attributes.window_type = GDK_WINDOW_CHILD;
800 attributes.x = allocation.x + border_width;
801 attributes.y = allocation.y + border_width;
802 attributes.width = allocation.width - border_width * 2;
803 attributes.height = allocation.height - border_width * 2;
804 attributes.event_mask = gtk_widget_get_events (widget);
805 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
806 GDK_BUTTON_RELEASE_MASK |
807 GDK_ENTER_NOTIFY_MASK |
808 GDK_LEAVE_NOTIFY_MASK);
810 attributes_mask = GDK_WA_X | GDK_WA_Y;
812 window = gtk_widget_get_parent_window (widget);
813 gtk_widget_set_window (widget, window);
814 g_object_ref (window);
816 gtk_widget_style_attach (widget);
818 priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
819 &attributes, attributes_mask);
820 gdk_window_set_user_data (priv->event_window, toolbar);
824 gtk_toolbar_unrealize (GtkWidget *widget)
826 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
827 GtkToolbarPrivate *priv = toolbar->priv;
829 if (priv->event_window)
831 gdk_window_set_user_data (priv->event_window, NULL);
832 gdk_window_destroy (priv->event_window);
833 priv->event_window = NULL;
836 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize (widget);
840 gtk_toolbar_draw (GtkWidget *widget,
843 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
844 GtkToolbarPrivate *priv = toolbar->priv;
848 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
850 gtk_paint_box (gtk_widget_get_style (widget),
852 gtk_widget_get_state (widget),
853 get_shadow_type (toolbar),
857 gtk_widget_get_allocated_width (widget) - 2 * border_width,
858 gtk_widget_get_allocated_height (widget) - 2 * border_width);
860 for (list = priv->content; list != NULL; list = list->next)
862 ToolbarContent *content = list->data;
864 toolbar_content_draw (content, GTK_CONTAINER (widget), cr);
867 gtk_container_propagate_draw (GTK_CONTAINER (widget),
875 gtk_toolbar_size_request (GtkWidget *widget,
876 GtkRequisition *requisition)
878 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
879 GtkToolbarPrivate *priv = toolbar->priv;
881 gint max_child_height;
882 gint max_child_width;
883 gint max_homogeneous_child_width;
884 gint max_homogeneous_child_height;
885 gint homogeneous_size;
887 gint pack_front_size;
890 GtkRequisition arrow_requisition;
892 max_homogeneous_child_width = 0;
893 max_homogeneous_child_height = 0;
895 max_child_height = 0;
896 for (list = priv->content; list != NULL; list = list->next)
898 GtkRequisition requisition;
899 ToolbarContent *content = list->data;
901 if (!toolbar_content_visible (content, toolbar))
904 toolbar_content_size_request (content, toolbar, &requisition);
906 max_child_width = MAX (max_child_width, requisition.width);
907 max_child_height = MAX (max_child_height, requisition.height);
909 if (toolbar_content_is_homogeneous (content, toolbar))
911 max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
912 max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
916 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
917 homogeneous_size = max_homogeneous_child_width;
919 homogeneous_size = max_homogeneous_child_height;
922 for (list = priv->content; list != NULL; list = list->next)
924 ToolbarContent *content = list->data;
927 if (!toolbar_content_visible (content, toolbar))
930 if (toolbar_content_is_homogeneous (content, toolbar))
932 size = homogeneous_size;
936 GtkRequisition requisition;
938 toolbar_content_size_request (content, toolbar, &requisition);
940 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
941 size = requisition.width;
943 size = requisition.height;
946 pack_front_size += size;
949 if (priv->show_arrow)
951 gtk_widget_get_preferred_size (priv->arrow_button,
952 &arrow_requisition, NULL);
954 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
955 long_req = arrow_requisition.width;
957 long_req = arrow_requisition.height;
959 /* There is no point requesting space for the arrow if that would take
960 * up more space than all the items combined
962 long_req = MIN (long_req, pack_front_size);
966 arrow_requisition.height = 0;
967 arrow_requisition.width = 0;
969 long_req = pack_front_size;
972 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
974 requisition->width = long_req;
975 requisition->height = MAX (max_child_height, arrow_requisition.height);
979 requisition->height = long_req;
980 requisition->width = MAX (max_child_width, arrow_requisition.width);
984 ipadding = get_internal_padding (toolbar);
986 border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
987 requisition->width += 2 * (ipadding + border_width);
988 requisition->height += 2 * (ipadding + border_width);
990 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
994 style = gtk_widget_get_style (widget);
995 requisition->width += 2 * style->xthickness;
996 requisition->height += 2 * style->ythickness;
999 priv->button_maxw = max_homogeneous_child_width;
1000 priv->button_maxh = max_homogeneous_child_height;
1004 gtk_toolbar_get_preferred_width (GtkWidget *widget,
1008 GtkRequisition requisition;
1010 gtk_toolbar_size_request (widget, &requisition);
1012 *minimum = *natural = requisition.width;
1016 gtk_toolbar_get_preferred_height (GtkWidget *widget,
1020 GtkRequisition requisition;
1022 gtk_toolbar_size_request (widget, &requisition);
1024 *minimum = *natural = requisition.height;
1028 position (GtkToolbar *toolbar,
1033 GtkToolbarPrivate *priv = toolbar->priv;
1036 if (!priv->animation)
1039 if (elapsed <= ACCEL_THRESHOLD)
1041 n_pixels = SLIDE_SPEED * elapsed;
1045 /* The formula is a second degree polynomial in
1046 * @elapsed that has the line SLIDE_SPEED * @elapsed
1047 * as tangent for @elapsed == ACCEL_THRESHOLD.
1048 * This makes @n_pixels a smooth function of elapsed time.
1050 n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
1051 SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
1055 return MIN (from + n_pixels, to);
1057 return MAX (from - n_pixels, to);
1061 compute_intermediate_allocation (GtkToolbar *toolbar,
1062 const GtkAllocation *start,
1063 const GtkAllocation *goal,
1064 GtkAllocation *intermediate)
1066 GtkToolbarPrivate *priv = toolbar->priv;
1067 gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
1069 intermediate->x = position (toolbar, start->x, goal->x, elapsed);
1070 intermediate->y = position (toolbar, start->y, goal->y, elapsed);
1071 intermediate->width = position (toolbar, start->x + start->width,
1072 goal->x + goal->width,
1073 elapsed) - intermediate->x;
1074 intermediate->height = position (toolbar, start->y + start->height,
1075 goal->y + goal->height,
1076 elapsed) - intermediate->y;
1080 fixup_allocation_for_rtl (gint total_size,
1081 GtkAllocation *allocation)
1083 allocation->x += (total_size - (2 * allocation->x + allocation->width));
1087 fixup_allocation_for_vertical (GtkAllocation *allocation)
1091 tmp = allocation->x;
1092 allocation->x = allocation->y;
1093 allocation->y = tmp;
1095 tmp = allocation->width;
1096 allocation->width = allocation->height;
1097 allocation->height = tmp;
1101 get_item_size (GtkToolbar *toolbar,
1102 ToolbarContent *content)
1104 GtkToolbarPrivate *priv = toolbar->priv;
1105 GtkRequisition requisition;
1107 toolbar_content_size_request (content, toolbar, &requisition);
1109 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1111 if (toolbar_content_is_homogeneous (content, toolbar))
1112 return priv->button_maxw;
1114 return requisition.width;
1118 if (toolbar_content_is_homogeneous (content, toolbar))
1119 return priv->button_maxh;
1121 return requisition.height;
1126 slide_idle_handler (gpointer data)
1128 GtkToolbar *toolbar = GTK_TOOLBAR (data);
1129 GtkToolbarPrivate *priv = toolbar->priv;
1132 if (priv->need_sync)
1135 priv->need_sync = FALSE;
1138 for (list = priv->content; list != NULL; list = list->next)
1140 ToolbarContent *content = list->data;
1142 GtkAllocation goal_allocation;
1143 GtkAllocation allocation;
1146 state = toolbar_content_get_state (content);
1147 toolbar_content_get_goal_allocation (content, &goal_allocation);
1148 toolbar_content_get_allocation (content, &allocation);
1152 if (state == NOT_ALLOCATED)
1154 /* an unallocated item means that size allocate has to
1155 * called at least once more
1160 /* An invisible item with a goal allocation of
1161 * 0 is already at its goal.
1163 if ((state == NORMAL || state == OVERFLOWN) &&
1164 ((goal_allocation.width != 0 &&
1165 goal_allocation.height != 0) ||
1166 toolbar_content_child_visible (content)))
1168 if ((goal_allocation.x != allocation.x ||
1169 goal_allocation.y != allocation.y ||
1170 goal_allocation.width != allocation.width ||
1171 goal_allocation.height != allocation.height))
1173 /* An item is not in its right position yet. Note
1174 * that OVERFLOWN items do get an allocation in
1175 * gtk_toolbar_size_allocate(). This way you can see
1176 * them slide back in when you drag an item off the
1183 if (toolbar_content_is_placeholder (content) &&
1184 toolbar_content_disappearing (content) &&
1185 toolbar_content_child_visible (content))
1187 /* A disappearing placeholder is still visible.
1195 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1201 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1203 priv->is_sliding = FALSE;
1210 rect_within (GtkAllocation *a1,
1213 return (a1->x >= a2->x &&
1214 a1->x + a1->width <= a2->x + a2->width &&
1216 a1->y + a1->height <= a2->y + a2->height);
1220 gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
1222 GtkAllocation allocation;
1223 GtkWidget *widget = GTK_WIDGET (toolbar);
1224 GtkToolbarPrivate *priv = toolbar->priv;
1233 /* Start the sliding. This function copies the allocation of every
1234 * item into content->start_allocation. For items that haven't
1235 * been allocated yet, we calculate their position and save that
1236 * in start_allocatino along with zero width and zero height.
1238 * FIXME: It would be nice if we could share this code with
1239 * the equivalent in gtk_widget_size_allocate().
1241 priv->is_sliding = TRUE;
1244 priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
1246 gtk_widget_get_allocation (widget, &allocation);
1247 style = gtk_widget_get_style (widget);
1249 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1250 vertical = (priv->orientation == GTK_ORIENTATION_VERTICAL);
1251 border_width = get_internal_padding (toolbar) + gtk_container_get_border_width (GTK_CONTAINER (toolbar));
1255 cur_x = allocation.width - border_width - style->xthickness;
1256 cur_y = allocation.height - border_width - style->ythickness;
1260 cur_x = border_width + style->xthickness;
1261 cur_y = border_width + style->ythickness;
1264 cur_x += allocation.x;
1265 cur_y += allocation.y;
1267 for (list = priv->content; list != NULL; list = list->next)
1269 ToolbarContent *content = list->data;
1270 GtkAllocation new_start_allocation;
1271 GtkAllocation item_allocation;
1274 state = toolbar_content_get_state (content);
1275 toolbar_content_get_allocation (content, &item_allocation);
1277 if ((state == NORMAL &&
1278 rect_within (&item_allocation, &allocation)) ||
1281 new_start_allocation = item_allocation;
1285 new_start_allocation.x = cur_x;
1286 new_start_allocation.y = cur_y;
1290 new_start_allocation.width = allocation.width -
1291 2 * border_width - 2 * style->xthickness;
1292 new_start_allocation.height = 0;
1296 new_start_allocation.width = 0;
1297 new_start_allocation.height = allocation.height -
1298 2 * border_width - 2 * style->ythickness;
1303 cur_y = new_start_allocation.y + new_start_allocation.height;
1305 cur_x = new_start_allocation.x;
1307 cur_x = new_start_allocation.x + new_start_allocation.width;
1309 toolbar_content_set_start_allocation (content, &new_start_allocation);
1312 /* This resize will run before the first idle handler. This
1313 * will make sure that items get the right goal allocation
1314 * so that the idle handler will not immediately return
1317 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1318 g_timer_reset (priv->timer);
1322 gtk_toolbar_stop_sliding (GtkToolbar *toolbar)
1324 GtkToolbarPrivate *priv = toolbar->priv;
1326 if (priv->is_sliding)
1330 priv->is_sliding = FALSE;
1334 g_source_remove (priv->idle_id);
1338 list = priv->content;
1341 ToolbarContent *content = list->data;
1344 if (toolbar_content_is_placeholder (content))
1346 toolbar_content_remove (content, toolbar);
1347 toolbar_content_free (content);
1351 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1356 remove_item (GtkWidget *menu_item,
1359 gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (menu_item)),
1364 menu_deactivated (GtkWidget *menu,
1365 GtkToolbar *toolbar)
1367 GtkToolbarPrivate *priv = toolbar->priv;
1369 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->arrow_button), FALSE);
1373 menu_detached (GtkWidget *widget,
1376 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1377 GtkToolbarPrivate *priv = toolbar->priv;
1383 rebuild_menu (GtkToolbar *toolbar)
1385 GtkToolbarPrivate *priv = toolbar->priv;
1386 GList *list, *children;
1390 priv->menu = GTK_MENU (gtk_menu_new());
1391 gtk_menu_attach_to_widget (priv->menu,
1392 GTK_WIDGET (toolbar),
1395 g_signal_connect (priv->menu, "deactivate",
1396 G_CALLBACK (menu_deactivated), toolbar);
1399 gtk_container_foreach (GTK_CONTAINER (priv->menu), remove_item, NULL);
1401 for (list = priv->content; list != NULL; list = list->next)
1403 ToolbarContent *content = list->data;
1405 if (toolbar_content_get_state (content) == OVERFLOWN &&
1406 !toolbar_content_is_placeholder (content))
1408 GtkWidget *menu_item = toolbar_content_retrieve_menu_item (content);
1412 g_assert (GTK_IS_MENU_ITEM (menu_item));
1413 gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item);
1418 /* Remove leading and trailing separator items */
1419 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1422 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1424 GtkWidget *child = list->data;
1426 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1429 g_list_free (children);
1431 /* Regenerate the list of children so we don't try to remove items twice */
1432 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1434 list = g_list_last (children);
1435 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1437 GtkWidget *child = list->data;
1439 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1442 g_list_free (children);
1444 priv->need_rebuild = FALSE;
1448 gtk_toolbar_size_allocate (GtkWidget *widget,
1449 GtkAllocation *allocation)
1451 GtkAllocation widget_allocation;
1452 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1453 GtkToolbarPrivate *priv = toolbar->priv;
1454 GtkAllocation *allocations;
1455 ItemState *new_states;
1456 GtkAllocation arrow_allocation;
1459 gint size, pos, short_size;
1462 gboolean need_arrow;
1463 gint n_expand_items;
1465 gint available_size;
1468 GtkRequisition arrow_requisition;
1469 gboolean overflowing;
1470 gboolean size_changed;
1472 GtkAllocation item_area;
1473 GtkShadowType shadow_type;
1475 style = gtk_widget_get_style (widget);
1477 gtk_widget_get_allocation (widget, &widget_allocation);
1478 size_changed = FALSE;
1479 if (widget_allocation.x != allocation->x ||
1480 widget_allocation.y != allocation->y ||
1481 widget_allocation.width != allocation->width ||
1482 widget_allocation.height != allocation->height)
1484 size_changed = TRUE;
1488 gtk_toolbar_stop_sliding (toolbar);
1490 gtk_widget_set_allocation (widget, allocation);
1492 border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
1494 if (gtk_widget_get_realized (widget))
1496 gdk_window_move_resize (priv->event_window,
1497 allocation->x + border_width,
1498 allocation->y + border_width,
1499 allocation->width - border_width * 2,
1500 allocation->height - border_width * 2);
1503 border_width += get_internal_padding (toolbar);
1505 gtk_widget_get_preferred_size (priv->arrow_button,
1506 &arrow_requisition, NULL);
1508 shadow_type = get_shadow_type (toolbar);
1510 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1512 available_size = size = allocation->width - 2 * border_width;
1513 short_size = allocation->height - 2 * border_width;
1514 arrow_size = arrow_requisition.width;
1516 if (shadow_type != GTK_SHADOW_NONE)
1518 available_size -= 2 * style->xthickness;
1519 short_size -= 2 * style->ythickness;
1524 available_size = size = allocation->height - 2 * border_width;
1525 short_size = allocation->width - 2 * border_width;
1526 arrow_size = arrow_requisition.height;
1528 if (shadow_type != GTK_SHADOW_NONE)
1530 available_size -= 2 * style->ythickness;
1531 short_size -= 2 * style->xthickness;
1535 n_items = g_list_length (priv->content);
1536 allocations = g_new0 (GtkAllocation, n_items);
1537 new_states = g_new0 (ItemState, n_items);
1541 for (list = priv->content; list != NULL; list = list->next)
1543 ToolbarContent *content = list->data;
1545 if (toolbar_content_visible (content, toolbar))
1547 needed_size += get_item_size (toolbar, content);
1549 /* Do we need an arrow?
1551 * Assume we don't, and see if any non-separator item with a
1552 * proxy menu item is then going to overflow.
1554 if (needed_size > available_size &&
1557 toolbar_content_has_proxy_menu_item (content) &&
1558 !toolbar_content_is_separator (content))
1566 size = available_size - arrow_size;
1568 size = available_size;
1570 /* calculate widths and states of items */
1571 overflowing = FALSE;
1572 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1574 ToolbarContent *content = list->data;
1577 if (!toolbar_content_visible (content, toolbar))
1579 new_states[i] = HIDDEN;
1583 item_size = get_item_size (toolbar, content);
1584 if (item_size <= size && !overflowing)
1587 allocations[i].width = item_size;
1588 new_states[i] = NORMAL;
1593 new_states[i] = OVERFLOWN;
1594 allocations[i].width = item_size;
1598 /* calculate width of arrow */
1601 arrow_allocation.width = arrow_size;
1602 arrow_allocation.height = MAX (short_size, 1);
1605 /* expand expandable items */
1607 /* We don't expand when there is an overflow menu, because that leads to
1608 * weird jumps when items get moved to the overflow menu and the expanding
1609 * items suddenly get a lot of extra space
1613 gint max_child_expand;
1616 for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
1618 ToolbarContent *content = list->data;
1620 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1624 max_child_expand = get_max_child_expand (toolbar);
1625 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1627 ToolbarContent *content = list->data;
1629 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1631 gint extra = size / n_expand_items;
1632 if (size % n_expand_items != 0)
1635 if (extra > max_child_expand)
1636 extra = max_child_expand;
1638 allocations[i].width += extra;
1644 g_assert (n_expand_items == 0);
1647 /* position items */
1649 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1651 /* both NORMAL and OVERFLOWN items get a position. This ensures
1652 * that sliding will work for OVERFLOWN items too
1654 if (new_states[i] == NORMAL ||
1655 new_states[i] == OVERFLOWN)
1657 allocations[i].x = pos;
1658 allocations[i].y = border_width;
1659 allocations[i].height = short_size;
1661 pos += allocations[i].width;
1665 /* position arrow */
1668 arrow_allocation.x = available_size - border_width - arrow_allocation.width;
1669 arrow_allocation.y = border_width;
1672 item_area.x = border_width;
1673 item_area.y = border_width;
1674 item_area.width = available_size - (need_arrow? arrow_size : 0);
1675 item_area.height = short_size;
1677 /* fix up allocations in the vertical or RTL cases */
1678 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
1680 for (i = 0; i < n_items; ++i)
1681 fixup_allocation_for_vertical (&(allocations[i]));
1684 fixup_allocation_for_vertical (&arrow_allocation);
1686 fixup_allocation_for_vertical (&item_area);
1688 else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1690 for (i = 0; i < n_items; ++i)
1691 fixup_allocation_for_rtl (available_size, &(allocations[i]));
1694 fixup_allocation_for_rtl (available_size, &arrow_allocation);
1696 fixup_allocation_for_rtl (available_size, &item_area);
1699 /* translate the items by allocation->(x,y) */
1700 for (i = 0; i < n_items; ++i)
1702 allocations[i].x += allocation->x;
1703 allocations[i].y += allocation->y;
1705 if (shadow_type != GTK_SHADOW_NONE)
1707 allocations[i].x += style->xthickness;
1708 allocations[i].y += style->ythickness;
1714 arrow_allocation.x += allocation->x;
1715 arrow_allocation.y += allocation->y;
1717 if (shadow_type != GTK_SHADOW_NONE)
1719 arrow_allocation.x += style->xthickness;
1720 arrow_allocation.y += style->ythickness;
1724 item_area.x += allocation->x;
1725 item_area.y += allocation->y;
1726 if (shadow_type != GTK_SHADOW_NONE)
1728 item_area.x += style->xthickness;
1729 item_area.y += style->ythickness;
1732 /* did anything change? */
1733 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1735 ToolbarContent *content = list->data;
1737 if (toolbar_content_get_state (content) == NORMAL &&
1738 new_states[i] != NORMAL)
1740 /* an item disappeared and we didn't change size, so begin sliding */
1742 gtk_toolbar_begin_sliding (toolbar);
1746 /* finally allocate the items */
1747 if (priv->is_sliding)
1749 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1751 ToolbarContent *content = list->data;
1753 toolbar_content_set_goal_allocation (content, &(allocations[i]));
1757 elapsed = g_timer_elapsed (priv->timer, NULL);
1758 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1760 ToolbarContent *content = list->data;
1762 if (new_states[i] == OVERFLOWN ||
1763 new_states[i] == NORMAL)
1765 GtkAllocation alloc;
1766 GtkAllocation start_allocation = { 0, };
1767 GtkAllocation goal_allocation;
1769 if (priv->is_sliding)
1771 toolbar_content_get_start_allocation (content, &start_allocation);
1772 toolbar_content_get_goal_allocation (content, &goal_allocation);
1774 compute_intermediate_allocation (toolbar,
1779 priv->need_sync = TRUE;
1783 alloc = allocations[i];
1786 if (alloc.width <= 0 || alloc.height <= 0)
1788 toolbar_content_set_child_visible (content, toolbar, FALSE);
1792 if (!rect_within (&alloc, &item_area))
1794 toolbar_content_set_child_visible (content, toolbar, FALSE);
1795 toolbar_content_size_allocate (content, &alloc);
1799 toolbar_content_set_child_visible (content, toolbar, TRUE);
1800 toolbar_content_size_allocate (content, &alloc);
1806 toolbar_content_set_child_visible (content, toolbar, FALSE);
1809 toolbar_content_set_state (content, new_states[i]);
1812 if (priv->menu && priv->need_rebuild)
1813 rebuild_menu (toolbar);
1817 gtk_widget_size_allocate (GTK_WIDGET (priv->arrow_button),
1819 gtk_widget_show (GTK_WIDGET (priv->arrow_button));
1823 gtk_widget_hide (GTK_WIDGET (priv->arrow_button));
1825 if (priv->menu && gtk_widget_get_visible (GTK_WIDGET (priv->menu)))
1826 gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
1829 g_free (allocations);
1830 g_free (new_states);
1834 gtk_toolbar_update_button_relief (GtkToolbar *toolbar)
1836 GtkToolbarPrivate *priv = toolbar->priv;
1837 GtkReliefStyle relief;
1839 relief = get_button_relief (toolbar);
1841 if (relief != gtk_button_get_relief (GTK_BUTTON (priv->arrow_button)))
1843 gtk_toolbar_reconfigured (toolbar);
1845 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), relief);
1850 gtk_toolbar_style_set (GtkWidget *widget,
1851 GtkStyle *prev_style)
1853 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1854 GtkToolbarPrivate *priv = toolbar->priv;
1856 priv->max_homogeneous_pixels = -1;
1858 if (gtk_widget_get_realized (widget))
1859 gtk_style_set_background (gtk_widget_get_style (widget),
1860 gtk_widget_get_window (widget),
1861 gtk_widget_get_state (widget));
1864 gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
1868 gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
1869 GtkDirectionType dir)
1871 GtkToolbarPrivate *priv = toolbar->priv;
1872 GList *result = NULL;
1876 /* generate list of children in reverse logical order */
1878 for (list = priv->content; list != NULL; list = list->next)
1880 ToolbarContent *content = list->data;
1883 widget = toolbar_content_get_widget (content);
1886 result = g_list_prepend (result, widget);
1889 result = g_list_prepend (result, priv->arrow_button);
1891 rtl = (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL);
1893 /* move in logical order when
1895 * - dir is TAB_FORWARD
1897 * - in RTL mode and moving left or up
1899 * - in LTR mode and moving right or down
1901 if (dir == GTK_DIR_TAB_FORWARD ||
1902 (rtl && (dir == GTK_DIR_UP || dir == GTK_DIR_LEFT)) ||
1903 (!rtl && (dir == GTK_DIR_DOWN || dir == GTK_DIR_RIGHT)))
1905 result = g_list_reverse (result);
1912 gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
1913 gboolean focus_home)
1915 GList *children, *list;
1916 GtkDirectionType dir = focus_home? GTK_DIR_RIGHT : GTK_DIR_LEFT;
1918 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1920 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1922 children = g_list_reverse (children);
1924 dir = (dir == GTK_DIR_RIGHT)? GTK_DIR_LEFT : GTK_DIR_RIGHT;
1927 for (list = children; list != NULL; list = list->next)
1929 GtkWidget *child = list->data;
1931 if (gtk_container_get_focus_child (GTK_CONTAINER (toolbar)) == child)
1934 if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1938 g_list_free (children);
1943 /* Keybinding handler. This function is called when the user presses
1944 * Ctrl TAB or an arrow key.
1947 gtk_toolbar_move_focus (GtkWidget *widget,
1948 GtkDirectionType dir)
1950 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1951 GtkContainer *container = GTK_CONTAINER (toolbar);
1952 GtkWidget *focus_child;
1954 gboolean try_focus = FALSE;
1957 focus_child = gtk_container_get_focus_child (container);
1959 if (focus_child && gtk_widget_child_focus (focus_child, dir))
1962 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1964 for (list = children; list != NULL; list = list->next)
1966 GtkWidget *child = list->data;
1968 if (try_focus && gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1971 if (child == focus_child)
1975 g_list_free (children);
1978 /* The focus handler for the toolbar. It called when the user presses
1979 * TAB or otherwise tries to focus the toolbar.
1982 gtk_toolbar_focus (GtkWidget *widget,
1983 GtkDirectionType dir)
1985 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1986 GList *children, *list;
1987 gboolean result = FALSE;
1989 /* if focus is already somewhere inside the toolbar then return FALSE.
1990 * The only way focus can stay inside the toolbar is when the user presses
1991 * arrow keys or Ctrl TAB (both of which are handled by the
1992 * gtk_toolbar_move_focus() keybinding function.
1994 if (gtk_container_get_focus_child (GTK_CONTAINER (widget)))
1997 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1999 for (list = children; list != NULL; list = list->next)
2001 GtkWidget *child = list->data;
2003 if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
2010 g_list_free (children);
2015 static GtkSettings *
2016 toolbar_get_settings (GtkToolbar *toolbar)
2018 return toolbar->priv->settings;
2022 style_change_notify (GtkToolbar *toolbar)
2024 GtkToolbarPrivate *priv = toolbar->priv;
2026 if (!priv->style_set)
2028 /* pretend it was set, then unset, thus reverting to new default */
2029 priv->style_set = TRUE;
2030 gtk_toolbar_unset_style (toolbar);
2035 icon_size_change_notify (GtkToolbar *toolbar)
2037 GtkToolbarPrivate *priv = toolbar->priv;
2039 if (!priv->icon_size_set)
2041 /* pretend it was set, then unset, thus reverting to new default */
2042 priv->icon_size_set = TRUE;
2043 gtk_toolbar_unset_icon_size (toolbar);
2048 animation_change_notify (GtkToolbar *toolbar)
2050 GtkToolbarPrivate *priv = toolbar->priv;
2051 GtkSettings *settings = toolbar_get_settings (toolbar);
2055 g_object_get (settings,
2056 "gtk-enable-animations", &animation,
2059 animation = DEFAULT_ANIMATION_STATE;
2061 priv->animation = animation;
2065 settings_change_notify (GtkSettings *settings,
2066 const GParamSpec *pspec,
2067 GtkToolbar *toolbar)
2069 if (! strcmp (pspec->name, "gtk-toolbar-style"))
2070 style_change_notify (toolbar);
2071 else if (! strcmp (pspec->name, "gtk-toolbar-icon-size"))
2072 icon_size_change_notify (toolbar);
2073 else if (! strcmp (pspec->name, "gtk-enable-animations"))
2074 animation_change_notify (toolbar);
2078 gtk_toolbar_screen_changed (GtkWidget *widget,
2079 GdkScreen *previous_screen)
2081 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2082 GtkToolbarPrivate *priv = toolbar->priv;
2083 GtkSettings *old_settings = toolbar_get_settings (toolbar);
2084 GtkSettings *settings;
2086 if (gtk_widget_has_screen (GTK_WIDGET (toolbar)))
2087 settings = gtk_widget_get_settings (GTK_WIDGET (toolbar));
2091 if (settings == old_settings)
2096 g_signal_handler_disconnect (old_settings, priv->settings_connection);
2098 g_object_unref (old_settings);
2103 priv->settings_connection =
2104 g_signal_connect (settings, "notify",
2105 G_CALLBACK (settings_change_notify),
2108 priv->settings = g_object_ref (settings);
2111 priv->settings = NULL;
2113 style_change_notify (toolbar);
2114 icon_size_change_notify (toolbar);
2115 animation_change_notify (toolbar);
2119 find_drop_index (GtkToolbar *toolbar,
2123 GtkToolbarPrivate *priv = toolbar->priv;
2124 GList *interesting_content;
2126 GtkOrientation orientation;
2127 GtkTextDirection direction;
2128 gint best_distance = G_MAXINT;
2132 ToolbarContent *best_content;
2133 GtkAllocation allocation;
2135 /* list items we care about wrt. drag and drop */
2136 interesting_content = NULL;
2137 for (list = priv->content; list != NULL; list = list->next)
2139 ToolbarContent *content = list->data;
2141 if (toolbar_content_get_state (content) == NORMAL)
2142 interesting_content = g_list_prepend (interesting_content, content);
2144 interesting_content = g_list_reverse (interesting_content);
2146 if (!interesting_content)
2149 orientation = priv->orientation;
2150 direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
2152 /* distance to first interesting item */
2153 best_content = interesting_content->data;
2154 toolbar_content_get_allocation (best_content, &allocation);
2156 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2160 if (direction == GTK_TEXT_DIR_LTR)
2163 pos = allocation.x + allocation.width;
2171 best_content = NULL;
2172 best_distance = ABS (pos - cursor);
2174 /* distance to far end of each item */
2175 for (list = interesting_content; list != NULL; list = list->next)
2177 ToolbarContent *content = list->data;
2179 toolbar_content_get_allocation (content, &allocation);
2181 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2183 if (direction == GTK_TEXT_DIR_LTR)
2184 pos = allocation.x + allocation.width;
2190 pos = allocation.y + allocation.height;
2193 distance = ABS (pos - cursor);
2195 if (distance < best_distance)
2197 best_distance = distance;
2198 best_content = content;
2202 g_list_free (interesting_content);
2207 return g_list_index (priv->content, best_content) + 1;
2211 reset_all_placeholders (GtkToolbar *toolbar)
2213 GtkToolbarPrivate *priv = toolbar->priv;
2216 for (list = priv->content; list != NULL; list = list->next)
2218 ToolbarContent *content = list->data;
2219 if (toolbar_content_is_placeholder (content))
2220 toolbar_content_set_disappearing (content, TRUE);
2225 physical_to_logical (GtkToolbar *toolbar,
2228 GtkToolbarPrivate *priv = toolbar->priv;
2232 g_assert (physical >= 0);
2235 for (list = priv->content; list && physical > 0; list = list->next)
2237 ToolbarContent *content = list->data;
2239 if (!toolbar_content_is_placeholder (content))
2244 g_assert (physical == 0);
2250 logical_to_physical (GtkToolbar *toolbar,
2253 GtkToolbarPrivate *priv = toolbar->priv;
2257 g_assert (logical >= 0);
2260 for (list = priv->content; list; list = list->next)
2262 ToolbarContent *content = list->data;
2264 if (!toolbar_content_is_placeholder (content))
2274 g_assert (logical == 0);
2280 * gtk_toolbar_set_drop_highlight_item:
2281 * @toolbar: a #GtkToolbar
2282 * @tool_item: (allow-none): a #GtkToolItem, or %NULL to turn of highlighting
2283 * @index_: a position on @toolbar
2285 * Highlights @toolbar to give an idea of what it would look like
2286 * if @item was added to @toolbar at the position indicated by @index_.
2287 * If @item is %NULL, highlighting is turned off. In that case @index_
2290 * The @tool_item passed to this function must not be part of any widget
2291 * hierarchy. When an item is set as drop highlight item it can not
2292 * added to any widget hierarchy or used as highlight item for another
2298 gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar,
2299 GtkToolItem *tool_item,
2302 ToolbarContent *content;
2303 GtkToolbarPrivate *priv;
2305 GtkRequisition requisition;
2306 GtkRequisition old_requisition;
2307 gboolean restart_sliding;
2309 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2310 g_return_if_fail (tool_item == NULL || GTK_IS_TOOL_ITEM (tool_item));
2312 priv = toolbar->priv;
2316 if (priv->highlight_tool_item)
2318 gtk_widget_unparent (GTK_WIDGET (priv->highlight_tool_item));
2319 g_object_unref (priv->highlight_tool_item);
2320 priv->highlight_tool_item = NULL;
2323 reset_all_placeholders (toolbar);
2324 gtk_toolbar_begin_sliding (toolbar);
2328 n_items = gtk_toolbar_get_n_items (toolbar);
2329 if (index_ < 0 || index_ > n_items)
2332 if (tool_item != priv->highlight_tool_item)
2334 if (priv->highlight_tool_item)
2335 g_object_unref (priv->highlight_tool_item);
2337 g_object_ref_sink (tool_item);
2339 priv->highlight_tool_item = tool_item;
2341 gtk_widget_set_parent (GTK_WIDGET (priv->highlight_tool_item),
2342 GTK_WIDGET (toolbar));
2345 index_ = logical_to_physical (toolbar, index_);
2347 content = g_list_nth_data (priv->content, index_);
2351 ToolbarContent *prev_content;
2353 prev_content = g_list_nth_data (priv->content, index_ - 1);
2355 if (prev_content && toolbar_content_is_placeholder (prev_content))
2356 content = prev_content;
2359 if (!content || !toolbar_content_is_placeholder (content))
2361 GtkWidget *placeholder;
2363 placeholder = GTK_WIDGET (gtk_separator_tool_item_new ());
2365 content = toolbar_content_new_tool_item (toolbar,
2366 GTK_TOOL_ITEM (placeholder),
2368 gtk_widget_show (placeholder);
2372 g_assert (toolbar_content_is_placeholder (content));
2374 gtk_widget_get_preferred_size (GTK_WIDGET (priv->highlight_tool_item),
2375 &requisition, NULL);
2377 toolbar_content_set_expand (content, gtk_tool_item_get_expand (tool_item));
2379 restart_sliding = FALSE;
2380 toolbar_content_size_request (content, toolbar, &old_requisition);
2381 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2383 requisition.height = -1;
2384 if (requisition.width != old_requisition.width)
2385 restart_sliding = TRUE;
2389 requisition.width = -1;
2390 if (requisition.height != old_requisition.height)
2391 restart_sliding = TRUE;
2394 if (toolbar_content_disappearing (content))
2395 restart_sliding = TRUE;
2397 reset_all_placeholders (toolbar);
2398 toolbar_content_set_disappearing (content, FALSE);
2400 toolbar_content_set_size_request (content,
2401 requisition.width, requisition.height);
2403 if (restart_sliding)
2404 gtk_toolbar_begin_sliding (toolbar);
2408 gtk_toolbar_get_child_property (GtkContainer *container,
2414 GtkToolItem *item = GTK_TOOL_ITEM (child);
2416 switch (property_id)
2418 case CHILD_PROP_HOMOGENEOUS:
2419 g_value_set_boolean (value, gtk_tool_item_get_homogeneous (item));
2422 case CHILD_PROP_EXPAND:
2423 g_value_set_boolean (value, gtk_tool_item_get_expand (item));
2427 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2433 gtk_toolbar_set_child_property (GtkContainer *container,
2436 const GValue *value,
2439 switch (property_id)
2441 case CHILD_PROP_HOMOGENEOUS:
2442 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2445 case CHILD_PROP_EXPAND:
2446 gtk_tool_item_set_expand (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2450 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2456 gtk_toolbar_show_all (GtkWidget *widget)
2458 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2459 GtkToolbarPrivate *priv = toolbar->priv;
2462 for (list = priv->content; list != NULL; list = list->next)
2464 ToolbarContent *content = list->data;
2466 toolbar_content_show_all (content);
2469 gtk_widget_show (widget);
2473 gtk_toolbar_add (GtkContainer *container,
2476 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2478 gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
2482 gtk_toolbar_remove (GtkContainer *container,
2485 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2486 GtkToolbarPrivate *priv = toolbar->priv;
2487 ToolbarContent *content_to_remove;
2490 content_to_remove = NULL;
2491 for (list = priv->content; list != NULL; list = list->next)
2493 ToolbarContent *content = list->data;
2496 child = toolbar_content_get_widget (content);
2497 if (child && child == widget)
2499 content_to_remove = content;
2504 g_return_if_fail (content_to_remove != NULL);
2506 toolbar_content_remove (content_to_remove, toolbar);
2507 toolbar_content_free (content_to_remove);
2511 gtk_toolbar_forall (GtkContainer *container,
2512 gboolean include_internals,
2513 GtkCallback callback,
2514 gpointer callback_data)
2516 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2517 GtkToolbarPrivate *priv = toolbar->priv;
2520 g_return_if_fail (callback != NULL);
2522 list = priv->content;
2525 ToolbarContent *content = list->data;
2526 GList *next = list->next;
2528 if (include_internals || !toolbar_content_is_placeholder (content))
2530 GtkWidget *child = toolbar_content_get_widget (content);
2533 callback (child, callback_data);
2539 if (include_internals)
2540 callback (priv->arrow_button, callback_data);
2544 gtk_toolbar_child_type (GtkContainer *container)
2546 return GTK_TYPE_TOOL_ITEM;
2550 gtk_toolbar_reconfigured (GtkToolbar *toolbar)
2552 GtkToolbarPrivate *priv = toolbar->priv;
2555 list = priv->content;
2558 ToolbarContent *content = list->data;
2559 GList *next = list->next;
2561 toolbar_content_toolbar_reconfigured (content, toolbar);
2568 gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
2569 GtkOrientation orientation)
2571 GtkToolbarPrivate *priv = toolbar->priv;
2573 if (priv->orientation != orientation)
2575 priv->orientation = orientation;
2577 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2578 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2580 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2582 gtk_toolbar_reconfigured (toolbar);
2584 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2585 g_object_notify (G_OBJECT (toolbar), "orientation");
2590 gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
2591 GtkToolbarStyle style)
2593 GtkToolbarPrivate *priv = toolbar->priv;
2595 if (priv->style != style)
2597 priv->style = style;
2599 gtk_toolbar_reconfigured (toolbar);
2601 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2602 g_object_notify (G_OBJECT (toolbar), "toolbar-style");
2607 menu_position_func (GtkMenu *menu,
2613 GtkAllocation allocation;
2614 GtkToolbar *toolbar = GTK_TOOLBAR (user_data);
2615 GtkToolbarPrivate *priv = toolbar->priv;
2617 GtkRequisition menu_req;
2618 GdkRectangle monitor;
2622 gtk_widget_get_preferred_size (priv->arrow_button,
2624 gtk_widget_get_preferred_size (GTK_WIDGET (menu),
2627 screen = gtk_widget_get_screen (GTK_WIDGET (menu));
2628 monitor_num = gdk_screen_get_monitor_at_window (screen,
2629 gtk_widget_get_window (priv->arrow_button));
2630 if (monitor_num < 0)
2632 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2634 gtk_widget_get_allocation (priv->arrow_button, &allocation);
2636 gdk_window_get_origin (gtk_button_get_event_window (GTK_BUTTON (priv->arrow_button)), x, y);
2637 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2639 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2640 *x += allocation.width - req.width;
2642 *x += req.width - menu_req.width;
2644 if ((*y + allocation.height + menu_req.height) <= monitor.y + monitor.height)
2645 *y += allocation.height;
2646 else if ((*y - menu_req.height) >= monitor.y)
2647 *y -= menu_req.height;
2648 else if (monitor.y + monitor.height - (*y + allocation.height) > *y)
2649 *y += allocation.height;
2651 *y -= menu_req.height;
2655 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2656 *x += allocation.width;
2658 *x -= menu_req.width;
2660 if (*y + menu_req.height > monitor.y + monitor.height &&
2661 *y + allocation.height - monitor.y > monitor.y + monitor.height - *y)
2662 *y += allocation.height - menu_req.height;
2669 show_menu (GtkToolbar *toolbar,
2670 GdkEventButton *event)
2672 GtkToolbarPrivate *priv = toolbar->priv;
2674 rebuild_menu (toolbar);
2676 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2678 gtk_menu_popup (priv->menu, NULL, NULL,
2679 menu_position_func, toolbar,
2680 event? event->button : 0,
2681 event? event->time : gtk_get_current_event_time());
2685 gtk_toolbar_arrow_button_clicked (GtkWidget *button,
2686 GtkToolbar *toolbar)
2688 GtkToolbarPrivate *priv = toolbar->priv;
2690 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) &&
2691 (!priv->menu || !gtk_widget_get_visible (GTK_WIDGET (priv->menu))))
2693 /* We only get here when the button is clicked with the keyboard,
2694 * because mouse button presses result in the menu being shown so
2695 * that priv->menu would be non-NULL and visible.
2697 show_menu (toolbar, NULL);
2698 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
2703 gtk_toolbar_arrow_button_press (GtkWidget *button,
2704 GdkEventButton *event,
2705 GtkToolbar *toolbar)
2707 show_menu (toolbar, event);
2708 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
2714 gtk_toolbar_button_press (GtkWidget *toolbar,
2715 GdkEventButton *event)
2719 if (event->button == 3)
2721 gboolean return_value;
2723 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2724 (int)event->x_root, (int)event->y_root, event->button,
2727 return return_value;
2730 window = gtk_widget_get_toplevel (toolbar);
2734 gboolean window_drag = FALSE;
2736 gtk_widget_style_get (toolbar,
2737 "window-dragging", &window_drag,
2742 gtk_window_begin_move_drag (GTK_WINDOW (window),
2756 gtk_toolbar_popup_menu (GtkWidget *toolbar)
2758 gboolean return_value;
2759 /* This function is the handler for the "popup menu" keybinding,
2760 * ie., it is called when the user presses Shift F10
2762 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2763 -1, -1, -1, &return_value);
2765 return return_value;
2771 * Creates a new toolbar.
2773 * Return Value: the newly-created toolbar.
2776 gtk_toolbar_new (void)
2778 GtkToolbar *toolbar;
2780 toolbar = g_object_new (GTK_TYPE_TOOLBAR, NULL);
2782 return GTK_WIDGET (toolbar);
2786 * gtk_toolbar_insert:
2787 * @toolbar: a #GtkToolbar
2788 * @item: a #GtkToolItem
2789 * @pos: the position of the new item
2791 * Insert a #GtkToolItem into the toolbar at position @pos. If @pos is
2792 * 0 the item is prepended to the start of the toolbar. If @pos is
2793 * negative, the item is appended to the end of the toolbar.
2798 gtk_toolbar_insert (GtkToolbar *toolbar,
2802 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2803 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
2806 pos = logical_to_physical (toolbar, pos);
2808 toolbar_content_new_tool_item (toolbar, item, FALSE, pos);
2812 * gtk_toolbar_get_item_index:
2813 * @toolbar: a #GtkToolbar
2814 * @item: a #GtkToolItem that is a child of @toolbar
2816 * Returns the position of @item on the toolbar, starting from 0.
2817 * It is an error if @item is not a child of the toolbar.
2819 * Return value: the position of item on the toolbar.
2824 gtk_toolbar_get_item_index (GtkToolbar *toolbar,
2827 GtkToolbarPrivate *priv;
2831 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2832 g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
2833 g_return_val_if_fail (gtk_widget_get_parent (GTK_WIDGET (item)) == GTK_WIDGET (toolbar), -1);
2835 priv = toolbar->priv;
2838 for (list = priv->content; list != NULL; list = list->next)
2840 ToolbarContent *content = list->data;
2843 widget = toolbar_content_get_widget (content);
2845 if (item == GTK_TOOL_ITEM (widget))
2851 return physical_to_logical (toolbar, n);
2855 * gtk_toolbar_set_style:
2856 * @toolbar: a #GtkToolbar.
2857 * @style: the new style for @toolbar.
2859 * Alters the view of @toolbar to display either icons only, text only, or both.
2862 gtk_toolbar_set_style (GtkToolbar *toolbar,
2863 GtkToolbarStyle style)
2865 GtkToolbarPrivate *priv;
2867 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2869 priv = toolbar->priv;
2871 priv->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->priv->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 GtkToolbarPrivate *priv;
2903 GtkToolbarStyle style;
2905 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2907 priv = toolbar->priv;
2909 if (priv->style_set)
2911 GtkSettings *settings = toolbar_get_settings (toolbar);
2914 g_object_get (settings,
2915 "gtk-toolbar-style", &style,
2918 style = DEFAULT_TOOLBAR_STYLE;
2920 if (style != priv->style)
2921 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2923 priv->style_set = FALSE;
2928 * gtk_toolbar_get_n_items:
2929 * @toolbar: a #GtkToolbar
2931 * Returns the number of items on the toolbar.
2933 * Return value: the number of items on the toolbar
2938 gtk_toolbar_get_n_items (GtkToolbar *toolbar)
2940 GtkToolbarPrivate *priv;
2942 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2944 priv = toolbar->priv;
2946 return physical_to_logical (toolbar, g_list_length (priv->content));
2950 * gtk_toolbar_get_nth_item:
2951 * @toolbar: a #GtkToolbar
2952 * @n: A position on the toolbar
2954 * Returns the @n<!-- -->'th item on @toolbar, or %NULL if the
2955 * toolbar does not contain an @n<!-- -->'th item.
2957 * Return value: (transfer none): The @n<!-- -->'th #GtkToolItem on @toolbar,
2958 * or %NULL if there isn't an @n<!-- -->'th item.
2963 gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
2966 GtkToolbarPrivate *priv;
2967 ToolbarContent *content;
2970 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
2972 priv = toolbar->priv;
2974 n_items = gtk_toolbar_get_n_items (toolbar);
2976 if (n < 0 || n >= n_items)
2979 content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
2982 g_assert (!toolbar_content_is_placeholder (content));
2984 return GTK_TOOL_ITEM (toolbar_content_get_widget (content));
2988 * gtk_toolbar_get_icon_size:
2989 * @toolbar: a #GtkToolbar
2991 * Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size().
2993 * Return value: (type int): the current icon size for the icons on
2997 gtk_toolbar_get_icon_size (GtkToolbar *toolbar)
2999 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_ICON_SIZE);
3001 return toolbar->priv->icon_size;
3005 * gtk_toolbar_get_relief_style:
3006 * @toolbar: a #GtkToolbar
3008 * Returns the relief style of buttons on @toolbar. See
3009 * gtk_button_set_relief().
3011 * Return value: The relief style of buttons on @toolbar.
3016 gtk_toolbar_get_relief_style (GtkToolbar *toolbar)
3018 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_RELIEF_NONE);
3020 return get_button_relief (toolbar);
3024 * gtk_toolbar_set_show_arrow:
3025 * @toolbar: a #GtkToolbar
3026 * @show_arrow: Whether to show an overflow menu
3028 * Sets whether to show an overflow menu when
3029 * @toolbar doesn't have room for all items on it. If %TRUE,
3030 * items that there are not room are available through an
3036 gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
3037 gboolean show_arrow)
3039 GtkToolbarPrivate *priv;
3041 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3043 priv = toolbar->priv;
3045 show_arrow = show_arrow != FALSE;
3047 if (priv->show_arrow != show_arrow)
3049 priv->show_arrow = show_arrow;
3051 if (!priv->show_arrow)
3052 gtk_widget_hide (priv->arrow_button);
3054 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3055 g_object_notify (G_OBJECT (toolbar), "show-arrow");
3060 * gtk_toolbar_get_show_arrow:
3061 * @toolbar: a #GtkToolbar
3063 * Returns whether the toolbar has an overflow menu.
3064 * See gtk_toolbar_set_show_arrow().
3066 * Return value: %TRUE if the toolbar has an overflow menu.
3071 gtk_toolbar_get_show_arrow (GtkToolbar *toolbar)
3073 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
3075 return toolbar->priv->show_arrow;
3079 * gtk_toolbar_get_drop_index:
3080 * @toolbar: a #GtkToolbar
3081 * @x: x coordinate of a point on the toolbar
3082 * @y: y coordinate of a point on the toolbar
3084 * Returns the position corresponding to the indicated point on
3085 * @toolbar. This is useful when dragging items to the toolbar:
3086 * this function returns the position a new item should be
3089 * @x and @y are in @toolbar coordinates.
3091 * Return value: The position corresponding to the point (@x, @y) on the toolbar.
3096 gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
3100 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
3102 return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
3106 gtk_toolbar_finalize (GObject *object)
3109 GtkToolbar *toolbar = GTK_TOOLBAR (object);
3110 GtkToolbarPrivate *priv = toolbar->priv;
3112 if (priv->arrow_button)
3113 gtk_widget_unparent (priv->arrow_button);
3115 for (list = priv->content; list != NULL; list = list->next)
3117 ToolbarContent *content = list->data;
3119 toolbar_content_free (content);
3122 g_list_free (priv->content);
3123 g_list_free (priv->children);
3125 g_timer_destroy (priv->timer);
3128 gtk_widget_destroy (GTK_WIDGET (priv->menu));
3131 g_source_remove (priv->idle_id);
3133 G_OBJECT_CLASS (gtk_toolbar_parent_class)->finalize (object);
3137 * gtk_toolbar_set_icon_size:
3138 * @toolbar: A #GtkToolbar
3139 * @icon_size: (type int): The #GtkIconSize that stock icons in the
3140 * toolbar shall have.
3142 * This function sets the size of stock icons in the toolbar. You
3143 * can call it both before you add the icons and after they've been
3144 * added. The size you set will override user preferences for the default
3147 * This should only be used for special-purpose toolbars, normal
3148 * application toolbars should respect the user preferences for the
3152 gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
3153 GtkIconSize icon_size)
3155 GtkToolbarPrivate *priv;
3157 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3158 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
3160 priv = toolbar->priv;
3162 if (!priv->icon_size_set)
3164 priv->icon_size_set = TRUE;
3165 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3168 if (priv->icon_size == icon_size)
3171 priv->icon_size = icon_size;
3172 g_object_notify (G_OBJECT (toolbar), "icon-size");
3174 gtk_toolbar_reconfigured (toolbar);
3176 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3180 * gtk_toolbar_unset_icon_size:
3181 * @toolbar: a #GtkToolbar
3183 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that
3184 * user preferences will be used to determine the icon size.
3187 gtk_toolbar_unset_icon_size (GtkToolbar *toolbar)
3189 GtkToolbarPrivate *priv;
3192 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3194 priv = toolbar->priv;
3196 if (priv->icon_size_set)
3198 GtkSettings *settings = toolbar_get_settings (toolbar);
3202 g_object_get (settings,
3203 "gtk-toolbar-icon-size", &size,
3207 size = DEFAULT_ICON_SIZE;
3209 if (size != priv->icon_size)
3211 gtk_toolbar_set_icon_size (toolbar, size);
3212 g_object_notify (G_OBJECT (toolbar), "icon-size");
3215 priv->icon_size_set = FALSE;
3216 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3221 * ToolbarContent methods
3229 struct _ToolbarContent
3234 GtkAllocation start_allocation;
3235 GtkAllocation goal_allocation;
3236 guint is_placeholder : 1;
3237 guint disappearing : 1;
3241 static ToolbarContent *
3242 toolbar_content_new_tool_item (GtkToolbar *toolbar,
3244 gboolean is_placeholder,
3247 GtkToolbarPrivate *priv = toolbar->priv;
3248 ToolbarContent *content;
3250 content = g_slice_new0 (ToolbarContent);
3252 content->state = NOT_ALLOCATED;
3253 content->item = item;
3254 content->is_placeholder = is_placeholder;
3256 gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
3258 priv->content = g_list_insert (priv->content, content, pos);
3260 if (!is_placeholder)
3262 priv->num_children++;
3264 gtk_toolbar_stop_sliding (toolbar);
3267 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3268 priv->need_rebuild = TRUE;
3274 toolbar_content_remove (ToolbarContent *content,
3275 GtkToolbar *toolbar)
3277 GtkToolbarPrivate *priv = toolbar->priv;
3279 gtk_widget_unparent (GTK_WIDGET (content->item));
3281 priv->content = g_list_remove (priv->content, content);
3283 if (!toolbar_content_is_placeholder (content))
3284 priv->num_children--;
3286 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3287 priv->need_rebuild = TRUE;
3291 toolbar_content_free (ToolbarContent *content)
3293 g_slice_free (ToolbarContent, content);
3297 calculate_max_homogeneous_pixels (GtkWidget *widget)
3299 PangoContext *context;
3300 PangoFontMetrics *metrics;
3303 context = gtk_widget_get_pango_context (widget);
3304 metrics = pango_context_get_metrics (context,
3305 gtk_widget_get_style (widget)->font_desc,
3306 pango_context_get_language (context));
3307 char_width = pango_font_metrics_get_approximate_char_width (metrics);
3308 pango_font_metrics_unref (metrics);
3310 return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
3314 toolbar_content_draw (ToolbarContent *content,
3315 GtkContainer *container,
3320 if (content->is_placeholder)
3323 widget = GTK_WIDGET (content->item);
3326 gtk_container_propagate_draw (container, widget, cr);
3330 toolbar_content_visible (ToolbarContent *content,
3331 GtkToolbar *toolbar)
3333 GtkToolbarPrivate *priv = toolbar->priv;
3336 item = content->item;
3338 if (!gtk_widget_get_visible (GTK_WIDGET (item)))
3341 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
3342 gtk_tool_item_get_visible_horizontal (item))
3345 if (priv->orientation == GTK_ORIENTATION_VERTICAL &&
3346 gtk_tool_item_get_visible_vertical (item))
3353 toolbar_content_size_request (ToolbarContent *content,
3354 GtkToolbar *toolbar,
3355 GtkRequisition *requisition)
3357 gtk_widget_get_preferred_size (GTK_WIDGET (content->item),
3359 if (content->is_placeholder &&
3360 content->disappearing)
3362 requisition->width = 0;
3363 requisition->height = 0;
3368 toolbar_content_is_homogeneous (ToolbarContent *content,
3369 GtkToolbar *toolbar)
3371 GtkToolbarPrivate *priv = toolbar->priv;
3372 GtkRequisition requisition;
3375 if (priv->max_homogeneous_pixels < 0)
3377 priv->max_homogeneous_pixels =
3378 calculate_max_homogeneous_pixels (GTK_WIDGET (toolbar));
3381 toolbar_content_size_request (content, toolbar, &requisition);
3383 if (requisition.width > priv->max_homogeneous_pixels)
3386 result = gtk_tool_item_get_homogeneous (content->item) &&
3387 !GTK_IS_SEPARATOR_TOOL_ITEM (content->item);
3389 if (gtk_tool_item_get_is_important (content->item) &&
3390 priv->style == GTK_TOOLBAR_BOTH_HORIZ &&
3391 priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3400 toolbar_content_is_placeholder (ToolbarContent *content)
3402 if (content->is_placeholder)
3409 toolbar_content_disappearing (ToolbarContent *content)
3411 if (content->disappearing)
3418 toolbar_content_get_state (ToolbarContent *content)
3420 return content->state;
3424 toolbar_content_child_visible (ToolbarContent *content)
3426 return gtk_widget_get_child_visible (GTK_WIDGET (content->item));
3430 toolbar_content_get_goal_allocation (ToolbarContent *content,
3431 GtkAllocation *allocation)
3433 *allocation = content->goal_allocation;
3437 toolbar_content_get_allocation (ToolbarContent *content,
3438 GtkAllocation *allocation)
3440 gtk_widget_get_allocation (GTK_WIDGET (content->item), allocation);
3444 toolbar_content_set_start_allocation (ToolbarContent *content,
3445 GtkAllocation *allocation)
3447 content->start_allocation = *allocation;
3451 toolbar_content_get_expand (ToolbarContent *content)
3453 if (!content->disappearing &&
3454 gtk_tool_item_get_expand (content->item))
3461 toolbar_content_set_goal_allocation (ToolbarContent *content,
3462 GtkAllocation *allocation)
3464 content->goal_allocation = *allocation;
3468 toolbar_content_set_child_visible (ToolbarContent *content,
3469 GtkToolbar *toolbar,
3472 gtk_widget_set_child_visible (GTK_WIDGET (content->item),
3477 toolbar_content_get_start_allocation (ToolbarContent *content,
3478 GtkAllocation *start_allocation)
3480 *start_allocation = content->start_allocation;
3484 toolbar_content_size_allocate (ToolbarContent *content,
3485 GtkAllocation *allocation)
3487 gtk_widget_size_allocate (GTK_WIDGET (content->item),
3492 toolbar_content_set_state (ToolbarContent *content,
3495 content->state = state;
3499 toolbar_content_get_widget (ToolbarContent *content)
3501 return GTK_WIDGET (content->item);
3506 toolbar_content_set_disappearing (ToolbarContent *content,
3507 gboolean disappearing)
3509 content->disappearing = disappearing;
3513 toolbar_content_set_size_request (ToolbarContent *content,
3517 gtk_widget_set_size_request (GTK_WIDGET (content->item),
3522 toolbar_content_toolbar_reconfigured (ToolbarContent *content,
3523 GtkToolbar *toolbar)
3525 gtk_tool_item_toolbar_reconfigured (content->item);
3529 toolbar_content_retrieve_menu_item (ToolbarContent *content)
3531 return gtk_tool_item_retrieve_proxy_menu_item (content->item);
3535 toolbar_content_has_proxy_menu_item (ToolbarContent *content)
3537 GtkWidget *menu_item;
3539 if (content->has_menu == YES)
3541 else if (content->has_menu == NO)
3544 menu_item = toolbar_content_retrieve_menu_item (content);
3546 content->has_menu = menu_item? YES : NO;
3548 return menu_item != NULL;
3552 toolbar_content_set_unknown_menu_status (ToolbarContent *content)
3554 content->has_menu = UNKNOWN;
3558 toolbar_content_is_separator (ToolbarContent *content)
3560 return GTK_IS_SEPARATOR_TOOL_ITEM (content->item);
3564 toolbar_content_set_expand (ToolbarContent *content,
3567 gtk_tool_item_set_expand (content->item, expand);
3571 toolbar_content_show_all (ToolbarContent *content)
3575 widget = toolbar_content_get_widget (content);
3577 gtk_widget_show_all (widget);
3583 static GtkReliefStyle
3584 get_button_relief (GtkToolbar *toolbar)
3586 GtkReliefStyle button_relief = GTK_RELIEF_NORMAL;
3588 gtk_widget_ensure_style (GTK_WIDGET (toolbar));
3590 gtk_widget_style_get (GTK_WIDGET (toolbar),
3591 "button-relief", &button_relief,
3594 return button_relief;
3598 get_internal_padding (GtkToolbar *toolbar)
3602 gtk_widget_style_get (GTK_WIDGET (toolbar),
3603 "internal-padding", &ipadding,
3610 get_max_child_expand (GtkToolbar *toolbar)
3612 gint mexpand = G_MAXINT;
3614 gtk_widget_style_get (GTK_WIDGET (toolbar),
3615 "max-child-expand", &mexpand,
3620 static GtkShadowType
3621 get_shadow_type (GtkToolbar *toolbar)
3623 GtkShadowType shadow_type;
3625 gtk_widget_style_get (GTK_WIDGET (toolbar),
3626 "shadow-type", &shadow_type,
3632 /* GTK+ internal methods */
3635 _gtk_toolbar_get_default_space_size (void)
3637 return DEFAULT_SPACE_SIZE;
3641 _gtk_toolbar_paint_space_line (GtkWidget *widget,
3642 GtkToolbar *toolbar,
3645 GtkToolbarPrivate *priv = toolbar->priv;
3646 GtkOrientation orientation;
3651 const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
3652 const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
3654 g_return_if_fail (GTK_IS_WIDGET (widget));
3656 orientation = toolbar? priv->orientation : GTK_ORIENTATION_HORIZONTAL;
3658 style = gtk_widget_get_style (widget);
3659 window = gtk_widget_get_window (widget);
3660 state = gtk_widget_get_state (widget);
3661 width = gtk_widget_get_allocated_width (widget);
3662 height = gtk_widget_get_allocated_height (widget);
3664 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3666 gboolean wide_separators;
3667 gint separator_width;
3669 gtk_widget_style_get (widget,
3670 "wide-separators", &wide_separators,
3671 "separator-width", &separator_width,
3674 if (wide_separators)
3675 gtk_paint_box (style, cr,
3676 state, GTK_SHADOW_ETCHED_OUT,
3677 widget, "vseparator",
3678 (width - separator_width) / 2,
3679 height * start_fraction,
3681 height * (end_fraction - start_fraction));
3683 gtk_paint_vline (style, cr,
3686 height * start_fraction,
3687 height * end_fraction,
3688 (width - style->xthickness) / 2);
3692 gboolean wide_separators;
3693 gint separator_height;
3695 gtk_widget_style_get (widget,
3696 "wide-separators", &wide_separators,
3697 "separator-height", &separator_height,
3700 if (wide_separators)
3701 gtk_paint_box (style, cr,
3702 state, GTK_SHADOW_ETCHED_OUT,
3703 widget, "hseparator",
3704 width * start_fraction,
3705 (height - separator_height) / 2,
3706 width * (end_fraction - start_fraction),
3709 gtk_paint_hline (style, cr,
3712 width * start_fraction,
3713 width * end_fraction,
3714 (height - style->ythickness) / 2);
3719 _gtk_toolbar_elide_underscores (const gchar *original)
3722 const gchar *p, *end;
3724 gboolean last_underscore;
3729 len = strlen (original);
3730 q = result = g_malloc (len + 1);
3731 last_underscore = FALSE;
3733 end = original + len;
3734 for (p = original; p < end; p++)
3736 if (!last_underscore && *p == '_')
3737 last_underscore = TRUE;
3740 last_underscore = FALSE;
3741 if (original + 2 <= p && p + 1 <= end &&
3742 p[-2] == '(' && p[-1] == '_' && p[0] != '_' && p[1] == ')')
3753 if (last_underscore)
3762 toolbar_get_icon_size (GtkToolShell *shell)
3764 GtkToolbar *toolbar = GTK_TOOLBAR (shell);
3765 GtkToolbarPrivate *priv = toolbar->priv;
3767 return priv->icon_size;
3770 static GtkOrientation
3771 toolbar_get_orientation (GtkToolShell *shell)
3773 GtkToolbar *toolbar = GTK_TOOLBAR (shell);
3774 GtkToolbarPrivate *priv = toolbar->priv;
3776 return priv->orientation;
3779 static GtkToolbarStyle
3780 toolbar_get_style (GtkToolShell *shell)
3782 GtkToolbar *toolbar = GTK_TOOLBAR (shell);
3783 GtkToolbarPrivate *priv = toolbar->priv;
3788 static GtkReliefStyle
3789 toolbar_get_relief_style (GtkToolShell *shell)
3791 return get_button_relief (GTK_TOOLBAR (shell));
3795 toolbar_rebuild_menu (GtkToolShell *shell)
3797 GtkToolbar *toolbar = GTK_TOOLBAR (shell);
3798 GtkToolbarPrivate *priv = toolbar->priv;
3801 priv->need_rebuild = TRUE;
3803 for (list = priv->content; list != NULL; list = list->next)
3805 ToolbarContent *content = list->data;
3807 toolbar_content_set_unknown_menu_status (content);
3810 gtk_widget_queue_resize (GTK_WIDGET (shell));