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/.
38 #include "gtktoolbar.h"
41 #include "gtkbindings.h"
45 #include "gtkmainprivate.h"
46 #include "gtkmarshalers.h"
48 #include "gtkorientable.h"
49 #include "gtkradiobutton.h"
50 #include "gtkradiotoolbutton.h"
51 #include "gtkseparatormenuitem.h"
52 #include "gtkseparatortoolitem.h"
54 #include "gtktoolshell.h"
56 #include "gtkprivate.h"
58 #include "gtktypebuiltins.h"
63 * @Short_description: Create bars of buttons and other widgets
65 * @See_also: #GtkToolItem
67 * A toolbar is created with a call to gtk_toolbar_new().
69 * A toolbar can contain instances of a subclass of #GtkToolItem. To add
70 * a #GtkToolItem to the a toolbar, use gtk_toolbar_insert(). To remove
71 * an item from the toolbar use gtk_container_remove(). To add a button
72 * to the toolbar, add an instance of #GtkToolButton.
74 * Toolbar items can be visually grouped by adding instances of
75 * #GtkSeparatorToolItem to the toolbar. If the GtkToolbar child property
76 * "expand" is #TRUE and the property #GtkSeparatorToolItem:draw is set to
77 * #FALSE, the effect is to force all following items to the end of the toolbar.
79 * Creating a context menu for the toolbar can be done by connecting to
80 * the #GtkToolbar::popup-context-menu signal.
84 typedef struct _ToolbarContent ToolbarContent;
86 #define DEFAULT_IPADDING 0
88 #define DEFAULT_SPACE_SIZE 12
89 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
90 #define SPACE_LINE_DIVISION 10.0
91 #define SPACE_LINE_START 2.0
92 #define SPACE_LINE_END 8.0
94 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
95 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
96 #define DEFAULT_ANIMATION_STATE TRUE
98 #define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
99 * in the homogeneous game. In units of
100 * pango_font_get_estimated_char_width().
102 #define SLIDE_SPEED 600.0 /* How fast the items slide, in pixels per second */
103 #define ACCEL_THRESHOLD 0.18 /* After how much time in seconds will items start speeding up */
106 struct _GtkToolbarPrivate
108 GtkIconSize icon_size;
110 GtkOrientation orientation;
111 GtkSettings *settings;
112 GtkToolbarStyle style;
113 GtkToolItem *highlight_tool_item;
115 GtkWidget *arrow_button;
117 GdkWindow *event_window;
125 gint button_maxw; /* maximum width of homogeneous children */
126 gint button_maxh; /* maximum height of homogeneous children */
127 gint max_homogeneous_pixels;
130 gulong settings_connection;
133 guint icon_size_set : 1;
134 guint is_sliding : 1;
135 guint need_rebuild : 1; /* whether the overflow menu should be regenerated */
137 guint show_arrow : 1;
152 /* Child properties */
156 CHILD_PROP_HOMOGENEOUS
176 static void gtk_toolbar_set_property (GObject *object,
180 static void gtk_toolbar_get_property (GObject *object,
184 static gint gtk_toolbar_draw (GtkWidget *widget,
186 static void gtk_toolbar_realize (GtkWidget *widget);
187 static void gtk_toolbar_unrealize (GtkWidget *widget);
188 static void gtk_toolbar_get_preferred_width (GtkWidget *widget,
191 static void gtk_toolbar_get_preferred_height (GtkWidget *widget,
195 static void gtk_toolbar_size_allocate (GtkWidget *widget,
196 GtkAllocation *allocation);
197 static void gtk_toolbar_style_updated (GtkWidget *widget);
198 static gboolean gtk_toolbar_focus (GtkWidget *widget,
199 GtkDirectionType dir);
200 static void gtk_toolbar_move_focus (GtkWidget *widget,
201 GtkDirectionType dir);
202 static void gtk_toolbar_screen_changed (GtkWidget *widget,
203 GdkScreen *previous_screen);
204 static void gtk_toolbar_map (GtkWidget *widget);
205 static void gtk_toolbar_unmap (GtkWidget *widget);
206 static void gtk_toolbar_set_child_property (GtkContainer *container,
211 static void gtk_toolbar_get_child_property (GtkContainer *container,
216 static void gtk_toolbar_finalize (GObject *object);
217 static void gtk_toolbar_show_all (GtkWidget *widget);
218 static void gtk_toolbar_add (GtkContainer *container,
220 static void gtk_toolbar_remove (GtkContainer *container,
222 static void gtk_toolbar_forall (GtkContainer *container,
223 gboolean include_internals,
224 GtkCallback callback,
225 gpointer callback_data);
226 static GType gtk_toolbar_child_type (GtkContainer *container);
227 static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
228 GtkOrientation orientation);
229 static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
230 GtkToolbarStyle style);
231 static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
232 gboolean focus_home);
233 static gboolean gtk_toolbar_button_press (GtkWidget *toolbar,
234 GdkEventButton *event);
235 static gboolean gtk_toolbar_arrow_button_press (GtkWidget *button,
236 GdkEventButton *event,
237 GtkToolbar *toolbar);
238 static void gtk_toolbar_arrow_button_clicked (GtkWidget *button,
239 GtkToolbar *toolbar);
240 static void gtk_toolbar_update_button_relief (GtkToolbar *toolbar);
241 static gboolean gtk_toolbar_popup_menu (GtkWidget *toolbar);
242 static void gtk_toolbar_reconfigured (GtkToolbar *toolbar);
244 static GtkReliefStyle get_button_relief (GtkToolbar *toolbar);
245 static gint get_internal_padding (GtkToolbar *toolbar);
246 static gint get_max_child_expand (GtkToolbar *toolbar);
247 static GtkShadowType get_shadow_type (GtkToolbar *toolbar);
249 /* methods on ToolbarContent 'class' */
250 static ToolbarContent *toolbar_content_new_tool_item (GtkToolbar *toolbar,
252 gboolean is_placeholder,
254 static void toolbar_content_remove (ToolbarContent *content,
255 GtkToolbar *toolbar);
256 static void toolbar_content_free (ToolbarContent *content);
257 static void toolbar_content_draw (ToolbarContent *content,
258 GtkContainer *container,
260 static gboolean toolbar_content_visible (ToolbarContent *content,
261 GtkToolbar *toolbar);
262 static void toolbar_content_size_request (ToolbarContent *content,
264 GtkRequisition *requisition);
265 static gboolean toolbar_content_is_homogeneous (ToolbarContent *content,
266 GtkToolbar *toolbar);
267 static gboolean toolbar_content_is_placeholder (ToolbarContent *content);
268 static gboolean toolbar_content_disappearing (ToolbarContent *content);
269 static ItemState toolbar_content_get_state (ToolbarContent *content);
270 static gboolean toolbar_content_child_visible (ToolbarContent *content);
271 static void toolbar_content_get_goal_allocation (ToolbarContent *content,
272 GtkAllocation *allocation);
273 static void toolbar_content_get_allocation (ToolbarContent *content,
274 GtkAllocation *allocation);
275 static void toolbar_content_set_start_allocation (ToolbarContent *content,
276 GtkAllocation *new_start_allocation);
277 static void toolbar_content_get_start_allocation (ToolbarContent *content,
278 GtkAllocation *start_allocation);
279 static gboolean toolbar_content_get_expand (ToolbarContent *content);
280 static void toolbar_content_set_goal_allocation (ToolbarContent *content,
281 GtkAllocation *allocation);
282 static void toolbar_content_set_child_visible (ToolbarContent *content,
285 static void toolbar_content_size_allocate (ToolbarContent *content,
286 GtkAllocation *allocation);
287 static void toolbar_content_set_state (ToolbarContent *content,
288 ItemState new_state);
289 static GtkWidget * toolbar_content_get_widget (ToolbarContent *content);
290 static void toolbar_content_set_disappearing (ToolbarContent *content,
291 gboolean disappearing);
292 static void toolbar_content_set_size_request (ToolbarContent *content,
295 static void toolbar_content_toolbar_reconfigured (ToolbarContent *content,
296 GtkToolbar *toolbar);
297 static GtkWidget * toolbar_content_retrieve_menu_item (ToolbarContent *content);
298 static gboolean toolbar_content_has_proxy_menu_item (ToolbarContent *content);
299 static gboolean toolbar_content_is_separator (ToolbarContent *content);
300 static void toolbar_content_show_all (ToolbarContent *content);
301 static void toolbar_content_set_expand (ToolbarContent *content,
304 static void toolbar_tool_shell_iface_init (GtkToolShellIface *iface);
305 static GtkIconSize toolbar_get_icon_size (GtkToolShell *shell);
306 static GtkOrientation toolbar_get_orientation (GtkToolShell *shell);
307 static GtkToolbarStyle toolbar_get_style (GtkToolShell *shell);
308 static GtkReliefStyle toolbar_get_relief_style (GtkToolShell *shell);
309 static void toolbar_rebuild_menu (GtkToolShell *shell);
312 G_DEFINE_TYPE_WITH_CODE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER,
313 G_IMPLEMENT_INTERFACE (GTK_TYPE_TOOL_SHELL,
314 toolbar_tool_shell_iface_init)
315 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
318 static guint toolbar_signals[LAST_SIGNAL] = { 0 };
322 add_arrow_bindings (GtkBindingSet *binding_set,
324 GtkDirectionType dir)
326 guint keypad_keysym = keysym - GDK_KEY_Left + GDK_KEY_KP_Left;
328 gtk_binding_entry_add_signal (binding_set, keysym, 0,
330 GTK_TYPE_DIRECTION_TYPE, dir);
331 gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
333 GTK_TYPE_DIRECTION_TYPE, dir);
337 add_ctrl_tab_bindings (GtkBindingSet *binding_set,
338 GdkModifierType modifiers,
339 GtkDirectionType direction)
341 gtk_binding_entry_add_signal (binding_set,
342 GDK_KEY_Tab, GDK_CONTROL_MASK | modifiers,
344 GTK_TYPE_DIRECTION_TYPE, direction);
345 gtk_binding_entry_add_signal (binding_set,
346 GDK_KEY_KP_Tab, GDK_CONTROL_MASK | modifiers,
348 GTK_TYPE_DIRECTION_TYPE, direction);
352 gtk_toolbar_class_init (GtkToolbarClass *klass)
354 GObjectClass *gobject_class;
355 GtkWidgetClass *widget_class;
356 GtkContainerClass *container_class;
357 GtkBindingSet *binding_set;
359 gobject_class = (GObjectClass *)klass;
360 widget_class = (GtkWidgetClass *)klass;
361 container_class = (GtkContainerClass *)klass;
363 gobject_class->set_property = gtk_toolbar_set_property;
364 gobject_class->get_property = gtk_toolbar_get_property;
365 gobject_class->finalize = gtk_toolbar_finalize;
367 widget_class->button_press_event = gtk_toolbar_button_press;
368 widget_class->draw = gtk_toolbar_draw;
369 widget_class->get_preferred_width = gtk_toolbar_get_preferred_width;
370 widget_class->get_preferred_height = gtk_toolbar_get_preferred_height;
371 widget_class->size_allocate = gtk_toolbar_size_allocate;
372 widget_class->style_updated = gtk_toolbar_style_updated;
373 widget_class->focus = gtk_toolbar_focus;
375 /* need to override the base class function via override_class_handler,
376 * because the signal slot is not available in GtkWidgetClass
378 g_signal_override_class_handler ("move-focus",
380 G_CALLBACK (gtk_toolbar_move_focus));
382 widget_class->screen_changed = gtk_toolbar_screen_changed;
383 widget_class->realize = gtk_toolbar_realize;
384 widget_class->unrealize = gtk_toolbar_unrealize;
385 widget_class->map = gtk_toolbar_map;
386 widget_class->unmap = gtk_toolbar_unmap;
387 widget_class->popup_menu = gtk_toolbar_popup_menu;
388 widget_class->show_all = gtk_toolbar_show_all;
390 container_class->add = gtk_toolbar_add;
391 container_class->remove = gtk_toolbar_remove;
392 container_class->forall = gtk_toolbar_forall;
393 container_class->child_type = gtk_toolbar_child_type;
394 container_class->get_child_property = gtk_toolbar_get_child_property;
395 container_class->set_child_property = gtk_toolbar_set_child_property;
397 klass->orientation_changed = gtk_toolbar_orientation_changed;
398 klass->style_changed = gtk_toolbar_real_style_changed;
401 * GtkToolbar::orientation-changed:
402 * @toolbar: the object which emitted the signal
403 * @orientation: the new #GtkOrientation of the toolbar
405 * Emitted when the orientation of the toolbar changes.
407 toolbar_signals[ORIENTATION_CHANGED] =
408 g_signal_new (I_("orientation-changed"),
409 G_OBJECT_CLASS_TYPE (klass),
411 G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
413 g_cclosure_marshal_VOID__ENUM,
415 GTK_TYPE_ORIENTATION);
417 * GtkToolbar::style-changed:
418 * @toolbar: The #GtkToolbar which emitted the signal
419 * @style: the new #GtkToolbarStyle of the toolbar
421 * Emitted when the style of the toolbar changes.
423 toolbar_signals[STYLE_CHANGED] =
424 g_signal_new (I_("style-changed"),
425 G_OBJECT_CLASS_TYPE (klass),
427 G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
429 g_cclosure_marshal_VOID__ENUM,
431 GTK_TYPE_TOOLBAR_STYLE);
433 * GtkToolbar::popup-context-menu:
434 * @toolbar: the #GtkToolbar which emitted the signal
435 * @x: the x coordinate of the point where the menu should appear
436 * @y: the y coordinate of the point where the menu should appear
437 * @button: the mouse button the user pressed, or -1
439 * Emitted when the user right-clicks the toolbar or uses the
440 * keybinding to display a popup menu.
442 * Application developers should handle this signal if they want
443 * to display a context menu on the toolbar. The context-menu should
444 * appear at the coordinates given by @x and @y. The mouse button
445 * number is given by the @button parameter. If the menu was popped
446 * up using the keybaord, @button is -1.
448 * Return value: return %TRUE if the signal was handled, %FALSE if not
450 toolbar_signals[POPUP_CONTEXT_MENU] =
451 g_signal_new (I_("popup-context-menu"),
452 G_OBJECT_CLASS_TYPE (klass),
454 G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
455 _gtk_boolean_handled_accumulator, NULL,
456 _gtk_marshal_BOOLEAN__INT_INT_INT,
458 G_TYPE_INT, G_TYPE_INT,
462 * GtkToolbar::focus-home-or-end:
463 * @toolbar: the #GtkToolbar which emitted the signal
464 * @focus_home: %TRUE if the first item should be focused
466 * A keybinding signal used internally by GTK+. This signal can't
467 * be used in application code
469 * Return value: %TRUE if the signal was handled, %FALSE if not
471 toolbar_signals[FOCUS_HOME_OR_END] =
472 g_signal_new_class_handler (I_("focus-home-or-end"),
473 G_OBJECT_CLASS_TYPE (klass),
474 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
475 G_CALLBACK (gtk_toolbar_focus_home_or_end),
477 _gtk_marshal_BOOLEAN__BOOLEAN,
482 g_object_class_override_property (gobject_class,
486 g_object_class_install_property (gobject_class,
488 g_param_spec_enum ("toolbar-style",
490 P_("How to draw the toolbar"),
491 GTK_TYPE_TOOLBAR_STYLE,
492 DEFAULT_TOOLBAR_STYLE,
493 GTK_PARAM_READWRITE));
494 g_object_class_install_property (gobject_class,
496 g_param_spec_boolean ("show-arrow",
498 P_("If an arrow should be shown if the toolbar doesn't fit"),
500 GTK_PARAM_READWRITE));
503 * GtkToolbar:icon-size:
505 * The size of the icons in a toolbar is normally determined by
506 * the toolbar-icon-size setting. When this property is set, it
507 * overrides the setting.
509 * This should only be used for special-purpose toolbars, normal
510 * application toolbars should respect the user preferences for the
515 g_object_class_install_property (gobject_class,
517 g_param_spec_int ("icon-size",
519 P_("Size of icons in this toolbar"),
522 GTK_PARAM_READWRITE));
525 * GtkToolbar:icon-size-set:
527 * Is %TRUE if the icon-size property has been set.
531 g_object_class_install_property (gobject_class,
533 g_param_spec_boolean ("icon-size-set",
535 P_("Whether the icon-size property has been set"),
537 GTK_PARAM_READWRITE));
539 /* child properties */
540 gtk_container_class_install_child_property (container_class,
542 g_param_spec_boolean ("expand",
544 P_("Whether the item should receive extra space when the toolbar grows"),
546 GTK_PARAM_READWRITE));
548 gtk_container_class_install_child_property (container_class,
549 CHILD_PROP_HOMOGENEOUS,
550 g_param_spec_boolean ("homogeneous",
552 P_("Whether the item should be the same size as other homogeneous items"),
554 GTK_PARAM_READWRITE));
556 /* style properties */
557 gtk_widget_class_install_style_property (widget_class,
558 g_param_spec_int ("space-size",
560 P_("Size of spacers"),
564 GTK_PARAM_READABLE));
566 gtk_widget_class_install_style_property (widget_class,
567 g_param_spec_int ("internal-padding",
568 P_("Internal padding"),
569 P_("Amount of border space between the toolbar shadow and the buttons"),
573 GTK_PARAM_READABLE));
575 gtk_widget_class_install_style_property (widget_class,
576 g_param_spec_int ("max-child-expand",
577 P_("Maximum child expand"),
578 P_("Maximum amount of space an expandable item will be given"),
582 GTK_PARAM_READABLE));
584 gtk_widget_class_install_style_property (widget_class,
585 g_param_spec_enum ("space-style",
587 P_("Whether spacers are vertical lines or just blank"),
588 GTK_TYPE_TOOLBAR_SPACE_STYLE,
590 GTK_PARAM_READABLE));
592 gtk_widget_class_install_style_property (widget_class,
593 g_param_spec_enum ("button-relief",
595 P_("Type of bevel around toolbar buttons"),
596 GTK_TYPE_RELIEF_STYLE,
598 GTK_PARAM_READABLE));
599 gtk_widget_class_install_style_property (widget_class,
600 g_param_spec_enum ("shadow-type",
602 P_("Style of bevel around the toolbar"),
603 GTK_TYPE_SHADOW_TYPE,
605 GTK_PARAM_READABLE));
607 binding_set = gtk_binding_set_by_class (klass);
609 add_arrow_bindings (binding_set, GDK_KEY_Left, GTK_DIR_LEFT);
610 add_arrow_bindings (binding_set, GDK_KEY_Right, GTK_DIR_RIGHT);
611 add_arrow_bindings (binding_set, GDK_KEY_Up, GTK_DIR_UP);
612 add_arrow_bindings (binding_set, GDK_KEY_Down, GTK_DIR_DOWN);
614 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Home, 0,
615 "focus-home-or-end", 1,
616 G_TYPE_BOOLEAN, TRUE);
617 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Home, 0,
618 "focus-home-or-end", 1,
619 G_TYPE_BOOLEAN, TRUE);
620 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_End, 0,
621 "focus-home-or-end", 1,
622 G_TYPE_BOOLEAN, FALSE);
623 gtk_binding_entry_add_signal (binding_set, GDK_KEY_End, 0,
624 "focus-home-or-end", 1,
625 G_TYPE_BOOLEAN, FALSE);
627 add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
628 add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
630 g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));
634 toolbar_tool_shell_iface_init (GtkToolShellIface *iface)
636 iface->get_icon_size = toolbar_get_icon_size;
637 iface->get_orientation = toolbar_get_orientation;
638 iface->get_style = toolbar_get_style;
639 iface->get_relief_style = toolbar_get_relief_style;
640 iface->rebuild_menu = toolbar_rebuild_menu;
644 gtk_toolbar_init (GtkToolbar *toolbar)
646 GtkToolbarPrivate *priv;
647 GtkStyleContext *context;
649 toolbar->priv = G_TYPE_INSTANCE_GET_PRIVATE (toolbar,
652 priv = toolbar->priv;
654 gtk_widget_set_can_focus (GTK_WIDGET (toolbar), FALSE);
655 gtk_widget_set_has_window (GTK_WIDGET (toolbar), FALSE);
657 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
658 priv->style = DEFAULT_TOOLBAR_STYLE;
659 priv->icon_size = DEFAULT_ICON_SIZE;
660 priv->animation = DEFAULT_ANIMATION_STATE;
662 priv->arrow_button = gtk_toggle_button_new ();
663 g_signal_connect (priv->arrow_button, "button-press-event",
664 G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar);
665 g_signal_connect (priv->arrow_button, "clicked",
666 G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar);
667 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
668 get_button_relief (toolbar));
670 gtk_button_set_focus_on_click (GTK_BUTTON (priv->arrow_button), FALSE);
672 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
673 gtk_widget_set_name (priv->arrow, "gtk-toolbar-arrow");
674 gtk_widget_show (priv->arrow);
675 gtk_container_add (GTK_CONTAINER (priv->arrow_button), priv->arrow);
677 gtk_widget_set_parent (priv->arrow_button, GTK_WIDGET (toolbar));
679 /* which child position a drop will occur at */
681 priv->show_arrow = TRUE;
682 priv->settings = NULL;
684 priv->max_homogeneous_pixels = -1;
686 priv->timer = g_timer_new ();
688 context = gtk_widget_get_style_context (GTK_WIDGET (toolbar));
689 gtk_style_context_add_class (context, GTK_STYLE_CLASS_TOOLBAR);
693 gtk_toolbar_set_property (GObject *object,
698 GtkToolbar *toolbar = GTK_TOOLBAR (object);
699 GtkToolbarPrivate *priv = toolbar->priv;
703 case PROP_ORIENTATION:
704 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0,
705 g_value_get_enum (value));
707 case PROP_TOOLBAR_STYLE:
708 gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
710 case PROP_SHOW_ARROW:
711 gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
714 gtk_toolbar_set_icon_size (toolbar, g_value_get_int (value));
716 case PROP_ICON_SIZE_SET:
717 if (g_value_get_boolean (value))
718 priv->icon_size_set = TRUE;
720 gtk_toolbar_unset_icon_size (toolbar);
723 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
729 gtk_toolbar_get_property (GObject *object,
734 GtkToolbar *toolbar = GTK_TOOLBAR (object);
735 GtkToolbarPrivate *priv = toolbar->priv;
739 case PROP_ORIENTATION:
740 g_value_set_enum (value, priv->orientation);
742 case PROP_TOOLBAR_STYLE:
743 g_value_set_enum (value, priv->style);
745 case PROP_SHOW_ARROW:
746 g_value_set_boolean (value, priv->show_arrow);
749 g_value_set_int (value, gtk_toolbar_get_icon_size (toolbar));
751 case PROP_ICON_SIZE_SET:
752 g_value_set_boolean (value, priv->icon_size_set);
755 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
761 gtk_toolbar_map (GtkWidget *widget)
763 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
764 GtkToolbarPrivate *priv = toolbar->priv;
766 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->map (widget);
768 if (priv->event_window)
769 gdk_window_show_unraised (priv->event_window);
773 gtk_toolbar_unmap (GtkWidget *widget)
775 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
776 GtkToolbarPrivate *priv = toolbar->priv;
778 if (priv->event_window)
779 gdk_window_hide (priv->event_window);
781 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unmap (widget);
785 gtk_toolbar_realize (GtkWidget *widget)
787 GtkAllocation allocation;
788 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
789 GtkToolbarPrivate *priv = toolbar->priv;
791 GdkWindowAttr attributes;
792 gint attributes_mask;
795 gtk_widget_set_realized (widget, TRUE);
797 gtk_widget_get_allocation (widget, &allocation);
798 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
800 attributes.wclass = GDK_INPUT_ONLY;
801 attributes.window_type = GDK_WINDOW_CHILD;
802 attributes.x = allocation.x + border_width;
803 attributes.y = allocation.y + border_width;
804 attributes.width = allocation.width - border_width * 2;
805 attributes.height = allocation.height - border_width * 2;
806 attributes.event_mask = gtk_widget_get_events (widget);
807 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
808 GDK_BUTTON_RELEASE_MASK |
809 GDK_ENTER_NOTIFY_MASK |
810 GDK_LEAVE_NOTIFY_MASK);
812 attributes_mask = GDK_WA_X | GDK_WA_Y;
814 window = gtk_widget_get_parent_window (widget);
815 gtk_widget_set_window (widget, window);
816 g_object_ref (window);
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;
845 GtkStyleContext *context;
850 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
851 context = gtk_widget_get_style_context (widget);
852 state = gtk_widget_get_state_flags (widget);
854 gtk_style_context_save (context);
855 gtk_style_context_set_state (context, state);
857 gtk_render_background (context, cr, border_width, border_width,
858 gtk_widget_get_allocated_width (widget) - 2 * border_width,
859 gtk_widget_get_allocated_height (widget) - 2 * border_width);
860 gtk_render_frame (context, cr, border_width, border_width,
861 gtk_widget_get_allocated_width (widget) - 2 * border_width,
862 gtk_widget_get_allocated_height (widget) - 2 * border_width);
864 for (list = priv->content; list != NULL; list = list->next)
866 ToolbarContent *content = list->data;
868 toolbar_content_draw (content, GTK_CONTAINER (widget), cr);
871 gtk_container_propagate_draw (GTK_CONTAINER (widget),
875 gtk_style_context_restore (context);
881 gtk_toolbar_size_request (GtkWidget *widget,
882 GtkRequisition *requisition)
884 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
885 GtkToolbarPrivate *priv = toolbar->priv;
887 gint max_child_height;
888 gint max_child_width;
889 gint max_homogeneous_child_width;
890 gint max_homogeneous_child_height;
891 gint homogeneous_size;
893 gint pack_front_size;
896 GtkRequisition arrow_requisition;
898 max_homogeneous_child_width = 0;
899 max_homogeneous_child_height = 0;
901 max_child_height = 0;
902 for (list = priv->content; list != NULL; list = list->next)
904 GtkRequisition requisition;
905 ToolbarContent *content = list->data;
907 if (!toolbar_content_visible (content, toolbar))
910 toolbar_content_size_request (content, toolbar, &requisition);
912 max_child_width = MAX (max_child_width, requisition.width);
913 max_child_height = MAX (max_child_height, requisition.height);
915 if (toolbar_content_is_homogeneous (content, toolbar))
917 max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
918 max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
922 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
923 homogeneous_size = max_homogeneous_child_width;
925 homogeneous_size = max_homogeneous_child_height;
928 for (list = priv->content; list != NULL; list = list->next)
930 ToolbarContent *content = list->data;
933 if (!toolbar_content_visible (content, toolbar))
936 if (toolbar_content_is_homogeneous (content, toolbar))
938 size = homogeneous_size;
942 GtkRequisition requisition;
944 toolbar_content_size_request (content, toolbar, &requisition);
946 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
947 size = requisition.width;
949 size = requisition.height;
952 pack_front_size += size;
955 if (priv->show_arrow)
957 gtk_widget_get_preferred_size (priv->arrow_button,
958 &arrow_requisition, NULL);
960 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
961 long_req = arrow_requisition.width;
963 long_req = arrow_requisition.height;
965 /* There is no point requesting space for the arrow if that would take
966 * up more space than all the items combined
968 long_req = MIN (long_req, pack_front_size);
972 arrow_requisition.height = 0;
973 arrow_requisition.width = 0;
975 long_req = pack_front_size;
978 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
980 requisition->width = long_req;
981 requisition->height = MAX (max_child_height, arrow_requisition.height);
985 requisition->height = long_req;
986 requisition->width = MAX (max_child_width, arrow_requisition.width);
990 ipadding = get_internal_padding (toolbar);
992 border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
993 requisition->width += 2 * (ipadding + border_width);
994 requisition->height += 2 * (ipadding + border_width);
996 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
998 GtkStyleContext *context;
1002 context = gtk_widget_get_style_context (widget);
1003 state = gtk_widget_get_state_flags (widget);
1004 gtk_style_context_get_padding (context, state, &padding);
1006 requisition->width += padding.left + padding.right;
1007 requisition->height += padding.top + padding.bottom;
1010 priv->button_maxw = max_homogeneous_child_width;
1011 priv->button_maxh = max_homogeneous_child_height;
1015 gtk_toolbar_get_preferred_width (GtkWidget *widget,
1019 GtkRequisition requisition;
1021 gtk_toolbar_size_request (widget, &requisition);
1023 *minimum = *natural = requisition.width;
1027 gtk_toolbar_get_preferred_height (GtkWidget *widget,
1031 GtkRequisition requisition;
1033 gtk_toolbar_size_request (widget, &requisition);
1035 *minimum = *natural = requisition.height;
1039 position (GtkToolbar *toolbar,
1044 GtkToolbarPrivate *priv = toolbar->priv;
1047 if (!priv->animation)
1050 if (elapsed <= ACCEL_THRESHOLD)
1052 n_pixels = SLIDE_SPEED * elapsed;
1056 /* The formula is a second degree polynomial in
1057 * @elapsed that has the line SLIDE_SPEED * @elapsed
1058 * as tangent for @elapsed == ACCEL_THRESHOLD.
1059 * This makes @n_pixels a smooth function of elapsed time.
1061 n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
1062 SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
1066 return MIN (from + n_pixels, to);
1068 return MAX (from - n_pixels, to);
1072 compute_intermediate_allocation (GtkToolbar *toolbar,
1073 const GtkAllocation *start,
1074 const GtkAllocation *goal,
1075 GtkAllocation *intermediate)
1077 GtkToolbarPrivate *priv = toolbar->priv;
1078 gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
1080 intermediate->x = position (toolbar, start->x, goal->x, elapsed);
1081 intermediate->y = position (toolbar, start->y, goal->y, elapsed);
1082 intermediate->width = position (toolbar, start->x + start->width,
1083 goal->x + goal->width,
1084 elapsed) - intermediate->x;
1085 intermediate->height = position (toolbar, start->y + start->height,
1086 goal->y + goal->height,
1087 elapsed) - intermediate->y;
1091 fixup_allocation_for_rtl (gint total_size,
1092 GtkAllocation *allocation)
1094 allocation->x += (total_size - (2 * allocation->x + allocation->width));
1098 fixup_allocation_for_vertical (GtkAllocation *allocation)
1102 tmp = allocation->x;
1103 allocation->x = allocation->y;
1104 allocation->y = tmp;
1106 tmp = allocation->width;
1107 allocation->width = allocation->height;
1108 allocation->height = tmp;
1112 get_item_size (GtkToolbar *toolbar,
1113 ToolbarContent *content)
1115 GtkToolbarPrivate *priv = toolbar->priv;
1116 GtkRequisition requisition;
1118 toolbar_content_size_request (content, toolbar, &requisition);
1120 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1122 if (toolbar_content_is_homogeneous (content, toolbar))
1123 return priv->button_maxw;
1125 return requisition.width;
1129 if (toolbar_content_is_homogeneous (content, toolbar))
1130 return priv->button_maxh;
1132 return requisition.height;
1137 slide_idle_handler (gpointer data)
1139 GtkToolbar *toolbar = GTK_TOOLBAR (data);
1140 GtkToolbarPrivate *priv = toolbar->priv;
1143 if (priv->need_sync)
1146 priv->need_sync = FALSE;
1149 for (list = priv->content; list != NULL; list = list->next)
1151 ToolbarContent *content = list->data;
1153 GtkAllocation goal_allocation;
1154 GtkAllocation allocation;
1157 state = toolbar_content_get_state (content);
1158 toolbar_content_get_goal_allocation (content, &goal_allocation);
1159 toolbar_content_get_allocation (content, &allocation);
1163 if (state == NOT_ALLOCATED)
1165 /* an unallocated item means that size allocate has to
1166 * called at least once more
1171 /* An invisible item with a goal allocation of
1172 * 0 is already at its goal.
1174 if ((state == NORMAL || state == OVERFLOWN) &&
1175 ((goal_allocation.width != 0 &&
1176 goal_allocation.height != 0) ||
1177 toolbar_content_child_visible (content)))
1179 if ((goal_allocation.x != allocation.x ||
1180 goal_allocation.y != allocation.y ||
1181 goal_allocation.width != allocation.width ||
1182 goal_allocation.height != allocation.height))
1184 /* An item is not in its right position yet. Note
1185 * that OVERFLOWN items do get an allocation in
1186 * gtk_toolbar_size_allocate(). This way you can see
1187 * them slide back in when you drag an item off the
1194 if (toolbar_content_is_placeholder (content) &&
1195 toolbar_content_disappearing (content) &&
1196 toolbar_content_child_visible (content))
1198 /* A disappearing placeholder is still visible.
1206 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1212 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1214 priv->is_sliding = FALSE;
1221 rect_within (GtkAllocation *a1,
1224 return (a1->x >= a2->x &&
1225 a1->x + a1->width <= a2->x + a2->width &&
1227 a1->y + a1->height <= a2->y + a2->height);
1231 gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
1233 GtkAllocation allocation;
1234 GtkWidget *widget = GTK_WIDGET (toolbar);
1235 GtkToolbarPrivate *priv = toolbar->priv;
1236 GtkStyleContext *context;
1237 GtkStateFlags state;
1246 /* Start the sliding. This function copies the allocation of every
1247 * item into content->start_allocation. For items that haven't
1248 * been allocated yet, we calculate their position and save that
1249 * in start_allocatino along with zero width and zero height.
1251 * FIXME: It would be nice if we could share this code with
1252 * the equivalent in gtk_widget_size_allocate().
1254 priv->is_sliding = TRUE;
1257 priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
1259 gtk_widget_get_allocation (widget, &allocation);
1260 context = gtk_widget_get_style_context (widget);
1261 state = gtk_widget_get_state_flags (widget);
1262 gtk_style_context_get_padding (context, state, &padding);
1264 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1265 vertical = (priv->orientation == GTK_ORIENTATION_VERTICAL);
1266 border_width = get_internal_padding (toolbar) + gtk_container_get_border_width (GTK_CONTAINER (toolbar));
1270 cur_x = allocation.width - border_width - padding.right;
1271 cur_y = allocation.height - border_width - padding.top;
1275 cur_x = border_width + padding.left;
1276 cur_y = border_width + padding.top;
1279 cur_x += allocation.x;
1280 cur_y += allocation.y;
1282 for (list = priv->content; list != NULL; list = list->next)
1284 ToolbarContent *content = list->data;
1285 GtkAllocation new_start_allocation;
1286 GtkAllocation item_allocation;
1289 state = toolbar_content_get_state (content);
1290 toolbar_content_get_allocation (content, &item_allocation);
1292 if ((state == NORMAL &&
1293 rect_within (&item_allocation, &allocation)) ||
1296 new_start_allocation = item_allocation;
1300 new_start_allocation.x = cur_x;
1301 new_start_allocation.y = cur_y;
1305 new_start_allocation.width = allocation.width -
1307 padding.left - padding.right;
1308 new_start_allocation.height = 0;
1312 new_start_allocation.width = 0;
1313 new_start_allocation.height = allocation.height -
1315 padding.top - padding.bottom;
1320 cur_y = new_start_allocation.y + new_start_allocation.height;
1322 cur_x = new_start_allocation.x;
1324 cur_x = new_start_allocation.x + new_start_allocation.width;
1326 toolbar_content_set_start_allocation (content, &new_start_allocation);
1329 /* This resize will run before the first idle handler. This
1330 * will make sure that items get the right goal allocation
1331 * so that the idle handler will not immediately return
1334 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1335 g_timer_reset (priv->timer);
1339 gtk_toolbar_stop_sliding (GtkToolbar *toolbar)
1341 GtkToolbarPrivate *priv = toolbar->priv;
1343 if (priv->is_sliding)
1347 priv->is_sliding = FALSE;
1351 g_source_remove (priv->idle_id);
1355 list = priv->content;
1358 ToolbarContent *content = list->data;
1361 if (toolbar_content_is_placeholder (content))
1363 toolbar_content_remove (content, toolbar);
1364 toolbar_content_free (content);
1368 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1373 remove_item (GtkWidget *menu_item,
1376 gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (menu_item)),
1381 menu_deactivated (GtkWidget *menu,
1382 GtkToolbar *toolbar)
1384 GtkToolbarPrivate *priv = toolbar->priv;
1386 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->arrow_button), FALSE);
1390 menu_detached (GtkWidget *widget,
1393 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1394 GtkToolbarPrivate *priv = toolbar->priv;
1400 rebuild_menu (GtkToolbar *toolbar)
1402 GtkToolbarPrivate *priv = toolbar->priv;
1403 GList *list, *children;
1407 priv->menu = GTK_MENU (gtk_menu_new());
1408 gtk_menu_attach_to_widget (priv->menu,
1409 GTK_WIDGET (toolbar),
1412 g_signal_connect (priv->menu, "deactivate",
1413 G_CALLBACK (menu_deactivated), toolbar);
1416 gtk_container_foreach (GTK_CONTAINER (priv->menu), remove_item, NULL);
1418 for (list = priv->content; list != NULL; list = list->next)
1420 ToolbarContent *content = list->data;
1422 if (toolbar_content_get_state (content) == OVERFLOWN &&
1423 !toolbar_content_is_placeholder (content))
1425 GtkWidget *menu_item = toolbar_content_retrieve_menu_item (content);
1429 g_assert (GTK_IS_MENU_ITEM (menu_item));
1430 gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item);
1435 /* Remove leading and trailing separator items */
1436 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1439 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1441 GtkWidget *child = list->data;
1443 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1446 g_list_free (children);
1448 /* Regenerate the list of children so we don't try to remove items twice */
1449 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1451 list = g_list_last (children);
1452 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1454 GtkWidget *child = list->data;
1456 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1459 g_list_free (children);
1461 priv->need_rebuild = FALSE;
1465 gtk_toolbar_size_allocate (GtkWidget *widget,
1466 GtkAllocation *allocation)
1468 GtkAllocation widget_allocation;
1469 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1470 GtkToolbarPrivate *priv = toolbar->priv;
1471 GtkAllocation *allocations;
1472 ItemState *new_states;
1473 GtkAllocation arrow_allocation;
1474 GtkStyleContext *context;
1475 GtkStateFlags state;
1478 gint size, pos, short_size;
1481 gboolean need_arrow;
1482 gint n_expand_items;
1484 gint available_size;
1487 GtkRequisition arrow_requisition;
1488 gboolean overflowing;
1489 gboolean size_changed;
1491 GtkAllocation item_area;
1492 GtkShadowType shadow_type;
1494 context = gtk_widget_get_style_context (widget);
1495 state = gtk_widget_get_state_flags (widget);
1496 gtk_style_context_get_padding (context, state, &padding);
1498 gtk_widget_get_allocation (widget, &widget_allocation);
1499 size_changed = FALSE;
1500 if (widget_allocation.x != allocation->x ||
1501 widget_allocation.y != allocation->y ||
1502 widget_allocation.width != allocation->width ||
1503 widget_allocation.height != allocation->height)
1505 size_changed = TRUE;
1509 gtk_toolbar_stop_sliding (toolbar);
1511 gtk_widget_set_allocation (widget, allocation);
1513 border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
1515 if (gtk_widget_get_realized (widget))
1517 gdk_window_move_resize (priv->event_window,
1518 allocation->x + border_width,
1519 allocation->y + border_width,
1520 allocation->width - border_width * 2,
1521 allocation->height - border_width * 2);
1524 border_width += get_internal_padding (toolbar);
1526 gtk_widget_get_preferred_size (priv->arrow_button,
1527 &arrow_requisition, NULL);
1529 shadow_type = get_shadow_type (toolbar);
1531 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1533 available_size = size = allocation->width - 2 * border_width;
1534 short_size = allocation->height - 2 * border_width;
1535 arrow_size = arrow_requisition.width;
1537 if (shadow_type != GTK_SHADOW_NONE)
1539 available_size -= padding.left + padding.right;
1540 short_size -= padding.top + padding.bottom;
1545 available_size = size = allocation->height - 2 * border_width;
1546 short_size = allocation->width - 2 * border_width;
1547 arrow_size = arrow_requisition.height;
1549 if (shadow_type != GTK_SHADOW_NONE)
1551 available_size -= padding.top + padding.bottom;
1552 short_size -= padding.left + padding.right;
1556 n_items = g_list_length (priv->content);
1557 allocations = g_new0 (GtkAllocation, n_items);
1558 new_states = g_new0 (ItemState, n_items);
1562 for (list = priv->content; list != NULL; list = list->next)
1564 ToolbarContent *content = list->data;
1566 if (toolbar_content_visible (content, toolbar))
1568 needed_size += get_item_size (toolbar, content);
1570 /* Do we need an arrow?
1572 * Assume we don't, and see if any non-separator item with a
1573 * proxy menu item is then going to overflow.
1575 if (needed_size > available_size &&
1578 toolbar_content_has_proxy_menu_item (content) &&
1579 !toolbar_content_is_separator (content))
1587 size = available_size - arrow_size;
1589 size = available_size;
1591 /* calculate widths and states of items */
1592 overflowing = FALSE;
1593 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1595 ToolbarContent *content = list->data;
1598 if (!toolbar_content_visible (content, toolbar))
1600 new_states[i] = HIDDEN;
1604 item_size = get_item_size (toolbar, content);
1605 if (item_size <= size && !overflowing)
1608 allocations[i].width = item_size;
1609 new_states[i] = NORMAL;
1614 new_states[i] = OVERFLOWN;
1615 allocations[i].width = item_size;
1619 /* calculate width of arrow */
1622 arrow_allocation.width = arrow_size;
1623 arrow_allocation.height = MAX (short_size, 1);
1626 /* expand expandable items */
1628 /* We don't expand when there is an overflow menu, because that leads to
1629 * weird jumps when items get moved to the overflow menu and the expanding
1630 * items suddenly get a lot of extra space
1634 gint max_child_expand;
1637 for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
1639 ToolbarContent *content = list->data;
1641 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1645 max_child_expand = get_max_child_expand (toolbar);
1646 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1648 ToolbarContent *content = list->data;
1650 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1652 gint extra = size / n_expand_items;
1653 if (size % n_expand_items != 0)
1656 if (extra > max_child_expand)
1657 extra = max_child_expand;
1659 allocations[i].width += extra;
1665 g_assert (n_expand_items == 0);
1668 /* position items */
1670 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1672 /* both NORMAL and OVERFLOWN items get a position. This ensures
1673 * that sliding will work for OVERFLOWN items too
1675 if (new_states[i] == NORMAL ||
1676 new_states[i] == OVERFLOWN)
1678 allocations[i].x = pos;
1679 allocations[i].y = border_width;
1680 allocations[i].height = short_size;
1682 pos += allocations[i].width;
1686 /* position arrow */
1689 arrow_allocation.x = available_size - border_width - arrow_allocation.width;
1690 arrow_allocation.y = border_width;
1693 item_area.x = border_width;
1694 item_area.y = border_width;
1695 item_area.width = available_size - (need_arrow? arrow_size : 0);
1696 item_area.height = short_size;
1698 /* fix up allocations in the vertical or RTL cases */
1699 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
1701 for (i = 0; i < n_items; ++i)
1702 fixup_allocation_for_vertical (&(allocations[i]));
1705 fixup_allocation_for_vertical (&arrow_allocation);
1707 fixup_allocation_for_vertical (&item_area);
1709 else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1711 for (i = 0; i < n_items; ++i)
1712 fixup_allocation_for_rtl (available_size, &(allocations[i]));
1715 fixup_allocation_for_rtl (available_size, &arrow_allocation);
1717 fixup_allocation_for_rtl (available_size, &item_area);
1720 /* translate the items by allocation->(x,y) */
1721 for (i = 0; i < n_items; ++i)
1723 allocations[i].x += allocation->x;
1724 allocations[i].y += allocation->y;
1726 if (shadow_type != GTK_SHADOW_NONE)
1728 allocations[i].x += padding.left;
1729 allocations[i].y += padding.top;
1735 arrow_allocation.x += allocation->x;
1736 arrow_allocation.y += allocation->y;
1738 if (shadow_type != GTK_SHADOW_NONE)
1740 arrow_allocation.x += padding.left;
1741 arrow_allocation.y += padding.top;
1745 item_area.x += allocation->x;
1746 item_area.y += allocation->y;
1747 if (shadow_type != GTK_SHADOW_NONE)
1749 item_area.x += padding.left;
1750 item_area.y += padding.top;
1753 /* did anything change? */
1754 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1756 ToolbarContent *content = list->data;
1758 if (toolbar_content_get_state (content) == NORMAL &&
1759 new_states[i] != NORMAL)
1761 /* an item disappeared and we didn't change size, so begin sliding */
1763 gtk_toolbar_begin_sliding (toolbar);
1767 /* finally allocate the items */
1768 if (priv->is_sliding)
1770 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1772 ToolbarContent *content = list->data;
1774 toolbar_content_set_goal_allocation (content, &(allocations[i]));
1778 elapsed = g_timer_elapsed (priv->timer, NULL);
1779 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1781 ToolbarContent *content = list->data;
1783 if (new_states[i] == OVERFLOWN ||
1784 new_states[i] == NORMAL)
1786 GtkAllocation alloc;
1787 GtkAllocation start_allocation = { 0, };
1788 GtkAllocation goal_allocation;
1790 if (priv->is_sliding)
1792 toolbar_content_get_start_allocation (content, &start_allocation);
1793 toolbar_content_get_goal_allocation (content, &goal_allocation);
1795 compute_intermediate_allocation (toolbar,
1800 priv->need_sync = TRUE;
1804 alloc = allocations[i];
1807 if (alloc.width <= 0 || alloc.height <= 0)
1809 toolbar_content_set_child_visible (content, toolbar, FALSE);
1813 if (!rect_within (&alloc, &item_area))
1815 toolbar_content_set_child_visible (content, toolbar, FALSE);
1816 toolbar_content_size_allocate (content, &alloc);
1820 toolbar_content_set_child_visible (content, toolbar, TRUE);
1821 toolbar_content_size_allocate (content, &alloc);
1827 toolbar_content_set_child_visible (content, toolbar, FALSE);
1830 toolbar_content_set_state (content, new_states[i]);
1833 if (priv->menu && priv->need_rebuild)
1834 rebuild_menu (toolbar);
1838 gtk_widget_size_allocate (GTK_WIDGET (priv->arrow_button),
1840 gtk_widget_show (GTK_WIDGET (priv->arrow_button));
1844 gtk_widget_hide (GTK_WIDGET (priv->arrow_button));
1846 if (priv->menu && gtk_widget_get_visible (GTK_WIDGET (priv->menu)))
1847 gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
1850 g_free (allocations);
1851 g_free (new_states);
1855 gtk_toolbar_update_button_relief (GtkToolbar *toolbar)
1857 GtkToolbarPrivate *priv = toolbar->priv;
1858 GtkReliefStyle relief;
1860 relief = get_button_relief (toolbar);
1862 if (relief != gtk_button_get_relief (GTK_BUTTON (priv->arrow_button)))
1864 gtk_toolbar_reconfigured (toolbar);
1866 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), relief);
1871 gtk_toolbar_style_updated (GtkWidget *widget)
1873 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1874 GtkToolbarPrivate *priv = toolbar->priv;
1876 priv->max_homogeneous_pixels = -1;
1878 if (gtk_widget_get_realized (widget))
1879 gtk_style_context_set_background (gtk_widget_get_style_context (widget),
1880 gtk_widget_get_window (widget));
1882 gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
1886 gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
1887 GtkDirectionType dir)
1889 GtkToolbarPrivate *priv = toolbar->priv;
1890 GList *result = NULL;
1894 /* generate list of children in reverse logical order */
1896 for (list = priv->content; list != NULL; list = list->next)
1898 ToolbarContent *content = list->data;
1901 widget = toolbar_content_get_widget (content);
1904 result = g_list_prepend (result, widget);
1907 result = g_list_prepend (result, priv->arrow_button);
1909 rtl = (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL);
1911 /* move in logical order when
1913 * - dir is TAB_FORWARD
1915 * - in RTL mode and moving left or up
1917 * - in LTR mode and moving right or down
1919 if (dir == GTK_DIR_TAB_FORWARD ||
1920 (rtl && (dir == GTK_DIR_UP || dir == GTK_DIR_LEFT)) ||
1921 (!rtl && (dir == GTK_DIR_DOWN || dir == GTK_DIR_RIGHT)))
1923 result = g_list_reverse (result);
1930 gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
1931 gboolean focus_home)
1933 GList *children, *list;
1934 GtkDirectionType dir = focus_home? GTK_DIR_RIGHT : GTK_DIR_LEFT;
1936 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1938 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1940 children = g_list_reverse (children);
1942 dir = (dir == GTK_DIR_RIGHT)? GTK_DIR_LEFT : GTK_DIR_RIGHT;
1945 for (list = children; list != NULL; list = list->next)
1947 GtkWidget *child = list->data;
1949 if (gtk_container_get_focus_child (GTK_CONTAINER (toolbar)) == child)
1952 if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1956 g_list_free (children);
1961 /* Keybinding handler. This function is called when the user presses
1962 * Ctrl TAB or an arrow key.
1965 gtk_toolbar_move_focus (GtkWidget *widget,
1966 GtkDirectionType dir)
1968 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1969 GtkContainer *container = GTK_CONTAINER (toolbar);
1970 GtkWidget *focus_child;
1972 gboolean try_focus = FALSE;
1975 focus_child = gtk_container_get_focus_child (container);
1977 if (focus_child && gtk_widget_child_focus (focus_child, dir))
1980 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1982 for (list = children; list != NULL; list = list->next)
1984 GtkWidget *child = list->data;
1986 if (try_focus && gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1989 if (child == focus_child)
1993 g_list_free (children);
1996 /* The focus handler for the toolbar. It called when the user presses
1997 * TAB or otherwise tries to focus the toolbar.
2000 gtk_toolbar_focus (GtkWidget *widget,
2001 GtkDirectionType dir)
2003 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2004 GList *children, *list;
2005 gboolean result = FALSE;
2007 /* if focus is already somewhere inside the toolbar then return FALSE.
2008 * The only way focus can stay inside the toolbar is when the user presses
2009 * arrow keys or Ctrl TAB (both of which are handled by the
2010 * gtk_toolbar_move_focus() keybinding function.
2012 if (gtk_container_get_focus_child (GTK_CONTAINER (widget)))
2015 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
2017 for (list = children; list != NULL; list = list->next)
2019 GtkWidget *child = list->data;
2021 if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
2028 g_list_free (children);
2033 static GtkSettings *
2034 toolbar_get_settings (GtkToolbar *toolbar)
2036 return toolbar->priv->settings;
2040 style_change_notify (GtkToolbar *toolbar)
2042 GtkToolbarPrivate *priv = toolbar->priv;
2044 if (!priv->style_set)
2046 /* pretend it was set, then unset, thus reverting to new default */
2047 priv->style_set = TRUE;
2048 gtk_toolbar_unset_style (toolbar);
2053 icon_size_change_notify (GtkToolbar *toolbar)
2055 GtkToolbarPrivate *priv = toolbar->priv;
2057 if (!priv->icon_size_set)
2059 /* pretend it was set, then unset, thus reverting to new default */
2060 priv->icon_size_set = TRUE;
2061 gtk_toolbar_unset_icon_size (toolbar);
2066 animation_change_notify (GtkToolbar *toolbar)
2068 GtkToolbarPrivate *priv = toolbar->priv;
2069 GtkSettings *settings = toolbar_get_settings (toolbar);
2073 g_object_get (settings,
2074 "gtk-enable-animations", &animation,
2077 animation = DEFAULT_ANIMATION_STATE;
2079 priv->animation = animation;
2083 settings_change_notify (GtkSettings *settings,
2084 const GParamSpec *pspec,
2085 GtkToolbar *toolbar)
2087 if (! strcmp (pspec->name, "gtk-toolbar-style"))
2088 style_change_notify (toolbar);
2089 else if (! strcmp (pspec->name, "gtk-toolbar-icon-size"))
2090 icon_size_change_notify (toolbar);
2091 else if (! strcmp (pspec->name, "gtk-enable-animations"))
2092 animation_change_notify (toolbar);
2096 gtk_toolbar_screen_changed (GtkWidget *widget,
2097 GdkScreen *previous_screen)
2099 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2100 GtkToolbarPrivate *priv = toolbar->priv;
2101 GtkSettings *old_settings = toolbar_get_settings (toolbar);
2102 GtkSettings *settings;
2104 if (gtk_widget_has_screen (GTK_WIDGET (toolbar)))
2105 settings = gtk_widget_get_settings (GTK_WIDGET (toolbar));
2109 if (settings == old_settings)
2114 g_signal_handler_disconnect (old_settings, priv->settings_connection);
2116 g_object_unref (old_settings);
2121 priv->settings_connection =
2122 g_signal_connect (settings, "notify",
2123 G_CALLBACK (settings_change_notify),
2126 priv->settings = g_object_ref (settings);
2129 priv->settings = NULL;
2131 style_change_notify (toolbar);
2132 icon_size_change_notify (toolbar);
2133 animation_change_notify (toolbar);
2137 find_drop_index (GtkToolbar *toolbar,
2141 GtkToolbarPrivate *priv = toolbar->priv;
2142 GList *interesting_content;
2144 GtkOrientation orientation;
2145 GtkTextDirection direction;
2146 gint best_distance = G_MAXINT;
2150 ToolbarContent *best_content;
2151 GtkAllocation allocation;
2153 /* list items we care about wrt. drag and drop */
2154 interesting_content = NULL;
2155 for (list = priv->content; list != NULL; list = list->next)
2157 ToolbarContent *content = list->data;
2159 if (toolbar_content_get_state (content) == NORMAL)
2160 interesting_content = g_list_prepend (interesting_content, content);
2162 interesting_content = g_list_reverse (interesting_content);
2164 if (!interesting_content)
2167 orientation = priv->orientation;
2168 direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
2170 /* distance to first interesting item */
2171 best_content = interesting_content->data;
2172 toolbar_content_get_allocation (best_content, &allocation);
2174 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2178 if (direction == GTK_TEXT_DIR_LTR)
2181 pos = allocation.x + allocation.width;
2189 best_content = NULL;
2190 best_distance = ABS (pos - cursor);
2192 /* distance to far end of each item */
2193 for (list = interesting_content; list != NULL; list = list->next)
2195 ToolbarContent *content = list->data;
2197 toolbar_content_get_allocation (content, &allocation);
2199 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2201 if (direction == GTK_TEXT_DIR_LTR)
2202 pos = allocation.x + allocation.width;
2208 pos = allocation.y + allocation.height;
2211 distance = ABS (pos - cursor);
2213 if (distance < best_distance)
2215 best_distance = distance;
2216 best_content = content;
2220 g_list_free (interesting_content);
2225 return g_list_index (priv->content, best_content) + 1;
2229 reset_all_placeholders (GtkToolbar *toolbar)
2231 GtkToolbarPrivate *priv = toolbar->priv;
2234 for (list = priv->content; list != NULL; list = list->next)
2236 ToolbarContent *content = list->data;
2237 if (toolbar_content_is_placeholder (content))
2238 toolbar_content_set_disappearing (content, TRUE);
2243 physical_to_logical (GtkToolbar *toolbar,
2246 GtkToolbarPrivate *priv = toolbar->priv;
2250 g_assert (physical >= 0);
2253 for (list = priv->content; list && physical > 0; list = list->next)
2255 ToolbarContent *content = list->data;
2257 if (!toolbar_content_is_placeholder (content))
2262 g_assert (physical == 0);
2268 logical_to_physical (GtkToolbar *toolbar,
2271 GtkToolbarPrivate *priv = toolbar->priv;
2275 g_assert (logical >= 0);
2278 for (list = priv->content; list; list = list->next)
2280 ToolbarContent *content = list->data;
2282 if (!toolbar_content_is_placeholder (content))
2292 g_assert (logical == 0);
2298 * gtk_toolbar_set_drop_highlight_item:
2299 * @toolbar: a #GtkToolbar
2300 * @tool_item: (allow-none): a #GtkToolItem, or %NULL to turn of highlighting
2301 * @index_: a position on @toolbar
2303 * Highlights @toolbar to give an idea of what it would look like
2304 * if @item was added to @toolbar at the position indicated by @index_.
2305 * If @item is %NULL, highlighting is turned off. In that case @index_
2308 * The @tool_item passed to this function must not be part of any widget
2309 * hierarchy. When an item is set as drop highlight item it can not
2310 * added to any widget hierarchy or used as highlight item for another
2316 gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar,
2317 GtkToolItem *tool_item,
2320 ToolbarContent *content;
2321 GtkToolbarPrivate *priv;
2323 GtkRequisition requisition;
2324 GtkRequisition old_requisition;
2325 gboolean restart_sliding;
2327 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2328 g_return_if_fail (tool_item == NULL || GTK_IS_TOOL_ITEM (tool_item));
2330 priv = toolbar->priv;
2334 if (priv->highlight_tool_item)
2336 gtk_widget_unparent (GTK_WIDGET (priv->highlight_tool_item));
2337 g_object_unref (priv->highlight_tool_item);
2338 priv->highlight_tool_item = NULL;
2341 reset_all_placeholders (toolbar);
2342 gtk_toolbar_begin_sliding (toolbar);
2346 n_items = gtk_toolbar_get_n_items (toolbar);
2347 if (index_ < 0 || index_ > n_items)
2350 if (tool_item != priv->highlight_tool_item)
2352 if (priv->highlight_tool_item)
2353 g_object_unref (priv->highlight_tool_item);
2355 g_object_ref_sink (tool_item);
2357 priv->highlight_tool_item = tool_item;
2359 gtk_widget_set_parent (GTK_WIDGET (priv->highlight_tool_item),
2360 GTK_WIDGET (toolbar));
2363 index_ = logical_to_physical (toolbar, index_);
2365 content = g_list_nth_data (priv->content, index_);
2369 ToolbarContent *prev_content;
2371 prev_content = g_list_nth_data (priv->content, index_ - 1);
2373 if (prev_content && toolbar_content_is_placeholder (prev_content))
2374 content = prev_content;
2377 if (!content || !toolbar_content_is_placeholder (content))
2379 GtkWidget *placeholder;
2381 placeholder = GTK_WIDGET (gtk_separator_tool_item_new ());
2383 content = toolbar_content_new_tool_item (toolbar,
2384 GTK_TOOL_ITEM (placeholder),
2386 gtk_widget_show (placeholder);
2390 g_assert (toolbar_content_is_placeholder (content));
2392 gtk_widget_get_preferred_size (GTK_WIDGET (priv->highlight_tool_item),
2393 &requisition, NULL);
2395 toolbar_content_set_expand (content, gtk_tool_item_get_expand (tool_item));
2397 restart_sliding = FALSE;
2398 toolbar_content_size_request (content, toolbar, &old_requisition);
2399 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2401 requisition.height = -1;
2402 if (requisition.width != old_requisition.width)
2403 restart_sliding = TRUE;
2407 requisition.width = -1;
2408 if (requisition.height != old_requisition.height)
2409 restart_sliding = TRUE;
2412 if (toolbar_content_disappearing (content))
2413 restart_sliding = TRUE;
2415 reset_all_placeholders (toolbar);
2416 toolbar_content_set_disappearing (content, FALSE);
2418 toolbar_content_set_size_request (content,
2419 requisition.width, requisition.height);
2421 if (restart_sliding)
2422 gtk_toolbar_begin_sliding (toolbar);
2426 gtk_toolbar_get_child_property (GtkContainer *container,
2432 GtkToolItem *item = GTK_TOOL_ITEM (child);
2434 switch (property_id)
2436 case CHILD_PROP_HOMOGENEOUS:
2437 g_value_set_boolean (value, gtk_tool_item_get_homogeneous (item));
2440 case CHILD_PROP_EXPAND:
2441 g_value_set_boolean (value, gtk_tool_item_get_expand (item));
2445 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2451 gtk_toolbar_set_child_property (GtkContainer *container,
2454 const GValue *value,
2457 switch (property_id)
2459 case CHILD_PROP_HOMOGENEOUS:
2460 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2463 case CHILD_PROP_EXPAND:
2464 gtk_tool_item_set_expand (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2468 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2474 gtk_toolbar_show_all (GtkWidget *widget)
2476 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2477 GtkToolbarPrivate *priv = toolbar->priv;
2480 for (list = priv->content; list != NULL; list = list->next)
2482 ToolbarContent *content = list->data;
2484 toolbar_content_show_all (content);
2487 gtk_widget_show (widget);
2491 gtk_toolbar_add (GtkContainer *container,
2494 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2496 gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
2500 gtk_toolbar_remove (GtkContainer *container,
2503 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2504 GtkToolbarPrivate *priv = toolbar->priv;
2505 ToolbarContent *content_to_remove;
2508 content_to_remove = NULL;
2509 for (list = priv->content; list != NULL; list = list->next)
2511 ToolbarContent *content = list->data;
2514 child = toolbar_content_get_widget (content);
2515 if (child && child == widget)
2517 content_to_remove = content;
2522 g_return_if_fail (content_to_remove != NULL);
2524 toolbar_content_remove (content_to_remove, toolbar);
2525 toolbar_content_free (content_to_remove);
2529 gtk_toolbar_forall (GtkContainer *container,
2530 gboolean include_internals,
2531 GtkCallback callback,
2532 gpointer callback_data)
2534 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2535 GtkToolbarPrivate *priv = toolbar->priv;
2538 g_return_if_fail (callback != NULL);
2540 list = priv->content;
2543 ToolbarContent *content = list->data;
2544 GList *next = list->next;
2546 if (include_internals || !toolbar_content_is_placeholder (content))
2548 GtkWidget *child = toolbar_content_get_widget (content);
2551 callback (child, callback_data);
2557 if (include_internals)
2558 callback (priv->arrow_button, callback_data);
2562 gtk_toolbar_child_type (GtkContainer *container)
2564 return GTK_TYPE_TOOL_ITEM;
2568 gtk_toolbar_reconfigured (GtkToolbar *toolbar)
2570 GtkToolbarPrivate *priv = toolbar->priv;
2573 list = priv->content;
2576 ToolbarContent *content = list->data;
2577 GList *next = list->next;
2579 toolbar_content_toolbar_reconfigured (content, toolbar);
2586 gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
2587 GtkOrientation orientation)
2589 GtkToolbarPrivate *priv = toolbar->priv;
2591 if (priv->orientation != orientation)
2593 priv->orientation = orientation;
2595 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2596 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2598 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2600 gtk_toolbar_reconfigured (toolbar);
2602 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2603 g_object_notify (G_OBJECT (toolbar), "orientation");
2608 gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
2609 GtkToolbarStyle style)
2611 GtkToolbarPrivate *priv = toolbar->priv;
2613 if (priv->style != style)
2615 priv->style = style;
2617 gtk_toolbar_reconfigured (toolbar);
2619 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2620 g_object_notify (G_OBJECT (toolbar), "toolbar-style");
2625 menu_position_func (GtkMenu *menu,
2631 GtkAllocation allocation;
2632 GtkToolbar *toolbar = GTK_TOOLBAR (user_data);
2633 GtkToolbarPrivate *priv = toolbar->priv;
2635 GtkRequisition menu_req;
2636 GdkRectangle monitor;
2640 gtk_widget_get_preferred_size (priv->arrow_button,
2642 gtk_widget_get_preferred_size (GTK_WIDGET (menu),
2645 screen = gtk_widget_get_screen (GTK_WIDGET (menu));
2646 monitor_num = gdk_screen_get_monitor_at_window (screen,
2647 gtk_widget_get_window (priv->arrow_button));
2648 if (monitor_num < 0)
2650 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2652 gtk_widget_get_allocation (priv->arrow_button, &allocation);
2654 gdk_window_get_origin (gtk_button_get_event_window (GTK_BUTTON (priv->arrow_button)), x, y);
2655 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2657 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2658 *x += allocation.width - req.width;
2660 *x += req.width - menu_req.width;
2662 if ((*y + allocation.height + menu_req.height) <= monitor.y + monitor.height)
2663 *y += allocation.height;
2664 else if ((*y - menu_req.height) >= monitor.y)
2665 *y -= menu_req.height;
2666 else if (monitor.y + monitor.height - (*y + allocation.height) > *y)
2667 *y += allocation.height;
2669 *y -= menu_req.height;
2673 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2674 *x += allocation.width;
2676 *x -= menu_req.width;
2678 if (*y + menu_req.height > monitor.y + monitor.height &&
2679 *y + allocation.height - monitor.y > monitor.y + monitor.height - *y)
2680 *y += allocation.height - menu_req.height;
2687 show_menu (GtkToolbar *toolbar,
2688 GdkEventButton *event)
2690 GtkToolbarPrivate *priv = toolbar->priv;
2692 rebuild_menu (toolbar);
2694 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2696 gtk_menu_popup (priv->menu, NULL, NULL,
2697 menu_position_func, toolbar,
2698 event? event->button : 0,
2699 event? event->time : gtk_get_current_event_time());
2703 gtk_toolbar_arrow_button_clicked (GtkWidget *button,
2704 GtkToolbar *toolbar)
2706 GtkToolbarPrivate *priv = toolbar->priv;
2708 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) &&
2709 (!priv->menu || !gtk_widget_get_visible (GTK_WIDGET (priv->menu))))
2711 /* We only get here when the button is clicked with the keyboard,
2712 * because mouse button presses result in the menu being shown so
2713 * that priv->menu would be non-NULL and visible.
2715 show_menu (toolbar, NULL);
2716 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
2721 gtk_toolbar_arrow_button_press (GtkWidget *button,
2722 GdkEventButton *event,
2723 GtkToolbar *toolbar)
2725 show_menu (toolbar, event);
2726 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
2732 gtk_toolbar_button_press (GtkWidget *toolbar,
2733 GdkEventButton *event)
2737 if (event->button == 3)
2739 gboolean return_value;
2741 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2742 (int)event->x_root, (int)event->y_root, event->button,
2745 return return_value;
2748 window = gtk_widget_get_toplevel (toolbar);
2752 gboolean window_drag = FALSE;
2754 gtk_widget_style_get (toolbar,
2755 "window-dragging", &window_drag,
2760 gtk_window_begin_move_drag (GTK_WINDOW (window),
2774 gtk_toolbar_popup_menu (GtkWidget *toolbar)
2776 gboolean return_value;
2777 /* This function is the handler for the "popup menu" keybinding,
2778 * ie., it is called when the user presses Shift F10
2780 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2781 -1, -1, -1, &return_value);
2783 return return_value;
2789 * Creates a new toolbar.
2791 * Return Value: the newly-created toolbar.
2794 gtk_toolbar_new (void)
2796 GtkToolbar *toolbar;
2798 toolbar = g_object_new (GTK_TYPE_TOOLBAR, NULL);
2800 return GTK_WIDGET (toolbar);
2804 * gtk_toolbar_insert:
2805 * @toolbar: a #GtkToolbar
2806 * @item: a #GtkToolItem
2807 * @pos: the position of the new item
2809 * Insert a #GtkToolItem into the toolbar at position @pos. If @pos is
2810 * 0 the item is prepended to the start of the toolbar. If @pos is
2811 * negative, the item is appended to the end of the toolbar.
2816 gtk_toolbar_insert (GtkToolbar *toolbar,
2820 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2821 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
2824 pos = logical_to_physical (toolbar, pos);
2826 toolbar_content_new_tool_item (toolbar, item, FALSE, pos);
2830 * gtk_toolbar_get_item_index:
2831 * @toolbar: a #GtkToolbar
2832 * @item: a #GtkToolItem that is a child of @toolbar
2834 * Returns the position of @item on the toolbar, starting from 0.
2835 * It is an error if @item is not a child of the toolbar.
2837 * Return value: the position of item on the toolbar.
2842 gtk_toolbar_get_item_index (GtkToolbar *toolbar,
2845 GtkToolbarPrivate *priv;
2849 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2850 g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
2851 g_return_val_if_fail (gtk_widget_get_parent (GTK_WIDGET (item)) == GTK_WIDGET (toolbar), -1);
2853 priv = toolbar->priv;
2856 for (list = priv->content; list != NULL; list = list->next)
2858 ToolbarContent *content = list->data;
2861 widget = toolbar_content_get_widget (content);
2863 if (item == GTK_TOOL_ITEM (widget))
2869 return physical_to_logical (toolbar, n);
2873 * gtk_toolbar_set_style:
2874 * @toolbar: a #GtkToolbar.
2875 * @style: the new style for @toolbar.
2877 * Alters the view of @toolbar to display either icons only, text only, or both.
2880 gtk_toolbar_set_style (GtkToolbar *toolbar,
2881 GtkToolbarStyle style)
2883 GtkToolbarPrivate *priv;
2885 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2887 priv = toolbar->priv;
2889 priv->style_set = TRUE;
2890 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2894 * gtk_toolbar_get_style:
2895 * @toolbar: a #GtkToolbar
2897 * Retrieves whether the toolbar has text, icons, or both . See
2898 * gtk_toolbar_set_style().
2900 * Return value: the current style of @toolbar
2903 gtk_toolbar_get_style (GtkToolbar *toolbar)
2905 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_TOOLBAR_STYLE);
2907 return toolbar->priv->style;
2911 * gtk_toolbar_unset_style:
2912 * @toolbar: a #GtkToolbar
2914 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that
2915 * user preferences will be used to determine the toolbar style.
2918 gtk_toolbar_unset_style (GtkToolbar *toolbar)
2920 GtkToolbarPrivate *priv;
2921 GtkToolbarStyle style;
2923 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2925 priv = toolbar->priv;
2927 if (priv->style_set)
2929 GtkSettings *settings = toolbar_get_settings (toolbar);
2932 g_object_get (settings,
2933 "gtk-toolbar-style", &style,
2936 style = DEFAULT_TOOLBAR_STYLE;
2938 if (style != priv->style)
2939 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2941 priv->style_set = FALSE;
2946 * gtk_toolbar_get_n_items:
2947 * @toolbar: a #GtkToolbar
2949 * Returns the number of items on the toolbar.
2951 * Return value: the number of items on the toolbar
2956 gtk_toolbar_get_n_items (GtkToolbar *toolbar)
2958 GtkToolbarPrivate *priv;
2960 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2962 priv = toolbar->priv;
2964 return physical_to_logical (toolbar, g_list_length (priv->content));
2968 * gtk_toolbar_get_nth_item:
2969 * @toolbar: a #GtkToolbar
2970 * @n: A position on the toolbar
2972 * Returns the @n<!-- -->'th item on @toolbar, or %NULL if the
2973 * toolbar does not contain an @n<!-- -->'th item.
2975 * Return value: (transfer none): The @n<!-- -->'th #GtkToolItem on @toolbar,
2976 * or %NULL if there isn't an @n<!-- -->'th item.
2981 gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
2984 GtkToolbarPrivate *priv;
2985 ToolbarContent *content;
2988 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
2990 priv = toolbar->priv;
2992 n_items = gtk_toolbar_get_n_items (toolbar);
2994 if (n < 0 || n >= n_items)
2997 content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
3000 g_assert (!toolbar_content_is_placeholder (content));
3002 return GTK_TOOL_ITEM (toolbar_content_get_widget (content));
3006 * gtk_toolbar_get_icon_size:
3007 * @toolbar: a #GtkToolbar
3009 * Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size().
3011 * Return value: (type int): the current icon size for the icons on
3015 gtk_toolbar_get_icon_size (GtkToolbar *toolbar)
3017 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_ICON_SIZE);
3019 return toolbar->priv->icon_size;
3023 * gtk_toolbar_get_relief_style:
3024 * @toolbar: a #GtkToolbar
3026 * Returns the relief style of buttons on @toolbar. See
3027 * gtk_button_set_relief().
3029 * Return value: The relief style of buttons on @toolbar.
3034 gtk_toolbar_get_relief_style (GtkToolbar *toolbar)
3036 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_RELIEF_NONE);
3038 return get_button_relief (toolbar);
3042 * gtk_toolbar_set_show_arrow:
3043 * @toolbar: a #GtkToolbar
3044 * @show_arrow: Whether to show an overflow menu
3046 * Sets whether to show an overflow menu when
3047 * @toolbar doesn't have room for all items on it. If %TRUE,
3048 * items that there are not room are available through an
3054 gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
3055 gboolean show_arrow)
3057 GtkToolbarPrivate *priv;
3059 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3061 priv = toolbar->priv;
3063 show_arrow = show_arrow != FALSE;
3065 if (priv->show_arrow != show_arrow)
3067 priv->show_arrow = show_arrow;
3069 if (!priv->show_arrow)
3070 gtk_widget_hide (priv->arrow_button);
3072 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3073 g_object_notify (G_OBJECT (toolbar), "show-arrow");
3078 * gtk_toolbar_get_show_arrow:
3079 * @toolbar: a #GtkToolbar
3081 * Returns whether the toolbar has an overflow menu.
3082 * See gtk_toolbar_set_show_arrow().
3084 * Return value: %TRUE if the toolbar has an overflow menu.
3089 gtk_toolbar_get_show_arrow (GtkToolbar *toolbar)
3091 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
3093 return toolbar->priv->show_arrow;
3097 * gtk_toolbar_get_drop_index:
3098 * @toolbar: a #GtkToolbar
3099 * @x: x coordinate of a point on the toolbar
3100 * @y: y coordinate of a point on the toolbar
3102 * Returns the position corresponding to the indicated point on
3103 * @toolbar. This is useful when dragging items to the toolbar:
3104 * this function returns the position a new item should be
3107 * @x and @y are in @toolbar coordinates.
3109 * Return value: The position corresponding to the point (@x, @y) on the toolbar.
3114 gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
3118 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
3120 return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
3124 gtk_toolbar_finalize (GObject *object)
3127 GtkToolbar *toolbar = GTK_TOOLBAR (object);
3128 GtkToolbarPrivate *priv = toolbar->priv;
3130 if (priv->arrow_button)
3131 gtk_widget_unparent (priv->arrow_button);
3133 for (list = priv->content; list != NULL; list = list->next)
3135 ToolbarContent *content = list->data;
3137 toolbar_content_free (content);
3140 g_list_free (priv->content);
3141 g_list_free (priv->children);
3143 g_timer_destroy (priv->timer);
3147 g_signal_handlers_disconnect_by_func (priv->menu,
3148 menu_deactivated, toolbar);
3149 gtk_widget_destroy (GTK_WIDGET (priv->menu));
3153 g_source_remove (priv->idle_id);
3155 G_OBJECT_CLASS (gtk_toolbar_parent_class)->finalize (object);
3159 * gtk_toolbar_set_icon_size:
3160 * @toolbar: A #GtkToolbar
3161 * @icon_size: (type int): The #GtkIconSize that stock icons in the
3162 * toolbar shall have.
3164 * This function sets the size of stock icons in the toolbar. You
3165 * can call it both before you add the icons and after they've been
3166 * added. The size you set will override user preferences for the default
3169 * This should only be used for special-purpose toolbars, normal
3170 * application toolbars should respect the user preferences for the
3174 gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
3175 GtkIconSize icon_size)
3177 GtkToolbarPrivate *priv;
3179 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3180 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
3182 priv = toolbar->priv;
3184 if (!priv->icon_size_set)
3186 priv->icon_size_set = TRUE;
3187 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3190 if (priv->icon_size == icon_size)
3193 priv->icon_size = icon_size;
3194 g_object_notify (G_OBJECT (toolbar), "icon-size");
3196 gtk_toolbar_reconfigured (toolbar);
3198 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3202 * gtk_toolbar_unset_icon_size:
3203 * @toolbar: a #GtkToolbar
3205 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that
3206 * user preferences will be used to determine the icon size.
3209 gtk_toolbar_unset_icon_size (GtkToolbar *toolbar)
3211 GtkToolbarPrivate *priv;
3214 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3216 priv = toolbar->priv;
3218 if (priv->icon_size_set)
3220 GtkSettings *settings = toolbar_get_settings (toolbar);
3224 g_object_get (settings,
3225 "gtk-toolbar-icon-size", &size,
3229 size = DEFAULT_ICON_SIZE;
3231 if (size != priv->icon_size)
3233 gtk_toolbar_set_icon_size (toolbar, size);
3234 g_object_notify (G_OBJECT (toolbar), "icon-size");
3237 priv->icon_size_set = FALSE;
3238 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3243 * ToolbarContent methods
3251 struct _ToolbarContent
3256 GtkAllocation start_allocation;
3257 GtkAllocation goal_allocation;
3258 guint is_placeholder : 1;
3259 guint disappearing : 1;
3263 static ToolbarContent *
3264 toolbar_content_new_tool_item (GtkToolbar *toolbar,
3266 gboolean is_placeholder,
3269 GtkToolbarPrivate *priv = toolbar->priv;
3270 ToolbarContent *content;
3272 content = g_slice_new0 (ToolbarContent);
3274 content->state = NOT_ALLOCATED;
3275 content->item = item;
3276 content->is_placeholder = is_placeholder;
3278 gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
3280 priv->content = g_list_insert (priv->content, content, pos);
3282 if (!is_placeholder)
3284 priv->num_children++;
3286 gtk_toolbar_stop_sliding (toolbar);
3289 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3290 priv->need_rebuild = TRUE;
3296 toolbar_content_remove (ToolbarContent *content,
3297 GtkToolbar *toolbar)
3299 GtkToolbarPrivate *priv = toolbar->priv;
3301 gtk_widget_unparent (GTK_WIDGET (content->item));
3303 priv->content = g_list_remove (priv->content, content);
3305 if (!toolbar_content_is_placeholder (content))
3306 priv->num_children--;
3308 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3309 priv->need_rebuild = TRUE;
3313 toolbar_content_free (ToolbarContent *content)
3315 g_slice_free (ToolbarContent, content);
3319 calculate_max_homogeneous_pixels (GtkWidget *widget)
3321 PangoContext *context;
3322 PangoFontMetrics *metrics;
3323 const PangoFontDescription *font_desc;
3324 GtkStyleContext *style_context;
3325 GtkStateFlags state;
3328 context = gtk_widget_get_pango_context (widget);
3329 style_context = gtk_widget_get_style_context (widget);
3330 state = gtk_widget_get_state_flags (widget);
3332 font_desc = gtk_style_context_get_font (style_context, state);
3334 metrics = pango_context_get_metrics (context, font_desc,
3335 pango_context_get_language (context));
3336 char_width = pango_font_metrics_get_approximate_char_width (metrics);
3337 pango_font_metrics_unref (metrics);
3339 return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
3343 toolbar_content_draw (ToolbarContent *content,
3344 GtkContainer *container,
3349 if (content->is_placeholder)
3352 widget = GTK_WIDGET (content->item);
3355 gtk_container_propagate_draw (container, widget, cr);
3359 toolbar_content_visible (ToolbarContent *content,
3360 GtkToolbar *toolbar)
3362 GtkToolbarPrivate *priv = toolbar->priv;
3365 item = content->item;
3367 if (!gtk_widget_get_visible (GTK_WIDGET (item)))
3370 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
3371 gtk_tool_item_get_visible_horizontal (item))
3374 if (priv->orientation == GTK_ORIENTATION_VERTICAL &&
3375 gtk_tool_item_get_visible_vertical (item))
3382 toolbar_content_size_request (ToolbarContent *content,
3383 GtkToolbar *toolbar,
3384 GtkRequisition *requisition)
3386 gtk_widget_get_preferred_size (GTK_WIDGET (content->item),
3388 if (content->is_placeholder &&
3389 content->disappearing)
3391 requisition->width = 0;
3392 requisition->height = 0;
3397 toolbar_content_is_homogeneous (ToolbarContent *content,
3398 GtkToolbar *toolbar)
3400 GtkToolbarPrivate *priv = toolbar->priv;
3401 GtkRequisition requisition;
3404 if (priv->max_homogeneous_pixels < 0)
3406 priv->max_homogeneous_pixels =
3407 calculate_max_homogeneous_pixels (GTK_WIDGET (toolbar));
3410 toolbar_content_size_request (content, toolbar, &requisition);
3412 if (requisition.width > priv->max_homogeneous_pixels)
3415 result = gtk_tool_item_get_homogeneous (content->item) &&
3416 !GTK_IS_SEPARATOR_TOOL_ITEM (content->item);
3418 if (gtk_tool_item_get_is_important (content->item) &&
3419 priv->style == GTK_TOOLBAR_BOTH_HORIZ &&
3420 priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3429 toolbar_content_is_placeholder (ToolbarContent *content)
3431 if (content->is_placeholder)
3438 toolbar_content_disappearing (ToolbarContent *content)
3440 if (content->disappearing)
3447 toolbar_content_get_state (ToolbarContent *content)
3449 return content->state;
3453 toolbar_content_child_visible (ToolbarContent *content)
3455 return gtk_widget_get_child_visible (GTK_WIDGET (content->item));
3459 toolbar_content_get_goal_allocation (ToolbarContent *content,
3460 GtkAllocation *allocation)
3462 *allocation = content->goal_allocation;
3466 toolbar_content_get_allocation (ToolbarContent *content,
3467 GtkAllocation *allocation)
3469 gtk_widget_get_allocation (GTK_WIDGET (content->item), allocation);
3473 toolbar_content_set_start_allocation (ToolbarContent *content,
3474 GtkAllocation *allocation)
3476 content->start_allocation = *allocation;
3480 toolbar_content_get_expand (ToolbarContent *content)
3482 if (!content->disappearing &&
3483 gtk_tool_item_get_expand (content->item))
3490 toolbar_content_set_goal_allocation (ToolbarContent *content,
3491 GtkAllocation *allocation)
3493 content->goal_allocation = *allocation;
3497 toolbar_content_set_child_visible (ToolbarContent *content,
3498 GtkToolbar *toolbar,
3501 gtk_widget_set_child_visible (GTK_WIDGET (content->item),
3506 toolbar_content_get_start_allocation (ToolbarContent *content,
3507 GtkAllocation *start_allocation)
3509 *start_allocation = content->start_allocation;
3513 toolbar_content_size_allocate (ToolbarContent *content,
3514 GtkAllocation *allocation)
3516 gtk_widget_size_allocate (GTK_WIDGET (content->item),
3521 toolbar_content_set_state (ToolbarContent *content,
3524 content->state = state;
3528 toolbar_content_get_widget (ToolbarContent *content)
3530 return GTK_WIDGET (content->item);
3535 toolbar_content_set_disappearing (ToolbarContent *content,
3536 gboolean disappearing)
3538 content->disappearing = disappearing;
3542 toolbar_content_set_size_request (ToolbarContent *content,
3546 gtk_widget_set_size_request (GTK_WIDGET (content->item),
3551 toolbar_content_toolbar_reconfigured (ToolbarContent *content,
3552 GtkToolbar *toolbar)
3554 gtk_tool_item_toolbar_reconfigured (content->item);
3558 toolbar_content_retrieve_menu_item (ToolbarContent *content)
3560 return gtk_tool_item_retrieve_proxy_menu_item (content->item);
3564 toolbar_content_has_proxy_menu_item (ToolbarContent *content)
3566 GtkWidget *menu_item;
3568 if (content->has_menu == YES)
3570 else if (content->has_menu == NO)
3573 menu_item = toolbar_content_retrieve_menu_item (content);
3575 content->has_menu = menu_item? YES : NO;
3577 return menu_item != NULL;
3581 toolbar_content_set_unknown_menu_status (ToolbarContent *content)
3583 content->has_menu = UNKNOWN;
3587 toolbar_content_is_separator (ToolbarContent *content)
3589 return GTK_IS_SEPARATOR_TOOL_ITEM (content->item);
3593 toolbar_content_set_expand (ToolbarContent *content,
3596 gtk_tool_item_set_expand (content->item, expand);
3600 toolbar_content_show_all (ToolbarContent *content)
3604 widget = toolbar_content_get_widget (content);
3606 gtk_widget_show_all (widget);
3612 static GtkReliefStyle
3613 get_button_relief (GtkToolbar *toolbar)
3615 GtkReliefStyle button_relief = GTK_RELIEF_NORMAL;
3617 gtk_widget_style_get (GTK_WIDGET (toolbar),
3618 "button-relief", &button_relief,
3621 return button_relief;
3625 get_internal_padding (GtkToolbar *toolbar)
3629 gtk_widget_style_get (GTK_WIDGET (toolbar),
3630 "internal-padding", &ipadding,
3637 get_max_child_expand (GtkToolbar *toolbar)
3639 gint mexpand = G_MAXINT;
3641 gtk_widget_style_get (GTK_WIDGET (toolbar),
3642 "max-child-expand", &mexpand,
3647 static GtkShadowType
3648 get_shadow_type (GtkToolbar *toolbar)
3650 GtkShadowType shadow_type;
3652 gtk_widget_style_get (GTK_WIDGET (toolbar),
3653 "shadow-type", &shadow_type,
3659 /* GTK+ internal methods */
3662 _gtk_toolbar_get_default_space_size (void)
3664 return DEFAULT_SPACE_SIZE;
3668 _gtk_toolbar_paint_space_line (GtkWidget *widget,
3669 GtkToolbar *toolbar,
3672 GtkToolbarPrivate *priv = toolbar->priv;
3673 GtkOrientation orientation;
3674 GtkStyleContext *context;
3675 GtkStateFlags state;
3679 const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
3680 const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
3682 g_return_if_fail (GTK_IS_WIDGET (widget));
3684 orientation = toolbar? priv->orientation : GTK_ORIENTATION_HORIZONTAL;
3686 context = gtk_widget_get_style_context (widget);
3687 window = gtk_widget_get_window (widget);
3688 state = gtk_widget_get_state_flags (widget);
3689 width = gtk_widget_get_allocated_width (widget);
3690 height = gtk_widget_get_allocated_height (widget);
3691 gtk_style_context_get_padding (context, state, &padding);
3693 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3695 gboolean wide_separators;
3696 gint separator_width;
3698 gtk_widget_style_get (widget,
3699 "wide-separators", &wide_separators,
3700 "separator-width", &separator_width,
3703 if (wide_separators)
3704 gtk_render_frame (context, cr,
3705 (width - separator_width) / 2,
3706 height * start_fraction,
3708 height * (end_fraction - start_fraction));
3710 gtk_render_line (context, cr,
3711 (width - padding.left) / 2,
3712 height * start_fraction,
3713 (width - padding.left) / 2,
3714 height * end_fraction);
3718 gboolean wide_separators;
3719 gint separator_height;
3721 gtk_widget_style_get (widget,
3722 "wide-separators", &wide_separators,
3723 "separator-height", &separator_height,
3726 if (wide_separators)
3727 gtk_render_frame (context, cr,
3728 width * start_fraction,
3729 (height - separator_height) / 2,
3730 width * (end_fraction - start_fraction),
3733 gtk_render_line (context, cr,
3734 width * start_fraction,
3735 (height - padding.top) / 2,
3736 width * end_fraction,
3737 (height - padding.top) / 2);
3742 _gtk_toolbar_elide_underscores (const gchar *original)
3745 const gchar *p, *end;
3747 gboolean last_underscore;
3752 len = strlen (original);
3753 q = result = g_malloc (len + 1);
3754 last_underscore = FALSE;
3756 end = original + len;
3757 for (p = original; p < end; p++)
3759 if (!last_underscore && *p == '_')
3760 last_underscore = TRUE;
3763 last_underscore = FALSE;
3764 if (original + 2 <= p && p + 1 <= end &&
3765 p[-2] == '(' && p[-1] == '_' && p[0] != '_' && p[1] == ')')
3776 if (last_underscore)
3785 toolbar_get_icon_size (GtkToolShell *shell)
3787 GtkToolbar *toolbar = GTK_TOOLBAR (shell);
3788 GtkToolbarPrivate *priv = toolbar->priv;
3790 return priv->icon_size;
3793 static GtkOrientation
3794 toolbar_get_orientation (GtkToolShell *shell)
3796 GtkToolbar *toolbar = GTK_TOOLBAR (shell);
3797 GtkToolbarPrivate *priv = toolbar->priv;
3799 return priv->orientation;
3802 static GtkToolbarStyle
3803 toolbar_get_style (GtkToolShell *shell)
3805 GtkToolbar *toolbar = GTK_TOOLBAR (shell);
3806 GtkToolbarPrivate *priv = toolbar->priv;
3811 static GtkReliefStyle
3812 toolbar_get_relief_style (GtkToolShell *shell)
3814 return get_button_relief (GTK_TOOLBAR (shell));
3818 toolbar_rebuild_menu (GtkToolShell *shell)
3820 GtkToolbar *toolbar = GTK_TOOLBAR (shell);
3821 GtkToolbarPrivate *priv = toolbar->priv;
3824 priv->need_rebuild = TRUE;
3826 for (list = priv->content; list != NULL; list = list->next)
3828 ToolbarContent *content = list->data;
3830 toolbar_content_set_unknown_menu_status (content);
3833 gtk_widget_queue_resize (GTK_WIDGET (shell));