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_set_property (GObject *object,
160 static void gtk_toolbar_get_property (GObject *object,
164 static gint gtk_toolbar_expose (GtkWidget *widget,
165 GdkEventExpose *event);
166 static void gtk_toolbar_realize (GtkWidget *widget);
167 static void gtk_toolbar_unrealize (GtkWidget *widget);
168 static void gtk_toolbar_size_request (GtkWidget *widget,
169 GtkRequisition *requisition);
170 static void gtk_toolbar_size_allocate (GtkWidget *widget,
171 GtkAllocation *allocation);
172 static void gtk_toolbar_style_set (GtkWidget *widget,
173 GtkStyle *prev_style);
174 static gboolean gtk_toolbar_focus (GtkWidget *widget,
175 GtkDirectionType dir);
176 static void gtk_toolbar_screen_changed (GtkWidget *widget,
177 GdkScreen *previous_screen);
178 static void gtk_toolbar_map (GtkWidget *widget);
179 static void gtk_toolbar_unmap (GtkWidget *widget);
180 static void gtk_toolbar_set_child_property (GtkContainer *container,
185 static void gtk_toolbar_get_child_property (GtkContainer *container,
190 static void gtk_toolbar_finalize (GObject *object);
191 static void gtk_toolbar_show_all (GtkWidget *widget);
192 static void gtk_toolbar_hide_all (GtkWidget *widget);
193 static void gtk_toolbar_add (GtkContainer *container,
195 static void gtk_toolbar_remove (GtkContainer *container,
197 static void gtk_toolbar_forall (GtkContainer *container,
198 gboolean include_internals,
199 GtkCallback callback,
200 gpointer callback_data);
201 static GType gtk_toolbar_child_type (GtkContainer *container);
202 static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
203 GtkOrientation orientation);
204 static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
205 GtkToolbarStyle style);
206 static gboolean gtk_toolbar_move_focus (GtkToolbar *toolbar,
207 GtkDirectionType dir);
208 static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
209 gboolean focus_home);
210 static gboolean gtk_toolbar_button_press (GtkWidget *toolbar,
211 GdkEventButton *event);
212 static gboolean gtk_toolbar_arrow_button_press (GtkWidget *button,
213 GdkEventButton *event,
214 GtkToolbar *toolbar);
215 static void gtk_toolbar_arrow_button_clicked (GtkWidget *button,
216 GtkToolbar *toolbar);
217 static void gtk_toolbar_update_button_relief (GtkToolbar *toolbar);
218 static gboolean gtk_toolbar_popup_menu (GtkWidget *toolbar);
219 static GtkWidget *internal_insert_element (GtkToolbar *toolbar,
220 GtkToolbarChildType type,
223 const char *tooltip_text,
224 const char *tooltip_private_text,
226 GtkSignalFunc callback,
230 static void gtk_toolbar_reconfigured (GtkToolbar *toolbar);
231 static gboolean gtk_toolbar_check_new_api (GtkToolbar *toolbar);
232 static gboolean gtk_toolbar_check_old_api (GtkToolbar *toolbar);
234 static GtkReliefStyle get_button_relief (GtkToolbar *toolbar);
235 static gint get_internal_padding (GtkToolbar *toolbar);
236 static gint get_max_child_expand (GtkToolbar *toolbar);
237 static GtkShadowType get_shadow_type (GtkToolbar *toolbar);
238 static gint get_space_size (GtkToolbar *toolbar);
239 static GtkToolbarSpaceStyle get_space_style (GtkToolbar *toolbar);
241 /* methods on ToolbarContent 'class' */
242 static ToolbarContent *toolbar_content_new_tool_item (GtkToolbar *toolbar,
244 gboolean is_placeholder,
246 static ToolbarContent *toolbar_content_new_compatibility (GtkToolbar *toolbar,
247 GtkToolbarChildType type,
252 static void toolbar_content_remove (ToolbarContent *content,
253 GtkToolbar *toolbar);
254 static void toolbar_content_free (ToolbarContent *content);
255 static void toolbar_content_expose (ToolbarContent *content,
256 GtkContainer *container,
257 GdkEventExpose *expose);
258 static gboolean toolbar_content_visible (ToolbarContent *content,
259 GtkToolbar *toolbar);
260 static void toolbar_content_size_request (ToolbarContent *content,
262 GtkRequisition *requisition);
263 static gboolean toolbar_content_is_homogeneous (ToolbarContent *content,
264 GtkToolbar *toolbar);
265 static gboolean toolbar_content_is_placeholder (ToolbarContent *content);
266 static gboolean toolbar_content_disappearing (ToolbarContent *content);
267 static ItemState toolbar_content_get_state (ToolbarContent *content);
268 static gboolean toolbar_content_child_visible (ToolbarContent *content);
269 static void toolbar_content_get_goal_allocation (ToolbarContent *content,
270 GtkAllocation *allocation);
271 static void toolbar_content_get_allocation (ToolbarContent *content,
272 GtkAllocation *allocation);
273 static void toolbar_content_set_start_allocation (ToolbarContent *content,
274 GtkAllocation *new_start_allocation);
275 static void toolbar_content_get_start_allocation (ToolbarContent *content,
276 GtkAllocation *start_allocation);
277 static gboolean toolbar_content_get_expand (ToolbarContent *content);
278 static void toolbar_content_set_goal_allocation (ToolbarContent *content,
279 GtkAllocation *allocation);
280 static void toolbar_content_set_child_visible (ToolbarContent *content,
283 static void toolbar_content_size_allocate (ToolbarContent *content,
284 GtkAllocation *allocation);
285 static void toolbar_content_set_state (ToolbarContent *content,
286 ItemState new_state);
287 static GtkWidget * toolbar_content_get_widget (ToolbarContent *content);
288 static void toolbar_content_set_disappearing (ToolbarContent *content,
289 gboolean disappearing);
290 static void toolbar_content_set_size_request (ToolbarContent *content,
293 static void toolbar_content_toolbar_reconfigured (ToolbarContent *content,
294 GtkToolbar *toolbar);
295 static GtkWidget * toolbar_content_retrieve_menu_item (ToolbarContent *content);
296 static gboolean toolbar_content_has_proxy_menu_item (ToolbarContent *content);
297 static gboolean toolbar_content_is_separator (ToolbarContent *content);
298 static void toolbar_content_show_all (ToolbarContent *content);
299 static void toolbar_content_hide_all (ToolbarContent *content);
300 static void toolbar_content_set_expand (ToolbarContent *content,
303 #define GTK_TOOLBAR_GET_PRIVATE(o) \
304 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOLBAR, GtkToolbarPrivate))
306 static guint toolbar_signals [LAST_SIGNAL] = { 0 };
308 G_DEFINE_TYPE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER)
311 add_arrow_bindings (GtkBindingSet *binding_set,
313 GtkDirectionType dir)
315 guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
317 gtk_binding_entry_add_signal (binding_set, keysym, 0,
319 GTK_TYPE_DIRECTION_TYPE, dir);
320 gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
322 GTK_TYPE_DIRECTION_TYPE, dir);
326 add_ctrl_tab_bindings (GtkBindingSet *binding_set,
327 GdkModifierType modifiers,
328 GtkDirectionType direction)
330 gtk_binding_entry_add_signal (binding_set,
331 GDK_Tab, GDK_CONTROL_MASK | modifiers,
333 GTK_TYPE_DIRECTION_TYPE, direction);
334 gtk_binding_entry_add_signal (binding_set,
335 GDK_KP_Tab, GDK_CONTROL_MASK | modifiers,
337 GTK_TYPE_DIRECTION_TYPE, direction);
341 gtk_toolbar_class_init (GtkToolbarClass *klass)
343 GObjectClass *gobject_class;
344 GtkWidgetClass *widget_class;
345 GtkContainerClass *container_class;
346 GtkBindingSet *binding_set;
348 gobject_class = (GObjectClass *)klass;
349 widget_class = (GtkWidgetClass *)klass;
350 container_class = (GtkContainerClass *)klass;
352 gobject_class->set_property = gtk_toolbar_set_property;
353 gobject_class->get_property = gtk_toolbar_get_property;
354 gobject_class->finalize = gtk_toolbar_finalize;
356 widget_class->button_press_event = gtk_toolbar_button_press;
357 widget_class->expose_event = gtk_toolbar_expose;
358 widget_class->size_request = gtk_toolbar_size_request;
359 widget_class->size_allocate = gtk_toolbar_size_allocate;
360 widget_class->style_set = gtk_toolbar_style_set;
361 widget_class->focus = gtk_toolbar_focus;
362 widget_class->screen_changed = gtk_toolbar_screen_changed;
363 widget_class->realize = gtk_toolbar_realize;
364 widget_class->unrealize = gtk_toolbar_unrealize;
365 widget_class->map = gtk_toolbar_map;
366 widget_class->unmap = gtk_toolbar_unmap;
367 widget_class->popup_menu = gtk_toolbar_popup_menu;
368 widget_class->show_all = gtk_toolbar_show_all;
369 widget_class->hide_all = gtk_toolbar_hide_all;
371 container_class->add = gtk_toolbar_add;
372 container_class->remove = gtk_toolbar_remove;
373 container_class->forall = gtk_toolbar_forall;
374 container_class->child_type = gtk_toolbar_child_type;
375 container_class->get_child_property = gtk_toolbar_get_child_property;
376 container_class->set_child_property = gtk_toolbar_set_child_property;
378 klass->orientation_changed = gtk_toolbar_orientation_changed;
379 klass->style_changed = gtk_toolbar_real_style_changed;
382 * GtkToolbar::orientation-changed:
383 * @toolbar: the object which emitted the signal
384 * @orientation: the new #GtkOrientation of the toolbar
386 * Emitted when the orientation of the toolbar changes.
388 toolbar_signals[ORIENTATION_CHANGED] =
389 g_signal_new (I_("orientation-changed"),
390 G_OBJECT_CLASS_TYPE (klass),
392 G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
394 g_cclosure_marshal_VOID__ENUM,
396 GTK_TYPE_ORIENTATION);
398 * GtkToolbar::style-changed:
399 * @toolbar: The #GtkToolbar which emitted the signal
400 * @style: the new #GtkToolbarStyle of the toolbar
402 * Emitted when the style of the toolbar changes.
404 toolbar_signals[STYLE_CHANGED] =
405 g_signal_new (I_("style-changed"),
406 G_OBJECT_CLASS_TYPE (klass),
408 G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
410 g_cclosure_marshal_VOID__ENUM,
412 GTK_TYPE_TOOLBAR_STYLE);
414 * GtkToolbar::popup-context-menu:
415 * @toolbar: the #GtkToolbar which emitted the signal
416 * @x: the x coordinate of the point where the menu should appear
417 * @y: the y coordinate of the point where the menu should appear
418 * @button: the mouse button the user pressed, or -1
420 * Emitted when the user right-clicks the toolbar or uses the
421 * keybinding to display a popup menu.
423 * Application developers should handle this signal if they want
424 * to display a context menu on the toolbar. The context-menu should
425 * appear at the coordinates given by @x and @y. The mouse button
426 * number is given by the @button parameter. If the menu was popped
427 * up using the keybaord, @button is -1.
429 * Return value: return %TRUE if the signal was handled, %FALSE if not
431 toolbar_signals[POPUP_CONTEXT_MENU] =
432 g_signal_new (I_("popup_context_menu"),
433 G_OBJECT_CLASS_TYPE (klass),
435 G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
436 _gtk_boolean_handled_accumulator, NULL,
437 _gtk_marshal_BOOLEAN__INT_INT_INT,
439 G_TYPE_INT, G_TYPE_INT,
442 * GtkToolbar::move-focus:
443 * @toolbar: the #GtkToolbar which emitted the signal
444 * @dir: a #GtkDirection
446 * A keybinding signal used internally by GTK+. This signal can't
447 * be used in application code.
449 * Return value: %TRUE if the signal was handled, %FALSE if not
451 toolbar_signals[MOVE_FOCUS] =
452 _gtk_binding_signal_new (I_("move_focus"),
453 G_TYPE_FROM_CLASS (klass),
454 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
455 G_CALLBACK (gtk_toolbar_move_focus),
457 _gtk_marshal_BOOLEAN__ENUM,
459 GTK_TYPE_DIRECTION_TYPE);
461 * GtkToolbar::focus-home-or-end:
462 * @toolbar: the #GtkToolbar which emitted the signal
463 * @focus_home: %TRUE if the first item should be focused
465 * A keybinding signal used internally by GTK+. This signal can't
466 * be used in application code
468 * Return value: %TRUE if the signal was handled, %FALSE if not
470 toolbar_signals[FOCUS_HOME_OR_END] =
471 _gtk_binding_signal_new (I_("focus_home_or_end"),
472 G_OBJECT_CLASS_TYPE (klass),
473 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
474 G_CALLBACK (gtk_toolbar_focus_home_or_end),
476 _gtk_marshal_BOOLEAN__BOOLEAN,
481 g_object_class_install_property (gobject_class,
483 g_param_spec_enum ("orientation",
485 P_("The orientation of the toolbar"),
486 GTK_TYPE_ORIENTATION,
487 GTK_ORIENTATION_HORIZONTAL,
488 GTK_PARAM_READWRITE));
490 g_object_class_install_property (gobject_class,
492 g_param_spec_enum ("toolbar-style",
494 P_("How to draw the toolbar"),
495 GTK_TYPE_TOOLBAR_STYLE,
497 GTK_PARAM_READWRITE));
498 g_object_class_install_property (gobject_class,
500 g_param_spec_boolean ("show-arrow",
502 P_("If an arrow should be shown if the toolbar doesn't fit"),
504 GTK_PARAM_READWRITE));
508 * GtkToolbar:tooltips:
510 * If the tooltips of the toolbar should be active or not.
514 g_object_class_install_property (gobject_class,
516 g_param_spec_boolean ("tooltips",
518 P_("If the tooltips of the toolbar should be active or not"),
520 GTK_PARAM_READWRITE));
524 * GtkToolbar:icon-size:
526 * The size of the icons in a toolbar is normally determined by
527 * the toolbar-icon-size setting. When this property is set, it
528 * overrides the setting.
530 * This should only be used for special-purpose toolbars, normal
531 * application toolbars should respect the user preferences for the
536 g_object_class_install_property (gobject_class,
538 g_param_spec_enum ("icon-size",
540 P_("Size of icons in this toolbar"),
543 GTK_PARAM_READWRITE));
546 * GtkToolbar:icon-size-set:
548 * Is %TRUE if the icon-size property has been set.
552 g_object_class_install_property (gobject_class,
554 g_param_spec_boolean ("icon-size-set",
556 P_("Whether the icon-size property has been set"),
558 GTK_PARAM_READWRITE));
560 /* child properties */
561 gtk_container_class_install_child_property (container_class,
563 g_param_spec_boolean ("expand",
565 P_("Whether the item should receive extra space when the toolbar grows"),
567 GTK_PARAM_READWRITE));
569 gtk_container_class_install_child_property (container_class,
570 CHILD_PROP_HOMOGENEOUS,
571 g_param_spec_boolean ("homogeneous",
573 P_("Whether the item should be the same size as other homogeneous items"),
575 GTK_PARAM_READWRITE));
577 /* style properties */
578 gtk_widget_class_install_style_property (widget_class,
579 g_param_spec_int ("space-size",
581 P_("Size of spacers"),
585 GTK_PARAM_READABLE));
587 gtk_widget_class_install_style_property (widget_class,
588 g_param_spec_int ("internal-padding",
589 P_("Internal padding"),
590 P_("Amount of border space between the toolbar shadow and the buttons"),
594 GTK_PARAM_READABLE));
596 gtk_widget_class_install_style_property (widget_class,
597 g_param_spec_int ("max-child-expand",
598 P_("Maximum child expand"),
599 P_("Maximum amount of space an expandable item will be given"),
603 GTK_PARAM_READABLE));
605 gtk_widget_class_install_style_property (widget_class,
606 g_param_spec_enum ("space-style",
608 P_("Whether spacers are vertical lines or just blank"),
609 GTK_TYPE_TOOLBAR_SPACE_STYLE,
611 GTK_PARAM_READABLE));
613 gtk_widget_class_install_style_property (widget_class,
614 g_param_spec_enum ("button-relief",
616 P_("Type of bevel around toolbar buttons"),
617 GTK_TYPE_RELIEF_STYLE,
619 GTK_PARAM_READABLE));
620 gtk_widget_class_install_style_property (widget_class,
621 g_param_spec_enum ("shadow-type",
623 P_("Style of bevel around the toolbar"),
624 GTK_TYPE_SHADOW_TYPE,
626 GTK_PARAM_READABLE));
628 gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-style",
630 P_("Whether default toolbars have text only, text and icons, icons only, etc."),
631 GTK_TYPE_TOOLBAR_STYLE,
632 DEFAULT_TOOLBAR_STYLE,
633 GTK_PARAM_READWRITE));
635 gtk_settings_install_property (g_param_spec_enum ("gtk-toolbar-icon-size",
636 P_("Toolbar icon size"),
637 P_("Size of icons in default toolbars"),
640 GTK_PARAM_READWRITE));
642 binding_set = gtk_binding_set_by_class (klass);
644 add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
645 add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
646 add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
647 add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
649 gtk_binding_entry_add_signal (binding_set, GDK_KP_Home, 0,
650 "focus_home_or_end", 1,
651 G_TYPE_BOOLEAN, TRUE);
652 gtk_binding_entry_add_signal (binding_set, GDK_Home, 0,
653 "focus_home_or_end", 1,
654 G_TYPE_BOOLEAN, TRUE);
655 gtk_binding_entry_add_signal (binding_set, GDK_KP_End, 0,
656 "focus_home_or_end", 1,
657 G_TYPE_BOOLEAN, FALSE);
658 gtk_binding_entry_add_signal (binding_set, GDK_End, 0,
659 "focus_home_or_end", 1,
660 G_TYPE_BOOLEAN, FALSE);
662 add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
663 add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
665 g_type_class_add_private (gobject_class, sizeof (GtkToolbarPrivate));
669 gtk_toolbar_init (GtkToolbar *toolbar)
671 GtkToolbarPrivate *priv;
673 GTK_WIDGET_UNSET_FLAGS (toolbar, GTK_CAN_FOCUS);
674 GTK_WIDGET_SET_FLAGS (toolbar, GTK_NO_WINDOW);
676 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
678 toolbar->orientation = GTK_ORIENTATION_HORIZONTAL;
679 toolbar->style = DEFAULT_TOOLBAR_STYLE;
680 toolbar->icon_size = DEFAULT_ICON_SIZE;
681 priv->animation = DEFAULT_ANIMATION_STATE;
682 toolbar->tooltips = gtk_tooltips_new ();
683 g_object_ref_sink (toolbar->tooltips);
685 priv->arrow_button = gtk_toggle_button_new ();
686 g_signal_connect (priv->arrow_button, "button_press_event",
687 G_CALLBACK (gtk_toolbar_arrow_button_press), toolbar);
688 g_signal_connect (priv->arrow_button, "clicked",
689 G_CALLBACK (gtk_toolbar_arrow_button_clicked), toolbar);
690 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
691 get_button_relief (toolbar));
693 priv->api_mode = DONT_KNOW;
695 gtk_button_set_focus_on_click (GTK_BUTTON (priv->arrow_button), FALSE);
697 priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
698 gtk_widget_set_name (priv->arrow, "gtk-toolbar-arrow");
699 gtk_widget_show (priv->arrow);
700 gtk_container_add (GTK_CONTAINER (priv->arrow_button), priv->arrow);
702 gtk_widget_set_parent (priv->arrow_button, GTK_WIDGET (toolbar));
704 /* which child position a drop will occur at */
706 priv->show_arrow = TRUE;
707 priv->settings = NULL;
709 priv->max_homogeneous_pixels = -1;
711 priv->timer = g_timer_new ();
715 gtk_toolbar_set_property (GObject *object,
720 GtkToolbar *toolbar = GTK_TOOLBAR (object);
724 case PROP_ORIENTATION:
725 gtk_toolbar_set_orientation (toolbar, g_value_get_enum (value));
727 case PROP_TOOLBAR_STYLE:
728 gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
730 case PROP_SHOW_ARROW:
731 gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
734 gtk_toolbar_set_tooltips (toolbar, g_value_get_boolean (value));
737 gtk_toolbar_set_icon_size (toolbar, g_value_get_enum (value));
739 case PROP_ICON_SIZE_SET:
740 if (g_value_get_boolean (value))
741 toolbar->icon_size_set = TRUE;
743 gtk_toolbar_unset_icon_size (toolbar);
746 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
752 gtk_toolbar_get_property (GObject *object,
757 GtkToolbar *toolbar = GTK_TOOLBAR (object);
758 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
762 case PROP_ORIENTATION:
763 g_value_set_enum (value, toolbar->orientation);
765 case PROP_TOOLBAR_STYLE:
766 g_value_set_enum (value, toolbar->style);
768 case PROP_SHOW_ARROW:
769 g_value_set_boolean (value, priv->show_arrow);
772 g_value_set_boolean (value, gtk_toolbar_get_tooltips (toolbar));
775 g_value_set_enum (value, gtk_toolbar_get_icon_size (toolbar));
777 case PROP_ICON_SIZE_SET:
778 g_value_set_boolean (value, toolbar->icon_size_set);
781 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
787 gtk_toolbar_map (GtkWidget *widget)
789 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
791 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->map (widget);
793 if (priv->event_window)
794 gdk_window_show_unraised (priv->event_window);
798 gtk_toolbar_unmap (GtkWidget *widget)
800 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
802 if (priv->event_window)
803 gdk_window_hide (priv->event_window);
805 GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unmap (widget);
809 gtk_toolbar_realize (GtkWidget *widget)
811 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
812 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
814 GdkWindowAttr attributes;
815 gint attributes_mask;
818 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
820 border_width = GTK_CONTAINER (widget)->border_width;
822 attributes.wclass = GDK_INPUT_ONLY;
823 attributes.window_type = GDK_WINDOW_CHILD;
824 attributes.x = widget->allocation.x + border_width;
825 attributes.y = widget->allocation.y + border_width;
826 attributes.width = widget->allocation.width - border_width * 2;
827 attributes.height = widget->allocation.height - border_width * 2;
828 attributes.event_mask = gtk_widget_get_events (widget);
829 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
830 GDK_BUTTON_RELEASE_MASK |
831 GDK_ENTER_NOTIFY_MASK |
832 GDK_LEAVE_NOTIFY_MASK);
834 attributes_mask = GDK_WA_X | GDK_WA_Y;
836 widget->window = gtk_widget_get_parent_window (widget);
837 g_object_ref (widget->window);
838 widget->style = gtk_style_attach (widget->style, widget->window);
840 priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
841 &attributes, attributes_mask);
842 gdk_window_set_user_data (priv->event_window, toolbar);
846 gtk_toolbar_unrealize (GtkWidget *widget)
848 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
850 if (priv->event_window)
852 gdk_window_set_user_data (priv->event_window, NULL);
853 gdk_window_destroy (priv->event_window);
854 priv->event_window = NULL;
857 if (GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize)
858 (* GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unrealize) (widget);
862 gtk_toolbar_expose (GtkWidget *widget,
863 GdkEventExpose *event)
865 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
866 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
871 border_width = GTK_CONTAINER (widget)->border_width;
873 if (GTK_WIDGET_DRAWABLE (widget))
875 gtk_paint_box (widget->style,
877 GTK_WIDGET_STATE (widget),
878 get_shadow_type (toolbar),
879 &event->area, widget, "toolbar",
880 border_width + widget->allocation.x,
881 border_width + widget->allocation.y,
882 widget->allocation.width - 2 * border_width,
883 widget->allocation.height - 2 * border_width);
886 for (list = priv->content; list != NULL; list = list->next)
888 ToolbarContent *content = list->data;
890 toolbar_content_expose (content, GTK_CONTAINER (widget), event);
893 gtk_container_propagate_expose (GTK_CONTAINER (widget),
901 gtk_toolbar_size_request (GtkWidget *widget,
902 GtkRequisition *requisition)
904 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
905 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
907 gint max_child_height;
908 gint max_child_width;
909 gint max_homogeneous_child_width;
910 gint max_homogeneous_child_height;
911 gint homogeneous_size;
913 gint pack_front_size;
915 GtkRequisition arrow_requisition;
917 max_homogeneous_child_width = 0;
918 max_homogeneous_child_height = 0;
920 max_child_height = 0;
921 for (list = priv->content; list != NULL; list = list->next)
923 GtkRequisition requisition;
924 ToolbarContent *content = list->data;
926 if (!toolbar_content_visible (content, toolbar))
929 toolbar_content_size_request (content, toolbar, &requisition);
931 max_child_width = MAX (max_child_width, requisition.width);
932 max_child_height = MAX (max_child_height, requisition.height);
934 if (toolbar_content_is_homogeneous (content, toolbar))
936 max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
937 max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
941 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
942 homogeneous_size = max_homogeneous_child_width;
944 homogeneous_size = max_homogeneous_child_height;
947 for (list = priv->content; list != NULL; list = list->next)
949 ToolbarContent *content = list->data;
952 if (!toolbar_content_visible (content, toolbar))
955 if (toolbar_content_is_homogeneous (content, toolbar))
957 size = homogeneous_size;
961 GtkRequisition requisition;
963 toolbar_content_size_request (content, toolbar, &requisition);
965 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
966 size = requisition.width;
968 size = requisition.height;
971 pack_front_size += size;
974 if (priv->show_arrow && priv->api_mode == NEW_API)
976 gtk_widget_size_request (priv->arrow_button, &arrow_requisition);
978 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
979 long_req = arrow_requisition.width;
981 long_req = arrow_requisition.height;
983 /* There is no point requesting space for the arrow if that would take
984 * up more space than all the items combined
986 long_req = MIN (long_req, pack_front_size);
990 arrow_requisition.height = 0;
991 arrow_requisition.width = 0;
993 long_req = pack_front_size;
996 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
998 requisition->width = long_req;
999 requisition->height = MAX (max_child_height, arrow_requisition.height);
1003 requisition->height = long_req;
1004 requisition->width = MAX (max_child_width, arrow_requisition.width);
1008 ipadding = get_internal_padding (toolbar);
1010 requisition->width += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
1011 requisition->height += 2 * (ipadding + GTK_CONTAINER (toolbar)->border_width);
1013 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1015 requisition->width += 2 * widget->style->xthickness;
1016 requisition->height += 2 * widget->style->ythickness;
1019 toolbar->button_maxw = max_homogeneous_child_width;
1020 toolbar->button_maxh = max_homogeneous_child_height;
1024 position (GtkToolbar *toolbar,
1031 if (! GTK_TOOLBAR_GET_PRIVATE (toolbar)->animation)
1034 if (elapsed <= ACCEL_THRESHOLD)
1036 n_pixels = SLIDE_SPEED * elapsed;
1040 /* The formula is a second degree polynomial in
1041 * @elapsed that has the line SLIDE_SPEED * @elapsed
1042 * as tangent for @elapsed == ACCEL_THRESHOLD.
1043 * This makes @n_pixels a smooth function of elapsed time.
1045 n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
1046 SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
1050 return MIN (from + n_pixels, to);
1052 return MAX (from - n_pixels, to);
1056 compute_intermediate_allocation (GtkToolbar *toolbar,
1057 const GtkAllocation *start,
1058 const GtkAllocation *goal,
1059 GtkAllocation *intermediate)
1061 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1062 gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
1064 intermediate->x = position (toolbar, start->x, goal->x, elapsed);
1065 intermediate->y = position (toolbar, start->y, goal->y, elapsed);
1066 intermediate->width = position (toolbar, start->x + start->width,
1067 goal->x + goal->width,
1068 elapsed) - intermediate->x;
1069 intermediate->height = position (toolbar, start->y + start->height,
1070 goal->y + goal->height,
1071 elapsed) - intermediate->y;
1075 fixup_allocation_for_rtl (gint total_size,
1076 GtkAllocation *allocation)
1078 allocation->x += (total_size - (2 * allocation->x + allocation->width));
1082 fixup_allocation_for_vertical (GtkAllocation *allocation)
1086 tmp = allocation->x;
1087 allocation->x = allocation->y;
1088 allocation->y = tmp;
1090 tmp = allocation->width;
1091 allocation->width = allocation->height;
1092 allocation->height = tmp;
1096 get_item_size (GtkToolbar *toolbar,
1097 ToolbarContent *content)
1099 GtkRequisition requisition;
1101 toolbar_content_size_request (content, toolbar, &requisition);
1103 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1105 if (toolbar_content_is_homogeneous (content, toolbar))
1106 return toolbar->button_maxw;
1108 return requisition.width;
1112 if (toolbar_content_is_homogeneous (content, toolbar))
1113 return toolbar->button_maxh;
1115 return requisition.height;
1120 slide_idle_handler (gpointer data)
1122 GtkToolbar *toolbar = data;
1123 GtkToolbarPrivate *priv;
1126 GDK_THREADS_ENTER ();
1128 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1130 if (priv->need_sync)
1133 priv->need_sync = FALSE;
1136 for (list = priv->content; list != NULL; list = list->next)
1138 ToolbarContent *content = list->data;
1140 GtkAllocation goal_allocation;
1141 GtkAllocation allocation;
1144 state = toolbar_content_get_state (content);
1145 toolbar_content_get_goal_allocation (content, &goal_allocation);
1146 toolbar_content_get_allocation (content, &allocation);
1150 if (state == NOT_ALLOCATED)
1152 /* an unallocated item means that size allocate has to
1153 * called at least once more
1158 /* An invisible item with a goal allocation of
1159 * 0 is already at its goal.
1161 if ((state == NORMAL || state == OVERFLOWN) &&
1162 ((goal_allocation.width != 0 &&
1163 goal_allocation.height != 0) ||
1164 toolbar_content_child_visible (content)))
1166 if ((goal_allocation.x != allocation.x ||
1167 goal_allocation.y != allocation.y ||
1168 goal_allocation.width != allocation.width ||
1169 goal_allocation.height != allocation.height))
1171 /* An item is not in its right position yet. Note
1172 * that OVERFLOWN items do get an allocation in
1173 * gtk_toolbar_size_allocate(). This way you can see
1174 * them slide back in when you drag an item off the
1181 if (toolbar_content_is_placeholder (content) &&
1182 toolbar_content_disappearing (content) &&
1183 toolbar_content_child_visible (content))
1185 /* A disappearing placeholder is still visible.
1193 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1195 GDK_THREADS_LEAVE ();
1200 priv->is_sliding = FALSE;
1203 GDK_THREADS_LEAVE();
1208 rect_within (GtkAllocation *a1,
1211 return (a1->x >= a2->x &&
1212 a1->x + a1->width <= a2->x + a2->width &&
1214 a1->y + a1->height <= a2->y + a2->height);
1218 gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
1220 GtkWidget *widget = GTK_WIDGET (toolbar);
1221 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1229 /* Start the sliding. This function copies the allocation of every
1230 * item into content->start_allocation. For items that haven't
1231 * been allocated yet, we calculate their position and save that
1232 * in start_allocatino along with zero width and zero height.
1234 * FIXME: It would be nice if we could share this code with
1235 * the equivalent in gtk_widget_size_allocate().
1237 priv->is_sliding = TRUE;
1240 priv->idle_id = g_idle_add (slide_idle_handler, toolbar);
1242 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1243 vertical = (toolbar->orientation == GTK_ORIENTATION_VERTICAL);
1244 border_width = get_internal_padding (toolbar) + GTK_CONTAINER (toolbar)->border_width;
1248 cur_x = widget->allocation.width - border_width - widget->style->xthickness;
1249 cur_y = widget->allocation.height - border_width - widget->style->ythickness;
1253 cur_x = border_width + widget->style->xthickness;
1254 cur_y = border_width + widget->style->ythickness;
1257 cur_x += widget->allocation.x;
1258 cur_y += widget->allocation.y;
1260 for (list = priv->content; list != NULL; list = list->next)
1262 ToolbarContent *content = list->data;
1263 GtkAllocation new_start_allocation;
1264 GtkAllocation item_allocation;
1267 state = toolbar_content_get_state (content);
1268 toolbar_content_get_allocation (content, &item_allocation);
1270 if ((state == NORMAL &&
1271 rect_within (&item_allocation, &(widget->allocation))) ||
1274 new_start_allocation = item_allocation;
1278 new_start_allocation.x = cur_x;
1279 new_start_allocation.y = cur_y;
1283 new_start_allocation.width = widget->allocation.width -
1284 2 * border_width - 2 * widget->style->xthickness;
1285 new_start_allocation.height = 0;
1289 new_start_allocation.width = 0;
1290 new_start_allocation.height = widget->allocation.height -
1291 2 * border_width - 2 * widget->style->ythickness;
1296 cur_y = new_start_allocation.y + new_start_allocation.height;
1298 cur_x = new_start_allocation.x;
1300 cur_x = new_start_allocation.x + new_start_allocation.width;
1302 toolbar_content_set_start_allocation (content, &new_start_allocation);
1305 /* This resize will run before the first idle handler. This
1306 * will make sure that items get the right goal allocation
1307 * so that the idle handler will not immediately return
1310 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1311 g_timer_reset (priv->timer);
1315 gtk_toolbar_stop_sliding (GtkToolbar *toolbar)
1317 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1319 if (priv->is_sliding)
1323 priv->is_sliding = FALSE;
1327 g_source_remove (priv->idle_id);
1331 list = priv->content;
1334 ToolbarContent *content = list->data;
1337 if (toolbar_content_is_placeholder (content))
1339 toolbar_content_remove (content, toolbar);
1340 toolbar_content_free (content);
1344 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (toolbar));
1349 remove_item (GtkWidget *menu_item,
1352 gtk_container_remove (GTK_CONTAINER (menu_item->parent), menu_item);
1356 menu_deactivated (GtkWidget *menu,
1357 GtkToolbar *toolbar)
1359 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1360 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->arrow_button), FALSE);
1364 menu_detached (GtkWidget *toolbar,
1367 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1372 rebuild_menu (GtkToolbar *toolbar)
1374 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1375 GList *list, *children;
1379 priv->menu = GTK_MENU (gtk_menu_new());
1380 gtk_menu_attach_to_widget (priv->menu,
1381 GTK_WIDGET (toolbar),
1384 g_signal_connect (priv->menu, "deactivate", G_CALLBACK (menu_deactivated), toolbar);
1387 gtk_container_foreach (GTK_CONTAINER (priv->menu), remove_item, NULL);
1389 for (list = priv->content; list != NULL; list = list->next)
1391 ToolbarContent *content = list->data;
1393 if (toolbar_content_get_state (content) == OVERFLOWN &&
1394 !toolbar_content_is_placeholder (content))
1396 GtkWidget *menu_item = toolbar_content_retrieve_menu_item (content);
1400 g_assert (GTK_IS_MENU_ITEM (menu_item));
1401 gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item);
1406 /* Remove leading and trailing separator items */
1407 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1410 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1412 GtkWidget *child = list->data;
1414 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1417 g_list_free (children);
1419 /* Regenerate the list of children so we don't try to remove items twice */
1420 children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
1422 list = g_list_last (children);
1423 while (list && GTK_IS_SEPARATOR_MENU_ITEM (list->data))
1425 GtkWidget *child = list->data;
1427 gtk_container_remove (GTK_CONTAINER (priv->menu), child);
1430 g_list_free (children);
1432 priv->need_rebuild = FALSE;
1436 gtk_toolbar_size_allocate (GtkWidget *widget,
1437 GtkAllocation *allocation)
1439 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1440 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1441 GtkAllocation *allocations;
1442 ItemState *new_states;
1443 GtkAllocation arrow_allocation;
1445 gint size, pos, short_size;
1448 gboolean need_arrow;
1449 gint n_expand_items;
1451 gint available_size;
1454 GtkRequisition arrow_requisition;
1455 gboolean overflowing;
1456 gboolean size_changed;
1458 GtkAllocation item_area;
1460 size_changed = FALSE;
1461 if (widget->allocation.x != allocation->x ||
1462 widget->allocation.y != allocation->y ||
1463 widget->allocation.width != allocation->width ||
1464 widget->allocation.height != allocation->height)
1466 size_changed = TRUE;
1470 gtk_toolbar_stop_sliding (toolbar);
1472 widget->allocation = *allocation;
1474 border_width = GTK_CONTAINER (toolbar)->border_width;
1476 if (GTK_WIDGET_REALIZED (widget))
1478 gdk_window_move_resize (priv->event_window,
1479 allocation->x + border_width,
1480 allocation->y + border_width,
1481 allocation->width - border_width * 2,
1482 allocation->height - border_width * 2);
1485 border_width += get_internal_padding (toolbar);
1487 gtk_widget_get_child_requisition (GTK_WIDGET (priv->arrow_button),
1488 &arrow_requisition);
1490 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
1492 available_size = size = allocation->width - 2 * border_width;
1493 short_size = allocation->height - 2 * border_width;
1494 arrow_size = arrow_requisition.width;
1496 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1498 available_size -= 2 * widget->style->xthickness;
1499 short_size -= 2 * widget->style->ythickness;
1504 available_size = size = allocation->height - 2 * border_width;
1505 short_size = allocation->width - 2 * border_width;
1506 arrow_size = arrow_requisition.height;
1508 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1510 available_size -= 2 * widget->style->ythickness;
1511 short_size -= 2 * widget->style->xthickness;
1515 n_items = g_list_length (priv->content);
1516 allocations = g_new0 (GtkAllocation, n_items);
1517 new_states = g_new0 (ItemState, n_items);
1521 for (list = priv->content; list != NULL; list = list->next)
1523 ToolbarContent *content = list->data;
1525 if (toolbar_content_visible (content, toolbar))
1527 needed_size += get_item_size (toolbar, content);
1529 /* Do we need an arrow?
1531 * Assume we don't, and see if any non-separator item with a
1532 * proxy menu item is then going to overflow.
1534 if (needed_size > available_size &&
1537 priv->api_mode == NEW_API &&
1538 toolbar_content_has_proxy_menu_item (content) &&
1539 !toolbar_content_is_separator (content))
1547 size = available_size - arrow_size;
1549 size = available_size;
1551 /* calculate widths and states of items */
1552 overflowing = FALSE;
1553 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1555 ToolbarContent *content = list->data;
1558 if (!toolbar_content_visible (content, toolbar))
1560 new_states[i] = HIDDEN;
1564 item_size = get_item_size (toolbar, content);
1565 if (item_size <= size && !overflowing)
1568 allocations[i].width = item_size;
1569 new_states[i] = NORMAL;
1574 new_states[i] = OVERFLOWN;
1575 allocations[i].width = item_size;
1579 /* calculate width of arrow */
1582 arrow_allocation.width = arrow_size;
1583 arrow_allocation.height = MAX (short_size, 1);
1586 /* expand expandable items */
1588 /* We don't expand when there is an overflow menu, because that leads to
1589 * weird jumps when items get moved to the overflow menu and the expanding
1590 * items suddenly get a lot of extra space
1594 gint max_child_expand;
1597 for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
1599 ToolbarContent *content = list->data;
1601 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1605 max_child_expand = get_max_child_expand (toolbar);
1606 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1608 ToolbarContent *content = list->data;
1610 if (toolbar_content_get_expand (content) && new_states[i] == NORMAL)
1612 gint extra = size / n_expand_items;
1613 if (size % n_expand_items != 0)
1616 if (extra > max_child_expand)
1617 extra = max_child_expand;
1619 allocations[i].width += extra;
1625 g_assert (n_expand_items == 0);
1628 /* position items */
1630 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1632 /* both NORMAL and OVERFLOWN items get a position. This ensures
1633 * that sliding will work for OVERFLOWN items too
1635 if (new_states[i] == NORMAL ||
1636 new_states[i] == OVERFLOWN)
1638 allocations[i].x = pos;
1639 allocations[i].y = border_width;
1640 allocations[i].height = short_size;
1642 pos += allocations[i].width;
1646 /* position arrow */
1649 arrow_allocation.x = available_size - border_width - arrow_allocation.width;
1650 arrow_allocation.y = border_width;
1653 item_area.x = border_width;
1654 item_area.y = border_width;
1655 item_area.width = available_size - (need_arrow? arrow_size : 0);
1656 item_area.height = short_size;
1658 /* fix up allocations in the vertical or RTL cases */
1659 if (toolbar->orientation == GTK_ORIENTATION_VERTICAL)
1661 for (i = 0; i < n_items; ++i)
1662 fixup_allocation_for_vertical (&(allocations[i]));
1665 fixup_allocation_for_vertical (&arrow_allocation);
1667 fixup_allocation_for_vertical (&item_area);
1669 else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1671 for (i = 0; i < n_items; ++i)
1672 fixup_allocation_for_rtl (available_size, &(allocations[i]));
1675 fixup_allocation_for_rtl (available_size, &arrow_allocation);
1677 fixup_allocation_for_rtl (available_size, &item_area);
1680 /* translate the items by allocation->(x,y) */
1681 for (i = 0; i < n_items; ++i)
1683 allocations[i].x += allocation->x;
1684 allocations[i].y += allocation->y;
1686 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1688 allocations[i].x += widget->style->xthickness;
1689 allocations[i].y += widget->style->ythickness;
1695 arrow_allocation.x += allocation->x;
1696 arrow_allocation.y += allocation->y;
1698 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1700 arrow_allocation.x += widget->style->xthickness;
1701 arrow_allocation.y += widget->style->ythickness;
1705 item_area.x += allocation->x;
1706 item_area.y += allocation->y;
1707 if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
1709 item_area.x += widget->style->xthickness;
1710 item_area.y += widget->style->ythickness;
1713 /* did anything change? */
1714 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1716 ToolbarContent *content = list->data;
1718 if (toolbar_content_get_state (content) == NORMAL &&
1719 new_states[i] != NORMAL)
1721 /* an item disappeared and we didn't change size, so begin sliding */
1722 if (!size_changed && priv->api_mode == NEW_API)
1723 gtk_toolbar_begin_sliding (toolbar);
1727 /* finally allocate the items */
1728 if (priv->is_sliding)
1730 for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
1732 ToolbarContent *content = list->data;
1734 toolbar_content_set_goal_allocation (content, &(allocations[i]));
1738 elapsed = g_timer_elapsed (priv->timer, NULL);
1739 for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
1741 ToolbarContent *content = list->data;
1743 if (new_states[i] == OVERFLOWN ||
1744 new_states[i] == NORMAL)
1746 GtkAllocation alloc;
1747 GtkAllocation start_allocation = { 0, };
1748 GtkAllocation goal_allocation;
1750 if (priv->is_sliding)
1752 toolbar_content_get_start_allocation (content, &start_allocation);
1753 toolbar_content_get_goal_allocation (content, &goal_allocation);
1755 compute_intermediate_allocation (toolbar,
1760 priv->need_sync = TRUE;
1764 alloc = allocations[i];
1767 if (alloc.width <= 0 || alloc.height <= 0)
1769 toolbar_content_set_child_visible (content, toolbar, FALSE);
1773 if (!rect_within (&alloc, &item_area))
1775 toolbar_content_set_child_visible (content, toolbar, FALSE);
1776 toolbar_content_size_allocate (content, &alloc);
1780 toolbar_content_set_child_visible (content, toolbar, TRUE);
1781 toolbar_content_size_allocate (content, &alloc);
1787 toolbar_content_set_child_visible (content, toolbar, FALSE);
1790 toolbar_content_set_state (content, new_states[i]);
1793 if (priv->menu && priv->need_rebuild)
1794 rebuild_menu (toolbar);
1798 gtk_widget_size_allocate (GTK_WIDGET (priv->arrow_button),
1800 gtk_widget_show (GTK_WIDGET (priv->arrow_button));
1804 gtk_widget_hide (GTK_WIDGET (priv->arrow_button));
1806 if (priv->menu && GTK_WIDGET_VISIBLE (priv->menu))
1807 gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
1810 g_free (allocations);
1811 g_free (new_states);
1815 gtk_toolbar_update_button_relief (GtkToolbar *toolbar)
1817 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1819 gtk_toolbar_reconfigured (toolbar);
1821 gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), get_button_relief (toolbar));
1825 gtk_toolbar_style_set (GtkWidget *widget,
1826 GtkStyle *prev_style)
1828 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
1830 priv->max_homogeneous_pixels = -1;
1832 if (GTK_WIDGET_REALIZED (widget))
1833 gtk_style_set_background (widget->style, widget->window, widget->state);
1836 gtk_toolbar_update_button_relief (GTK_TOOLBAR (widget));
1840 gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
1841 GtkDirectionType dir)
1843 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1844 GList *result = NULL;
1848 /* generate list of children in reverse logical order */
1850 for (list = priv->content; list != NULL; list = list->next)
1852 ToolbarContent *content = list->data;
1855 widget = toolbar_content_get_widget (content);
1858 result = g_list_prepend (result, widget);
1861 result = g_list_prepend (result, priv->arrow_button);
1863 rtl = (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL);
1865 /* move in logical order when
1867 * - dir is TAB_FORWARD
1869 * - in RTL mode and moving left or up
1871 * - in LTR mode and moving right or down
1873 if (dir == GTK_DIR_TAB_FORWARD ||
1874 (rtl && (dir == GTK_DIR_UP || dir == GTK_DIR_LEFT)) ||
1875 (!rtl && (dir == GTK_DIR_DOWN || dir == GTK_DIR_RIGHT)))
1877 result = g_list_reverse (result);
1884 gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
1885 gboolean focus_home)
1887 GList *children, *list;
1888 GtkDirectionType dir = focus_home? GTK_DIR_RIGHT : GTK_DIR_LEFT;
1890 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1892 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
1894 children = g_list_reverse (children);
1896 dir = (dir == GTK_DIR_RIGHT)? GTK_DIR_LEFT : GTK_DIR_RIGHT;
1899 for (list = children; list != NULL; list = list->next)
1901 GtkWidget *child = list->data;
1903 if (GTK_CONTAINER (toolbar)->focus_child == child)
1906 if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1910 g_list_free (children);
1915 /* Keybinding handler. This function is called when the user presses
1916 * Ctrl TAB or an arrow key.
1919 gtk_toolbar_move_focus (GtkToolbar *toolbar,
1920 GtkDirectionType dir)
1923 gboolean try_focus = FALSE;
1925 GtkContainer *container = GTK_CONTAINER (toolbar);
1927 if (container->focus_child &&
1928 gtk_widget_child_focus (container->focus_child, dir))
1933 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1935 for (list = children; list != NULL; list = list->next)
1937 GtkWidget *child = list->data;
1939 if (try_focus && GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1942 if (child == GTK_CONTAINER (toolbar)->focus_child)
1946 g_list_free (children);
1951 /* The focus handler for the toolbar. It called when the user presses
1952 * TAB or otherwise tries to focus the toolbar.
1955 gtk_toolbar_focus (GtkWidget *widget,
1956 GtkDirectionType dir)
1958 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
1959 GList *children, *list;
1960 gboolean result = FALSE;
1962 /* if focus is already somewhere inside the toolbar then return FALSE.
1963 * The only way focus can stay inside the toolbar is when the user presses
1964 * arrow keys or Ctrl TAB (both of which are handled by the
1965 * gtk_toolbar_move_focus() keybinding function.
1967 if (GTK_CONTAINER (widget)->focus_child)
1970 children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
1972 for (list = children; list != NULL; list = list->next)
1974 GtkWidget *child = list->data;
1976 if (GTK_WIDGET_MAPPED (child) && gtk_widget_child_focus (child, dir))
1983 g_list_free (children);
1988 static GtkSettings *
1989 toolbar_get_settings (GtkToolbar *toolbar)
1991 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
1992 return priv->settings;
1996 style_change_notify (GtkToolbar *toolbar)
1998 if (!toolbar->style_set)
2000 /* pretend it was set, then unset, thus reverting to new default */
2001 toolbar->style_set = TRUE;
2002 gtk_toolbar_unset_style (toolbar);
2007 icon_size_change_notify (GtkToolbar *toolbar)
2009 if (!toolbar->icon_size_set)
2011 /* pretend it was set, then unset, thus reverting to new default */
2012 toolbar->icon_size_set = TRUE;
2013 gtk_toolbar_unset_icon_size (toolbar);
2018 animation_change_notify (GtkToolbar *toolbar)
2020 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2021 GtkSettings *settings = toolbar_get_settings (toolbar);
2025 g_object_get (settings,
2026 "gtk-enable-animations", &animation,
2029 animation = DEFAULT_ANIMATION_STATE;
2031 priv->animation = animation;
2035 settings_change_notify (GtkSettings *settings,
2036 const GParamSpec *pspec,
2037 GtkToolbar *toolbar)
2039 if (! strcmp (pspec->name, "gtk-toolbar-style"))
2040 style_change_notify (toolbar);
2041 else if (! strcmp (pspec->name, "gtk-toolbar-icon-size"))
2042 icon_size_change_notify (toolbar);
2043 else if (! strcmp (pspec->name, "gtk-enable-animations"))
2044 animation_change_notify (toolbar);
2048 gtk_toolbar_screen_changed (GtkWidget *widget,
2049 GdkScreen *previous_screen)
2051 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2052 GtkToolbar *toolbar = GTK_TOOLBAR (widget);
2053 GtkSettings *old_settings = toolbar_get_settings (toolbar);
2054 GtkSettings *settings;
2056 if (gtk_widget_has_screen (GTK_WIDGET (toolbar)))
2057 settings = gtk_widget_get_settings (GTK_WIDGET (toolbar));
2061 if (settings == old_settings)
2066 g_signal_handler_disconnect (old_settings, priv->settings_connection);
2068 g_object_unref (old_settings);
2073 priv->settings_connection =
2074 g_signal_connect (settings, "notify",
2075 G_CALLBACK (settings_change_notify),
2078 priv->settings = g_object_ref (settings);
2081 priv->settings = NULL;
2083 style_change_notify (toolbar);
2084 icon_size_change_notify (toolbar);
2085 animation_change_notify (toolbar);
2089 find_drop_index (GtkToolbar *toolbar,
2093 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2094 GList *interesting_content;
2096 GtkOrientation orientation;
2097 GtkTextDirection direction;
2098 gint best_distance = G_MAXINT;
2102 ToolbarContent *best_content;
2103 GtkAllocation allocation;
2105 /* list items we care about wrt. drag and drop */
2106 interesting_content = NULL;
2107 for (list = priv->content; list != NULL; list = list->next)
2109 ToolbarContent *content = list->data;
2111 if (toolbar_content_get_state (content) == NORMAL)
2112 interesting_content = g_list_prepend (interesting_content, content);
2114 interesting_content = g_list_reverse (interesting_content);
2116 if (!interesting_content)
2119 orientation = toolbar->orientation;
2120 direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
2122 /* distance to first interesting item */
2123 best_content = interesting_content->data;
2124 toolbar_content_get_allocation (best_content, &allocation);
2126 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2130 if (direction == GTK_TEXT_DIR_LTR)
2133 pos = allocation.x + allocation.width;
2141 best_content = NULL;
2142 best_distance = ABS (pos - cursor);
2144 /* distance to far end of each item */
2145 for (list = interesting_content; list != NULL; list = list->next)
2147 ToolbarContent *content = list->data;
2149 toolbar_content_get_allocation (content, &allocation);
2151 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2153 if (direction == GTK_TEXT_DIR_LTR)
2154 pos = allocation.x + allocation.width;
2160 pos = allocation.y + allocation.height;
2163 distance = ABS (pos - cursor);
2165 if (distance < best_distance)
2167 best_distance = distance;
2168 best_content = content;
2172 g_list_free (interesting_content);
2177 return g_list_index (priv->content, best_content) + 1;
2181 reset_all_placeholders (GtkToolbar *toolbar)
2183 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2186 for (list = priv->content; list != NULL; list = list->next)
2188 ToolbarContent *content = list->data;
2189 if (toolbar_content_is_placeholder (content))
2190 toolbar_content_set_disappearing (content, TRUE);
2195 physical_to_logical (GtkToolbar *toolbar,
2198 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2202 g_assert (physical >= 0);
2205 for (list = priv->content; list && physical > 0; list = list->next)
2207 ToolbarContent *content = list->data;
2209 if (!toolbar_content_is_placeholder (content))
2214 g_assert (physical == 0);
2220 logical_to_physical (GtkToolbar *toolbar,
2223 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2227 g_assert (logical >= 0);
2230 for (list = priv->content; list; list = list->next)
2232 ToolbarContent *content = list->data;
2234 if (!toolbar_content_is_placeholder (content))
2244 g_assert (logical == 0);
2250 * gtk_toolbar_set_drop_highlight_item:
2251 * @toolbar: a #GtkToolbar
2252 * @tool_item: a #GtkToolItem, or %NULL to turn of highlighting
2253 * @index_: a position on @toolbar
2255 * Highlights @toolbar to give an idea of what it would look like
2256 * if @item was added to @toolbar at the position indicated by @index_.
2257 * If @item is %NULL, highlighting is turned off. In that case @index_
2260 * The @tool_item passed to this function must not be part of any widget
2261 * hierarchy. When an item is set as drop highlight item it can not
2262 * added to any widget hierarchy or used as highlight item for another
2268 gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar,
2269 GtkToolItem *tool_item,
2272 ToolbarContent *content;
2273 GtkToolbarPrivate *priv;
2275 GtkRequisition requisition;
2276 GtkRequisition old_requisition;
2277 gboolean restart_sliding;
2279 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2280 g_return_if_fail (tool_item == NULL || GTK_IS_TOOL_ITEM (tool_item));
2282 gtk_toolbar_check_new_api (toolbar);
2284 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2288 if (priv->highlight_tool_item)
2290 gtk_widget_unparent (GTK_WIDGET (priv->highlight_tool_item));
2291 g_object_unref (priv->highlight_tool_item);
2292 priv->highlight_tool_item = NULL;
2295 reset_all_placeholders (toolbar);
2296 gtk_toolbar_begin_sliding (toolbar);
2300 n_items = gtk_toolbar_get_n_items (toolbar);
2301 if (index_ < 0 || index_ > n_items)
2304 if (tool_item != priv->highlight_tool_item)
2306 if (priv->highlight_tool_item)
2307 g_object_unref (priv->highlight_tool_item);
2309 g_object_ref_sink (tool_item);
2311 priv->highlight_tool_item = tool_item;
2313 gtk_widget_set_parent (GTK_WIDGET (priv->highlight_tool_item),
2314 GTK_WIDGET (toolbar));
2317 index_ = logical_to_physical (toolbar, index_);
2319 content = g_list_nth_data (priv->content, index_);
2323 ToolbarContent *prev_content;
2325 prev_content = g_list_nth_data (priv->content, index_ - 1);
2327 if (prev_content && toolbar_content_is_placeholder (prev_content))
2328 content = prev_content;
2331 if (!content || !toolbar_content_is_placeholder (content))
2333 GtkWidget *placeholder;
2335 placeholder = GTK_WIDGET (gtk_separator_tool_item_new ());
2337 content = toolbar_content_new_tool_item (toolbar,
2338 GTK_TOOL_ITEM (placeholder),
2340 gtk_widget_show (placeholder);
2344 g_assert (toolbar_content_is_placeholder (content));
2346 gtk_widget_size_request (GTK_WIDGET (priv->highlight_tool_item),
2349 toolbar_content_set_expand (content, gtk_tool_item_get_expand (tool_item));
2351 restart_sliding = FALSE;
2352 toolbar_content_size_request (content, toolbar, &old_requisition);
2353 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2355 requisition.height = -1;
2356 if (requisition.width != old_requisition.width)
2357 restart_sliding = TRUE;
2361 requisition.width = -1;
2362 if (requisition.height != old_requisition.height)
2363 restart_sliding = TRUE;
2366 if (toolbar_content_disappearing (content))
2367 restart_sliding = TRUE;
2369 reset_all_placeholders (toolbar);
2370 toolbar_content_set_disappearing (content, FALSE);
2372 toolbar_content_set_size_request (content,
2373 requisition.width, requisition.height);
2375 if (restart_sliding)
2376 gtk_toolbar_begin_sliding (toolbar);
2380 gtk_toolbar_get_child_property (GtkContainer *container,
2386 GtkToolItem *item = GTK_TOOL_ITEM (child);
2388 switch (property_id)
2390 case CHILD_PROP_HOMOGENEOUS:
2391 g_value_set_boolean (value, gtk_tool_item_get_homogeneous (item));
2394 case CHILD_PROP_EXPAND:
2395 g_value_set_boolean (value, gtk_tool_item_get_expand (item));
2399 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2405 gtk_toolbar_set_child_property (GtkContainer *container,
2408 const GValue *value,
2411 switch (property_id)
2413 case CHILD_PROP_HOMOGENEOUS:
2414 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2417 case CHILD_PROP_EXPAND:
2418 gtk_tool_item_set_expand (GTK_TOOL_ITEM (child), g_value_get_boolean (value));
2422 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
2428 gtk_toolbar_show_all (GtkWidget *widget)
2430 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2433 for (list = priv->content; list != NULL; list = list->next)
2435 ToolbarContent *content = list->data;
2437 toolbar_content_show_all (content);
2440 gtk_widget_show (widget);
2444 gtk_toolbar_hide_all (GtkWidget *widget)
2446 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (widget);
2449 for (list = priv->content; list != NULL; list = list->next)
2451 ToolbarContent *content = list->data;
2453 toolbar_content_hide_all (content);
2456 gtk_widget_hide (widget);
2460 gtk_toolbar_add (GtkContainer *container,
2463 GtkToolbar *toolbar;
2465 g_return_if_fail (GTK_IS_TOOLBAR (container));
2466 g_return_if_fail (widget != NULL);
2468 toolbar = GTK_TOOLBAR (container);
2470 if (GTK_IS_TOOL_ITEM (widget))
2471 gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
2473 gtk_toolbar_append_widget (toolbar, widget, NULL, NULL);
2477 gtk_toolbar_remove (GtkContainer *container,
2480 GtkToolbar *toolbar;
2481 GtkToolbarPrivate *priv;
2482 ToolbarContent *content_to_remove;
2485 g_return_if_fail (GTK_IS_TOOLBAR (container));
2486 g_return_if_fail (GTK_IS_WIDGET (widget));
2488 toolbar = GTK_TOOLBAR (container);
2489 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2491 content_to_remove = NULL;
2492 for (list = priv->content; list != NULL; list = list->next)
2494 ToolbarContent *content = list->data;
2497 child = toolbar_content_get_widget (content);
2498 if (child && child == widget)
2500 content_to_remove = content;
2505 g_return_if_fail (content_to_remove != NULL);
2507 toolbar_content_remove (content_to_remove, toolbar);
2508 toolbar_content_free (content_to_remove);
2512 gtk_toolbar_forall (GtkContainer *container,
2513 gboolean include_internals,
2514 GtkCallback callback,
2515 gpointer callback_data)
2517 GtkToolbar *toolbar = GTK_TOOLBAR (container);
2518 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2521 g_return_if_fail (callback != NULL);
2523 list = priv->content;
2526 ToolbarContent *content = list->data;
2527 GList *next = list->next;
2529 if (include_internals || !toolbar_content_is_placeholder (content))
2531 GtkWidget *child = toolbar_content_get_widget (content);
2534 (*callback) (child, callback_data);
2540 if (include_internals)
2541 (* callback) (priv->arrow_button, callback_data);
2545 gtk_toolbar_child_type (GtkContainer *container)
2547 return GTK_TYPE_TOOL_ITEM;
2551 gtk_toolbar_reconfigured (GtkToolbar *toolbar)
2553 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2556 list = priv->content;
2559 ToolbarContent *content = list->data;
2560 GList *next = list->next;
2562 toolbar_content_toolbar_reconfigured (content, toolbar);
2569 gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
2570 GtkOrientation orientation)
2572 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2573 if (toolbar->orientation != orientation)
2575 toolbar->orientation = orientation;
2577 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2578 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_DOWN, GTK_SHADOW_NONE);
2580 gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2582 gtk_toolbar_reconfigured (toolbar);
2584 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2585 g_object_notify (G_OBJECT (toolbar), "orientation");
2590 gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
2591 GtkToolbarStyle style)
2593 if (toolbar->style != style)
2595 toolbar->style = style;
2597 gtk_toolbar_reconfigured (toolbar);
2599 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
2600 g_object_notify (G_OBJECT (toolbar), "toolbar-style");
2605 menu_position_func (GtkMenu *menu,
2611 GtkToolbar *toolbar = GTK_TOOLBAR (user_data);
2612 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2614 GtkRequisition menu_req;
2615 GdkRectangle monitor;
2619 gtk_widget_size_request (priv->arrow_button, &req);
2620 gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
2622 screen = gtk_widget_get_screen (GTK_WIDGET (menu));
2623 monitor_num = gdk_screen_get_monitor_at_window (screen, priv->arrow_button->window);
2624 if (monitor_num < 0)
2626 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
2628 gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
2629 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
2631 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2632 *x += priv->arrow_button->allocation.width - req.width;
2634 *x += req.width - menu_req.width;
2636 if ((*y + priv->arrow_button->allocation.height + menu_req.height) <= monitor.y + monitor.height)
2637 *y += priv->arrow_button->allocation.height;
2638 else if ((*y - menu_req.height) >= monitor.y)
2639 *y -= menu_req.height;
2640 else if (monitor.y + monitor.height - (*y + priv->arrow_button->allocation.height) > *y)
2641 *y += priv->arrow_button->allocation.height;
2643 *y -= menu_req.height;
2647 if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_LTR)
2648 *x += priv->arrow_button->allocation.width;
2650 *x -= menu_req.width;
2652 if (*y + menu_req.height > monitor.y + monitor.height &&
2653 *y + priv->arrow_button->allocation.height - monitor.y > monitor.y + monitor.height - *y)
2654 *y += priv->arrow_button->allocation.height - menu_req.height;
2661 show_menu (GtkToolbar *toolbar,
2662 GdkEventButton *event)
2664 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2666 rebuild_menu (toolbar);
2668 gtk_widget_show_all (GTK_WIDGET (priv->menu));
2670 gtk_menu_popup (priv->menu, NULL, NULL,
2671 menu_position_func, toolbar,
2672 event? event->button : 0,
2673 event? event->time : gtk_get_current_event_time());
2677 gtk_toolbar_arrow_button_clicked (GtkWidget *button,
2678 GtkToolbar *toolbar)
2680 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2682 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) &&
2683 (!priv->menu || !GTK_WIDGET_VISIBLE (priv->menu)))
2685 /* We only get here when the button is clicked with the keyboard,
2686 * because mouse button presses result in the menu being shown so
2687 * that priv->menu would be non-NULL and visible.
2689 show_menu (toolbar, NULL);
2690 gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
2695 gtk_toolbar_arrow_button_press (GtkWidget *button,
2696 GdkEventButton *event,
2697 GtkToolbar *toolbar)
2699 show_menu (toolbar, event);
2700 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
2706 gtk_toolbar_button_press (GtkWidget *toolbar,
2707 GdkEventButton *event)
2709 if (event->button == 3)
2711 gboolean return_value;
2713 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2714 (int)event->x_root, (int)event->y_root, event->button,
2717 return return_value;
2724 gtk_toolbar_popup_menu (GtkWidget *toolbar)
2726 gboolean return_value;
2727 /* This function is the handler for the "popup menu" keybinding,
2728 * ie., it is called when the user presses Shift F10
2730 g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
2731 -1, -1, -1, &return_value);
2733 return return_value;
2739 * Creates a new toolbar.
2741 * Return Value: the newly-created toolbar.
2744 gtk_toolbar_new (void)
2746 GtkToolbar *toolbar;
2748 toolbar = g_object_new (GTK_TYPE_TOOLBAR, NULL);
2750 return GTK_WIDGET (toolbar);
2754 * gtk_toolbar_insert:
2755 * @toolbar: a #GtkToolbar
2756 * @item: a #GtkToolItem
2757 * @pos: the position of the new item
2759 * Insert a #GtkToolItem into the toolbar at position @pos. If @pos is
2760 * 0 the item is prepended to the start of the toolbar. If @pos is
2761 * negative, the item is appended to the end of the toolbar.
2766 gtk_toolbar_insert (GtkToolbar *toolbar,
2770 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2771 g_return_if_fail (GTK_IS_TOOL_ITEM (item));
2773 if (!gtk_toolbar_check_new_api (toolbar))
2777 pos = logical_to_physical (toolbar, pos);
2779 toolbar_content_new_tool_item (toolbar, item, FALSE, pos);
2783 * gtk_toolbar_get_item_index:
2784 * @toolbar: a #GtkToolbar
2785 * @item: a #GtkToolItem that is a child of @toolbar
2787 * Returns the position of @item on the toolbar, starting from 0.
2788 * It is an error if @item is not a child of the toolbar.
2790 * Return value: the position of item on the toolbar.
2795 gtk_toolbar_get_item_index (GtkToolbar *toolbar,
2798 GtkToolbarPrivate *priv;
2802 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2803 g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
2804 g_return_val_if_fail (GTK_WIDGET (item)->parent == GTK_WIDGET (toolbar), -1);
2806 if (!gtk_toolbar_check_new_api (toolbar))
2809 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2812 for (list = priv->content; list != NULL; list = list->next)
2814 ToolbarContent *content = list->data;
2817 widget = toolbar_content_get_widget (content);
2819 if (item == GTK_TOOL_ITEM (widget))
2825 return physical_to_logical (toolbar, n);
2829 * gtk_toolbar_set_orientation:
2830 * @toolbar: a #GtkToolbar.
2831 * @orientation: a new #GtkOrientation.
2833 * Sets whether a toolbar should appear horizontally or vertically.
2836 gtk_toolbar_set_orientation (GtkToolbar *toolbar,
2837 GtkOrientation orientation)
2839 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2841 g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0, orientation);
2845 * gtk_toolbar_get_orientation:
2846 * @toolbar: a #GtkToolbar
2848 * Retrieves the current orientation of the toolbar. See
2849 * gtk_toolbar_set_orientation().
2851 * Return value: the orientation
2854 gtk_toolbar_get_orientation (GtkToolbar *toolbar)
2856 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_ORIENTATION_HORIZONTAL);
2858 return toolbar->orientation;
2862 * gtk_toolbar_set_style:
2863 * @toolbar: a #GtkToolbar.
2864 * @style: the new style for @toolbar.
2866 * Alters the view of @toolbar to display either icons only, text only, or both.
2869 gtk_toolbar_set_style (GtkToolbar *toolbar,
2870 GtkToolbarStyle style)
2872 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2874 toolbar->style_set = TRUE;
2875 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2879 * gtk_toolbar_get_style:
2880 * @toolbar: a #GtkToolbar
2882 * Retrieves whether the toolbar has text, icons, or both . See
2883 * gtk_toolbar_set_style().
2885 * Return value: the current style of @toolbar
2888 gtk_toolbar_get_style (GtkToolbar *toolbar)
2890 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_TOOLBAR_STYLE);
2892 return toolbar->style;
2896 * gtk_toolbar_unset_style:
2897 * @toolbar: a #GtkToolbar
2899 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that
2900 * user preferences will be used to determine the toolbar style.
2903 gtk_toolbar_unset_style (GtkToolbar *toolbar)
2905 GtkToolbarStyle style;
2907 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2909 if (toolbar->style_set)
2911 GtkSettings *settings = toolbar_get_settings (toolbar);
2914 g_object_get (settings,
2915 "gtk-toolbar-style", &style,
2918 style = DEFAULT_TOOLBAR_STYLE;
2920 if (style != toolbar->style)
2921 g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
2923 toolbar->style_set = FALSE;
2928 * gtk_toolbar_set_tooltips:
2929 * @toolbar: a #GtkToolbar.
2930 * @enable: set to %FALSE to disable the tooltips, or %TRUE to enable them.
2932 * Sets if the tooltips of a toolbar should be active or not.
2935 gtk_toolbar_set_tooltips (GtkToolbar *toolbar,
2938 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
2941 gtk_tooltips_enable (toolbar->tooltips);
2943 gtk_tooltips_disable (toolbar->tooltips);
2945 g_object_notify (G_OBJECT (toolbar), "tooltips");
2949 * gtk_toolbar_get_tooltips:
2950 * @toolbar: a #GtkToolbar
2952 * Retrieves whether tooltips are enabled. See
2953 * gtk_toolbar_set_tooltips().
2955 * Return value: %TRUE if tooltips are enabled
2958 gtk_toolbar_get_tooltips (GtkToolbar *toolbar)
2960 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
2962 return toolbar->tooltips->enabled;
2966 * gtk_toolbar_get_n_items:
2967 * @toolbar: a #GtkToolbar
2969 * Returns the number of items on the toolbar.
2971 * Return value: the number of items on the toolbar
2976 gtk_toolbar_get_n_items (GtkToolbar *toolbar)
2978 GtkToolbarPrivate *priv;
2980 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
2982 if (!gtk_toolbar_check_new_api (toolbar))
2985 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
2987 return physical_to_logical (toolbar, g_list_length (priv->content));
2991 * gtk_toolbar_get_nth_item:
2992 * @toolbar: a #GtkToolbar
2993 * @n: A position on the toolbar
2995 * Returns the @n<!-- -->'th item on @toolbar, or %NULL if the
2996 * toolbar does not contain an @n<!-- -->'th item.
2998 * Return value: The @n<!-- -->'th #GtkToolItem on @toolbar, or %NULL if there
2999 * isn't an @n<!-- -->'th item.
3004 gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
3007 GtkToolbarPrivate *priv;
3008 ToolbarContent *content;
3011 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
3013 if (!gtk_toolbar_check_new_api (toolbar))
3016 n_items = gtk_toolbar_get_n_items (toolbar);
3018 if (n < 0 || n >= n_items)
3021 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3023 content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
3026 g_assert (!toolbar_content_is_placeholder (content));
3028 return GTK_TOOL_ITEM (toolbar_content_get_widget (content));
3032 * gtk_toolbar_get_icon_size:
3033 * @toolbar: a #GtkToolbar
3035 * Retrieves the icon size for the toolbar. See gtk_toolbar_set_icon_size().
3037 * Return value: the current icon size for the icons on the toolbar.
3040 gtk_toolbar_get_icon_size (GtkToolbar *toolbar)
3042 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_ICON_SIZE);
3044 return toolbar->icon_size;
3048 * gtk_toolbar_get_relief_style:
3049 * @toolbar: a #GtkToolbar
3051 * Returns the relief style of buttons on @toolbar. See
3052 * gtk_button_set_relief().
3054 * Return value: The relief style of buttons on @toolbar.
3059 gtk_toolbar_get_relief_style (GtkToolbar *toolbar)
3061 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), GTK_RELIEF_NONE);
3063 return get_button_relief (toolbar);
3067 * gtk_toolbar_set_show_arrow:
3068 * @toolbar: a #GtkToolbar
3069 * @show_arrow: Whether to show an overflow menu
3071 * Sets whether to show an overflow menu when
3072 * @toolbar doesn't have room for all items on it. If %TRUE,
3073 * items that there are not room are available through an
3079 gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
3080 gboolean show_arrow)
3082 GtkToolbarPrivate *priv;
3084 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3086 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3087 show_arrow = show_arrow != FALSE;
3089 if (priv->show_arrow != show_arrow)
3091 priv->show_arrow = show_arrow;
3093 if (!priv->show_arrow)
3094 gtk_widget_hide (priv->arrow_button);
3096 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3097 g_object_notify (G_OBJECT (toolbar), "show-arrow");
3102 * gtk_toolbar_get_show_arrow:
3103 * @toolbar: a #GtkToolbar
3105 * Returns whether the toolbar has an overflow menu.
3106 * See gtk_toolbar_set_show_arrow().
3108 * Return value: %TRUE if the toolbar has an overflow menu.
3113 gtk_toolbar_get_show_arrow (GtkToolbar *toolbar)
3115 GtkToolbarPrivate *priv;
3117 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
3119 if (!gtk_toolbar_check_new_api (toolbar))
3122 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3124 return priv->show_arrow;
3128 * gtk_toolbar_get_drop_index:
3129 * @toolbar: a #GtkToolbar
3130 * @x: x coordinate of a point on the toolbar
3131 * @y: y coordinate of a point on the toolbar
3133 * Returns the position corresponding to the indicated point on
3134 * @toolbar. This is useful when dragging items to the toolbar:
3135 * this function returns the position a new item should be
3138 * @x and @y are in @toolbar coordinates.
3140 * Return value: The position corresponding to the point (@x, @y) on the toolbar.
3145 gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
3149 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
3151 if (!gtk_toolbar_check_new_api (toolbar))
3154 return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
3158 gtk_toolbar_finalize (GObject *object)
3161 GtkToolbar *toolbar = GTK_TOOLBAR (object);
3162 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3164 if (toolbar->tooltips)
3165 g_object_unref (toolbar->tooltips);
3167 if (priv->arrow_button)
3168 gtk_widget_unparent (priv->arrow_button);
3170 for (list = priv->content; list != NULL; list = list->next)
3172 ToolbarContent *content = list->data;
3174 toolbar_content_free (content);
3177 g_list_free (priv->content);
3178 g_list_free (toolbar->children);
3180 g_timer_destroy (priv->timer);
3183 gtk_widget_destroy (GTK_WIDGET (priv->menu));
3186 g_source_remove (priv->idle_id);
3188 G_OBJECT_CLASS (gtk_toolbar_parent_class)->finalize (object);
3192 * gtk_toolbar_set_icon_size:
3193 * @toolbar: A #GtkToolbar
3194 * @icon_size: The #GtkIconSize that stock icons in the toolbar shall have.
3196 * This function sets the size of stock icons in the toolbar. You
3197 * can call it both before you add the icons and after they've been
3198 * added. The size you set will override user preferences for the default
3201 * This should only be used for special-purpose toolbars, normal
3202 * application toolbars should respect the user preferences for the
3206 gtk_toolbar_set_icon_size (GtkToolbar *toolbar,
3207 GtkIconSize icon_size)
3209 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3210 g_return_if_fail (icon_size != GTK_ICON_SIZE_INVALID);
3212 if (!toolbar->icon_size_set)
3214 toolbar->icon_size_set = TRUE;
3215 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3218 if (toolbar->icon_size == icon_size)
3221 toolbar->icon_size = icon_size;
3222 g_object_notify (G_OBJECT (toolbar), "icon-size");
3224 gtk_toolbar_reconfigured (toolbar);
3226 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3230 * gtk_toolbar_unset_icon_size:
3231 * @toolbar: a #GtkToolbar
3233 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that
3234 * user preferences will be used to determine the icon size.
3237 gtk_toolbar_unset_icon_size (GtkToolbar *toolbar)
3241 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3243 if (toolbar->icon_size_set)
3245 GtkSettings *settings = toolbar_get_settings (toolbar);
3249 g_object_get (settings,
3250 "gtk-toolbar-icon-size", &size,
3254 size = DEFAULT_ICON_SIZE;
3256 if (size != toolbar->icon_size)
3258 gtk_toolbar_set_icon_size (toolbar, size);
3259 g_object_notify (G_OBJECT (toolbar), "icon-size");
3262 toolbar->icon_size_set = FALSE;
3263 g_object_notify (G_OBJECT (toolbar), "icon-size-set");
3272 * gtk_toolbar_append_item:
3273 * @toolbar: a #GtkToolbar.
3274 * @text: give your toolbar button a label.
3275 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3276 * @tooltip_private_text: use with #GtkTipsQuery.
3277 * @icon: a #GtkWidget that should be used as the button's icon.
3278 * @callback: the function to be executed when the button is pressed.
3279 * @user_data: a pointer to any data you wish to be passed to the callback.
3281 * Inserts a new item into the toolbar. You must specify the position
3282 * in the toolbar where it will be inserted.
3284 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3285 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3287 * Return value: the new toolbar item as a #GtkWidget.
3290 gtk_toolbar_append_item (GtkToolbar *toolbar,
3292 const char *tooltip_text,
3293 const char *tooltip_private_text,
3295 GtkSignalFunc callback,
3298 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3300 tooltip_text, tooltip_private_text,
3301 icon, callback, user_data,
3302 toolbar->num_children);
3306 * gtk_toolbar_prepend_item:
3307 * @toolbar: a #GtkToolbar.
3308 * @text: give your toolbar button a label.
3309 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3310 * @tooltip_private_text: use with #GtkTipsQuery.
3311 * @icon: a #GtkWidget that should be used as the button's icon.
3312 * @callback: the function to be executed when the button is pressed.
3313 * @user_data: a pointer to any data you wish to be passed to the callback.
3315 * Adds a new button to the beginning (top or left edges) of the given toolbar.
3317 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3318 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3320 * Return value: the new toolbar item as a #GtkWidget.
3323 gtk_toolbar_prepend_item (GtkToolbar *toolbar,
3325 const char *tooltip_text,
3326 const char *tooltip_private_text,
3328 GtkSignalFunc callback,
3331 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3333 tooltip_text, tooltip_private_text,
3334 icon, callback, user_data,
3339 * gtk_toolbar_insert_item:
3340 * @toolbar: a #GtkToolbar.
3341 * @text: give your toolbar button a label.
3342 * @tooltip_text: a string that appears when the user holds the mouse over this item.
3343 * @tooltip_private_text: use with #GtkTipsQuery.
3344 * @icon: a #GtkWidget that should be used as the button's icon.
3345 * @callback: the function to be executed when the button is pressed.
3346 * @user_data: a pointer to any data you wish to be passed to the callback.
3347 * @position: the number of widgets to insert this item after.
3349 * Inserts a new item into the toolbar. You must specify the position in the
3350 * toolbar where it will be inserted.
3352 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3353 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3355 * Return value: the new toolbar item as a #GtkWidget.
3358 gtk_toolbar_insert_item (GtkToolbar *toolbar,
3360 const char *tooltip_text,
3361 const char *tooltip_private_text,
3363 GtkSignalFunc callback,
3367 return gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3369 tooltip_text, tooltip_private_text,
3370 icon, callback, user_data,
3375 * gtk_toolbar_insert_stock:
3376 * @toolbar: A #GtkToolbar
3377 * @stock_id: The id of the stock item you want to insert
3378 * @tooltip_text: The text in the tooltip of the toolbar button
3379 * @tooltip_private_text: The private text of the tooltip
3380 * @callback: The callback called when the toolbar button is clicked.
3381 * @user_data: user data passed to callback
3382 * @position: The position the button shall be inserted at.
3383 * -1 means at the end.
3385 * Inserts a stock item at the specified position of the toolbar. If
3386 * @stock_id is not a known stock item ID, it's inserted verbatim,
3387 * except that underscores used to mark mnemonics are removed.
3389 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3390 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3392 * Returns: the inserted widget
3395 gtk_toolbar_insert_stock (GtkToolbar *toolbar,
3396 const gchar *stock_id,
3397 const char *tooltip_text,
3398 const char *tooltip_private_text,
3399 GtkSignalFunc callback,
3403 return internal_insert_element (toolbar, GTK_TOOLBAR_CHILD_BUTTON,
3405 tooltip_text, tooltip_private_text,
3406 NULL, callback, user_data,
3411 * gtk_toolbar_append_space:
3412 * @toolbar: a #GtkToolbar.
3414 * Adds a new space to the end of the toolbar.
3417 gtk_toolbar_append_space (GtkToolbar *toolbar)
3419 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3423 toolbar->num_children);
3427 * gtk_toolbar_prepend_space:
3428 * @toolbar: a #GtkToolbar.
3430 * Adds a new space to the beginning of the toolbar.
3433 gtk_toolbar_prepend_space (GtkToolbar *toolbar)
3435 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3443 * gtk_toolbar_insert_space:
3444 * @toolbar: a #GtkToolbar
3445 * @position: the number of widgets after which a space should be inserted.
3447 * Inserts a new space in the toolbar at the specified position.
3450 gtk_toolbar_insert_space (GtkToolbar *toolbar,
3453 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_SPACE,
3461 * gtk_toolbar_remove_space:
3462 * @toolbar: a #GtkToolbar.
3463 * @position: the index of the space to remove.
3465 * Removes a space from the specified position.
3468 gtk_toolbar_remove_space (GtkToolbar *toolbar,
3471 GtkToolbarPrivate *priv;
3472 ToolbarContent *content;
3474 g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
3476 if (!gtk_toolbar_check_old_api (toolbar))
3479 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3481 content = g_list_nth_data (priv->content, position);
3485 g_warning ("Toolbar position %d doesn't exist", position);
3489 if (!toolbar_content_is_separator (content))
3491 g_warning ("Toolbar position %d is not a space", position);
3495 toolbar_content_remove (content, toolbar);
3496 toolbar_content_free (content);
3500 * gtk_toolbar_append_widget:
3501 * @toolbar: a #GtkToolbar.
3502 * @widget: a #GtkWidget to add to the toolbar.
3503 * @tooltip_text: the element's tooltip.
3504 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3506 * Adds a widget to the end of the given toolbar.
3509 gtk_toolbar_append_widget (GtkToolbar *toolbar,
3511 const gchar *tooltip_text,
3512 const gchar *tooltip_private_text)
3514 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3516 tooltip_text, tooltip_private_text,
3518 toolbar->num_children);
3522 * gtk_toolbar_prepend_widget:
3523 * @toolbar: a #GtkToolbar.
3524 * @widget: a #GtkWidget to add to the toolbar.
3525 * @tooltip_text: the element's tooltip.
3526 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3528 * Adds a widget to the beginning of the given toolbar.
3531 gtk_toolbar_prepend_widget (GtkToolbar *toolbar,
3533 const gchar *tooltip_text,
3534 const gchar *tooltip_private_text)
3536 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3538 tooltip_text, tooltip_private_text,
3544 * gtk_toolbar_insert_widget:
3545 * @toolbar: a #GtkToolbar.
3546 * @widget: a #GtkWidget to add to the toolbar.
3547 * @tooltip_text: the element's tooltip.
3548 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3549 * @position: the number of widgets to insert this widget after.
3551 * Inserts a widget in the toolbar at the given position.
3554 gtk_toolbar_insert_widget (GtkToolbar *toolbar,
3556 const char *tooltip_text,
3557 const char *tooltip_private_text,
3560 gtk_toolbar_insert_element (toolbar, GTK_TOOLBAR_CHILD_WIDGET,
3562 tooltip_text, tooltip_private_text,
3568 * gtk_toolbar_append_element:
3569 * @toolbar: a #GtkToolbar.
3570 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3571 * @widget: a #GtkWidget, or %NULL.
3572 * @text: the element's label.
3573 * @tooltip_text: the element's tooltip.
3574 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3575 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3576 * @callback: the function to be executed when the button is pressed.
3577 * @user_data: any data you wish to pass to the callback.
3579 * Adds a new element to the end of a toolbar.
3581 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3582 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3583 * the radio group for the new element. In all other cases, @widget must
3586 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3587 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3589 * Return value: the new toolbar element as a #GtkWidget.
3592 gtk_toolbar_append_element (GtkToolbar *toolbar,
3593 GtkToolbarChildType type,
3596 const char *tooltip_text,
3597 const char *tooltip_private_text,
3599 GtkSignalFunc callback,
3602 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3603 tooltip_text, tooltip_private_text,
3604 icon, callback, user_data,
3605 toolbar->num_children);
3609 * gtk_toolbar_prepend_element:
3610 * @toolbar: a #GtkToolbar.
3611 * @type: a value of type #GtkToolbarChildType that determines what @widget will be.
3612 * @widget: a #GtkWidget, or %NULL
3613 * @text: the element's label.
3614 * @tooltip_text: the element's tooltip.
3615 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3616 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3617 * @callback: the function to be executed when the button is pressed.
3618 * @user_data: any data you wish to pass to the callback.
3620 * Adds a new element to the beginning of a toolbar.
3622 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3623 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3624 * the radio group for the new element. In all other cases, @widget must
3627 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3628 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3630 * Return value: the new toolbar element as a #GtkWidget.
3633 gtk_toolbar_prepend_element (GtkToolbar *toolbar,
3634 GtkToolbarChildType type,
3637 const char *tooltip_text,
3638 const char *tooltip_private_text,
3640 GtkSignalFunc callback,
3643 return gtk_toolbar_insert_element (toolbar, type, widget, text,
3644 tooltip_text, tooltip_private_text,
3645 icon, callback, user_data, 0);
3649 * gtk_toolbar_insert_element:
3650 * @toolbar: a #GtkToolbar.
3651 * @type: a value of type #GtkToolbarChildType that determines what @widget
3653 * @widget: a #GtkWidget, or %NULL.
3654 * @text: the element's label.
3655 * @tooltip_text: the element's tooltip.
3656 * @tooltip_private_text: used for context-sensitive help about this toolbar element.
3657 * @icon: a #GtkWidget that provides pictorial representation of the element's function.
3658 * @callback: the function to be executed when the button is pressed.
3659 * @user_data: any data you wish to pass to the callback.
3660 * @position: the number of widgets to insert this element after.
3662 * Inserts a new element in the toolbar at the given position.
3664 * If @type == %GTK_TOOLBAR_CHILD_WIDGET, @widget is used as the new element.
3665 * If @type == %GTK_TOOLBAR_CHILD_RADIOBUTTON, @widget is used to determine
3666 * the radio group for the new element. In all other cases, @widget must
3669 * @callback must be a pointer to a function taking a #GtkWidget and a gpointer as
3670 * arguments. Use the GTK_SIGNAL_FUNC() to cast the function to #GtkSignalFunc.
3672 * Return value: the new toolbar element as a #GtkWidget.
3675 gtk_toolbar_insert_element (GtkToolbar *toolbar,
3676 GtkToolbarChildType type,
3679 const char *tooltip_text,
3680 const char *tooltip_private_text,
3682 GtkSignalFunc callback,
3686 return internal_insert_element (toolbar, type, widget, text,
3687 tooltip_text, tooltip_private_text,
3688 icon, callback, user_data, position, FALSE);
3692 set_child_packing_and_visibility(GtkToolbar *toolbar,
3693 GtkToolbarChild *child)
3698 box = gtk_bin_get_child (GTK_BIN (child->widget));
3700 g_return_if_fail (GTK_IS_BOX (box));
3704 expand = (toolbar->style != GTK_TOOLBAR_BOTH);
3706 gtk_box_set_child_packing (GTK_BOX (box), child->label,
3707 expand, expand, 0, GTK_PACK_END);
3709 if (toolbar->style != GTK_TOOLBAR_ICONS)
3710 gtk_widget_show (child->label);
3712 gtk_widget_hide (child->label);
3717 expand = (toolbar->style != GTK_TOOLBAR_BOTH_HORIZ);
3719 gtk_box_set_child_packing (GTK_BOX (box), child->icon,
3720 expand, expand, 0, GTK_PACK_END);
3722 if (toolbar->style != GTK_TOOLBAR_TEXT)
3723 gtk_widget_show (child->icon);
3725 gtk_widget_hide (child->icon);
3730 internal_insert_element (GtkToolbar *toolbar,
3731 GtkToolbarChildType type,
3734 const char *tooltip_text,
3735 const char *tooltip_private_text,
3737 GtkSignalFunc callback,
3743 ToolbarContent *content;
3744 char *free_me = NULL;
3746 GtkWidget *child_widget;
3747 GtkWidget *child_label;
3748 GtkWidget *child_icon;
3750 g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
3751 if (type == GTK_TOOLBAR_CHILD_WIDGET)
3752 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3753 else if (type != GTK_TOOLBAR_CHILD_RADIOBUTTON)
3754 g_return_val_if_fail (widget == NULL, NULL);
3755 if (GTK_IS_TOOL_ITEM (widget))
3756 g_warning (MIXED_API_WARNING);
3758 if (!gtk_toolbar_check_old_api (toolbar))
3761 child_widget = NULL;
3767 case GTK_TOOLBAR_CHILD_SPACE:
3770 case GTK_TOOLBAR_CHILD_WIDGET:
3771 child_widget = widget;
3774 case GTK_TOOLBAR_CHILD_BUTTON:
3775 case GTK_TOOLBAR_CHILD_TOGGLEBUTTON:
3776 case GTK_TOOLBAR_CHILD_RADIOBUTTON:
3777 if (type == GTK_TOOLBAR_CHILD_BUTTON)
3779 child_widget = gtk_button_new ();
3781 else if (type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
3783 child_widget = gtk_toggle_button_new ();
3784 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3786 else /* type == GTK_TOOLBAR_CHILD_RADIOBUTTON */
3788 GSList *group = NULL;
3791 group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
3793 child_widget = gtk_radio_button_new (group);
3794 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (child_widget), FALSE);
3797 gtk_button_set_relief (GTK_BUTTON (child_widget), get_button_relief (toolbar));
3798 gtk_button_set_focus_on_click (GTK_BUTTON (child_widget), FALSE);
3802 g_signal_connect (child_widget, "clicked",
3803 callback, user_data);
3806 if (toolbar->style == GTK_TOOLBAR_BOTH_HORIZ)
3807 box = gtk_hbox_new (FALSE, 0);
3809 box = gtk_vbox_new (FALSE, 0);
3811 gtk_container_add (GTK_CONTAINER (child_widget), box);
3812 gtk_widget_show (box);
3814 if (text && use_stock)
3816 GtkStockItem stock_item;
3817 if (gtk_stock_lookup (text, &stock_item))
3820 icon = gtk_image_new_from_stock (text, toolbar->icon_size);
3822 text = free_me = _gtk_toolbar_elide_underscores (stock_item.label);
3828 child_label = gtk_label_new (text);
3830 gtk_container_add (GTK_CONTAINER (box), child_label);
3835 child_icon = GTK_WIDGET (icon);
3836 gtk_container_add (GTK_CONTAINER (box), child_icon);
3839 gtk_widget_show (child_widget);
3843 g_assert_not_reached ();
3847 if ((type != GTK_TOOLBAR_CHILD_SPACE) && tooltip_text)
3849 gtk_tooltips_set_tip (toolbar->tooltips, child_widget,
3850 tooltip_text, tooltip_private_text);
3853 content = toolbar_content_new_compatibility (toolbar, type, child_widget,
3854 child_icon, child_label, position);
3859 return child_widget;
3863 * ToolbarContent methods
3871 struct _ToolbarContent
3881 GtkAllocation start_allocation;
3882 GtkAllocation goal_allocation;
3883 guint is_placeholder : 1;
3884 guint disappearing : 1;
3885 TriState has_menu : 2;
3890 GtkToolbarChild child;
3891 GtkAllocation space_allocation;
3892 guint space_visible : 1;
3897 static ToolbarContent *
3898 toolbar_content_new_tool_item (GtkToolbar *toolbar,
3900 gboolean is_placeholder,
3903 ToolbarContent *content;
3904 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3906 content = g_new0 (ToolbarContent, 1);
3908 content->type = TOOL_ITEM;
3909 content->state = NOT_ALLOCATED;
3910 content->u.tool_item.item = item;
3911 content->u.tool_item.is_placeholder = is_placeholder;
3913 gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
3915 priv->content = g_list_insert (priv->content, content, pos);
3917 if (!is_placeholder)
3919 toolbar->num_children++;
3921 gtk_toolbar_stop_sliding (toolbar);
3924 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3925 priv->need_rebuild = TRUE;
3930 static ToolbarContent *
3931 toolbar_content_new_compatibility (GtkToolbar *toolbar,
3932 GtkToolbarChildType type,
3938 ToolbarContent *content;
3939 GtkToolbarChild *child;
3940 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3942 content = g_new0 (ToolbarContent, 1);
3944 child = &(content->u.compatibility.child);
3946 content->type = COMPATIBILITY;
3948 child->widget = widget;
3950 child->label = label;
3952 if (type != GTK_TOOLBAR_CHILD_SPACE)
3954 gtk_widget_set_parent (child->widget, GTK_WIDGET (toolbar));
3958 content->u.compatibility.space_visible = TRUE;
3959 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
3962 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
3963 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
3964 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
3966 set_child_packing_and_visibility (toolbar, child);
3969 priv->content = g_list_insert (priv->content, content, pos);
3970 toolbar->children = g_list_insert (toolbar->children, child, pos);
3971 priv->need_rebuild = TRUE;
3973 toolbar->num_children++;
3979 toolbar_content_remove (ToolbarContent *content,
3980 GtkToolbar *toolbar)
3982 GtkToolbarChild *child;
3983 GtkToolbarPrivate *priv;
3985 priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
3987 switch (content->type)
3990 gtk_widget_unparent (GTK_WIDGET (content->u.tool_item.item));
3994 child = &(content->u.compatibility.child);
3996 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
3998 g_object_ref (child->widget);
3999 gtk_widget_unparent (child->widget);
4000 gtk_widget_destroy (child->widget);
4001 g_object_unref (child->widget);
4004 toolbar->children = g_list_remove (toolbar->children, child);
4008 priv->content = g_list_remove (priv->content, content);
4010 if (!toolbar_content_is_placeholder (content))
4011 toolbar->num_children--;
4013 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
4014 priv->need_rebuild = TRUE;
4018 toolbar_content_free (ToolbarContent *content)
4024 calculate_max_homogeneous_pixels (GtkWidget *widget)
4026 PangoContext *context;
4027 PangoFontMetrics *metrics;
4030 context = gtk_widget_get_pango_context (widget);
4031 metrics = pango_context_get_metrics (context,
4032 widget->style->font_desc,
4033 pango_context_get_language (context));
4034 char_width = pango_font_metrics_get_approximate_char_width (metrics);
4035 pango_font_metrics_unref (metrics);
4037 return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
4041 toolbar_content_expose (ToolbarContent *content,
4042 GtkContainer *container,
4043 GdkEventExpose *expose)
4045 GtkToolbar *toolbar = GTK_TOOLBAR (container);
4046 GtkToolbarChild *child;
4047 GtkWidget *widget = NULL; /* quiet gcc */
4049 switch (content->type)
4052 if (!content->u.tool_item.is_placeholder)
4053 widget = GTK_WIDGET (content->u.tool_item.item);
4057 child = &(content->u.compatibility.child);
4059 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
4061 if (get_space_style (toolbar) == GTK_TOOLBAR_SPACE_LINE &&
4062 content->u.compatibility.space_visible)
4064 _gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), toolbar,
4066 &content->u.compatibility.space_allocation);
4071 widget = child->widget;
4076 gtk_container_propagate_expose (container, widget, expose);
4080 toolbar_content_visible (ToolbarContent *content,
4081 GtkToolbar *toolbar)
4085 switch (content->type)
4088 item = content->u.tool_item.item;
4090 if (!GTK_WIDGET_VISIBLE (item))
4093 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL &&
4094 gtk_tool_item_get_visible_horizontal (item))
4099 if ((toolbar->orientation == GTK_ORIENTATION_VERTICAL &&
4100 gtk_tool_item_get_visible_vertical (item)))
4109 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4110 return GTK_WIDGET_VISIBLE (content->u.compatibility.child.widget);
4116 g_assert_not_reached ();
4121 toolbar_content_size_request (ToolbarContent *content,
4122 GtkToolbar *toolbar,
4123 GtkRequisition *requisition)
4127 switch (content->type)
4130 gtk_widget_size_request (GTK_WIDGET (content->u.tool_item.item),
4132 if (content->u.tool_item.is_placeholder &&
4133 content->u.tool_item.disappearing)
4135 requisition->width = 0;
4136 requisition->height = 0;
4141 space_size = get_space_size (toolbar);
4143 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4145 gtk_widget_size_request (content->u.compatibility.child.widget,
4150 if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
4152 requisition->width = space_size;
4153 requisition->height = 0;
4157 requisition->height = space_size;
4158 requisition->width = 0;
4167 toolbar_content_is_homogeneous (ToolbarContent *content,
4168 GtkToolbar *toolbar)
4170 gboolean result = FALSE; /* quiet gcc */
4171 GtkRequisition requisition;
4172 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4174 if (priv->max_homogeneous_pixels < 0)
4176 priv->max_homogeneous_pixels =
4177 calculate_max_homogeneous_pixels (GTK_WIDGET (toolbar));
4180 toolbar_content_size_request (content, toolbar, &requisition);
4182 if (requisition.width > priv->max_homogeneous_pixels)
4185 switch (content->type)
4188 result = gtk_tool_item_get_homogeneous (content->u.tool_item.item) &&
4189 !GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4191 if (gtk_tool_item_get_is_important (content->u.tool_item.item) &&
4192 toolbar->style == GTK_TOOLBAR_BOTH_HORIZ &&
4193 toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
4200 if (content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_BUTTON ||
4201 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4202 content->u.compatibility.child.type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4217 toolbar_content_is_placeholder (ToolbarContent *content)
4219 if (content->type == TOOL_ITEM && content->u.tool_item.is_placeholder)
4226 toolbar_content_disappearing (ToolbarContent *content)
4228 if (content->type == TOOL_ITEM && content->u.tool_item.disappearing)
4235 toolbar_content_get_state (ToolbarContent *content)
4237 return content->state;
4241 toolbar_content_child_visible (ToolbarContent *content)
4243 switch (content->type)
4246 return GTK_WIDGET_CHILD_VISIBLE (content->u.tool_item.item);
4250 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4252 return GTK_WIDGET_CHILD_VISIBLE (content->u.compatibility.child.widget);
4256 return content->u.compatibility.space_visible;
4261 return FALSE; /* quiet gcc */
4265 toolbar_content_get_goal_allocation (ToolbarContent *content,
4266 GtkAllocation *allocation)
4268 switch (content->type)
4271 *allocation = content->u.tool_item.goal_allocation;
4275 /* Goal allocations are only relevant when we are
4276 * using the new API, so we should never get here
4278 g_assert_not_reached ();
4284 toolbar_content_get_allocation (ToolbarContent *content,
4285 GtkAllocation *allocation)
4287 GtkToolbarChild *child;
4289 switch (content->type)
4292 *allocation = GTK_WIDGET (content->u.tool_item.item)->allocation;
4296 child = &(content->u.compatibility.child);
4298 if (child->type == GTK_TOOLBAR_CHILD_SPACE)
4299 *allocation = content->u.compatibility.space_allocation;
4301 *allocation = child->widget->allocation;
4307 toolbar_content_set_start_allocation (ToolbarContent *content,
4308 GtkAllocation *allocation)
4310 switch (content->type)
4313 content->u.tool_item.start_allocation = *allocation;
4317 /* start_allocation is only relevant when using the new API */
4318 g_assert_not_reached ();
4324 toolbar_content_get_expand (ToolbarContent *content)
4326 if (content->type == TOOL_ITEM &&
4327 gtk_tool_item_get_expand (content->u.tool_item.item) &&
4328 !content->u.tool_item.disappearing)
4337 toolbar_content_set_goal_allocation (ToolbarContent *content,
4338 GtkAllocation *allocation)
4340 switch (content->type)
4343 content->u.tool_item.goal_allocation = *allocation;
4347 /* Only relevant when using new API */
4348 g_assert_not_reached ();
4354 toolbar_content_set_child_visible (ToolbarContent *content,
4355 GtkToolbar *toolbar,
4358 GtkToolbarChild *child;
4360 switch (content->type)
4363 gtk_widget_set_child_visible (GTK_WIDGET (content->u.tool_item.item),
4368 child = &(content->u.compatibility.child);
4370 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4372 gtk_widget_set_child_visible (child->widget, visible);
4376 if (content->u.compatibility.space_visible != visible)
4378 content->u.compatibility.space_visible = visible;
4379 gtk_widget_queue_draw (GTK_WIDGET (toolbar));
4387 toolbar_content_get_start_allocation (ToolbarContent *content,
4388 GtkAllocation *start_allocation)
4390 switch (content->type)
4393 *start_allocation = content->u.tool_item.start_allocation;
4397 /* Only relevant for new API */
4398 g_assert_not_reached ();
4404 toolbar_content_size_allocate (ToolbarContent *content,
4405 GtkAllocation *allocation)
4407 switch (content->type)
4410 gtk_widget_size_allocate (GTK_WIDGET (content->u.tool_item.item),
4415 if (content->u.compatibility.child.type != GTK_TOOLBAR_CHILD_SPACE)
4417 gtk_widget_size_allocate (content->u.compatibility.child.widget,
4422 content->u.compatibility.space_allocation = *allocation;
4429 toolbar_content_set_state (ToolbarContent *content,
4432 content->state = state;
4436 toolbar_content_get_widget (ToolbarContent *content)
4438 GtkToolbarChild *child;
4440 switch (content->type)
4443 return GTK_WIDGET (content->u.tool_item.item);
4447 child = &(content->u.compatibility.child);
4448 if (child->type != GTK_TOOLBAR_CHILD_SPACE)
4449 return child->widget;
4459 toolbar_content_set_disappearing (ToolbarContent *content,
4460 gboolean disappearing)
4462 switch (content->type)
4465 content->u.tool_item.disappearing = disappearing;
4469 /* Only relevant for new API */
4470 g_assert_not_reached ();
4476 toolbar_content_set_size_request (ToolbarContent *content,
4480 switch (content->type)
4483 gtk_widget_set_size_request (GTK_WIDGET (content->u.tool_item.item),
4488 /* Setting size requests only happens with sliding,
4489 * so not relevant here
4491 g_assert_not_reached ();
4497 toolbar_child_reconfigure (GtkToolbar *toolbar,
4498 GtkToolbarChild *child)
4502 GtkToolbarStyle style;
4503 GtkIconSize icon_size;
4504 GtkReliefStyle relief;
4507 style = gtk_toolbar_get_style (toolbar);
4508 icon_size = gtk_toolbar_get_icon_size (toolbar);
4509 relief = gtk_toolbar_get_relief_style (toolbar);
4512 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4513 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4514 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4516 box = gtk_bin_get_child (GTK_BIN (child->widget));
4518 if (style == GTK_TOOLBAR_BOTH && GTK_IS_HBOX (box))
4522 vbox = gtk_vbox_new (FALSE, 0);
4525 gtk_widget_reparent (child->label, vbox);
4527 gtk_widget_reparent (child->icon, vbox);
4529 gtk_widget_destroy (box);
4530 gtk_container_add (GTK_CONTAINER (child->widget), vbox);
4532 gtk_widget_show (vbox);
4534 else if (style == GTK_TOOLBAR_BOTH_HORIZ && GTK_IS_VBOX (box))
4538 hbox = gtk_hbox_new (FALSE, 0);
4541 gtk_widget_reparent (child->label, hbox);
4543 gtk_widget_reparent (child->icon, hbox);
4545 gtk_widget_destroy (box);
4546 gtk_container_add (GTK_CONTAINER (child->widget), hbox);
4548 gtk_widget_show (hbox);
4551 set_child_packing_and_visibility (toolbar, child);
4556 if ((child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4557 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4558 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON) &&
4559 GTK_IS_IMAGE (child->icon))
4561 image = GTK_IMAGE (child->icon);
4562 if (gtk_image_get_storage_type (image) == GTK_IMAGE_STOCK)
4564 gtk_image_get_stock (image, &stock_id, NULL);
4565 stock_id = g_strdup (stock_id);
4566 gtk_image_set_from_stock (image,
4574 if (child->type == GTK_TOOLBAR_CHILD_BUTTON ||
4575 child->type == GTK_TOOLBAR_CHILD_RADIOBUTTON ||
4576 child->type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON)
4578 gtk_button_set_relief (GTK_BUTTON (child->widget), relief);
4583 toolbar_content_toolbar_reconfigured (ToolbarContent *content,
4584 GtkToolbar *toolbar)
4586 switch (content->type)
4589 _gtk_tool_item_toolbar_reconfigured (content->u.tool_item.item);
4593 toolbar_child_reconfigure (toolbar, &(content->u.compatibility.child));
4599 toolbar_content_retrieve_menu_item (ToolbarContent *content)
4601 if (content->type == TOOL_ITEM)
4602 return gtk_tool_item_retrieve_proxy_menu_item (content->u.tool_item.item);
4604 /* FIXME - we might actually be able to do something meaningful here */
4609 toolbar_content_has_proxy_menu_item (ToolbarContent *content)
4611 if (content->type == TOOL_ITEM)
4613 GtkWidget *menu_item;
4615 if (content->u.tool_item.has_menu == YES)
4617 else if (content->u.tool_item.has_menu == NO)
4620 menu_item = toolbar_content_retrieve_menu_item (content);
4622 content->u.tool_item.has_menu = menu_item? YES : NO;
4624 return menu_item != NULL;
4633 toolbar_content_set_unknown_menu_status (ToolbarContent *content)
4635 if (content->type == TOOL_ITEM)
4636 content->u.tool_item.has_menu = UNKNOWN;
4640 toolbar_content_is_separator (ToolbarContent *content)
4642 GtkToolbarChild *child;
4644 switch (content->type)
4647 return GTK_IS_SEPARATOR_TOOL_ITEM (content->u.tool_item.item);
4651 child = &(content->u.compatibility.child);
4652 return (child->type == GTK_TOOLBAR_CHILD_SPACE);
4660 toolbar_content_set_expand (ToolbarContent *content,
4663 if (content->type == TOOL_ITEM)
4664 gtk_tool_item_set_expand (content->u.tool_item.item, expand);
4668 ignore_show_and_hide_all (ToolbarContent *content)
4670 if (content->type == COMPATIBILITY)
4672 GtkToolbarChildType type = content->u.compatibility.child.type;
4674 if (type == GTK_TOOLBAR_CHILD_BUTTON ||
4675 type == GTK_TOOLBAR_CHILD_TOGGLEBUTTON ||
4676 type == GTK_TOOLBAR_CHILD_RADIOBUTTON)
4686 toolbar_content_show_all (ToolbarContent *content)
4690 if (ignore_show_and_hide_all (content))
4693 widget = toolbar_content_get_widget (content);
4695 gtk_widget_show_all (widget);
4699 toolbar_content_hide_all (ToolbarContent *content)
4703 if (ignore_show_and_hide_all (content))
4706 widget = toolbar_content_get_widget (content);
4708 gtk_widget_hide_all (widget);
4715 get_space_size (GtkToolbar *toolbar)
4717 gint space_size = DEFAULT_SPACE_SIZE;
4721 gtk_widget_style_get (GTK_WIDGET (toolbar),
4722 "space-size", &space_size,
4729 static GtkToolbarSpaceStyle
4730 get_space_style (GtkToolbar *toolbar)
4732 GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE;
4736 gtk_widget_style_get (GTK_WIDGET (toolbar),
4737 "space-style", &space_style,
4744 static GtkReliefStyle
4745 get_button_relief (GtkToolbar *toolbar)
4747 GtkReliefStyle button_relief = GTK_RELIEF_NORMAL;
4749 gtk_widget_ensure_style (GTK_WIDGET (toolbar));
4751 gtk_widget_style_get (GTK_WIDGET (toolbar),
4752 "button-relief", &button_relief,
4755 return button_relief;
4759 get_internal_padding (GtkToolbar *toolbar)
4763 gtk_widget_style_get (GTK_WIDGET (toolbar),
4764 "internal-padding", &ipadding,
4771 get_max_child_expand (GtkToolbar *toolbar)
4773 gint mexpand = G_MAXINT;
4775 gtk_widget_style_get (GTK_WIDGET (toolbar),
4776 "max-child-expand", &mexpand,
4781 static GtkShadowType
4782 get_shadow_type (GtkToolbar *toolbar)
4784 GtkShadowType shadow_type;
4786 gtk_widget_style_get (GTK_WIDGET (toolbar),
4787 "shadow-type", &shadow_type,
4797 gtk_toolbar_check_old_api (GtkToolbar *toolbar)
4799 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4801 if (priv->api_mode == NEW_API)
4803 g_warning (MIXED_API_WARNING);
4807 priv->api_mode = OLD_API;
4812 gtk_toolbar_check_new_api (GtkToolbar *toolbar)
4814 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4816 if (priv->api_mode == OLD_API)
4818 g_warning (MIXED_API_WARNING);
4822 priv->api_mode = NEW_API;
4826 /* GTK+ internal methods */
4829 _gtk_toolbar_get_default_space_size (void)
4831 return DEFAULT_SPACE_SIZE;
4835 _gtk_toolbar_paint_space_line (GtkWidget *widget,
4836 GtkToolbar *toolbar,
4838 GtkAllocation *allocation)
4840 const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION);
4841 const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION);
4843 GtkOrientation orientation;
4845 g_return_if_fail (GTK_IS_WIDGET (widget));
4847 orientation = toolbar? toolbar->orientation : GTK_ORIENTATION_HORIZONTAL;
4849 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4851 gboolean wide_separators;
4852 gint separator_width;
4854 gtk_widget_style_get (widget,
4855 "wide-separators", &wide_separators,
4856 "separator-width", &separator_width,
4859 if (wide_separators)
4860 gtk_paint_box (widget->style, widget->window,
4861 GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
4862 area, widget, "vseparator",
4863 allocation->x + (allocation->width - separator_width) / 2,
4864 allocation->y + allocation->height * start_fraction,
4866 allocation->height * (end_fraction - start_fraction));
4868 gtk_paint_vline (widget->style, widget->window,
4869 GTK_WIDGET_STATE (widget), area, widget,
4871 allocation->y + allocation->height * start_fraction,
4872 allocation->y + allocation->height * end_fraction,
4873 allocation->x + (allocation->width - widget->style->xthickness) / 2);
4877 gboolean wide_separators;
4878 gint separator_height;
4880 gtk_widget_style_get (widget,
4881 "wide-separators", &wide_separators,
4882 "separator-height", &separator_height,
4885 if (wide_separators)
4886 gtk_paint_box (widget->style, widget->window,
4887 GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
4888 area, widget, "hseparator",
4889 allocation->x + allocation->width * start_fraction,
4890 allocation->y + (allocation->height - separator_height) / 2,
4891 allocation->width * (end_fraction - start_fraction),
4894 gtk_paint_hline (widget->style, widget->window,
4895 GTK_WIDGET_STATE (widget), area, widget,
4897 allocation->x + allocation->width * start_fraction,
4898 allocation->x + allocation->width * end_fraction,
4899 allocation->y + (allocation->height - widget->style->ythickness) / 2);
4904 _gtk_toolbar_elide_underscores (const gchar *original)
4907 const gchar *p, *end;
4909 gboolean last_underscore;
4914 len = strlen (original);
4915 q = result = g_malloc (len + 1);
4916 last_underscore = FALSE;
4918 end = original + len;
4919 for (p = original; p < end; p++)
4921 if (!last_underscore && *p == '_')
4922 last_underscore = TRUE;
4925 last_underscore = FALSE;
4926 if (*p != '_' && original + 2 <= p && p + 1 <= end && p[-2] == '(' && p[1] == ')')
4937 if (last_underscore)
4946 _gtk_toolbar_rebuild_menu (GtkToolbar *toolbar)
4948 GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
4951 priv->need_rebuild = TRUE;
4953 for (list = priv->content; list != NULL; list = list->next)
4955 ToolbarContent *content = list->data;
4957 toolbar_content_set_unknown_menu_status (content);
4960 gtk_widget_queue_resize (GTK_WIDGET (toolbar));
4963 #define __GTK_TOOLBAR_C__
4964 #include "gtkaliasdef.c"