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
36 #include "gtktoolbar.h"
37 #include "gtkradiotoolbutton.h"
38 #include "gtkseparatortoolitem.h"
40 #include "gtkradiobutton.h"
41 #include "gtktoolbar.h"
42 #include "gtkbindings.h"
43 #include <gdk/gdkkeysyms.h>
44 #include "gtkmarshalers.h"
48 #include "gtkprivate.h"
54 #include "gtkseparatormenuitem.h"
58 typedef struct _ToolbarContent ToolbarContent;
60 #define DEFAULT_IPADDING 0
62 #define DEFAULT_SPACE_SIZE 12
63 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE
64 #define SPACE_LINE_DIVISION 10.0
65 #define SPACE_LINE_START 2.0
66 #define SPACE_LINE_END 8.0
68 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR
69 #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH
70 #define DEFAULT_ANIMATION_STATE TRUE
72 #define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
73 * in the homogeneous game. In units of
74 * pango_font_get_estimated_char_width().
76 #define SLIDE_SPEED 600.0 /* How fast the items slide, in pixels per second */
77 #define ACCEL_THRESHOLD 0.18 /* After how much time in seconds will items start speeding up */
79 #define MIXED_API_WARNING \
80 "Mixing deprecated and non-deprecated GtkToolbar API is not allowed"
94 /* Child properties */
98 CHILD_PROP_HOMOGENEOUS
130 struct _GtkToolbarPrivate
135 GtkWidget * arrow_button;
138 GdkWindow * event_window;
140 GtkSettings * settings;
142 GtkToolItem * highlight_tool_item;
143 gint max_homogeneous_pixels;
147 gulong settings_connection;
149 guint show_arrow : 1;
151 guint is_sliding : 1;
152 guint need_rebuild : 1; /* whether the overflow menu should be regenerated */
156 static void gtk_toolbar_init (GtkToolbar *toolbar);
157 static void gtk_toolbar_class_init (GtkToolbarClass *klass);
158 static void gtk_toolbar_set_property (GObject *object,
162 static void gtk_toolbar_get_property (GObject *object,
166 static gint gtk_toolbar_expose (GtkWidget *widget,
167 GdkEventExpose *event);
168 static void gtk_toolbar_realize (GtkWidget *widget);
169 static void gtk_toolbar_unrealize (GtkWidget *widget);
170 static void gtk_toolbar_size_request (GtkWidget *widget,
171 GtkRequisition *requisition);
172 static void gtk_toolbar_size_allocate (GtkWidget *widget,
173 GtkAllocation *allocation);
174 static void gtk_toolbar_style_set (GtkWidget *widget,
175 GtkStyle *prev_style);
176 static gboolean gtk_toolbar_focus (GtkWidget *widget,
177 GtkDirectionType dir);
178 static void gtk_toolbar_screen_changed (GtkWidget *widget,
179 GdkScreen *previous_screen);
180 static void gtk_toolbar_map (GtkWidget *widget);
181 static void gtk_toolbar_unmap (GtkWidget *widget);
182 static void gtk_toolbar_set_child_property (GtkContainer *container,
187 static void gtk_toolbar_get_child_property (GtkContainer *container,
192 static void gtk_toolbar_finalize (GObject *object);
193 static void gtk_toolbar_show_all (GtkWidget *widget);
194 static void gtk_toolbar_hide_all (GtkWidget *widget);
195 static void gtk_toolbar_add (GtkContainer *container,
197 static void gtk_toolbar_remove (GtkContainer *container,
199 static void gtk_toolbar_forall (GtkContainer *container,
200 gboolean include_internals,
201 GtkCallback callback,
202 gpointer callback_data);
203 static GType gtk_toolbar_child_type (GtkContainer *container);
204 static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
205 GtkOrientation orientation);
206 static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
207 GtkToolbarStyle style);
208 static gboolean gtk_toolbar_move_focus (GtkToolbar *toolbar,
209 GtkDirectionType dir);
210 static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
211 gboolean focus_home);
212 static gboolean gtk_toolbar_button_press (GtkWidget *toolbar,
213 GdkEventButton *event);
214 static gboolean gtk_toolbar_arrow_button_press (GtkWidget *button,
215 GdkEventButton *event,
216 GtkToolbar *toolbar);
217 static void gtk_toolbar_arrow_button_clicked (GtkWidget *button,
218 GtkToolbar *toolbar);
219 static void gtk_toolbar_update_button_relief (GtkToolbar *toolbar);
220 static gboolean gtk_toolbar_popup_menu (GtkWidget *toolbar);
221 static GtkWidget *internal_insert_element (GtkToolbar *toolbar,
222 GtkToolbarChildType type,
225 const char *tooltip_text,
226 const char *tooltip_private_text,
228 GtkSignalFunc callback,
232 static void gtk_toolbar_reconfigured (GtkToolbar *toolbar);
233 static gboolean gtk_toolbar_check_new_api (GtkToolbar *toolbar);
234 static gboolean gtk_toolbar_check_old_api (GtkToolbar *toolbar);
236 static GtkReliefStyle get_button_relief (GtkToolbar *toolbar);
237 static gint get_internal_padding (GtkToolbar *toolbar);
238 static GtkShadowType get_shadow_type (GtkToolbar *toolbar);
239 static gint get_space_size (GtkToolbar *toolbar);
240 static GtkToolbarSpaceStyle get_space_style (GtkToolbar *toolbar);
242 /* methods on ToolbarContent 'class' */
243 static ToolbarContent *toolbar_content_new_tool_item (GtkToolbar *toolbar,
245 gboolean is_placeholder,
247 static ToolbarContent *toolbar_content_new_compatibility (GtkToolbar *toolbar,
248 GtkToolbarChildType type,
253 static void toolbar_content_remove (ToolbarContent *content,
254 GtkToolbar *toolbar);
255 static void toolbar_content_free (ToolbarContent *content);
256 static void toolbar_content_expose (ToolbarContent *content,
257 GtkContainer *container,
258 GdkEventExpose *expose);
259 static gboolean toolbar_content_visible (ToolbarContent *content,
260 GtkToolbar *toolbar);
261 static void toolbar_content_size_request (ToolbarContent *content,
263 GtkRequisition *requisition);
264 static gboolean toolbar_content_is_homogeneous (ToolbarContent *content,
265 GtkToolbar *toolbar);
266 static gboolean toolbar_content_is_placeholder (ToolbarContent *content);
267 static gboolean toolbar_content_disappearing (ToolbarContent *content);
268 static ItemState toolbar_content_get_state (ToolbarContent *content);
269 static gboolean toolbar_content_child_visible (ToolbarContent *content);
270 static void toolbar_content_get_goal_allocation (ToolbarContent *content,
271 GtkAllocation *allocation);
272 static void toolbar_content_get_allocation (ToolbarContent *content,
273 GtkAllocation *allocation);
274 static void toolbar_content_set_start_allocation (ToolbarContent *content,
275 GtkAllocation *new_start_allocation);
276 static void toolbar_content_get_start_allocation (ToolbarContent *content,
277 GtkAllocation *start_allocation);
278 static gboolean toolbar_content_get_expand (ToolbarContent *content);
279 static void toolbar_content_set_goal_allocation (ToolbarContent *content,
280 GtkAllocation *allocation);
281 static void toolbar_content_set_child_visible (ToolbarContent *content,
284 static void toolbar_content_size_allocate (ToolbarContent *content,
285 GtkAllocation *allocation);
286 static void toolbar_content_set_state (ToolbarContent *content,
287 ItemState new_state);
288 static GtkWidget * toolbar_content_get_widget (ToolbarContent *content);
289 static void toolbar_content_set_disappearing (ToolbarContent *content,
290 gboolean disappearing);
291 static void toolbar_content_set_size_request (ToolbarContent *content,
294 static void toolbar_content_toolbar_reconfigured (ToolbarContent *content,
295 GtkToolbar *toolbar);
296 static GtkWidget * toolbar_content_retrieve_menu_item (ToolbarContent *content);
297 static gboolean toolbar_content_has_proxy_menu_item (ToolbarContent *content);
298 static gboolean toolbar_content_is_separator (ToolbarContent *content);
299 static void toolbar_content_show_all (ToolbarContent *content);
300 static void toolbar_content_hide_all (ToolbarContent *content);
301 static void toolbar_content_set_expand (ToolbarContent *content,
304 #define GTK_TOOLBAR_GET_PRIVATE(o) \
305 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOLBAR, GtkToolbarPrivate))
307 static GtkContainerClass * parent_class = NULL;
308 static guint toolbar_signals [LAST_SIGNAL] = { 0 };
311 gtk_toolbar_get_type (void)
313 static GtkType type = 0;
317 static const GTypeInfo type_info =
319 sizeof (GtkToolbarClass),
320 (GBaseInitFunc) NULL,
321 (GBaseFinalizeFunc) NULL,
322 (GClassInitFunc) gtk_toolbar_class_init,
323 (GClassFinalizeFunc) NULL,
327 (GInstanceInitFunc) gtk_toolbar_init,
330 type = g_type_register_static (GTK_TYPE_CONTAINER,
339 add_arrow_bindings (GtkBindingSet *binding_set,
341 GtkDirectionType dir)
343 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
345 gtk_binding_entry_add_signal (binding_set, keysym, 0,
347 GTK_TYPE_DIRECTION_TYPE, dir);
348 gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
350 GTK_TYPE_DIRECTION_TYPE, dir);
354 add_ctrl_tab_bindings (GtkBindingSet *binding_set,
355 GdkModifierType modifiers,
356 GtkDirectionType direction)
358 gtk_binding_entry_add_signal (binding_set,
359 GDK_Tab, GDK_CONTROL_MASK | modifiers,
361 GTK_TYPE_DIRECTION_TYPE, direction);
362 gtk_binding_entry_add_signal (binding_set,
363 GDK_KP_Tab, GDK_CONTROL_MASK | modifiers,
365 GTK_TYPE_DIRECTION_TYPE, direction);
369 gtk_toolbar_class_init (GtkToolbarClass *klass)
371 GObjectClass *gobject_class;
372 GtkWidgetClass *widget_class;
373 GtkContainerClass *container_class;
374 GtkBindingSet *binding_set;
376 parent_class = g_type_class_peek_parent (klass);
378 gobject_class = (GObjectClass *)klass;
379 widget_class = (GtkWidgetClass *)klass;
380 container_class = (GtkContainerClass *)klass;
382 gobject_class->set_property = gtk_toolbar_set_property;
383 gobject_class->get_property = gtk_toolbar_get_property;
384 gobject_class->finalize = gtk_toolbar_finalize;
386 widget_class->button_press_event = gtk_toolbar_button_press;
387 widget_class->expose_event = gtk_toolbar_expose;
388 widget_class->size_request = gtk_toolbar_size_request;
389 widget_class->size_allocate = gtk_toolbar_size_allocate;
390 widget_class->style_set = gtk_toolbar_style_set;
391 widget_class->focus = gtk_toolbar_focus;
392 widget_class->screen_changed = gtk_toolbar_screen_changed;
393 widget_class->realize = gtk_toolbar_realize;
394 widget_class->unrealize = gtk_toolbar_unrealize;
395 widget_class->map = gtk_toolbar_map;
396 widget_class->unmap = gtk_toolbar_unmap;
397 widget_class->popup_menu = gtk_toolbar_popup_menu;
398 widget_class->show_all = gtk_toolbar_show_all;
399 widget_class->hide_all = gtk_toolbar_hide_all;
401 container_class->add = gtk_toolbar_add;
402 container_class->remove = gtk_toolbar_remove;
403 container_class->forall = gtk_toolbar_forall;
404 container_class->child_type = gtk_toolbar_child_type;
405 container_class->get_child_property = gtk_toolbar_get_child_property;
406 container_class->set_child_property = gtk_toolbar_set_child_property;
408 klass->orientation_changed = gtk_toolbar_orientation_changed;
409 klass->style_changed = gtk_toolbar_real_style_changed;
412 * GtkToolbar::orientation-changed:
413 * @toolbar: the object which emitted the signal
414 * @orientation: the new #GtkOrientation of the toolbar
416 * Emitted when the orientation of the toolbar changes.
418 toolbar_signals[ORIENTATION_CHANGED] =
419 g_signal_new (I_("orientation-changed"),
420 G_OBJECT_CLASS_TYPE (klass),
422 G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
424 g_cclosure_marshal_VOID__ENUM,
426 GTK_TYPE_ORIENTATION);
428 * GtkToolbar::style-changed:
429 * @toolbar: The #GtkToolbar which emitted the signal
430 * @style: the new #GtkToolbarStyle of the toolbar
432 * Emitted when the style of the toolbar changes.
434 toolbar_signals[STYLE_CHANGED] =
435 g_signal_new (I_("style-changed"),
436 G_OBJECT_CLASS_TYPE (klass),
438 G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
440 g_cclosure_marshal_VOID__ENUM,
442 GTK_TYPE_TOOLBAR_STYLE);
444 * GtkToolbar::popup-context-menu:
445 * @toolbar: the #GtkToolbar which emitted the signal
446 * @x: the x coordinate of the point where the menu should appear
447 * @y: the y coordinate of the point where the menu should appear
448 * @button: the mouse button the user pressed, or -1
450 * Emitted when the user right-clicks the toolbar or uses the
451 * keybinding to display a popup menu.
453 * Application developers should handle this signal if they want
454 * to display a context menu on the toolbar. The context-menu should
455 * appear at the coordinates given by @x and @y. The mouse button
456 * number is given by the @button parameter. If the menu was popped
457 * up using the keybaord, @button is -1.
459 * Return value: return %TRUE if the signal was handled, %FALSE if not
461 toolbar_signals[POPUP_CONTEXT_MENU] =
462 g_signal_new (I_("popup_context_menu"),
463 G_OBJECT_CLASS_TYPE (klass),
465 G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
466 _gtk_boolean_handled_accumulator, NULL,
467 _gtk_marshal_BOOLEAN__INT_INT_INT,
469 G_TYPE_INT, G_TYPE_INT,
472 * GtkToolbar::move-focus:
473 * @toolbar: the #GtkToolbar which emitted the signal
474 * @dir: a #GtkDirection
476 * A keybinding signal used internally by GTK+. This signal can't
477 * be used in application code.
479 * Return value: %TRUE if the signal was handled, %FALSE if not
481 toolbar_signals[MOVE_FOCUS] =
482 _gtk_binding_signal_new (I_("move_focus"),
483 G_TYPE_FROM_CLASS (klass),
484 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
485 G_CALLBACK (gtk_toolbar_move_focus),
487 _gtk_marshal_BOOLEAN__ENUM,
489 GTK_TYPE_DIRECTION_TYPE);
491 * GtkToolbar::focus-home-or-end:
492 * @toolbar: the #GtkToolbar which emitted the signal
493 * @focus_home: %TRUE if the first item should be focused
495 * A keybinding signal used internally by GTK+. This signal can't
496 * be used in application code
498 * Return value: %TRUE if the signal was handled, %FALSE if not
500 toolbar_signals[FOCUS_HOME_OR_END] =
501 _gtk_binding_signal_new (I_("focus_home_or_end"),
502 G_OBJECT_CLASS_TYPE (klass),
503 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
504 G_CALLBACK (gtk_toolbar_focus_home_or_end),
506 _gtk_marshal_BOOLEAN__BOOLEAN,
511 g_object_class_install_property (gobject_class,
513 g_param_spec_enum ("orientation",
515 P_("The orientation of the toolbar"),
516 GTK_TYPE_ORIENTATION,
517 GTK_ORIENTATION_HORIZONTAL,
518 GTK_PARAM_READWRITE));
520 g_object_class_install_property (gobject_class,
522 g_param_spec_enum ("toolbar-style",
524 P_("How to draw the toolbar"),
525 GTK_TYPE_TOOLBAR_STYLE,
527 GTK_PARAM_READWRITE));
528 g_object_class_install_property (gobject_class,
530 g_param_spec_boolean ("show-arrow",
532 P_("If an arrow should be shown if the toolbar doesn't fit"),
534 GTK_PARAM_READWRITE));
538 * GtkToolbar:tooltips:
540 * If the tooltips of the toolbar should be active or not.
544 g_object_class_install_property (gobject_class,
546 g_param_spec_boolean ("tooltips",
548 P_("If the tooltips of the toolbar should be active or not"),
550 GTK_PARAM_READWRITE));
554 * GtkToolbar:icon-size:
556 * The size of the icons in a toolbar is normally determined by
557 * the toolbar-icon-size setting. When this property is set, it
558 * overrides the setting.
560 * This should only be used for special-purpose toolbars, normal
561 * application toolbars should respect the user preferences for the
566 g_object_class_install_property (gobject_class,
568 g_param_spec_enum ("icon-size",
570 P_("Size of icons in this toolbar"),
573 GTK_PARAM_READWRITE));
576 * GtkToolbar:icon-size-set:
578 * Is %TRUE if the icon-size property has been set.
582 g_object_class_install_property (gobject_class,
584 g_param_spec_boolean ("icon-size-set",
586 P_("Whether the icon-size property has been set"),
588 GTK_PARAM_READWRITE));
590 /* child properties */
591 gtk_container_class_install_child_property (container_class,
593 g_param_spec_boolean ("expand",
595 P_("Whether the item should receive extra space when the toolbar grows"),
597 GTK_PARAM_READWRITE));
599 gtk_container_class_install_child_property (container_class,
600 CHILD_PROP_HOMOGENEOUS,
601 g_param_spec_boolean ("homogeneous",
603 P_("Whether the item should be the same size as other homogeneous items"),
605 GTK_PARAM_READWRITE));
607 /* style properties */
608 gtk_widget_class_install_style_property (widget_class,
609 g_param_spec_int ("space-size",
611 P_("Size of spacers"),
615 GTK_PARAM_READABLE));
617 gtk_widget_class_install_style_property (widget_class,
618 g_param_spec_int ("internal-padding",
619 P_("Internal padding"),
620 P_("Amount of border space between the toolbar shadow and the buttons"),
624 GTK_PARAM_READABLE));
626 gtk_widget_class_install_style_property (widget_class,
627 g_param_spec_enum ("space-style",
629 P_("Whether spacers are vertical lines or just blank"),
630 GTK_TYPE_TOOLBAR_SPACE_STYLE,
632 GTK_PARAM_READABLE));
634 gtk_widget_class_install_style_property (widget_class,
635 g_param_spec_enum ("button-relief",
637 P_("Type of bevel around toolbar buttons"),
638 GTK_TYPE_RELIEF_STYLE,
640 GTK_PARAM_READABLE));
641 gtk_widget_class_install_style_property (widget_class,
642 g_param_spec_enum ("shadow-type",
644 P_("Style of bevel around the toolbar"),
645 GTK_TYPE_SHADOW_TYPE,
647 GTK_PARAM_READABLE));
649 gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-style",
651 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
652 GTK_TYPE_TOOLBAR_STYLE,
653 DEFAULT_TOOLBAR_STYLE,
654 GTK_PARAM_READWRITE));
656 gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-icon-size",
657 P_("Toolbar icon size"),
658 P_("Size of icons in default toolbars"),
661 GTK_PARAM_READWRITE));
663 binding_set = gtk_binding_set_by_class (klass);
665 add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
666 add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
667 add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
668 add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
670 gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, 0,
671 "focus_home_or_end", 1,
672 G_TYPE_BOOLEAN, TRUE);
673 gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
674 "focus_home_or_end", 1,
675 G_TYPE_BOOLEAN, TRUE);
676 gtk_binding_entry_add_signal (binding_set, GDK_KP_End, 0,
677 "focus_home_or_end", 1,
678 G_TYPE_BOOLEAN, FALSE);
679 gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
680 "focus_home_or_end", 1,
681 G_TYPE_BOOLEAN, FALSE);
683 add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
684 add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
686 g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));
690 gtk_toolbar_init (GtkToolbar *toolbar)
692 GtkToolbarPrivate *priv;
694 GTK_WIDGET_UNSET_FLAGS (toolbar, GTK_CAN_FOCUS);
695 GTK_WIDGET_SET_FLAGS (toolbar, GTK_NO_WINDOW);
697 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
699 toolbar->orientation = GTK_ORIENTATION_HORIZONTAL;
700 toolbar->style = DEFAULT_TOOLBAR_STYLE;
701 toolbar->icon_size = DEFAULT_ICON_SIZE;
702 priv->animation = DEFAULT_ANIMATION_STATE;
703 toolbar->tooltips = gtk_tooltips_new ();
704 g_object_ref_sink (toolbar->tooltips);
706 priv->arrow_button = gtk_toggle_button_new ();
707 g_signal_connect (priv->arrow_button, "button_press_event",
708 G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar);
709 g_signal_connect (priv->arrow_button, "clicked",
710 G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar);
711 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
712 get_button_relief (toolbar));
714 priv->api_mode = DONT_KNOW;
716 gtk_button_set_focus_on_click (GTK_BUTTON (priv->arrow_button), FALSE);
718 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
719 gtk_widget_set_name (priv->arrow, "gtk-toolbar-arrow");
720 gtk_widget_show (priv->arrow);
721 gtk_container_add (GTK_CONTAINER (priv->arrow_button), priv->arrow);
723 gtk_widget_set_parent (priv->arrow_button, GTK_WIDGET (toolbar));
725 /* which child position a drop will occur at */
727 priv->show_arrow = TRUE;
728 priv->settings = NULL;
730 priv->max_homogeneous_pixels = -1;
732 priv->timer = g_timer_new ();
736 gtk_toolbar_set_property (GObject *object,
741 GtkToolbar *toolbar = GTK_TOOLBAR (object);
745 case PROP_ORIENTATION:
746 gtk_toolbar_set_orientation (toolbar, g_value_get_enum (value));
748 case PROP_TOOLBAR_STYLE:
749 gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
751 case PROP_SHOW_ARROW:
752 gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
755 gtk_toolbar_set_tooltips (toolbar, g_value_get_boolean (value));
758 gtk_toolbar_set_icon_size (toolbar, g_value_get_enum (value));
760 case PROP_ICON_SIZE_SET:
761 if (g_value_get_boolean (value))
762 toolbar->icon_size_set = TRUE;
764 gtk_toolbar_unset_icon_size (toolbar);
767 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
773 gtk_toolbar_get_property (GObject *object,
778 GtkToolbar *toolbar = GTK_TOOLBAR (object);
779 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
783 case PROP_ORIENTATION:
784 g_value_set_enum (value, toolbar->orientation);
786 case PROP_TOOLBAR_STYLE:
787 g_value_set_enum (value, toolbar->style);
789 case PROP_SHOW_ARROW:
790 g_value_set_boolean (value, priv->show_arrow);
793 g_value_set_boolean (value, gtk_toolbar_get_tooltips (toolbar));
796 g_value_set_enum (value, gtk_toolbar_get_icon_size (toolbar));
798 case PROP_ICON_SIZE_SET:
799 g_value_set_boolean (value, toolbar->icon_size_set);
802 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
808 gtk_toolbar_map (GtkWidget *widget)
810 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
812 GTK_WIDGET_CLASS (parent_class)->map (widget);
814 if (priv->event_window)
815 gdk_window_show_unraised (priv->event_window);
819 gtk_toolbar_unmap (GtkWidget *widget)
821 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
823 if (priv->event_window)
824 gdk_window_hide (priv->event_window);
826 GTK_WIDGET_CLASS (parent_class)->unmap (widget);
830 gtk_toolbar_realize (GtkWidget *widget)
832 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
833 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
835 GdkWindowAttr attributes;
836 gint attributes_mask;
839 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
841 border_width = GTK_CONTAINER (widget)->border_width;
843 attributes.wclass = GDK_INPUT_ONLY;
844 attributes.window_type = GDK_WINDOW_CHILD;
845 attributes.x = widget->allocation.x + border_width;
846 attributes.y = widget->allocation.y + border_width;
847 attributes.width = widget->allocation.width - border_width * 2;
848 attributes.height = widget->allocation.height - border_width * 2;
849 attributes.event_mask = gtk_widget_get_events (widget);
850 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
851 GDK_BUTTON_RELEASE_MASK |
852 GDK_ENTER_NOTIFY_MASK |
853 GDK_LEAVE_NOTIFY_MASK);
855 attributes_mask = GDK_WA_X | GDK_WA_Y;
857 widget->window = gtk_widget_get_parent_window (widget);
858 g_object_ref (widget->window);
859 widget->style = gtk_style_attach (widget->style, widget->window);
861 priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
862 &attributes, attributes_mask);
863 gdk_window_set_user_data (priv->event_window, toolbar);
867 gtk_toolbar_unrealize (GtkWidget *widget)
869 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
871 if (priv->event_window)
873 gdk_window_set_user_data (priv->event_window, NULL);
874 gdk_window_destroy (priv->event_window);
875 priv->event_window = NULL;
878 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
879 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
883 gtk_toolbar_expose (GtkWidget *widget,
884 GdkEventExpose *event)
886 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
887 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
892 border_width = GTK_CONTAINER (widget)->border_width;
894 if (GTK_WIDGET_DRAWABLE (widget))
896 gtk_paint_box (widget->style,
898 GTK_WIDGET_STATE (widget),
899 get_shadow_type (toolbar),
900 &event->area, widget, "toolbar",
901 border_width + widget->allocation.x,
902 border_width + widget->allocation.y,
903 widget->allocation.width - 2 * border_width,
904 widget->allocation.height - 2 * border_width);
907 for (list = priv->content; list != NULL; list = list->next)
909 ToolbarContent *content = list->data;
911 toolbar_content_expose (content, GTK_CONTAINER (widget), event);
914 gtk_container_propagate_expose (GTK_CONTAINER (widget),
922 gtk_toolbar_size_request (GtkWidget *widget,
923 GtkRequisition *requisition)
925 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
926 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
928 gint max_child_height;
929 gint max_child_width;
930 gint max_homogeneous_child_width;
931 gint max_homogeneous_child_height;
932 gint homogeneous_size;
934 gint pack_front_size;
936 GtkRequisition arrow_requisition;
938 max_homogeneous_child_width = 0;
939 max_homogeneous_child_height = 0;
941 max_child_height = 0;
942 for (list = priv->content; list != NULL; list = list->next)
944 GtkRequisition requisition;
945 ToolbarContent *content = list->data;
947 if (!toolbar_content_visible (content, toolbar))
950 toolbar_content_size_request (content, toolbar, &requisition);
952 max_child_width = MAX (max_child_width, requisition.width);
953 max_child_height = MAX (max_child_height, requisition.height);
955 if (toolbar_content_is_homogeneous (content, toolbar))
957 max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
958 max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
962 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
963 homogeneous_size = max_homogeneous_child_width;
965 homogeneous_size = max_homogeneous_child_height;
968 for (list = priv->content; list != NULL; list = list->next)
970 ToolbarContent *content = list->data;
973 if (!toolbar_content_visible (content, toolbar))
976 if (toolbar_content_is_homogeneous (content, toolbar))
978 size = homogeneous_size;
982 GtkRequisition requisition;
984 toolbar_content_size_request (content, toolbar, &requisition);
986 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
987 size = requisition.width;
989 size = requisition.height;
992 pack_front_size += size;
995 if (priv->show_arrow && priv->api_mode == NEW_API)
997 gtk_widget_size_request (priv->arrow_button, &arrow_requisition);
999 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1000 long_req = arrow_requisition.width;
1002 long_req = arrow_requisition.height;
1004 /* There is no point requesting space for the arrow if that would take
1005 * up more space than all the items combined
1007 long_req = MIN (long_req, pack_front_size);
1011 arrow_requisition.height = 0;
1012 arrow_requisition.width = 0;
1014 long_req = pack_front_size;
1017 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1019 requisition->width = long_req;
1020 requisition->height = MAX (max_child_height, arrow_requisition.height);
1024 requisition->height = long_req;
1025 requisition->width = MAX (max_child_width, arrow_requisition.width);
1029 ipadding = get_internal_padding (toolbar);
1031 requisition->width += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
1032 requisition->height += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
1034 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1036 requisition->width += 2 * widget->style->xthickness;
1037 requisition->height += 2 * widget->style->ythickness;
1040 toolbar->button_maxw = max_homogeneous_child_width;
1041 toolbar->button_maxh = max_homogeneous_child_height;
1045 position (GtkToolbar *toolbar,
1052 if (! GTK_TOOLBAR_GET_PRIVATE (toolbar)->animation)
1055 if (elapsed <= ACCEL_THRESHOLD)
1057 n_pixels = SLIDE_SPEED * elapsed;
1061 /* The formula is a second degree polynomial in
1062 * @elapsed that has the line SLIDE_SPEED * @elapsed
1063 * as tangent for @elapsed == ACCEL_THRESHOLD.
1064 * This makes @n_pixels a smooth function of elapsed time.
1066 n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
1067 SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
1071 return MIN (from + n_pixels, to);
1073 return MAX (from - n_pixels, to);
1077 compute_intermediate_allocation (GtkToolbar *toolbar,
1078 const GtkAllocation *start,
1079 const GtkAllocation *goal,
1080 GtkAllocation *intermediate)
1082 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1083 gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
1085 intermediate->x = position (toolbar, start->x, goal->x, elapsed);
1086 intermediate->y = position (toolbar, start->y, goal->y, elapsed);
1087 intermediate->width = position (toolbar, start->x + start->width,
1088 goal->x + goal->width,
1089 elapsed) - intermediate->x;
1090 intermediate->height = position (toolbar, start->y + start->height,
1091 goal->y + goal->height,
1092 elapsed) - intermediate->y;
1096 fixup_allocation_for_rtl (gint total_size,
1097 GtkAllocation *allocation)
1099 allocation->x += (total_size - (2 * allocation->x + allocation->width));
1103 fixup_allocation_for_vertical (GtkAllocation *allocation)
1107 tmp = allocation->x;
1108 allocation->x = allocation->y;
1109 allocation->y = tmp;
1111 tmp = allocation->width;
1112 allocation->width = allocation->height;
1113 allocation->height = tmp;
1117 get_item_size (GtkToolbar *toolbar,
1118 ToolbarContent *content)
1120 GtkRequisition requisition;
1122 toolbar_content_size_request (content, toolbar, &requisition);
1124 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1126 if (toolbar_content_is_homogeneous (content, toolbar))
1127 return toolbar->button_maxw;
1129 return requisition.width;
1133 if (toolbar_content_is_homogeneous (content, toolbar))
1134 return toolbar->button_maxh;
1136 return requisition.height;
1141 slide_idle_handler (gpointer data)
1143 GtkToolbar *toolbar = data;
1144 GtkToolbarPrivate *priv;
1147 GDK_THREADS_ENTER ();
1149 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1151 if (priv->need_sync)
1154 priv->need_sync = FALSE;
1157 for (list = priv->content; list != NULL; list = list->next)
1159 ToolbarContent *content = list->data;
1161 GtkAllocation goal_allocation;
1162 GtkAllocation allocation;
1165 state = toolbar_content_get_state (content);
1166 toolbar_content_get_goal_allocation (content, &goal_allocation);
1167 toolbar_content_get_allocation (content, &allocation);
1171 if (state == NOT_ALLOCATED)
1173 /* an unallocated item means that size allocate has to
1174 * called at least once more
1179 /* An invisible item with a goal allocation of
1180 * 0 is already at its goal.
1182 if ((state == NORMAL || state == OVERFLOWN) &&
1183 ((goal_allocation.width != 0 &&
1184 goal_allocation.height != 0) ||
1185 toolbar_content_child_visible (content)))
1187 if ((goal_allocation.x != allocation.x ||
1188 goal_allocation.y != allocation.y ||
1189 goal_allocation.width != allocation.width ||
1190 goal_allocation.height != allocation.height))
1192 /* An item is not in its right position yet. Note
1193 * that OVERFLOWN items do get an allocation in
1194 * gtk_toolbar_size_allocate(). This way you can see
1195 * them slide back in when you drag an item off the
1202 if (toolbar_content_is_placeholder (content) &&
1203 toolbar_content_disappearing (content) &&
1204 toolbar_content_child_visible (content))
1206 /* A disappearing placeholder is still visible.
1214 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1216 GDK_THREADS_LEAVE ();
1221 priv->is_sliding = FALSE;
1224 GDK_THREADS_LEAVE();
1229 rect_within (GtkAllocation *a1,
1232 return (a1->x >= a2->x &&
1233 a1->x + a1->width <= a2->x + a2->width &&
1235 a1->y + a1->height <= a2->y + a2->height);
1239 gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
1241 GtkWidget *widget = GTK_WIDGET (toolbar);
1242 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1250 /* Start the sliding. This function copies the allocation of every
1251 * item into content->start_allocation. For items that haven't
1252 * been allocated yet, we calculate their position and save that
1253 * in start_allocatino along with zero width and zero height.
1255 * FIXME: It would be nice if we could share this code with
1256 * the equivalent in gtk_widget_size_allocate().
1258 priv->is_sliding = TRUE;
1261 priv->idle_id = g_idle_add (slide_idle_handler, toolbar);
1263 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1264 vertical = (toolbar->orientation == GTK_ORIENTATION_VERTICAL);
1265 border_width = get_internal_padding (toolbar) + GTK_CONTAINER (toolbar)->border_width;
1269 cur_x = widget->allocation.width - border_width - widget->style->xthickness;
1270 cur_y = widget->allocation.height - border_width - widget->style->ythickness;
1274 cur_x = border_width + widget->style->xthickness;
1275 cur_y = border_width + widget->style->ythickness;
1278 cur_x += widget->allocation.x;
1279 cur_y += widget->allocation.y;
1281 for (list = priv->content; list != NULL; list = list->next)
1283 ToolbarContent *content = list->data;
1284 GtkAllocation new_start_allocation;
1285 GtkAllocation item_allocation;
1288 state = toolbar_content_get_state (content);
1289 toolbar_content_get_allocation (content, &item_allocation);
1291 if ((state == NORMAL &&
1292 rect_within (&item_allocation, &(widget->allocation))) ||
1295 new_start_allocation = item_allocation;
1299 new_start_allocation.x = cur_x;
1300 new_start_allocation.y = cur_y;
1304 new_start_allocation.width = widget->allocation.width -
1305 2 * border_width - 2 * widget->style->xthickness;
1306 new_start_allocation.height = 0;
1310 new_start_allocation.width = 0;
1311 new_start_allocation.height = widget->allocation.height -
1312 2 * border_width - 2 * widget->style->ythickness;
1317 cur_y = new_start_allocation.y + new_start_allocation.height;
1319 cur_x = new_start_allocation.x;
1321 cur_x = new_start_allocation.x + new_start_allocation.width;
1323 toolbar_content_set_start_allocation (content, &new_start_allocation);
1326 /* This resize will run before the first idle handler. This
1327 * will make sure that items get the right goal allocation
1328 * so that the idle handler will not immediately return
1331 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1332 g_timer_reset (priv->timer);
1336 gtk_toolbar_stop_sliding (GtkToolbar *toolbar)
1338 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1340 if (priv->is_sliding)
1344 priv->is_sliding = FALSE;
1348 g_source_remove (priv->idle_id);
1352 list = priv->content;
1355 ToolbarContent *content = list->data;
1358 if (toolbar_content_is_placeholder (content))
1360 toolbar_content_remove (content, toolbar);
1361 toolbar_content_free (content);
1365 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1370 remove_item (GtkWidget *menu_item,
1373 gtk_container_remove (GTK_CONTAINER (menu_item->parent), menu_item);
1377 menu_deactivated (GtkWidget *menu,
1378 GtkToolbar *toolbar)
1380 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1381 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->arrow_button), FALSE);
1385 menu_detached (GtkWidget *toolbar,
1388 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1393 rebuild_menu (GtkToolbar *toolbar)
1395 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1396 GList *list, *children;
1400 priv->menu = GTK_MENU (gtk_menu_new());
1401 gtk_menu_attach_to_widget (priv->menu,
1402 GTK_WIDGET (toolbar),
1405 g_signal_connect (priv->menu, "deactivate", G_CALLBACK (menu_deactivated), toolbar);
1408 gtk_container_foreach (GTK_CONTAINER (priv->menu), remove_item, NULL);
1410 for (list = priv->content; list != NULL; list = list->next)
1412 ToolbarContent *content = list->data;
1414 if (toolbar_content_get_state (content) == OVERFLOWN &&
1415 !toolbar_content_is_placeholder (content))
1417 GtkWidget *menu_item = toolbar_content_retrieve_menu_item (content);
1421 g_assert (GTK_IS_MENU_ITEM (menu_item));
1422 gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item);
1427 /* Remove leading and trailing separator items */
1428 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1431 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1433 GtkWidget *child = list->data;
1435 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1438 g_list_free (children);
1440 /* Regenerate the list of children so we don't try to remove items twice */
1441 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1443 list = g_list_last (children);
1444 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1446 GtkWidget *child = list->data;
1448 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1451 g_list_free (children);
1453 priv->need_rebuild = FALSE;
1457 gtk_toolbar_size_allocate (GtkWidget *widget,
1458 GtkAllocation *allocation)
1460 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1461 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1462 GtkAllocation *allocations;
1463 ItemState *new_states;
1464 GtkAllocation arrow_allocation;
1466 gint size, pos, short_size;
1469 gboolean need_arrow;
1470 gint n_expand_items;
1472 gint available_size;
1475 GtkRequisition arrow_requisition;
1476 gboolean overflowing;
1477 gboolean size_changed;
1479 GtkAllocation item_area;
1481 size_changed = FALSE;
1482 if (widget->allocation.x != allocation->x ||
1483 widget->allocation.y != allocation->y ||
1484 widget->allocation.width != allocation->width ||
1485 widget->allocation.height != allocation->height)
1487 size_changed = TRUE;
1491 gtk_toolbar_stop_sliding (toolbar);
1493 widget->allocation = *allocation;
1495 border_width = GTK_CONTAINER (toolbar)->border_width;
1497 if (GTK_WIDGET_REALIZED (widget))
1499 gdk_window_move_resize (priv->event_window,
1500 allocation->x + border_width,
1501 allocation->y + border_width,
1502 allocation->width - border_width * 2,
1503 allocation->height - border_width * 2);
1506 border_width += get_internal_padding (toolbar);
1508 gtk_widget_get_child_requisition (GTK_WIDGET (priv->arrow_button),
1509 &arrow_requisition);
1511 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1513 available_size = size = allocation->width - 2 * border_width;
1514 short_size = allocation->height - 2 * border_width;
1515 arrow_size = arrow_requisition.width;
1517 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1519 available_size -= 2 * widget->style->xthickness;
1520 short_size -= 2 * widget->style->ythickness;
1525 available_size = size = allocation->height - 2 * border_width;
1526 short_size = allocation->width - 2 * border_width;
1527 arrow_size = arrow_requisition.height;
1529 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1531 available_size -= 2 * widget->style->ythickness;
1532 short_size -= 2 * widget->style->xthickness;
1536 n_items = g_list_length (priv->content);
1537 allocations = g_new0 (GtkAllocation, n_items);
1538 new_states = g_new0 (ItemState, n_items);
1542 for (list = priv->content; list != NULL; list = list->next)
1544 ToolbarContent *content = list->data;
1546 if (toolbar_content_visible (content, toolbar))
1548 needed_size += get_item_size (toolbar, content);
1550 /* Do we need an arrow?
1552 * Assume we don't, and see if any non-separator item with a
1553 * proxy menu item is then going to overflow.
1555 if (needed_size > available_size &&
1558 priv->api_mode == NEW_API &&
1559 toolbar_content_has_proxy_menu_item (content) &&
1560 !toolbar_content_is_separator (content))
1568 size = available_size - arrow_size;
1570 size = available_size;
1572 /* calculate widths and states of items */
1573 overflowing = FALSE;
1574 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1576 ToolbarContent *content = list->data;
1579 if (!toolbar_content_visible (content, toolbar))
1581 new_states[i] = HIDDEN;
1585 item_size = get_item_size (toolbar, content);
1586 if (item_size <= size && !overflowing)
1589 allocations[i].width = item_size;
1590 new_states[i] = NORMAL;
1595 new_states[i] = OVERFLOWN;
1596 allocations[i].width = item_size;
1600 /* calculate width of arrow */
1603 arrow_allocation.width = arrow_size;
1604 arrow_allocation.height = MAX (short_size, 1);
1607 /* expand expandable items */
1609 /* We don't expand when there is an overflow menu, because that leads to
1610 * weird jumps when items get moved to the overflow menu and the expanding
1611 * items suddenly get a lot of extra space
1616 for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
1618 ToolbarContent *content = list->data;
1620 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1624 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1626 ToolbarContent *content = list->data;
1628 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1630 gint extra = size / n_expand_items;
1631 if (size % n_expand_items != 0)
1634 allocations[i].width += extra;
1640 g_assert (n_expand_items == 0);
1643 /* position items */
1645 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1647 /* both NORMAL and OVERFLOWN items get a position. This ensures
1648 * that sliding will work for OVERFLOWN items too
1650 if (new_states[i] == NORMAL ||
1651 new_states[i] == OVERFLOWN)
1653 allocations[i].x = pos;
1654 allocations[i].y = border_width;
1655 allocations[i].height = short_size;
1657 pos += allocations[i].width;
1661 /* position arrow */
1664 arrow_allocation.x = available_size - border_width - arrow_allocation.width;
1665 arrow_allocation.y = border_width;
1668 item_area.x = border_width;
1669 item_area.y = border_width;
1670 item_area.width = available_size - (need_arrow? arrow_size : 0);
1671 item_area.height = short_size;
1673 /* fix up allocations in the vertical or RTL cases */
1674 if (toolbar->orientation == GTK_ORIENTATION_VERTICAL)
1676 for (i = 0; i < n_items; ++i)
1677 fixup_allocation_for_vertical (&(allocations[i]));
1680 fixup_allocation_for_vertical (&arrow_allocation);
1682 fixup_allocation_for_vertical (&item_area);
1684 else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1686 for (i = 0; i < n_items; ++i)
1687 fixup_allocation_for_rtl (available_size, &(allocations[i]));
1690 fixup_allocation_for_rtl (available_size, &arrow_allocation);
1692 fixup_allocation_for_rtl (available_size, &item_area);
1695 /* translate the items by allocation->(x,y) */
1696 for (i = 0; i < n_items; ++i)
1698 allocations[i].x += allocation->x;
1699 allocations[i].y += allocation->y;
1701 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1703 allocations[i].x += widget->style->xthickness;
1704 allocations[i].y += widget->style->ythickness;
1710 arrow_allocation.x += allocation->x;
1711 arrow_allocation.y += allocation->y;
1713 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1715 arrow_allocation.x += widget->style->xthickness;
1716 arrow_allocation.y += widget->style->ythickness;
1720 item_area.x += allocation->x;
1721 item_area.y += allocation->y;
1722 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1724 item_area.x += widget->style->xthickness;
1725 item_area.y += widget->style->ythickness;
1728 /* did anything change? */
1729 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1731 ToolbarContent *content = list->data;
1733 if (toolbar_content_get_state (content) == NORMAL &&
1734 new_states[i] != NORMAL)
1736 /* an item disappeared and we didn't change size, so begin sliding */
1737 if (!size_changed && priv->api_mode == NEW_API)
1738 gtk_toolbar_begin_sliding (toolbar);
1742 /* finally allocate the items */
1743 if (priv->is_sliding)
1745 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1747 ToolbarContent *content = list->data;
1749 toolbar_content_set_goal_allocation (content, &(allocations[i]));
1753 elapsed = g_timer_elapsed (priv->timer, NULL);
1754 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1756 ToolbarContent *content = list->data;
1758 if (new_states[i] == OVERFLOWN ||
1759 new_states[i] == NORMAL)
1761 GtkAllocation alloc;
1762 GtkAllocation start_allocation = { 0, };
1763 GtkAllocation goal_allocation;
1765 if (priv->is_sliding)
1767 toolbar_content_get_start_allocation (content, &start_allocation);
1768 toolbar_content_get_goal_allocation (content, &goal_allocation);
1770 compute_intermediate_allocation (toolbar,
1775 priv->need_sync = TRUE;
1779 alloc = allocations[i];
1782 if (alloc.width <= 0 || alloc.height <= 0)
1784 toolbar_content_set_child_visible (content, toolbar, FALSE);
1788 if (!rect_within (&alloc, &item_area))
1790 toolbar_content_set_child_visible (content, toolbar, FALSE);
1791 toolbar_content_size_allocate (content, &alloc);
1795 toolbar_content_set_child_visible (content, toolbar, TRUE);
1796 toolbar_content_size_allocate (content, &alloc);
1802 toolbar_content_set_child_visible (content, toolbar, FALSE);
1805 toolbar_content_set_state (content, new_states[i]);
1808 if (priv->menu && priv->need_rebuild)
1809 rebuild_menu (toolbar);
1813 gtk_widget_size_allocate (GTK_WIDGET (priv->arrow_button),
1815 gtk_widget_show (GTK_WIDGET (priv->arrow_button));
1819 gtk_widget_hide (GTK_WIDGET (priv->arrow_button));
1821 if (priv->menu && GTK_WIDGET_VISIBLE (priv->menu))
1822 gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
1825 g_free (allocations);
1826 g_free (new_states);
1830 gtk_toolbar_update_button_relief (GtkToolbar *toolbar)
1832 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1834 gtk_toolbar_reconfigured (toolbar);
1836 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), get_button_relief (toolbar));
1840 gtk_toolbar_style_set (GtkWidget *widget,
1841 GtkStyle *prev_style)
1843 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
1845 priv->max_homogeneous_pixels = -1;
1847 if (GTK_WIDGET_REALIZED (widget))
1848 gtk_style_set_background (widget->style, widget->window, widget->state);
1851 gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
1855 gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
1856 GtkDirectionType dir)
1858 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1859 GList *result = NULL;
1863 /* generate list of children in reverse logical order */
1865 for (list = priv->content; list != NULL; list = list->next)
1867 ToolbarContent *content = list->data;
1870 widget = toolbar_content_get_widget (content);
1873 result = g_list_prepend (result, widget);
1876 result = g_list_prepend (result, priv->arrow_button);
1878 rtl = (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL);
1880 /* move in logical order when
1882 * - dir is TAB_FORWARD
1884 * - in RTL mode and moving left or up
1886 * - in LTR mode and moving right or down
1888 if (dir == GTK_DIR_TAB_FORWARD ||
1889 (rtl && (dir == GTK_DIR_UP || dir == GTK_DIR_LEFT)) ||
1890 (!rtl && (dir == GTK_DIR_DOWN || dir == GTK_DIR_RIGHT)))
1892 result = g_list_reverse (result);
1899 gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
1900 gboolean focus_home)
1902 GList *children, *list;
1903 GtkDirectionType dir = focus_home? GTK_DIR_RIGHT : GTK_DIR_LEFT;
1905 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1907 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1909 children = g_list_reverse (children);
1911 dir = (dir == GTK_DIR_RIGHT)? GTK_DIR_LEFT : GTK_DIR_RIGHT;
1914 for (list = children; list != NULL; list = list->next)
1916 GtkWidget *child = list->data;
1918 if (GTK_CONTAINER (toolbar)->focus_child == child)
1921 if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1925 g_list_free (children);
1930 /* Keybinding handler. This function is called when the user presses
1931 * Ctrl TAB or an arrow key.
1934 gtk_toolbar_move_focus (GtkToolbar *toolbar,
1935 GtkDirectionType dir)
1938 gboolean try_focus = FALSE;
1940 GtkContainer *container = GTK_CONTAINER (toolbar);
1942 if (container->focus_child &&
1943 gtk_widget_child_focus (container->focus_child, dir))
1948 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1950 for (list = children; list != NULL; list = list->next)
1952 GtkWidget *child = list->data;
1954 if (try_focus && GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1957 if (child == GTK_CONTAINER (toolbar)->focus_child)
1961 g_list_free (children);
1966 /* The focus handler for the toolbar. It called when the user presses
1967 * TAB or otherwise tries to focus the toolbar.
1970 gtk_toolbar_focus (GtkWidget *widget,
1971 GtkDirectionType dir)
1973 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1974 GList *children, *list;
1975 gboolean result = FALSE;
1977 /* if focus is already somewhere inside the toolbar then return FALSE.
1978 * The only way focus can stay inside the toolbar is when the user presses
1979 * arrow keys or Ctrl TAB (both of which are handled by the
1980 * gtk_toolbar_move_focus() keybinding function.
1982 if (GTK_CONTAINER (widget)->focus_child)
1985 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1987 for (list = children; list != NULL; list = list->next)
1989 GtkWidget *child = list->data;
1991 if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1998 g_list_free (children);
2003 static GtkSettings *
2004 toolbar_get_settings (GtkToolbar *toolbar)
2006 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2007 return priv->settings;
2011 style_change_notify (GtkToolbar *toolbar)
2013 if (!toolbar->style_set)
2015 /* pretend it was set, then unset, thus reverting to new default */
2016 toolbar->style_set = TRUE;
2017 gtk_toolbar_unset_style (toolbar);
2022 icon_size_change_notify (GtkToolbar *toolbar)
2024 if (!toolbar->icon_size_set)
2026 /* pretend it was set, then unset, thus reverting to new default */
2027 toolbar->icon_size_set = TRUE;
2028 gtk_toolbar_unset_icon_size (toolbar);
2033 animation_change_notify (GtkToolbar *toolbar)
2035 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2036 GtkSettings *settings = toolbar_get_settings (toolbar);
2040 g_object_get (settings,
2041 "gtk-enable-animations", &animation,
2044 animation = DEFAULT_ANIMATION_STATE;
2046 priv->animation = animation;
2050 settings_change_notify (GtkSettings *settings,
2051 const GParamSpec *pspec,
2052 GtkToolbar *toolbar)
2054 if (! strcmp (pspec->name, "gtk-toolbar-style"))
2055 style_change_notify (toolbar);
2056 else if (! strcmp (pspec->name, "gtk-toolbar-icon-size"))
2057 icon_size_change_notify (toolbar);
2058 else if (! strcmp (pspec->name, "gtk-enable-animations"))
2059 animation_change_notify (toolbar);
2063 gtk_toolbar_screen_changed (GtkWidget *widget,
2064 GdkScreen *previous_screen)
2066 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2067 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2068 GtkSettings *old_settings = toolbar_get_settings (toolbar);
2069 GtkSettings *settings;
2071 if (gtk_widget_has_screen (GTK_WIDGET (toolbar)))
2072 settings = gtk_widget_get_settings (GTK_WIDGET (toolbar));
2076 if (settings == old_settings)
2081 g_signal_handler_disconnect (old_settings, priv->settings_connection);
2083 g_object_unref (old_settings);
2088 priv->settings_connection =
2089 g_signal_connect (settings, "notify",
2090 G_CALLBACK (settings_change_notify),
2093 priv->settings = g_object_ref (settings);
2096 priv->settings = NULL;
2098 style_change_notify (toolbar);
2099 icon_size_change_notify (toolbar);
2100 animation_change_notify (toolbar);
2104 find_drop_index (GtkToolbar *toolbar,
2108 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2109 GList *interesting_content;
2111 GtkOrientation orientation;
2112 GtkTextDirection direction;
2113 gint best_distance = G_MAXINT;
2117 ToolbarContent *best_content;
2118 GtkAllocation allocation;
2120 /* list items we care about wrt. drag and drop */
2121 interesting_content = NULL;
2122 for (list = priv->content; list != NULL; list = list->next)
2124 ToolbarContent *content = list->data;
2126 if (toolbar_content_get_state (content) == NORMAL)
2127 interesting_content = g_list_prepend (interesting_content, content);
2129 interesting_content = g_list_reverse (interesting_content);
2131 if (!interesting_content)
2134 orientation = toolbar->orientation;
2135 direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
2137 /* distance to first interesting item */
2138 best_content = interesting_content->data;
2139 toolbar_content_get_allocation (best_content, &allocation);
2141 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2145 if (direction == GTK_TEXT_DIR_LTR)
2148 pos = allocation.x + allocation.width;
2156 best_content = NULL;
2157 best_distance = ABS (pos - cursor);
2159 /* distance to far end of each item */
2160 for (list = interesting_content; list != NULL; list = list->next)
2162 ToolbarContent *content = list->data;
2164 toolbar_content_get_allocation (content, &allocation);
2166 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2168 if (direction == GTK_TEXT_DIR_LTR)
2169 pos = allocation.x + allocation.width;
2175 pos = allocation.y + allocation.height;
2178 distance = ABS (pos - cursor);
2180 if (distance < best_distance)
2182 best_distance = distance;
2183 best_content = content;
2187 g_list_free (interesting_content);
2192 return g_list_index (priv->content, best_content) + 1;
2196 reset_all_placeholders (GtkToolbar *toolbar)
2198 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2201 for (list = priv->content; list != NULL; list = list->next)
2203 ToolbarContent *content = list->data;
2204 if (toolbar_content_is_placeholder (content))
2205 toolbar_content_set_disappearing (content, TRUE);
2210 physical_to_logical (GtkToolbar *toolbar,
2213 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2217 g_assert (physical >= 0);
2220 for (list = priv->content; list && physical > 0; list = list->next)
2222 ToolbarContent *content = list->data;
2224 if (!toolbar_content_is_placeholder (content))
2229 g_assert (physical == 0);
2235 logical_to_physical (GtkToolbar *toolbar,
2238 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2242 g_assert (logical >= 0);
2245 for (list = priv->content; list; list = list->next)
2247 ToolbarContent *content = list->data;
2249 if (!toolbar_content_is_placeholder (content))
2259 g_assert (logical == 0);
2265 * gtk_toolbar_set_drop_highlight_item:
2266 * @toolbar: a #GtkToolbar
2267 * @tool_item: a #GtkToolItem, or %NULL to turn of highlighting
2268 * @index_: a position on @toolbar
2270 * Highlights @toolbar to give an idea of what it would look like
2271 * if @item was added to @toolbar at the position indicated by @index_.
2272 * If @item is %NULL, highlighting is turned off. In that case @index_
2275 * The @tool_item passed to this function must not be part of any widget
2276 * hierarchy. When an item is set as drop highlight item it can not
2277 * added to any widget hierarchy or used as highlight item for another
2283 gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar,
2284 GtkToolItem *tool_item,
2287 ToolbarContent *content;
2288 GtkToolbarPrivate *priv;
2290 GtkRequisition requisition;
2291 GtkRequisition old_requisition;
2292 gboolean restart_sliding;
2294 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2295 g_return_if_fail (tool_item == NULL || GTK_IS_TOOL_ITEM (tool_item));
2297 gtk_toolbar_check_new_api (toolbar);
2299 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2303 if (priv->highlight_tool_item)
2305 gtk_widget_unparent (GTK_WIDGET (priv->highlight_tool_item));
2306 g_object_unref (priv->highlight_tool_item);
2307 priv->highlight_tool_item = NULL;
2310 reset_all_placeholders (toolbar);
2311 gtk_toolbar_begin_sliding (toolbar);
2315 n_items = gtk_toolbar_get_n_items (toolbar);
2316 if (index_ < 0 || index_ > n_items)
2319 if (tool_item != priv->highlight_tool_item)
2321 if (priv->highlight_tool_item)
2322 g_object_unref (priv->highlight_tool_item);
2324 g_object_ref_sink (tool_item);
2326 priv->highlight_tool_item = tool_item;
2328 gtk_widget_set_parent (GTK_WIDGET (priv->highlight_tool_item),
2329 GTK_WIDGET (toolbar));
2332 index_ = logical_to_physical (toolbar, index_);
2334 content = g_list_nth_data (priv->content, index_);
2338 ToolbarContent *prev_content;
2340 prev_content = g_list_nth_data (priv->content, index_ - 1);
2342 if (prev_content && toolbar_content_is_placeholder (prev_content))
2343 content = prev_content;
2346 if (!content || !toolbar_content_is_placeholder (content))
2348 GtkWidget *placeholder;
2350 placeholder = GTK_WIDGET (gtk_separator_tool_item_new ());
2352 content = toolbar_content_new_tool_item (toolbar,
2353 GTK_TOOL_ITEM (placeholder),
2355 gtk_widget_show (placeholder);
2359 g_assert (toolbar_content_is_placeholder (content));
2361 gtk_widget_size_request (GTK_WIDGET (priv->highlight_tool_item),
2364 toolbar_content_set_expand (content, gtk_tool_item_get_expand (tool_item));
2366 restart_sliding = FALSE;
2367 toolbar_content_size_request (content, toolbar, &old_requisition);
2368 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2370 requisition.height = -1;
2371 if (requisition.width != old_requisition.width)
2372 restart_sliding = TRUE;
2376 requisition.width = -1;
2377 if (requisition.height != old_requisition.height)
2378 restart_sliding = TRUE;
2381 if (toolbar_content_disappearing (content))
2382 restart_sliding = TRUE;
2384 reset_all_placeholders (toolbar);
2385 toolbar_content_set_disappearing (content, FALSE);
2387 toolbar_content_set_size_request (content,
2388 requisition.width, requisition.height);
2390 if (restart_sliding)
2391 gtk_toolbar_begin_sliding (toolbar);
2395 gtk_toolbar_get_child_property (GtkContainer *container,
2401 GtkToolItem *item = GTK_TOOL_ITEM (child);
2403 switch (property_id)
2405 case CHILD_PROP_HOMOGENEOUS:
2406 g_value_set_boolean (value, gtk_tool_item_get_homogeneous (item));
2409 case CHILD_PROP_EXPAND:
2410 g_value_set_boolean (value, gtk_tool_item_get_expand (item));
2414 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2420 gtk_toolbar_set_child_property (GtkContainer *container,
2423 const GValue *value,
2426 switch (property_id)
2428 case CHILD_PROP_HOMOGENEOUS:
2429 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2432 case CHILD_PROP_EXPAND:
2433 gtk_tool_item_set_expand (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2437 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2443 gtk_toolbar_show_all (GtkWidget *widget)
2445 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2448 for (list = priv->content; list != NULL; list = list->next)
2450 ToolbarContent *content = list->data;
2452 toolbar_content_show_all (content);
2455 gtk_widget_show (widget);
2459 gtk_toolbar_hide_all (GtkWidget *widget)
2461 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2464 for (list = priv->content; list != NULL; list = list->next)
2466 ToolbarContent *content = list->data;
2468 toolbar_content_hide_all (content);
2471 gtk_widget_hide (widget);
2475 gtk_toolbar_add (GtkContainer *container,
2478 GtkToolbar *toolbar;
2480 g_return_if_fail (GTK_IS_TOOLBAR (container));
2481 g_return_if_fail (widget != NULL);
2483 toolbar = GTK_TOOLBAR (container);
2485 if (GTK_IS_TOOL_ITEM (widget))
2486 gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
2488 gtk_toolbar_append_widget (toolbar, widget, NULL, NULL);
2492 gtk_toolbar_remove (GtkContainer *container,
2495 GtkToolbar *toolbar;
2496 GtkToolbarPrivate *priv;
2497 ToolbarContent *content_to_remove;
2500 g_return_if_fail (GTK_IS_TOOLBAR (container));
2501 g_return_if_fail (GTK_IS_WIDGET (widget));
2503 toolbar = GTK_TOOLBAR (container);
2504 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2506 content_to_remove = NULL;
2507 for (list = priv->content; list != NULL; list = list->next)
2509 ToolbarContent *content = list->data;
2512 child = toolbar_content_get_widget (content);
2513 if (child && child == widget)
2515 content_to_remove = content;
2520 g_return_if_fail (content_to_remove != NULL);
2522 toolbar_content_remove (content_to_remove, toolbar);
2523 toolbar_content_free (content_to_remove);
2527 gtk_toolbar_forall (GtkContainer *container,
2528 gboolean include_internals,
2529 GtkCallback callback,
2530 gpointer callback_data)
2532 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2533 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2536 g_return_if_fail (callback != NULL);
2538 list = priv->content;
2541 ToolbarContent *content = list->data;
2542 GList *next = list->next;
2544 if (include_internals || !toolbar_content_is_placeholder (content))
2546 GtkWidget *child = toolbar_content_get_widget (content);
2549 (*callback) (child, callback_data);
2555 if (include_internals)
2556 (* callback) (priv->arrow_button, callback_data);
2560 gtk_toolbar_child_type (GtkContainer *container)
2562 return GTK_TYPE_TOOL_ITEM;
2566 gtk_toolbar_reconfigured (GtkToolbar *toolbar)
2568 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2571 list = priv->content;
2574 ToolbarContent *content = list->data;
2575 GList *next = list->next;
2577 toolbar_content_toolbar_reconfigured (content, toolbar);
2584 gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
2585 GtkOrientation orientation)
2587 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2588 if (toolbar->orientation != orientation)
2590 toolbar->orientation = orientation;
2592 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2593 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2595 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2597 gtk_toolbar_reconfigured (toolbar);
2599 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2600 g_object_notify (G_OBJECT (toolbar), "orientation");
2605 gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
2606 GtkToolbarStyle style)
2608 if (toolbar->style != style)
2610 toolbar->style = style;
2612 gtk_toolbar_reconfigured (toolbar);
2614 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2615 g_object_notify (G_OBJECT (toolbar), "toolbar-style");
2620 menu_position_func (GtkMenu *menu,
2626 GtkToolbar *toolbar = GTK_TOOLBAR (user_data);
2627 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2629 GtkRequisition menu_req;
2630 GdkRectangle monitor;
2634 gtk_widget_size_request (priv->arrow_button, &req);
2635 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2637 screen = gtk_widget_get_screen (GTK_WIDGET (menu));
2638 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->arrow_button->window);
2639 if (monitor_num < 0)
2641 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2643 gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
2644 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2646 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2647 *x += priv->arrow_button->allocation.width - req.width;
2649 *x += req.width - menu_req.width;
2651 if ((*y + priv->arrow_button->allocation.height + menu_req.height) <= monitor.y + monitor.height)
2652 *y += priv->arrow_button->allocation.height;
2653 else if ((*y - menu_req.height) >= monitor.y)
2654 *y -= menu_req.height;
2655 else if (monitor.y + monitor.height - (*y + priv->arrow_button->allocation.height) > *y)
2656 *y += priv->arrow_button->allocation.height;
2658 *y -= menu_req.height;
2662 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2663 *x += priv->arrow_button->allocation.width;
2665 *x -= menu_req.width;
2667 if (*y + menu_req.height > monitor.y + monitor.height &&
2668 *y + priv->arrow_button->allocation.height - monitor.y > monitor.y + monitor.height - *y)
2669 *y += priv->arrow_button->allocation.height - menu_req.height;
2676 show_menu (GtkToolbar *toolbar,
2677 GdkEventButton *event)
2679 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2681 rebuild_menu (toolbar);
2683 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2685 gtk_menu_popup (priv->menu, NULL, NULL,
2686 menu_position_func, toolbar,
2687 event? event->button : 0,
2688 event? event->time : gtk_get_current_event_time());
2692 gtk_toolbar_arrow_button_clicked (GtkWidget *button,
2693 GtkToolbar *toolbar)
2695 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2697 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) &&
2698 (!priv->menu || !GTK_WIDGET_VISIBLE (priv->menu)))
2700 /* We only get here when the button is clicked with the keyboard,
2701 * because mouse button presses result in the menu being shown so
2702 * that priv->menu would be non-NULL and visible.
2704 show_menu (toolbar, NULL);
2705 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
2710 gtk_toolbar_arrow_button_press (GtkWidget *button,
2711 GdkEventButton *event,
2712 GtkToolbar *toolbar)
2714 show_menu (toolbar, event);
2715 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
2721 gtk_toolbar_button_press (GtkWidget *toolbar,
2722 GdkEventButton *event)
2724 if (event->button == 3)
2726 gboolean return_value;
2728 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2729 (int)event->x_root, (int)event->y_root, event->button,
2732 return return_value;
2739 gtk_toolbar_popup_menu (GtkWidget *toolbar)
2741 gboolean return_value;
2742 /* This function is the handler for the "popup menu" keybinding,
2743 * ie., it is called when the user presses Shift F10
2745 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2746 -1, -1, -1, &return_value);
2748 return return_value;
2754 * Creates a new toolbar.
2756 * Return Value: the newly-created toolbar.
2759 gtk_toolbar_new (void)
2761 GtkToolbar *toolbar;
2763 toolbar = g_object_new (GTK_TYPE_TOOLBAR, NULL);
2765 return GTK_WIDGET (toolbar);
2769 * gtk_toolbar_insert:
2770 * @toolbar: a #GtkToolbar
2771 * @item: a #GtkToolItem
2772 * @pos: the position of the new item
2774 * Insert a #GtkToolItem into the toolbar at position @pos. If @pos is
2775 * 0 the item is prepended to the start of the toolbar. If @pos is
2776 * negative, the item is appended to the end of the toolbar.
2781 gtk_toolbar_insert (GtkToolbar *toolbar,
2785 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2786 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
2788 if (!gtk_toolbar_check_new_api (toolbar))
2792 pos = logical_to_physical (toolbar, pos);
2794 toolbar_content_new_tool_item (toolbar, item, FALSE, pos);
2798 * gtk_toolbar_get_item_index:
2799 * @toolbar: a #GtkToolbar
2800 * @item: a #GtkToolItem that is a child of @toolbar
2802 * Returns the position of @item on the toolbar, starting from 0.
2803 * It is an error if @item is not a child of the toolbar.
2805 * Return value: the position of item on the toolbar.
2810 gtk_toolbar_get_item_index (GtkToolbar *toolbar,
2813 GtkToolbarPrivate *priv;
2817 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2818 g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
2819 g_return_val_if_fail (GTK_WIDGET (item)->parent == GTK_WIDGET (toolbar), -1);
2821 if (!gtk_toolbar_check_new_api (toolbar))
2824 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2827 for (list = priv->content; list != NULL; list = list->next)
2829 ToolbarContent *content = list->data;
2832 widget = toolbar_content_get_widget (content);
2834 if (item == GTK_TOOL_ITEM (widget))
2840 return physical_to_logical (toolbar, n);
2844 * gtk_toolbar_set_orientation:
2845 * @toolbar: a #GtkToolbar.
2846 * @orientation: a new #GtkOrientation.
2848 * Sets whether a toolbar should appear horizontally or vertically.
2851 gtk_toolbar_set_orientation (GtkToolbar *toolbar,
2852 GtkOrientation orientation)
2854 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2856 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0, orientation);
2860 * gtk_toolbar_get_orientation:
2861 * @toolbar: a #GtkToolbar
2863 * Retrieves the current orientation of the toolbar. See
2864 * gtk_toolbar_set_orientation().
2866 * Return value: the orientation
2869 gtk_toolbar_get_orientation (GtkToolbar *toolbar)
2871 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_ORIENTATION_HORIZONTAL);
2873 return toolbar->orientation;
2877 * gtk_toolbar_set_style:
2878 * @toolbar: a #GtkToolbar.
2879 * @style: the new style for @toolbar.
2881 * Alters the view of @toolbar to display either icons only, text only, or both.
2884 gtk_toolbar_set_style (GtkToolbar *toolbar,
2885 GtkToolbarStyle style)
2887 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2889 toolbar->style_set = TRUE;
2890 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2894 * gtk_toolbar_get_style:
2895 * @toolbar: a #GtkToolbar
2897 * Retrieves whether the toolbar has text, icons, or both . See
2898 * gtk_toolbar_set_style().
2900 * Return value: the current style of @toolbar
2903 gtk_toolbar_get_style (GtkToolbar *toolbar)
2905 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_TOOLBAR_STYLE);
2907 return toolbar->style;
2911 * gtk_toolbar_unset_style:
2912 * @toolbar: a #GtkToolbar
2914 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that
2915 * user preferences will be used to determine the toolbar style.
2918 gtk_toolbar_unset_style (GtkToolbar *toolbar)
2920 GtkToolbarStyle style;
2922 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2924 if (toolbar->style_set)
2926 GtkSettings *settings = toolbar_get_settings (toolbar);
2929 g_object_get (settings,
2930 "gtk-toolbar-style", &style,
2933 style = DEFAULT_TOOLBAR_STYLE;
2935 if (style != toolbar->style)
2936 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2938 toolbar->style_set = FALSE;
2943 * gtk_toolbar_set_tooltips:
2944 * @toolbar: a #GtkToolbar.
2945 * @enable: set to %FALSE to disable the tooltips, or %TRUE to enable them.
2947 * Sets if the tooltips of a toolbar should be active or not.
2950 gtk_toolbar_set_tooltips (GtkToolbar *toolbar,
2953 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2956 gtk_tooltips_enable (toolbar->tooltips);
2958 gtk_tooltips_disable (toolbar->tooltips);
2960 g_object_notify (G_OBJECT (toolbar), "tooltips");
2964 * gtk_toolbar_get_tooltips:
2965 * @toolbar: a #GtkToolbar
2967 * Retrieves whether tooltips are enabled. See
2968 * gtk_toolbar_set_tooltips().
2970 * Return value: %TRUE if tooltips are enabled
2973 gtk_toolbar_get_tooltips (GtkToolbar *toolbar)
2975 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
2977 return toolbar->tooltips->enabled;
2981 * gtk_toolbar_get_n_items:
2982 * @toolbar: a #GtkToolbar
2984 * Returns the number of items on the toolbar.
2986 * Return value: the number of items on the toolbar
2991 gtk_toolbar_get_n_items (GtkToolbar *toolbar)
2993 GtkToolbarPrivate *priv;
2995 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2997 if (!gtk_toolbar_check_new_api (toolbar))
3000 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3002 return physical_to_logical (toolbar, g_list_length (priv->content));
3006 * gtk_toolbar_get_nth_item:
3007 * @toolbar: a #GtkToolbar
3008 * @n: A position on the toolbar
3010 * Returns the @n<!-- -->'th item on @toolbar, or %NULL if the
3011 * toolbar does not contain an @n<!-- -->'th item.
3013 * Return value: The @n<!-- -->'th #GtkToolItem on @toolbar, or %NULL if there
3014 * isn't an @n<!-- -->'th item.
3019 gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
3022 GtkToolbarPrivate *priv;
3023 ToolbarContent *content;
3026 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
3028 if (!gtk_toolbar_check_new_api (toolbar))
3031 n_items = gtk_toolbar_get_n_items (toolbar);
3033 if (n < 0 || n >= n_items)
3036 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3038 content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
3041 g_assert (!toolbar_content_is_placeholder (content));
3043 return GTK_TOOL_ITEM (toolbar_content_get_widget (content));
3047 * gtk_toolbar_get_icon_size:
3048 * @toolbar: a #GtkToolbar
3050 * Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size().
3052 * Return value: the current icon size for the icons on the toolbar.
3055 gtk_toolbar_get_icon_size (GtkToolbar *toolbar)
3057 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_ICON_SIZE);
3059 return toolbar->icon_size;
3063 * gtk_toolbar_get_relief_style:
3064 * @toolbar: a #GtkToolbar
3066 * Returns the relief style of buttons on @toolbar. See
3067 * gtk_button_set_relief().
3069 * Return value: The relief style of buttons on @toolbar.
3074 gtk_toolbar_get_relief_style (GtkToolbar *toolbar)
3076 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_RELIEF_NONE);
3078 return get_button_relief (toolbar);
3082 * gtk_toolbar_set_show_arrow:
3083 * @toolbar: a #GtkToolbar
3084 * @show_arrow: Whether to show an overflow menu
3086 * Sets whether to show an overflow menu when
3087 * @toolbar doesn't have room for all items on it. If %TRUE,
3088 * items that there are not room are available through an
3094 gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
3095 gboolean show_arrow)
3097 GtkToolbarPrivate *priv;
3099 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3101 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3102 show_arrow = show_arrow != FALSE;
3104 if (priv->show_arrow != show_arrow)
3106 priv->show_arrow = show_arrow;
3108 if (!priv->show_arrow)
3109 gtk_widget_hide (priv->arrow_button);
3111 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3112 g_object_notify (G_OBJECT (toolbar), "show-arrow");
3117 * gtk_toolbar_get_show_arrow:
3118 * @toolbar: a #GtkToolbar
3120 * Returns whether the toolbar has an overflow menu.
3121 * See gtk_toolbar_set_show_arrow().
3123 * Return value: %TRUE if the toolbar has an overflow menu.
3128 gtk_toolbar_get_show_arrow (GtkToolbar *toolbar)
3130 GtkToolbarPrivate *priv;
3132 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
3134 if (!gtk_toolbar_check_new_api (toolbar))
3137 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3139 return priv->show_arrow;
3143 * gtk_toolbar_get_drop_index:
3144 * @toolbar: a #GtkToolbar
3145 * @x: x coordinate of a point on the toolbar
3146 * @y: y coordinate of a point on the toolbar
3148 * Returns the position corresponding to the indicated point on
3149 * @toolbar. This is useful when dragging items to the toolbar:
3150 * this function returns the position a new item should be
3153 * @x and @y are in @toolbar coordinates.
3155 * Return value: The position corresponding to the point (@x, @y) on the toolbar.
3160 gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
3164 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
3166 if (!gtk_toolbar_check_new_api (toolbar))
3169 return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
3173 gtk_toolbar_finalize (GObject *object)
3176 GtkToolbar *toolbar = GTK_TOOLBAR (object);
3177 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3179 if (toolbar->tooltips)
3180 g_object_unref (toolbar->tooltips);
3182 if (priv->arrow_button)
3183 gtk_widget_unparent (priv->arrow_button);
3185 for (list = priv->content; list != NULL; list = list->next)
3187 ToolbarContent *content = list->data;
3189 toolbar_content_free (content);
3192 g_list_free (priv->content);
3193 g_list_free (toolbar->children);
3195 g_timer_destroy (priv->timer);
3198 gtk_widget_destroy (GTK_WIDGET (priv->menu));
3201 g_source_remove (priv->idle_id);
3203 G_OBJECT_CLASS (parent_class)->finalize (object);
3207 * gtk_toolbar_set_icon_size:
3208 * @toolbar: A #GtkToolbar
3209 * @icon_size: The #GtkIconSize that stock icons in the toolbar shall have.
3211 * This function sets the size of stock icons in the toolbar. You
3212 * can call it both before you add the icons and after they've been
3213 * added. The size you set will override user preferences for the default
3216 * This should only be used for special-purpose toolbars, normal
3217 * application toolbars should respect the user preferences for the
3221 gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
3222 GtkIconSize icon_size)
3224 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3225 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
3227 if (!toolbar->icon_size_set)
3229 toolbar->icon_size_set = TRUE;
3230 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3233 if (toolbar->icon_size == icon_size)
3236 toolbar->icon_size = icon_size;
3237 g_object_notify (G_OBJECT (toolbar), "icon-size");
3239 gtk_toolbar_reconfigured (toolbar);
3241 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3245 * gtk_toolbar_unset_icon_size:
3246 * @toolbar: a #GtkToolbar
3248 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that
3249 * user preferences will be used to determine the icon size.
3252 gtk_toolbar_unset_icon_size (GtkToolbar *toolbar)
3256 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3258 if (toolbar->icon_size_set)
3260 GtkSettings *settings = toolbar_get_settings (toolbar);
3264 g_object_get (settings,
3265 "gtk-toolbar-icon-size", &size,
3269 size = DEFAULT_ICON_SIZE;
3271 if (size != toolbar->icon_size)
3273 gtk_toolbar_set_icon_size (toolbar, size);
3274 g_object_notify (G_OBJECT (toolbar), "icon-size");
3277 toolbar->icon_size_set = FALSE;
3278 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3287 * gtk_toolbar_append_item:
3288 * @toolbar: a #GtkToolbar.
3289 * @text: give your toolbar button a label.
3290 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3291 * @tooltip_private_text: use with #GtkTipsQuery.
3292 * @icon: a #GtkWidget that should be used as the button's icon.
3293 * @callback: the function to be executed when the button is pressed.
3294 * @user_data: a pointer to any data you wish to be passed to the callback.
3296 * Inserts a new item into the toolbar. You must specify the position
3297 * in the toolbar where it will be inserted.
3299 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3300 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3302 * Return value: the new toolbar item as a #GtkWidget.
3305 gtk_toolbar_append_item (GtkToolbar *toolbar,
3307 const char *tooltip_text,
3308 const char *tooltip_private_text,
3310 GtkSignalFunc callback,
3313 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3315 tooltip_text, tooltip_private_text,
3316 icon, callback, user_data,
3317 toolbar->num_children);
3321 * gtk_toolbar_prepend_item:
3322 * @toolbar: a #GtkToolbar.
3323 * @text: give your toolbar button a label.
3324 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3325 * @tooltip_private_text: use with #GtkTipsQuery.
3326 * @icon: a #GtkWidget that should be used as the button's icon.
3327 * @callback: the function to be executed when the button is pressed.
3328 * @user_data: a pointer to any data you wish to be passed to the callback.
3330 * Adds a new button to the beginning (top or left edges) of the given toolbar.
3332 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3333 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3335 * Return value: the new toolbar item as a #GtkWidget.
3338 gtk_toolbar_prepend_item (GtkToolbar *toolbar,
3340 const char *tooltip_text,
3341 const char *tooltip_private_text,
3343 GtkSignalFunc callback,
3346 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3348 tooltip_text, tooltip_private_text,
3349 icon, callback, user_data,
3354 * gtk_toolbar_insert_item:
3355 * @toolbar: a #GtkToolbar.
3356 * @text: give your toolbar button a label.
3357 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3358 * @tooltip_private_text: use with #GtkTipsQuery.
3359 * @icon: a #GtkWidget that should be used as the button's icon.
3360 * @callback: the function to be executed when the button is pressed.
3361 * @user_data: a pointer to any data you wish to be passed to the callback.
3362 * @position: the number of widgets to insert this item after.
3364 * Inserts a new item into the toolbar. You must specify the position in the
3365 * toolbar where it will be inserted.
3367 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3368 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3370 * Return value: the new toolbar item as a #GtkWidget.
3373 gtk_toolbar_insert_item (GtkToolbar *toolbar,
3375 const char *tooltip_text,
3376 const char *tooltip_private_text,
3378 GtkSignalFunc callback,
3382 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3384 tooltip_text, tooltip_private_text,
3385 icon, callback, user_data,
3390 * gtk_toolbar_insert_stock:
3391 * @toolbar: A #GtkToolbar
3392 * @stock_id: The id of the stock item you want to insert
3393 * @tooltip_text: The text in the tooltip of the toolbar button
3394 * @tooltip_private_text: The private text of the tooltip
3395 * @callback: The callback called when the toolbar button is clicked.
3396 * @user_data: user data passed to callback
3397 * @position: The position the button shall be inserted at.
3398 * -1 means at the end.
3400 * Inserts a stock item at the specified position of the toolbar. If
3401 * @stock_id is not a known stock item ID, it's inserted verbatim,
3402 * except that underscores used to mark mnemonics are removed.
3404 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3405 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3407 * Returns: the inserted widget
3410 gtk_toolbar_insert_stock (GtkToolbar *toolbar,
3411 const gchar *stock_id,
3412 const char *tooltip_text,
3413 const char *tooltip_private_text,
3414 GtkSignalFunc callback,
3418 return internal_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3420 tooltip_text, tooltip_private_text,
3421 NULL, callback, user_data,
3426 * gtk_toolbar_append_space:
3427 * @toolbar: a #GtkToolbar.
3429 * Adds a new space to the end of the toolbar.
3432 gtk_toolbar_append_space (GtkToolbar *toolbar)
3434 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3438 toolbar->num_children);
3442 * gtk_toolbar_prepend_space:
3443 * @toolbar: a #GtkToolbar.
3445 * Adds a new space to the beginning of the toolbar.
3448 gtk_toolbar_prepend_space (GtkToolbar *toolbar)
3450 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3458 * gtk_toolbar_insert_space:
3459 * @toolbar: a #GtkToolbar
3460 * @position: the number of widgets after which a space should be inserted.
3462 * Inserts a new space in the toolbar at the specified position.
3465 gtk_toolbar_insert_space (GtkToolbar *toolbar,
3468 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3476 * gtk_toolbar_remove_space:
3477 * @toolbar: a #GtkToolbar.
3478 * @position: the index of the space to remove.
3480 * Removes a space from the specified position.
3483 gtk_toolbar_remove_space (GtkToolbar *toolbar,
3486 GtkToolbarPrivate *priv;
3487 ToolbarContent *content;
3489 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3491 if (!gtk_toolbar_check_old_api (toolbar))
3494 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3496 content = g_list_nth_data (priv->content, position);
3500 g_warning ("Toolbar position %d doesn't exist", position);
3504 if (!toolbar_content_is_separator (content))
3506 g_warning ("Toolbar position %d is not a space", position);
3510 toolbar_content_remove (content, toolbar);
3511 toolbar_content_free (content);
3515 * gtk_toolbar_append_widget:
3516 * @toolbar: a #GtkToolbar.
3517 * @widget: a #GtkWidget to add to the toolbar.
3518 * @tooltip_text: the element's tooltip.
3519 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3521 * Adds a widget to the end of the given toolbar.
3524 gtk_toolbar_append_widget (GtkToolbar *toolbar,
3526 const gchar *tooltip_text,
3527 const gchar *tooltip_private_text)
3529 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3531 tooltip_text, tooltip_private_text,
3533 toolbar->num_children);
3537 * gtk_toolbar_prepend_widget:
3538 * @toolbar: a #GtkToolbar.
3539 * @widget: a #GtkWidget to add to the toolbar.
3540 * @tooltip_text: the element's tooltip.
3541 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3543 * Adds a widget to the beginning of the given toolbar.
3546 gtk_toolbar_prepend_widget (GtkToolbar *toolbar,
3548 const gchar *tooltip_text,
3549 const gchar *tooltip_private_text)
3551 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3553 tooltip_text, tooltip_private_text,
3559 * gtk_toolbar_insert_widget:
3560 * @toolbar: a #GtkToolbar.
3561 * @widget: a #GtkWidget to add to the toolbar.
3562 * @tooltip_text: the element's tooltip.
3563 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3564 * @position: the number of widgets to insert this widget after.
3566 * Inserts a widget in the toolbar at the given position.
3569 gtk_toolbar_insert_widget (GtkToolbar *toolbar,
3571 const char *tooltip_text,
3572 const char *tooltip_private_text,
3575 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3577 tooltip_text, tooltip_private_text,
3583 * gtk_toolbar_append_element:
3584 * @toolbar: a #GtkToolbar.
3585 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3586 * @widget: a #GtkWidget, or %NULL.
3587 * @text: the element's label.
3588 * @tooltip_text: the element's tooltip.
3589 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3590 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3591 * @callback: the function to be executed when the button is pressed.
3592 * @user_data: any data you wish to pass to the callback.
3594 * Adds a new element to the end of a toolbar.
3596 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3597 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3598 * the radio group for the new element. In all other cases, @widget must
3601 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3602 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3604 * Return value: the new toolbar element as a #GtkWidget.
3607 gtk_toolbar_append_element (GtkToolbar *toolbar,
3608 GtkToolbarChildType type,
3611 const char *tooltip_text,
3612 const char *tooltip_private_text,
3614 GtkSignalFunc callback,
3617 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3618 tooltip_text, tooltip_private_text,
3619 icon, callback, user_data,
3620 toolbar->num_children);
3624 * gtk_toolbar_prepend_element:
3625 * @toolbar: a #GtkToolbar.
3626 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3627 * @widget: a #GtkWidget, or %NULL
3628 * @text: the element's label.
3629 * @tooltip_text: the element's tooltip.
3630 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3631 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3632 * @callback: the function to be executed when the button is pressed.
3633 * @user_data: any data you wish to pass to the callback.
3635 * Adds a new element to the beginning of a toolbar.
3637 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3638 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3639 * the radio group for the new element. In all other cases, @widget must
3642 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3643 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3645 * Return value: the new toolbar element as a #GtkWidget.
3648 gtk_toolbar_prepend_element (GtkToolbar *toolbar,
3649 GtkToolbarChildType type,
3652 const char *tooltip_text,
3653 const char *tooltip_private_text,
3655 GtkSignalFunc callback,
3658 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3659 tooltip_text, tooltip_private_text,
3660 icon, callback, user_data, 0);
3664 * gtk_toolbar_insert_element:
3665 * @toolbar: a #GtkToolbar.
3666 * @type: a value of type #GtkToolbarChildType that determines what @widget
3668 * @widget: a #GtkWidget, or %NULL.
3669 * @text: the element's label.
3670 * @tooltip_text: the element's tooltip.
3671 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3672 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3673 * @callback: the function to be executed when the button is pressed.
3674 * @user_data: any data you wish to pass to the callback.
3675 * @position: the number of widgets to insert this element after.
3677 * Inserts a new element in the toolbar at the given position.
3679 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3680 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3681 * the radio group for the new element. In all other cases, @widget must
3684 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3685 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3687 * Return value: the new toolbar element as a #GtkWidget.
3690 gtk_toolbar_insert_element (GtkToolbar *toolbar,
3691 GtkToolbarChildType type,
3694 const char *tooltip_text,
3695 const char *tooltip_private_text,
3697 GtkSignalFunc callback,
3701 return internal_insert_element (toolbar, type, widget, text,
3702 tooltip_text, tooltip_private_text,
3703 icon, callback, user_data, position, FALSE);
3707 set_child_packing_and_visibility(GtkToolbar *toolbar,
3708 GtkToolbarChild *child)
3713 box = gtk_bin_get_child (GTK_BIN (child->widget));
3715 g_return_if_fail (GTK_IS_BOX (box));
3719 expand = (toolbar->style != GTK_TOOLBAR_BOTH);
3721 gtk_box_set_child_packing (GTK_BOX (box), child->label,
3722 expand, expand, 0, GTK_PACK_END);
3724 if (toolbar->style != GTK_TOOLBAR_ICONS)
3725 gtk_widget_show (child->label);
3727 gtk_widget_hide (child->label);
3732 expand = (toolbar->style != GTK_TOOLBAR_BOTH_HORIZ);
3734 gtk_box_set_child_packing (GTK_BOX (box), child->icon,
3735 expand, expand, 0, GTK_PACK_END);
3737 if (toolbar->style != GTK_TOOLBAR_TEXT)
3738 gtk_widget_show (child->icon);
3740 gtk_widget_hide (child->icon);
3745 internal_insert_element (GtkToolbar *toolbar,
3746 GtkToolbarChildType type,
3749 const char *tooltip_text,
3750 const char *tooltip_private_text,
3752 GtkSignalFunc callback,
3758 ToolbarContent *content;
3759 char *free_me = NULL;
3761 GtkWidget *child_widget;
3762 GtkWidget *child_label;
3763 GtkWidget *child_icon;
3765 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
3766 if (type == GTK_TOOLBAR_CHILD_WIDGET)
3767 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3768 else if (type != GTK_TOOLBAR_CHILD_RADIOBUTTON)
3769 g_return_val_if_fail (widget == NULL, NULL);
3770 if (GTK_IS_TOOL_ITEM (widget))
3771 g_warning (MIXED_API_WARNING);
3773 if (!gtk_toolbar_check_old_api (toolbar))
3776 child_widget = NULL;
3782 case GTK_TOOLBAR_CHILD_SPACE:
3785 case GTK_TOOLBAR_CHILD_WIDGET:
3786 child_widget = widget;
3789 case GTK_TOOLBAR_CHILD_BUTTON:
3790 case GTK_TOOLBAR_CHILD_TOGGLEBUTTON:
3791 case GTK_TOOLBAR_CHILD_RADIOBUTTON:
3792 if (type == GTK_TOOLBAR_CHILD_BUTTON)
3794 child_widget = gtk_button_new ();
3796 else if (type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
3798 child_widget = gtk_toggle_button_new ();
3799 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3801 else /* type == GTK_TOOLBAR_CHILD_RADIOBUTTON */
3803 GSList *group = NULL;
3806 group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
3808 child_widget = gtk_radio_button_new (group);
3809 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3812 gtk_button_set_relief (GTK_BUTTON (child_widget), get_button_relief (toolbar));
3813 gtk_button_set_focus_on_click (GTK_BUTTON (child_widget), FALSE);
3817 g_signal_connect (child_widget, "clicked",
3818 callback, user_data);
3821 if (toolbar->style == GTK_TOOLBAR_BOTH_HORIZ)
3822 box = gtk_hbox_new (FALSE, 0);
3824 box = gtk_vbox_new (FALSE, 0);
3826 gtk_container_add (GTK_CONTAINER (child_widget), box);
3827 gtk_widget_show (box);
3829 if (text && use_stock)
3831 GtkStockItem stock_item;
3832 if (gtk_stock_lookup (text, &stock_item))
3835 icon = gtk_image_new_from_stock (text, toolbar->icon_size);
3837 text = free_me = _gtk_toolbar_elide_underscores (stock_item.label);
3843 child_label = gtk_label_new (text);
3845 gtk_container_add (GTK_CONTAINER (box), child_label);
3850 child_icon = GTK_WIDGET (icon);
3851 gtk_container_add (GTK_CONTAINER (box), child_icon);
3854 gtk_widget_show (child_widget);
3858 g_assert_not_reached ();
3862 if ((type != GTK_TOOLBAR_CHILD_SPACE) && tooltip_text)
3864 gtk_tooltips_set_tip (toolbar->tooltips, child_widget,
3865 tooltip_text, tooltip_private_text);
3868 content = toolbar_content_new_compatibility (toolbar, type, child_widget,
3869 child_icon, child_label, position);
3874 return child_widget;
3878 * ToolbarContent methods
3886 struct _ToolbarContent
3896 GtkAllocation start_allocation;
3897 GtkAllocation goal_allocation;
3898 guint is_placeholder : 1;
3899 guint disappearing : 1;
3900 TriState has_menu : 2;
3905 GtkToolbarChild child;
3906 GtkAllocation space_allocation;
3907 guint space_visible : 1;
3912 static ToolbarContent *
3913 toolbar_content_new_tool_item (GtkToolbar *toolbar,
3915 gboolean is_placeholder,
3918 ToolbarContent *content;
3919 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3921 content = g_new0 (ToolbarContent, 1);
3923 content->type = TOOL_ITEM;
3924 content->state = NOT_ALLOCATED;
3925 content->u.tool_item.item = item;
3926 content->u.tool_item.is_placeholder = is_placeholder;
3928 gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
3930 priv->content = g_list_insert (priv->content, content, pos);
3932 if (!is_placeholder)
3934 toolbar->num_children++;
3936 gtk_toolbar_stop_sliding (toolbar);
3939 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3940 priv->need_rebuild = TRUE;
3945 static ToolbarContent *
3946 toolbar_content_new_compatibility (GtkToolbar *toolbar,
3947 GtkToolbarChildType type,
3953 ToolbarContent *content;
3954 GtkToolbarChild *child;
3955 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3957 content = g_new0 (ToolbarContent, 1);
3959 child = &(content->u.compatibility.child);
3961 content->type = COMPATIBILITY;
3963 child->widget = widget;
3965 child->label = label;
3967 if (type != GTK_TOOLBAR_CHILD_SPACE)
3969 gtk_widget_set_parent (child->widget, GTK_WIDGET (toolbar));
3973 content->u.compatibility.space_visible = TRUE;
3974 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3977 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
3978 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
3979 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
3981 set_child_packing_and_visibility (toolbar, child);
3984 priv->content = g_list_insert (priv->content, content, pos);
3985 toolbar->children = g_list_insert (toolbar->children, child, pos);
3986 priv->need_rebuild = TRUE;
3988 toolbar->num_children++;
3994 toolbar_content_remove (ToolbarContent *content,
3995 GtkToolbar *toolbar)
3997 GtkToolbarChild *child;
3998 GtkToolbarPrivate *priv;
4000 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4002 switch (content->type)
4005 gtk_widget_unparent (GTK_WIDGET (content->u.tool_item.item));
4009 child = &(content->u.compatibility.child);
4011 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4013 g_object_ref (child->widget);
4014 gtk_widget_unparent (child->widget);
4015 gtk_widget_destroy (child->widget);
4016 g_object_unref (child->widget);
4019 toolbar->children = g_list_remove (toolbar->children, child);
4023 priv->content = g_list_remove (priv->content, content);
4025 if (!toolbar_content_is_placeholder (content))
4026 toolbar->num_children--;
4028 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
4029 priv->need_rebuild = TRUE;
4033 toolbar_content_free (ToolbarContent *content)
4039 calculate_max_homogeneous_pixels (GtkWidget *widget)
4041 PangoContext *context;
4042 PangoFontMetrics *metrics;
4045 context = gtk_widget_get_pango_context (widget);
4046 metrics = pango_context_get_metrics (context,
4047 widget->style->font_desc,
4048 pango_context_get_language (context));
4049 char_width = pango_font_metrics_get_approximate_char_width (metrics);
4050 pango_font_metrics_unref (metrics);
4052 return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
4056 toolbar_content_expose (ToolbarContent *content,
4057 GtkContainer *container,
4058 GdkEventExpose *expose)
4060 GtkToolbar *toolbar = GTK_TOOLBAR (container);
4061 GtkToolbarChild *child;
4062 GtkWidget *widget = NULL; /* quiet gcc */
4064 switch (content->type)
4067 if (!content->u.tool_item.is_placeholder)
4068 widget = GTK_WIDGET (content->u.tool_item.item);
4072 child = &(content->u.compatibility.child);
4074 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
4076 if (get_space_style (toolbar) == GTK_TOOLBAR_SPACE_LINE &&
4077 content->u.compatibility.space_visible)
4079 _gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), toolbar,
4081 &content->u.compatibility.space_allocation);
4086 widget = child->widget;
4091 gtk_container_propagate_expose (container, widget, expose);
4095 toolbar_content_visible (ToolbarContent *content,
4096 GtkToolbar *toolbar)
4100 switch (content->type)
4103 item = content->u.tool_item.item;
4105 if (!GTK_WIDGET_VISIBLE (item))
4108 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL &&
4109 gtk_tool_item_get_visible_horizontal (item))
4114 if ((toolbar->orientation == GTK_ORIENTATION_VERTICAL &&
4115 gtk_tool_item_get_visible_vertical (item)))
4124 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4125 return GTK_WIDGET_VISIBLE (content->u.compatibility.child.widget);
4131 g_assert_not_reached ();
4136 toolbar_content_size_request (ToolbarContent *content,
4137 GtkToolbar *toolbar,
4138 GtkRequisition *requisition)
4142 switch (content->type)
4145 gtk_widget_size_request (GTK_WIDGET (content->u.tool_item.item),
4147 if (content->u.tool_item.is_placeholder &&
4148 content->u.tool_item.disappearing)
4150 requisition->width = 0;
4151 requisition->height = 0;
4156 space_size = get_space_size (toolbar);
4158 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4160 gtk_widget_size_request (content->u.compatibility.child.widget,
4165 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
4167 requisition->width = space_size;
4168 requisition->height = 0;
4172 requisition->height = space_size;
4173 requisition->width = 0;
4182 toolbar_content_is_homogeneous (ToolbarContent *content,
4183 GtkToolbar *toolbar)
4185 gboolean result = FALSE; /* quiet gcc */
4186 GtkRequisition requisition;
4187 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4189 if (priv->max_homogeneous_pixels < 0)
4191 priv->max_homogeneous_pixels =
4192 calculate_max_homogeneous_pixels (GTK_WIDGET (toolbar));
4195 toolbar_content_size_request (content, toolbar, &requisition);
4197 if (requisition.width > priv->max_homogeneous_pixels)
4200 switch (content->type)
4203 result = gtk_tool_item_get_homogeneous (content->u.tool_item.item) &&
4204 !GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4206 if (gtk_tool_item_get_is_important (content->u.tool_item.item) &&
4207 toolbar->style == GTK_TOOLBAR_BOTH_HORIZ &&
4208 toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
4215 if (content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_BUTTON ||
4216 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4217 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4232 toolbar_content_is_placeholder (ToolbarContent *content)
4234 if (content->type == TOOL_ITEM && content->u.tool_item.is_placeholder)
4241 toolbar_content_disappearing (ToolbarContent *content)
4243 if (content->type == TOOL_ITEM && content->u.tool_item.disappearing)
4250 toolbar_content_get_state (ToolbarContent *content)
4252 return content->state;
4256 toolbar_content_child_visible (ToolbarContent *content)
4258 switch (content->type)
4261 return GTK_WIDGET_CHILD_VISIBLE (content->u.tool_item.item);
4265 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4267 return GTK_WIDGET_CHILD_VISIBLE (content->u.compatibility.child.widget);
4271 return content->u.compatibility.space_visible;
4276 return FALSE; /* quiet gcc */
4280 toolbar_content_get_goal_allocation (ToolbarContent *content,
4281 GtkAllocation *allocation)
4283 switch (content->type)
4286 *allocation = content->u.tool_item.goal_allocation;
4290 /* Goal allocations are only relevant when we are
4291 * using the new API, so we should never get here
4293 g_assert_not_reached ();
4299 toolbar_content_get_allocation (ToolbarContent *content,
4300 GtkAllocation *allocation)
4302 GtkToolbarChild *child;
4304 switch (content->type)
4307 *allocation = GTK_WIDGET (content->u.tool_item.item)->allocation;
4311 child = &(content->u.compatibility.child);
4313 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
4314 *allocation = content->u.compatibility.space_allocation;
4316 *allocation = child->widget->allocation;
4322 toolbar_content_set_start_allocation (ToolbarContent *content,
4323 GtkAllocation *allocation)
4325 switch (content->type)
4328 content->u.tool_item.start_allocation = *allocation;
4332 /* start_allocation is only relevant when using the new API */
4333 g_assert_not_reached ();
4339 toolbar_content_get_expand (ToolbarContent *content)
4341 if (content->type == TOOL_ITEM &&
4342 gtk_tool_item_get_expand (content->u.tool_item.item) &&
4343 !content->u.tool_item.disappearing)
4352 toolbar_content_set_goal_allocation (ToolbarContent *content,
4353 GtkAllocation *allocation)
4355 switch (content->type)
4358 content->u.tool_item.goal_allocation = *allocation;
4362 /* Only relevant when using new API */
4363 g_assert_not_reached ();
4369 toolbar_content_set_child_visible (ToolbarContent *content,
4370 GtkToolbar *toolbar,
4373 GtkToolbarChild *child;
4375 switch (content->type)
4378 gtk_widget_set_child_visible (GTK_WIDGET (content->u.tool_item.item),
4383 child = &(content->u.compatibility.child);
4385 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4387 gtk_widget_set_child_visible (child->widget, visible);
4391 if (content->u.compatibility.space_visible != visible)
4393 content->u.compatibility.space_visible = visible;
4394 gtk_widget_queue_draw (GTK_WIDGET (toolbar));
4402 toolbar_content_get_start_allocation (ToolbarContent *content,
4403 GtkAllocation *start_allocation)
4405 switch (content->type)
4408 *start_allocation = content->u.tool_item.start_allocation;
4412 /* Only relevant for new API */
4413 g_assert_not_reached ();
4419 toolbar_content_size_allocate (ToolbarContent *content,
4420 GtkAllocation *allocation)
4422 switch (content->type)
4425 gtk_widget_size_allocate (GTK_WIDGET (content->u.tool_item.item),
4430 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4432 gtk_widget_size_allocate (content->u.compatibility.child.widget,
4437 content->u.compatibility.space_allocation = *allocation;
4444 toolbar_content_set_state (ToolbarContent *content,
4447 content->state = state;
4451 toolbar_content_get_widget (ToolbarContent *content)
4453 GtkToolbarChild *child;
4455 switch (content->type)
4458 return GTK_WIDGET (content->u.tool_item.item);
4462 child = &(content->u.compatibility.child);
4463 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4464 return child->widget;
4474 toolbar_content_set_disappearing (ToolbarContent *content,
4475 gboolean disappearing)
4477 switch (content->type)
4480 content->u.tool_item.disappearing = disappearing;
4484 /* Only relevant for new API */
4485 g_assert_not_reached ();
4491 toolbar_content_set_size_request (ToolbarContent *content,
4495 switch (content->type)
4498 gtk_widget_set_size_request (GTK_WIDGET (content->u.tool_item.item),
4503 /* Setting size requests only happens with sliding,
4504 * so not relevant here
4506 g_assert_not_reached ();
4512 toolbar_child_reconfigure (GtkToolbar *toolbar,
4513 GtkToolbarChild *child)
4517 GtkToolbarStyle style;
4518 GtkIconSize icon_size;
4519 GtkReliefStyle relief;
4522 style = gtk_toolbar_get_style (toolbar);
4523 icon_size = gtk_toolbar_get_icon_size (toolbar);
4524 relief = gtk_toolbar_get_relief_style (toolbar);
4527 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4528 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4529 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4531 box = gtk_bin_get_child (GTK_BIN (child->widget));
4533 if (style == GTK_TOOLBAR_BOTH && GTK_IS_HBOX (box))
4537 vbox = gtk_vbox_new (FALSE, 0);
4540 gtk_widget_reparent (child->label, vbox);
4542 gtk_widget_reparent (child->icon, vbox);
4544 gtk_widget_destroy (box);
4545 gtk_container_add (GTK_CONTAINER (child->widget), vbox);
4547 gtk_widget_show (vbox);
4549 else if (style == GTK_TOOLBAR_BOTH_HORIZ && GTK_IS_VBOX (box))
4553 hbox = gtk_hbox_new (FALSE, 0);
4556 gtk_widget_reparent (child->label, hbox);
4558 gtk_widget_reparent (child->icon, hbox);
4560 gtk_widget_destroy (box);
4561 gtk_container_add (GTK_CONTAINER (child->widget), hbox);
4563 gtk_widget_show (hbox);
4566 set_child_packing_and_visibility (toolbar, child);
4571 if ((child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4572 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4573 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON) &&
4574 GTK_IS_IMAGE (child->icon))
4576 image = GTK_IMAGE (child->icon);
4577 if (gtk_image_get_storage_type (image) == GTK_IMAGE_STOCK)
4579 gtk_image_get_stock (image, &stock_id, NULL);
4580 stock_id = g_strdup (stock_id);
4581 gtk_image_set_from_stock (image,
4589 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4590 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4591 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4593 gtk_button_set_relief (GTK_BUTTON (child->widget), relief);
4598 toolbar_content_toolbar_reconfigured (ToolbarContent *content,
4599 GtkToolbar *toolbar)
4601 switch (content->type)
4604 _gtk_tool_item_toolbar_reconfigured (content->u.tool_item.item);
4608 toolbar_child_reconfigure (toolbar, &(content->u.compatibility.child));
4614 toolbar_content_retrieve_menu_item (ToolbarContent *content)
4616 if (content->type == TOOL_ITEM)
4617 return gtk_tool_item_retrieve_proxy_menu_item (content->u.tool_item.item);
4619 /* FIXME - we might actually be able to do something meaningful here */
4624 toolbar_content_has_proxy_menu_item (ToolbarContent *content)
4626 if (content->type == TOOL_ITEM)
4628 GtkWidget *menu_item;
4630 if (content->u.tool_item.has_menu == YES)
4632 else if (content->u.tool_item.has_menu == NO)
4635 menu_item = toolbar_content_retrieve_menu_item (content);
4637 content->u.tool_item.has_menu = menu_item? YES : NO;
4639 return menu_item != NULL;
4648 toolbar_content_set_unknown_menu_status (ToolbarContent *content)
4650 if (content->type == TOOL_ITEM)
4651 content->u.tool_item.has_menu = UNKNOWN;
4655 toolbar_content_is_separator (ToolbarContent *content)
4657 GtkToolbarChild *child;
4659 switch (content->type)
4662 return GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4666 child = &(content->u.compatibility.child);
4667 return (child->type == GTK_TOOLBAR_CHILD_SPACE);
4675 toolbar_content_set_expand (ToolbarContent *content,
4678 if (content->type == TOOL_ITEM)
4679 gtk_tool_item_set_expand (content->u.tool_item.item, expand);
4683 ignore_show_and_hide_all (ToolbarContent *content)
4685 if (content->type == COMPATIBILITY)
4687 GtkToolbarChildType type = content->u.compatibility.child.type;
4689 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
4690 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4691 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
4701 toolbar_content_show_all (ToolbarContent *content)
4705 if (ignore_show_and_hide_all (content))
4708 widget = toolbar_content_get_widget (content);
4710 gtk_widget_show_all (widget);
4714 toolbar_content_hide_all (ToolbarContent *content)
4718 if (ignore_show_and_hide_all (content))
4721 widget = toolbar_content_get_widget (content);
4723 gtk_widget_hide_all (widget);
4730 get_space_size (GtkToolbar *toolbar)
4732 gint space_size = DEFAULT_SPACE_SIZE;
4736 gtk_widget_style_get (GTK_WIDGET (toolbar),
4737 "space-size", &space_size,
4744 static GtkToolbarSpaceStyle
4745 get_space_style (GtkToolbar *toolbar)
4747 GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
4751 gtk_widget_style_get (GTK_WIDGET (toolbar),
4752 "space-style", &space_style,
4759 static GtkReliefStyle
4760 get_button_relief (GtkToolbar *toolbar)
4762 GtkReliefStyle button_relief = GTK_RELIEF_NORMAL;
4764 gtk_widget_ensure_style (GTK_WIDGET (toolbar));
4766 gtk_widget_style_get (GTK_WIDGET (toolbar),
4767 "button-relief", &button_relief,
4770 return button_relief;
4774 get_internal_padding (GtkToolbar *toolbar)
4778 gtk_widget_style_get (GTK_WIDGET (toolbar),
4779 "internal-padding", &ipadding,
4785 static GtkShadowType
4786 get_shadow_type (GtkToolbar *toolbar)
4788 GtkShadowType shadow_type;
4790 gtk_widget_style_get (GTK_WIDGET (toolbar),
4791 "shadow-type", &shadow_type,
4801 gtk_toolbar_check_old_api (GtkToolbar *toolbar)
4803 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4805 if (priv->api_mode == NEW_API)
4807 g_warning (MIXED_API_WARNING);
4811 priv->api_mode = OLD_API;
4816 gtk_toolbar_check_new_api (GtkToolbar *toolbar)
4818 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4820 if (priv->api_mode == OLD_API)
4822 g_warning (MIXED_API_WARNING);
4826 priv->api_mode = NEW_API;
4830 /* GTK+ internal methods */
4833 _gtk_toolbar_get_default_space_size (void)
4835 return DEFAULT_SPACE_SIZE;
4839 _gtk_toolbar_paint_space_line (GtkWidget *widget,
4840 GtkToolbar *toolbar,
4842 GtkAllocation *allocation)
4844 const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
4845 const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
4847 GtkOrientation orientation;
4849 g_return_if_fail (GTK_IS_WIDGET (widget));
4851 orientation = toolbar? toolbar->orientation : GTK_ORIENTATION_HORIZONTAL;
4853 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4855 gtk_paint_vline (widget->style, widget->window,
4856 GTK_WIDGET_STATE (widget), area, widget,
4858 allocation->y + allocation->height * start_fraction,
4859 allocation->y + allocation->height * end_fraction,
4860 allocation->x + (allocation->width - widget->style->xthickness) / 2);
4864 gtk_paint_hline (widget->style, widget->window,
4865 GTK_WIDGET_STATE (widget), area, widget,
4867 allocation->x + allocation->width * start_fraction,
4868 allocation->x + allocation->width * end_fraction,
4869 allocation->y + (allocation->height - widget->style->ythickness) / 2);
4874 _gtk_toolbar_elide_underscores (const gchar *original)
4878 gboolean last_underscore;
4883 q = result = g_malloc (strlen (original) + 1);
4884 last_underscore = FALSE;
4886 for (p = original; *p; p++)
4888 if (!last_underscore && *p == '_')
4889 last_underscore = TRUE;
4892 last_underscore = FALSE;
4903 _gtk_toolbar_rebuild_menu (GtkToolbar *toolbar)
4905 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4908 priv->need_rebuild = TRUE;
4910 for (list = priv->content; list != NULL; list = list->next)
4912 ToolbarContent *content = list->data;
4914 toolbar_content_set_unknown_menu_status (content);
4917 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
4920 #define __GTK_TOOLBAR_C__
4921 #include "gtkaliasdef.c"