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"
62 typedef struct _ToolbarContent ToolbarContent;
64 #define DEFAULT_IPADDING 0
66 #define DEFAULT_SPACE_SIZE 12
67 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
68 #define SPACE_LINE_DIVISION 10.0
69 #define SPACE_LINE_START 2.0
70 #define SPACE_LINE_END 8.0
72 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
73 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
74 #define DEFAULT_ANIMATION_STATE TRUE
76 #define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
77 * in the homogeneous game. In units of
78 * pango_font_get_estimated_char_width().
80 #define SLIDE_SPEED 600.0 /* How fast the items slide, in pixels per second */
81 #define ACCEL_THRESHOLD 0.18 /* After how much time in seconds will items start speeding up */
84 struct _GtkToolbarPrivate
86 GtkIconSize icon_size;
88 GtkOrientation orientation;
89 GtkSettings *settings;
90 GtkToolbarStyle style;
91 GtkToolItem *highlight_tool_item;
93 GtkWidget *arrow_button;
95 GdkWindow *event_window;
103 gint button_maxw; /* maximum width of homogeneous children */
104 gint button_maxh; /* maximum height of homogeneous children */
105 gint max_homogeneous_pixels;
108 gulong settings_connection;
111 guint icon_size_set : 1;
112 guint is_sliding : 1;
113 guint need_rebuild : 1; /* whether the overflow menu should be regenerated */
115 guint show_arrow : 1;
130 /* Child properties */
134 CHILD_PROP_HOMOGENEOUS
154 static void gtk_toolbar_set_property (GObject *object,
158 static void gtk_toolbar_get_property (GObject *object,
162 static gint gtk_toolbar_draw (GtkWidget *widget,
164 static void gtk_toolbar_realize (GtkWidget *widget);
165 static void gtk_toolbar_unrealize (GtkWidget *widget);
166 static void gtk_toolbar_size_request (GtkWidget *widget,
167 GtkRequisition *requisition);
168 static void gtk_toolbar_size_allocate (GtkWidget *widget,
169 GtkAllocation *allocation);
170 static void gtk_toolbar_style_set (GtkWidget *widget,
171 GtkStyle *prev_style);
172 static gboolean gtk_toolbar_focus (GtkWidget *widget,
173 GtkDirectionType dir);
174 static void gtk_toolbar_move_focus (GtkWidget *widget,
175 GtkDirectionType dir);
176 static void gtk_toolbar_screen_changed (GtkWidget *widget,
177 GdkScreen *previous_screen);
178 static void gtk_toolbar_map (GtkWidget *widget);
179 static void gtk_toolbar_unmap (GtkWidget *widget);
180 static void gtk_toolbar_set_child_property (GtkContainer *container,
185 static void gtk_toolbar_get_child_property (GtkContainer *container,
190 static void gtk_toolbar_finalize (GObject *object);
191 static void gtk_toolbar_show_all (GtkWidget *widget);
192 static void gtk_toolbar_hide_all (GtkWidget *widget);
193 static void gtk_toolbar_add (GtkContainer *container,
195 static void gtk_toolbar_remove (GtkContainer *container,
197 static void gtk_toolbar_forall (GtkContainer *container,
198 gboolean include_internals,
199 GtkCallback callback,
200 gpointer callback_data);
201 static GType gtk_toolbar_child_type (GtkContainer *container);
202 static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
203 GtkOrientation orientation);
204 static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
205 GtkToolbarStyle style);
206 static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
207 gboolean focus_home);
208 static gboolean gtk_toolbar_button_press (GtkWidget *toolbar,
209 GdkEventButton *event);
210 static gboolean gtk_toolbar_arrow_button_press (GtkWidget *button,
211 GdkEventButton *event,
212 GtkToolbar *toolbar);
213 static void gtk_toolbar_arrow_button_clicked (GtkWidget *button,
214 GtkToolbar *toolbar);
215 static void gtk_toolbar_update_button_relief (GtkToolbar *toolbar);
216 static gboolean gtk_toolbar_popup_menu (GtkWidget *toolbar);
217 static void gtk_toolbar_reconfigured (GtkToolbar *toolbar);
219 static GtkReliefStyle get_button_relief (GtkToolbar *toolbar);
220 static gint get_internal_padding (GtkToolbar *toolbar);
221 static gint get_max_child_expand (GtkToolbar *toolbar);
222 static GtkShadowType get_shadow_type (GtkToolbar *toolbar);
224 /* methods on ToolbarContent 'class' */
225 static ToolbarContent *toolbar_content_new_tool_item (GtkToolbar *toolbar,
227 gboolean is_placeholder,
229 static void toolbar_content_remove (ToolbarContent *content,
230 GtkToolbar *toolbar);
231 static void toolbar_content_free (ToolbarContent *content);
232 static void toolbar_content_draw (ToolbarContent *content,
233 GtkContainer *container,
235 static gboolean toolbar_content_visible (ToolbarContent *content,
236 GtkToolbar *toolbar);
237 static void toolbar_content_size_request (ToolbarContent *content,
239 GtkRequisition *requisition);
240 static gboolean toolbar_content_is_homogeneous (ToolbarContent *content,
241 GtkToolbar *toolbar);
242 static gboolean toolbar_content_is_placeholder (ToolbarContent *content);
243 static gboolean toolbar_content_disappearing (ToolbarContent *content);
244 static ItemState toolbar_content_get_state (ToolbarContent *content);
245 static gboolean toolbar_content_child_visible (ToolbarContent *content);
246 static void toolbar_content_get_goal_allocation (ToolbarContent *content,
247 GtkAllocation *allocation);
248 static void toolbar_content_get_allocation (ToolbarContent *content,
249 GtkAllocation *allocation);
250 static void toolbar_content_set_start_allocation (ToolbarContent *content,
251 GtkAllocation *new_start_allocation);
252 static void toolbar_content_get_start_allocation (ToolbarContent *content,
253 GtkAllocation *start_allocation);
254 static gboolean toolbar_content_get_expand (ToolbarContent *content);
255 static void toolbar_content_set_goal_allocation (ToolbarContent *content,
256 GtkAllocation *allocation);
257 static void toolbar_content_set_child_visible (ToolbarContent *content,
260 static void toolbar_content_size_allocate (ToolbarContent *content,
261 GtkAllocation *allocation);
262 static void toolbar_content_set_state (ToolbarContent *content,
263 ItemState new_state);
264 static GtkWidget * toolbar_content_get_widget (ToolbarContent *content);
265 static void toolbar_content_set_disappearing (ToolbarContent *content,
266 gboolean disappearing);
267 static void toolbar_content_set_size_request (ToolbarContent *content,
270 static void toolbar_content_toolbar_reconfigured (ToolbarContent *content,
271 GtkToolbar *toolbar);
272 static GtkWidget * toolbar_content_retrieve_menu_item (ToolbarContent *content);
273 static gboolean toolbar_content_has_proxy_menu_item (ToolbarContent *content);
274 static gboolean toolbar_content_is_separator (ToolbarContent *content);
275 static void toolbar_content_show_all (ToolbarContent *content);
276 static void toolbar_content_hide_all (ToolbarContent *content);
277 static void toolbar_content_set_expand (ToolbarContent *content,
280 static void toolbar_tool_shell_iface_init (GtkToolShellIface *iface);
281 static GtkIconSize toolbar_get_icon_size (GtkToolShell *shell);
282 static GtkOrientation toolbar_get_orientation (GtkToolShell *shell);
283 static GtkToolbarStyle toolbar_get_style (GtkToolShell *shell);
284 static GtkReliefStyle toolbar_get_relief_style (GtkToolShell *shell);
285 static void toolbar_rebuild_menu (GtkToolShell *shell);
288 G_DEFINE_TYPE_WITH_CODE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER,
289 G_IMPLEMENT_INTERFACE (GTK_TYPE_TOOL_SHELL,
290 toolbar_tool_shell_iface_init)
291 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
294 static guint toolbar_signals[LAST_SIGNAL] = { 0 };
298 add_arrow_bindings (GtkBindingSet *binding_set,
300 GtkDirectionType dir)
302 guint keypad_keysym = keysym - GDK_KEY_Left + GDK_KEY_KP_Left;
304 gtk_binding_entry_add_signal (binding_set, keysym, 0,
306 GTK_TYPE_DIRECTION_TYPE, dir);
307 gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
309 GTK_TYPE_DIRECTION_TYPE, dir);
313 add_ctrl_tab_bindings (GtkBindingSet *binding_set,
314 GdkModifierType modifiers,
315 GtkDirectionType direction)
317 gtk_binding_entry_add_signal (binding_set,
318 GDK_KEY_Tab, GDK_CONTROL_MASK | modifiers,
320 GTK_TYPE_DIRECTION_TYPE, direction);
321 gtk_binding_entry_add_signal (binding_set,
322 GDK_KEY_KP_Tab, GDK_CONTROL_MASK | modifiers,
324 GTK_TYPE_DIRECTION_TYPE, direction);
328 gtk_toolbar_class_init (GtkToolbarClass *klass)
330 GObjectClass *gobject_class;
331 GtkWidgetClass *widget_class;
332 GtkContainerClass *container_class;
333 GtkBindingSet *binding_set;
335 gobject_class = (GObjectClass *)klass;
336 widget_class = (GtkWidgetClass *)klass;
337 container_class = (GtkContainerClass *)klass;
339 gobject_class->set_property = gtk_toolbar_set_property;
340 gobject_class->get_property = gtk_toolbar_get_property;
341 gobject_class->finalize = gtk_toolbar_finalize;
343 widget_class->button_press_event = gtk_toolbar_button_press;
344 widget_class->draw = gtk_toolbar_draw;
345 widget_class->size_request = gtk_toolbar_size_request;
346 widget_class->size_allocate = gtk_toolbar_size_allocate;
347 widget_class->style_set = gtk_toolbar_style_set;
348 widget_class->focus = gtk_toolbar_focus;
350 /* need to override the base class function via override_class_handler,
351 * because the signal slot is not available in GtkWidgetClass
353 g_signal_override_class_handler ("move-focus",
355 G_CALLBACK (gtk_toolbar_move_focus));
357 widget_class->screen_changed = gtk_toolbar_screen_changed;
358 widget_class->realize = gtk_toolbar_realize;
359 widget_class->unrealize = gtk_toolbar_unrealize;
360 widget_class->map = gtk_toolbar_map;
361 widget_class->unmap = gtk_toolbar_unmap;
362 widget_class->popup_menu = gtk_toolbar_popup_menu;
363 widget_class->show_all = gtk_toolbar_show_all;
364 widget_class->hide_all = gtk_toolbar_hide_all;
366 container_class->add = gtk_toolbar_add;
367 container_class->remove = gtk_toolbar_remove;
368 container_class->forall = gtk_toolbar_forall;
369 container_class->child_type = gtk_toolbar_child_type;
370 container_class->get_child_property = gtk_toolbar_get_child_property;
371 container_class->set_child_property = gtk_toolbar_set_child_property;
373 klass->orientation_changed = gtk_toolbar_orientation_changed;
374 klass->style_changed = gtk_toolbar_real_style_changed;
377 * GtkToolbar::orientation-changed:
378 * @toolbar: the object which emitted the signal
379 * @orientation: the new #GtkOrientation of the toolbar
381 * Emitted when the orientation of the toolbar changes.
383 toolbar_signals[ORIENTATION_CHANGED] =
384 g_signal_new (I_("orientation-changed"),
385 G_OBJECT_CLASS_TYPE (klass),
387 G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
389 g_cclosure_marshal_VOID__ENUM,
391 GTK_TYPE_ORIENTATION);
393 * GtkToolbar::style-changed:
394 * @toolbar: The #GtkToolbar which emitted the signal
395 * @style: the new #GtkToolbarStyle of the toolbar
397 * Emitted when the style of the toolbar changes.
399 toolbar_signals[STYLE_CHANGED] =
400 g_signal_new (I_("style-changed"),
401 G_OBJECT_CLASS_TYPE (klass),
403 G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
405 g_cclosure_marshal_VOID__ENUM,
407 GTK_TYPE_TOOLBAR_STYLE);
409 * GtkToolbar::popup-context-menu:
410 * @toolbar: the #GtkToolbar which emitted the signal
411 * @x: the x coordinate of the point where the menu should appear
412 * @y: the y coordinate of the point where the menu should appear
413 * @button: the mouse button the user pressed, or -1
415 * Emitted when the user right-clicks the toolbar or uses the
416 * keybinding to display a popup menu.
418 * Application developers should handle this signal if they want
419 * to display a context menu on the toolbar. The context-menu should
420 * appear at the coordinates given by @x and @y. The mouse button
421 * number is given by the @button parameter. If the menu was popped
422 * up using the keybaord, @button is -1.
424 * Return value: return %TRUE if the signal was handled, %FALSE if not
426 toolbar_signals[POPUP_CONTEXT_MENU] =
427 g_signal_new (I_("popup-context-menu"),
428 G_OBJECT_CLASS_TYPE (klass),
430 G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
431 _gtk_boolean_handled_accumulator, NULL,
432 _gtk_marshal_BOOLEAN__INT_INT_INT,
434 G_TYPE_INT, G_TYPE_INT,
438 * GtkToolbar::focus-home-or-end:
439 * @toolbar: the #GtkToolbar which emitted the signal
440 * @focus_home: %TRUE if the first item should be focused
442 * A keybinding signal used internally by GTK+. This signal can't
443 * be used in application code
445 * Return value: %TRUE if the signal was handled, %FALSE if not
447 toolbar_signals[FOCUS_HOME_OR_END] =
448 g_signal_new_class_handler (I_("focus-home-or-end"),
449 G_OBJECT_CLASS_TYPE (klass),
450 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
451 G_CALLBACK (gtk_toolbar_focus_home_or_end),
453 _gtk_marshal_BOOLEAN__BOOLEAN,
458 g_object_class_override_property (gobject_class,
462 g_object_class_install_property (gobject_class,
464 g_param_spec_enum ("toolbar-style",
466 P_("How to draw the toolbar"),
467 GTK_TYPE_TOOLBAR_STYLE,
468 DEFAULT_TOOLBAR_STYLE,
469 GTK_PARAM_READWRITE));
470 g_object_class_install_property (gobject_class,
472 g_param_spec_boolean ("show-arrow",
474 P_("If an arrow should be shown if the toolbar doesn't fit"),
476 GTK_PARAM_READWRITE));
479 * GtkToolbar:icon-size:
481 * The size of the icons in a toolbar is normally determined by
482 * the toolbar-icon-size setting. When this property is set, it
483 * overrides the setting.
485 * This should only be used for special-purpose toolbars, normal
486 * application toolbars should respect the user preferences for the
491 g_object_class_install_property (gobject_class,
493 g_param_spec_int ("icon-size",
495 P_("Size of icons in this toolbar"),
498 GTK_PARAM_READWRITE));
501 * GtkToolbar:icon-size-set:
503 * Is %TRUE if the icon-size property has been set.
507 g_object_class_install_property (gobject_class,
509 g_param_spec_boolean ("icon-size-set",
511 P_("Whether the icon-size property has been set"),
513 GTK_PARAM_READWRITE));
515 /* child properties */
516 gtk_container_class_install_child_property (container_class,
518 g_param_spec_boolean ("expand",
520 P_("Whether the item should receive extra space when the toolbar grows"),
522 GTK_PARAM_READWRITE));
524 gtk_container_class_install_child_property (container_class,
525 CHILD_PROP_HOMOGENEOUS,
526 g_param_spec_boolean ("homogeneous",
528 P_("Whether the item should be the same size as other homogeneous items"),
530 GTK_PARAM_READWRITE));
532 /* style properties */
533 gtk_widget_class_install_style_property (widget_class,
534 g_param_spec_int ("space-size",
536 P_("Size of spacers"),
540 GTK_PARAM_READABLE));
542 gtk_widget_class_install_style_property (widget_class,
543 g_param_spec_int ("internal-padding",
544 P_("Internal padding"),
545 P_("Amount of border space between the toolbar shadow and the buttons"),
549 GTK_PARAM_READABLE));
551 gtk_widget_class_install_style_property (widget_class,
552 g_param_spec_int ("max-child-expand",
553 P_("Maximum child expand"),
554 P_("Maximum amount of space an expandable item will be given"),
558 GTK_PARAM_READABLE));
560 gtk_widget_class_install_style_property (widget_class,
561 g_param_spec_enum ("space-style",
563 P_("Whether spacers are vertical lines or just blank"),
564 GTK_TYPE_TOOLBAR_SPACE_STYLE,
566 GTK_PARAM_READABLE));
568 gtk_widget_class_install_style_property (widget_class,
569 g_param_spec_enum ("button-relief",
571 P_("Type of bevel around toolbar buttons"),
572 GTK_TYPE_RELIEF_STYLE,
574 GTK_PARAM_READABLE));
575 gtk_widget_class_install_style_property (widget_class,
576 g_param_spec_enum ("shadow-type",
578 P_("Style of bevel around the toolbar"),
579 GTK_TYPE_SHADOW_TYPE,
581 GTK_PARAM_READABLE));
583 binding_set = gtk_binding_set_by_class (klass);
585 add_arrow_bindings (binding_set, GDK_KEY_Left, GTK_DIR_LEFT);
586 add_arrow_bindings (binding_set, GDK_KEY_Right, GTK_DIR_RIGHT);
587 add_arrow_bindings (binding_set, GDK_KEY_Up, GTK_DIR_UP);
588 add_arrow_bindings (binding_set, GDK_KEY_Down, GTK_DIR_DOWN);
590 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Home, 0,
591 "focus-home-or-end", 1,
592 G_TYPE_BOOLEAN, TRUE);
593 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Home, 0,
594 "focus-home-or-end", 1,
595 G_TYPE_BOOLEAN, TRUE);
596 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_End, 0,
597 "focus-home-or-end", 1,
598 G_TYPE_BOOLEAN, FALSE);
599 gtk_binding_entry_add_signal (binding_set, GDK_KEY_End, 0,
600 "focus-home-or-end", 1,
601 G_TYPE_BOOLEAN, FALSE);
603 add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
604 add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
606 g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));
610 toolbar_tool_shell_iface_init (GtkToolShellIface *iface)
612 iface->get_icon_size = toolbar_get_icon_size;
613 iface->get_orientation = toolbar_get_orientation;
614 iface->get_style = toolbar_get_style;
615 iface->get_relief_style = toolbar_get_relief_style;
616 iface->rebuild_menu = toolbar_rebuild_menu;
620 gtk_toolbar_init (GtkToolbar *toolbar)
622 GtkToolbarPrivate *priv;
624 toolbar->priv = G_TYPE_INSTANCE_GET_PRIVATE (toolbar,
627 priv = toolbar->priv;
629 gtk_widget_set_can_focus (GTK_WIDGET (toolbar), FALSE);
630 gtk_widget_set_has_window (GTK_WIDGET (toolbar), FALSE);
632 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
633 priv->style = DEFAULT_TOOLBAR_STYLE;
634 priv->icon_size = DEFAULT_ICON_SIZE;
635 priv->animation = DEFAULT_ANIMATION_STATE;
637 priv->arrow_button = gtk_toggle_button_new ();
638 g_signal_connect (priv->arrow_button, "button-press-event",
639 G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar);
640 g_signal_connect (priv->arrow_button, "clicked",
641 G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar);
642 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
643 get_button_relief (toolbar));
645 gtk_button_set_focus_on_click (GTK_BUTTON (priv->arrow_button), FALSE);
647 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
648 gtk_widget_set_name (priv->arrow, "gtk-toolbar-arrow");
649 gtk_widget_show (priv->arrow);
650 gtk_container_add (GTK_CONTAINER (priv->arrow_button), priv->arrow);
652 gtk_widget_set_parent (priv->arrow_button, GTK_WIDGET (toolbar));
654 /* which child position a drop will occur at */
656 priv->show_arrow = TRUE;
657 priv->settings = NULL;
659 priv->max_homogeneous_pixels = -1;
661 priv->timer = g_timer_new ();
665 gtk_toolbar_set_property (GObject *object,
670 GtkToolbar *toolbar = GTK_TOOLBAR (object);
671 GtkToolbarPrivate *priv = toolbar->priv;
675 case PROP_ORIENTATION:
676 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0,
677 g_value_get_enum (value));
679 case PROP_TOOLBAR_STYLE:
680 gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
682 case PROP_SHOW_ARROW:
683 gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
686 gtk_toolbar_set_icon_size (toolbar, g_value_get_int (value));
688 case PROP_ICON_SIZE_SET:
689 if (g_value_get_boolean (value))
690 priv->icon_size_set = TRUE;
692 gtk_toolbar_unset_icon_size (toolbar);
695 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
701 gtk_toolbar_get_property (GObject *object,
706 GtkToolbar *toolbar = GTK_TOOLBAR (object);
707 GtkToolbarPrivate *priv = toolbar->priv;
711 case PROP_ORIENTATION:
712 g_value_set_enum (value, priv->orientation);
714 case PROP_TOOLBAR_STYLE:
715 g_value_set_enum (value, priv->style);
717 case PROP_SHOW_ARROW:
718 g_value_set_boolean (value, priv->show_arrow);
721 g_value_set_int (value, gtk_toolbar_get_icon_size (toolbar));
723 case PROP_ICON_SIZE_SET:
724 g_value_set_boolean (value, priv->icon_size_set);
727 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
733 gtk_toolbar_map (GtkWidget *widget)
735 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
736 GtkToolbarPrivate *priv = toolbar->priv;
738 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->map (widget);
740 if (priv->event_window)
741 gdk_window_show_unraised (priv->event_window);
745 gtk_toolbar_unmap (GtkWidget *widget)
747 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
748 GtkToolbarPrivate *priv = toolbar->priv;
750 if (priv->event_window)
751 gdk_window_hide (priv->event_window);
753 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unmap (widget);
757 gtk_toolbar_realize (GtkWidget *widget)
759 GtkAllocation allocation;
760 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
761 GtkToolbarPrivate *priv = toolbar->priv;
763 GdkWindowAttr attributes;
764 gint attributes_mask;
767 gtk_widget_set_realized (widget, TRUE);
769 gtk_widget_get_allocation (widget, &allocation);
770 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
772 attributes.wclass = GDK_INPUT_ONLY;
773 attributes.window_type = GDK_WINDOW_CHILD;
774 attributes.x = allocation.x + border_width;
775 attributes.y = allocation.y + border_width;
776 attributes.width = allocation.width - border_width * 2;
777 attributes.height = allocation.height - border_width * 2;
778 attributes.event_mask = gtk_widget_get_events (widget);
779 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
780 GDK_BUTTON_RELEASE_MASK |
781 GDK_ENTER_NOTIFY_MASK |
782 GDK_LEAVE_NOTIFY_MASK);
784 attributes_mask = GDK_WA_X | GDK_WA_Y;
786 window = gtk_widget_get_parent_window (widget);
787 gtk_widget_set_window (widget, window);
788 g_object_ref (window);
790 gtk_widget_style_attach (widget);
792 priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
793 &attributes, attributes_mask);
794 gdk_window_set_user_data (priv->event_window, toolbar);
798 gtk_toolbar_unrealize (GtkWidget *widget)
800 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
801 GtkToolbarPrivate *priv = toolbar->priv;
803 if (priv->event_window)
805 gdk_window_set_user_data (priv->event_window, NULL);
806 gdk_window_destroy (priv->event_window);
807 priv->event_window = NULL;
810 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize (widget);
814 gtk_toolbar_draw (GtkWidget *widget,
817 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
818 GtkToolbarPrivate *priv = toolbar->priv;
822 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
824 gtk_paint_box (gtk_widget_get_style (widget),
826 gtk_widget_get_state (widget),
827 get_shadow_type (toolbar),
831 gtk_widget_get_allocated_width (widget) - 2 * border_width,
832 gtk_widget_get_allocated_height (widget) - 2 * border_width);
834 for (list = priv->content; list != NULL; list = list->next)
836 ToolbarContent *content = list->data;
838 toolbar_content_draw (content, GTK_CONTAINER (widget), cr);
841 gtk_container_propagate_draw (GTK_CONTAINER (widget),
849 gtk_toolbar_size_request (GtkWidget *widget,
850 GtkRequisition *requisition)
852 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
853 GtkToolbarPrivate *priv = toolbar->priv;
855 gint max_child_height;
856 gint max_child_width;
857 gint max_homogeneous_child_width;
858 gint max_homogeneous_child_height;
859 gint homogeneous_size;
861 gint pack_front_size;
864 GtkRequisition arrow_requisition;
866 max_homogeneous_child_width = 0;
867 max_homogeneous_child_height = 0;
869 max_child_height = 0;
870 for (list = priv->content; list != NULL; list = list->next)
872 GtkRequisition requisition;
873 ToolbarContent *content = list->data;
875 if (!toolbar_content_visible (content, toolbar))
878 toolbar_content_size_request (content, toolbar, &requisition);
880 max_child_width = MAX (max_child_width, requisition.width);
881 max_child_height = MAX (max_child_height, requisition.height);
883 if (toolbar_content_is_homogeneous (content, toolbar))
885 max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
886 max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
890 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
891 homogeneous_size = max_homogeneous_child_width;
893 homogeneous_size = max_homogeneous_child_height;
896 for (list = priv->content; list != NULL; list = list->next)
898 ToolbarContent *content = list->data;
901 if (!toolbar_content_visible (content, toolbar))
904 if (toolbar_content_is_homogeneous (content, toolbar))
906 size = homogeneous_size;
910 GtkRequisition requisition;
912 toolbar_content_size_request (content, toolbar, &requisition);
914 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
915 size = requisition.width;
917 size = requisition.height;
920 pack_front_size += size;
923 if (priv->show_arrow)
925 gtk_widget_get_preferred_size (priv->arrow_button,
926 &arrow_requisition, NULL);
928 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
929 long_req = arrow_requisition.width;
931 long_req = arrow_requisition.height;
933 /* There is no point requesting space for the arrow if that would take
934 * up more space than all the items combined
936 long_req = MIN (long_req, pack_front_size);
940 arrow_requisition.height = 0;
941 arrow_requisition.width = 0;
943 long_req = pack_front_size;
946 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
948 requisition->width = long_req;
949 requisition->height = MAX (max_child_height, arrow_requisition.height);
953 requisition->height = long_req;
954 requisition->width = MAX (max_child_width, arrow_requisition.width);
958 ipadding = get_internal_padding (toolbar);
960 border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
961 requisition->width += 2 * (ipadding + border_width);
962 requisition->height += 2 * (ipadding + border_width);
964 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
968 style = gtk_widget_get_style (widget);
969 requisition->width += 2 * style->xthickness;
970 requisition->height += 2 * style->ythickness;
973 priv->button_maxw = max_homogeneous_child_width;
974 priv->button_maxh = max_homogeneous_child_height;
978 position (GtkToolbar *toolbar,
983 GtkToolbarPrivate *priv = toolbar->priv;
986 if (!priv->animation)
989 if (elapsed <= ACCEL_THRESHOLD)
991 n_pixels = SLIDE_SPEED * elapsed;
995 /* The formula is a second degree polynomial in
996 * @elapsed that has the line SLIDE_SPEED * @elapsed
997 * as tangent for @elapsed == ACCEL_THRESHOLD.
998 * This makes @n_pixels a smooth function of elapsed time.
1000 n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
1001 SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
1005 return MIN (from + n_pixels, to);
1007 return MAX (from - n_pixels, to);
1011 compute_intermediate_allocation (GtkToolbar *toolbar,
1012 const GtkAllocation *start,
1013 const GtkAllocation *goal,
1014 GtkAllocation *intermediate)
1016 GtkToolbarPrivate *priv = toolbar->priv;
1017 gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
1019 intermediate->x = position (toolbar, start->x, goal->x, elapsed);
1020 intermediate->y = position (toolbar, start->y, goal->y, elapsed);
1021 intermediate->width = position (toolbar, start->x + start->width,
1022 goal->x + goal->width,
1023 elapsed) - intermediate->x;
1024 intermediate->height = position (toolbar, start->y + start->height,
1025 goal->y + goal->height,
1026 elapsed) - intermediate->y;
1030 fixup_allocation_for_rtl (gint total_size,
1031 GtkAllocation *allocation)
1033 allocation->x += (total_size - (2 * allocation->x + allocation->width));
1037 fixup_allocation_for_vertical (GtkAllocation *allocation)
1041 tmp = allocation->x;
1042 allocation->x = allocation->y;
1043 allocation->y = tmp;
1045 tmp = allocation->width;
1046 allocation->width = allocation->height;
1047 allocation->height = tmp;
1051 get_item_size (GtkToolbar *toolbar,
1052 ToolbarContent *content)
1054 GtkToolbarPrivate *priv = toolbar->priv;
1055 GtkRequisition requisition;
1057 toolbar_content_size_request (content, toolbar, &requisition);
1059 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1061 if (toolbar_content_is_homogeneous (content, toolbar))
1062 return priv->button_maxw;
1064 return requisition.width;
1068 if (toolbar_content_is_homogeneous (content, toolbar))
1069 return priv->button_maxh;
1071 return requisition.height;
1076 slide_idle_handler (gpointer data)
1078 GtkToolbar *toolbar = GTK_TOOLBAR (data);
1079 GtkToolbarPrivate *priv = toolbar->priv;
1082 if (priv->need_sync)
1085 priv->need_sync = FALSE;
1088 for (list = priv->content; list != NULL; list = list->next)
1090 ToolbarContent *content = list->data;
1092 GtkAllocation goal_allocation;
1093 GtkAllocation allocation;
1096 state = toolbar_content_get_state (content);
1097 toolbar_content_get_goal_allocation (content, &goal_allocation);
1098 toolbar_content_get_allocation (content, &allocation);
1102 if (state == NOT_ALLOCATED)
1104 /* an unallocated item means that size allocate has to
1105 * called at least once more
1110 /* An invisible item with a goal allocation of
1111 * 0 is already at its goal.
1113 if ((state == NORMAL || state == OVERFLOWN) &&
1114 ((goal_allocation.width != 0 &&
1115 goal_allocation.height != 0) ||
1116 toolbar_content_child_visible (content)))
1118 if ((goal_allocation.x != allocation.x ||
1119 goal_allocation.y != allocation.y ||
1120 goal_allocation.width != allocation.width ||
1121 goal_allocation.height != allocation.height))
1123 /* An item is not in its right position yet. Note
1124 * that OVERFLOWN items do get an allocation in
1125 * gtk_toolbar_size_allocate(). This way you can see
1126 * them slide back in when you drag an item off the
1133 if (toolbar_content_is_placeholder (content) &&
1134 toolbar_content_disappearing (content) &&
1135 toolbar_content_child_visible (content))
1137 /* A disappearing placeholder is still visible.
1145 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1151 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1153 priv->is_sliding = FALSE;
1160 rect_within (GtkAllocation *a1,
1163 return (a1->x >= a2->x &&
1164 a1->x + a1->width <= a2->x + a2->width &&
1166 a1->y + a1->height <= a2->y + a2->height);
1170 gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
1172 GtkAllocation allocation;
1173 GtkWidget *widget = GTK_WIDGET (toolbar);
1174 GtkToolbarPrivate *priv = toolbar->priv;
1183 /* Start the sliding. This function copies the allocation of every
1184 * item into content->start_allocation. For items that haven't
1185 * been allocated yet, we calculate their position and save that
1186 * in start_allocatino along with zero width and zero height.
1188 * FIXME: It would be nice if we could share this code with
1189 * the equivalent in gtk_widget_size_allocate().
1191 priv->is_sliding = TRUE;
1194 priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
1196 gtk_widget_get_allocation (widget, &allocation);
1197 style = gtk_widget_get_style (widget);
1199 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1200 vertical = (priv->orientation == GTK_ORIENTATION_VERTICAL);
1201 border_width = get_internal_padding (toolbar) + gtk_container_get_border_width (GTK_CONTAINER (toolbar));
1205 cur_x = allocation.width - border_width - style->xthickness;
1206 cur_y = allocation.height - border_width - style->ythickness;
1210 cur_x = border_width + style->xthickness;
1211 cur_y = border_width + style->ythickness;
1214 cur_x += allocation.x;
1215 cur_y += allocation.y;
1217 for (list = priv->content; list != NULL; list = list->next)
1219 ToolbarContent *content = list->data;
1220 GtkAllocation new_start_allocation;
1221 GtkAllocation item_allocation;
1224 state = toolbar_content_get_state (content);
1225 toolbar_content_get_allocation (content, &item_allocation);
1227 if ((state == NORMAL &&
1228 rect_within (&item_allocation, &allocation)) ||
1231 new_start_allocation = item_allocation;
1235 new_start_allocation.x = cur_x;
1236 new_start_allocation.y = cur_y;
1240 new_start_allocation.width = allocation.width -
1241 2 * border_width - 2 * style->xthickness;
1242 new_start_allocation.height = 0;
1246 new_start_allocation.width = 0;
1247 new_start_allocation.height = allocation.height -
1248 2 * border_width - 2 * style->ythickness;
1253 cur_y = new_start_allocation.y + new_start_allocation.height;
1255 cur_x = new_start_allocation.x;
1257 cur_x = new_start_allocation.x + new_start_allocation.width;
1259 toolbar_content_set_start_allocation (content, &new_start_allocation);
1262 /* This resize will run before the first idle handler. This
1263 * will make sure that items get the right goal allocation
1264 * so that the idle handler will not immediately return
1267 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1268 g_timer_reset (priv->timer);
1272 gtk_toolbar_stop_sliding (GtkToolbar *toolbar)
1274 GtkToolbarPrivate *priv = toolbar->priv;
1276 if (priv->is_sliding)
1280 priv->is_sliding = FALSE;
1284 g_source_remove (priv->idle_id);
1288 list = priv->content;
1291 ToolbarContent *content = list->data;
1294 if (toolbar_content_is_placeholder (content))
1296 toolbar_content_remove (content, toolbar);
1297 toolbar_content_free (content);
1301 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1306 remove_item (GtkWidget *menu_item,
1309 gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (menu_item)),
1314 menu_deactivated (GtkWidget *menu,
1315 GtkToolbar *toolbar)
1317 GtkToolbarPrivate *priv = toolbar->priv;
1319 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->arrow_button), FALSE);
1323 menu_detached (GtkWidget *widget,
1326 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1327 GtkToolbarPrivate *priv = toolbar->priv;
1333 rebuild_menu (GtkToolbar *toolbar)
1335 GtkToolbarPrivate *priv = toolbar->priv;
1336 GList *list, *children;
1340 priv->menu = GTK_MENU (gtk_menu_new());
1341 gtk_menu_attach_to_widget (priv->menu,
1342 GTK_WIDGET (toolbar),
1345 g_signal_connect (priv->menu, "deactivate",
1346 G_CALLBACK (menu_deactivated), toolbar);
1349 gtk_container_foreach (GTK_CONTAINER (priv->menu), remove_item, NULL);
1351 for (list = priv->content; list != NULL; list = list->next)
1353 ToolbarContent *content = list->data;
1355 if (toolbar_content_get_state (content) == OVERFLOWN &&
1356 !toolbar_content_is_placeholder (content))
1358 GtkWidget *menu_item = toolbar_content_retrieve_menu_item (content);
1362 g_assert (GTK_IS_MENU_ITEM (menu_item));
1363 gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item);
1368 /* Remove leading and trailing separator items */
1369 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1372 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1374 GtkWidget *child = list->data;
1376 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1379 g_list_free (children);
1381 /* Regenerate the list of children so we don't try to remove items twice */
1382 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1384 list = g_list_last (children);
1385 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1387 GtkWidget *child = list->data;
1389 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1392 g_list_free (children);
1394 priv->need_rebuild = FALSE;
1398 gtk_toolbar_size_allocate (GtkWidget *widget,
1399 GtkAllocation *allocation)
1401 GtkAllocation widget_allocation;
1402 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1403 GtkToolbarPrivate *priv = toolbar->priv;
1404 GtkAllocation *allocations;
1405 ItemState *new_states;
1406 GtkAllocation arrow_allocation;
1409 gint size, pos, short_size;
1412 gboolean need_arrow;
1413 gint n_expand_items;
1415 gint available_size;
1418 GtkRequisition arrow_requisition;
1419 gboolean overflowing;
1420 gboolean size_changed;
1422 GtkAllocation item_area;
1423 GtkShadowType shadow_type;
1425 style = gtk_widget_get_style (widget);
1427 gtk_widget_get_allocation (widget, &widget_allocation);
1428 size_changed = FALSE;
1429 if (widget_allocation.x != allocation->x ||
1430 widget_allocation.y != allocation->y ||
1431 widget_allocation.width != allocation->width ||
1432 widget_allocation.height != allocation->height)
1434 size_changed = TRUE;
1438 gtk_toolbar_stop_sliding (toolbar);
1440 gtk_widget_set_allocation (widget, allocation);
1442 border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
1444 if (gtk_widget_get_realized (widget))
1446 gdk_window_move_resize (priv->event_window,
1447 allocation->x + border_width,
1448 allocation->y + border_width,
1449 allocation->width - border_width * 2,
1450 allocation->height - border_width * 2);
1453 border_width += get_internal_padding (toolbar);
1455 gtk_widget_get_preferred_size (priv->arrow_button,
1456 &arrow_requisition, NULL);
1458 shadow_type = get_shadow_type (toolbar);
1460 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1462 available_size = size = allocation->width - 2 * border_width;
1463 short_size = allocation->height - 2 * border_width;
1464 arrow_size = arrow_requisition.width;
1466 if (shadow_type != GTK_SHADOW_NONE)
1468 available_size -= 2 * style->xthickness;
1469 short_size -= 2 * style->ythickness;
1474 available_size = size = allocation->height - 2 * border_width;
1475 short_size = allocation->width - 2 * border_width;
1476 arrow_size = arrow_requisition.height;
1478 if (shadow_type != GTK_SHADOW_NONE)
1480 available_size -= 2 * style->ythickness;
1481 short_size -= 2 * style->xthickness;
1485 n_items = g_list_length (priv->content);
1486 allocations = g_new0 (GtkAllocation, n_items);
1487 new_states = g_new0 (ItemState, n_items);
1491 for (list = priv->content; list != NULL; list = list->next)
1493 ToolbarContent *content = list->data;
1495 if (toolbar_content_visible (content, toolbar))
1497 needed_size += get_item_size (toolbar, content);
1499 /* Do we need an arrow?
1501 * Assume we don't, and see if any non-separator item with a
1502 * proxy menu item is then going to overflow.
1504 if (needed_size > available_size &&
1507 toolbar_content_has_proxy_menu_item (content) &&
1508 !toolbar_content_is_separator (content))
1516 size = available_size - arrow_size;
1518 size = available_size;
1520 /* calculate widths and states of items */
1521 overflowing = FALSE;
1522 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1524 ToolbarContent *content = list->data;
1527 if (!toolbar_content_visible (content, toolbar))
1529 new_states[i] = HIDDEN;
1533 item_size = get_item_size (toolbar, content);
1534 if (item_size <= size && !overflowing)
1537 allocations[i].width = item_size;
1538 new_states[i] = NORMAL;
1543 new_states[i] = OVERFLOWN;
1544 allocations[i].width = item_size;
1548 /* calculate width of arrow */
1551 arrow_allocation.width = arrow_size;
1552 arrow_allocation.height = MAX (short_size, 1);
1555 /* expand expandable items */
1557 /* We don't expand when there is an overflow menu, because that leads to
1558 * weird jumps when items get moved to the overflow menu and the expanding
1559 * items suddenly get a lot of extra space
1563 gint max_child_expand;
1566 for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
1568 ToolbarContent *content = list->data;
1570 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1574 max_child_expand = get_max_child_expand (toolbar);
1575 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1577 ToolbarContent *content = list->data;
1579 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1581 gint extra = size / n_expand_items;
1582 if (size % n_expand_items != 0)
1585 if (extra > max_child_expand)
1586 extra = max_child_expand;
1588 allocations[i].width += extra;
1594 g_assert (n_expand_items == 0);
1597 /* position items */
1599 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1601 /* both NORMAL and OVERFLOWN items get a position. This ensures
1602 * that sliding will work for OVERFLOWN items too
1604 if (new_states[i] == NORMAL ||
1605 new_states[i] == OVERFLOWN)
1607 allocations[i].x = pos;
1608 allocations[i].y = border_width;
1609 allocations[i].height = short_size;
1611 pos += allocations[i].width;
1615 /* position arrow */
1618 arrow_allocation.x = available_size - border_width - arrow_allocation.width;
1619 arrow_allocation.y = border_width;
1622 item_area.x = border_width;
1623 item_area.y = border_width;
1624 item_area.width = available_size - (need_arrow? arrow_size : 0);
1625 item_area.height = short_size;
1627 /* fix up allocations in the vertical or RTL cases */
1628 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
1630 for (i = 0; i < n_items; ++i)
1631 fixup_allocation_for_vertical (&(allocations[i]));
1634 fixup_allocation_for_vertical (&arrow_allocation);
1636 fixup_allocation_for_vertical (&item_area);
1638 else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1640 for (i = 0; i < n_items; ++i)
1641 fixup_allocation_for_rtl (available_size, &(allocations[i]));
1644 fixup_allocation_for_rtl (available_size, &arrow_allocation);
1646 fixup_allocation_for_rtl (available_size, &item_area);
1649 /* translate the items by allocation->(x,y) */
1650 for (i = 0; i < n_items; ++i)
1652 allocations[i].x += allocation->x;
1653 allocations[i].y += allocation->y;
1655 if (shadow_type != GTK_SHADOW_NONE)
1657 allocations[i].x += style->xthickness;
1658 allocations[i].y += style->ythickness;
1664 arrow_allocation.x += allocation->x;
1665 arrow_allocation.y += allocation->y;
1667 if (shadow_type != GTK_SHADOW_NONE)
1669 arrow_allocation.x += style->xthickness;
1670 arrow_allocation.y += style->ythickness;
1674 item_area.x += allocation->x;
1675 item_area.y += allocation->y;
1676 if (shadow_type != GTK_SHADOW_NONE)
1678 item_area.x += style->xthickness;
1679 item_area.y += style->ythickness;
1682 /* did anything change? */
1683 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1685 ToolbarContent *content = list->data;
1687 if (toolbar_content_get_state (content) == NORMAL &&
1688 new_states[i] != NORMAL)
1690 /* an item disappeared and we didn't change size, so begin sliding */
1692 gtk_toolbar_begin_sliding (toolbar);
1696 /* finally allocate the items */
1697 if (priv->is_sliding)
1699 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1701 ToolbarContent *content = list->data;
1703 toolbar_content_set_goal_allocation (content, &(allocations[i]));
1707 elapsed = g_timer_elapsed (priv->timer, NULL);
1708 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1710 ToolbarContent *content = list->data;
1712 if (new_states[i] == OVERFLOWN ||
1713 new_states[i] == NORMAL)
1715 GtkAllocation alloc;
1716 GtkAllocation start_allocation = { 0, };
1717 GtkAllocation goal_allocation;
1719 if (priv->is_sliding)
1721 toolbar_content_get_start_allocation (content, &start_allocation);
1722 toolbar_content_get_goal_allocation (content, &goal_allocation);
1724 compute_intermediate_allocation (toolbar,
1729 priv->need_sync = TRUE;
1733 alloc = allocations[i];
1736 if (alloc.width <= 0 || alloc.height <= 0)
1738 toolbar_content_set_child_visible (content, toolbar, FALSE);
1742 if (!rect_within (&alloc, &item_area))
1744 toolbar_content_set_child_visible (content, toolbar, FALSE);
1745 toolbar_content_size_allocate (content, &alloc);
1749 toolbar_content_set_child_visible (content, toolbar, TRUE);
1750 toolbar_content_size_allocate (content, &alloc);
1756 toolbar_content_set_child_visible (content, toolbar, FALSE);
1759 toolbar_content_set_state (content, new_states[i]);
1762 if (priv->menu && priv->need_rebuild)
1763 rebuild_menu (toolbar);
1767 gtk_widget_size_allocate (GTK_WIDGET (priv->arrow_button),
1769 gtk_widget_show (GTK_WIDGET (priv->arrow_button));
1773 gtk_widget_hide (GTK_WIDGET (priv->arrow_button));
1775 if (priv->menu && gtk_widget_get_visible (GTK_WIDGET (priv->menu)))
1776 gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
1779 g_free (allocations);
1780 g_free (new_states);
1784 gtk_toolbar_update_button_relief (GtkToolbar *toolbar)
1786 GtkToolbarPrivate *priv = toolbar->priv;
1787 GtkReliefStyle relief;
1789 relief = get_button_relief (toolbar);
1791 if (relief != gtk_button_get_relief (GTK_BUTTON (priv->arrow_button)))
1793 gtk_toolbar_reconfigured (toolbar);
1795 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), relief);
1800 gtk_toolbar_style_set (GtkWidget *widget,
1801 GtkStyle *prev_style)
1803 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1804 GtkToolbarPrivate *priv = toolbar->priv;
1806 priv->max_homogeneous_pixels = -1;
1808 if (gtk_widget_get_realized (widget))
1809 gtk_style_set_background (gtk_widget_get_style (widget),
1810 gtk_widget_get_window (widget),
1811 gtk_widget_get_state (widget));
1814 gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
1818 gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
1819 GtkDirectionType dir)
1821 GtkToolbarPrivate *priv = toolbar->priv;
1822 GList *result = NULL;
1826 /* generate list of children in reverse logical order */
1828 for (list = priv->content; list != NULL; list = list->next)
1830 ToolbarContent *content = list->data;
1833 widget = toolbar_content_get_widget (content);
1836 result = g_list_prepend (result, widget);
1839 result = g_list_prepend (result, priv->arrow_button);
1841 rtl = (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL);
1843 /* move in logical order when
1845 * - dir is TAB_FORWARD
1847 * - in RTL mode and moving left or up
1849 * - in LTR mode and moving right or down
1851 if (dir == GTK_DIR_TAB_FORWARD ||
1852 (rtl && (dir == GTK_DIR_UP || dir == GTK_DIR_LEFT)) ||
1853 (!rtl && (dir == GTK_DIR_DOWN || dir == GTK_DIR_RIGHT)))
1855 result = g_list_reverse (result);
1862 gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
1863 gboolean focus_home)
1865 GList *children, *list;
1866 GtkDirectionType dir = focus_home? GTK_DIR_RIGHT : GTK_DIR_LEFT;
1868 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1870 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1872 children = g_list_reverse (children);
1874 dir = (dir == GTK_DIR_RIGHT)? GTK_DIR_LEFT : GTK_DIR_RIGHT;
1877 for (list = children; list != NULL; list = list->next)
1879 GtkWidget *child = list->data;
1881 if (gtk_container_get_focus_child (GTK_CONTAINER (toolbar)) == child)
1884 if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1888 g_list_free (children);
1893 /* Keybinding handler. This function is called when the user presses
1894 * Ctrl TAB or an arrow key.
1897 gtk_toolbar_move_focus (GtkWidget *widget,
1898 GtkDirectionType dir)
1900 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1901 GtkContainer *container = GTK_CONTAINER (toolbar);
1902 GtkWidget *focus_child;
1904 gboolean try_focus = FALSE;
1907 focus_child = gtk_container_get_focus_child (container);
1909 if (focus_child && gtk_widget_child_focus (focus_child, dir))
1912 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1914 for (list = children; list != NULL; list = list->next)
1916 GtkWidget *child = list->data;
1918 if (try_focus && gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1921 if (child == focus_child)
1925 g_list_free (children);
1928 /* The focus handler for the toolbar. It called when the user presses
1929 * TAB or otherwise tries to focus the toolbar.
1932 gtk_toolbar_focus (GtkWidget *widget,
1933 GtkDirectionType dir)
1935 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1936 GList *children, *list;
1937 gboolean result = FALSE;
1939 /* if focus is already somewhere inside the toolbar then return FALSE.
1940 * The only way focus can stay inside the toolbar is when the user presses
1941 * arrow keys or Ctrl TAB (both of which are handled by the
1942 * gtk_toolbar_move_focus() keybinding function.
1944 if (gtk_container_get_focus_child (GTK_CONTAINER (widget)))
1947 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1949 for (list = children; list != NULL; list = list->next)
1951 GtkWidget *child = list->data;
1953 if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1960 g_list_free (children);
1965 static GtkSettings *
1966 toolbar_get_settings (GtkToolbar *toolbar)
1968 return toolbar->priv->settings;
1972 style_change_notify (GtkToolbar *toolbar)
1974 GtkToolbarPrivate *priv = toolbar->priv;
1976 if (!priv->style_set)
1978 /* pretend it was set, then unset, thus reverting to new default */
1979 priv->style_set = TRUE;
1980 gtk_toolbar_unset_style (toolbar);
1985 icon_size_change_notify (GtkToolbar *toolbar)
1987 GtkToolbarPrivate *priv = toolbar->priv;
1989 if (!priv->icon_size_set)
1991 /* pretend it was set, then unset, thus reverting to new default */
1992 priv->icon_size_set = TRUE;
1993 gtk_toolbar_unset_icon_size (toolbar);
1998 animation_change_notify (GtkToolbar *toolbar)
2000 GtkToolbarPrivate *priv = toolbar->priv;
2001 GtkSettings *settings = toolbar_get_settings (toolbar);
2005 g_object_get (settings,
2006 "gtk-enable-animations", &animation,
2009 animation = DEFAULT_ANIMATION_STATE;
2011 priv->animation = animation;
2015 settings_change_notify (GtkSettings *settings,
2016 const GParamSpec *pspec,
2017 GtkToolbar *toolbar)
2019 if (! strcmp (pspec->name, "gtk-toolbar-style"))
2020 style_change_notify (toolbar);
2021 else if (! strcmp (pspec->name, "gtk-toolbar-icon-size"))
2022 icon_size_change_notify (toolbar);
2023 else if (! strcmp (pspec->name, "gtk-enable-animations"))
2024 animation_change_notify (toolbar);
2028 gtk_toolbar_screen_changed (GtkWidget *widget,
2029 GdkScreen *previous_screen)
2031 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2032 GtkToolbarPrivate *priv = toolbar->priv;
2033 GtkSettings *old_settings = toolbar_get_settings (toolbar);
2034 GtkSettings *settings;
2036 if (gtk_widget_has_screen (GTK_WIDGET (toolbar)))
2037 settings = gtk_widget_get_settings (GTK_WIDGET (toolbar));
2041 if (settings == old_settings)
2046 g_signal_handler_disconnect (old_settings, priv->settings_connection);
2048 g_object_unref (old_settings);
2053 priv->settings_connection =
2054 g_signal_connect (settings, "notify",
2055 G_CALLBACK (settings_change_notify),
2058 priv->settings = g_object_ref (settings);
2061 priv->settings = NULL;
2063 style_change_notify (toolbar);
2064 icon_size_change_notify (toolbar);
2065 animation_change_notify (toolbar);
2069 find_drop_index (GtkToolbar *toolbar,
2073 GtkToolbarPrivate *priv = toolbar->priv;
2074 GList *interesting_content;
2076 GtkOrientation orientation;
2077 GtkTextDirection direction;
2078 gint best_distance = G_MAXINT;
2082 ToolbarContent *best_content;
2083 GtkAllocation allocation;
2085 /* list items we care about wrt. drag and drop */
2086 interesting_content = NULL;
2087 for (list = priv->content; list != NULL; list = list->next)
2089 ToolbarContent *content = list->data;
2091 if (toolbar_content_get_state (content) == NORMAL)
2092 interesting_content = g_list_prepend (interesting_content, content);
2094 interesting_content = g_list_reverse (interesting_content);
2096 if (!interesting_content)
2099 orientation = priv->orientation;
2100 direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
2102 /* distance to first interesting item */
2103 best_content = interesting_content->data;
2104 toolbar_content_get_allocation (best_content, &allocation);
2106 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2110 if (direction == GTK_TEXT_DIR_LTR)
2113 pos = allocation.x + allocation.width;
2121 best_content = NULL;
2122 best_distance = ABS (pos - cursor);
2124 /* distance to far end of each item */
2125 for (list = interesting_content; list != NULL; list = list->next)
2127 ToolbarContent *content = list->data;
2129 toolbar_content_get_allocation (content, &allocation);
2131 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2133 if (direction == GTK_TEXT_DIR_LTR)
2134 pos = allocation.x + allocation.width;
2140 pos = allocation.y + allocation.height;
2143 distance = ABS (pos - cursor);
2145 if (distance < best_distance)
2147 best_distance = distance;
2148 best_content = content;
2152 g_list_free (interesting_content);
2157 return g_list_index (priv->content, best_content) + 1;
2161 reset_all_placeholders (GtkToolbar *toolbar)
2163 GtkToolbarPrivate *priv = toolbar->priv;
2166 for (list = priv->content; list != NULL; list = list->next)
2168 ToolbarContent *content = list->data;
2169 if (toolbar_content_is_placeholder (content))
2170 toolbar_content_set_disappearing (content, TRUE);
2175 physical_to_logical (GtkToolbar *toolbar,
2178 GtkToolbarPrivate *priv = toolbar->priv;
2182 g_assert (physical >= 0);
2185 for (list = priv->content; list && physical > 0; list = list->next)
2187 ToolbarContent *content = list->data;
2189 if (!toolbar_content_is_placeholder (content))
2194 g_assert (physical == 0);
2200 logical_to_physical (GtkToolbar *toolbar,
2203 GtkToolbarPrivate *priv = toolbar->priv;
2207 g_assert (logical >= 0);
2210 for (list = priv->content; list; list = list->next)
2212 ToolbarContent *content = list->data;
2214 if (!toolbar_content_is_placeholder (content))
2224 g_assert (logical == 0);
2230 * gtk_toolbar_set_drop_highlight_item:
2231 * @toolbar: a #GtkToolbar
2232 * @tool_item: (allow-none): a #GtkToolItem, or %NULL to turn of highlighting
2233 * @index_: a position on @toolbar
2235 * Highlights @toolbar to give an idea of what it would look like
2236 * if @item was added to @toolbar at the position indicated by @index_.
2237 * If @item is %NULL, highlighting is turned off. In that case @index_
2240 * The @tool_item passed to this function must not be part of any widget
2241 * hierarchy. When an item is set as drop highlight item it can not
2242 * added to any widget hierarchy or used as highlight item for another
2248 gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar,
2249 GtkToolItem *tool_item,
2252 ToolbarContent *content;
2253 GtkToolbarPrivate *priv;
2255 GtkRequisition requisition;
2256 GtkRequisition old_requisition;
2257 gboolean restart_sliding;
2259 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2260 g_return_if_fail (tool_item == NULL || GTK_IS_TOOL_ITEM (tool_item));
2262 priv = toolbar->priv;
2266 if (priv->highlight_tool_item)
2268 gtk_widget_unparent (GTK_WIDGET (priv->highlight_tool_item));
2269 g_object_unref (priv->highlight_tool_item);
2270 priv->highlight_tool_item = NULL;
2273 reset_all_placeholders (toolbar);
2274 gtk_toolbar_begin_sliding (toolbar);
2278 n_items = gtk_toolbar_get_n_items (toolbar);
2279 if (index_ < 0 || index_ > n_items)
2282 if (tool_item != priv->highlight_tool_item)
2284 if (priv->highlight_tool_item)
2285 g_object_unref (priv->highlight_tool_item);
2287 g_object_ref_sink (tool_item);
2289 priv->highlight_tool_item = tool_item;
2291 gtk_widget_set_parent (GTK_WIDGET (priv->highlight_tool_item),
2292 GTK_WIDGET (toolbar));
2295 index_ = logical_to_physical (toolbar, index_);
2297 content = g_list_nth_data (priv->content, index_);
2301 ToolbarContent *prev_content;
2303 prev_content = g_list_nth_data (priv->content, index_ - 1);
2305 if (prev_content && toolbar_content_is_placeholder (prev_content))
2306 content = prev_content;
2309 if (!content || !toolbar_content_is_placeholder (content))
2311 GtkWidget *placeholder;
2313 placeholder = GTK_WIDGET (gtk_separator_tool_item_new ());
2315 content = toolbar_content_new_tool_item (toolbar,
2316 GTK_TOOL_ITEM (placeholder),
2318 gtk_widget_show (placeholder);
2322 g_assert (toolbar_content_is_placeholder (content));
2324 gtk_widget_get_preferred_size (GTK_WIDGET (priv->highlight_tool_item),
2325 &requisition, NULL);
2327 toolbar_content_set_expand (content, gtk_tool_item_get_expand (tool_item));
2329 restart_sliding = FALSE;
2330 toolbar_content_size_request (content, toolbar, &old_requisition);
2331 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2333 requisition.height = -1;
2334 if (requisition.width != old_requisition.width)
2335 restart_sliding = TRUE;
2339 requisition.width = -1;
2340 if (requisition.height != old_requisition.height)
2341 restart_sliding = TRUE;
2344 if (toolbar_content_disappearing (content))
2345 restart_sliding = TRUE;
2347 reset_all_placeholders (toolbar);
2348 toolbar_content_set_disappearing (content, FALSE);
2350 toolbar_content_set_size_request (content,
2351 requisition.width, requisition.height);
2353 if (restart_sliding)
2354 gtk_toolbar_begin_sliding (toolbar);
2358 gtk_toolbar_get_child_property (GtkContainer *container,
2364 GtkToolItem *item = GTK_TOOL_ITEM (child);
2366 switch (property_id)
2368 case CHILD_PROP_HOMOGENEOUS:
2369 g_value_set_boolean (value, gtk_tool_item_get_homogeneous (item));
2372 case CHILD_PROP_EXPAND:
2373 g_value_set_boolean (value, gtk_tool_item_get_expand (item));
2377 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2383 gtk_toolbar_set_child_property (GtkContainer *container,
2386 const GValue *value,
2389 switch (property_id)
2391 case CHILD_PROP_HOMOGENEOUS:
2392 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2395 case CHILD_PROP_EXPAND:
2396 gtk_tool_item_set_expand (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2400 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2406 gtk_toolbar_show_all (GtkWidget *widget)
2408 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2409 GtkToolbarPrivate *priv = toolbar->priv;
2412 for (list = priv->content; list != NULL; list = list->next)
2414 ToolbarContent *content = list->data;
2416 toolbar_content_show_all (content);
2419 gtk_widget_show (widget);
2423 gtk_toolbar_hide_all (GtkWidget *widget)
2425 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2426 GtkToolbarPrivate *priv = toolbar->priv;
2429 for (list = priv->content; list != NULL; list = list->next)
2431 ToolbarContent *content = list->data;
2433 toolbar_content_hide_all (content);
2436 gtk_widget_hide (widget);
2440 gtk_toolbar_add (GtkContainer *container,
2443 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2445 gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
2449 gtk_toolbar_remove (GtkContainer *container,
2452 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2453 GtkToolbarPrivate *priv = toolbar->priv;
2454 ToolbarContent *content_to_remove;
2457 content_to_remove = NULL;
2458 for (list = priv->content; list != NULL; list = list->next)
2460 ToolbarContent *content = list->data;
2463 child = toolbar_content_get_widget (content);
2464 if (child && child == widget)
2466 content_to_remove = content;
2471 g_return_if_fail (content_to_remove != NULL);
2473 toolbar_content_remove (content_to_remove, toolbar);
2474 toolbar_content_free (content_to_remove);
2478 gtk_toolbar_forall (GtkContainer *container,
2479 gboolean include_internals,
2480 GtkCallback callback,
2481 gpointer callback_data)
2483 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2484 GtkToolbarPrivate *priv = toolbar->priv;
2487 g_return_if_fail (callback != NULL);
2489 list = priv->content;
2492 ToolbarContent *content = list->data;
2493 GList *next = list->next;
2495 if (include_internals || !toolbar_content_is_placeholder (content))
2497 GtkWidget *child = toolbar_content_get_widget (content);
2500 callback (child, callback_data);
2506 if (include_internals)
2507 callback (priv->arrow_button, callback_data);
2511 gtk_toolbar_child_type (GtkContainer *container)
2513 return GTK_TYPE_TOOL_ITEM;
2517 gtk_toolbar_reconfigured (GtkToolbar *toolbar)
2519 GtkToolbarPrivate *priv = toolbar->priv;
2522 list = priv->content;
2525 ToolbarContent *content = list->data;
2526 GList *next = list->next;
2528 toolbar_content_toolbar_reconfigured (content, toolbar);
2535 gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
2536 GtkOrientation orientation)
2538 GtkToolbarPrivate *priv = toolbar->priv;
2540 if (priv->orientation != orientation)
2542 priv->orientation = orientation;
2544 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2545 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2547 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2549 gtk_toolbar_reconfigured (toolbar);
2551 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2552 g_object_notify (G_OBJECT (toolbar), "orientation");
2557 gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
2558 GtkToolbarStyle style)
2560 GtkToolbarPrivate *priv = toolbar->priv;
2562 if (priv->style != style)
2564 priv->style = style;
2566 gtk_toolbar_reconfigured (toolbar);
2568 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2569 g_object_notify (G_OBJECT (toolbar), "toolbar-style");
2574 menu_position_func (GtkMenu *menu,
2580 GtkAllocation allocation;
2581 GtkToolbar *toolbar = GTK_TOOLBAR (user_data);
2582 GtkToolbarPrivate *priv = toolbar->priv;
2584 GtkRequisition menu_req;
2585 GdkRectangle monitor;
2589 gtk_widget_get_preferred_size (priv->arrow_button,
2591 gtk_widget_get_preferred_size (GTK_WIDGET (menu),
2594 screen = gtk_widget_get_screen (GTK_WIDGET (menu));
2595 monitor_num = gdk_screen_get_monitor_at_window (screen,
2596 gtk_widget_get_window (priv->arrow_button));
2597 if (monitor_num < 0)
2599 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2601 gtk_widget_get_allocation (priv->arrow_button, &allocation);
2603 gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
2604 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2606 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2607 *x += allocation.width - req.width;
2609 *x += req.width - menu_req.width;
2611 if ((*y + allocation.height + menu_req.height) <= monitor.y + monitor.height)
2612 *y += allocation.height;
2613 else if ((*y - menu_req.height) >= monitor.y)
2614 *y -= menu_req.height;
2615 else if (monitor.y + monitor.height - (*y + allocation.height) > *y)
2616 *y += allocation.height;
2618 *y -= menu_req.height;
2622 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2623 *x += allocation.width;
2625 *x -= menu_req.width;
2627 if (*y + menu_req.height > monitor.y + monitor.height &&
2628 *y + allocation.height - monitor.y > monitor.y + monitor.height - *y)
2629 *y += allocation.height - menu_req.height;
2636 show_menu (GtkToolbar *toolbar,
2637 GdkEventButton *event)
2639 GtkToolbarPrivate *priv = toolbar->priv;
2641 rebuild_menu (toolbar);
2643 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2645 gtk_menu_popup (priv->menu, NULL, NULL,
2646 menu_position_func, toolbar,
2647 event? event->button : 0,
2648 event? event->time : gtk_get_current_event_time());
2652 gtk_toolbar_arrow_button_clicked (GtkWidget *button,
2653 GtkToolbar *toolbar)
2655 GtkToolbarPrivate *priv = toolbar->priv;
2657 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) &&
2658 (!priv->menu || !gtk_widget_get_visible (GTK_WIDGET (priv->menu))))
2660 /* We only get here when the button is clicked with the keyboard,
2661 * because mouse button presses result in the menu being shown so
2662 * that priv->menu would be non-NULL and visible.
2664 show_menu (toolbar, NULL);
2665 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
2670 gtk_toolbar_arrow_button_press (GtkWidget *button,
2671 GdkEventButton *event,
2672 GtkToolbar *toolbar)
2674 show_menu (toolbar, event);
2675 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
2681 gtk_toolbar_button_press (GtkWidget *toolbar,
2682 GdkEventButton *event)
2686 if (event->button == 3)
2688 gboolean return_value;
2690 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2691 (int)event->x_root, (int)event->y_root, event->button,
2694 return return_value;
2697 window = gtk_widget_get_toplevel (toolbar);
2701 gboolean window_drag = FALSE;
2703 gtk_widget_style_get (toolbar,
2704 "window-dragging", &window_drag,
2709 gtk_window_begin_move_drag (GTK_WINDOW (window),
2723 gtk_toolbar_popup_menu (GtkWidget *toolbar)
2725 gboolean return_value;
2726 /* This function is the handler for the "popup menu" keybinding,
2727 * ie., it is called when the user presses Shift F10
2729 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2730 -1, -1, -1, &return_value);
2732 return return_value;
2738 * Creates a new toolbar.
2740 * Return Value: the newly-created toolbar.
2743 gtk_toolbar_new (void)
2745 GtkToolbar *toolbar;
2747 toolbar = g_object_new (GTK_TYPE_TOOLBAR, NULL);
2749 return GTK_WIDGET (toolbar);
2753 * gtk_toolbar_insert:
2754 * @toolbar: a #GtkToolbar
2755 * @item: a #GtkToolItem
2756 * @pos: the position of the new item
2758 * Insert a #GtkToolItem into the toolbar at position @pos. If @pos is
2759 * 0 the item is prepended to the start of the toolbar. If @pos is
2760 * negative, the item is appended to the end of the toolbar.
2765 gtk_toolbar_insert (GtkToolbar *toolbar,
2769 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2770 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
2773 pos = logical_to_physical (toolbar, pos);
2775 toolbar_content_new_tool_item (toolbar, item, FALSE, pos);
2779 * gtk_toolbar_get_item_index:
2780 * @toolbar: a #GtkToolbar
2781 * @item: a #GtkToolItem that is a child of @toolbar
2783 * Returns the position of @item on the toolbar, starting from 0.
2784 * It is an error if @item is not a child of the toolbar.
2786 * Return value: the position of item on the toolbar.
2791 gtk_toolbar_get_item_index (GtkToolbar *toolbar,
2794 GtkToolbarPrivate *priv;
2798 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2799 g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
2800 g_return_val_if_fail (gtk_widget_get_parent (GTK_WIDGET (item)) == GTK_WIDGET (toolbar), -1);
2802 priv = toolbar->priv;
2805 for (list = priv->content; list != NULL; list = list->next)
2807 ToolbarContent *content = list->data;
2810 widget = toolbar_content_get_widget (content);
2812 if (item == GTK_TOOL_ITEM (widget))
2818 return physical_to_logical (toolbar, n);
2822 * gtk_toolbar_set_style:
2823 * @toolbar: a #GtkToolbar.
2824 * @style: the new style for @toolbar.
2826 * Alters the view of @toolbar to display either icons only, text only, or both.
2829 gtk_toolbar_set_style (GtkToolbar *toolbar,
2830 GtkToolbarStyle style)
2832 GtkToolbarPrivate *priv;
2834 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2836 priv = toolbar->priv;
2838 priv->style_set = TRUE;
2839 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2843 * gtk_toolbar_get_style:
2844 * @toolbar: a #GtkToolbar
2846 * Retrieves whether the toolbar has text, icons, or both . See
2847 * gtk_toolbar_set_style().
2849 * Return value: the current style of @toolbar
2852 gtk_toolbar_get_style (GtkToolbar *toolbar)
2854 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_TOOLBAR_STYLE);
2856 return toolbar->priv->style;
2860 * gtk_toolbar_unset_style:
2861 * @toolbar: a #GtkToolbar
2863 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that
2864 * user preferences will be used to determine the toolbar style.
2867 gtk_toolbar_unset_style (GtkToolbar *toolbar)
2869 GtkToolbarPrivate *priv;
2870 GtkToolbarStyle style;
2872 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2874 priv = toolbar->priv;
2876 if (priv->style_set)
2878 GtkSettings *settings = toolbar_get_settings (toolbar);
2881 g_object_get (settings,
2882 "gtk-toolbar-style", &style,
2885 style = DEFAULT_TOOLBAR_STYLE;
2887 if (style != priv->style)
2888 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2890 priv->style_set = FALSE;
2895 * gtk_toolbar_get_n_items:
2896 * @toolbar: a #GtkToolbar
2898 * Returns the number of items on the toolbar.
2900 * Return value: the number of items on the toolbar
2905 gtk_toolbar_get_n_items (GtkToolbar *toolbar)
2907 GtkToolbarPrivate *priv;
2909 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2911 priv = toolbar->priv;
2913 return physical_to_logical (toolbar, g_list_length (priv->content));
2917 * gtk_toolbar_get_nth_item:
2918 * @toolbar: a #GtkToolbar
2919 * @n: A position on the toolbar
2921 * Returns the @n<!-- -->'th item on @toolbar, or %NULL if the
2922 * toolbar does not contain an @n<!-- -->'th item.
2924 * Return value: (transfer none): The @n<!-- -->'th #GtkToolItem on @toolbar,
2925 * or %NULL if there isn't an @n<!-- -->'th item.
2930 gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
2933 GtkToolbarPrivate *priv;
2934 ToolbarContent *content;
2937 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
2939 priv = toolbar->priv;
2941 n_items = gtk_toolbar_get_n_items (toolbar);
2943 if (n < 0 || n >= n_items)
2946 content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
2949 g_assert (!toolbar_content_is_placeholder (content));
2951 return GTK_TOOL_ITEM (toolbar_content_get_widget (content));
2955 * gtk_toolbar_get_icon_size:
2956 * @toolbar: a #GtkToolbar
2958 * Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size().
2960 * Return value: (type int): the current icon size for the icons on
2964 gtk_toolbar_get_icon_size (GtkToolbar *toolbar)
2966 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_ICON_SIZE);
2968 return toolbar->priv->icon_size;
2972 * gtk_toolbar_get_relief_style:
2973 * @toolbar: a #GtkToolbar
2975 * Returns the relief style of buttons on @toolbar. See
2976 * gtk_button_set_relief().
2978 * Return value: The relief style of buttons on @toolbar.
2983 gtk_toolbar_get_relief_style (GtkToolbar *toolbar)
2985 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_RELIEF_NONE);
2987 return get_button_relief (toolbar);
2991 * gtk_toolbar_set_show_arrow:
2992 * @toolbar: a #GtkToolbar
2993 * @show_arrow: Whether to show an overflow menu
2995 * Sets whether to show an overflow menu when
2996 * @toolbar doesn't have room for all items on it. If %TRUE,
2997 * items that there are not room are available through an
3003 gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
3004 gboolean show_arrow)
3006 GtkToolbarPrivate *priv;
3008 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3010 priv = toolbar->priv;
3012 show_arrow = show_arrow != FALSE;
3014 if (priv->show_arrow != show_arrow)
3016 priv->show_arrow = show_arrow;
3018 if (!priv->show_arrow)
3019 gtk_widget_hide (priv->arrow_button);
3021 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3022 g_object_notify (G_OBJECT (toolbar), "show-arrow");
3027 * gtk_toolbar_get_show_arrow:
3028 * @toolbar: a #GtkToolbar
3030 * Returns whether the toolbar has an overflow menu.
3031 * See gtk_toolbar_set_show_arrow().
3033 * Return value: %TRUE if the toolbar has an overflow menu.
3038 gtk_toolbar_get_show_arrow (GtkToolbar *toolbar)
3040 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
3042 return toolbar->priv->show_arrow;
3046 * gtk_toolbar_get_drop_index:
3047 * @toolbar: a #GtkToolbar
3048 * @x: x coordinate of a point on the toolbar
3049 * @y: y coordinate of a point on the toolbar
3051 * Returns the position corresponding to the indicated point on
3052 * @toolbar. This is useful when dragging items to the toolbar:
3053 * this function returns the position a new item should be
3056 * @x and @y are in @toolbar coordinates.
3058 * Return value: The position corresponding to the point (@x, @y) on the toolbar.
3063 gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
3067 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
3069 return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
3073 gtk_toolbar_finalize (GObject *object)
3076 GtkToolbar *toolbar = GTK_TOOLBAR (object);
3077 GtkToolbarPrivate *priv = toolbar->priv;
3079 if (priv->arrow_button)
3080 gtk_widget_unparent (priv->arrow_button);
3082 for (list = priv->content; list != NULL; list = list->next)
3084 ToolbarContent *content = list->data;
3086 toolbar_content_free (content);
3089 g_list_free (priv->content);
3090 g_list_free (priv->children);
3092 g_timer_destroy (priv->timer);
3095 gtk_widget_destroy (GTK_WIDGET (priv->menu));
3098 g_source_remove (priv->idle_id);
3100 G_OBJECT_CLASS (gtk_toolbar_parent_class)->finalize (object);
3104 * gtk_toolbar_set_icon_size:
3105 * @toolbar: A #GtkToolbar
3106 * @icon_size: (type int): The #GtkIconSize that stock icons in the
3107 * toolbar shall have.
3109 * This function sets the size of stock icons in the toolbar. You
3110 * can call it both before you add the icons and after they've been
3111 * added. The size you set will override user preferences for the default
3114 * This should only be used for special-purpose toolbars, normal
3115 * application toolbars should respect the user preferences for the
3119 gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
3120 GtkIconSize icon_size)
3122 GtkToolbarPrivate *priv;
3124 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3125 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
3127 priv = toolbar->priv;
3129 if (!priv->icon_size_set)
3131 priv->icon_size_set = TRUE;
3132 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3135 if (priv->icon_size == icon_size)
3138 priv->icon_size = icon_size;
3139 g_object_notify (G_OBJECT (toolbar), "icon-size");
3141 gtk_toolbar_reconfigured (toolbar);
3143 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3147 * gtk_toolbar_unset_icon_size:
3148 * @toolbar: a #GtkToolbar
3150 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that
3151 * user preferences will be used to determine the icon size.
3154 gtk_toolbar_unset_icon_size (GtkToolbar *toolbar)
3156 GtkToolbarPrivate *priv;
3159 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3161 priv = toolbar->priv;
3163 if (priv->icon_size_set)
3165 GtkSettings *settings = toolbar_get_settings (toolbar);
3169 g_object_get (settings,
3170 "gtk-toolbar-icon-size", &size,
3174 size = DEFAULT_ICON_SIZE;
3176 if (size != priv->icon_size)
3178 gtk_toolbar_set_icon_size (toolbar, size);
3179 g_object_notify (G_OBJECT (toolbar), "icon-size");
3182 priv->icon_size_set = FALSE;
3183 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3188 * ToolbarContent methods
3196 struct _ToolbarContent
3201 GtkAllocation start_allocation;
3202 GtkAllocation goal_allocation;
3203 guint is_placeholder : 1;
3204 guint disappearing : 1;
3208 static ToolbarContent *
3209 toolbar_content_new_tool_item (GtkToolbar *toolbar,
3211 gboolean is_placeholder,
3214 GtkToolbarPrivate *priv = toolbar->priv;
3215 ToolbarContent *content;
3217 content = g_slice_new0 (ToolbarContent);
3219 content->state = NOT_ALLOCATED;
3220 content->item = item;
3221 content->is_placeholder = is_placeholder;
3223 gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
3225 priv->content = g_list_insert (priv->content, content, pos);
3227 if (!is_placeholder)
3229 priv->num_children++;
3231 gtk_toolbar_stop_sliding (toolbar);
3234 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3235 priv->need_rebuild = TRUE;
3241 toolbar_content_remove (ToolbarContent *content,
3242 GtkToolbar *toolbar)
3244 GtkToolbarPrivate *priv = toolbar->priv;
3246 gtk_widget_unparent (GTK_WIDGET (content->item));
3248 priv->content = g_list_remove (priv->content, content);
3250 if (!toolbar_content_is_placeholder (content))
3251 priv->num_children--;
3253 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3254 priv->need_rebuild = TRUE;
3258 toolbar_content_free (ToolbarContent *content)
3260 g_slice_free (ToolbarContent, content);
3264 calculate_max_homogeneous_pixels (GtkWidget *widget)
3266 PangoContext *context;
3267 PangoFontMetrics *metrics;
3270 context = gtk_widget_get_pango_context (widget);
3271 metrics = pango_context_get_metrics (context,
3272 gtk_widget_get_style (widget)->font_desc,
3273 pango_context_get_language (context));
3274 char_width = pango_font_metrics_get_approximate_char_width (metrics);
3275 pango_font_metrics_unref (metrics);
3277 return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
3281 toolbar_content_draw (ToolbarContent *content,
3282 GtkContainer *container,
3287 if (content->is_placeholder)
3290 widget = GTK_WIDGET (content->item);
3293 gtk_container_propagate_draw (container, widget, cr);
3297 toolbar_content_visible (ToolbarContent *content,
3298 GtkToolbar *toolbar)
3300 GtkToolbarPrivate *priv = toolbar->priv;
3303 item = content->item;
3305 if (!gtk_widget_get_visible (GTK_WIDGET (item)))
3308 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
3309 gtk_tool_item_get_visible_horizontal (item))
3312 if (priv->orientation == GTK_ORIENTATION_VERTICAL &&
3313 gtk_tool_item_get_visible_vertical (item))
3320 toolbar_content_size_request (ToolbarContent *content,
3321 GtkToolbar *toolbar,
3322 GtkRequisition *requisition)
3324 gtk_widget_get_preferred_size (GTK_WIDGET (content->item),
3326 if (content->is_placeholder &&
3327 content->disappearing)
3329 requisition->width = 0;
3330 requisition->height = 0;
3335 toolbar_content_is_homogeneous (ToolbarContent *content,
3336 GtkToolbar *toolbar)
3338 GtkToolbarPrivate *priv = toolbar->priv;
3339 GtkRequisition requisition;
3342 if (priv->max_homogeneous_pixels < 0)
3344 priv->max_homogeneous_pixels =
3345 calculate_max_homogeneous_pixels (GTK_WIDGET (toolbar));
3348 toolbar_content_size_request (content, toolbar, &requisition);
3350 if (requisition.width > priv->max_homogeneous_pixels)
3353 result = gtk_tool_item_get_homogeneous (content->item) &&
3354 !GTK_IS_SEPARATOR_TOOL_ITEM (content->item);
3356 if (gtk_tool_item_get_is_important (content->item) &&
3357 priv->style == GTK_TOOLBAR_BOTH_HORIZ &&
3358 priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3367 toolbar_content_is_placeholder (ToolbarContent *content)
3369 if (content->is_placeholder)
3376 toolbar_content_disappearing (ToolbarContent *content)
3378 if (content->disappearing)
3385 toolbar_content_get_state (ToolbarContent *content)
3387 return content->state;
3391 toolbar_content_child_visible (ToolbarContent *content)
3393 return GTK_WIDGET_CHILD_VISIBLE (content->item);
3397 toolbar_content_get_goal_allocation (ToolbarContent *content,
3398 GtkAllocation *allocation)
3400 *allocation = content->goal_allocation;
3404 toolbar_content_get_allocation (ToolbarContent *content,
3405 GtkAllocation *allocation)
3407 gtk_widget_get_allocation (GTK_WIDGET (content->item), allocation);
3411 toolbar_content_set_start_allocation (ToolbarContent *content,
3412 GtkAllocation *allocation)
3414 content->start_allocation = *allocation;
3418 toolbar_content_get_expand (ToolbarContent *content)
3420 if (!content->disappearing &&
3421 gtk_tool_item_get_expand (content->item))
3428 toolbar_content_set_goal_allocation (ToolbarContent *content,
3429 GtkAllocation *allocation)
3431 content->goal_allocation = *allocation;
3435 toolbar_content_set_child_visible (ToolbarContent *content,
3436 GtkToolbar *toolbar,
3439 gtk_widget_set_child_visible (GTK_WIDGET (content->item),
3444 toolbar_content_get_start_allocation (ToolbarContent *content,
3445 GtkAllocation *start_allocation)
3447 *start_allocation = content->start_allocation;
3451 toolbar_content_size_allocate (ToolbarContent *content,
3452 GtkAllocation *allocation)
3454 gtk_widget_size_allocate (GTK_WIDGET (content->item),
3459 toolbar_content_set_state (ToolbarContent *content,
3462 content->state = state;
3466 toolbar_content_get_widget (ToolbarContent *content)
3468 return GTK_WIDGET (content->item);
3473 toolbar_content_set_disappearing (ToolbarContent *content,
3474 gboolean disappearing)
3476 content->disappearing = disappearing;
3480 toolbar_content_set_size_request (ToolbarContent *content,
3484 gtk_widget_set_size_request (GTK_WIDGET (content->item),
3489 toolbar_content_toolbar_reconfigured (ToolbarContent *content,
3490 GtkToolbar *toolbar)
3492 gtk_tool_item_toolbar_reconfigured (content->item);
3496 toolbar_content_retrieve_menu_item (ToolbarContent *content)
3498 return gtk_tool_item_retrieve_proxy_menu_item (content->item);
3502 toolbar_content_has_proxy_menu_item (ToolbarContent *content)
3504 GtkWidget *menu_item;
3506 if (content->has_menu == YES)
3508 else if (content->has_menu == NO)
3511 menu_item = toolbar_content_retrieve_menu_item (content);
3513 content->has_menu = menu_item? YES : NO;
3515 return menu_item != NULL;
3519 toolbar_content_set_unknown_menu_status (ToolbarContent *content)
3521 content->has_menu = UNKNOWN;
3525 toolbar_content_is_separator (ToolbarContent *content)
3527 return GTK_IS_SEPARATOR_TOOL_ITEM (content->item);
3531 toolbar_content_set_expand (ToolbarContent *content,
3534 gtk_tool_item_set_expand (content->item, expand);
3538 toolbar_content_show_all (ToolbarContent *content)
3542 widget = toolbar_content_get_widget (content);
3544 gtk_widget_show_all (widget);
3548 toolbar_content_hide_all (ToolbarContent *content)
3552 widget = toolbar_content_get_widget (content);
3554 gtk_widget_hide_all (widget);
3560 static GtkReliefStyle
3561 get_button_relief (GtkToolbar *toolbar)
3563 GtkReliefStyle button_relief = GTK_RELIEF_NORMAL;
3565 gtk_widget_ensure_style (GTK_WIDGET (toolbar));
3567 gtk_widget_style_get (GTK_WIDGET (toolbar),
3568 "button-relief", &button_relief,
3571 return button_relief;
3575 get_internal_padding (GtkToolbar *toolbar)
3579 gtk_widget_style_get (GTK_WIDGET (toolbar),
3580 "internal-padding", &ipadding,
3587 get_max_child_expand (GtkToolbar *toolbar)
3589 gint mexpand = G_MAXINT;
3591 gtk_widget_style_get (GTK_WIDGET (toolbar),
3592 "max-child-expand", &mexpand,
3597 static GtkShadowType
3598 get_shadow_type (GtkToolbar *toolbar)
3600 GtkShadowType shadow_type;
3602 gtk_widget_style_get (GTK_WIDGET (toolbar),
3603 "shadow-type", &shadow_type,
3609 /* GTK+ internal methods */
3612 _gtk_toolbar_get_default_space_size (void)
3614 return DEFAULT_SPACE_SIZE;
3618 _gtk_toolbar_paint_space_line (GtkWidget *widget,
3619 GtkToolbar *toolbar,
3622 GtkToolbarPrivate *priv = toolbar->priv;
3623 GtkOrientation orientation;
3628 const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
3629 const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
3631 g_return_if_fail (GTK_IS_WIDGET (widget));
3633 orientation = toolbar? priv->orientation : GTK_ORIENTATION_HORIZONTAL;
3635 style = gtk_widget_get_style (widget);
3636 window = gtk_widget_get_window (widget);
3637 state = gtk_widget_get_state (widget);
3638 width = gtk_widget_get_allocated_width (widget);
3639 height = gtk_widget_get_allocated_height (widget);
3641 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3643 gboolean wide_separators;
3644 gint separator_width;
3646 gtk_widget_style_get (widget,
3647 "wide-separators", &wide_separators,
3648 "separator-width", &separator_width,
3651 if (wide_separators)
3652 gtk_paint_box (style, cr,
3653 state, GTK_SHADOW_ETCHED_OUT,
3654 widget, "vseparator",
3655 (width - separator_width) / 2,
3656 height * start_fraction,
3658 height * (end_fraction - start_fraction));
3660 gtk_paint_vline (style, cr,
3663 height * start_fraction,
3664 height * end_fraction,
3665 (width - style->xthickness) / 2);
3669 gboolean wide_separators;
3670 gint separator_height;
3672 gtk_widget_style_get (widget,
3673 "wide-separators", &wide_separators,
3674 "separator-height", &separator_height,
3677 if (wide_separators)
3678 gtk_paint_box (style, cr,
3679 state, GTK_SHADOW_ETCHED_OUT,
3680 widget, "hseparator",
3681 width * start_fraction,
3682 (height - separator_height) / 2,
3683 width * (end_fraction - start_fraction),
3686 gtk_paint_hline (style, cr,
3689 width * start_fraction,
3690 width * end_fraction,
3691 (height - style->ythickness) / 2);
3696 _gtk_toolbar_elide_underscores (const gchar *original)
3699 const gchar *p, *end;
3701 gboolean last_underscore;
3706 len = strlen (original);
3707 q = result = g_malloc (len + 1);
3708 last_underscore = FALSE;
3710 end = original + len;
3711 for (p = original; p < end; p++)
3713 if (!last_underscore && *p == '_')
3714 last_underscore = TRUE;
3717 last_underscore = FALSE;
3718 if (original + 2 <= p && p + 1 <= end &&
3719 p[-2] == '(' && p[-1] == '_' && p[0] != '_' && p[1] == ')')
3730 if (last_underscore)
3739 toolbar_get_icon_size (GtkToolShell *shell)
3741 GtkToolbar *toolbar = GTK_TOOLBAR (shell);
3742 GtkToolbarPrivate *priv = toolbar->priv;
3744 return priv->icon_size;
3747 static GtkOrientation
3748 toolbar_get_orientation (GtkToolShell *shell)
3750 GtkToolbar *toolbar = GTK_TOOLBAR (shell);
3751 GtkToolbarPrivate *priv = toolbar->priv;
3753 return priv->orientation;
3756 static GtkToolbarStyle
3757 toolbar_get_style (GtkToolShell *shell)
3759 GtkToolbar *toolbar = GTK_TOOLBAR (shell);
3760 GtkToolbarPrivate *priv = toolbar->priv;
3765 static GtkReliefStyle
3766 toolbar_get_relief_style (GtkToolShell *shell)
3768 return get_button_relief (GTK_TOOLBAR (shell));
3772 toolbar_rebuild_menu (GtkToolShell *shell)
3774 GtkToolbar *toolbar = GTK_TOOLBAR (shell);
3775 GtkToolbarPrivate *priv = toolbar->priv;
3778 priv->need_rebuild = TRUE;
3780 for (list = priv->content; list != NULL; list = list->next)
3782 ToolbarContent *content = list->data;
3784 toolbar_content_set_unknown_menu_status (content);
3787 gtk_widget_queue_resize (GTK_WIDGET (shell));