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/.
32 #undef GTK_DISABLE_DEPRECATED
39 #include <gdk/gdkkeysyms.h>
42 #include "gtkbindings.h"
47 #include "gtkmarshalers.h"
49 #include "gtkorientable.h"
50 #include "gtkradiobutton.h"
51 #include "gtkradiotoolbutton.h"
52 #include "gtkseparatormenuitem.h"
53 #include "gtkseparatortoolitem.h"
55 #include "gtktoolbar.h"
56 #include "gtktoolshell.h"
58 #include "gtkprivate.h"
62 typedef struct _ToolbarContent ToolbarContent;
64 #define DEFAULT_IPADDING 0
66 #define DEFAULT_SPACE_SIZE 12
67 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
68 #define SPACE_LINE_DIVISION 10.0
69 #define SPACE_LINE_START 2.0
70 #define SPACE_LINE_END 8.0
72 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
73 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
74 #define DEFAULT_ANIMATION_STATE TRUE
76 #define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
77 * in the homogeneous game. In units of
78 * pango_font_get_estimated_char_width().
80 #define SLIDE_SPEED 600.0 /* How fast the items slide, in pixels per second */
81 #define ACCEL_THRESHOLD 0.18 /* After how much time in seconds will items start speeding up */
83 #define MIXED_API_WARNING \
84 "Mixing deprecated and non-deprecated GtkToolbar API is not allowed"
98 /* Child properties */
102 CHILD_PROP_HOMOGENEOUS
133 struct _GtkToolbarPrivate
138 GtkWidget * arrow_button;
141 GdkWindow * event_window;
143 GtkSettings * settings;
145 GtkToolItem * highlight_tool_item;
146 gint max_homogeneous_pixels;
150 gulong settings_connection;
152 guint show_arrow : 1;
154 guint is_sliding : 1;
155 guint need_rebuild : 1; /* whether the overflow menu should be regenerated */
159 static void gtk_toolbar_set_property (GObject *object,
163 static void gtk_toolbar_get_property (GObject *object,
167 static gint gtk_toolbar_expose (GtkWidget *widget,
168 GdkEventExpose *event);
169 static void gtk_toolbar_realize (GtkWidget *widget);
170 static void gtk_toolbar_unrealize (GtkWidget *widget);
171 static void gtk_toolbar_size_request (GtkWidget *widget,
172 GtkRequisition *requisition);
173 static void gtk_toolbar_size_allocate (GtkWidget *widget,
174 GtkAllocation *allocation);
175 static void gtk_toolbar_style_set (GtkWidget *widget,
176 GtkStyle *prev_style);
177 static gboolean gtk_toolbar_focus (GtkWidget *widget,
178 GtkDirectionType dir);
179 static void gtk_toolbar_move_focus (GtkWidget *widget,
180 GtkDirectionType dir);
181 static void gtk_toolbar_screen_changed (GtkWidget *widget,
182 GdkScreen *previous_screen);
183 static void gtk_toolbar_map (GtkWidget *widget);
184 static void gtk_toolbar_unmap (GtkWidget *widget);
185 static void gtk_toolbar_set_child_property (GtkContainer *container,
190 static void gtk_toolbar_get_child_property (GtkContainer *container,
195 static void gtk_toolbar_finalize (GObject *object);
196 static void gtk_toolbar_show_all (GtkWidget *widget);
197 static void gtk_toolbar_hide_all (GtkWidget *widget);
198 static void gtk_toolbar_add (GtkContainer *container,
200 static void gtk_toolbar_remove (GtkContainer *container,
202 static void gtk_toolbar_forall (GtkContainer *container,
203 gboolean include_internals,
204 GtkCallback callback,
205 gpointer callback_data);
206 static GType gtk_toolbar_child_type (GtkContainer *container);
207 static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
208 GtkOrientation orientation);
209 static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
210 GtkToolbarStyle style);
211 static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
212 gboolean focus_home);
213 static gboolean gtk_toolbar_button_press (GtkWidget *toolbar,
214 GdkEventButton *event);
215 static gboolean gtk_toolbar_arrow_button_press (GtkWidget *button,
216 GdkEventButton *event,
217 GtkToolbar *toolbar);
218 static void gtk_toolbar_arrow_button_clicked (GtkWidget *button,
219 GtkToolbar *toolbar);
220 static void gtk_toolbar_update_button_relief (GtkToolbar *toolbar);
221 static gboolean gtk_toolbar_popup_menu (GtkWidget *toolbar);
222 static void gtk_toolbar_reconfigured (GtkToolbar *toolbar);
224 static GtkReliefStyle get_button_relief (GtkToolbar *toolbar);
225 static gint get_internal_padding (GtkToolbar *toolbar);
226 static gint get_max_child_expand (GtkToolbar *toolbar);
227 static GtkShadowType get_shadow_type (GtkToolbar *toolbar);
228 static gint get_space_size (GtkToolbar *toolbar);
229 static GtkToolbarSpaceStyle get_space_style (GtkToolbar *toolbar);
231 /* methods on ToolbarContent 'class' */
232 static ToolbarContent *toolbar_content_new_tool_item (GtkToolbar *toolbar,
234 gboolean is_placeholder,
236 static void toolbar_content_remove (ToolbarContent *content,
237 GtkToolbar *toolbar);
238 static void toolbar_content_free (ToolbarContent *content);
239 static void toolbar_content_expose (ToolbarContent *content,
240 GtkContainer *container,
241 GdkEventExpose *expose);
242 static gboolean toolbar_content_visible (ToolbarContent *content,
243 GtkToolbar *toolbar);
244 static void toolbar_content_size_request (ToolbarContent *content,
246 GtkRequisition *requisition);
247 static gboolean toolbar_content_is_homogeneous (ToolbarContent *content,
248 GtkToolbar *toolbar);
249 static gboolean toolbar_content_is_placeholder (ToolbarContent *content);
250 static gboolean toolbar_content_disappearing (ToolbarContent *content);
251 static ItemState toolbar_content_get_state (ToolbarContent *content);
252 static gboolean toolbar_content_child_visible (ToolbarContent *content);
253 static void toolbar_content_get_goal_allocation (ToolbarContent *content,
254 GtkAllocation *allocation);
255 static void toolbar_content_get_allocation (ToolbarContent *content,
256 GtkAllocation *allocation);
257 static void toolbar_content_set_start_allocation (ToolbarContent *content,
258 GtkAllocation *new_start_allocation);
259 static void toolbar_content_get_start_allocation (ToolbarContent *content,
260 GtkAllocation *start_allocation);
261 static gboolean toolbar_content_get_expand (ToolbarContent *content);
262 static void toolbar_content_set_goal_allocation (ToolbarContent *content,
263 GtkAllocation *allocation);
264 static void toolbar_content_set_child_visible (ToolbarContent *content,
267 static void toolbar_content_size_allocate (ToolbarContent *content,
268 GtkAllocation *allocation);
269 static void toolbar_content_set_state (ToolbarContent *content,
270 ItemState new_state);
271 static GtkWidget * toolbar_content_get_widget (ToolbarContent *content);
272 static void toolbar_content_set_disappearing (ToolbarContent *content,
273 gboolean disappearing);
274 static void toolbar_content_set_size_request (ToolbarContent *content,
277 static void toolbar_content_toolbar_reconfigured (ToolbarContent *content,
278 GtkToolbar *toolbar);
279 static GtkWidget * toolbar_content_retrieve_menu_item (ToolbarContent *content);
280 static gboolean toolbar_content_has_proxy_menu_item (ToolbarContent *content);
281 static gboolean toolbar_content_is_separator (ToolbarContent *content);
282 static void toolbar_content_show_all (ToolbarContent *content);
283 static void toolbar_content_hide_all (ToolbarContent *content);
284 static void toolbar_content_set_expand (ToolbarContent *content,
287 static void toolbar_tool_shell_iface_init (GtkToolShellIface *iface);
288 static GtkIconSize toolbar_get_icon_size (GtkToolShell *shell);
289 static GtkOrientation toolbar_get_orientation (GtkToolShell *shell);
290 static GtkToolbarStyle toolbar_get_style (GtkToolShell *shell);
291 static GtkReliefStyle toolbar_get_relief_style (GtkToolShell *shell);
292 static void toolbar_rebuild_menu (GtkToolShell *shell);
294 #define GTK_TOOLBAR_GET_PRIVATE(o) \
295 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOLBAR, GtkToolbarPrivate))
298 G_DEFINE_TYPE_WITH_CODE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER,
299 G_IMPLEMENT_INTERFACE (GTK_TYPE_TOOL_SHELL,
300 toolbar_tool_shell_iface_init)
301 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
304 static guint toolbar_signals[LAST_SIGNAL] = { 0 };
308 add_arrow_bindings (GtkBindingSet *binding_set,
310 GtkDirectionType dir)
312 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
314 gtk_binding_entry_add_signal (binding_set, keysym, 0,
316 GTK_TYPE_DIRECTION_TYPE, dir);
317 gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
319 GTK_TYPE_DIRECTION_TYPE, dir);
323 add_ctrl_tab_bindings (GtkBindingSet *binding_set,
324 GdkModifierType modifiers,
325 GtkDirectionType direction)
327 gtk_binding_entry_add_signal (binding_set,
328 GDK_Tab, GDK_CONTROL_MASK | modifiers,
330 GTK_TYPE_DIRECTION_TYPE, direction);
331 gtk_binding_entry_add_signal (binding_set,
332 GDK_KP_Tab, GDK_CONTROL_MASK | modifiers,
334 GTK_TYPE_DIRECTION_TYPE, direction);
338 gtk_toolbar_class_init (GtkToolbarClass *klass)
340 GObjectClass *gobject_class;
341 GtkWidgetClass *widget_class;
342 GtkContainerClass *container_class;
343 GtkBindingSet *binding_set;
345 gobject_class = (GObjectClass *)klass;
346 widget_class = (GtkWidgetClass *)klass;
347 container_class = (GtkContainerClass *)klass;
349 gobject_class->set_property = gtk_toolbar_set_property;
350 gobject_class->get_property = gtk_toolbar_get_property;
351 gobject_class->finalize = gtk_toolbar_finalize;
353 widget_class->button_press_event = gtk_toolbar_button_press;
354 widget_class->expose_event = gtk_toolbar_expose;
355 widget_class->size_request = gtk_toolbar_size_request;
356 widget_class->size_allocate = gtk_toolbar_size_allocate;
357 widget_class->style_set = gtk_toolbar_style_set;
358 widget_class->focus = gtk_toolbar_focus;
360 /* need to override the base class function via override_class_handler,
361 * because the signal slot is not available in GtkWidgetClass
363 g_signal_override_class_handler ("move-focus",
365 G_CALLBACK (gtk_toolbar_move_focus));
367 widget_class->screen_changed = gtk_toolbar_screen_changed;
368 widget_class->realize = gtk_toolbar_realize;
369 widget_class->unrealize = gtk_toolbar_unrealize;
370 widget_class->map = gtk_toolbar_map;
371 widget_class->unmap = gtk_toolbar_unmap;
372 widget_class->popup_menu = gtk_toolbar_popup_menu;
373 widget_class->show_all = gtk_toolbar_show_all;
374 widget_class->hide_all = gtk_toolbar_hide_all;
376 container_class->add = gtk_toolbar_add;
377 container_class->remove = gtk_toolbar_remove;
378 container_class->forall = gtk_toolbar_forall;
379 container_class->child_type = gtk_toolbar_child_type;
380 container_class->get_child_property = gtk_toolbar_get_child_property;
381 container_class->set_child_property = gtk_toolbar_set_child_property;
383 klass->orientation_changed = gtk_toolbar_orientation_changed;
384 klass->style_changed = gtk_toolbar_real_style_changed;
387 * GtkToolbar::orientation-changed:
388 * @toolbar: the object which emitted the signal
389 * @orientation: the new #GtkOrientation of the toolbar
391 * Emitted when the orientation of the toolbar changes.
393 toolbar_signals[ORIENTATION_CHANGED] =
394 g_signal_new (I_("orientation-changed"),
395 G_OBJECT_CLASS_TYPE (klass),
397 G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
399 g_cclosure_marshal_VOID__ENUM,
401 GTK_TYPE_ORIENTATION);
403 * GtkToolbar::style-changed:
404 * @toolbar: The #GtkToolbar which emitted the signal
405 * @style: the new #GtkToolbarStyle of the toolbar
407 * Emitted when the style of the toolbar changes.
409 toolbar_signals[STYLE_CHANGED] =
410 g_signal_new (I_("style-changed"),
411 G_OBJECT_CLASS_TYPE (klass),
413 G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
415 g_cclosure_marshal_VOID__ENUM,
417 GTK_TYPE_TOOLBAR_STYLE);
419 * GtkToolbar::popup-context-menu:
420 * @toolbar: the #GtkToolbar which emitted the signal
421 * @x: the x coordinate of the point where the menu should appear
422 * @y: the y coordinate of the point where the menu should appear
423 * @button: the mouse button the user pressed, or -1
425 * Emitted when the user right-clicks the toolbar or uses the
426 * keybinding to display a popup menu.
428 * Application developers should handle this signal if they want
429 * to display a context menu on the toolbar. The context-menu should
430 * appear at the coordinates given by @x and @y. The mouse button
431 * number is given by the @button parameter. If the menu was popped
432 * up using the keybaord, @button is -1.
434 * Return value: return %TRUE if the signal was handled, %FALSE if not
436 toolbar_signals[POPUP_CONTEXT_MENU] =
437 g_signal_new (I_("popup-context-menu"),
438 G_OBJECT_CLASS_TYPE (klass),
440 G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
441 _gtk_boolean_handled_accumulator, NULL,
442 _gtk_marshal_BOOLEAN__INT_INT_INT,
444 G_TYPE_INT, G_TYPE_INT,
448 * GtkToolbar::focus-home-or-end:
449 * @toolbar: the #GtkToolbar which emitted the signal
450 * @focus_home: %TRUE if the first item should be focused
452 * A keybinding signal used internally by GTK+. This signal can't
453 * be used in application code
455 * Return value: %TRUE if the signal was handled, %FALSE if not
457 toolbar_signals[FOCUS_HOME_OR_END] =
458 g_signal_new_class_handler (I_("focus-home-or-end"),
459 G_OBJECT_CLASS_TYPE (klass),
460 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
461 G_CALLBACK (gtk_toolbar_focus_home_or_end),
463 _gtk_marshal_BOOLEAN__BOOLEAN,
468 g_object_class_override_property (gobject_class,
472 g_object_class_install_property (gobject_class,
474 g_param_spec_enum ("toolbar-style",
476 P_("How to draw the toolbar"),
477 GTK_TYPE_TOOLBAR_STYLE,
478 DEFAULT_TOOLBAR_STYLE,
479 GTK_PARAM_READWRITE));
480 g_object_class_install_property (gobject_class,
482 g_param_spec_boolean ("show-arrow",
484 P_("If an arrow should be shown if the toolbar doesn't fit"),
486 GTK_PARAM_READWRITE));
489 * GtkToolbar:icon-size:
491 * The size of the icons in a toolbar is normally determined by
492 * the toolbar-icon-size setting. When this property is set, it
493 * overrides the setting.
495 * This should only be used for special-purpose toolbars, normal
496 * application toolbars should respect the user preferences for the
501 g_object_class_install_property (gobject_class,
503 g_param_spec_int ("icon-size",
505 P_("Size of icons in this toolbar"),
508 GTK_PARAM_READWRITE));
511 * GtkToolbar:icon-size-set:
513 * Is %TRUE if the icon-size property has been set.
517 g_object_class_install_property (gobject_class,
519 g_param_spec_boolean ("icon-size-set",
521 P_("Whether the icon-size property has been set"),
523 GTK_PARAM_READWRITE));
525 /* child properties */
526 gtk_container_class_install_child_property (container_class,
528 g_param_spec_boolean ("expand",
530 P_("Whether the item should receive extra space when the toolbar grows"),
532 GTK_PARAM_READWRITE));
534 gtk_container_class_install_child_property (container_class,
535 CHILD_PROP_HOMOGENEOUS,
536 g_param_spec_boolean ("homogeneous",
538 P_("Whether the item should be the same size as other homogeneous items"),
540 GTK_PARAM_READWRITE));
542 /* style properties */
543 gtk_widget_class_install_style_property (widget_class,
544 g_param_spec_int ("space-size",
546 P_("Size of spacers"),
550 GTK_PARAM_READABLE));
552 gtk_widget_class_install_style_property (widget_class,
553 g_param_spec_int ("internal-padding",
554 P_("Internal padding"),
555 P_("Amount of border space between the toolbar shadow and the buttons"),
559 GTK_PARAM_READABLE));
561 gtk_widget_class_install_style_property (widget_class,
562 g_param_spec_int ("max-child-expand",
563 P_("Maximum child expand"),
564 P_("Maximum amount of space an expandable item will be given"),
568 GTK_PARAM_READABLE));
570 gtk_widget_class_install_style_property (widget_class,
571 g_param_spec_enum ("space-style",
573 P_("Whether spacers are vertical lines or just blank"),
574 GTK_TYPE_TOOLBAR_SPACE_STYLE,
576 GTK_PARAM_READABLE));
578 gtk_widget_class_install_style_property (widget_class,
579 g_param_spec_enum ("button-relief",
581 P_("Type of bevel around toolbar buttons"),
582 GTK_TYPE_RELIEF_STYLE,
584 GTK_PARAM_READABLE));
585 gtk_widget_class_install_style_property (widget_class,
586 g_param_spec_enum ("shadow-type",
588 P_("Style of bevel around the toolbar"),
589 GTK_TYPE_SHADOW_TYPE,
591 GTK_PARAM_READABLE));
593 binding_set = gtk_binding_set_by_class (klass);
595 add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
596 add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
597 add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
598 add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
600 gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, 0,
601 "focus-home-or-end", 1,
602 G_TYPE_BOOLEAN, TRUE);
603 gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
604 "focus-home-or-end", 1,
605 G_TYPE_BOOLEAN, TRUE);
606 gtk_binding_entry_add_signal (binding_set, GDK_KP_End, 0,
607 "focus-home-or-end", 1,
608 G_TYPE_BOOLEAN, FALSE);
609 gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
610 "focus-home-or-end", 1,
611 G_TYPE_BOOLEAN, FALSE);
613 add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
614 add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
616 g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));
620 toolbar_tool_shell_iface_init (GtkToolShellIface *iface)
622 iface->get_icon_size = toolbar_get_icon_size;
623 iface->get_orientation = toolbar_get_orientation;
624 iface->get_style = toolbar_get_style;
625 iface->get_relief_style = toolbar_get_relief_style;
626 iface->rebuild_menu = toolbar_rebuild_menu;
630 gtk_toolbar_init (GtkToolbar *toolbar)
632 GtkToolbarPrivate *priv;
634 gtk_widget_set_can_focus (GTK_WIDGET (toolbar), FALSE);
635 gtk_widget_set_has_window (GTK_WIDGET (toolbar), FALSE);
637 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
639 toolbar->orientation = GTK_ORIENTATION_HORIZONTAL;
640 toolbar->style = DEFAULT_TOOLBAR_STYLE;
641 toolbar->icon_size = DEFAULT_ICON_SIZE;
642 priv->animation = DEFAULT_ANIMATION_STATE;
643 toolbar->tooltips = NULL; /* FIXME: Remove this */
645 priv->arrow_button = gtk_toggle_button_new ();
646 g_signal_connect (priv->arrow_button, "button-press-event",
647 G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar);
648 g_signal_connect (priv->arrow_button, "clicked",
649 G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar);
650 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
651 get_button_relief (toolbar));
653 priv->api_mode = DONT_KNOW;
655 gtk_button_set_focus_on_click (GTK_BUTTON (priv->arrow_button), FALSE);
657 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
658 gtk_widget_set_name (priv->arrow, "gtk-toolbar-arrow");
659 gtk_widget_show (priv->arrow);
660 gtk_container_add (GTK_CONTAINER (priv->arrow_button), priv->arrow);
662 gtk_widget_set_parent (priv->arrow_button, GTK_WIDGET (toolbar));
664 /* which child position a drop will occur at */
666 priv->show_arrow = TRUE;
667 priv->settings = NULL;
669 priv->max_homogeneous_pixels = -1;
671 priv->timer = g_timer_new ();
675 gtk_toolbar_set_property (GObject *object,
680 GtkToolbar *toolbar = GTK_TOOLBAR (object);
684 case PROP_ORIENTATION:
685 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0,
686 g_value_get_enum (value));
688 case PROP_TOOLBAR_STYLE:
689 gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
691 case PROP_SHOW_ARROW:
692 gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
695 gtk_toolbar_set_icon_size (toolbar, g_value_get_int (value));
697 case PROP_ICON_SIZE_SET:
698 if (g_value_get_boolean (value))
699 toolbar->icon_size_set = TRUE;
701 gtk_toolbar_unset_icon_size (toolbar);
704 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
710 gtk_toolbar_get_property (GObject *object,
715 GtkToolbar *toolbar = GTK_TOOLBAR (object);
716 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
720 case PROP_ORIENTATION:
721 g_value_set_enum (value, toolbar->orientation);
723 case PROP_TOOLBAR_STYLE:
724 g_value_set_enum (value, toolbar->style);
726 case PROP_SHOW_ARROW:
727 g_value_set_boolean (value, priv->show_arrow);
730 g_value_set_int (value, gtk_toolbar_get_icon_size (toolbar));
732 case PROP_ICON_SIZE_SET:
733 g_value_set_boolean (value, toolbar->icon_size_set);
736 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
742 gtk_toolbar_map (GtkWidget *widget)
744 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
746 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->map (widget);
748 if (priv->event_window)
749 gdk_window_show_unraised (priv->event_window);
753 gtk_toolbar_unmap (GtkWidget *widget)
755 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
757 if (priv->event_window)
758 gdk_window_hide (priv->event_window);
760 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unmap (widget);
764 gtk_toolbar_realize (GtkWidget *widget)
766 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
767 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
769 GdkWindowAttr attributes;
770 gint attributes_mask;
773 gtk_widget_set_realized (widget, TRUE);
775 border_width = GTK_CONTAINER (widget)->border_width;
777 attributes.wclass = GDK_INPUT_ONLY;
778 attributes.window_type = GDK_WINDOW_CHILD;
779 attributes.x = widget->allocation.x + border_width;
780 attributes.y = widget->allocation.y + border_width;
781 attributes.width = widget->allocation.width - border_width * 2;
782 attributes.height = widget->allocation.height - border_width * 2;
783 attributes.event_mask = gtk_widget_get_events (widget);
784 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
785 GDK_BUTTON_RELEASE_MASK |
786 GDK_ENTER_NOTIFY_MASK |
787 GDK_LEAVE_NOTIFY_MASK);
789 attributes_mask = GDK_WA_X | GDK_WA_Y;
791 widget->window = gtk_widget_get_parent_window (widget);
792 g_object_ref (widget->window);
793 widget->style = gtk_style_attach (widget->style, widget->window);
795 priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
796 &attributes, attributes_mask);
797 gdk_window_set_user_data (priv->event_window, toolbar);
801 gtk_toolbar_unrealize (GtkWidget *widget)
803 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
805 if (priv->event_window)
807 gdk_window_set_user_data (priv->event_window, NULL);
808 gdk_window_destroy (priv->event_window);
809 priv->event_window = NULL;
812 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize (widget);
816 gtk_toolbar_expose (GtkWidget *widget,
817 GdkEventExpose *event)
819 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
820 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
825 border_width = GTK_CONTAINER (widget)->border_width;
827 if (gtk_widget_is_drawable (widget))
829 gtk_paint_box (widget->style,
831 gtk_widget_get_state (widget),
832 get_shadow_type (toolbar),
833 &event->area, widget, "toolbar",
834 border_width + widget->allocation.x,
835 border_width + widget->allocation.y,
836 widget->allocation.width - 2 * border_width,
837 widget->allocation.height - 2 * border_width);
840 for (list = priv->content; list != NULL; list = list->next)
842 ToolbarContent *content = list->data;
844 toolbar_content_expose (content, GTK_CONTAINER (widget), event);
847 gtk_container_propagate_expose (GTK_CONTAINER (widget),
855 gtk_toolbar_size_request (GtkWidget *widget,
856 GtkRequisition *requisition)
858 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
859 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
861 gint max_child_height;
862 gint max_child_width;
863 gint max_homogeneous_child_width;
864 gint max_homogeneous_child_height;
865 gint homogeneous_size;
867 gint pack_front_size;
869 GtkRequisition arrow_requisition;
871 max_homogeneous_child_width = 0;
872 max_homogeneous_child_height = 0;
874 max_child_height = 0;
875 for (list = priv->content; list != NULL; list = list->next)
877 GtkRequisition requisition;
878 ToolbarContent *content = list->data;
880 if (!toolbar_content_visible (content, toolbar))
883 toolbar_content_size_request (content, toolbar, &requisition);
885 max_child_width = MAX (max_child_width, requisition.width);
886 max_child_height = MAX (max_child_height, requisition.height);
888 if (toolbar_content_is_homogeneous (content, toolbar))
890 max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
891 max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
895 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
896 homogeneous_size = max_homogeneous_child_width;
898 homogeneous_size = max_homogeneous_child_height;
901 for (list = priv->content; list != NULL; list = list->next)
903 ToolbarContent *content = list->data;
906 if (!toolbar_content_visible (content, toolbar))
909 if (toolbar_content_is_homogeneous (content, toolbar))
911 size = homogeneous_size;
915 GtkRequisition requisition;
917 toolbar_content_size_request (content, toolbar, &requisition);
919 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
920 size = requisition.width;
922 size = requisition.height;
925 pack_front_size += size;
928 if (priv->show_arrow && priv->api_mode == NEW_API)
930 gtk_widget_size_request (priv->arrow_button, &arrow_requisition);
932 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
933 long_req = arrow_requisition.width;
935 long_req = arrow_requisition.height;
937 /* There is no point requesting space for the arrow if that would take
938 * up more space than all the items combined
940 long_req = MIN (long_req, pack_front_size);
944 arrow_requisition.height = 0;
945 arrow_requisition.width = 0;
947 long_req = pack_front_size;
950 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
952 requisition->width = long_req;
953 requisition->height = MAX (max_child_height, arrow_requisition.height);
957 requisition->height = long_req;
958 requisition->width = MAX (max_child_width, arrow_requisition.width);
962 ipadding = get_internal_padding (toolbar);
964 requisition->width += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
965 requisition->height += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
967 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
969 requisition->width += 2 * widget->style->xthickness;
970 requisition->height += 2 * widget->style->ythickness;
973 toolbar->button_maxw = max_homogeneous_child_width;
974 toolbar->button_maxh = max_homogeneous_child_height;
978 position (GtkToolbar *toolbar,
985 if (! GTK_TOOLBAR_GET_PRIVATE (toolbar)->animation)
988 if (elapsed <= ACCEL_THRESHOLD)
990 n_pixels = SLIDE_SPEED * elapsed;
994 /* The formula is a second degree polynomial in
995 * @elapsed that has the line SLIDE_SPEED * @elapsed
996 * as tangent for @elapsed == ACCEL_THRESHOLD.
997 * This makes @n_pixels a smooth function of elapsed time.
999 n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
1000 SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
1004 return MIN (from + n_pixels, to);
1006 return MAX (from - n_pixels, to);
1010 compute_intermediate_allocation (GtkToolbar *toolbar,
1011 const GtkAllocation *start,
1012 const GtkAllocation *goal,
1013 GtkAllocation *intermediate)
1015 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1016 gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
1018 intermediate->x = position (toolbar, start->x, goal->x, elapsed);
1019 intermediate->y = position (toolbar, start->y, goal->y, elapsed);
1020 intermediate->width = position (toolbar, start->x + start->width,
1021 goal->x + goal->width,
1022 elapsed) - intermediate->x;
1023 intermediate->height = position (toolbar, start->y + start->height,
1024 goal->y + goal->height,
1025 elapsed) - intermediate->y;
1029 fixup_allocation_for_rtl (gint total_size,
1030 GtkAllocation *allocation)
1032 allocation->x += (total_size - (2 * allocation->x + allocation->width));
1036 fixup_allocation_for_vertical (GtkAllocation *allocation)
1040 tmp = allocation->x;
1041 allocation->x = allocation->y;
1042 allocation->y = tmp;
1044 tmp = allocation->width;
1045 allocation->width = allocation->height;
1046 allocation->height = tmp;
1050 get_item_size (GtkToolbar *toolbar,
1051 ToolbarContent *content)
1053 GtkRequisition requisition;
1055 toolbar_content_size_request (content, toolbar, &requisition);
1057 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1059 if (toolbar_content_is_homogeneous (content, toolbar))
1060 return toolbar->button_maxw;
1062 return requisition.width;
1066 if (toolbar_content_is_homogeneous (content, toolbar))
1067 return toolbar->button_maxh;
1069 return requisition.height;
1074 slide_idle_handler (gpointer data)
1076 GtkToolbar *toolbar = data;
1077 GtkToolbarPrivate *priv;
1080 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1082 if (priv->need_sync)
1085 priv->need_sync = FALSE;
1088 for (list = priv->content; list != NULL; list = list->next)
1090 ToolbarContent *content = list->data;
1092 GtkAllocation goal_allocation;
1093 GtkAllocation allocation;
1096 state = toolbar_content_get_state (content);
1097 toolbar_content_get_goal_allocation (content, &goal_allocation);
1098 toolbar_content_get_allocation (content, &allocation);
1102 if (state == NOT_ALLOCATED)
1104 /* an unallocated item means that size allocate has to
1105 * called at least once more
1110 /* An invisible item with a goal allocation of
1111 * 0 is already at its goal.
1113 if ((state == NORMAL || state == OVERFLOWN) &&
1114 ((goal_allocation.width != 0 &&
1115 goal_allocation.height != 0) ||
1116 toolbar_content_child_visible (content)))
1118 if ((goal_allocation.x != allocation.x ||
1119 goal_allocation.y != allocation.y ||
1120 goal_allocation.width != allocation.width ||
1121 goal_allocation.height != allocation.height))
1123 /* An item is not in its right position yet. Note
1124 * that OVERFLOWN items do get an allocation in
1125 * gtk_toolbar_size_allocate(). This way you can see
1126 * them slide back in when you drag an item off the
1133 if (toolbar_content_is_placeholder (content) &&
1134 toolbar_content_disappearing (content) &&
1135 toolbar_content_child_visible (content))
1137 /* A disappearing placeholder is still visible.
1145 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1151 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1153 priv->is_sliding = FALSE;
1160 rect_within (GtkAllocation *a1,
1163 return (a1->x >= a2->x &&
1164 a1->x + a1->width <= a2->x + a2->width &&
1166 a1->y + a1->height <= a2->y + a2->height);
1170 gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
1172 GtkWidget *widget = GTK_WIDGET (toolbar);
1173 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1181 /* Start the sliding. This function copies the allocation of every
1182 * item into content->start_allocation. For items that haven't
1183 * been allocated yet, we calculate their position and save that
1184 * in start_allocatino along with zero width and zero height.
1186 * FIXME: It would be nice if we could share this code with
1187 * the equivalent in gtk_widget_size_allocate().
1189 priv->is_sliding = TRUE;
1192 priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
1194 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1195 vertical = (toolbar->orientation == GTK_ORIENTATION_VERTICAL);
1196 border_width = get_internal_padding (toolbar) + GTK_CONTAINER (toolbar)->border_width;
1200 cur_x = widget->allocation.width - border_width - widget->style->xthickness;
1201 cur_y = widget->allocation.height - border_width - widget->style->ythickness;
1205 cur_x = border_width + widget->style->xthickness;
1206 cur_y = border_width + widget->style->ythickness;
1209 cur_x += widget->allocation.x;
1210 cur_y += widget->allocation.y;
1212 for (list = priv->content; list != NULL; list = list->next)
1214 ToolbarContent *content = list->data;
1215 GtkAllocation new_start_allocation;
1216 GtkAllocation item_allocation;
1219 state = toolbar_content_get_state (content);
1220 toolbar_content_get_allocation (content, &item_allocation);
1222 if ((state == NORMAL &&
1223 rect_within (&item_allocation, &(widget->allocation))) ||
1226 new_start_allocation = item_allocation;
1230 new_start_allocation.x = cur_x;
1231 new_start_allocation.y = cur_y;
1235 new_start_allocation.width = widget->allocation.width -
1236 2 * border_width - 2 * widget->style->xthickness;
1237 new_start_allocation.height = 0;
1241 new_start_allocation.width = 0;
1242 new_start_allocation.height = widget->allocation.height -
1243 2 * border_width - 2 * widget->style->ythickness;
1248 cur_y = new_start_allocation.y + new_start_allocation.height;
1250 cur_x = new_start_allocation.x;
1252 cur_x = new_start_allocation.x + new_start_allocation.width;
1254 toolbar_content_set_start_allocation (content, &new_start_allocation);
1257 /* This resize will run before the first idle handler. This
1258 * will make sure that items get the right goal allocation
1259 * so that the idle handler will not immediately return
1262 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1263 g_timer_reset (priv->timer);
1267 gtk_toolbar_stop_sliding (GtkToolbar *toolbar)
1269 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1271 if (priv->is_sliding)
1275 priv->is_sliding = FALSE;
1279 g_source_remove (priv->idle_id);
1283 list = priv->content;
1286 ToolbarContent *content = list->data;
1289 if (toolbar_content_is_placeholder (content))
1291 toolbar_content_remove (content, toolbar);
1292 toolbar_content_free (content);
1296 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1301 remove_item (GtkWidget *menu_item,
1304 gtk_container_remove (GTK_CONTAINER (menu_item->parent), menu_item);
1308 menu_deactivated (GtkWidget *menu,
1309 GtkToolbar *toolbar)
1311 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1312 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->arrow_button), FALSE);
1316 menu_detached (GtkWidget *toolbar,
1319 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1324 rebuild_menu (GtkToolbar *toolbar)
1326 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1327 GList *list, *children;
1331 priv->menu = GTK_MENU (gtk_menu_new());
1332 gtk_menu_attach_to_widget (priv->menu,
1333 GTK_WIDGET (toolbar),
1336 g_signal_connect (priv->menu, "deactivate",
1337 G_CALLBACK (menu_deactivated), toolbar);
1340 gtk_container_foreach (GTK_CONTAINER (priv->menu), remove_item, NULL);
1342 for (list = priv->content; list != NULL; list = list->next)
1344 ToolbarContent *content = list->data;
1346 if (toolbar_content_get_state (content) == OVERFLOWN &&
1347 !toolbar_content_is_placeholder (content))
1349 GtkWidget *menu_item = toolbar_content_retrieve_menu_item (content);
1353 g_assert (GTK_IS_MENU_ITEM (menu_item));
1354 gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item);
1359 /* Remove leading and trailing separator items */
1360 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1363 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1365 GtkWidget *child = list->data;
1367 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1370 g_list_free (children);
1372 /* Regenerate the list of children so we don't try to remove items twice */
1373 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1375 list = g_list_last (children);
1376 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1378 GtkWidget *child = list->data;
1380 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1383 g_list_free (children);
1385 priv->need_rebuild = FALSE;
1389 gtk_toolbar_size_allocate (GtkWidget *widget,
1390 GtkAllocation *allocation)
1392 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1393 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1394 GtkAllocation *allocations;
1395 ItemState *new_states;
1396 GtkAllocation arrow_allocation;
1398 gint size, pos, short_size;
1401 gboolean need_arrow;
1402 gint n_expand_items;
1404 gint available_size;
1407 GtkRequisition arrow_requisition;
1408 gboolean overflowing;
1409 gboolean size_changed;
1411 GtkAllocation item_area;
1412 GtkShadowType shadow_type;
1414 size_changed = FALSE;
1415 if (widget->allocation.x != allocation->x ||
1416 widget->allocation.y != allocation->y ||
1417 widget->allocation.width != allocation->width ||
1418 widget->allocation.height != allocation->height)
1420 size_changed = TRUE;
1424 gtk_toolbar_stop_sliding (toolbar);
1426 widget->allocation = *allocation;
1428 border_width = GTK_CONTAINER (toolbar)->border_width;
1430 if (gtk_widget_get_realized (widget))
1432 gdk_window_move_resize (priv->event_window,
1433 allocation->x + border_width,
1434 allocation->y + border_width,
1435 allocation->width - border_width * 2,
1436 allocation->height - border_width * 2);
1439 border_width += get_internal_padding (toolbar);
1441 gtk_widget_get_child_requisition (GTK_WIDGET (priv->arrow_button),
1442 &arrow_requisition);
1444 shadow_type = get_shadow_type (toolbar);
1446 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1448 available_size = size = allocation->width - 2 * border_width;
1449 short_size = allocation->height - 2 * border_width;
1450 arrow_size = arrow_requisition.width;
1452 if (shadow_type != GTK_SHADOW_NONE)
1454 available_size -= 2 * widget->style->xthickness;
1455 short_size -= 2 * widget->style->ythickness;
1460 available_size = size = allocation->height - 2 * border_width;
1461 short_size = allocation->width - 2 * border_width;
1462 arrow_size = arrow_requisition.height;
1464 if (shadow_type != GTK_SHADOW_NONE)
1466 available_size -= 2 * widget->style->ythickness;
1467 short_size -= 2 * widget->style->xthickness;
1471 n_items = g_list_length (priv->content);
1472 allocations = g_new0 (GtkAllocation, n_items);
1473 new_states = g_new0 (ItemState, n_items);
1477 for (list = priv->content; list != NULL; list = list->next)
1479 ToolbarContent *content = list->data;
1481 if (toolbar_content_visible (content, toolbar))
1483 needed_size += get_item_size (toolbar, content);
1485 /* Do we need an arrow?
1487 * Assume we don't, and see if any non-separator item with a
1488 * proxy menu item is then going to overflow.
1490 if (needed_size > available_size &&
1493 priv->api_mode == NEW_API &&
1494 toolbar_content_has_proxy_menu_item (content) &&
1495 !toolbar_content_is_separator (content))
1503 size = available_size - arrow_size;
1505 size = available_size;
1507 /* calculate widths and states of items */
1508 overflowing = FALSE;
1509 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1511 ToolbarContent *content = list->data;
1514 if (!toolbar_content_visible (content, toolbar))
1516 new_states[i] = HIDDEN;
1520 item_size = get_item_size (toolbar, content);
1521 if (item_size <= size && !overflowing)
1524 allocations[i].width = item_size;
1525 new_states[i] = NORMAL;
1530 new_states[i] = OVERFLOWN;
1531 allocations[i].width = item_size;
1535 /* calculate width of arrow */
1538 arrow_allocation.width = arrow_size;
1539 arrow_allocation.height = MAX (short_size, 1);
1542 /* expand expandable items */
1544 /* We don't expand when there is an overflow menu, because that leads to
1545 * weird jumps when items get moved to the overflow menu and the expanding
1546 * items suddenly get a lot of extra space
1550 gint max_child_expand;
1553 for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
1555 ToolbarContent *content = list->data;
1557 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1561 max_child_expand = get_max_child_expand (toolbar);
1562 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1564 ToolbarContent *content = list->data;
1566 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1568 gint extra = size / n_expand_items;
1569 if (size % n_expand_items != 0)
1572 if (extra > max_child_expand)
1573 extra = max_child_expand;
1575 allocations[i].width += extra;
1581 g_assert (n_expand_items == 0);
1584 /* position items */
1586 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1588 /* both NORMAL and OVERFLOWN items get a position. This ensures
1589 * that sliding will work for OVERFLOWN items too
1591 if (new_states[i] == NORMAL ||
1592 new_states[i] == OVERFLOWN)
1594 allocations[i].x = pos;
1595 allocations[i].y = border_width;
1596 allocations[i].height = short_size;
1598 pos += allocations[i].width;
1602 /* position arrow */
1605 arrow_allocation.x = available_size - border_width - arrow_allocation.width;
1606 arrow_allocation.y = border_width;
1609 item_area.x = border_width;
1610 item_area.y = border_width;
1611 item_area.width = available_size - (need_arrow? arrow_size : 0);
1612 item_area.height = short_size;
1614 /* fix up allocations in the vertical or RTL cases */
1615 if (toolbar->orientation == GTK_ORIENTATION_VERTICAL)
1617 for (i = 0; i < n_items; ++i)
1618 fixup_allocation_for_vertical (&(allocations[i]));
1621 fixup_allocation_for_vertical (&arrow_allocation);
1623 fixup_allocation_for_vertical (&item_area);
1625 else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1627 for (i = 0; i < n_items; ++i)
1628 fixup_allocation_for_rtl (available_size, &(allocations[i]));
1631 fixup_allocation_for_rtl (available_size, &arrow_allocation);
1633 fixup_allocation_for_rtl (available_size, &item_area);
1636 /* translate the items by allocation->(x,y) */
1637 for (i = 0; i < n_items; ++i)
1639 allocations[i].x += allocation->x;
1640 allocations[i].y += allocation->y;
1642 if (shadow_type != GTK_SHADOW_NONE)
1644 allocations[i].x += widget->style->xthickness;
1645 allocations[i].y += widget->style->ythickness;
1651 arrow_allocation.x += allocation->x;
1652 arrow_allocation.y += allocation->y;
1654 if (shadow_type != GTK_SHADOW_NONE)
1656 arrow_allocation.x += widget->style->xthickness;
1657 arrow_allocation.y += widget->style->ythickness;
1661 item_area.x += allocation->x;
1662 item_area.y += allocation->y;
1663 if (shadow_type != GTK_SHADOW_NONE)
1665 item_area.x += widget->style->xthickness;
1666 item_area.y += widget->style->ythickness;
1669 /* did anything change? */
1670 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1672 ToolbarContent *content = list->data;
1674 if (toolbar_content_get_state (content) == NORMAL &&
1675 new_states[i] != NORMAL)
1677 /* an item disappeared and we didn't change size, so begin sliding */
1678 if (!size_changed && priv->api_mode == NEW_API)
1679 gtk_toolbar_begin_sliding (toolbar);
1683 /* finally allocate the items */
1684 if (priv->is_sliding)
1686 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1688 ToolbarContent *content = list->data;
1690 toolbar_content_set_goal_allocation (content, &(allocations[i]));
1694 elapsed = g_timer_elapsed (priv->timer, NULL);
1695 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1697 ToolbarContent *content = list->data;
1699 if (new_states[i] == OVERFLOWN ||
1700 new_states[i] == NORMAL)
1702 GtkAllocation alloc;
1703 GtkAllocation start_allocation = { 0, };
1704 GtkAllocation goal_allocation;
1706 if (priv->is_sliding)
1708 toolbar_content_get_start_allocation (content, &start_allocation);
1709 toolbar_content_get_goal_allocation (content, &goal_allocation);
1711 compute_intermediate_allocation (toolbar,
1716 priv->need_sync = TRUE;
1720 alloc = allocations[i];
1723 if (alloc.width <= 0 || alloc.height <= 0)
1725 toolbar_content_set_child_visible (content, toolbar, FALSE);
1729 if (!rect_within (&alloc, &item_area))
1731 toolbar_content_set_child_visible (content, toolbar, FALSE);
1732 toolbar_content_size_allocate (content, &alloc);
1736 toolbar_content_set_child_visible (content, toolbar, TRUE);
1737 toolbar_content_size_allocate (content, &alloc);
1743 toolbar_content_set_child_visible (content, toolbar, FALSE);
1746 toolbar_content_set_state (content, new_states[i]);
1749 if (priv->menu && priv->need_rebuild)
1750 rebuild_menu (toolbar);
1754 gtk_widget_size_allocate (GTK_WIDGET (priv->arrow_button),
1756 gtk_widget_show (GTK_WIDGET (priv->arrow_button));
1760 gtk_widget_hide (GTK_WIDGET (priv->arrow_button));
1762 if (priv->menu && gtk_widget_get_visible (GTK_WIDGET (priv->menu)))
1763 gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
1766 g_free (allocations);
1767 g_free (new_states);
1771 gtk_toolbar_update_button_relief (GtkToolbar *toolbar)
1773 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1774 GtkReliefStyle relief;
1776 relief = get_button_relief (toolbar);
1778 if (relief != gtk_button_get_relief (GTK_BUTTON (priv->arrow_button)))
1780 gtk_toolbar_reconfigured (toolbar);
1782 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), relief);
1787 gtk_toolbar_style_set (GtkWidget *widget,
1788 GtkStyle *prev_style)
1790 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
1792 priv->max_homogeneous_pixels = -1;
1794 if (gtk_widget_get_realized (widget))
1795 gtk_style_set_background (widget->style, widget->window, widget->state);
1798 gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
1802 gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
1803 GtkDirectionType dir)
1805 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1806 GList *result = NULL;
1810 /* generate list of children in reverse logical order */
1812 for (list = priv->content; list != NULL; list = list->next)
1814 ToolbarContent *content = list->data;
1817 widget = toolbar_content_get_widget (content);
1820 result = g_list_prepend (result, widget);
1823 result = g_list_prepend (result, priv->arrow_button);
1825 rtl = (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL);
1827 /* move in logical order when
1829 * - dir is TAB_FORWARD
1831 * - in RTL mode and moving left or up
1833 * - in LTR mode and moving right or down
1835 if (dir == GTK_DIR_TAB_FORWARD ||
1836 (rtl && (dir == GTK_DIR_UP || dir == GTK_DIR_LEFT)) ||
1837 (!rtl && (dir == GTK_DIR_DOWN || dir == GTK_DIR_RIGHT)))
1839 result = g_list_reverse (result);
1846 gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
1847 gboolean focus_home)
1849 GList *children, *list;
1850 GtkDirectionType dir = focus_home? GTK_DIR_RIGHT : GTK_DIR_LEFT;
1852 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1854 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1856 children = g_list_reverse (children);
1858 dir = (dir == GTK_DIR_RIGHT)? GTK_DIR_LEFT : GTK_DIR_RIGHT;
1861 for (list = children; list != NULL; list = list->next)
1863 GtkWidget *child = list->data;
1865 if (GTK_CONTAINER (toolbar)->focus_child == child)
1868 if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1872 g_list_free (children);
1877 /* Keybinding handler. This function is called when the user presses
1878 * Ctrl TAB or an arrow key.
1881 gtk_toolbar_move_focus (GtkWidget *widget,
1882 GtkDirectionType dir)
1884 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1885 GtkContainer *container = GTK_CONTAINER (toolbar);
1887 gboolean try_focus = FALSE;
1890 if (container->focus_child &&
1891 gtk_widget_child_focus (container->focus_child, dir))
1896 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1898 for (list = children; list != NULL; list = list->next)
1900 GtkWidget *child = list->data;
1902 if (try_focus && gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1905 if (child == GTK_CONTAINER (toolbar)->focus_child)
1909 g_list_free (children);
1912 /* The focus handler for the toolbar. It called when the user presses
1913 * TAB or otherwise tries to focus the toolbar.
1916 gtk_toolbar_focus (GtkWidget *widget,
1917 GtkDirectionType dir)
1919 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1920 GList *children, *list;
1921 gboolean result = FALSE;
1923 /* if focus is already somewhere inside the toolbar then return FALSE.
1924 * The only way focus can stay inside the toolbar is when the user presses
1925 * arrow keys or Ctrl TAB (both of which are handled by the
1926 * gtk_toolbar_move_focus() keybinding function.
1928 if (GTK_CONTAINER (widget)->focus_child)
1931 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1933 for (list = children; list != NULL; list = list->next)
1935 GtkWidget *child = list->data;
1937 if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
1944 g_list_free (children);
1949 static GtkSettings *
1950 toolbar_get_settings (GtkToolbar *toolbar)
1952 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1953 return priv->settings;
1957 style_change_notify (GtkToolbar *toolbar)
1959 if (!toolbar->style_set)
1961 /* pretend it was set, then unset, thus reverting to new default */
1962 toolbar->style_set = TRUE;
1963 gtk_toolbar_unset_style (toolbar);
1968 icon_size_change_notify (GtkToolbar *toolbar)
1970 if (!toolbar->icon_size_set)
1972 /* pretend it was set, then unset, thus reverting to new default */
1973 toolbar->icon_size_set = TRUE;
1974 gtk_toolbar_unset_icon_size (toolbar);
1979 animation_change_notify (GtkToolbar *toolbar)
1981 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1982 GtkSettings *settings = toolbar_get_settings (toolbar);
1986 g_object_get (settings,
1987 "gtk-enable-animations", &animation,
1990 animation = DEFAULT_ANIMATION_STATE;
1992 priv->animation = animation;
1996 settings_change_notify (GtkSettings *settings,
1997 const GParamSpec *pspec,
1998 GtkToolbar *toolbar)
2000 if (! strcmp (pspec->name, "gtk-toolbar-style"))
2001 style_change_notify (toolbar);
2002 else if (! strcmp (pspec->name, "gtk-toolbar-icon-size"))
2003 icon_size_change_notify (toolbar);
2004 else if (! strcmp (pspec->name, "gtk-enable-animations"))
2005 animation_change_notify (toolbar);
2009 gtk_toolbar_screen_changed (GtkWidget *widget,
2010 GdkScreen *previous_screen)
2012 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2013 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2014 GtkSettings *old_settings = toolbar_get_settings (toolbar);
2015 GtkSettings *settings;
2017 if (gtk_widget_has_screen (GTK_WIDGET (toolbar)))
2018 settings = gtk_widget_get_settings (GTK_WIDGET (toolbar));
2022 if (settings == old_settings)
2027 g_signal_handler_disconnect (old_settings, priv->settings_connection);
2029 g_object_unref (old_settings);
2034 priv->settings_connection =
2035 g_signal_connect (settings, "notify",
2036 G_CALLBACK (settings_change_notify),
2039 priv->settings = g_object_ref (settings);
2042 priv->settings = NULL;
2044 style_change_notify (toolbar);
2045 icon_size_change_notify (toolbar);
2046 animation_change_notify (toolbar);
2050 find_drop_index (GtkToolbar *toolbar,
2054 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2055 GList *interesting_content;
2057 GtkOrientation orientation;
2058 GtkTextDirection direction;
2059 gint best_distance = G_MAXINT;
2063 ToolbarContent *best_content;
2064 GtkAllocation allocation;
2066 /* list items we care about wrt. drag and drop */
2067 interesting_content = NULL;
2068 for (list = priv->content; list != NULL; list = list->next)
2070 ToolbarContent *content = list->data;
2072 if (toolbar_content_get_state (content) == NORMAL)
2073 interesting_content = g_list_prepend (interesting_content, content);
2075 interesting_content = g_list_reverse (interesting_content);
2077 if (!interesting_content)
2080 orientation = toolbar->orientation;
2081 direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
2083 /* distance to first interesting item */
2084 best_content = interesting_content->data;
2085 toolbar_content_get_allocation (best_content, &allocation);
2087 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2091 if (direction == GTK_TEXT_DIR_LTR)
2094 pos = allocation.x + allocation.width;
2102 best_content = NULL;
2103 best_distance = ABS (pos - cursor);
2105 /* distance to far end of each item */
2106 for (list = interesting_content; list != NULL; list = list->next)
2108 ToolbarContent *content = list->data;
2110 toolbar_content_get_allocation (content, &allocation);
2112 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2114 if (direction == GTK_TEXT_DIR_LTR)
2115 pos = allocation.x + allocation.width;
2121 pos = allocation.y + allocation.height;
2124 distance = ABS (pos - cursor);
2126 if (distance < best_distance)
2128 best_distance = distance;
2129 best_content = content;
2133 g_list_free (interesting_content);
2138 return g_list_index (priv->content, best_content) + 1;
2142 reset_all_placeholders (GtkToolbar *toolbar)
2144 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2147 for (list = priv->content; list != NULL; list = list->next)
2149 ToolbarContent *content = list->data;
2150 if (toolbar_content_is_placeholder (content))
2151 toolbar_content_set_disappearing (content, TRUE);
2156 physical_to_logical (GtkToolbar *toolbar,
2159 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2163 g_assert (physical >= 0);
2166 for (list = priv->content; list && physical > 0; list = list->next)
2168 ToolbarContent *content = list->data;
2170 if (!toolbar_content_is_placeholder (content))
2175 g_assert (physical == 0);
2181 logical_to_physical (GtkToolbar *toolbar,
2184 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2188 g_assert (logical >= 0);
2191 for (list = priv->content; list; list = list->next)
2193 ToolbarContent *content = list->data;
2195 if (!toolbar_content_is_placeholder (content))
2205 g_assert (logical == 0);
2211 * gtk_toolbar_set_drop_highlight_item:
2212 * @toolbar: a #GtkToolbar
2213 * @tool_item: (allow-none): a #GtkToolItem, or %NULL to turn of highlighting
2214 * @index_: a position on @toolbar
2216 * Highlights @toolbar to give an idea of what it would look like
2217 * if @item was added to @toolbar at the position indicated by @index_.
2218 * If @item is %NULL, highlighting is turned off. In that case @index_
2221 * The @tool_item passed to this function must not be part of any widget
2222 * hierarchy. When an item is set as drop highlight item it can not
2223 * added to any widget hierarchy or used as highlight item for another
2229 gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar,
2230 GtkToolItem *tool_item,
2233 ToolbarContent *content;
2234 GtkToolbarPrivate *priv;
2236 GtkRequisition requisition;
2237 GtkRequisition old_requisition;
2238 gboolean restart_sliding;
2240 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2241 g_return_if_fail (tool_item == NULL || GTK_IS_TOOL_ITEM (tool_item));
2243 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2247 if (priv->highlight_tool_item)
2249 gtk_widget_unparent (GTK_WIDGET (priv->highlight_tool_item));
2250 g_object_unref (priv->highlight_tool_item);
2251 priv->highlight_tool_item = NULL;
2254 reset_all_placeholders (toolbar);
2255 gtk_toolbar_begin_sliding (toolbar);
2259 n_items = gtk_toolbar_get_n_items (toolbar);
2260 if (index_ < 0 || index_ > n_items)
2263 if (tool_item != priv->highlight_tool_item)
2265 if (priv->highlight_tool_item)
2266 g_object_unref (priv->highlight_tool_item);
2268 g_object_ref_sink (tool_item);
2270 priv->highlight_tool_item = tool_item;
2272 gtk_widget_set_parent (GTK_WIDGET (priv->highlight_tool_item),
2273 GTK_WIDGET (toolbar));
2276 index_ = logical_to_physical (toolbar, index_);
2278 content = g_list_nth_data (priv->content, index_);
2282 ToolbarContent *prev_content;
2284 prev_content = g_list_nth_data (priv->content, index_ - 1);
2286 if (prev_content && toolbar_content_is_placeholder (prev_content))
2287 content = prev_content;
2290 if (!content || !toolbar_content_is_placeholder (content))
2292 GtkWidget *placeholder;
2294 placeholder = GTK_WIDGET (gtk_separator_tool_item_new ());
2296 content = toolbar_content_new_tool_item (toolbar,
2297 GTK_TOOL_ITEM (placeholder),
2299 gtk_widget_show (placeholder);
2303 g_assert (toolbar_content_is_placeholder (content));
2305 gtk_widget_size_request (GTK_WIDGET (priv->highlight_tool_item),
2308 toolbar_content_set_expand (content, gtk_tool_item_get_expand (tool_item));
2310 restart_sliding = FALSE;
2311 toolbar_content_size_request (content, toolbar, &old_requisition);
2312 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2314 requisition.height = -1;
2315 if (requisition.width != old_requisition.width)
2316 restart_sliding = TRUE;
2320 requisition.width = -1;
2321 if (requisition.height != old_requisition.height)
2322 restart_sliding = TRUE;
2325 if (toolbar_content_disappearing (content))
2326 restart_sliding = TRUE;
2328 reset_all_placeholders (toolbar);
2329 toolbar_content_set_disappearing (content, FALSE);
2331 toolbar_content_set_size_request (content,
2332 requisition.width, requisition.height);
2334 if (restart_sliding)
2335 gtk_toolbar_begin_sliding (toolbar);
2339 gtk_toolbar_get_child_property (GtkContainer *container,
2345 GtkToolItem *item = GTK_TOOL_ITEM (child);
2347 switch (property_id)
2349 case CHILD_PROP_HOMOGENEOUS:
2350 g_value_set_boolean (value, gtk_tool_item_get_homogeneous (item));
2353 case CHILD_PROP_EXPAND:
2354 g_value_set_boolean (value, gtk_tool_item_get_expand (item));
2358 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2364 gtk_toolbar_set_child_property (GtkContainer *container,
2367 const GValue *value,
2370 switch (property_id)
2372 case CHILD_PROP_HOMOGENEOUS:
2373 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2376 case CHILD_PROP_EXPAND:
2377 gtk_tool_item_set_expand (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2381 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2387 gtk_toolbar_show_all (GtkWidget *widget)
2389 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2392 for (list = priv->content; list != NULL; list = list->next)
2394 ToolbarContent *content = list->data;
2396 toolbar_content_show_all (content);
2399 gtk_widget_show (widget);
2403 gtk_toolbar_hide_all (GtkWidget *widget)
2405 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2408 for (list = priv->content; list != NULL; list = list->next)
2410 ToolbarContent *content = list->data;
2412 toolbar_content_hide_all (content);
2415 gtk_widget_hide (widget);
2419 gtk_toolbar_add (GtkContainer *container,
2422 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2424 gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
2428 gtk_toolbar_remove (GtkContainer *container,
2431 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2432 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2433 ToolbarContent *content_to_remove;
2436 content_to_remove = NULL;
2437 for (list = priv->content; list != NULL; list = list->next)
2439 ToolbarContent *content = list->data;
2442 child = toolbar_content_get_widget (content);
2443 if (child && child == widget)
2445 content_to_remove = content;
2450 g_return_if_fail (content_to_remove != NULL);
2452 toolbar_content_remove (content_to_remove, toolbar);
2453 toolbar_content_free (content_to_remove);
2457 gtk_toolbar_forall (GtkContainer *container,
2458 gboolean include_internals,
2459 GtkCallback callback,
2460 gpointer callback_data)
2462 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2463 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2466 g_return_if_fail (callback != NULL);
2468 list = priv->content;
2471 ToolbarContent *content = list->data;
2472 GList *next = list->next;
2474 if (include_internals || !toolbar_content_is_placeholder (content))
2476 GtkWidget *child = toolbar_content_get_widget (content);
2479 callback (child, callback_data);
2485 if (include_internals)
2486 callback (priv->arrow_button, callback_data);
2490 gtk_toolbar_child_type (GtkContainer *container)
2492 return GTK_TYPE_TOOL_ITEM;
2496 gtk_toolbar_reconfigured (GtkToolbar *toolbar)
2498 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2501 list = priv->content;
2504 ToolbarContent *content = list->data;
2505 GList *next = list->next;
2507 toolbar_content_toolbar_reconfigured (content, toolbar);
2514 gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
2515 GtkOrientation orientation)
2517 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2518 if (toolbar->orientation != orientation)
2520 toolbar->orientation = orientation;
2522 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2523 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2525 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2527 gtk_toolbar_reconfigured (toolbar);
2529 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2530 g_object_notify (G_OBJECT (toolbar), "orientation");
2535 gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
2536 GtkToolbarStyle style)
2538 if (toolbar->style != style)
2540 toolbar->style = style;
2542 gtk_toolbar_reconfigured (toolbar);
2544 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2545 g_object_notify (G_OBJECT (toolbar), "toolbar-style");
2550 menu_position_func (GtkMenu *menu,
2556 GtkToolbar *toolbar = GTK_TOOLBAR (user_data);
2557 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2559 GtkRequisition menu_req;
2560 GdkRectangle monitor;
2564 gtk_widget_size_request (priv->arrow_button, &req);
2565 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2567 screen = gtk_widget_get_screen (GTK_WIDGET (menu));
2568 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->arrow_button->window);
2569 if (monitor_num < 0)
2571 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2573 gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
2574 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2576 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2577 *x += priv->arrow_button->allocation.width - req.width;
2579 *x += req.width - menu_req.width;
2581 if ((*y + priv->arrow_button->allocation.height + menu_req.height) <= monitor.y + monitor.height)
2582 *y += priv->arrow_button->allocation.height;
2583 else if ((*y - menu_req.height) >= monitor.y)
2584 *y -= menu_req.height;
2585 else if (monitor.y + monitor.height - (*y + priv->arrow_button->allocation.height) > *y)
2586 *y += priv->arrow_button->allocation.height;
2588 *y -= menu_req.height;
2592 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2593 *x += priv->arrow_button->allocation.width;
2595 *x -= menu_req.width;
2597 if (*y + menu_req.height > monitor.y + monitor.height &&
2598 *y + priv->arrow_button->allocation.height - monitor.y > monitor.y + monitor.height - *y)
2599 *y += priv->arrow_button->allocation.height - menu_req.height;
2606 show_menu (GtkToolbar *toolbar,
2607 GdkEventButton *event)
2609 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2611 rebuild_menu (toolbar);
2613 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2615 gtk_menu_popup (priv->menu, NULL, NULL,
2616 menu_position_func, toolbar,
2617 event? event->button : 0,
2618 event? event->time : gtk_get_current_event_time());
2622 gtk_toolbar_arrow_button_clicked (GtkWidget *button,
2623 GtkToolbar *toolbar)
2625 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2627 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) &&
2628 (!priv->menu || !gtk_widget_get_visible (GTK_WIDGET (priv->menu))))
2630 /* We only get here when the button is clicked with the keyboard,
2631 * because mouse button presses result in the menu being shown so
2632 * that priv->menu would be non-NULL and visible.
2634 show_menu (toolbar, NULL);
2635 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
2640 gtk_toolbar_arrow_button_press (GtkWidget *button,
2641 GdkEventButton *event,
2642 GtkToolbar *toolbar)
2644 show_menu (toolbar, event);
2645 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
2651 gtk_toolbar_button_press (GtkWidget *toolbar,
2652 GdkEventButton *event)
2654 if (event->button == 3)
2656 gboolean return_value;
2658 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2659 (int)event->x_root, (int)event->y_root, event->button,
2662 return return_value;
2669 gtk_toolbar_popup_menu (GtkWidget *toolbar)
2671 gboolean return_value;
2672 /* This function is the handler for the "popup menu" keybinding,
2673 * ie., it is called when the user presses Shift F10
2675 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2676 -1, -1, -1, &return_value);
2678 return return_value;
2684 * Creates a new toolbar.
2686 * Return Value: the newly-created toolbar.
2689 gtk_toolbar_new (void)
2691 GtkToolbar *toolbar;
2693 toolbar = g_object_new (GTK_TYPE_TOOLBAR, NULL);
2695 return GTK_WIDGET (toolbar);
2699 * gtk_toolbar_insert:
2700 * @toolbar: a #GtkToolbar
2701 * @item: a #GtkToolItem
2702 * @pos: the position of the new item
2704 * Insert a #GtkToolItem into the toolbar at position @pos. If @pos is
2705 * 0 the item is prepended to the start of the toolbar. If @pos is
2706 * negative, the item is appended to the end of the toolbar.
2711 gtk_toolbar_insert (GtkToolbar *toolbar,
2715 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2716 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
2719 pos = logical_to_physical (toolbar, pos);
2721 toolbar_content_new_tool_item (toolbar, item, FALSE, pos);
2725 * gtk_toolbar_get_item_index:
2726 * @toolbar: a #GtkToolbar
2727 * @item: a #GtkToolItem that is a child of @toolbar
2729 * Returns the position of @item on the toolbar, starting from 0.
2730 * It is an error if @item is not a child of the toolbar.
2732 * Return value: the position of item on the toolbar.
2737 gtk_toolbar_get_item_index (GtkToolbar *toolbar,
2740 GtkToolbarPrivate *priv;
2744 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2745 g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
2746 g_return_val_if_fail (GTK_WIDGET (item)->parent == GTK_WIDGET (toolbar), -1);
2748 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2751 for (list = priv->content; list != NULL; list = list->next)
2753 ToolbarContent *content = list->data;
2756 widget = toolbar_content_get_widget (content);
2758 if (item == GTK_TOOL_ITEM (widget))
2764 return physical_to_logical (toolbar, n);
2768 * gtk_toolbar_set_style:
2769 * @toolbar: a #GtkToolbar.
2770 * @style: the new style for @toolbar.
2772 * Alters the view of @toolbar to display either icons only, text only, or both.
2775 gtk_toolbar_set_style (GtkToolbar *toolbar,
2776 GtkToolbarStyle style)
2778 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2780 toolbar->style_set = TRUE;
2781 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2785 * gtk_toolbar_get_style:
2786 * @toolbar: a #GtkToolbar
2788 * Retrieves whether the toolbar has text, icons, or both . See
2789 * gtk_toolbar_set_style().
2791 * Return value: the current style of @toolbar
2794 gtk_toolbar_get_style (GtkToolbar *toolbar)
2796 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_TOOLBAR_STYLE);
2798 return toolbar->style;
2802 * gtk_toolbar_unset_style:
2803 * @toolbar: a #GtkToolbar
2805 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that
2806 * user preferences will be used to determine the toolbar style.
2809 gtk_toolbar_unset_style (GtkToolbar *toolbar)
2811 GtkToolbarStyle style;
2813 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2815 if (toolbar->style_set)
2817 GtkSettings *settings = toolbar_get_settings (toolbar);
2820 g_object_get (settings,
2821 "gtk-toolbar-style", &style,
2824 style = DEFAULT_TOOLBAR_STYLE;
2826 if (style != toolbar->style)
2827 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2829 toolbar->style_set = FALSE;
2834 * gtk_toolbar_get_n_items:
2835 * @toolbar: a #GtkToolbar
2837 * Returns the number of items on the toolbar.
2839 * Return value: the number of items on the toolbar
2844 gtk_toolbar_get_n_items (GtkToolbar *toolbar)
2846 GtkToolbarPrivate *priv;
2848 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2850 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2852 return physical_to_logical (toolbar, g_list_length (priv->content));
2856 * gtk_toolbar_get_nth_item:
2857 * @toolbar: a #GtkToolbar
2858 * @n: A position on the toolbar
2860 * Returns the @n<!-- -->'th item on @toolbar, or %NULL if the
2861 * toolbar does not contain an @n<!-- -->'th item.
2863 * Return value: The @n<!-- -->'th #GtkToolItem on @toolbar, or %NULL if there
2864 * isn't an @n<!-- -->'th item.
2869 gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
2872 GtkToolbarPrivate *priv;
2873 ToolbarContent *content;
2876 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
2878 n_items = gtk_toolbar_get_n_items (toolbar);
2880 if (n < 0 || n >= n_items)
2883 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2885 content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
2888 g_assert (!toolbar_content_is_placeholder (content));
2890 return GTK_TOOL_ITEM (toolbar_content_get_widget (content));
2894 * gtk_toolbar_get_icon_size:
2895 * @toolbar: a #GtkToolbar
2897 * Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size().
2899 * Return value: (type int): the current icon size for the icons on
2903 gtk_toolbar_get_icon_size (GtkToolbar *toolbar)
2905 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_ICON_SIZE);
2907 return toolbar->icon_size;
2911 * gtk_toolbar_get_relief_style:
2912 * @toolbar: a #GtkToolbar
2914 * Returns the relief style of buttons on @toolbar. See
2915 * gtk_button_set_relief().
2917 * Return value: The relief style of buttons on @toolbar.
2922 gtk_toolbar_get_relief_style (GtkToolbar *toolbar)
2924 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_RELIEF_NONE);
2926 return get_button_relief (toolbar);
2930 * gtk_toolbar_set_show_arrow:
2931 * @toolbar: a #GtkToolbar
2932 * @show_arrow: Whether to show an overflow menu
2934 * Sets whether to show an overflow menu when
2935 * @toolbar doesn't have room for all items on it. If %TRUE,
2936 * items that there are not room are available through an
2942 gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
2943 gboolean show_arrow)
2945 GtkToolbarPrivate *priv;
2947 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2949 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2950 show_arrow = show_arrow != FALSE;
2952 if (priv->show_arrow != show_arrow)
2954 priv->show_arrow = show_arrow;
2956 if (!priv->show_arrow)
2957 gtk_widget_hide (priv->arrow_button);
2959 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2960 g_object_notify (G_OBJECT (toolbar), "show-arrow");
2965 * gtk_toolbar_get_show_arrow:
2966 * @toolbar: a #GtkToolbar
2968 * Returns whether the toolbar has an overflow menu.
2969 * See gtk_toolbar_set_show_arrow().
2971 * Return value: %TRUE if the toolbar has an overflow menu.
2976 gtk_toolbar_get_show_arrow (GtkToolbar *toolbar)
2978 GtkToolbarPrivate *priv;
2980 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
2982 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2984 return priv->show_arrow;
2988 * gtk_toolbar_get_drop_index:
2989 * @toolbar: a #GtkToolbar
2990 * @x: x coordinate of a point on the toolbar
2991 * @y: y coordinate of a point on the toolbar
2993 * Returns the position corresponding to the indicated point on
2994 * @toolbar. This is useful when dragging items to the toolbar:
2995 * this function returns the position a new item should be
2998 * @x and @y are in @toolbar coordinates.
3000 * Return value: The position corresponding to the point (@x, @y) on the toolbar.
3005 gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
3009 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
3011 return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
3015 gtk_toolbar_finalize (GObject *object)
3018 GtkToolbar *toolbar = GTK_TOOLBAR (object);
3019 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3021 if (priv->arrow_button)
3022 gtk_widget_unparent (priv->arrow_button);
3024 for (list = priv->content; list != NULL; list = list->next)
3026 ToolbarContent *content = list->data;
3028 toolbar_content_free (content);
3031 g_list_free (priv->content);
3032 g_list_free (toolbar->children);
3034 g_timer_destroy (priv->timer);
3037 gtk_widget_destroy (GTK_WIDGET (priv->menu));
3040 g_source_remove (priv->idle_id);
3042 G_OBJECT_CLASS (gtk_toolbar_parent_class)->finalize (object);
3046 * gtk_toolbar_set_icon_size:
3047 * @toolbar: A #GtkToolbar
3048 * @icon_size: (type int): The #GtkIconSize that stock icons in the
3049 * toolbar shall have.
3051 * This function sets the size of stock icons in the toolbar. You
3052 * can call it both before you add the icons and after they've been
3053 * added. The size you set will override user preferences for the default
3056 * This should only be used for special-purpose toolbars, normal
3057 * application toolbars should respect the user preferences for the
3061 gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
3062 GtkIconSize icon_size)
3064 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3065 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
3067 if (!toolbar->icon_size_set)
3069 toolbar->icon_size_set = TRUE;
3070 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3073 if (toolbar->icon_size == icon_size)
3076 toolbar->icon_size = icon_size;
3077 g_object_notify (G_OBJECT (toolbar), "icon-size");
3079 gtk_toolbar_reconfigured (toolbar);
3081 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3085 * gtk_toolbar_unset_icon_size:
3086 * @toolbar: a #GtkToolbar
3088 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that
3089 * user preferences will be used to determine the icon size.
3092 gtk_toolbar_unset_icon_size (GtkToolbar *toolbar)
3096 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3098 if (toolbar->icon_size_set)
3100 GtkSettings *settings = toolbar_get_settings (toolbar);
3104 g_object_get (settings,
3105 "gtk-toolbar-icon-size", &size,
3109 size = DEFAULT_ICON_SIZE;
3111 if (size != toolbar->icon_size)
3113 gtk_toolbar_set_icon_size (toolbar, size);
3114 g_object_notify (G_OBJECT (toolbar), "icon-size");
3117 toolbar->icon_size_set = FALSE;
3118 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3123 set_child_packing_and_visibility(GtkToolbar *toolbar,
3124 GtkToolbarChild *child)
3129 box = gtk_bin_get_child (GTK_BIN (child->widget));
3131 g_return_if_fail (GTK_IS_BOX (box));
3135 expand = (toolbar->style != GTK_TOOLBAR_BOTH);
3137 gtk_box_set_child_packing (GTK_BOX (box), child->label,
3138 expand, expand, 0, GTK_PACK_END);
3140 if (toolbar->style != GTK_TOOLBAR_ICONS)
3141 gtk_widget_show (child->label);
3143 gtk_widget_hide (child->label);
3148 expand = (toolbar->style != GTK_TOOLBAR_BOTH_HORIZ);
3150 gtk_box_set_child_packing (GTK_BOX (box), child->icon,
3151 expand, expand, 0, GTK_PACK_END);
3153 if (toolbar->style != GTK_TOOLBAR_TEXT)
3154 gtk_widget_show (child->icon);
3156 gtk_widget_hide (child->icon);
3161 * ToolbarContent methods
3169 struct _ToolbarContent
3179 GtkAllocation start_allocation;
3180 GtkAllocation goal_allocation;
3181 guint is_placeholder : 1;
3182 guint disappearing : 1;
3188 GtkToolbarChild child;
3189 GtkAllocation space_allocation;
3190 guint space_visible : 1;
3195 static ToolbarContent *
3196 toolbar_content_new_tool_item (GtkToolbar *toolbar,
3198 gboolean is_placeholder,
3201 ToolbarContent *content;
3202 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3204 content = g_slice_new0 (ToolbarContent);
3206 content->type = TOOL_ITEM;
3207 content->state = NOT_ALLOCATED;
3208 content->u.tool_item.item = item;
3209 content->u.tool_item.is_placeholder = is_placeholder;
3211 gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
3213 priv->content = g_list_insert (priv->content, content, pos);
3215 if (!is_placeholder)
3217 toolbar->num_children++;
3219 gtk_toolbar_stop_sliding (toolbar);
3222 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3223 priv->need_rebuild = TRUE;
3229 toolbar_content_remove (ToolbarContent *content,
3230 GtkToolbar *toolbar)
3232 GtkToolbarChild *child;
3233 GtkToolbarPrivate *priv;
3235 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3237 switch (content->type)
3240 gtk_widget_unparent (GTK_WIDGET (content->u.tool_item.item));
3244 child = &(content->u.compatibility.child);
3246 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
3248 g_object_ref (child->widget);
3249 gtk_widget_unparent (child->widget);
3250 gtk_widget_destroy (child->widget);
3251 g_object_unref (child->widget);
3254 toolbar->children = g_list_remove (toolbar->children, child);
3258 priv->content = g_list_remove (priv->content, content);
3260 if (!toolbar_content_is_placeholder (content))
3261 toolbar->num_children--;
3263 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3264 priv->need_rebuild = TRUE;
3268 toolbar_content_free (ToolbarContent *content)
3270 g_slice_free (ToolbarContent, content);
3274 calculate_max_homogeneous_pixels (GtkWidget *widget)
3276 PangoContext *context;
3277 PangoFontMetrics *metrics;
3280 context = gtk_widget_get_pango_context (widget);
3281 metrics = pango_context_get_metrics (context,
3282 widget->style->font_desc,
3283 pango_context_get_language (context));
3284 char_width = pango_font_metrics_get_approximate_char_width (metrics);
3285 pango_font_metrics_unref (metrics);
3287 return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
3291 toolbar_content_expose (ToolbarContent *content,
3292 GtkContainer *container,
3293 GdkEventExpose *expose)
3295 GtkToolbar *toolbar = GTK_TOOLBAR (container);
3296 GtkToolbarChild *child;
3297 GtkWidget *widget = NULL; /* quiet gcc */
3299 switch (content->type)
3302 if (!content->u.tool_item.is_placeholder)
3303 widget = GTK_WIDGET (content->u.tool_item.item);
3307 child = &(content->u.compatibility.child);
3309 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
3311 if (content->u.compatibility.space_visible &&
3312 get_space_style (toolbar) == GTK_TOOLBAR_SPACE_LINE)
3313 _gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), toolbar,
3315 &content->u.compatibility.space_allocation);
3319 widget = child->widget;
3324 gtk_container_propagate_expose (container, widget, expose);
3328 toolbar_content_visible (ToolbarContent *content,
3329 GtkToolbar *toolbar)
3333 switch (content->type)
3336 item = content->u.tool_item.item;
3338 if (!gtk_widget_get_visible (GTK_WIDGET (item)))
3341 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL &&
3342 gtk_tool_item_get_visible_horizontal (item))
3345 if ((toolbar->orientation == GTK_ORIENTATION_VERTICAL &&
3346 gtk_tool_item_get_visible_vertical (item)))
3353 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
3354 return gtk_widget_get_visible (content->u.compatibility.child.widget);
3360 g_assert_not_reached ();
3365 toolbar_content_size_request (ToolbarContent *content,
3366 GtkToolbar *toolbar,
3367 GtkRequisition *requisition)
3371 switch (content->type)
3374 gtk_widget_size_request (GTK_WIDGET (content->u.tool_item.item),
3376 if (content->u.tool_item.is_placeholder &&
3377 content->u.tool_item.disappearing)
3379 requisition->width = 0;
3380 requisition->height = 0;
3385 space_size = get_space_size (toolbar);
3387 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
3389 gtk_widget_size_request (content->u.compatibility.child.widget,
3394 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
3396 requisition->width = space_size;
3397 requisition->height = 0;
3401 requisition->height = space_size;
3402 requisition->width = 0;
3411 toolbar_content_is_homogeneous (ToolbarContent *content,
3412 GtkToolbar *toolbar)
3414 gboolean result = FALSE; /* quiet gcc */
3415 GtkRequisition requisition;
3416 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3418 if (priv->max_homogeneous_pixels < 0)
3420 priv->max_homogeneous_pixels =
3421 calculate_max_homogeneous_pixels (GTK_WIDGET (toolbar));
3424 toolbar_content_size_request (content, toolbar, &requisition);
3426 if (requisition.width > priv->max_homogeneous_pixels)
3429 switch (content->type)
3432 result = gtk_tool_item_get_homogeneous (content->u.tool_item.item) &&
3433 !GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
3435 if (gtk_tool_item_get_is_important (content->u.tool_item.item) &&
3436 toolbar->style == GTK_TOOLBAR_BOTH_HORIZ &&
3437 toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
3444 if (content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_BUTTON ||
3445 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
3446 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
3461 toolbar_content_is_placeholder (ToolbarContent *content)
3463 if (content->type == TOOL_ITEM && content->u.tool_item.is_placeholder)
3470 toolbar_content_disappearing (ToolbarContent *content)
3472 if (content->type == TOOL_ITEM && content->u.tool_item.disappearing)
3479 toolbar_content_get_state (ToolbarContent *content)
3481 return content->state;
3485 toolbar_content_child_visible (ToolbarContent *content)
3487 switch (content->type)
3490 return GTK_WIDGET_CHILD_VISIBLE (content->u.tool_item.item);
3494 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
3496 return GTK_WIDGET_CHILD_VISIBLE (content->u.compatibility.child.widget);
3500 return content->u.compatibility.space_visible;
3505 return FALSE; /* quiet gcc */
3509 toolbar_content_get_goal_allocation (ToolbarContent *content,
3510 GtkAllocation *allocation)
3512 switch (content->type)
3515 *allocation = content->u.tool_item.goal_allocation;
3519 /* Goal allocations are only relevant when we are
3520 * using the new API, so we should never get here
3522 g_assert_not_reached ();
3526 g_assert_not_reached ();
3532 toolbar_content_get_allocation (ToolbarContent *content,
3533 GtkAllocation *allocation)
3535 GtkToolbarChild *child;
3537 switch (content->type)
3540 *allocation = GTK_WIDGET (content->u.tool_item.item)->allocation;
3544 child = &(content->u.compatibility.child);
3546 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
3547 *allocation = content->u.compatibility.space_allocation;
3549 *allocation = child->widget->allocation;
3553 g_assert_not_reached ();
3559 toolbar_content_set_start_allocation (ToolbarContent *content,
3560 GtkAllocation *allocation)
3562 switch (content->type)
3565 content->u.tool_item.start_allocation = *allocation;
3569 /* start_allocation is only relevant when using the new API */
3570 g_assert_not_reached ();
3576 toolbar_content_get_expand (ToolbarContent *content)
3578 if (content->type == TOOL_ITEM &&
3579 gtk_tool_item_get_expand (content->u.tool_item.item) &&
3580 !content->u.tool_item.disappearing)
3589 toolbar_content_set_goal_allocation (ToolbarContent *content,
3590 GtkAllocation *allocation)
3592 switch (content->type)
3595 content->u.tool_item.goal_allocation = *allocation;
3599 /* Only relevant when using new API */
3600 g_assert_not_reached ();
3606 toolbar_content_set_child_visible (ToolbarContent *content,
3607 GtkToolbar *toolbar,
3610 GtkToolbarChild *child;
3612 switch (content->type)
3615 gtk_widget_set_child_visible (GTK_WIDGET (content->u.tool_item.item),
3620 child = &(content->u.compatibility.child);
3622 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
3624 gtk_widget_set_child_visible (child->widget, visible);
3628 if (content->u.compatibility.space_visible != visible)
3630 content->u.compatibility.space_visible = visible;
3631 gtk_widget_queue_draw (GTK_WIDGET (toolbar));
3639 toolbar_content_get_start_allocation (ToolbarContent *content,
3640 GtkAllocation *start_allocation)
3642 switch (content->type)
3645 *start_allocation = content->u.tool_item.start_allocation;
3649 /* Only relevant for new API */
3650 g_assert_not_reached ();
3656 toolbar_content_size_allocate (ToolbarContent *content,
3657 GtkAllocation *allocation)
3659 switch (content->type)
3662 gtk_widget_size_allocate (GTK_WIDGET (content->u.tool_item.item),
3667 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
3669 gtk_widget_size_allocate (content->u.compatibility.child.widget,
3674 content->u.compatibility.space_allocation = *allocation;
3681 toolbar_content_set_state (ToolbarContent *content,
3684 content->state = state;
3688 toolbar_content_get_widget (ToolbarContent *content)
3690 GtkToolbarChild *child;
3692 switch (content->type)
3695 return GTK_WIDGET (content->u.tool_item.item);
3699 child = &(content->u.compatibility.child);
3700 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
3701 return child->widget;
3711 toolbar_content_set_disappearing (ToolbarContent *content,
3712 gboolean disappearing)
3714 switch (content->type)
3717 content->u.tool_item.disappearing = disappearing;
3721 /* Only relevant for new API */
3722 g_assert_not_reached ();
3728 toolbar_content_set_size_request (ToolbarContent *content,
3732 switch (content->type)
3735 gtk_widget_set_size_request (GTK_WIDGET (content->u.tool_item.item),
3740 /* Setting size requests only happens with sliding,
3741 * so not relevant here
3743 g_assert_not_reached ();
3749 toolbar_child_reconfigure (GtkToolbar *toolbar,
3750 GtkToolbarChild *child)
3754 GtkToolbarStyle style;
3755 GtkIconSize icon_size;
3756 GtkReliefStyle relief;
3759 style = gtk_toolbar_get_style (toolbar);
3760 icon_size = gtk_toolbar_get_icon_size (toolbar);
3761 relief = gtk_toolbar_get_relief_style (toolbar);
3764 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
3765 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
3766 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
3768 box = gtk_bin_get_child (GTK_BIN (child->widget));
3770 if (style == GTK_TOOLBAR_BOTH && GTK_IS_HBOX (box))
3774 vbox = gtk_vbox_new (FALSE, 0);
3777 gtk_widget_reparent (child->label, vbox);
3779 gtk_widget_reparent (child->icon, vbox);
3781 gtk_widget_destroy (box);
3782 gtk_container_add (GTK_CONTAINER (child->widget), vbox);
3784 gtk_widget_show (vbox);
3786 else if (style == GTK_TOOLBAR_BOTH_HORIZ && GTK_IS_VBOX (box))
3790 hbox = gtk_hbox_new (FALSE, 0);
3793 gtk_widget_reparent (child->label, hbox);
3795 gtk_widget_reparent (child->icon, hbox);
3797 gtk_widget_destroy (box);
3798 gtk_container_add (GTK_CONTAINER (child->widget), hbox);
3800 gtk_widget_show (hbox);
3803 set_child_packing_and_visibility (toolbar, child);
3808 if ((child->type == GTK_TOOLBAR_CHILD_BUTTON ||
3809 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
3810 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON) &&
3811 GTK_IS_IMAGE (child->icon))
3813 image = GTK_IMAGE (child->icon);
3814 if (gtk_image_get_storage_type (image) == GTK_IMAGE_STOCK)
3816 gtk_image_get_stock (image, &stock_id, NULL);
3817 stock_id = g_strdup (stock_id);
3818 gtk_image_set_from_stock (image,
3826 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
3827 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
3828 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
3830 gtk_button_set_relief (GTK_BUTTON (child->widget), relief);
3835 toolbar_content_toolbar_reconfigured (ToolbarContent *content,
3836 GtkToolbar *toolbar)
3838 switch (content->type)
3841 gtk_tool_item_toolbar_reconfigured (content->u.tool_item.item);
3845 toolbar_child_reconfigure (toolbar, &(content->u.compatibility.child));
3851 toolbar_content_retrieve_menu_item (ToolbarContent *content)
3853 if (content->type == TOOL_ITEM)
3854 return gtk_tool_item_retrieve_proxy_menu_item (content->u.tool_item.item);
3856 /* FIXME - we might actually be able to do something meaningful here */
3861 toolbar_content_has_proxy_menu_item (ToolbarContent *content)
3863 if (content->type == TOOL_ITEM)
3865 GtkWidget *menu_item;
3867 if (content->u.tool_item.has_menu == YES)
3869 else if (content->u.tool_item.has_menu == NO)
3872 menu_item = toolbar_content_retrieve_menu_item (content);
3874 content->u.tool_item.has_menu = menu_item? YES : NO;
3876 return menu_item != NULL;
3885 toolbar_content_set_unknown_menu_status (ToolbarContent *content)
3887 if (content->type == TOOL_ITEM)
3888 content->u.tool_item.has_menu = UNKNOWN;
3892 toolbar_content_is_separator (ToolbarContent *content)
3894 GtkToolbarChild *child;
3896 switch (content->type)
3899 return GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
3903 child = &(content->u.compatibility.child);
3904 return (child->type == GTK_TOOLBAR_CHILD_SPACE);
3912 toolbar_content_set_expand (ToolbarContent *content,
3915 if (content->type == TOOL_ITEM)
3916 gtk_tool_item_set_expand (content->u.tool_item.item, expand);
3920 ignore_show_and_hide_all (ToolbarContent *content)
3922 if (content->type == COMPATIBILITY)
3924 GtkToolbarChildType type = content->u.compatibility.child.type;
3926 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
3927 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
3928 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
3938 toolbar_content_show_all (ToolbarContent *content)
3942 if (ignore_show_and_hide_all (content))
3945 widget = toolbar_content_get_widget (content);
3947 gtk_widget_show_all (widget);
3951 toolbar_content_hide_all (ToolbarContent *content)
3955 if (ignore_show_and_hide_all (content))
3958 widget = toolbar_content_get_widget (content);
3960 gtk_widget_hide_all (widget);
3967 get_space_size (GtkToolbar *toolbar)
3969 gint space_size = DEFAULT_SPACE_SIZE;
3973 gtk_widget_style_get (GTK_WIDGET (toolbar),
3974 "space-size", &space_size,
3981 static GtkToolbarSpaceStyle
3982 get_space_style (GtkToolbar *toolbar)
3984 GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
3988 gtk_widget_style_get (GTK_WIDGET (toolbar),
3989 "space-style", &space_style,
3996 static GtkReliefStyle
3997 get_button_relief (GtkToolbar *toolbar)
3999 GtkReliefStyle button_relief = GTK_RELIEF_NORMAL;
4001 gtk_widget_ensure_style (GTK_WIDGET (toolbar));
4003 gtk_widget_style_get (GTK_WIDGET (toolbar),
4004 "button-relief", &button_relief,
4007 return button_relief;
4011 get_internal_padding (GtkToolbar *toolbar)
4015 gtk_widget_style_get (GTK_WIDGET (toolbar),
4016 "internal-padding", &ipadding,
4023 get_max_child_expand (GtkToolbar *toolbar)
4025 gint mexpand = G_MAXINT;
4027 gtk_widget_style_get (GTK_WIDGET (toolbar),
4028 "max-child-expand", &mexpand,
4033 static GtkShadowType
4034 get_shadow_type (GtkToolbar *toolbar)
4036 GtkShadowType shadow_type;
4038 gtk_widget_style_get (GTK_WIDGET (toolbar),
4039 "shadow-type", &shadow_type,
4045 /* GTK+ internal methods */
4048 _gtk_toolbar_get_default_space_size (void)
4050 return DEFAULT_SPACE_SIZE;
4054 _gtk_toolbar_paint_space_line (GtkWidget *widget,
4055 GtkToolbar *toolbar,
4056 const GdkRectangle *area,
4057 const GtkAllocation *allocation)
4059 const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
4060 const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
4062 GtkOrientation orientation;
4064 g_return_if_fail (GTK_IS_WIDGET (widget));
4066 orientation = toolbar? toolbar->orientation : GTK_ORIENTATION_HORIZONTAL;
4068 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4070 gboolean wide_separators;
4071 gint separator_width;
4073 gtk_widget_style_get (widget,
4074 "wide-separators", &wide_separators,
4075 "separator-width", &separator_width,
4078 if (wide_separators)
4079 gtk_paint_box (widget->style, widget->window,
4080 gtk_widget_get_state (widget), GTK_SHADOW_ETCHED_OUT,
4081 area, widget, "vseparator",
4082 allocation->x + (allocation->width - separator_width) / 2,
4083 allocation->y + allocation->height * start_fraction,
4085 allocation->height * (end_fraction - start_fraction));
4087 gtk_paint_vline (widget->style, widget->window,
4088 gtk_widget_get_state (widget), area, widget,
4090 allocation->y + allocation->height * start_fraction,
4091 allocation->y + allocation->height * end_fraction,
4092 allocation->x + (allocation->width - widget->style->xthickness) / 2);
4096 gboolean wide_separators;
4097 gint separator_height;
4099 gtk_widget_style_get (widget,
4100 "wide-separators", &wide_separators,
4101 "separator-height", &separator_height,
4104 if (wide_separators)
4105 gtk_paint_box (widget->style, widget->window,
4106 gtk_widget_get_state (widget), GTK_SHADOW_ETCHED_OUT,
4107 area, widget, "hseparator",
4108 allocation->x + allocation->width * start_fraction,
4109 allocation->y + (allocation->height - separator_height) / 2,
4110 allocation->width * (end_fraction - start_fraction),
4113 gtk_paint_hline (widget->style, widget->window,
4114 gtk_widget_get_state (widget), area, widget,
4116 allocation->x + allocation->width * start_fraction,
4117 allocation->x + allocation->width * end_fraction,
4118 allocation->y + (allocation->height - widget->style->ythickness) / 2);
4123 _gtk_toolbar_elide_underscores (const gchar *original)
4126 const gchar *p, *end;
4128 gboolean last_underscore;
4133 len = strlen (original);
4134 q = result = g_malloc (len + 1);
4135 last_underscore = FALSE;
4137 end = original + len;
4138 for (p = original; p < end; p++)
4140 if (!last_underscore && *p == '_')
4141 last_underscore = TRUE;
4144 last_underscore = FALSE;
4145 if (original + 2 <= p && p + 1 <= end &&
4146 p[-2] == '(' && p[-1] == '_' && p[0] != '_' && p[1] == ')')
4157 if (last_underscore)
4166 toolbar_get_icon_size (GtkToolShell *shell)
4168 return GTK_TOOLBAR (shell)->icon_size;
4171 static GtkOrientation
4172 toolbar_get_orientation (GtkToolShell *shell)
4174 return GTK_TOOLBAR (shell)->orientation;
4177 static GtkToolbarStyle
4178 toolbar_get_style (GtkToolShell *shell)
4180 return GTK_TOOLBAR (shell)->style;
4183 static GtkReliefStyle
4184 toolbar_get_relief_style (GtkToolShell *shell)
4186 return get_button_relief (GTK_TOOLBAR (shell));
4190 toolbar_rebuild_menu (GtkToolShell *shell)
4192 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (shell);
4195 priv->need_rebuild = TRUE;
4197 for (list = priv->content; list != NULL; list = list->next)
4199 ToolbarContent *content = list->data;
4201 toolbar_content_set_unknown_menu_status (content);
4204 gtk_widget_queue_resize (GTK_WIDGET (shell));
4207 #define __GTK_TOOLBAR_C__
4208 #include "gtkaliasdef.c"