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 "gtksizerequest.h"
57 #include "gtktoolshell.h"
59 #include "gtkprivate.h"
63 typedef struct _ToolbarContent ToolbarContent;
65 #define DEFAULT_IPADDING 0
67 #define DEFAULT_SPACE_SIZE 12
68 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
69 #define SPACE_LINE_DIVISION 10.0
70 #define SPACE_LINE_START 2.0
71 #define SPACE_LINE_END 8.0
73 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
74 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
75 #define DEFAULT_ANIMATION_STATE TRUE
77 #define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
78 * in the homogeneous game. In units of
79 * pango_font_get_estimated_char_width().
81 #define SLIDE_SPEED 600.0 /* How fast the items slide, in pixels per second */
82 #define ACCEL_THRESHOLD 0.18 /* After how much time in seconds will items start speeding up */
85 struct _GtkToolbarPrivate
87 GtkIconSize icon_size;
89 GtkOrientation orientation;
90 GtkSettings *settings;
91 GtkToolbarStyle style;
92 GtkToolItem *highlight_tool_item;
94 GtkWidget *arrow_button;
96 GdkWindow *event_window;
104 gint button_maxw; /* maximum width of homogeneous children */
105 gint button_maxh; /* maximum height of homogeneous children */
106 gint max_homogeneous_pixels;
109 gulong settings_connection;
112 guint icon_size_set : 1;
113 guint is_sliding : 1;
114 guint need_rebuild : 1; /* whether the overflow menu should be regenerated */
116 guint show_arrow : 1;
131 /* Child properties */
135 CHILD_PROP_HOMOGENEOUS
155 static void gtk_toolbar_set_property (GObject *object,
159 static void gtk_toolbar_get_property (GObject *object,
163 static gint gtk_toolbar_draw (GtkWidget *widget,
165 static void gtk_toolbar_realize (GtkWidget *widget);
166 static void gtk_toolbar_unrealize (GtkWidget *widget);
167 static void gtk_toolbar_size_request (GtkWidget *widget,
168 GtkRequisition *requisition);
169 static void gtk_toolbar_size_allocate (GtkWidget *widget,
170 GtkAllocation *allocation);
171 static void gtk_toolbar_style_set (GtkWidget *widget,
172 GtkStyle *prev_style);
173 static gboolean gtk_toolbar_focus (GtkWidget *widget,
174 GtkDirectionType dir);
175 static void gtk_toolbar_move_focus (GtkWidget *widget,
176 GtkDirectionType dir);
177 static void gtk_toolbar_screen_changed (GtkWidget *widget,
178 GdkScreen *previous_screen);
179 static void gtk_toolbar_map (GtkWidget *widget);
180 static void gtk_toolbar_unmap (GtkWidget *widget);
181 static void gtk_toolbar_set_child_property (GtkContainer *container,
186 static void gtk_toolbar_get_child_property (GtkContainer *container,
191 static void gtk_toolbar_finalize (GObject *object);
192 static void gtk_toolbar_show_all (GtkWidget *widget);
193 static void gtk_toolbar_hide_all (GtkWidget *widget);
194 static void gtk_toolbar_add (GtkContainer *container,
196 static void gtk_toolbar_remove (GtkContainer *container,
198 static void gtk_toolbar_forall (GtkContainer *container,
199 gboolean include_internals,
200 GtkCallback callback,
201 gpointer callback_data);
202 static GType gtk_toolbar_child_type (GtkContainer *container);
203 static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
204 GtkOrientation orientation);
205 static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
206 GtkToolbarStyle style);
207 static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
208 gboolean focus_home);
209 static gboolean gtk_toolbar_button_press (GtkWidget *toolbar,
210 GdkEventButton *event);
211 static gboolean gtk_toolbar_arrow_button_press (GtkWidget *button,
212 GdkEventButton *event,
213 GtkToolbar *toolbar);
214 static void gtk_toolbar_arrow_button_clicked (GtkWidget *button,
215 GtkToolbar *toolbar);
216 static void gtk_toolbar_update_button_relief (GtkToolbar *toolbar);
217 static gboolean gtk_toolbar_popup_menu (GtkWidget *toolbar);
218 static void gtk_toolbar_reconfigured (GtkToolbar *toolbar);
220 static GtkReliefStyle get_button_relief (GtkToolbar *toolbar);
221 static gint get_internal_padding (GtkToolbar *toolbar);
222 static gint get_max_child_expand (GtkToolbar *toolbar);
223 static GtkShadowType get_shadow_type (GtkToolbar *toolbar);
225 /* methods on ToolbarContent 'class' */
226 static ToolbarContent *toolbar_content_new_tool_item (GtkToolbar *toolbar,
228 gboolean is_placeholder,
230 static void toolbar_content_remove (ToolbarContent *content,
231 GtkToolbar *toolbar);
232 static void toolbar_content_free (ToolbarContent *content);
233 static void toolbar_content_draw (ToolbarContent *content,
234 GtkContainer *container,
236 static gboolean toolbar_content_visible (ToolbarContent *content,
237 GtkToolbar *toolbar);
238 static void toolbar_content_size_request (ToolbarContent *content,
240 GtkRequisition *requisition);
241 static gboolean toolbar_content_is_homogeneous (ToolbarContent *content,
242 GtkToolbar *toolbar);
243 static gboolean toolbar_content_is_placeholder (ToolbarContent *content);
244 static gboolean toolbar_content_disappearing (ToolbarContent *content);
245 static ItemState toolbar_content_get_state (ToolbarContent *content);
246 static gboolean toolbar_content_child_visible (ToolbarContent *content);
247 static void toolbar_content_get_goal_allocation (ToolbarContent *content,
248 GtkAllocation *allocation);
249 static void toolbar_content_get_allocation (ToolbarContent *content,
250 GtkAllocation *allocation);
251 static void toolbar_content_set_start_allocation (ToolbarContent *content,
252 GtkAllocation *new_start_allocation);
253 static void toolbar_content_get_start_allocation (ToolbarContent *content,
254 GtkAllocation *start_allocation);
255 static gboolean toolbar_content_get_expand (ToolbarContent *content);
256 static void toolbar_content_set_goal_allocation (ToolbarContent *content,
257 GtkAllocation *allocation);
258 static void toolbar_content_set_child_visible (ToolbarContent *content,
261 static void toolbar_content_size_allocate (ToolbarContent *content,
262 GtkAllocation *allocation);
263 static void toolbar_content_set_state (ToolbarContent *content,
264 ItemState new_state);
265 static GtkWidget * toolbar_content_get_widget (ToolbarContent *content);
266 static void toolbar_content_set_disappearing (ToolbarContent *content,
267 gboolean disappearing);
268 static void toolbar_content_set_size_request (ToolbarContent *content,
271 static void toolbar_content_toolbar_reconfigured (ToolbarContent *content,
272 GtkToolbar *toolbar);
273 static GtkWidget * toolbar_content_retrieve_menu_item (ToolbarContent *content);
274 static gboolean toolbar_content_has_proxy_menu_item (ToolbarContent *content);
275 static gboolean toolbar_content_is_separator (ToolbarContent *content);
276 static void toolbar_content_show_all (ToolbarContent *content);
277 static void toolbar_content_hide_all (ToolbarContent *content);
278 static void toolbar_content_set_expand (ToolbarContent *content,
281 static void toolbar_tool_shell_iface_init (GtkToolShellIface *iface);
282 static GtkIconSize toolbar_get_icon_size (GtkToolShell *shell);
283 static GtkOrientation toolbar_get_orientation (GtkToolShell *shell);
284 static GtkToolbarStyle toolbar_get_style (GtkToolShell *shell);
285 static GtkReliefStyle toolbar_get_relief_style (GtkToolShell *shell);
286 static void toolbar_rebuild_menu (GtkToolShell *shell);
289 G_DEFINE_TYPE_WITH_CODE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER,
290 G_IMPLEMENT_INTERFACE (GTK_TYPE_TOOL_SHELL,
291 toolbar_tool_shell_iface_init)
292 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
295 static guint toolbar_signals[LAST_SIGNAL] = { 0 };
299 add_arrow_bindings (GtkBindingSet *binding_set,
301 GtkDirectionType dir)
303 guint keypad_keysym = keysym - GDK_KEY_Left + GDK_KEY_KP_Left;
305 gtk_binding_entry_add_signal (binding_set, keysym, 0,
307 GTK_TYPE_DIRECTION_TYPE, dir);
308 gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
310 GTK_TYPE_DIRECTION_TYPE, dir);
314 add_ctrl_tab_bindings (GtkBindingSet *binding_set,
315 GdkModifierType modifiers,
316 GtkDirectionType direction)
318 gtk_binding_entry_add_signal (binding_set,
319 GDK_KEY_Tab, GDK_CONTROL_MASK | modifiers,
321 GTK_TYPE_DIRECTION_TYPE, direction);
322 gtk_binding_entry_add_signal (binding_set,
323 GDK_KEY_KP_Tab, GDK_CONTROL_MASK | modifiers,
325 GTK_TYPE_DIRECTION_TYPE, direction);
329 gtk_toolbar_class_init (GtkToolbarClass *klass)
331 GObjectClass *gobject_class;
332 GtkWidgetClass *widget_class;
333 GtkContainerClass *container_class;
334 GtkBindingSet *binding_set;
336 gobject_class = (GObjectClass *)klass;
337 widget_class = (GtkWidgetClass *)klass;
338 container_class = (GtkContainerClass *)klass;
340 gobject_class->set_property = gtk_toolbar_set_property;
341 gobject_class->get_property = gtk_toolbar_get_property;
342 gobject_class->finalize = gtk_toolbar_finalize;
344 widget_class->button_press_event = gtk_toolbar_button_press;
345 widget_class->draw = gtk_toolbar_draw;
346 widget_class->size_request = gtk_toolbar_size_request;
347 widget_class->size_allocate = gtk_toolbar_size_allocate;
348 widget_class->style_set = gtk_toolbar_style_set;
349 widget_class->focus = gtk_toolbar_focus;
351 /* need to override the base class function via override_class_handler,
352 * because the signal slot is not available in GtkWidgetClass
354 g_signal_override_class_handler ("move-focus",
356 G_CALLBACK (gtk_toolbar_move_focus));
358 widget_class->screen_changed = gtk_toolbar_screen_changed;
359 widget_class->realize = gtk_toolbar_realize;
360 widget_class->unrealize = gtk_toolbar_unrealize;
361 widget_class->map = gtk_toolbar_map;
362 widget_class->unmap = gtk_toolbar_unmap;
363 widget_class->popup_menu = gtk_toolbar_popup_menu;
364 widget_class->show_all = gtk_toolbar_show_all;
365 widget_class->hide_all = gtk_toolbar_hide_all;
367 container_class->add = gtk_toolbar_add;
368 container_class->remove = gtk_toolbar_remove;
369 container_class->forall = gtk_toolbar_forall;
370 container_class->child_type = gtk_toolbar_child_type;
371 container_class->get_child_property = gtk_toolbar_get_child_property;
372 container_class->set_child_property = gtk_toolbar_set_child_property;
374 klass->orientation_changed = gtk_toolbar_orientation_changed;
375 klass->style_changed = gtk_toolbar_real_style_changed;
378 * GtkToolbar::orientation-changed:
379 * @toolbar: the object which emitted the signal
380 * @orientation: the new #GtkOrientation of the toolbar
382 * Emitted when the orientation of the toolbar changes.
384 toolbar_signals[ORIENTATION_CHANGED] =
385 g_signal_new (I_("orientation-changed"),
386 G_OBJECT_CLASS_TYPE (klass),
388 G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
390 g_cclosure_marshal_VOID__ENUM,
392 GTK_TYPE_ORIENTATION);
394 * GtkToolbar::style-changed:
395 * @toolbar: The #GtkToolbar which emitted the signal
396 * @style: the new #GtkToolbarStyle of the toolbar
398 * Emitted when the style of the toolbar changes.
400 toolbar_signals[STYLE_CHANGED] =
401 g_signal_new (I_("style-changed"),
402 G_OBJECT_CLASS_TYPE (klass),
404 G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
406 g_cclosure_marshal_VOID__ENUM,
408 GTK_TYPE_TOOLBAR_STYLE);
410 * GtkToolbar::popup-context-menu:
411 * @toolbar: the #GtkToolbar which emitted the signal
412 * @x: the x coordinate of the point where the menu should appear
413 * @y: the y coordinate of the point where the menu should appear
414 * @button: the mouse button the user pressed, or -1
416 * Emitted when the user right-clicks the toolbar or uses the
417 * keybinding to display a popup menu.
419 * Application developers should handle this signal if they want
420 * to display a context menu on the toolbar. The context-menu should
421 * appear at the coordinates given by @x and @y. The mouse button
422 * number is given by the @button parameter. If the menu was popped
423 * up using the keybaord, @button is -1.
425 * Return value: return %TRUE if the signal was handled, %FALSE if not
427 toolbar_signals[POPUP_CONTEXT_MENU] =
428 g_signal_new (I_("popup-context-menu"),
429 G_OBJECT_CLASS_TYPE (klass),
431 G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
432 _gtk_boolean_handled_accumulator, NULL,
433 _gtk_marshal_BOOLEAN__INT_INT_INT,
435 G_TYPE_INT, G_TYPE_INT,
439 * GtkToolbar::focus-home-or-end:
440 * @toolbar: the #GtkToolbar which emitted the signal
441 * @focus_home: %TRUE if the first item should be focused
443 * A keybinding signal used internally by GTK+. This signal can't
444 * be used in application code
446 * Return value: %TRUE if the signal was handled, %FALSE if not
448 toolbar_signals[FOCUS_HOME_OR_END] =
449 g_signal_new_class_handler (I_("focus-home-or-end"),
450 G_OBJECT_CLASS_TYPE (klass),
451 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
452 G_CALLBACK (gtk_toolbar_focus_home_or_end),
454 _gtk_marshal_BOOLEAN__BOOLEAN,
459 g_object_class_override_property (gobject_class,
463 g_object_class_install_property (gobject_class,
465 g_param_spec_enum ("toolbar-style",
467 P_("How to draw the toolbar"),
468 GTK_TYPE_TOOLBAR_STYLE,
469 DEFAULT_TOOLBAR_STYLE,
470 GTK_PARAM_READWRITE));
471 g_object_class_install_property (gobject_class,
473 g_param_spec_boolean ("show-arrow",
475 P_("If an arrow should be shown if the toolbar doesn't fit"),
477 GTK_PARAM_READWRITE));
480 * GtkToolbar:icon-size:
482 * The size of the icons in a toolbar is normally determined by
483 * the toolbar-icon-size setting. When this property is set, it
484 * overrides the setting.
486 * This should only be used for special-purpose toolbars, normal
487 * application toolbars should respect the user preferences for the
492 g_object_class_install_property (gobject_class,
494 g_param_spec_int ("icon-size",
496 P_("Size of icons in this toolbar"),
499 GTK_PARAM_READWRITE));
502 * GtkToolbar:icon-size-set:
504 * Is %TRUE if the icon-size property has been set.
508 g_object_class_install_property (gobject_class,
510 g_param_spec_boolean ("icon-size-set",
512 P_("Whether the icon-size property has been set"),
514 GTK_PARAM_READWRITE));
516 /* child properties */
517 gtk_container_class_install_child_property (container_class,
519 g_param_spec_boolean ("expand",
521 P_("Whether the item should receive extra space when the toolbar grows"),
523 GTK_PARAM_READWRITE));
525 gtk_container_class_install_child_property (container_class,
526 CHILD_PROP_HOMOGENEOUS,
527 g_param_spec_boolean ("homogeneous",
529 P_("Whether the item should be the same size as other homogeneous items"),
531 GTK_PARAM_READWRITE));
533 /* style properties */
534 gtk_widget_class_install_style_property (widget_class,
535 g_param_spec_int ("space-size",
537 P_("Size of spacers"),
541 GTK_PARAM_READABLE));
543 gtk_widget_class_install_style_property (widget_class,
544 g_param_spec_int ("internal-padding",
545 P_("Internal padding"),
546 P_("Amount of border space between the toolbar shadow and the buttons"),
550 GTK_PARAM_READABLE));
552 gtk_widget_class_install_style_property (widget_class,
553 g_param_spec_int ("max-child-expand",
554 P_("Maximum child expand"),
555 P_("Maximum amount of space an expandable item will be given"),
559 GTK_PARAM_READABLE));
561 gtk_widget_class_install_style_property (widget_class,
562 g_param_spec_enum ("space-style",
564 P_("Whether spacers are vertical lines or just blank"),
565 GTK_TYPE_TOOLBAR_SPACE_STYLE,
567 GTK_PARAM_READABLE));
569 gtk_widget_class_install_style_property (widget_class,
570 g_param_spec_enum ("button-relief",
572 P_("Type of bevel around toolbar buttons"),
573 GTK_TYPE_RELIEF_STYLE,
575 GTK_PARAM_READABLE));
576 gtk_widget_class_install_style_property (widget_class,
577 g_param_spec_enum ("shadow-type",
579 P_("Style of bevel around the toolbar"),
580 GTK_TYPE_SHADOW_TYPE,
582 GTK_PARAM_READABLE));
584 binding_set = gtk_binding_set_by_class (klass);
586 add_arrow_bindings (binding_set, GDK_KEY_Left, GTK_DIR_LEFT);
587 add_arrow_bindings (binding_set, GDK_KEY_Right, GTK_DIR_RIGHT);
588 add_arrow_bindings (binding_set, GDK_KEY_Up, GTK_DIR_UP);
589 add_arrow_bindings (binding_set, GDK_KEY_Down, GTK_DIR_DOWN);
591 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Home, 0,
592 "focus-home-or-end", 1,
593 G_TYPE_BOOLEAN, TRUE);
594 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Home, 0,
595 "focus-home-or-end", 1,
596 G_TYPE_BOOLEAN, TRUE);
597 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_End, 0,
598 "focus-home-or-end", 1,
599 G_TYPE_BOOLEAN, FALSE);
600 gtk_binding_entry_add_signal (binding_set, GDK_KEY_End, 0,
601 "focus-home-or-end", 1,
602 G_TYPE_BOOLEAN, FALSE);
604 add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
605 add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
607 g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));
611 toolbar_tool_shell_iface_init (GtkToolShellIface *iface)
613 iface->get_icon_size = toolbar_get_icon_size;
614 iface->get_orientation = toolbar_get_orientation;
615 iface->get_style = toolbar_get_style;
616 iface->get_relief_style = toolbar_get_relief_style;
617 iface->rebuild_menu = toolbar_rebuild_menu;
621 gtk_toolbar_init (GtkToolbar *toolbar)
623 GtkToolbarPrivate *priv;
625 toolbar->priv = G_TYPE_INSTANCE_GET_PRIVATE (toolbar,
628 priv = toolbar->priv;
630 gtk_widget_set_can_focus (GTK_WIDGET (toolbar), FALSE);
631 gtk_widget_set_has_window (GTK_WIDGET (toolbar), FALSE);
633 priv->orientation = GTK_ORIENTATION_HORIZONTAL;
634 priv->style = DEFAULT_TOOLBAR_STYLE;
635 priv->icon_size = DEFAULT_ICON_SIZE;
636 priv->animation = DEFAULT_ANIMATION_STATE;
638 priv->arrow_button = gtk_toggle_button_new ();
639 g_signal_connect (priv->arrow_button, "button-press-event",
640 G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar);
641 g_signal_connect (priv->arrow_button, "clicked",
642 G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar);
643 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
644 get_button_relief (toolbar));
646 gtk_button_set_focus_on_click (GTK_BUTTON (priv->arrow_button), FALSE);
648 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
649 gtk_widget_set_name (priv->arrow, "gtk-toolbar-arrow");
650 gtk_widget_show (priv->arrow);
651 gtk_container_add (GTK_CONTAINER (priv->arrow_button), priv->arrow);
653 gtk_widget_set_parent (priv->arrow_button, GTK_WIDGET (toolbar));
655 /* which child position a drop will occur at */
657 priv->show_arrow = TRUE;
658 priv->settings = NULL;
660 priv->max_homogeneous_pixels = -1;
662 priv->timer = g_timer_new ();
666 gtk_toolbar_set_property (GObject *object,
671 GtkToolbar *toolbar = GTK_TOOLBAR (object);
672 GtkToolbarPrivate *priv = toolbar->priv;
676 case PROP_ORIENTATION:
677 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0,
678 g_value_get_enum (value));
680 case PROP_TOOLBAR_STYLE:
681 gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
683 case PROP_SHOW_ARROW:
684 gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
687 gtk_toolbar_set_icon_size (toolbar, g_value_get_int (value));
689 case PROP_ICON_SIZE_SET:
690 if (g_value_get_boolean (value))
691 priv->icon_size_set = TRUE;
693 gtk_toolbar_unset_icon_size (toolbar);
696 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
702 gtk_toolbar_get_property (GObject *object,
707 GtkToolbar *toolbar = GTK_TOOLBAR (object);
708 GtkToolbarPrivate *priv = toolbar->priv;
712 case PROP_ORIENTATION:
713 g_value_set_enum (value, priv->orientation);
715 case PROP_TOOLBAR_STYLE:
716 g_value_set_enum (value, priv->style);
718 case PROP_SHOW_ARROW:
719 g_value_set_boolean (value, priv->show_arrow);
722 g_value_set_int (value, gtk_toolbar_get_icon_size (toolbar));
724 case PROP_ICON_SIZE_SET:
725 g_value_set_boolean (value, priv->icon_size_set);
728 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
734 gtk_toolbar_map (GtkWidget *widget)
736 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
737 GtkToolbarPrivate *priv = toolbar->priv;
739 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->map (widget);
741 if (priv->event_window)
742 gdk_window_show_unraised (priv->event_window);
746 gtk_toolbar_unmap (GtkWidget *widget)
748 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
749 GtkToolbarPrivate *priv = toolbar->priv;
751 if (priv->event_window)
752 gdk_window_hide (priv->event_window);
754 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unmap (widget);
758 gtk_toolbar_realize (GtkWidget *widget)
760 GtkAllocation allocation;
761 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
762 GtkToolbarPrivate *priv = toolbar->priv;
764 GdkWindowAttr attributes;
765 gint attributes_mask;
768 gtk_widget_set_realized (widget, TRUE);
770 gtk_widget_get_allocation (widget, &allocation);
771 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
773 attributes.wclass = GDK_INPUT_ONLY;
774 attributes.window_type = GDK_WINDOW_CHILD;
775 attributes.x = allocation.x + border_width;
776 attributes.y = allocation.y + border_width;
777 attributes.width = allocation.width - border_width * 2;
778 attributes.height = allocation.height - border_width * 2;
779 attributes.event_mask = gtk_widget_get_events (widget);
780 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
781 GDK_BUTTON_RELEASE_MASK |
782 GDK_ENTER_NOTIFY_MASK |
783 GDK_LEAVE_NOTIFY_MASK);
785 attributes_mask = GDK_WA_X | GDK_WA_Y;
787 window = gtk_widget_get_parent_window (widget);
788 gtk_widget_set_window (widget, window);
789 g_object_ref (window);
791 gtk_widget_style_attach (widget);
793 priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
794 &attributes, attributes_mask);
795 gdk_window_set_user_data (priv->event_window, toolbar);
799 gtk_toolbar_unrealize (GtkWidget *widget)
801 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
802 GtkToolbarPrivate *priv = toolbar->priv;
804 if (priv->event_window)
806 gdk_window_set_user_data (priv->event_window, NULL);
807 gdk_window_destroy (priv->event_window);
808 priv->event_window = NULL;
811 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize (widget);
815 gtk_toolbar_draw (GtkWidget *widget,
818 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
819 GtkToolbarPrivate *priv = toolbar->priv;
823 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
825 gtk_cairo_paint_box (gtk_widget_get_style (widget),
827 gtk_widget_get_state (widget),
828 get_shadow_type (toolbar),
832 gtk_widget_get_allocated_width (widget) - 2 * border_width,
833 gtk_widget_get_allocated_height (widget) - 2 * border_width);
835 for (list = priv->content; list != NULL; list = list->next)
837 ToolbarContent *content = list->data;
839 toolbar_content_draw (content, GTK_CONTAINER (widget), cr);
842 gtk_container_propagate_draw (GTK_CONTAINER (widget),
850 gtk_toolbar_size_request (GtkWidget *widget,
851 GtkRequisition *requisition)
853 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
854 GtkToolbarPrivate *priv = toolbar->priv;
856 gint max_child_height;
857 gint max_child_width;
858 gint max_homogeneous_child_width;
859 gint max_homogeneous_child_height;
860 gint homogeneous_size;
862 gint pack_front_size;
865 GtkRequisition arrow_requisition;
867 max_homogeneous_child_width = 0;
868 max_homogeneous_child_height = 0;
870 max_child_height = 0;
871 for (list = priv->content; list != NULL; list = list->next)
873 GtkRequisition requisition;
874 ToolbarContent *content = list->data;
876 if (!toolbar_content_visible (content, toolbar))
879 toolbar_content_size_request (content, toolbar, &requisition);
881 max_child_width = MAX (max_child_width, requisition.width);
882 max_child_height = MAX (max_child_height, requisition.height);
884 if (toolbar_content_is_homogeneous (content, toolbar))
886 max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
887 max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
891 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
892 homogeneous_size = max_homogeneous_child_width;
894 homogeneous_size = max_homogeneous_child_height;
897 for (list = priv->content; list != NULL; list = list->next)
899 ToolbarContent *content = list->data;
902 if (!toolbar_content_visible (content, toolbar))
905 if (toolbar_content_is_homogeneous (content, toolbar))
907 size = homogeneous_size;
911 GtkRequisition requisition;
913 toolbar_content_size_request (content, toolbar, &requisition);
915 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
916 size = requisition.width;
918 size = requisition.height;
921 pack_front_size += size;
924 if (priv->show_arrow)
926 gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->arrow_button),
927 &arrow_requisition, NULL);
929 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
930 long_req = arrow_requisition.width;
932 long_req = arrow_requisition.height;
934 /* There is no point requesting space for the arrow if that would take
935 * up more space than all the items combined
937 long_req = MIN (long_req, pack_front_size);
941 arrow_requisition.height = 0;
942 arrow_requisition.width = 0;
944 long_req = pack_front_size;
947 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
949 requisition->width = long_req;
950 requisition->height = MAX (max_child_height, arrow_requisition.height);
954 requisition->height = long_req;
955 requisition->width = MAX (max_child_width, arrow_requisition.width);
959 ipadding = get_internal_padding (toolbar);
961 border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
962 requisition->width += 2 * (ipadding + border_width);
963 requisition->height += 2 * (ipadding + border_width);
965 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
969 style = gtk_widget_get_style (widget);
970 requisition->width += 2 * style->xthickness;
971 requisition->height += 2 * style->ythickness;
974 priv->button_maxw = max_homogeneous_child_width;
975 priv->button_maxh = max_homogeneous_child_height;
979 position (GtkToolbar *toolbar,
984 GtkToolbarPrivate *priv = toolbar->priv;
987 if (!priv->animation)
990 if (elapsed <= ACCEL_THRESHOLD)
992 n_pixels = SLIDE_SPEED * elapsed;
996 /* The formula is a second degree polynomial in
997 * @elapsed that has the line SLIDE_SPEED * @elapsed
998 * as tangent for @elapsed == ACCEL_THRESHOLD.
999 * This makes @n_pixels a smooth function of elapsed time.
1001 n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
1002 SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
1006 return MIN (from + n_pixels, to);
1008 return MAX (from - n_pixels, to);
1012 compute_intermediate_allocation (GtkToolbar *toolbar,
1013 const GtkAllocation *start,
1014 const GtkAllocation *goal,
1015 GtkAllocation *intermediate)
1017 GtkToolbarPrivate *priv = toolbar->priv;
1018 gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
1020 intermediate->x = position (toolbar, start->x, goal->x, elapsed);
1021 intermediate->y = position (toolbar, start->y, goal->y, elapsed);
1022 intermediate->width = position (toolbar, start->x + start->width,
1023 goal->x + goal->width,
1024 elapsed) - intermediate->x;
1025 intermediate->height = position (toolbar, start->y + start->height,
1026 goal->y + goal->height,
1027 elapsed) - intermediate->y;
1031 fixup_allocation_for_rtl (gint total_size,
1032 GtkAllocation *allocation)
1034 allocation->x += (total_size - (2 * allocation->x + allocation->width));
1038 fixup_allocation_for_vertical (GtkAllocation *allocation)
1042 tmp = allocation->x;
1043 allocation->x = allocation->y;
1044 allocation->y = tmp;
1046 tmp = allocation->width;
1047 allocation->width = allocation->height;
1048 allocation->height = tmp;
1052 get_item_size (GtkToolbar *toolbar,
1053 ToolbarContent *content)
1055 GtkToolbarPrivate *priv = toolbar->priv;
1056 GtkRequisition requisition;
1058 toolbar_content_size_request (content, toolbar, &requisition);
1060 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1062 if (toolbar_content_is_homogeneous (content, toolbar))
1063 return priv->button_maxw;
1065 return requisition.width;
1069 if (toolbar_content_is_homogeneous (content, toolbar))
1070 return priv->button_maxh;
1072 return requisition.height;
1077 slide_idle_handler (gpointer data)
1079 GtkToolbar *toolbar = GTK_TOOLBAR (data);
1080 GtkToolbarPrivate *priv = toolbar->priv;
1083 if (priv->need_sync)
1086 priv->need_sync = FALSE;
1089 for (list = priv->content; list != NULL; list = list->next)
1091 ToolbarContent *content = list->data;
1093 GtkAllocation goal_allocation;
1094 GtkAllocation allocation;
1097 state = toolbar_content_get_state (content);
1098 toolbar_content_get_goal_allocation (content, &goal_allocation);
1099 toolbar_content_get_allocation (content, &allocation);
1103 if (state == NOT_ALLOCATED)
1105 /* an unallocated item means that size allocate has to
1106 * called at least once more
1111 /* An invisible item with a goal allocation of
1112 * 0 is already at its goal.
1114 if ((state == NORMAL || state == OVERFLOWN) &&
1115 ((goal_allocation.width != 0 &&
1116 goal_allocation.height != 0) ||
1117 toolbar_content_child_visible (content)))
1119 if ((goal_allocation.x != allocation.x ||
1120 goal_allocation.y != allocation.y ||
1121 goal_allocation.width != allocation.width ||
1122 goal_allocation.height != allocation.height))
1124 /* An item is not in its right position yet. Note
1125 * that OVERFLOWN items do get an allocation in
1126 * gtk_toolbar_size_allocate(). This way you can see
1127 * them slide back in when you drag an item off the
1134 if (toolbar_content_is_placeholder (content) &&
1135 toolbar_content_disappearing (content) &&
1136 toolbar_content_child_visible (content))
1138 /* A disappearing placeholder is still visible.
1146 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1152 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1154 priv->is_sliding = FALSE;
1161 rect_within (GtkAllocation *a1,
1164 return (a1->x >= a2->x &&
1165 a1->x + a1->width <= a2->x + a2->width &&
1167 a1->y + a1->height <= a2->y + a2->height);
1171 gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
1173 GtkAllocation allocation;
1174 GtkWidget *widget = GTK_WIDGET (toolbar);
1175 GtkToolbarPrivate *priv = toolbar->priv;
1184 /* Start the sliding. This function copies the allocation of every
1185 * item into content->start_allocation. For items that haven't
1186 * been allocated yet, we calculate their position and save that
1187 * in start_allocatino along with zero width and zero height.
1189 * FIXME: It would be nice if we could share this code with
1190 * the equivalent in gtk_widget_size_allocate().
1192 priv->is_sliding = TRUE;
1195 priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
1197 gtk_widget_get_allocation (widget, &allocation);
1198 style = gtk_widget_get_style (widget);
1200 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1201 vertical = (priv->orientation == GTK_ORIENTATION_VERTICAL);
1202 border_width = get_internal_padding (toolbar) + gtk_container_get_border_width (GTK_CONTAINER (toolbar));
1206 cur_x = allocation.width - border_width - style->xthickness;
1207 cur_y = allocation.height - border_width - style->ythickness;
1211 cur_x = border_width + style->xthickness;
1212 cur_y = border_width + style->ythickness;
1215 cur_x += allocation.x;
1216 cur_y += allocation.y;
1218 for (list = priv->content; list != NULL; list = list->next)
1220 ToolbarContent *content = list->data;
1221 GtkAllocation new_start_allocation;
1222 GtkAllocation item_allocation;
1225 state = toolbar_content_get_state (content);
1226 toolbar_content_get_allocation (content, &item_allocation);
1228 if ((state == NORMAL &&
1229 rect_within (&item_allocation, &allocation)) ||
1232 new_start_allocation = item_allocation;
1236 new_start_allocation.x = cur_x;
1237 new_start_allocation.y = cur_y;
1241 new_start_allocation.width = allocation.width -
1242 2 * border_width - 2 * style->xthickness;
1243 new_start_allocation.height = 0;
1247 new_start_allocation.width = 0;
1248 new_start_allocation.height = allocation.height -
1249 2 * border_width - 2 * style->ythickness;
1254 cur_y = new_start_allocation.y + new_start_allocation.height;
1256 cur_x = new_start_allocation.x;
1258 cur_x = new_start_allocation.x + new_start_allocation.width;
1260 toolbar_content_set_start_allocation (content, &new_start_allocation);
1263 /* This resize will run before the first idle handler. This
1264 * will make sure that items get the right goal allocation
1265 * so that the idle handler will not immediately return
1268 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1269 g_timer_reset (priv->timer);
1273 gtk_toolbar_stop_sliding (GtkToolbar *toolbar)
1275 GtkToolbarPrivate *priv = toolbar->priv;
1277 if (priv->is_sliding)
1281 priv->is_sliding = FALSE;
1285 g_source_remove (priv->idle_id);
1289 list = priv->content;
1292 ToolbarContent *content = list->data;
1295 if (toolbar_content_is_placeholder (content))
1297 toolbar_content_remove (content, toolbar);
1298 toolbar_content_free (content);
1302 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1307 remove_item (GtkWidget *menu_item,
1310 gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (menu_item)),
1315 menu_deactivated (GtkWidget *menu,
1316 GtkToolbar *toolbar)
1318 GtkToolbarPrivate *priv = toolbar->priv;
1320 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->arrow_button), FALSE);
1324 menu_detached (GtkWidget *widget,
1327 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1328 GtkToolbarPrivate *priv = toolbar->priv;
1334 rebuild_menu (GtkToolbar *toolbar)
1336 GtkToolbarPrivate *priv = toolbar->priv;
1337 GList *list, *children;
1341 priv->menu = GTK_MENU (gtk_menu_new());
1342 gtk_menu_attach_to_widget (priv->menu,
1343 GTK_WIDGET (toolbar),
1346 g_signal_connect (priv->menu, "deactivate",
1347 G_CALLBACK (menu_deactivated), toolbar);
1350 gtk_container_foreach (GTK_CONTAINER (priv->menu), remove_item, NULL);
1352 for (list = priv->content; list != NULL; list = list->next)
1354 ToolbarContent *content = list->data;
1356 if (toolbar_content_get_state (content) == OVERFLOWN &&
1357 !toolbar_content_is_placeholder (content))
1359 GtkWidget *menu_item = toolbar_content_retrieve_menu_item (content);
1363 g_assert (GTK_IS_MENU_ITEM (menu_item));
1364 gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item);
1369 /* Remove leading and trailing separator items */
1370 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1373 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1375 GtkWidget *child = list->data;
1377 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1380 g_list_free (children);
1382 /* Regenerate the list of children so we don't try to remove items twice */
1383 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1385 list = g_list_last (children);
1386 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1388 GtkWidget *child = list->data;
1390 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1393 g_list_free (children);
1395 priv->need_rebuild = FALSE;
1399 gtk_toolbar_size_allocate (GtkWidget *widget,
1400 GtkAllocation *allocation)
1402 GtkAllocation widget_allocation;
1403 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1404 GtkToolbarPrivate *priv = toolbar->priv;
1405 GtkAllocation *allocations;
1406 ItemState *new_states;
1407 GtkAllocation arrow_allocation;
1410 gint size, pos, short_size;
1413 gboolean need_arrow;
1414 gint n_expand_items;
1416 gint available_size;
1419 GtkRequisition arrow_requisition;
1420 gboolean overflowing;
1421 gboolean size_changed;
1423 GtkAllocation item_area;
1424 GtkShadowType shadow_type;
1426 style = gtk_widget_get_style (widget);
1428 gtk_widget_get_allocation (widget, &widget_allocation);
1429 size_changed = FALSE;
1430 if (widget_allocation.x != allocation->x ||
1431 widget_allocation.y != allocation->y ||
1432 widget_allocation.width != allocation->width ||
1433 widget_allocation.height != allocation->height)
1435 size_changed = TRUE;
1439 gtk_toolbar_stop_sliding (toolbar);
1441 gtk_widget_set_allocation (widget, allocation);
1443 border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
1445 if (gtk_widget_get_realized (widget))
1447 gdk_window_move_resize (priv->event_window,
1448 allocation->x + border_width,
1449 allocation->y + border_width,
1450 allocation->width - border_width * 2,
1451 allocation->height - border_width * 2);
1454 border_width += get_internal_padding (toolbar);
1456 gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->arrow_button),
1457 &arrow_requisition, NULL);
1459 shadow_type = get_shadow_type (toolbar);
1461 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
1463 available_size = size = allocation->width - 2 * border_width;
1464 short_size = allocation->height - 2 * border_width;
1465 arrow_size = arrow_requisition.width;
1467 if (shadow_type != GTK_SHADOW_NONE)
1469 available_size -= 2 * style->xthickness;
1470 short_size -= 2 * style->ythickness;
1475 available_size = size = allocation->height - 2 * border_width;
1476 short_size = allocation->width - 2 * border_width;
1477 arrow_size = arrow_requisition.height;
1479 if (shadow_type != GTK_SHADOW_NONE)
1481 available_size -= 2 * style->ythickness;
1482 short_size -= 2 * style->xthickness;
1486 n_items = g_list_length (priv->content);
1487 allocations = g_new0 (GtkAllocation, n_items);
1488 new_states = g_new0 (ItemState, n_items);
1492 for (list = priv->content; list != NULL; list = list->next)
1494 ToolbarContent *content = list->data;
1496 if (toolbar_content_visible (content, toolbar))
1498 needed_size += get_item_size (toolbar, content);
1500 /* Do we need an arrow?
1502 * Assume we don't, and see if any non-separator item with a
1503 * proxy menu item is then going to overflow.
1505 if (needed_size > available_size &&
1508 toolbar_content_has_proxy_menu_item (content) &&
1509 !toolbar_content_is_separator (content))
1517 size = available_size - arrow_size;
1519 size = available_size;
1521 /* calculate widths and states of items */
1522 overflowing = FALSE;
1523 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1525 ToolbarContent *content = list->data;
1528 if (!toolbar_content_visible (content, toolbar))
1530 new_states[i] = HIDDEN;
1534 item_size = get_item_size (toolbar, content);
1535 if (item_size <= size && !overflowing)
1538 allocations[i].width = item_size;
1539 new_states[i] = NORMAL;
1544 new_states[i] = OVERFLOWN;
1545 allocations[i].width = item_size;
1549 /* calculate width of arrow */
1552 arrow_allocation.width = arrow_size;
1553 arrow_allocation.height = MAX (short_size, 1);
1556 /* expand expandable items */
1558 /* We don't expand when there is an overflow menu, because that leads to
1559 * weird jumps when items get moved to the overflow menu and the expanding
1560 * items suddenly get a lot of extra space
1564 gint max_child_expand;
1567 for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
1569 ToolbarContent *content = list->data;
1571 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1575 max_child_expand = get_max_child_expand (toolbar);
1576 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1578 ToolbarContent *content = list->data;
1580 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1582 gint extra = size / n_expand_items;
1583 if (size % n_expand_items != 0)
1586 if (extra > max_child_expand)
1587 extra = max_child_expand;
1589 allocations[i].width += extra;
1595 g_assert (n_expand_items == 0);
1598 /* position items */
1600 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1602 /* both NORMAL and OVERFLOWN items get a position. This ensures
1603 * that sliding will work for OVERFLOWN items too
1605 if (new_states[i] == NORMAL ||
1606 new_states[i] == OVERFLOWN)
1608 allocations[i].x = pos;
1609 allocations[i].y = border_width;
1610 allocations[i].height = short_size;
1612 pos += allocations[i].width;
1616 /* position arrow */
1619 arrow_allocation.x = available_size - border_width - arrow_allocation.width;
1620 arrow_allocation.y = border_width;
1623 item_area.x = border_width;
1624 item_area.y = border_width;
1625 item_area.width = available_size - (need_arrow? arrow_size : 0);
1626 item_area.height = short_size;
1628 /* fix up allocations in the vertical or RTL cases */
1629 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
1631 for (i = 0; i < n_items; ++i)
1632 fixup_allocation_for_vertical (&(allocations[i]));
1635 fixup_allocation_for_vertical (&arrow_allocation);
1637 fixup_allocation_for_vertical (&item_area);
1639 else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1641 for (i = 0; i < n_items; ++i)
1642 fixup_allocation_for_rtl (available_size, &(allocations[i]));
1645 fixup_allocation_for_rtl (available_size, &arrow_allocation);
1647 fixup_allocation_for_rtl (available_size, &item_area);
1650 /* translate the items by allocation->(x,y) */
1651 for (i = 0; i < n_items; ++i)
1653 allocations[i].x += allocation->x;
1654 allocations[i].y += allocation->y;
1656 if (shadow_type != GTK_SHADOW_NONE)
1658 allocations[i].x += style->xthickness;
1659 allocations[i].y += style->ythickness;
1665 arrow_allocation.x += allocation->x;
1666 arrow_allocation.y += allocation->y;
1668 if (shadow_type != GTK_SHADOW_NONE)
1670 arrow_allocation.x += style->xthickness;
1671 arrow_allocation.y += style->ythickness;
1675 item_area.x += allocation->x;
1676 item_area.y += allocation->y;
1677 if (shadow_type != GTK_SHADOW_NONE)
1679 item_area.x += style->xthickness;
1680 item_area.y += style->ythickness;
1683 /* did anything change? */
1684 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1686 ToolbarContent *content = list->data;
1688 if (toolbar_content_get_state (content) == NORMAL &&
1689 new_states[i] != NORMAL)
1691 /* an item disappeared and we didn't change size, so begin sliding */
1693 gtk_toolbar_begin_sliding (toolbar);
1697 /* finally allocate the items */
1698 if (priv->is_sliding)
1700 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1702 ToolbarContent *content = list->data;
1704 toolbar_content_set_goal_allocation (content, &(allocations[i]));
1708 elapsed = g_timer_elapsed (priv->timer, NULL);
1709 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1711 ToolbarContent *content = list->data;
1713 if (new_states[i] == OVERFLOWN ||
1714 new_states[i] == NORMAL)
1716 GtkAllocation alloc;
1717 GtkAllocation start_allocation = { 0, };
1718 GtkAllocation goal_allocation;
1720 if (priv->is_sliding)
1722 toolbar_content_get_start_allocation (content, &start_allocation);
1723 toolbar_content_get_goal_allocation (content, &goal_allocation);
1725 compute_intermediate_allocation (toolbar,
1730 priv->need_sync = TRUE;
1734 alloc = allocations[i];
1737 if (alloc.width <= 0 || alloc.height <= 0)
1739 toolbar_content_set_child_visible (content, toolbar, FALSE);
1743 if (!rect_within (&alloc, &item_area))
1745 toolbar_content_set_child_visible (content, toolbar, FALSE);
1746 toolbar_content_size_allocate (content, &alloc);
1750 toolbar_content_set_child_visible (content, toolbar, TRUE);
1751 toolbar_content_size_allocate (content, &alloc);
1757 toolbar_content_set_child_visible (content, toolbar, FALSE);
1760 toolbar_content_set_state (content, new_states[i]);
1763 if (priv->menu && priv->need_rebuild)
1764 rebuild_menu (toolbar);
1768 gtk_widget_size_allocate (GTK_WIDGET (priv->arrow_button),
1770 gtk_widget_show (GTK_WIDGET (priv->arrow_button));
1774 gtk_widget_hide (GTK_WIDGET (priv->arrow_button));
1776 if (priv->menu && gtk_widget_get_visible (GTK_WIDGET (priv->menu)))
1777 gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
1780 g_free (allocations);
1781 g_free (new_states);
1785 gtk_toolbar_update_button_relief (GtkToolbar *toolbar)
1787 GtkToolbarPrivate *priv = toolbar->priv;
1788 GtkReliefStyle relief;
1790 relief = get_button_relief (toolbar);
1792 if (relief != gtk_button_get_relief (GTK_BUTTON (priv->arrow_button)))
1794 gtk_toolbar_reconfigured (toolbar);
1796 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), relief);
1801 gtk_toolbar_style_set (GtkWidget *widget,
1802 GtkStyle *prev_style)
1804 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1805 GtkToolbarPrivate *priv = toolbar->priv;
1807 priv->max_homogeneous_pixels = -1;
1809 if (gtk_widget_get_realized (widget))
1810 gtk_style_set_background (gtk_widget_get_style (widget),
1811 gtk_widget_get_window (widget),
1812 gtk_widget_get_state (widget));
1815 gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
1819 gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
1820 GtkDirectionType dir)
1822 GtkToolbarPrivate *priv = toolbar->priv;
1823 GList *result = NULL;
1827 /* generate list of children in reverse logical order */
1829 for (list = priv->content; list != NULL; list = list->next)
1831 ToolbarContent *content = list->data;
1834 widget = toolbar_content_get_widget (content);
1837 result = g_list_prepend (result, widget);
1840 result = g_list_prepend (result, priv->arrow_button);
1842 rtl = (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL);
1844 /* move in logical order when
1846 * - dir is TAB_FORWARD
1848 * - in RTL mode and moving left or up
1850 * - in LTR mode and moving right or down
1852 if (dir == GTK_DIR_TAB_FORWARD ||
1853 (rtl && (dir == GTK_DIR_UP || dir == GTK_DIR_LEFT)) ||
1854 (!rtl && (dir == GTK_DIR_DOWN || dir == GTK_DIR_RIGHT)))
1856 result = g_list_reverse (result);
1863 gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
1864 gboolean focus_home)
1866 GList *children, *list;
1867 GtkDirectionType dir = focus_home? GTK_DIR_RIGHT : GTK_DIR_LEFT;
1869 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1871 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1873 children = g_list_reverse (children);
1875 dir = (dir == GTK_DIR_RIGHT)? GTK_DIR_LEFT : GTK_DIR_RIGHT;
1878 for (list = children; list != NULL; list = list->next)
1880 GtkWidget *child = list->data;
1882 if (gtk_container_get_focus_child (GTK_CONTAINER (toolbar)) == child)
1885 if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1889 g_list_free (children);
1894 /* Keybinding handler. This function is called when the user presses
1895 * Ctrl TAB or an arrow key.
1898 gtk_toolbar_move_focus (GtkWidget *widget,
1899 GtkDirectionType dir)
1901 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1902 GtkContainer *container = GTK_CONTAINER (toolbar);
1903 GtkWidget *focus_child;
1905 gboolean try_focus = FALSE;
1908 focus_child = gtk_container_get_focus_child (container);
1910 if (focus_child && gtk_widget_child_focus (focus_child, dir))
1913 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1915 for (list = children; list != NULL; list = list->next)
1917 GtkWidget *child = list->data;
1919 if (try_focus && gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1922 if (child == focus_child)
1926 g_list_free (children);
1929 /* The focus handler for the toolbar. It called when the user presses
1930 * TAB or otherwise tries to focus the toolbar.
1933 gtk_toolbar_focus (GtkWidget *widget,
1934 GtkDirectionType dir)
1936 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1937 GList *children, *list;
1938 gboolean result = FALSE;
1940 /* if focus is already somewhere inside the toolbar then return FALSE.
1941 * The only way focus can stay inside the toolbar is when the user presses
1942 * arrow keys or Ctrl TAB (both of which are handled by the
1943 * gtk_toolbar_move_focus() keybinding function.
1945 if (gtk_container_get_focus_child (GTK_CONTAINER (widget)))
1948 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1950 for (list = children; list != NULL; list = list->next)
1952 GtkWidget *child = list->data;
1954 if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1961 g_list_free (children);
1966 static GtkSettings *
1967 toolbar_get_settings (GtkToolbar *toolbar)
1969 return toolbar->priv->settings;
1973 style_change_notify (GtkToolbar *toolbar)
1975 GtkToolbarPrivate *priv = toolbar->priv;
1977 if (!priv->style_set)
1979 /* pretend it was set, then unset, thus reverting to new default */
1980 priv->style_set = TRUE;
1981 gtk_toolbar_unset_style (toolbar);
1986 icon_size_change_notify (GtkToolbar *toolbar)
1988 GtkToolbarPrivate *priv = toolbar->priv;
1990 if (!priv->icon_size_set)
1992 /* pretend it was set, then unset, thus reverting to new default */
1993 priv->icon_size_set = TRUE;
1994 gtk_toolbar_unset_icon_size (toolbar);
1999 animation_change_notify (GtkToolbar *toolbar)
2001 GtkToolbarPrivate *priv = toolbar->priv;
2002 GtkSettings *settings = toolbar_get_settings (toolbar);
2006 g_object_get (settings,
2007 "gtk-enable-animations", &animation,
2010 animation = DEFAULT_ANIMATION_STATE;
2012 priv->animation = animation;
2016 settings_change_notify (GtkSettings *settings,
2017 const GParamSpec *pspec,
2018 GtkToolbar *toolbar)
2020 if (! strcmp (pspec->name, "gtk-toolbar-style"))
2021 style_change_notify (toolbar);
2022 else if (! strcmp (pspec->name, "gtk-toolbar-icon-size"))
2023 icon_size_change_notify (toolbar);
2024 else if (! strcmp (pspec->name, "gtk-enable-animations"))
2025 animation_change_notify (toolbar);
2029 gtk_toolbar_screen_changed (GtkWidget *widget,
2030 GdkScreen *previous_screen)
2032 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2033 GtkToolbarPrivate *priv = toolbar->priv;
2034 GtkSettings *old_settings = toolbar_get_settings (toolbar);
2035 GtkSettings *settings;
2037 if (gtk_widget_has_screen (GTK_WIDGET (toolbar)))
2038 settings = gtk_widget_get_settings (GTK_WIDGET (toolbar));
2042 if (settings == old_settings)
2047 g_signal_handler_disconnect (old_settings, priv->settings_connection);
2049 g_object_unref (old_settings);
2054 priv->settings_connection =
2055 g_signal_connect (settings, "notify",
2056 G_CALLBACK (settings_change_notify),
2059 priv->settings = g_object_ref (settings);
2062 priv->settings = NULL;
2064 style_change_notify (toolbar);
2065 icon_size_change_notify (toolbar);
2066 animation_change_notify (toolbar);
2070 find_drop_index (GtkToolbar *toolbar,
2074 GtkToolbarPrivate *priv = toolbar->priv;
2075 GList *interesting_content;
2077 GtkOrientation orientation;
2078 GtkTextDirection direction;
2079 gint best_distance = G_MAXINT;
2083 ToolbarContent *best_content;
2084 GtkAllocation allocation;
2086 /* list items we care about wrt. drag and drop */
2087 interesting_content = NULL;
2088 for (list = priv->content; list != NULL; list = list->next)
2090 ToolbarContent *content = list->data;
2092 if (toolbar_content_get_state (content) == NORMAL)
2093 interesting_content = g_list_prepend (interesting_content, content);
2095 interesting_content = g_list_reverse (interesting_content);
2097 if (!interesting_content)
2100 orientation = priv->orientation;
2101 direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
2103 /* distance to first interesting item */
2104 best_content = interesting_content->data;
2105 toolbar_content_get_allocation (best_content, &allocation);
2107 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2111 if (direction == GTK_TEXT_DIR_LTR)
2114 pos = allocation.x + allocation.width;
2122 best_content = NULL;
2123 best_distance = ABS (pos - cursor);
2125 /* distance to far end of each item */
2126 for (list = interesting_content; list != NULL; list = list->next)
2128 ToolbarContent *content = list->data;
2130 toolbar_content_get_allocation (content, &allocation);
2132 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2134 if (direction == GTK_TEXT_DIR_LTR)
2135 pos = allocation.x + allocation.width;
2141 pos = allocation.y + allocation.height;
2144 distance = ABS (pos - cursor);
2146 if (distance < best_distance)
2148 best_distance = distance;
2149 best_content = content;
2153 g_list_free (interesting_content);
2158 return g_list_index (priv->content, best_content) + 1;
2162 reset_all_placeholders (GtkToolbar *toolbar)
2164 GtkToolbarPrivate *priv = toolbar->priv;
2167 for (list = priv->content; list != NULL; list = list->next)
2169 ToolbarContent *content = list->data;
2170 if (toolbar_content_is_placeholder (content))
2171 toolbar_content_set_disappearing (content, TRUE);
2176 physical_to_logical (GtkToolbar *toolbar,
2179 GtkToolbarPrivate *priv = toolbar->priv;
2183 g_assert (physical >= 0);
2186 for (list = priv->content; list && physical > 0; list = list->next)
2188 ToolbarContent *content = list->data;
2190 if (!toolbar_content_is_placeholder (content))
2195 g_assert (physical == 0);
2201 logical_to_physical (GtkToolbar *toolbar,
2204 GtkToolbarPrivate *priv = toolbar->priv;
2208 g_assert (logical >= 0);
2211 for (list = priv->content; list; list = list->next)
2213 ToolbarContent *content = list->data;
2215 if (!toolbar_content_is_placeholder (content))
2225 g_assert (logical == 0);
2231 * gtk_toolbar_set_drop_highlight_item:
2232 * @toolbar: a #GtkToolbar
2233 * @tool_item: (allow-none): a #GtkToolItem, or %NULL to turn of highlighting
2234 * @index_: a position on @toolbar
2236 * Highlights @toolbar to give an idea of what it would look like
2237 * if @item was added to @toolbar at the position indicated by @index_.
2238 * If @item is %NULL, highlighting is turned off. In that case @index_
2241 * The @tool_item passed to this function must not be part of any widget
2242 * hierarchy. When an item is set as drop highlight item it can not
2243 * added to any widget hierarchy or used as highlight item for another
2249 gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar,
2250 GtkToolItem *tool_item,
2253 ToolbarContent *content;
2254 GtkToolbarPrivate *priv;
2256 GtkRequisition requisition;
2257 GtkRequisition old_requisition;
2258 gboolean restart_sliding;
2260 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2261 g_return_if_fail (tool_item == NULL || GTK_IS_TOOL_ITEM (tool_item));
2263 priv = toolbar->priv;
2267 if (priv->highlight_tool_item)
2269 gtk_widget_unparent (GTK_WIDGET (priv->highlight_tool_item));
2270 g_object_unref (priv->highlight_tool_item);
2271 priv->highlight_tool_item = NULL;
2274 reset_all_placeholders (toolbar);
2275 gtk_toolbar_begin_sliding (toolbar);
2279 n_items = gtk_toolbar_get_n_items (toolbar);
2280 if (index_ < 0 || index_ > n_items)
2283 if (tool_item != priv->highlight_tool_item)
2285 if (priv->highlight_tool_item)
2286 g_object_unref (priv->highlight_tool_item);
2288 g_object_ref_sink (tool_item);
2290 priv->highlight_tool_item = tool_item;
2292 gtk_widget_set_parent (GTK_WIDGET (priv->highlight_tool_item),
2293 GTK_WIDGET (toolbar));
2296 index_ = logical_to_physical (toolbar, index_);
2298 content = g_list_nth_data (priv->content, index_);
2302 ToolbarContent *prev_content;
2304 prev_content = g_list_nth_data (priv->content, index_ - 1);
2306 if (prev_content && toolbar_content_is_placeholder (prev_content))
2307 content = prev_content;
2310 if (!content || !toolbar_content_is_placeholder (content))
2312 GtkWidget *placeholder;
2314 placeholder = GTK_WIDGET (gtk_separator_tool_item_new ());
2316 content = toolbar_content_new_tool_item (toolbar,
2317 GTK_TOOL_ITEM (placeholder),
2319 gtk_widget_show (placeholder);
2323 g_assert (toolbar_content_is_placeholder (content));
2325 gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->highlight_tool_item),
2326 &requisition, NULL);
2328 toolbar_content_set_expand (content, gtk_tool_item_get_expand (tool_item));
2330 restart_sliding = FALSE;
2331 toolbar_content_size_request (content, toolbar, &old_requisition);
2332 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2334 requisition.height = -1;
2335 if (requisition.width != old_requisition.width)
2336 restart_sliding = TRUE;
2340 requisition.width = -1;
2341 if (requisition.height != old_requisition.height)
2342 restart_sliding = TRUE;
2345 if (toolbar_content_disappearing (content))
2346 restart_sliding = TRUE;
2348 reset_all_placeholders (toolbar);
2349 toolbar_content_set_disappearing (content, FALSE);
2351 toolbar_content_set_size_request (content,
2352 requisition.width, requisition.height);
2354 if (restart_sliding)
2355 gtk_toolbar_begin_sliding (toolbar);
2359 gtk_toolbar_get_child_property (GtkContainer *container,
2365 GtkToolItem *item = GTK_TOOL_ITEM (child);
2367 switch (property_id)
2369 case CHILD_PROP_HOMOGENEOUS:
2370 g_value_set_boolean (value, gtk_tool_item_get_homogeneous (item));
2373 case CHILD_PROP_EXPAND:
2374 g_value_set_boolean (value, gtk_tool_item_get_expand (item));
2378 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2384 gtk_toolbar_set_child_property (GtkContainer *container,
2387 const GValue *value,
2390 switch (property_id)
2392 case CHILD_PROP_HOMOGENEOUS:
2393 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2396 case CHILD_PROP_EXPAND:
2397 gtk_tool_item_set_expand (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2401 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2407 gtk_toolbar_show_all (GtkWidget *widget)
2409 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2410 GtkToolbarPrivate *priv = toolbar->priv;
2413 for (list = priv->content; list != NULL; list = list->next)
2415 ToolbarContent *content = list->data;
2417 toolbar_content_show_all (content);
2420 gtk_widget_show (widget);
2424 gtk_toolbar_hide_all (GtkWidget *widget)
2426 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2427 GtkToolbarPrivate *priv = toolbar->priv;
2430 for (list = priv->content; list != NULL; list = list->next)
2432 ToolbarContent *content = list->data;
2434 toolbar_content_hide_all (content);
2437 gtk_widget_hide (widget);
2441 gtk_toolbar_add (GtkContainer *container,
2444 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2446 gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
2450 gtk_toolbar_remove (GtkContainer *container,
2453 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2454 GtkToolbarPrivate *priv = toolbar->priv;
2455 ToolbarContent *content_to_remove;
2458 content_to_remove = NULL;
2459 for (list = priv->content; list != NULL; list = list->next)
2461 ToolbarContent *content = list->data;
2464 child = toolbar_content_get_widget (content);
2465 if (child && child == widget)
2467 content_to_remove = content;
2472 g_return_if_fail (content_to_remove != NULL);
2474 toolbar_content_remove (content_to_remove, toolbar);
2475 toolbar_content_free (content_to_remove);
2479 gtk_toolbar_forall (GtkContainer *container,
2480 gboolean include_internals,
2481 GtkCallback callback,
2482 gpointer callback_data)
2484 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2485 GtkToolbarPrivate *priv = toolbar->priv;
2488 g_return_if_fail (callback != NULL);
2490 list = priv->content;
2493 ToolbarContent *content = list->data;
2494 GList *next = list->next;
2496 if (include_internals || !toolbar_content_is_placeholder (content))
2498 GtkWidget *child = toolbar_content_get_widget (content);
2501 callback (child, callback_data);
2507 if (include_internals)
2508 callback (priv->arrow_button, callback_data);
2512 gtk_toolbar_child_type (GtkContainer *container)
2514 return GTK_TYPE_TOOL_ITEM;
2518 gtk_toolbar_reconfigured (GtkToolbar *toolbar)
2520 GtkToolbarPrivate *priv = toolbar->priv;
2523 list = priv->content;
2526 ToolbarContent *content = list->data;
2527 GList *next = list->next;
2529 toolbar_content_toolbar_reconfigured (content, toolbar);
2536 gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
2537 GtkOrientation orientation)
2539 GtkToolbarPrivate *priv = toolbar->priv;
2541 if (priv->orientation != orientation)
2543 priv->orientation = orientation;
2545 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2546 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2548 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2550 gtk_toolbar_reconfigured (toolbar);
2552 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2553 g_object_notify (G_OBJECT (toolbar), "orientation");
2558 gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
2559 GtkToolbarStyle style)
2561 GtkToolbarPrivate *priv = toolbar->priv;
2563 if (priv->style != style)
2565 priv->style = style;
2567 gtk_toolbar_reconfigured (toolbar);
2569 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2570 g_object_notify (G_OBJECT (toolbar), "toolbar-style");
2575 menu_position_func (GtkMenu *menu,
2581 GtkAllocation allocation;
2582 GtkToolbar *toolbar = GTK_TOOLBAR (user_data);
2583 GtkToolbarPrivate *priv = toolbar->priv;
2585 GtkRequisition menu_req;
2586 GdkRectangle monitor;
2590 gtk_size_request_get_size (GTK_SIZE_REQUEST (priv->arrow_button),
2592 gtk_size_request_get_size (GTK_SIZE_REQUEST (menu),
2595 screen = gtk_widget_get_screen (GTK_WIDGET (menu));
2596 monitor_num = gdk_screen_get_monitor_at_window (screen,
2597 gtk_widget_get_window (priv->arrow_button));
2598 if (monitor_num < 0)
2600 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2602 gtk_widget_get_allocation (priv->arrow_button, &allocation);
2604 gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
2605 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2607 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2608 *x += allocation.width - req.width;
2610 *x += req.width - menu_req.width;
2612 if ((*y + allocation.height + menu_req.height) <= monitor.y + monitor.height)
2613 *y += allocation.height;
2614 else if ((*y - menu_req.height) >= monitor.y)
2615 *y -= menu_req.height;
2616 else if (monitor.y + monitor.height - (*y + allocation.height) > *y)
2617 *y += allocation.height;
2619 *y -= menu_req.height;
2623 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2624 *x += allocation.width;
2626 *x -= menu_req.width;
2628 if (*y + menu_req.height > monitor.y + monitor.height &&
2629 *y + allocation.height - monitor.y > monitor.y + monitor.height - *y)
2630 *y += allocation.height - menu_req.height;
2637 show_menu (GtkToolbar *toolbar,
2638 GdkEventButton *event)
2640 GtkToolbarPrivate *priv = toolbar->priv;
2642 rebuild_menu (toolbar);
2644 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2646 gtk_menu_popup (priv->menu, NULL, NULL,
2647 menu_position_func, toolbar,
2648 event? event->button : 0,
2649 event? event->time : gtk_get_current_event_time());
2653 gtk_toolbar_arrow_button_clicked (GtkWidget *button,
2654 GtkToolbar *toolbar)
2656 GtkToolbarPrivate *priv = toolbar->priv;
2658 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) &&
2659 (!priv->menu || !gtk_widget_get_visible (GTK_WIDGET (priv->menu))))
2661 /* We only get here when the button is clicked with the keyboard,
2662 * because mouse button presses result in the menu being shown so
2663 * that priv->menu would be non-NULL and visible.
2665 show_menu (toolbar, NULL);
2666 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
2671 gtk_toolbar_arrow_button_press (GtkWidget *button,
2672 GdkEventButton *event,
2673 GtkToolbar *toolbar)
2675 show_menu (toolbar, event);
2676 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
2682 gtk_toolbar_button_press (GtkWidget *toolbar,
2683 GdkEventButton *event)
2687 if (event->button == 3)
2689 gboolean return_value;
2691 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2692 (int)event->x_root, (int)event->y_root, event->button,
2695 return return_value;
2698 window = gtk_widget_get_toplevel (toolbar);
2702 gboolean window_drag = FALSE;
2704 gtk_widget_style_get (toolbar,
2705 "window-dragging", &window_drag,
2710 gtk_window_begin_move_drag (GTK_WINDOW (window),
2724 gtk_toolbar_popup_menu (GtkWidget *toolbar)
2726 gboolean return_value;
2727 /* This function is the handler for the "popup menu" keybinding,
2728 * ie., it is called when the user presses Shift F10
2730 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2731 -1, -1, -1, &return_value);
2733 return return_value;
2739 * Creates a new toolbar.
2741 * Return Value: the newly-created toolbar.
2744 gtk_toolbar_new (void)
2746 GtkToolbar *toolbar;
2748 toolbar = g_object_new (GTK_TYPE_TOOLBAR, NULL);
2750 return GTK_WIDGET (toolbar);
2754 * gtk_toolbar_insert:
2755 * @toolbar: a #GtkToolbar
2756 * @item: a #GtkToolItem
2757 * @pos: the position of the new item
2759 * Insert a #GtkToolItem into the toolbar at position @pos. If @pos is
2760 * 0 the item is prepended to the start of the toolbar. If @pos is
2761 * negative, the item is appended to the end of the toolbar.
2766 gtk_toolbar_insert (GtkToolbar *toolbar,
2770 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2771 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
2774 pos = logical_to_physical (toolbar, pos);
2776 toolbar_content_new_tool_item (toolbar, item, FALSE, pos);
2780 * gtk_toolbar_get_item_index:
2781 * @toolbar: a #GtkToolbar
2782 * @item: a #GtkToolItem that is a child of @toolbar
2784 * Returns the position of @item on the toolbar, starting from 0.
2785 * It is an error if @item is not a child of the toolbar.
2787 * Return value: the position of item on the toolbar.
2792 gtk_toolbar_get_item_index (GtkToolbar *toolbar,
2795 GtkToolbarPrivate *priv;
2799 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2800 g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
2801 g_return_val_if_fail (gtk_widget_get_parent (GTK_WIDGET (item)) == GTK_WIDGET (toolbar), -1);
2803 priv = toolbar->priv;
2806 for (list = priv->content; list != NULL; list = list->next)
2808 ToolbarContent *content = list->data;
2811 widget = toolbar_content_get_widget (content);
2813 if (item == GTK_TOOL_ITEM (widget))
2819 return physical_to_logical (toolbar, n);
2823 * gtk_toolbar_set_style:
2824 * @toolbar: a #GtkToolbar.
2825 * @style: the new style for @toolbar.
2827 * Alters the view of @toolbar to display either icons only, text only, or both.
2830 gtk_toolbar_set_style (GtkToolbar *toolbar,
2831 GtkToolbarStyle style)
2833 GtkToolbarPrivate *priv;
2835 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2837 priv = toolbar->priv;
2839 priv->style_set = TRUE;
2840 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2844 * gtk_toolbar_get_style:
2845 * @toolbar: a #GtkToolbar
2847 * Retrieves whether the toolbar has text, icons, or both . See
2848 * gtk_toolbar_set_style().
2850 * Return value: the current style of @toolbar
2853 gtk_toolbar_get_style (GtkToolbar *toolbar)
2855 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_TOOLBAR_STYLE);
2857 return toolbar->priv->style;
2861 * gtk_toolbar_unset_style:
2862 * @toolbar: a #GtkToolbar
2864 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that
2865 * user preferences will be used to determine the toolbar style.
2868 gtk_toolbar_unset_style (GtkToolbar *toolbar)
2870 GtkToolbarPrivate *priv;
2871 GtkToolbarStyle style;
2873 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2875 priv = toolbar->priv;
2877 if (priv->style_set)
2879 GtkSettings *settings = toolbar_get_settings (toolbar);
2882 g_object_get (settings,
2883 "gtk-toolbar-style", &style,
2886 style = DEFAULT_TOOLBAR_STYLE;
2888 if (style != priv->style)
2889 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2891 priv->style_set = FALSE;
2896 * gtk_toolbar_get_n_items:
2897 * @toolbar: a #GtkToolbar
2899 * Returns the number of items on the toolbar.
2901 * Return value: the number of items on the toolbar
2906 gtk_toolbar_get_n_items (GtkToolbar *toolbar)
2908 GtkToolbarPrivate *priv;
2910 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2912 priv = toolbar->priv;
2914 return physical_to_logical (toolbar, g_list_length (priv->content));
2918 * gtk_toolbar_get_nth_item:
2919 * @toolbar: a #GtkToolbar
2920 * @n: A position on the toolbar
2922 * Returns the @n<!-- -->'th item on @toolbar, or %NULL if the
2923 * toolbar does not contain an @n<!-- -->'th item.
2925 * Return value: (transfer none): The @n<!-- -->'th #GtkToolItem on @toolbar,
2926 * or %NULL if there isn't an @n<!-- -->'th item.
2931 gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
2934 GtkToolbarPrivate *priv;
2935 ToolbarContent *content;
2938 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
2940 priv = toolbar->priv;
2942 n_items = gtk_toolbar_get_n_items (toolbar);
2944 if (n < 0 || n >= n_items)
2947 content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
2950 g_assert (!toolbar_content_is_placeholder (content));
2952 return GTK_TOOL_ITEM (toolbar_content_get_widget (content));
2956 * gtk_toolbar_get_icon_size:
2957 * @toolbar: a #GtkToolbar
2959 * Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size().
2961 * Return value: (type int): the current icon size for the icons on
2965 gtk_toolbar_get_icon_size (GtkToolbar *toolbar)
2967 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_ICON_SIZE);
2969 return toolbar->priv->icon_size;
2973 * gtk_toolbar_get_relief_style:
2974 * @toolbar: a #GtkToolbar
2976 * Returns the relief style of buttons on @toolbar. See
2977 * gtk_button_set_relief().
2979 * Return value: The relief style of buttons on @toolbar.
2984 gtk_toolbar_get_relief_style (GtkToolbar *toolbar)
2986 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_RELIEF_NONE);
2988 return get_button_relief (toolbar);
2992 * gtk_toolbar_set_show_arrow:
2993 * @toolbar: a #GtkToolbar
2994 * @show_arrow: Whether to show an overflow menu
2996 * Sets whether to show an overflow menu when
2997 * @toolbar doesn't have room for all items on it. If %TRUE,
2998 * items that there are not room are available through an
3004 gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
3005 gboolean show_arrow)
3007 GtkToolbarPrivate *priv;
3009 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3011 priv = toolbar->priv;
3013 show_arrow = show_arrow != FALSE;
3015 if (priv->show_arrow != show_arrow)
3017 priv->show_arrow = show_arrow;
3019 if (!priv->show_arrow)
3020 gtk_widget_hide (priv->arrow_button);
3022 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3023 g_object_notify (G_OBJECT (toolbar), "show-arrow");
3028 * gtk_toolbar_get_show_arrow:
3029 * @toolbar: a #GtkToolbar
3031 * Returns whether the toolbar has an overflow menu.
3032 * See gtk_toolbar_set_show_arrow().
3034 * Return value: %TRUE if the toolbar has an overflow menu.
3039 gtk_toolbar_get_show_arrow (GtkToolbar *toolbar)
3041 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
3043 return toolbar->priv->show_arrow;
3047 * gtk_toolbar_get_drop_index:
3048 * @toolbar: a #GtkToolbar
3049 * @x: x coordinate of a point on the toolbar
3050 * @y: y coordinate of a point on the toolbar
3052 * Returns the position corresponding to the indicated point on
3053 * @toolbar. This is useful when dragging items to the toolbar:
3054 * this function returns the position a new item should be
3057 * @x and @y are in @toolbar coordinates.
3059 * Return value: The position corresponding to the point (@x, @y) on the toolbar.
3064 gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
3068 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
3070 return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
3074 gtk_toolbar_finalize (GObject *object)
3077 GtkToolbar *toolbar = GTK_TOOLBAR (object);
3078 GtkToolbarPrivate *priv = toolbar->priv;
3080 if (priv->arrow_button)
3081 gtk_widget_unparent (priv->arrow_button);
3083 for (list = priv->content; list != NULL; list = list->next)
3085 ToolbarContent *content = list->data;
3087 toolbar_content_free (content);
3090 g_list_free (priv->content);
3091 g_list_free (priv->children);
3093 g_timer_destroy (priv->timer);
3096 gtk_widget_destroy (GTK_WIDGET (priv->menu));
3099 g_source_remove (priv->idle_id);
3101 G_OBJECT_CLASS (gtk_toolbar_parent_class)->finalize (object);
3105 * gtk_toolbar_set_icon_size:
3106 * @toolbar: A #GtkToolbar
3107 * @icon_size: (type int): The #GtkIconSize that stock icons in the
3108 * toolbar shall have.
3110 * This function sets the size of stock icons in the toolbar. You
3111 * can call it both before you add the icons and after they've been
3112 * added. The size you set will override user preferences for the default
3115 * This should only be used for special-purpose toolbars, normal
3116 * application toolbars should respect the user preferences for the
3120 gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
3121 GtkIconSize icon_size)
3123 GtkToolbarPrivate *priv;
3125 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3126 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
3128 priv = toolbar->priv;
3130 if (!priv->icon_size_set)
3132 priv->icon_size_set = TRUE;
3133 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3136 if (priv->icon_size == icon_size)
3139 priv->icon_size = icon_size;
3140 g_object_notify (G_OBJECT (toolbar), "icon-size");
3142 gtk_toolbar_reconfigured (toolbar);
3144 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3148 * gtk_toolbar_unset_icon_size:
3149 * @toolbar: a #GtkToolbar
3151 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that
3152 * user preferences will be used to determine the icon size.
3155 gtk_toolbar_unset_icon_size (GtkToolbar *toolbar)
3157 GtkToolbarPrivate *priv;
3160 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3162 priv = toolbar->priv;
3164 if (priv->icon_size_set)
3166 GtkSettings *settings = toolbar_get_settings (toolbar);
3170 g_object_get (settings,
3171 "gtk-toolbar-icon-size", &size,
3175 size = DEFAULT_ICON_SIZE;
3177 if (size != priv->icon_size)
3179 gtk_toolbar_set_icon_size (toolbar, size);
3180 g_object_notify (G_OBJECT (toolbar), "icon-size");
3183 priv->icon_size_set = FALSE;
3184 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3189 * ToolbarContent methods
3197 struct _ToolbarContent
3202 GtkAllocation start_allocation;
3203 GtkAllocation goal_allocation;
3204 guint is_placeholder : 1;
3205 guint disappearing : 1;
3209 static ToolbarContent *
3210 toolbar_content_new_tool_item (GtkToolbar *toolbar,
3212 gboolean is_placeholder,
3215 GtkToolbarPrivate *priv = toolbar->priv;
3216 ToolbarContent *content;
3218 content = g_slice_new0 (ToolbarContent);
3220 content->state = NOT_ALLOCATED;
3221 content->item = item;
3222 content->is_placeholder = is_placeholder;
3224 gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
3226 priv->content = g_list_insert (priv->content, content, pos);
3228 if (!is_placeholder)
3230 priv->num_children++;
3232 gtk_toolbar_stop_sliding (toolbar);
3235 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3236 priv->need_rebuild = TRUE;
3242 toolbar_content_remove (ToolbarContent *content,
3243 GtkToolbar *toolbar)
3245 GtkToolbarPrivate *priv = toolbar->priv;
3247 gtk_widget_unparent (GTK_WIDGET (content->item));
3249 priv->content = g_list_remove (priv->content, content);
3251 if (!toolbar_content_is_placeholder (content))
3252 priv->num_children--;
3254 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3255 priv->need_rebuild = TRUE;
3259 toolbar_content_free (ToolbarContent *content)
3261 g_slice_free (ToolbarContent, content);
3265 calculate_max_homogeneous_pixels (GtkWidget *widget)
3267 PangoContext *context;
3268 PangoFontMetrics *metrics;
3271 context = gtk_widget_get_pango_context (widget);
3272 metrics = pango_context_get_metrics (context,
3273 gtk_widget_get_style (widget)->font_desc,
3274 pango_context_get_language (context));
3275 char_width = pango_font_metrics_get_approximate_char_width (metrics);
3276 pango_font_metrics_unref (metrics);
3278 return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
3282 toolbar_content_draw (ToolbarContent *content,
3283 GtkContainer *container,
3288 if (content->is_placeholder)
3291 widget = GTK_WIDGET (content->item);
3294 gtk_container_propagate_draw (container, widget, cr);
3298 toolbar_content_visible (ToolbarContent *content,
3299 GtkToolbar *toolbar)
3301 GtkToolbarPrivate *priv = toolbar->priv;
3304 item = content->item;
3306 if (!gtk_widget_get_visible (GTK_WIDGET (item)))
3309 if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
3310 gtk_tool_item_get_visible_horizontal (item))
3313 if (priv->orientation == GTK_ORIENTATION_VERTICAL &&
3314 gtk_tool_item_get_visible_vertical (item))
3321 toolbar_content_size_request (ToolbarContent *content,
3322 GtkToolbar *toolbar,
3323 GtkRequisition *requisition)
3325 gtk_size_request_get_size (GTK_SIZE_REQUEST (content->item),
3327 if (content->is_placeholder &&
3328 content->disappearing)
3330 requisition->width = 0;
3331 requisition->height = 0;
3336 toolbar_content_is_homogeneous (ToolbarContent *content,
3337 GtkToolbar *toolbar)
3339 GtkToolbarPrivate *priv = toolbar->priv;
3340 GtkRequisition requisition;
3343 if (priv->max_homogeneous_pixels < 0)
3345 priv->max_homogeneous_pixels =
3346 calculate_max_homogeneous_pixels (GTK_WIDGET (toolbar));
3349 toolbar_content_size_request (content, toolbar, &requisition);
3351 if (requisition.width > priv->max_homogeneous_pixels)
3354 result = gtk_tool_item_get_homogeneous (content->item) &&
3355 !GTK_IS_SEPARATOR_TOOL_ITEM (content->item);
3357 if (gtk_tool_item_get_is_important (content->item) &&
3358 priv->style == GTK_TOOLBAR_BOTH_HORIZ &&
3359 priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3368 toolbar_content_is_placeholder (ToolbarContent *content)
3370 if (content->is_placeholder)
3377 toolbar_content_disappearing (ToolbarContent *content)
3379 if (content->disappearing)
3386 toolbar_content_get_state (ToolbarContent *content)
3388 return content->state;
3392 toolbar_content_child_visible (ToolbarContent *content)
3394 return GTK_WIDGET_CHILD_VISIBLE (content->item);
3398 toolbar_content_get_goal_allocation (ToolbarContent *content,
3399 GtkAllocation *allocation)
3401 *allocation = content->goal_allocation;
3405 toolbar_content_get_allocation (ToolbarContent *content,
3406 GtkAllocation *allocation)
3408 gtk_widget_get_allocation (GTK_WIDGET (content->item), allocation);
3412 toolbar_content_set_start_allocation (ToolbarContent *content,
3413 GtkAllocation *allocation)
3415 content->start_allocation = *allocation;
3419 toolbar_content_get_expand (ToolbarContent *content)
3421 if (!content->disappearing &&
3422 gtk_tool_item_get_expand (content->item))
3429 toolbar_content_set_goal_allocation (ToolbarContent *content,
3430 GtkAllocation *allocation)
3432 content->goal_allocation = *allocation;
3436 toolbar_content_set_child_visible (ToolbarContent *content,
3437 GtkToolbar *toolbar,
3440 gtk_widget_set_child_visible (GTK_WIDGET (content->item),
3445 toolbar_content_get_start_allocation (ToolbarContent *content,
3446 GtkAllocation *start_allocation)
3448 *start_allocation = content->start_allocation;
3452 toolbar_content_size_allocate (ToolbarContent *content,
3453 GtkAllocation *allocation)
3455 gtk_widget_size_allocate (GTK_WIDGET (content->item),
3460 toolbar_content_set_state (ToolbarContent *content,
3463 content->state = state;
3467 toolbar_content_get_widget (ToolbarContent *content)
3469 return GTK_WIDGET (content->item);
3474 toolbar_content_set_disappearing (ToolbarContent *content,
3475 gboolean disappearing)
3477 content->disappearing = disappearing;
3481 toolbar_content_set_size_request (ToolbarContent *content,
3485 gtk_widget_set_size_request (GTK_WIDGET (content->item),
3490 toolbar_content_toolbar_reconfigured (ToolbarContent *content,
3491 GtkToolbar *toolbar)
3493 gtk_tool_item_toolbar_reconfigured (content->item);
3497 toolbar_content_retrieve_menu_item (ToolbarContent *content)
3499 return gtk_tool_item_retrieve_proxy_menu_item (content->item);
3503 toolbar_content_has_proxy_menu_item (ToolbarContent *content)
3505 GtkWidget *menu_item;
3507 if (content->has_menu == YES)
3509 else if (content->has_menu == NO)
3512 menu_item = toolbar_content_retrieve_menu_item (content);
3514 content->has_menu = menu_item? YES : NO;
3516 return menu_item != NULL;
3520 toolbar_content_set_unknown_menu_status (ToolbarContent *content)
3522 content->has_menu = UNKNOWN;
3526 toolbar_content_is_separator (ToolbarContent *content)
3528 return GTK_IS_SEPARATOR_TOOL_ITEM (content->item);
3532 toolbar_content_set_expand (ToolbarContent *content,
3535 gtk_tool_item_set_expand (content->item, expand);
3539 toolbar_content_show_all (ToolbarContent *content)
3543 widget = toolbar_content_get_widget (content);
3545 gtk_widget_show_all (widget);
3549 toolbar_content_hide_all (ToolbarContent *content)
3553 widget = toolbar_content_get_widget (content);
3555 gtk_widget_hide_all (widget);
3561 static GtkReliefStyle
3562 get_button_relief (GtkToolbar *toolbar)
3564 GtkReliefStyle button_relief = GTK_RELIEF_NORMAL;
3566 gtk_widget_ensure_style (GTK_WIDGET (toolbar));
3568 gtk_widget_style_get (GTK_WIDGET (toolbar),
3569 "button-relief", &button_relief,
3572 return button_relief;
3576 get_internal_padding (GtkToolbar *toolbar)
3580 gtk_widget_style_get (GTK_WIDGET (toolbar),
3581 "internal-padding", &ipadding,
3588 get_max_child_expand (GtkToolbar *toolbar)
3590 gint mexpand = G_MAXINT;
3592 gtk_widget_style_get (GTK_WIDGET (toolbar),
3593 "max-child-expand", &mexpand,
3598 static GtkShadowType
3599 get_shadow_type (GtkToolbar *toolbar)
3601 GtkShadowType shadow_type;
3603 gtk_widget_style_get (GTK_WIDGET (toolbar),
3604 "shadow-type", &shadow_type,
3610 /* GTK+ internal methods */
3613 _gtk_toolbar_get_default_space_size (void)
3615 return DEFAULT_SPACE_SIZE;
3619 _gtk_toolbar_paint_space_line (GtkWidget *widget,
3620 GtkToolbar *toolbar,
3623 GtkToolbarPrivate *priv = toolbar->priv;
3624 GtkOrientation orientation;
3629 const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
3630 const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
3632 g_return_if_fail (GTK_IS_WIDGET (widget));
3634 orientation = toolbar? priv->orientation : GTK_ORIENTATION_HORIZONTAL;
3636 style = gtk_widget_get_style (widget);
3637 window = gtk_widget_get_window (widget);
3638 state = gtk_widget_get_state (widget);
3639 width = gtk_widget_get_allocated_width (widget);
3640 height = gtk_widget_get_allocated_height (widget);
3642 if (orientation == GTK_ORIENTATION_HORIZONTAL)
3644 gboolean wide_separators;
3645 gint separator_width;
3647 gtk_widget_style_get (widget,
3648 "wide-separators", &wide_separators,
3649 "separator-width", &separator_width,
3652 if (wide_separators)
3653 gtk_cairo_paint_box (style, cr,
3654 state, GTK_SHADOW_ETCHED_OUT,
3655 widget, "vseparator",
3656 (width - separator_width) / 2,
3657 height * start_fraction,
3659 height * (end_fraction - start_fraction));
3661 gtk_cairo_paint_vline (style, cr,
3664 height * start_fraction,
3665 height * end_fraction,
3666 (width - style->xthickness) / 2);
3670 gboolean wide_separators;
3671 gint separator_height;
3673 gtk_widget_style_get (widget,
3674 "wide-separators", &wide_separators,
3675 "separator-height", &separator_height,
3678 if (wide_separators)
3679 gtk_cairo_paint_box (style, cr,
3680 state, GTK_SHADOW_ETCHED_OUT,
3681 widget, "hseparator",
3682 width * start_fraction,
3683 (height - separator_height) / 2,
3684 width * (end_fraction - start_fraction),
3687 gtk_cairo_paint_hline (style, cr,
3690 width * start_fraction,
3691 width * end_fraction,
3692 (height - style->ythickness) / 2);
3697 _gtk_toolbar_elide_underscores (const gchar *original)
3700 const gchar *p, *end;
3702 gboolean last_underscore;
3707 len = strlen (original);
3708 q = result = g_malloc (len + 1);
3709 last_underscore = FALSE;
3711 end = original + len;
3712 for (p = original; p < end; p++)
3714 if (!last_underscore && *p == '_')
3715 last_underscore = TRUE;
3718 last_underscore = FALSE;
3719 if (original + 2 <= p && p + 1 <= end &&
3720 p[-2] == '(' && p[-1] == '_' && p[0] != '_' && p[1] == ')')
3731 if (last_underscore)
3740 toolbar_get_icon_size (GtkToolShell *shell)
3742 GtkToolbar *toolbar = GTK_TOOLBAR (shell);
3743 GtkToolbarPrivate *priv = toolbar->priv;
3745 return priv->icon_size;
3748 static GtkOrientation
3749 toolbar_get_orientation (GtkToolShell *shell)
3751 GtkToolbar *toolbar = GTK_TOOLBAR (shell);
3752 GtkToolbarPrivate *priv = toolbar->priv;
3754 return priv->orientation;
3757 static GtkToolbarStyle
3758 toolbar_get_style (GtkToolShell *shell)
3760 GtkToolbar *toolbar = GTK_TOOLBAR (shell);
3761 GtkToolbarPrivate *priv = toolbar->priv;
3766 static GtkReliefStyle
3767 toolbar_get_relief_style (GtkToolShell *shell)
3769 return get_button_relief (GTK_TOOLBAR (shell));
3773 toolbar_rebuild_menu (GtkToolShell *shell)
3775 GtkToolbar *toolbar = GTK_TOOLBAR (shell);
3776 GtkToolbarPrivate *priv = toolbar->priv;
3779 priv->need_rebuild = TRUE;
3781 for (list = priv->content; list != NULL; list = list->next)
3783 ToolbarContent *content = list->data;
3785 toolbar_content_set_unknown_menu_status (content);
3788 gtk_widget_queue_resize (GTK_WIDGET (shell));