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 <gdk/gdkkeysyms.h>
41 #include "gtkbindings.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 "gtktoolbar.h"
55 #include "gtktoolshell.h"
57 #include "gtkprivate.h"
61 typedef struct _ToolbarContent ToolbarContent;
63 #define DEFAULT_IPADDING 0
65 #define DEFAULT_SPACE_SIZE 12
66 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
67 #define SPACE_LINE_DIVISION 10.0
68 #define SPACE_LINE_START 2.0
69 #define SPACE_LINE_END 8.0
71 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
72 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
73 #define DEFAULT_ANIMATION_STATE TRUE
75 #define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
76 * in the homogeneous game. In units of
77 * pango_font_get_estimated_char_width().
79 #define SLIDE_SPEED 600.0 /* How fast the items slide, in pixels per second */
80 #define ACCEL_THRESHOLD 0.18 /* After how much time in seconds will items start speeding up */
94 /* Child properties */
98 CHILD_PROP_HOMOGENEOUS
117 struct _GtkToolbarPrivate
122 GtkWidget * arrow_button;
125 GdkWindow * event_window;
126 GtkSettings * settings;
128 GtkToolItem * highlight_tool_item;
129 gint max_homogeneous_pixels;
133 gulong settings_connection;
135 guint show_arrow : 1;
137 guint is_sliding : 1;
138 guint need_rebuild : 1; /* whether the overflow menu should be regenerated */
142 static void gtk_toolbar_set_property (GObject *object,
146 static void gtk_toolbar_get_property (GObject *object,
150 static gint gtk_toolbar_expose (GtkWidget *widget,
151 GdkEventExpose *event);
152 static void gtk_toolbar_realize (GtkWidget *widget);
153 static void gtk_toolbar_unrealize (GtkWidget *widget);
154 static void gtk_toolbar_size_request (GtkWidget *widget,
155 GtkRequisition *requisition);
156 static void gtk_toolbar_size_allocate (GtkWidget *widget,
157 GtkAllocation *allocation);
158 static void gtk_toolbar_style_set (GtkWidget *widget,
159 GtkStyle *prev_style);
160 static gboolean gtk_toolbar_focus (GtkWidget *widget,
161 GtkDirectionType dir);
162 static void gtk_toolbar_move_focus (GtkWidget *widget,
163 GtkDirectionType dir);
164 static void gtk_toolbar_screen_changed (GtkWidget *widget,
165 GdkScreen *previous_screen);
166 static void gtk_toolbar_map (GtkWidget *widget);
167 static void gtk_toolbar_unmap (GtkWidget *widget);
168 static void gtk_toolbar_set_child_property (GtkContainer *container,
173 static void gtk_toolbar_get_child_property (GtkContainer *container,
178 static void gtk_toolbar_finalize (GObject *object);
179 static void gtk_toolbar_show_all (GtkWidget *widget);
180 static void gtk_toolbar_hide_all (GtkWidget *widget);
181 static void gtk_toolbar_add (GtkContainer *container,
183 static void gtk_toolbar_remove (GtkContainer *container,
185 static void gtk_toolbar_forall (GtkContainer *container,
186 gboolean include_internals,
187 GtkCallback callback,
188 gpointer callback_data);
189 static GType gtk_toolbar_child_type (GtkContainer *container);
190 static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
191 GtkOrientation orientation);
192 static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
193 GtkToolbarStyle style);
194 static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
195 gboolean focus_home);
196 static gboolean gtk_toolbar_button_press (GtkWidget *toolbar,
197 GdkEventButton *event);
198 static gboolean gtk_toolbar_arrow_button_press (GtkWidget *button,
199 GdkEventButton *event,
200 GtkToolbar *toolbar);
201 static void gtk_toolbar_arrow_button_clicked (GtkWidget *button,
202 GtkToolbar *toolbar);
203 static void gtk_toolbar_update_button_relief (GtkToolbar *toolbar);
204 static gboolean gtk_toolbar_popup_menu (GtkWidget *toolbar);
205 static void gtk_toolbar_reconfigured (GtkToolbar *toolbar);
207 static GtkReliefStyle get_button_relief (GtkToolbar *toolbar);
208 static gint get_internal_padding (GtkToolbar *toolbar);
209 static gint get_max_child_expand (GtkToolbar *toolbar);
210 static GtkShadowType get_shadow_type (GtkToolbar *toolbar);
212 /* methods on ToolbarContent 'class' */
213 static ToolbarContent *toolbar_content_new_tool_item (GtkToolbar *toolbar,
215 gboolean is_placeholder,
217 static void toolbar_content_remove (ToolbarContent *content,
218 GtkToolbar *toolbar);
219 static void toolbar_content_free (ToolbarContent *content);
220 static void toolbar_content_expose (ToolbarContent *content,
221 GtkContainer *container,
222 GdkEventExpose *expose);
223 static gboolean toolbar_content_visible (ToolbarContent *content,
224 GtkToolbar *toolbar);
225 static void toolbar_content_size_request (ToolbarContent *content,
227 GtkRequisition *requisition);
228 static gboolean toolbar_content_is_homogeneous (ToolbarContent *content,
229 GtkToolbar *toolbar);
230 static gboolean toolbar_content_is_placeholder (ToolbarContent *content);
231 static gboolean toolbar_content_disappearing (ToolbarContent *content);
232 static ItemState toolbar_content_get_state (ToolbarContent *content);
233 static gboolean toolbar_content_child_visible (ToolbarContent *content);
234 static void toolbar_content_get_goal_allocation (ToolbarContent *content,
235 GtkAllocation *allocation);
236 static void toolbar_content_get_allocation (ToolbarContent *content,
237 GtkAllocation *allocation);
238 static void toolbar_content_set_start_allocation (ToolbarContent *content,
239 GtkAllocation *new_start_allocation);
240 static void toolbar_content_get_start_allocation (ToolbarContent *content,
241 GtkAllocation *start_allocation);
242 static gboolean toolbar_content_get_expand (ToolbarContent *content);
243 static void toolbar_content_set_goal_allocation (ToolbarContent *content,
244 GtkAllocation *allocation);
245 static void toolbar_content_set_child_visible (ToolbarContent *content,
248 static void toolbar_content_size_allocate (ToolbarContent *content,
249 GtkAllocation *allocation);
250 static void toolbar_content_set_state (ToolbarContent *content,
251 ItemState new_state);
252 static GtkWidget * toolbar_content_get_widget (ToolbarContent *content);
253 static void toolbar_content_set_disappearing (ToolbarContent *content,
254 gboolean disappearing);
255 static void toolbar_content_set_size_request (ToolbarContent *content,
258 static void toolbar_content_toolbar_reconfigured (ToolbarContent *content,
259 GtkToolbar *toolbar);
260 static GtkWidget * toolbar_content_retrieve_menu_item (ToolbarContent *content);
261 static gboolean toolbar_content_has_proxy_menu_item (ToolbarContent *content);
262 static gboolean toolbar_content_is_separator (ToolbarContent *content);
263 static void toolbar_content_show_all (ToolbarContent *content);
264 static void toolbar_content_hide_all (ToolbarContent *content);
265 static void toolbar_content_set_expand (ToolbarContent *content,
268 static void toolbar_tool_shell_iface_init (GtkToolShellIface *iface);
269 static GtkIconSize toolbar_get_icon_size (GtkToolShell *shell);
270 static GtkOrientation toolbar_get_orientation (GtkToolShell *shell);
271 static GtkToolbarStyle toolbar_get_style (GtkToolShell *shell);
272 static GtkReliefStyle toolbar_get_relief_style (GtkToolShell *shell);
273 static void toolbar_rebuild_menu (GtkToolShell *shell);
275 #define GTK_TOOLBAR_GET_PRIVATE(o) \
276 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOLBAR, GtkToolbarPrivate))
279 G_DEFINE_TYPE_WITH_CODE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER,
280 G_IMPLEMENT_INTERFACE (GTK_TYPE_TOOL_SHELL,
281 toolbar_tool_shell_iface_init)
282 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
285 static guint toolbar_signals[LAST_SIGNAL] = { 0 };
289 add_arrow_bindings (GtkBindingSet *binding_set,
291 GtkDirectionType dir)
293 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
295 gtk_binding_entry_add_signal (binding_set, keysym, 0,
297 GTK_TYPE_DIRECTION_TYPE, dir);
298 gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
300 GTK_TYPE_DIRECTION_TYPE, dir);
304 add_ctrl_tab_bindings (GtkBindingSet *binding_set,
305 GdkModifierType modifiers,
306 GtkDirectionType direction)
308 gtk_binding_entry_add_signal (binding_set,
309 GDK_Tab, GDK_CONTROL_MASK | modifiers,
311 GTK_TYPE_DIRECTION_TYPE, direction);
312 gtk_binding_entry_add_signal (binding_set,
313 GDK_KP_Tab, GDK_CONTROL_MASK | modifiers,
315 GTK_TYPE_DIRECTION_TYPE, direction);
319 gtk_toolbar_class_init (GtkToolbarClass *klass)
321 GObjectClass *gobject_class;
322 GtkWidgetClass *widget_class;
323 GtkContainerClass *container_class;
324 GtkBindingSet *binding_set;
326 gobject_class = (GObjectClass *)klass;
327 widget_class = (GtkWidgetClass *)klass;
328 container_class = (GtkContainerClass *)klass;
330 gobject_class->set_property = gtk_toolbar_set_property;
331 gobject_class->get_property = gtk_toolbar_get_property;
332 gobject_class->finalize = gtk_toolbar_finalize;
334 widget_class->button_press_event = gtk_toolbar_button_press;
335 widget_class->expose_event = gtk_toolbar_expose;
336 widget_class->size_request = gtk_toolbar_size_request;
337 widget_class->size_allocate = gtk_toolbar_size_allocate;
338 widget_class->style_set = gtk_toolbar_style_set;
339 widget_class->focus = gtk_toolbar_focus;
341 /* need to override the base class function via override_class_handler,
342 * because the signal slot is not available in GtkWidgetClass
344 g_signal_override_class_handler ("move-focus",
346 G_CALLBACK (gtk_toolbar_move_focus));
348 widget_class->screen_changed = gtk_toolbar_screen_changed;
349 widget_class->realize = gtk_toolbar_realize;
350 widget_class->unrealize = gtk_toolbar_unrealize;
351 widget_class->map = gtk_toolbar_map;
352 widget_class->unmap = gtk_toolbar_unmap;
353 widget_class->popup_menu = gtk_toolbar_popup_menu;
354 widget_class->show_all = gtk_toolbar_show_all;
355 widget_class->hide_all = gtk_toolbar_hide_all;
357 container_class->add = gtk_toolbar_add;
358 container_class->remove = gtk_toolbar_remove;
359 container_class->forall = gtk_toolbar_forall;
360 container_class->child_type = gtk_toolbar_child_type;
361 container_class->get_child_property = gtk_toolbar_get_child_property;
362 container_class->set_child_property = gtk_toolbar_set_child_property;
364 klass->orientation_changed = gtk_toolbar_orientation_changed;
365 klass->style_changed = gtk_toolbar_real_style_changed;
368 * GtkToolbar::orientation-changed:
369 * @toolbar: the object which emitted the signal
370 * @orientation: the new #GtkOrientation of the toolbar
372 * Emitted when the orientation of the toolbar changes.
374 toolbar_signals[ORIENTATION_CHANGED] =
375 g_signal_new (I_("orientation-changed"),
376 G_OBJECT_CLASS_TYPE (klass),
378 G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
380 g_cclosure_marshal_VOID__ENUM,
382 GTK_TYPE_ORIENTATION);
384 * GtkToolbar::style-changed:
385 * @toolbar: The #GtkToolbar which emitted the signal
386 * @style: the new #GtkToolbarStyle of the toolbar
388 * Emitted when the style of the toolbar changes.
390 toolbar_signals[STYLE_CHANGED] =
391 g_signal_new (I_("style-changed"),
392 G_OBJECT_CLASS_TYPE (klass),
394 G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
396 g_cclosure_marshal_VOID__ENUM,
398 GTK_TYPE_TOOLBAR_STYLE);
400 * GtkToolbar::popup-context-menu:
401 * @toolbar: the #GtkToolbar which emitted the signal
402 * @x: the x coordinate of the point where the menu should appear
403 * @y: the y coordinate of the point where the menu should appear
404 * @button: the mouse button the user pressed, or -1
406 * Emitted when the user right-clicks the toolbar or uses the
407 * keybinding to display a popup menu.
409 * Application developers should handle this signal if they want
410 * to display a context menu on the toolbar. The context-menu should
411 * appear at the coordinates given by @x and @y. The mouse button
412 * number is given by the @button parameter. If the menu was popped
413 * up using the keybaord, @button is -1.
415 * Return value: return %TRUE if the signal was handled, %FALSE if not
417 toolbar_signals[POPUP_CONTEXT_MENU] =
418 g_signal_new (I_("popup-context-menu"),
419 G_OBJECT_CLASS_TYPE (klass),
421 G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
422 _gtk_boolean_handled_accumulator, NULL,
423 _gtk_marshal_BOOLEAN__INT_INT_INT,
425 G_TYPE_INT, G_TYPE_INT,
429 * GtkToolbar::focus-home-or-end:
430 * @toolbar: the #GtkToolbar which emitted the signal
431 * @focus_home: %TRUE if the first item should be focused
433 * A keybinding signal used internally by GTK+. This signal can't
434 * be used in application code
436 * Return value: %TRUE if the signal was handled, %FALSE if not
438 toolbar_signals[FOCUS_HOME_OR_END] =
439 g_signal_new_class_handler (I_("focus-home-or-end"),
440 G_OBJECT_CLASS_TYPE (klass),
441 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
442 G_CALLBACK (gtk_toolbar_focus_home_or_end),
444 _gtk_marshal_BOOLEAN__BOOLEAN,
449 g_object_class_override_property (gobject_class,
453 g_object_class_install_property (gobject_class,
455 g_param_spec_enum ("toolbar-style",
457 P_("How to draw the toolbar"),
458 GTK_TYPE_TOOLBAR_STYLE,
459 DEFAULT_TOOLBAR_STYLE,
460 GTK_PARAM_READWRITE));
461 g_object_class_install_property (gobject_class,
463 g_param_spec_boolean ("show-arrow",
465 P_("If an arrow should be shown if the toolbar doesn't fit"),
467 GTK_PARAM_READWRITE));
470 * GtkToolbar:icon-size:
472 * The size of the icons in a toolbar is normally determined by
473 * the toolbar-icon-size setting. When this property is set, it
474 * overrides the setting.
476 * This should only be used for special-purpose toolbars, normal
477 * application toolbars should respect the user preferences for the
482 g_object_class_install_property (gobject_class,
484 g_param_spec_int ("icon-size",
486 P_("Size of icons in this toolbar"),
489 GTK_PARAM_READWRITE));
492 * GtkToolbar:icon-size-set:
494 * Is %TRUE if the icon-size property has been set.
498 g_object_class_install_property (gobject_class,
500 g_param_spec_boolean ("icon-size-set",
502 P_("Whether the icon-size property has been set"),
504 GTK_PARAM_READWRITE));
506 /* child properties */
507 gtk_container_class_install_child_property (container_class,
509 g_param_spec_boolean ("expand",
511 P_("Whether the item should receive extra space when the toolbar grows"),
513 GTK_PARAM_READWRITE));
515 gtk_container_class_install_child_property (container_class,
516 CHILD_PROP_HOMOGENEOUS,
517 g_param_spec_boolean ("homogeneous",
519 P_("Whether the item should be the same size as other homogeneous items"),
521 GTK_PARAM_READWRITE));
523 /* style properties */
524 gtk_widget_class_install_style_property (widget_class,
525 g_param_spec_int ("space-size",
527 P_("Size of spacers"),
531 GTK_PARAM_READABLE));
533 gtk_widget_class_install_style_property (widget_class,
534 g_param_spec_int ("internal-padding",
535 P_("Internal padding"),
536 P_("Amount of border space between the toolbar shadow and the buttons"),
540 GTK_PARAM_READABLE));
542 gtk_widget_class_install_style_property (widget_class,
543 g_param_spec_int ("max-child-expand",
544 P_("Maximum child expand"),
545 P_("Maximum amount of space an expandable item will be given"),
549 GTK_PARAM_READABLE));
551 gtk_widget_class_install_style_property (widget_class,
552 g_param_spec_enum ("space-style",
554 P_("Whether spacers are vertical lines or just blank"),
555 GTK_TYPE_TOOLBAR_SPACE_STYLE,
557 GTK_PARAM_READABLE));
559 gtk_widget_class_install_style_property (widget_class,
560 g_param_spec_enum ("button-relief",
562 P_("Type of bevel around toolbar buttons"),
563 GTK_TYPE_RELIEF_STYLE,
565 GTK_PARAM_READABLE));
566 gtk_widget_class_install_style_property (widget_class,
567 g_param_spec_enum ("shadow-type",
569 P_("Style of bevel around the toolbar"),
570 GTK_TYPE_SHADOW_TYPE,
572 GTK_PARAM_READABLE));
574 binding_set = gtk_binding_set_by_class (klass);
576 add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
577 add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
578 add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
579 add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
581 gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, 0,
582 "focus-home-or-end", 1,
583 G_TYPE_BOOLEAN, TRUE);
584 gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
585 "focus-home-or-end", 1,
586 G_TYPE_BOOLEAN, TRUE);
587 gtk_binding_entry_add_signal (binding_set, GDK_KP_End, 0,
588 "focus-home-or-end", 1,
589 G_TYPE_BOOLEAN, FALSE);
590 gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
591 "focus-home-or-end", 1,
592 G_TYPE_BOOLEAN, FALSE);
594 add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
595 add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
597 g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));
601 toolbar_tool_shell_iface_init (GtkToolShellIface *iface)
603 iface->get_icon_size = toolbar_get_icon_size;
604 iface->get_orientation = toolbar_get_orientation;
605 iface->get_style = toolbar_get_style;
606 iface->get_relief_style = toolbar_get_relief_style;
607 iface->rebuild_menu = toolbar_rebuild_menu;
611 gtk_toolbar_init (GtkToolbar *toolbar)
613 GtkToolbarPrivate *priv;
615 gtk_widget_set_can_focus (GTK_WIDGET (toolbar), FALSE);
616 gtk_widget_set_has_window (GTK_WIDGET (toolbar), FALSE);
618 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
620 toolbar->orientation = GTK_ORIENTATION_HORIZONTAL;
621 toolbar->style = DEFAULT_TOOLBAR_STYLE;
622 toolbar->icon_size = DEFAULT_ICON_SIZE;
623 priv->animation = DEFAULT_ANIMATION_STATE;
625 priv->arrow_button = gtk_toggle_button_new ();
626 g_signal_connect (priv->arrow_button, "button-press-event",
627 G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar);
628 g_signal_connect (priv->arrow_button, "clicked",
629 G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar);
630 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
631 get_button_relief (toolbar));
633 gtk_button_set_focus_on_click (GTK_BUTTON (priv->arrow_button), FALSE);
635 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
636 gtk_widget_set_name (priv->arrow, "gtk-toolbar-arrow");
637 gtk_widget_show (priv->arrow);
638 gtk_container_add (GTK_CONTAINER (priv->arrow_button), priv->arrow);
640 gtk_widget_set_parent (priv->arrow_button, GTK_WIDGET (toolbar));
642 /* which child position a drop will occur at */
644 priv->show_arrow = TRUE;
645 priv->settings = NULL;
647 priv->max_homogeneous_pixels = -1;
649 priv->timer = g_timer_new ();
653 gtk_toolbar_set_property (GObject *object,
658 GtkToolbar *toolbar = GTK_TOOLBAR (object);
662 case PROP_ORIENTATION:
663 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0,
664 g_value_get_enum (value));
666 case PROP_TOOLBAR_STYLE:
667 gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
669 case PROP_SHOW_ARROW:
670 gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
673 gtk_toolbar_set_icon_size (toolbar, g_value_get_int (value));
675 case PROP_ICON_SIZE_SET:
676 if (g_value_get_boolean (value))
677 toolbar->icon_size_set = TRUE;
679 gtk_toolbar_unset_icon_size (toolbar);
682 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
688 gtk_toolbar_get_property (GObject *object,
693 GtkToolbar *toolbar = GTK_TOOLBAR (object);
694 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
698 case PROP_ORIENTATION:
699 g_value_set_enum (value, toolbar->orientation);
701 case PROP_TOOLBAR_STYLE:
702 g_value_set_enum (value, toolbar->style);
704 case PROP_SHOW_ARROW:
705 g_value_set_boolean (value, priv->show_arrow);
708 g_value_set_int (value, gtk_toolbar_get_icon_size (toolbar));
710 case PROP_ICON_SIZE_SET:
711 g_value_set_boolean (value, toolbar->icon_size_set);
714 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
720 gtk_toolbar_map (GtkWidget *widget)
722 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
724 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->map (widget);
726 if (priv->event_window)
727 gdk_window_show_unraised (priv->event_window);
731 gtk_toolbar_unmap (GtkWidget *widget)
733 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
735 if (priv->event_window)
736 gdk_window_hide (priv->event_window);
738 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unmap (widget);
742 gtk_toolbar_realize (GtkWidget *widget)
744 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
745 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
747 GdkWindowAttr attributes;
748 gint attributes_mask;
751 gtk_widget_set_realized (widget, TRUE);
753 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
755 attributes.wclass = GDK_INPUT_ONLY;
756 attributes.window_type = GDK_WINDOW_CHILD;
757 attributes.x = widget->allocation.x + border_width;
758 attributes.y = widget->allocation.y + border_width;
759 attributes.width = widget->allocation.width - border_width * 2;
760 attributes.height = widget->allocation.height - border_width * 2;
761 attributes.event_mask = gtk_widget_get_events (widget);
762 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
763 GDK_BUTTON_RELEASE_MASK |
764 GDK_ENTER_NOTIFY_MASK |
765 GDK_LEAVE_NOTIFY_MASK);
767 attributes_mask = GDK_WA_X | GDK_WA_Y;
769 widget->window = gtk_widget_get_parent_window (widget);
770 g_object_ref (widget->window);
771 widget->style = gtk_style_attach (widget->style, widget->window);
773 priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
774 &attributes, attributes_mask);
775 gdk_window_set_user_data (priv->event_window, toolbar);
779 gtk_toolbar_unrealize (GtkWidget *widget)
781 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
783 if (priv->event_window)
785 gdk_window_set_user_data (priv->event_window, NULL);
786 gdk_window_destroy (priv->event_window);
787 priv->event_window = NULL;
790 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize (widget);
794 gtk_toolbar_expose (GtkWidget *widget,
795 GdkEventExpose *event)
797 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
798 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
803 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
805 if (gtk_widget_is_drawable (widget))
807 gtk_paint_box (widget->style,
809 gtk_widget_get_state (widget),
810 get_shadow_type (toolbar),
811 &event->area, widget, "toolbar",
812 border_width + widget->allocation.x,
813 border_width + widget->allocation.y,
814 widget->allocation.width - 2 * border_width,
815 widget->allocation.height - 2 * border_width);
818 for (list = priv->content; list != NULL; list = list->next)
820 ToolbarContent *content = list->data;
822 toolbar_content_expose (content, GTK_CONTAINER (widget), event);
825 gtk_container_propagate_expose (GTK_CONTAINER (widget),
833 gtk_toolbar_size_request (GtkWidget *widget,
834 GtkRequisition *requisition)
836 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
837 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
839 gint max_child_height;
840 gint max_child_width;
841 gint max_homogeneous_child_width;
842 gint max_homogeneous_child_height;
843 gint homogeneous_size;
845 gint pack_front_size;
848 GtkRequisition arrow_requisition;
850 max_homogeneous_child_width = 0;
851 max_homogeneous_child_height = 0;
853 max_child_height = 0;
854 for (list = priv->content; list != NULL; list = list->next)
856 GtkRequisition requisition;
857 ToolbarContent *content = list->data;
859 if (!toolbar_content_visible (content, toolbar))
862 toolbar_content_size_request (content, toolbar, &requisition);
864 max_child_width = MAX (max_child_width, requisition.width);
865 max_child_height = MAX (max_child_height, requisition.height);
867 if (toolbar_content_is_homogeneous (content, toolbar))
869 max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
870 max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
874 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
875 homogeneous_size = max_homogeneous_child_width;
877 homogeneous_size = max_homogeneous_child_height;
880 for (list = priv->content; list != NULL; list = list->next)
882 ToolbarContent *content = list->data;
885 if (!toolbar_content_visible (content, toolbar))
888 if (toolbar_content_is_homogeneous (content, toolbar))
890 size = homogeneous_size;
894 GtkRequisition requisition;
896 toolbar_content_size_request (content, toolbar, &requisition);
898 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
899 size = requisition.width;
901 size = requisition.height;
904 pack_front_size += size;
907 if (priv->show_arrow)
909 gtk_widget_size_request (priv->arrow_button, &arrow_requisition);
911 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
912 long_req = arrow_requisition.width;
914 long_req = arrow_requisition.height;
916 /* There is no point requesting space for the arrow if that would take
917 * up more space than all the items combined
919 long_req = MIN (long_req, pack_front_size);
923 arrow_requisition.height = 0;
924 arrow_requisition.width = 0;
926 long_req = pack_front_size;
929 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
931 requisition->width = long_req;
932 requisition->height = MAX (max_child_height, arrow_requisition.height);
936 requisition->height = long_req;
937 requisition->width = MAX (max_child_width, arrow_requisition.width);
941 ipadding = get_internal_padding (toolbar);
943 border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
944 requisition->width += 2 * (ipadding + border_width);
945 requisition->height += 2 * (ipadding + border_width);
947 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
949 requisition->width += 2 * widget->style->xthickness;
950 requisition->height += 2 * widget->style->ythickness;
953 toolbar->button_maxw = max_homogeneous_child_width;
954 toolbar->button_maxh = max_homogeneous_child_height;
958 position (GtkToolbar *toolbar,
965 if (! GTK_TOOLBAR_GET_PRIVATE (toolbar)->animation)
968 if (elapsed <= ACCEL_THRESHOLD)
970 n_pixels = SLIDE_SPEED * elapsed;
974 /* The formula is a second degree polynomial in
975 * @elapsed that has the line SLIDE_SPEED * @elapsed
976 * as tangent for @elapsed == ACCEL_THRESHOLD.
977 * This makes @n_pixels a smooth function of elapsed time.
979 n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
980 SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
984 return MIN (from + n_pixels, to);
986 return MAX (from - n_pixels, to);
990 compute_intermediate_allocation (GtkToolbar *toolbar,
991 const GtkAllocation *start,
992 const GtkAllocation *goal,
993 GtkAllocation *intermediate)
995 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
996 gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
998 intermediate->x = position (toolbar, start->x, goal->x, elapsed);
999 intermediate->y = position (toolbar, start->y, goal->y, elapsed);
1000 intermediate->width = position (toolbar, start->x + start->width,
1001 goal->x + goal->width,
1002 elapsed) - intermediate->x;
1003 intermediate->height = position (toolbar, start->y + start->height,
1004 goal->y + goal->height,
1005 elapsed) - intermediate->y;
1009 fixup_allocation_for_rtl (gint total_size,
1010 GtkAllocation *allocation)
1012 allocation->x += (total_size - (2 * allocation->x + allocation->width));
1016 fixup_allocation_for_vertical (GtkAllocation *allocation)
1020 tmp = allocation->x;
1021 allocation->x = allocation->y;
1022 allocation->y = tmp;
1024 tmp = allocation->width;
1025 allocation->width = allocation->height;
1026 allocation->height = tmp;
1030 get_item_size (GtkToolbar *toolbar,
1031 ToolbarContent *content)
1033 GtkRequisition requisition;
1035 toolbar_content_size_request (content, toolbar, &requisition);
1037 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1039 if (toolbar_content_is_homogeneous (content, toolbar))
1040 return toolbar->button_maxw;
1042 return requisition.width;
1046 if (toolbar_content_is_homogeneous (content, toolbar))
1047 return toolbar->button_maxh;
1049 return requisition.height;
1054 slide_idle_handler (gpointer data)
1056 GtkToolbar *toolbar = data;
1057 GtkToolbarPrivate *priv;
1060 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1062 if (priv->need_sync)
1065 priv->need_sync = FALSE;
1068 for (list = priv->content; list != NULL; list = list->next)
1070 ToolbarContent *content = list->data;
1072 GtkAllocation goal_allocation;
1073 GtkAllocation allocation;
1076 state = toolbar_content_get_state (content);
1077 toolbar_content_get_goal_allocation (content, &goal_allocation);
1078 toolbar_content_get_allocation (content, &allocation);
1082 if (state == NOT_ALLOCATED)
1084 /* an unallocated item means that size allocate has to
1085 * called at least once more
1090 /* An invisible item with a goal allocation of
1091 * 0 is already at its goal.
1093 if ((state == NORMAL || state == OVERFLOWN) &&
1094 ((goal_allocation.width != 0 &&
1095 goal_allocation.height != 0) ||
1096 toolbar_content_child_visible (content)))
1098 if ((goal_allocation.x != allocation.x ||
1099 goal_allocation.y != allocation.y ||
1100 goal_allocation.width != allocation.width ||
1101 goal_allocation.height != allocation.height))
1103 /* An item is not in its right position yet. Note
1104 * that OVERFLOWN items do get an allocation in
1105 * gtk_toolbar_size_allocate(). This way you can see
1106 * them slide back in when you drag an item off the
1113 if (toolbar_content_is_placeholder (content) &&
1114 toolbar_content_disappearing (content) &&
1115 toolbar_content_child_visible (content))
1117 /* A disappearing placeholder is still visible.
1125 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1131 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1133 priv->is_sliding = FALSE;
1140 rect_within (GtkAllocation *a1,
1143 return (a1->x >= a2->x &&
1144 a1->x + a1->width <= a2->x + a2->width &&
1146 a1->y + a1->height <= a2->y + a2->height);
1150 gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
1152 GtkWidget *widget = GTK_WIDGET (toolbar);
1153 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1161 /* Start the sliding. This function copies the allocation of every
1162 * item into content->start_allocation. For items that haven't
1163 * been allocated yet, we calculate their position and save that
1164 * in start_allocatino along with zero width and zero height.
1166 * FIXME: It would be nice if we could share this code with
1167 * the equivalent in gtk_widget_size_allocate().
1169 priv->is_sliding = TRUE;
1172 priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
1174 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1175 vertical = (toolbar->orientation == GTK_ORIENTATION_VERTICAL);
1176 border_width = get_internal_padding (toolbar) + gtk_container_get_border_width (GTK_CONTAINER (toolbar));
1180 cur_x = widget->allocation.width - border_width - widget->style->xthickness;
1181 cur_y = widget->allocation.height - border_width - widget->style->ythickness;
1185 cur_x = border_width + widget->style->xthickness;
1186 cur_y = border_width + widget->style->ythickness;
1189 cur_x += widget->allocation.x;
1190 cur_y += widget->allocation.y;
1192 for (list = priv->content; list != NULL; list = list->next)
1194 ToolbarContent *content = list->data;
1195 GtkAllocation new_start_allocation;
1196 GtkAllocation item_allocation;
1199 state = toolbar_content_get_state (content);
1200 toolbar_content_get_allocation (content, &item_allocation);
1202 if ((state == NORMAL &&
1203 rect_within (&item_allocation, &(widget->allocation))) ||
1206 new_start_allocation = item_allocation;
1210 new_start_allocation.x = cur_x;
1211 new_start_allocation.y = cur_y;
1215 new_start_allocation.width = widget->allocation.width -
1216 2 * border_width - 2 * widget->style->xthickness;
1217 new_start_allocation.height = 0;
1221 new_start_allocation.width = 0;
1222 new_start_allocation.height = widget->allocation.height -
1223 2 * border_width - 2 * widget->style->ythickness;
1228 cur_y = new_start_allocation.y + new_start_allocation.height;
1230 cur_x = new_start_allocation.x;
1232 cur_x = new_start_allocation.x + new_start_allocation.width;
1234 toolbar_content_set_start_allocation (content, &new_start_allocation);
1237 /* This resize will run before the first idle handler. This
1238 * will make sure that items get the right goal allocation
1239 * so that the idle handler will not immediately return
1242 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1243 g_timer_reset (priv->timer);
1247 gtk_toolbar_stop_sliding (GtkToolbar *toolbar)
1249 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1251 if (priv->is_sliding)
1255 priv->is_sliding = FALSE;
1259 g_source_remove (priv->idle_id);
1263 list = priv->content;
1266 ToolbarContent *content = list->data;
1269 if (toolbar_content_is_placeholder (content))
1271 toolbar_content_remove (content, toolbar);
1272 toolbar_content_free (content);
1276 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1281 remove_item (GtkWidget *menu_item,
1284 gtk_container_remove (GTK_CONTAINER (menu_item->parent), menu_item);
1288 menu_deactivated (GtkWidget *menu,
1289 GtkToolbar *toolbar)
1291 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1292 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->arrow_button), FALSE);
1296 menu_detached (GtkWidget *toolbar,
1299 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1304 rebuild_menu (GtkToolbar *toolbar)
1306 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1307 GList *list, *children;
1311 priv->menu = GTK_MENU (gtk_menu_new());
1312 gtk_menu_attach_to_widget (priv->menu,
1313 GTK_WIDGET (toolbar),
1316 g_signal_connect (priv->menu, "deactivate",
1317 G_CALLBACK (menu_deactivated), toolbar);
1320 gtk_container_foreach (GTK_CONTAINER (priv->menu), remove_item, NULL);
1322 for (list = priv->content; list != NULL; list = list->next)
1324 ToolbarContent *content = list->data;
1326 if (toolbar_content_get_state (content) == OVERFLOWN &&
1327 !toolbar_content_is_placeholder (content))
1329 GtkWidget *menu_item = toolbar_content_retrieve_menu_item (content);
1333 g_assert (GTK_IS_MENU_ITEM (menu_item));
1334 gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item);
1339 /* Remove leading and trailing separator items */
1340 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1343 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1345 GtkWidget *child = list->data;
1347 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1350 g_list_free (children);
1352 /* Regenerate the list of children so we don't try to remove items twice */
1353 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1355 list = g_list_last (children);
1356 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1358 GtkWidget *child = list->data;
1360 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1363 g_list_free (children);
1365 priv->need_rebuild = FALSE;
1369 gtk_toolbar_size_allocate (GtkWidget *widget,
1370 GtkAllocation *allocation)
1372 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1373 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1374 GtkAllocation *allocations;
1375 ItemState *new_states;
1376 GtkAllocation arrow_allocation;
1378 gint size, pos, short_size;
1381 gboolean need_arrow;
1382 gint n_expand_items;
1384 gint available_size;
1387 GtkRequisition arrow_requisition;
1388 gboolean overflowing;
1389 gboolean size_changed;
1391 GtkAllocation item_area;
1392 GtkShadowType shadow_type;
1394 size_changed = FALSE;
1395 if (widget->allocation.x != allocation->x ||
1396 widget->allocation.y != allocation->y ||
1397 widget->allocation.width != allocation->width ||
1398 widget->allocation.height != allocation->height)
1400 size_changed = TRUE;
1404 gtk_toolbar_stop_sliding (toolbar);
1406 widget->allocation = *allocation;
1408 border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
1410 if (gtk_widget_get_realized (widget))
1412 gdk_window_move_resize (priv->event_window,
1413 allocation->x + border_width,
1414 allocation->y + border_width,
1415 allocation->width - border_width * 2,
1416 allocation->height - border_width * 2);
1419 border_width += get_internal_padding (toolbar);
1421 gtk_widget_get_child_requisition (GTK_WIDGET (priv->arrow_button),
1422 &arrow_requisition);
1424 shadow_type = get_shadow_type (toolbar);
1426 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1428 available_size = size = allocation->width - 2 * border_width;
1429 short_size = allocation->height - 2 * border_width;
1430 arrow_size = arrow_requisition.width;
1432 if (shadow_type != GTK_SHADOW_NONE)
1434 available_size -= 2 * widget->style->xthickness;
1435 short_size -= 2 * widget->style->ythickness;
1440 available_size = size = allocation->height - 2 * border_width;
1441 short_size = allocation->width - 2 * border_width;
1442 arrow_size = arrow_requisition.height;
1444 if (shadow_type != GTK_SHADOW_NONE)
1446 available_size -= 2 * widget->style->ythickness;
1447 short_size -= 2 * widget->style->xthickness;
1451 n_items = g_list_length (priv->content);
1452 allocations = g_new0 (GtkAllocation, n_items);
1453 new_states = g_new0 (ItemState, n_items);
1457 for (list = priv->content; list != NULL; list = list->next)
1459 ToolbarContent *content = list->data;
1461 if (toolbar_content_visible (content, toolbar))
1463 needed_size += get_item_size (toolbar, content);
1465 /* Do we need an arrow?
1467 * Assume we don't, and see if any non-separator item with a
1468 * proxy menu item is then going to overflow.
1470 if (needed_size > available_size &&
1473 toolbar_content_has_proxy_menu_item (content) &&
1474 !toolbar_content_is_separator (content))
1482 size = available_size - arrow_size;
1484 size = available_size;
1486 /* calculate widths and states of items */
1487 overflowing = FALSE;
1488 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1490 ToolbarContent *content = list->data;
1493 if (!toolbar_content_visible (content, toolbar))
1495 new_states[i] = HIDDEN;
1499 item_size = get_item_size (toolbar, content);
1500 if (item_size <= size && !overflowing)
1503 allocations[i].width = item_size;
1504 new_states[i] = NORMAL;
1509 new_states[i] = OVERFLOWN;
1510 allocations[i].width = item_size;
1514 /* calculate width of arrow */
1517 arrow_allocation.width = arrow_size;
1518 arrow_allocation.height = MAX (short_size, 1);
1521 /* expand expandable items */
1523 /* We don't expand when there is an overflow menu, because that leads to
1524 * weird jumps when items get moved to the overflow menu and the expanding
1525 * items suddenly get a lot of extra space
1529 gint max_child_expand;
1532 for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
1534 ToolbarContent *content = list->data;
1536 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1540 max_child_expand = get_max_child_expand (toolbar);
1541 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1543 ToolbarContent *content = list->data;
1545 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1547 gint extra = size / n_expand_items;
1548 if (size % n_expand_items != 0)
1551 if (extra > max_child_expand)
1552 extra = max_child_expand;
1554 allocations[i].width += extra;
1560 g_assert (n_expand_items == 0);
1563 /* position items */
1565 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1567 /* both NORMAL and OVERFLOWN items get a position. This ensures
1568 * that sliding will work for OVERFLOWN items too
1570 if (new_states[i] == NORMAL ||
1571 new_states[i] == OVERFLOWN)
1573 allocations[i].x = pos;
1574 allocations[i].y = border_width;
1575 allocations[i].height = short_size;
1577 pos += allocations[i].width;
1581 /* position arrow */
1584 arrow_allocation.x = available_size - border_width - arrow_allocation.width;
1585 arrow_allocation.y = border_width;
1588 item_area.x = border_width;
1589 item_area.y = border_width;
1590 item_area.width = available_size - (need_arrow? arrow_size : 0);
1591 item_area.height = short_size;
1593 /* fix up allocations in the vertical or RTL cases */
1594 if (toolbar->orientation == GTK_ORIENTATION_VERTICAL)
1596 for (i = 0; i < n_items; ++i)
1597 fixup_allocation_for_vertical (&(allocations[i]));
1600 fixup_allocation_for_vertical (&arrow_allocation);
1602 fixup_allocation_for_vertical (&item_area);
1604 else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1606 for (i = 0; i < n_items; ++i)
1607 fixup_allocation_for_rtl (available_size, &(allocations[i]));
1610 fixup_allocation_for_rtl (available_size, &arrow_allocation);
1612 fixup_allocation_for_rtl (available_size, &item_area);
1615 /* translate the items by allocation->(x,y) */
1616 for (i = 0; i < n_items; ++i)
1618 allocations[i].x += allocation->x;
1619 allocations[i].y += allocation->y;
1621 if (shadow_type != GTK_SHADOW_NONE)
1623 allocations[i].x += widget->style->xthickness;
1624 allocations[i].y += widget->style->ythickness;
1630 arrow_allocation.x += allocation->x;
1631 arrow_allocation.y += allocation->y;
1633 if (shadow_type != GTK_SHADOW_NONE)
1635 arrow_allocation.x += widget->style->xthickness;
1636 arrow_allocation.y += widget->style->ythickness;
1640 item_area.x += allocation->x;
1641 item_area.y += allocation->y;
1642 if (shadow_type != GTK_SHADOW_NONE)
1644 item_area.x += widget->style->xthickness;
1645 item_area.y += widget->style->ythickness;
1648 /* did anything change? */
1649 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1651 ToolbarContent *content = list->data;
1653 if (toolbar_content_get_state (content) == NORMAL &&
1654 new_states[i] != NORMAL)
1656 /* an item disappeared and we didn't change size, so begin sliding */
1658 gtk_toolbar_begin_sliding (toolbar);
1662 /* finally allocate the items */
1663 if (priv->is_sliding)
1665 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1667 ToolbarContent *content = list->data;
1669 toolbar_content_set_goal_allocation (content, &(allocations[i]));
1673 elapsed = g_timer_elapsed (priv->timer, NULL);
1674 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1676 ToolbarContent *content = list->data;
1678 if (new_states[i] == OVERFLOWN ||
1679 new_states[i] == NORMAL)
1681 GtkAllocation alloc;
1682 GtkAllocation start_allocation = { 0, };
1683 GtkAllocation goal_allocation;
1685 if (priv->is_sliding)
1687 toolbar_content_get_start_allocation (content, &start_allocation);
1688 toolbar_content_get_goal_allocation (content, &goal_allocation);
1690 compute_intermediate_allocation (toolbar,
1695 priv->need_sync = TRUE;
1699 alloc = allocations[i];
1702 if (alloc.width <= 0 || alloc.height <= 0)
1704 toolbar_content_set_child_visible (content, toolbar, FALSE);
1708 if (!rect_within (&alloc, &item_area))
1710 toolbar_content_set_child_visible (content, toolbar, FALSE);
1711 toolbar_content_size_allocate (content, &alloc);
1715 toolbar_content_set_child_visible (content, toolbar, TRUE);
1716 toolbar_content_size_allocate (content, &alloc);
1722 toolbar_content_set_child_visible (content, toolbar, FALSE);
1725 toolbar_content_set_state (content, new_states[i]);
1728 if (priv->menu && priv->need_rebuild)
1729 rebuild_menu (toolbar);
1733 gtk_widget_size_allocate (GTK_WIDGET (priv->arrow_button),
1735 gtk_widget_show (GTK_WIDGET (priv->arrow_button));
1739 gtk_widget_hide (GTK_WIDGET (priv->arrow_button));
1741 if (priv->menu && gtk_widget_get_visible (GTK_WIDGET (priv->menu)))
1742 gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
1745 g_free (allocations);
1746 g_free (new_states);
1750 gtk_toolbar_update_button_relief (GtkToolbar *toolbar)
1752 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1753 GtkReliefStyle relief;
1755 relief = get_button_relief (toolbar);
1757 if (relief != gtk_button_get_relief (GTK_BUTTON (priv->arrow_button)))
1759 gtk_toolbar_reconfigured (toolbar);
1761 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), relief);
1766 gtk_toolbar_style_set (GtkWidget *widget,
1767 GtkStyle *prev_style)
1769 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
1771 priv->max_homogeneous_pixels = -1;
1773 if (gtk_widget_get_realized (widget))
1774 gtk_style_set_background (widget->style, widget->window, widget->state);
1777 gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
1781 gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
1782 GtkDirectionType dir)
1784 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1785 GList *result = NULL;
1789 /* generate list of children in reverse logical order */
1791 for (list = priv->content; list != NULL; list = list->next)
1793 ToolbarContent *content = list->data;
1796 widget = toolbar_content_get_widget (content);
1799 result = g_list_prepend (result, widget);
1802 result = g_list_prepend (result, priv->arrow_button);
1804 rtl = (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL);
1806 /* move in logical order when
1808 * - dir is TAB_FORWARD
1810 * - in RTL mode and moving left or up
1812 * - in LTR mode and moving right or down
1814 if (dir == GTK_DIR_TAB_FORWARD ||
1815 (rtl && (dir == GTK_DIR_UP || dir == GTK_DIR_LEFT)) ||
1816 (!rtl && (dir == GTK_DIR_DOWN || dir == GTK_DIR_RIGHT)))
1818 result = g_list_reverse (result);
1825 gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
1826 gboolean focus_home)
1828 GList *children, *list;
1829 GtkDirectionType dir = focus_home? GTK_DIR_RIGHT : GTK_DIR_LEFT;
1831 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1833 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1835 children = g_list_reverse (children);
1837 dir = (dir == GTK_DIR_RIGHT)? GTK_DIR_LEFT : GTK_DIR_RIGHT;
1840 for (list = children; list != NULL; list = list->next)
1842 GtkWidget *child = list->data;
1844 if (gtk_container_get_focus_child (GTK_CONTAINER (toolbar)) == child)
1847 if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1851 g_list_free (children);
1856 /* Keybinding handler. This function is called when the user presses
1857 * Ctrl TAB or an arrow key.
1860 gtk_toolbar_move_focus (GtkWidget *widget,
1861 GtkDirectionType dir)
1863 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1864 GtkContainer *container = GTK_CONTAINER (toolbar);
1865 GtkWidget *focus_child;
1867 gboolean try_focus = FALSE;
1870 focus_child = gtk_container_get_focus_child (container);
1872 if (focus_child && gtk_widget_child_focus (focus_child, dir))
1875 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1877 for (list = children; list != NULL; list = list->next)
1879 GtkWidget *child = list->data;
1881 if (try_focus && gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1884 if (child == focus_child)
1888 g_list_free (children);
1891 /* The focus handler for the toolbar. It called when the user presses
1892 * TAB or otherwise tries to focus the toolbar.
1895 gtk_toolbar_focus (GtkWidget *widget,
1896 GtkDirectionType dir)
1898 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1899 GList *children, *list;
1900 gboolean result = FALSE;
1902 /* if focus is already somewhere inside the toolbar then return FALSE.
1903 * The only way focus can stay inside the toolbar is when the user presses
1904 * arrow keys or Ctrl TAB (both of which are handled by the
1905 * gtk_toolbar_move_focus() keybinding function.
1907 if (gtk_container_get_focus_child (GTK_CONTAINER (widget)))
1910 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1912 for (list = children; list != NULL; list = list->next)
1914 GtkWidget *child = list->data;
1916 if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1923 g_list_free (children);
1928 static GtkSettings *
1929 toolbar_get_settings (GtkToolbar *toolbar)
1931 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1932 return priv->settings;
1936 style_change_notify (GtkToolbar *toolbar)
1938 if (!toolbar->style_set)
1940 /* pretend it was set, then unset, thus reverting to new default */
1941 toolbar->style_set = TRUE;
1942 gtk_toolbar_unset_style (toolbar);
1947 icon_size_change_notify (GtkToolbar *toolbar)
1949 if (!toolbar->icon_size_set)
1951 /* pretend it was set, then unset, thus reverting to new default */
1952 toolbar->icon_size_set = TRUE;
1953 gtk_toolbar_unset_icon_size (toolbar);
1958 animation_change_notify (GtkToolbar *toolbar)
1960 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1961 GtkSettings *settings = toolbar_get_settings (toolbar);
1965 g_object_get (settings,
1966 "gtk-enable-animations", &animation,
1969 animation = DEFAULT_ANIMATION_STATE;
1971 priv->animation = animation;
1975 settings_change_notify (GtkSettings *settings,
1976 const GParamSpec *pspec,
1977 GtkToolbar *toolbar)
1979 if (! strcmp (pspec->name, "gtk-toolbar-style"))
1980 style_change_notify (toolbar);
1981 else if (! strcmp (pspec->name, "gtk-toolbar-icon-size"))
1982 icon_size_change_notify (toolbar);
1983 else if (! strcmp (pspec->name, "gtk-enable-animations"))
1984 animation_change_notify (toolbar);
1988 gtk_toolbar_screen_changed (GtkWidget *widget,
1989 GdkScreen *previous_screen)
1991 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
1992 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1993 GtkSettings *old_settings = toolbar_get_settings (toolbar);
1994 GtkSettings *settings;
1996 if (gtk_widget_has_screen (GTK_WIDGET (toolbar)))
1997 settings = gtk_widget_get_settings (GTK_WIDGET (toolbar));
2001 if (settings == old_settings)
2006 g_signal_handler_disconnect (old_settings, priv->settings_connection);
2008 g_object_unref (old_settings);
2013 priv->settings_connection =
2014 g_signal_connect (settings, "notify",
2015 G_CALLBACK (settings_change_notify),
2018 priv->settings = g_object_ref (settings);
2021 priv->settings = NULL;
2023 style_change_notify (toolbar);
2024 icon_size_change_notify (toolbar);
2025 animation_change_notify (toolbar);
2029 find_drop_index (GtkToolbar *toolbar,
2033 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2034 GList *interesting_content;
2036 GtkOrientation orientation;
2037 GtkTextDirection direction;
2038 gint best_distance = G_MAXINT;
2042 ToolbarContent *best_content;
2043 GtkAllocation allocation;
2045 /* list items we care about wrt. drag and drop */
2046 interesting_content = NULL;
2047 for (list = priv->content; list != NULL; list = list->next)
2049 ToolbarContent *content = list->data;
2051 if (toolbar_content_get_state (content) == NORMAL)
2052 interesting_content = g_list_prepend (interesting_content, content);
2054 interesting_content = g_list_reverse (interesting_content);
2056 if (!interesting_content)
2059 orientation = toolbar->orientation;
2060 direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
2062 /* distance to first interesting item */
2063 best_content = interesting_content->data;
2064 toolbar_content_get_allocation (best_content, &allocation);
2066 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2070 if (direction == GTK_TEXT_DIR_LTR)
2073 pos = allocation.x + allocation.width;
2081 best_content = NULL;
2082 best_distance = ABS (pos - cursor);
2084 /* distance to far end of each item */
2085 for (list = interesting_content; list != NULL; list = list->next)
2087 ToolbarContent *content = list->data;
2089 toolbar_content_get_allocation (content, &allocation);
2091 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2093 if (direction == GTK_TEXT_DIR_LTR)
2094 pos = allocation.x + allocation.width;
2100 pos = allocation.y + allocation.height;
2103 distance = ABS (pos - cursor);
2105 if (distance < best_distance)
2107 best_distance = distance;
2108 best_content = content;
2112 g_list_free (interesting_content);
2117 return g_list_index (priv->content, best_content) + 1;
2121 reset_all_placeholders (GtkToolbar *toolbar)
2123 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2126 for (list = priv->content; list != NULL; list = list->next)
2128 ToolbarContent *content = list->data;
2129 if (toolbar_content_is_placeholder (content))
2130 toolbar_content_set_disappearing (content, TRUE);
2135 physical_to_logical (GtkToolbar *toolbar,
2138 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2142 g_assert (physical >= 0);
2145 for (list = priv->content; list && physical > 0; list = list->next)
2147 ToolbarContent *content = list->data;
2149 if (!toolbar_content_is_placeholder (content))
2154 g_assert (physical == 0);
2160 logical_to_physical (GtkToolbar *toolbar,
2163 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2167 g_assert (logical >= 0);
2170 for (list = priv->content; list; list = list->next)
2172 ToolbarContent *content = list->data;
2174 if (!toolbar_content_is_placeholder (content))
2184 g_assert (logical == 0);
2190 * gtk_toolbar_set_drop_highlight_item:
2191 * @toolbar: a #GtkToolbar
2192 * @tool_item: (allow-none): a #GtkToolItem, or %NULL to turn of highlighting
2193 * @index_: a position on @toolbar
2195 * Highlights @toolbar to give an idea of what it would look like
2196 * if @item was added to @toolbar at the position indicated by @index_.
2197 * If @item is %NULL, highlighting is turned off. In that case @index_
2200 * The @tool_item passed to this function must not be part of any widget
2201 * hierarchy. When an item is set as drop highlight item it can not
2202 * added to any widget hierarchy or used as highlight item for another
2208 gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar,
2209 GtkToolItem *tool_item,
2212 ToolbarContent *content;
2213 GtkToolbarPrivate *priv;
2215 GtkRequisition requisition;
2216 GtkRequisition old_requisition;
2217 gboolean restart_sliding;
2219 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2220 g_return_if_fail (tool_item == NULL || GTK_IS_TOOL_ITEM (tool_item));
2222 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2226 if (priv->highlight_tool_item)
2228 gtk_widget_unparent (GTK_WIDGET (priv->highlight_tool_item));
2229 g_object_unref (priv->highlight_tool_item);
2230 priv->highlight_tool_item = NULL;
2233 reset_all_placeholders (toolbar);
2234 gtk_toolbar_begin_sliding (toolbar);
2238 n_items = gtk_toolbar_get_n_items (toolbar);
2239 if (index_ < 0 || index_ > n_items)
2242 if (tool_item != priv->highlight_tool_item)
2244 if (priv->highlight_tool_item)
2245 g_object_unref (priv->highlight_tool_item);
2247 g_object_ref_sink (tool_item);
2249 priv->highlight_tool_item = tool_item;
2251 gtk_widget_set_parent (GTK_WIDGET (priv->highlight_tool_item),
2252 GTK_WIDGET (toolbar));
2255 index_ = logical_to_physical (toolbar, index_);
2257 content = g_list_nth_data (priv->content, index_);
2261 ToolbarContent *prev_content;
2263 prev_content = g_list_nth_data (priv->content, index_ - 1);
2265 if (prev_content && toolbar_content_is_placeholder (prev_content))
2266 content = prev_content;
2269 if (!content || !toolbar_content_is_placeholder (content))
2271 GtkWidget *placeholder;
2273 placeholder = GTK_WIDGET (gtk_separator_tool_item_new ());
2275 content = toolbar_content_new_tool_item (toolbar,
2276 GTK_TOOL_ITEM (placeholder),
2278 gtk_widget_show (placeholder);
2282 g_assert (toolbar_content_is_placeholder (content));
2284 gtk_widget_size_request (GTK_WIDGET (priv->highlight_tool_item),
2287 toolbar_content_set_expand (content, gtk_tool_item_get_expand (tool_item));
2289 restart_sliding = FALSE;
2290 toolbar_content_size_request (content, toolbar, &old_requisition);
2291 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2293 requisition.height = -1;
2294 if (requisition.width != old_requisition.width)
2295 restart_sliding = TRUE;
2299 requisition.width = -1;
2300 if (requisition.height != old_requisition.height)
2301 restart_sliding = TRUE;
2304 if (toolbar_content_disappearing (content))
2305 restart_sliding = TRUE;
2307 reset_all_placeholders (toolbar);
2308 toolbar_content_set_disappearing (content, FALSE);
2310 toolbar_content_set_size_request (content,
2311 requisition.width, requisition.height);
2313 if (restart_sliding)
2314 gtk_toolbar_begin_sliding (toolbar);
2318 gtk_toolbar_get_child_property (GtkContainer *container,
2324 GtkToolItem *item = GTK_TOOL_ITEM (child);
2326 switch (property_id)
2328 case CHILD_PROP_HOMOGENEOUS:
2329 g_value_set_boolean (value, gtk_tool_item_get_homogeneous (item));
2332 case CHILD_PROP_EXPAND:
2333 g_value_set_boolean (value, gtk_tool_item_get_expand (item));
2337 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2343 gtk_toolbar_set_child_property (GtkContainer *container,
2346 const GValue *value,
2349 switch (property_id)
2351 case CHILD_PROP_HOMOGENEOUS:
2352 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2355 case CHILD_PROP_EXPAND:
2356 gtk_tool_item_set_expand (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2360 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2366 gtk_toolbar_show_all (GtkWidget *widget)
2368 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2371 for (list = priv->content; list != NULL; list = list->next)
2373 ToolbarContent *content = list->data;
2375 toolbar_content_show_all (content);
2378 gtk_widget_show (widget);
2382 gtk_toolbar_hide_all (GtkWidget *widget)
2384 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2387 for (list = priv->content; list != NULL; list = list->next)
2389 ToolbarContent *content = list->data;
2391 toolbar_content_hide_all (content);
2394 gtk_widget_hide (widget);
2398 gtk_toolbar_add (GtkContainer *container,
2401 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2403 gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
2407 gtk_toolbar_remove (GtkContainer *container,
2410 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2411 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2412 ToolbarContent *content_to_remove;
2415 content_to_remove = NULL;
2416 for (list = priv->content; list != NULL; list = list->next)
2418 ToolbarContent *content = list->data;
2421 child = toolbar_content_get_widget (content);
2422 if (child && child == widget)
2424 content_to_remove = content;
2429 g_return_if_fail (content_to_remove != NULL);
2431 toolbar_content_remove (content_to_remove, toolbar);
2432 toolbar_content_free (content_to_remove);
2436 gtk_toolbar_forall (GtkContainer *container,
2437 gboolean include_internals,
2438 GtkCallback callback,
2439 gpointer callback_data)
2441 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2442 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2445 g_return_if_fail (callback != NULL);
2447 list = priv->content;
2450 ToolbarContent *content = list->data;
2451 GList *next = list->next;
2453 if (include_internals || !toolbar_content_is_placeholder (content))
2455 GtkWidget *child = toolbar_content_get_widget (content);
2458 callback (child, callback_data);
2464 if (include_internals)
2465 callback (priv->arrow_button, callback_data);
2469 gtk_toolbar_child_type (GtkContainer *container)
2471 return GTK_TYPE_TOOL_ITEM;
2475 gtk_toolbar_reconfigured (GtkToolbar *toolbar)
2477 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2480 list = priv->content;
2483 ToolbarContent *content = list->data;
2484 GList *next = list->next;
2486 toolbar_content_toolbar_reconfigured (content, toolbar);
2493 gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
2494 GtkOrientation orientation)
2496 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2497 if (toolbar->orientation != orientation)
2499 toolbar->orientation = orientation;
2501 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2502 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2504 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2506 gtk_toolbar_reconfigured (toolbar);
2508 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2509 g_object_notify (G_OBJECT (toolbar), "orientation");
2514 gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
2515 GtkToolbarStyle style)
2517 if (toolbar->style != style)
2519 toolbar->style = style;
2521 gtk_toolbar_reconfigured (toolbar);
2523 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2524 g_object_notify (G_OBJECT (toolbar), "toolbar-style");
2529 menu_position_func (GtkMenu *menu,
2535 GtkToolbar *toolbar = GTK_TOOLBAR (user_data);
2536 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2538 GtkRequisition menu_req;
2539 GdkRectangle monitor;
2543 gtk_widget_size_request (priv->arrow_button, &req);
2544 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2546 screen = gtk_widget_get_screen (GTK_WIDGET (menu));
2547 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->arrow_button->window);
2548 if (monitor_num < 0)
2550 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2552 gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
2553 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2555 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2556 *x += priv->arrow_button->allocation.width - req.width;
2558 *x += req.width - menu_req.width;
2560 if ((*y + priv->arrow_button->allocation.height + menu_req.height) <= monitor.y + monitor.height)
2561 *y += priv->arrow_button->allocation.height;
2562 else if ((*y - menu_req.height) >= monitor.y)
2563 *y -= menu_req.height;
2564 else if (monitor.y + monitor.height - (*y + priv->arrow_button->allocation.height) > *y)
2565 *y += priv->arrow_button->allocation.height;
2567 *y -= menu_req.height;
2571 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2572 *x += priv->arrow_button->allocation.width;
2574 *x -= menu_req.width;
2576 if (*y + menu_req.height > monitor.y + monitor.height &&
2577 *y + priv->arrow_button->allocation.height - monitor.y > monitor.y + monitor.height - *y)
2578 *y += priv->arrow_button->allocation.height - menu_req.height;
2585 show_menu (GtkToolbar *toolbar,
2586 GdkEventButton *event)
2588 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2590 rebuild_menu (toolbar);
2592 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2594 gtk_menu_popup (priv->menu, NULL, NULL,
2595 menu_position_func, toolbar,
2596 event? event->button : 0,
2597 event? event->time : gtk_get_current_event_time());
2601 gtk_toolbar_arrow_button_clicked (GtkWidget *button,
2602 GtkToolbar *toolbar)
2604 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2606 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) &&
2607 (!priv->menu || !gtk_widget_get_visible (GTK_WIDGET (priv->menu))))
2609 /* We only get here when the button is clicked with the keyboard,
2610 * because mouse button presses result in the menu being shown so
2611 * that priv->menu would be non-NULL and visible.
2613 show_menu (toolbar, NULL);
2614 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
2619 gtk_toolbar_arrow_button_press (GtkWidget *button,
2620 GdkEventButton *event,
2621 GtkToolbar *toolbar)
2623 show_menu (toolbar, event);
2624 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
2630 gtk_toolbar_button_press (GtkWidget *toolbar,
2631 GdkEventButton *event)
2633 if (event->button == 3)
2635 gboolean return_value;
2637 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2638 (int)event->x_root, (int)event->y_root, event->button,
2641 return return_value;
2648 gtk_toolbar_popup_menu (GtkWidget *toolbar)
2650 gboolean return_value;
2651 /* This function is the handler for the "popup menu" keybinding,
2652 * ie., it is called when the user presses Shift F10
2654 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2655 -1, -1, -1, &return_value);
2657 return return_value;
2663 * Creates a new toolbar.
2665 * Return Value: the newly-created toolbar.
2668 gtk_toolbar_new (void)
2670 GtkToolbar *toolbar;
2672 toolbar = g_object_new (GTK_TYPE_TOOLBAR, NULL);
2674 return GTK_WIDGET (toolbar);
2678 * gtk_toolbar_insert:
2679 * @toolbar: a #GtkToolbar
2680 * @item: a #GtkToolItem
2681 * @pos: the position of the new item
2683 * Insert a #GtkToolItem into the toolbar at position @pos. If @pos is
2684 * 0 the item is prepended to the start of the toolbar. If @pos is
2685 * negative, the item is appended to the end of the toolbar.
2690 gtk_toolbar_insert (GtkToolbar *toolbar,
2694 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2695 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
2698 pos = logical_to_physical (toolbar, pos);
2700 toolbar_content_new_tool_item (toolbar, item, FALSE, pos);
2704 * gtk_toolbar_get_item_index:
2705 * @toolbar: a #GtkToolbar
2706 * @item: a #GtkToolItem that is a child of @toolbar
2708 * Returns the position of @item on the toolbar, starting from 0.
2709 * It is an error if @item is not a child of the toolbar.
2711 * Return value: the position of item on the toolbar.
2716 gtk_toolbar_get_item_index (GtkToolbar *toolbar,
2719 GtkToolbarPrivate *priv;
2723 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2724 g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
2725 g_return_val_if_fail (GTK_WIDGET (item)->parent == GTK_WIDGET (toolbar), -1);
2727 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2730 for (list = priv->content; list != NULL; list = list->next)
2732 ToolbarContent *content = list->data;
2735 widget = toolbar_content_get_widget (content);
2737 if (item == GTK_TOOL_ITEM (widget))
2743 return physical_to_logical (toolbar, n);
2747 * gtk_toolbar_set_style:
2748 * @toolbar: a #GtkToolbar.
2749 * @style: the new style for @toolbar.
2751 * Alters the view of @toolbar to display either icons only, text only, or both.
2754 gtk_toolbar_set_style (GtkToolbar *toolbar,
2755 GtkToolbarStyle style)
2757 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2759 toolbar->style_set = TRUE;
2760 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2764 * gtk_toolbar_get_style:
2765 * @toolbar: a #GtkToolbar
2767 * Retrieves whether the toolbar has text, icons, or both . See
2768 * gtk_toolbar_set_style().
2770 * Return value: the current style of @toolbar
2773 gtk_toolbar_get_style (GtkToolbar *toolbar)
2775 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_TOOLBAR_STYLE);
2777 return toolbar->style;
2781 * gtk_toolbar_unset_style:
2782 * @toolbar: a #GtkToolbar
2784 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that
2785 * user preferences will be used to determine the toolbar style.
2788 gtk_toolbar_unset_style (GtkToolbar *toolbar)
2790 GtkToolbarStyle style;
2792 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2794 if (toolbar->style_set)
2796 GtkSettings *settings = toolbar_get_settings (toolbar);
2799 g_object_get (settings,
2800 "gtk-toolbar-style", &style,
2803 style = DEFAULT_TOOLBAR_STYLE;
2805 if (style != toolbar->style)
2806 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2808 toolbar->style_set = FALSE;
2813 * gtk_toolbar_get_n_items:
2814 * @toolbar: a #GtkToolbar
2816 * Returns the number of items on the toolbar.
2818 * Return value: the number of items on the toolbar
2823 gtk_toolbar_get_n_items (GtkToolbar *toolbar)
2825 GtkToolbarPrivate *priv;
2827 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2829 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2831 return physical_to_logical (toolbar, g_list_length (priv->content));
2835 * gtk_toolbar_get_nth_item:
2836 * @toolbar: a #GtkToolbar
2837 * @n: A position on the toolbar
2839 * Returns the @n<!-- -->'th item on @toolbar, or %NULL if the
2840 * toolbar does not contain an @n<!-- -->'th item.
2842 * Return value: The @n<!-- -->'th #GtkToolItem on @toolbar, or %NULL if there
2843 * isn't an @n<!-- -->'th item.
2848 gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
2851 GtkToolbarPrivate *priv;
2852 ToolbarContent *content;
2855 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
2857 n_items = gtk_toolbar_get_n_items (toolbar);
2859 if (n < 0 || n >= n_items)
2862 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2864 content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
2867 g_assert (!toolbar_content_is_placeholder (content));
2869 return GTK_TOOL_ITEM (toolbar_content_get_widget (content));
2873 * gtk_toolbar_get_icon_size:
2874 * @toolbar: a #GtkToolbar
2876 * Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size().
2878 * Return value: (type int): the current icon size for the icons on
2882 gtk_toolbar_get_icon_size (GtkToolbar *toolbar)
2884 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_ICON_SIZE);
2886 return toolbar->icon_size;
2890 * gtk_toolbar_get_relief_style:
2891 * @toolbar: a #GtkToolbar
2893 * Returns the relief style of buttons on @toolbar. See
2894 * gtk_button_set_relief().
2896 * Return value: The relief style of buttons on @toolbar.
2901 gtk_toolbar_get_relief_style (GtkToolbar *toolbar)
2903 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_RELIEF_NONE);
2905 return get_button_relief (toolbar);
2909 * gtk_toolbar_set_show_arrow:
2910 * @toolbar: a #GtkToolbar
2911 * @show_arrow: Whether to show an overflow menu
2913 * Sets whether to show an overflow menu when
2914 * @toolbar doesn't have room for all items on it. If %TRUE,
2915 * items that there are not room are available through an
2921 gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
2922 gboolean show_arrow)
2924 GtkToolbarPrivate *priv;
2926 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2928 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2929 show_arrow = show_arrow != FALSE;
2931 if (priv->show_arrow != show_arrow)
2933 priv->show_arrow = show_arrow;
2935 if (!priv->show_arrow)
2936 gtk_widget_hide (priv->arrow_button);
2938 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2939 g_object_notify (G_OBJECT (toolbar), "show-arrow");
2944 * gtk_toolbar_get_show_arrow:
2945 * @toolbar: a #GtkToolbar
2947 * Returns whether the toolbar has an overflow menu.
2948 * See gtk_toolbar_set_show_arrow().
2950 * Return value: %TRUE if the toolbar has an overflow menu.
2955 gtk_toolbar_get_show_arrow (GtkToolbar *toolbar)
2957 GtkToolbarPrivate *priv;
2959 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
2961 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2963 return priv->show_arrow;
2967 * gtk_toolbar_get_drop_index:
2968 * @toolbar: a #GtkToolbar
2969 * @x: x coordinate of a point on the toolbar
2970 * @y: y coordinate of a point on the toolbar
2972 * Returns the position corresponding to the indicated point on
2973 * @toolbar. This is useful when dragging items to the toolbar:
2974 * this function returns the position a new item should be
2977 * @x and @y are in @toolbar coordinates.
2979 * Return value: The position corresponding to the point (@x, @y) on the toolbar.
2984 gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
2988 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2990 return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
2994 gtk_toolbar_finalize (GObject *object)
2997 GtkToolbar *toolbar = GTK_TOOLBAR (object);
2998 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3000 if (priv->arrow_button)
3001 gtk_widget_unparent (priv->arrow_button);
3003 for (list = priv->content; list != NULL; list = list->next)
3005 ToolbarContent *content = list->data;
3007 toolbar_content_free (content);
3010 g_list_free (priv->content);
3011 g_list_free (toolbar->children);
3013 g_timer_destroy (priv->timer);
3016 gtk_widget_destroy (GTK_WIDGET (priv->menu));
3019 g_source_remove (priv->idle_id);
3021 G_OBJECT_CLASS (gtk_toolbar_parent_class)->finalize (object);
3025 * gtk_toolbar_set_icon_size:
3026 * @toolbar: A #GtkToolbar
3027 * @icon_size: (type int): The #GtkIconSize that stock icons in the
3028 * toolbar shall have.
3030 * This function sets the size of stock icons in the toolbar. You
3031 * can call it both before you add the icons and after they've been
3032 * added. The size you set will override user preferences for the default
3035 * This should only be used for special-purpose toolbars, normal
3036 * application toolbars should respect the user preferences for the
3040 gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
3041 GtkIconSize icon_size)
3043 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3044 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
3046 if (!toolbar->icon_size_set)
3048 toolbar->icon_size_set = TRUE;
3049 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3052 if (toolbar->icon_size == icon_size)
3055 toolbar->icon_size = icon_size;
3056 g_object_notify (G_OBJECT (toolbar), "icon-size");
3058 gtk_toolbar_reconfigured (toolbar);
3060 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3064 * gtk_toolbar_unset_icon_size:
3065 * @toolbar: a #GtkToolbar
3067 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that
3068 * user preferences will be used to determine the icon size.
3071 gtk_toolbar_unset_icon_size (GtkToolbar *toolbar)
3075 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3077 if (toolbar->icon_size_set)
3079 GtkSettings *settings = toolbar_get_settings (toolbar);
3083 g_object_get (settings,
3084 "gtk-toolbar-icon-size", &size,
3088 size = DEFAULT_ICON_SIZE;
3090 if (size != toolbar->icon_size)
3092 gtk_toolbar_set_icon_size (toolbar, size);
3093 g_object_notify (G_OBJECT (toolbar), "icon-size");
3096 toolbar->icon_size_set = FALSE;
3097 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3102 * ToolbarContent methods
3110 struct _ToolbarContent
3115 GtkAllocation start_allocation;
3116 GtkAllocation goal_allocation;
3117 guint is_placeholder : 1;
3118 guint disappearing : 1;
3122 static ToolbarContent *
3123 toolbar_content_new_tool_item (GtkToolbar *toolbar,
3125 gboolean is_placeholder,
3128 ToolbarContent *content;
3129 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3131 content = g_slice_new0 (ToolbarContent);
3133 content->state = NOT_ALLOCATED;
3134 content->item = item;
3135 content->is_placeholder = is_placeholder;
3137 gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
3139 priv->content = g_list_insert (priv->content, content, pos);
3141 if (!is_placeholder)
3143 toolbar->num_children++;
3145 gtk_toolbar_stop_sliding (toolbar);
3148 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3149 priv->need_rebuild = TRUE;
3155 toolbar_content_remove (ToolbarContent *content,
3156 GtkToolbar *toolbar)
3158 GtkToolbarPrivate *priv;
3160 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3162 gtk_widget_unparent (GTK_WIDGET (content->item));
3164 priv->content = g_list_remove (priv->content, content);
3166 if (!toolbar_content_is_placeholder (content))
3167 toolbar->num_children--;
3169 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3170 priv->need_rebuild = TRUE;
3174 toolbar_content_free (ToolbarContent *content)
3176 g_slice_free (ToolbarContent, content);
3180 calculate_max_homogeneous_pixels (GtkWidget *widget)
3182 PangoContext *context;
3183 PangoFontMetrics *metrics;
3186 context = gtk_widget_get_pango_context (widget);
3187 metrics = pango_context_get_metrics (context,
3188 widget->style->font_desc,
3189 pango_context_get_language (context));
3190 char_width = pango_font_metrics_get_approximate_char_width (metrics);
3191 pango_font_metrics_unref (metrics);
3193 return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
3197 toolbar_content_expose (ToolbarContent *content,
3198 GtkContainer *container,
3199 GdkEventExpose *expose)
3203 if (!content->is_placeholder)
3204 widget = GTK_WIDGET (content->item);
3207 gtk_container_propagate_expose (container, widget, expose);
3211 toolbar_content_visible (ToolbarContent *content,
3212 GtkToolbar *toolbar)
3216 item = content->item;
3218 if (!gtk_widget_get_visible (GTK_WIDGET (item)))
3221 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL &&
3222 gtk_tool_item_get_visible_horizontal (item))
3225 if (toolbar->orientation == GTK_ORIENTATION_VERTICAL &&
3226 gtk_tool_item_get_visible_vertical (item))
3233 toolbar_content_size_request (ToolbarContent *content,
3234 GtkToolbar *toolbar,
3235 GtkRequisition *requisition)
3237 gtk_widget_size_request (GTK_WIDGET (content->item),
3239 if (content->is_placeholder &&
3240 content->disappearing)
3242 requisition->width = 0;
3243 requisition->height = 0;
3248 toolbar_content_is_homogeneous (ToolbarContent *content,
3249 GtkToolbar *toolbar)
3251 GtkRequisition requisition;
3252 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3255 if (priv->max_homogeneous_pixels < 0)
3257 priv->max_homogeneous_pixels =
3258 calculate_max_homogeneous_pixels (GTK_WIDGET (toolbar));
3261 toolbar_content_size_request (content, toolbar, &requisition);
3263 if (requisition.width > priv->max_homogeneous_pixels)
3266 result = gtk_tool_item_get_homogeneous (content->item) &&
3267 !GTK_IS_SEPARATOR_TOOL_ITEM (content->item);
3269 if (gtk_tool_item_get_is_important (content->item) &&
3270 toolbar->style == GTK_TOOLBAR_BOTH_HORIZ &&
3271 toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
3280 toolbar_content_is_placeholder (ToolbarContent *content)
3282 if (content->is_placeholder)
3289 toolbar_content_disappearing (ToolbarContent *content)
3291 if (content->disappearing)
3298 toolbar_content_get_state (ToolbarContent *content)
3300 return content->state;
3304 toolbar_content_child_visible (ToolbarContent *content)
3306 return GTK_WIDGET_CHILD_VISIBLE (content->item);
3310 toolbar_content_get_goal_allocation (ToolbarContent *content,
3311 GtkAllocation *allocation)
3313 *allocation = content->goal_allocation;
3317 toolbar_content_get_allocation (ToolbarContent *content,
3318 GtkAllocation *allocation)
3320 gtk_widget_get_allocation (GTK_WIDGET (content->item), allocation);
3324 toolbar_content_set_start_allocation (ToolbarContent *content,
3325 GtkAllocation *allocation)
3327 content->start_allocation = *allocation;
3331 toolbar_content_get_expand (ToolbarContent *content)
3333 if (!content->disappearing &&
3334 gtk_tool_item_get_expand (content->item))
3341 toolbar_content_set_goal_allocation (ToolbarContent *content,
3342 GtkAllocation *allocation)
3344 content->goal_allocation = *allocation;
3348 toolbar_content_set_child_visible (ToolbarContent *content,
3349 GtkToolbar *toolbar,
3352 gtk_widget_set_child_visible (GTK_WIDGET (content->item),
3357 toolbar_content_get_start_allocation (ToolbarContent *content,
3358 GtkAllocation *start_allocation)
3360 *start_allocation = content->start_allocation;
3364 toolbar_content_size_allocate (ToolbarContent *content,
3365 GtkAllocation *allocation)
3367 gtk_widget_size_allocate (GTK_WIDGET (content->item),
3372 toolbar_content_set_state (ToolbarContent *content,
3375 content->state = state;
3379 toolbar_content_get_widget (ToolbarContent *content)
3381 return GTK_WIDGET (content->item);
3386 toolbar_content_set_disappearing (ToolbarContent *content,
3387 gboolean disappearing)
3389 content->disappearing = disappearing;
3393 toolbar_content_set_size_request (ToolbarContent *content,
3397 gtk_widget_set_size_request (GTK_WIDGET (content->item),
3402 toolbar_content_toolbar_reconfigured (ToolbarContent *content,
3403 GtkToolbar *toolbar)
3405 gtk_tool_item_toolbar_reconfigured (content->item);
3409 toolbar_content_retrieve_menu_item (ToolbarContent *content)
3411 return gtk_tool_item_retrieve_proxy_menu_item (content->item);
3415 toolbar_content_has_proxy_menu_item (ToolbarContent *content)
3417 GtkWidget *menu_item;
3419 if (content->has_menu == YES)
3421 else if (content->has_menu == NO)
3424 menu_item = toolbar_content_retrieve_menu_item (content);
3426 content->has_menu = menu_item? YES : NO;
3428 return menu_item != NULL;
3432 toolbar_content_set_unknown_menu_status (ToolbarContent *content)
3434 content->has_menu = UNKNOWN;
3438 toolbar_content_is_separator (ToolbarContent *content)
3440 return GTK_IS_SEPARATOR_TOOL_ITEM (content->item);
3444 toolbar_content_set_expand (ToolbarContent *content,
3447 gtk_tool_item_set_expand (content->item, expand);
3451 toolbar_content_show_all (ToolbarContent *content)
3455 widget = toolbar_content_get_widget (content);
3457 gtk_widget_show_all (widget);
3461 toolbar_content_hide_all (ToolbarContent *content)
3465 widget = toolbar_content_get_widget (content);
3467 gtk_widget_hide_all (widget);
3473 static GtkReliefStyle
3474 get_button_relief (GtkToolbar *toolbar)
3476 GtkReliefStyle button_relief = GTK_RELIEF_NORMAL;
3478 gtk_widget_ensure_style (GTK_WIDGET (toolbar));
3480 gtk_widget_style_get (GTK_WIDGET (toolbar),
3481 "button-relief", &button_relief,
3484 return button_relief;
3488 get_internal_padding (GtkToolbar *toolbar)
3492 gtk_widget_style_get (GTK_WIDGET (toolbar),
3493 "internal-padding", &ipadding,
3500 get_max_child_expand (GtkToolbar *toolbar)
3502 gint mexpand = G_MAXINT;
3504 gtk_widget_style_get (GTK_WIDGET (toolbar),
3505 "max-child-expand", &mexpand,
3510 static GtkShadowType
3511 get_shadow_type (GtkToolbar *toolbar)
3513 GtkShadowType shadow_type;
3515 gtk_widget_style_get (GTK_WIDGET (toolbar),
3516 "shadow-type", &shadow_type,
3522 /* GTK+ internal methods */
3525 _gtk_toolbar_get_default_space_size (void)
3527 return DEFAULT_SPACE_SIZE;
3531 _gtk_toolbar_paint_space_line (GtkWidget *widget,
3532 GtkToolbar *toolbar,
3533 const GdkRectangle *area,
3534 const GtkAllocation *allocation)
3536 const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
3537 const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
3539 GtkOrientation orientation;
3541 g_return_if_fail (GTK_IS_WIDGET (widget));
3543 orientation = toolbar? toolbar->orientation : GTK_ORIENTATION_HORIZONTAL;
3545 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3547 gboolean wide_separators;
3548 gint separator_width;
3550 gtk_widget_style_get (widget,
3551 "wide-separators", &wide_separators,
3552 "separator-width", &separator_width,
3555 if (wide_separators)
3556 gtk_paint_box (widget->style, widget->window,
3557 gtk_widget_get_state (widget), GTK_SHADOW_ETCHED_OUT,
3558 area, widget, "vseparator",
3559 allocation->x + (allocation->width - separator_width) / 2,
3560 allocation->y + allocation->height * start_fraction,
3562 allocation->height * (end_fraction - start_fraction));
3564 gtk_paint_vline (widget->style, widget->window,
3565 gtk_widget_get_state (widget), area, widget,
3567 allocation->y + allocation->height * start_fraction,
3568 allocation->y + allocation->height * end_fraction,
3569 allocation->x + (allocation->width - widget->style->xthickness) / 2);
3573 gboolean wide_separators;
3574 gint separator_height;
3576 gtk_widget_style_get (widget,
3577 "wide-separators", &wide_separators,
3578 "separator-height", &separator_height,
3581 if (wide_separators)
3582 gtk_paint_box (widget->style, widget->window,
3583 gtk_widget_get_state (widget), GTK_SHADOW_ETCHED_OUT,
3584 area, widget, "hseparator",
3585 allocation->x + allocation->width * start_fraction,
3586 allocation->y + (allocation->height - separator_height) / 2,
3587 allocation->width * (end_fraction - start_fraction),
3590 gtk_paint_hline (widget->style, widget->window,
3591 gtk_widget_get_state (widget), area, widget,
3593 allocation->x + allocation->width * start_fraction,
3594 allocation->x + allocation->width * end_fraction,
3595 allocation->y + (allocation->height - widget->style->ythickness) / 2);
3600 _gtk_toolbar_elide_underscores (const gchar *original)
3603 const gchar *p, *end;
3605 gboolean last_underscore;
3610 len = strlen (original);
3611 q = result = g_malloc (len + 1);
3612 last_underscore = FALSE;
3614 end = original + len;
3615 for (p = original; p < end; p++)
3617 if (!last_underscore && *p == '_')
3618 last_underscore = TRUE;
3621 last_underscore = FALSE;
3622 if (original + 2 <= p && p + 1 <= end &&
3623 p[-2] == '(' && p[-1] == '_' && p[0] != '_' && p[1] == ')')
3634 if (last_underscore)
3643 toolbar_get_icon_size (GtkToolShell *shell)
3645 return GTK_TOOLBAR (shell)->icon_size;
3648 static GtkOrientation
3649 toolbar_get_orientation (GtkToolShell *shell)
3651 return GTK_TOOLBAR (shell)->orientation;
3654 static GtkToolbarStyle
3655 toolbar_get_style (GtkToolShell *shell)
3657 return GTK_TOOLBAR (shell)->style;
3660 static GtkReliefStyle
3661 toolbar_get_relief_style (GtkToolShell *shell)
3663 return get_button_relief (GTK_TOOLBAR (shell));
3667 toolbar_rebuild_menu (GtkToolShell *shell)
3669 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (shell);
3672 priv->need_rebuild = TRUE;
3674 for (list = priv->content; list != NULL; list = list->next)
3676 ToolbarContent *content = list->data;
3678 toolbar_content_set_unknown_menu_status (content);
3681 gtk_widget_queue_resize (GTK_WIDGET (shell));